diff --git a/.asf.yaml b/.asf.yaml index 1772623f1b1..b7043cec822 100644 --- a/.asf.yaml +++ b/.asf.yaml @@ -53,13 +53,11 @@ github: - acs-robot - kiranchavala - rajujith - - alexandremattioli - - vishesh92 - GaOrtiga - - BryanMLima - SadiJr - - JoaoJandre - winterhazel + - gpordeus + - hsato03 protected_branches: ~ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1be892f4577..1c6c90a6183 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,7 +33,7 @@ jobs: - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '11' distribution: 'adopt' @@ -41,7 +41,7 @@ jobs: cache: maven - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.8' architecture: 'x64' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6edc7bdb20..c4196f06d4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -179,7 +179,8 @@ jobs: "component/test_project_usage component/test_protocol_number_security_group component/test_public_ip - component/test_resource_limits", + component/test_resource_limits + component/test_resource_limit_tags", "component/test_regions_accounts component/test_routers component/test_snapshots @@ -194,8 +195,15 @@ jobs: component/test_vpc_network component/test_vpc_offerings component/test_vpc_routers - component/test_vpn_users", - "component/test_vpc_network_lbrules" ] + component/test_vpn_users + component/test_vpc_network_lbrules", + "smoke/test_list_accounts + smoke/test_list_disk_offerings + smoke/test_list_domains + smoke/test_list_hosts + smoke/test_list_service_offerings + smoke/test_list_storage_pools + smoke/test_list_volumes"] steps: - uses: actions/checkout@v4 @@ -203,7 +211,7 @@ jobs: fetch-depth: 0 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '11' distribution: 'adopt' @@ -211,7 +219,7 @@ jobs: cache: maven - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.8' architecture: 'x64' @@ -278,7 +286,7 @@ jobs: while ! nc -vzw 5 localhost 8096 2>&1 > /dev/null; do grep Exception /tmp/jetty-log; sleep 10; done set -e echo -e "\nStarting Advanced Zone DataCenter deployment" - python3 tools/marvin/marvin/deployDataCenter.py -i setup/dev/advanced.cfg 2>&1 || true + python3 tools/marvin/marvin/deployDataCenter.py -i setup/dev/advdualzone.cfg 2>&1 || true - name: Run Integration Tests with Simulator run: | @@ -291,7 +299,7 @@ jobs: TESTS=($(echo $TESTS | tr -d '\n' | tr -s ' ')) for suite in "${TESTS[@]}" ; do echo -e "Currently running test: $suite\n" - time nosetests-3.4 --with-xunit --xunit-file=integration-test-results/$suite.xml --with-marvin --marvin-config=setup/dev/advanced.cfg test/integration/$suite.py -s -a tags=advanced,required_hardware=false --zone=Sandbox-simulator --hypervisor=simulator || true ; + time nosetests-3.4 --with-xunit --xunit-file=integration-test-results/$suite.xml --with-marvin --marvin-config=setup/dev/advdualzone.cfg test/integration/$suite.py -s -a tags=advanced,required_hardware=false --zone=zim1 --hypervisor=simulator || true ; done echo -e "Stopping Simulator, integration tests run completed\n" diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 430d62df8de..f7b28fdeecc 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -37,7 +37,7 @@ jobs: fetch-depth: 0 - name: Set up JDK11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' diff --git a/.github/workflows/main-sonar-check.yml b/.github/workflows/main-sonar-check.yml index cc27309f8a5..66bb1093e04 100644 --- a/.github/workflows/main-sonar-check.yml +++ b/.github/workflows/main-sonar-check.yml @@ -37,7 +37,7 @@ jobs: fetch-depth: 0 - name: Set up JDK11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' diff --git a/.github/workflows/rat.yml b/.github/workflows/rat.yml index 64fa4c3da0c..b8f83de8194 100644 --- a/.github/workflows/rat.yml +++ b/.github/workflows/rat.yml @@ -32,7 +32,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '11' distribution: 'adopt' diff --git a/.github/workflows/sonar-check.yml b/.github/workflows/sonar-check.yml index a8282f25145..2ebcf1fb2db 100644 --- a/.github/workflows/sonar-check.yml +++ b/.github/workflows/sonar-check.yml @@ -39,7 +39,7 @@ jobs: fetch-depth: 0 - name: Set up JDK11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '11' diff --git a/INSTALL.md b/INSTALL.md index 620fc1833a8..6586e4e57fc 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -15,7 +15,7 @@ was tested against a CentOS 7 x86_64 setup. Install tools and dependencies used for development: - # yum -y install git java-11-openjdk java-11-openjdk-devel \ + # yum -y install git java-17-openjdk java-17-openjdk-devel \ mysql mysql-server mkisofs git gcc python MySQL-python openssh-clients wget Set up Maven (3.6.0): diff --git a/agent/conf/agent.properties b/agent/conf/agent.properties index b15534a0be6..e600e8f8f20 100644 --- a/agent/conf/agent.properties +++ b/agent/conf/agent.properties @@ -5,9 +5,9 @@ # 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 @@ -378,6 +378,10 @@ iscsi.session.cleanup.enabled=false # If the time is exceeded shutdown will be forced. #stop.script.timeout=120 +# Time (in seconds) to wait for scripts to complete. +# This is currently used only while checking if the host supports UEFI. +#agent.script.timeout=60 + # Definition of VMs video model type. #vm.video.hardware= @@ -422,3 +426,7 @@ iscsi.session.cleanup.enabled=false # Instance Conversion from Vmware to KVM through virt-v2v. Enable verbose mode # virtv2v.verbose.enabled=false + +# If set to "true", the agent will register for libvirt domain events, allowing for immediate updates on crashed or +# unexpectedly stopped. Experimental, requires agent restart. +# libvirt.events.enabled=false diff --git a/agent/conf/log4j-cloud.xml.in b/agent/conf/log4j-cloud.xml.in index 9ed43e083e0..44ebd1358af 100644 --- a/agent/conf/log4j-cloud.xml.in +++ b/agent/conf/log4j-cloud.xml.in @@ -17,91 +17,60 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - + + - + + + - - - + + + + + + + + - - - - - - - - - - - - - - - - + + + - - - + + + + + - - - - + - - - + + + - - - - - - - - - - - + - - - - + - - - - - - - + - - - - + - - - - + - - - + - - - + - - - - - + + + - + + + + + + + diff --git a/agent/pom.xml b/agent/pom.xml index 5fe88c8bdb7..9caa6d992c8 100644 --- a/agent/pom.xml +++ b/agent/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT diff --git a/agent/src/main/java/com/cloud/agent/Agent.java b/agent/src/main/java/com/cloud/agent/Agent.java index 9e0ee746c03..56732dad993 100644 --- a/agent/src/main/java/com/cloud/agent/Agent.java +++ b/agent/src/main/java/com/cloud/agent/Agent.java @@ -55,9 +55,10 @@ import org.apache.cloudstack.managed.context.ManagedContextTimerTask; import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; -import org.apache.log4j.MDC; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.AgentControlAnswer; import com.cloud.agent.api.AgentControlCommand; @@ -89,6 +90,7 @@ import com.cloud.utils.nio.NioConnection; import com.cloud.utils.nio.Task; import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; +import org.apache.logging.log4j.ThreadContext; /** * @config @@ -104,7 +106,7 @@ import com.cloud.utils.script.Script; * **/ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater { - protected static Logger s_logger = Logger.getLogger(Agent.class); + protected Logger logger = LogManager.getLogger(getClass()); public enum ExitStatus { Normal(0), // Normal status = 0. @@ -181,7 +183,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater final String value = _shell.getPersistentProperty(getResourceName(), "id"); _id = value != null ? Long.parseLong(value) : null; - s_logger.info("id is " + (_id != null ? _id : "")); + logger.info("id is {}", ObjectUtils.defaultIfNull(_id, "")); final Map params = new HashMap<>(); @@ -199,7 +201,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater // ((NioClient)_connection).setBindAddress(_shell.getPrivateIp()); - s_logger.debug("Adding shutdown hook"); + logger.debug("Adding shutdown hook"); Runtime.getRuntime().addShutdownHook(_shutdownThread); _ugentTaskPool = @@ -210,8 +212,8 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater new ThreadPoolExecutor(_shell.getWorkers(), 5 * _shell.getWorkers(), 1, TimeUnit.DAYS, new LinkedBlockingQueue(), new NamedThreadFactory( "agentRequest-Handler")); - s_logger.info("Agent [id = " + (_id != null ? _id : "new") + " : type = " + getResourceName() + " : zone = " + _shell.getZone() + " : pod = " + _shell.getPod() + - " : workers = " + _shell.getWorkers() + " : host = " + host + " : port = " + _shell.getPort()); + logger.info("Agent [id = {} : type = {} : zone = {} : pod = {} : workers = {} : host = {} : port = {}", ObjectUtils.defaultIfNull(_id, "new"), getResourceName(), + _shell.getZone(), _shell.getPod(), _shell.getWorkers(), host, _shell.getPort()); } public String getVersion() { @@ -268,7 +270,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater public void start() { if (!_resource.start()) { - s_logger.error("Unable to start the resource: " + _resource.getName()); + logger.error("Unable to start the resource: {}", _resource.getName()); throw new CloudRuntimeException("Unable to start the resource: " + _resource.getName()); } @@ -285,14 +287,13 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater try { _connection.start(); } catch (final NioConnectionException e) { - s_logger.warn("NIO Connection Exception " + e); - s_logger.info("Attempted to connect to the server, but received an unexpected exception, trying again..."); + logger.warn("Attempt to connect to server generated NIO Connection Exception {}, trying again", e.getLocalizedMessage()); } while (!_connection.isStartup()) { final String host = _shell.getNextHost(); _shell.getBackoffAlgorithm().waitBeforeRetry(); _connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this); - s_logger.info("Connecting to host:" + host); + logger.info("Connecting to host:{}", host); try { _connection.start(); } catch (final NioConnectionException e) { @@ -300,9 +301,9 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater try { _connection.cleanUp(); } catch (final IOException ex) { - s_logger.warn("Fail to clean up old connection. " + ex); + logger.warn("Fail to clean up old connection. {}", ex); } - s_logger.info("Attempted to connect to the server, but received an unexpected exception, trying again...", e); + logger.info("Attempted to connect to the server, but received an unexpected exception, trying again...", e); } } _shell.updateConnectedHost(); @@ -311,7 +312,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater } public void stop(final String reason, final String detail) { - s_logger.info("Stopping the agent: Reason = " + reason + (detail != null ? ": Detail = " + detail : "")); + logger.info("Stopping the agent: Reason = {} {}", reason, ": Detail = " + ObjectUtils.defaultIfNull(detail, "")); _reconnectAllowed = false; if (_connection != null) { final ShutdownCommand cmd = new ShutdownCommand(reason, detail); @@ -321,15 +322,15 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater _link.send(req.toBytes()); } } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send: " + cmd.toString()); + logger.warn("Unable to send: {}", cmd.toString()); } catch (final Exception e) { - s_logger.warn("Unable to send: " + cmd.toString() + " due to exception: ", e); + logger.warn("Unable to send: {} due to exception: {}", cmd.toString(), e); } - s_logger.debug("Sending shutdown to management server"); + logger.debug("Sending shutdown to management server"); try { Thread.sleep(1000); } catch (final InterruptedException e) { - s_logger.debug("Who the heck interrupted me here?"); + logger.debug("Who the heck interrupted me here?"); } _connection.stop(); _connection = null; @@ -376,7 +377,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater } public void setId(final Long id) { - s_logger.info("Set agent id " + id); + logger.debug("Set agent id {}", id); _id = id; _shell.setPersistentProperty(getResourceName(), "id", Long.toString(id)); } @@ -395,7 +396,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater hostLBTimer.cancel(); } if (checkInterval > 0L) { - s_logger.info("Scheduling preferred host timer task with host.lb.interval=" + checkInterval + "ms"); + logger.info("Scheduling preferred host timer task with host.lb.interval={}ms", checkInterval); hostLBTimer = new Timer("Host LB Timer"); hostLBTimer.scheduleAtFixedRate(new PreferredHostCheckerTask(), checkInterval, checkInterval); } @@ -403,9 +404,8 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater public void scheduleWatch(final Link link, final Request request, final long delay, final long period) { synchronized (_watchList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Adding a watch list"); - } + logger.debug("Adding task with request: {} to watch list", request.toString()); + final WatchTask task = new WatchTask(link, request, this); _timer.schedule(task, 0, period); _watchList.add(task); @@ -415,14 +415,14 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater public void triggerUpdate() { PingCommand command = _resource.getCurrentStatus(getId()); command.setOutOfBand(true); - s_logger.debug("Sending out of band ping"); + logger.debug("Sending out of band ping"); final Request request = new Request(_id, -1, command, false); request.setSequence(getNextSequence()); try { _link.send(request.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send ping update: " + request.toString()); + logger.warn("Unable to send ping update: {}", request.toString()); } } @@ -431,9 +431,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater for (final WatchTask task : _watchList) { task.cancel(); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Clearing watch list: " + _watchList.size()); - } + logger.debug("Clearing {} tasks of watch list", _watchList.size()); _watchList.clear(); } } @@ -469,14 +467,12 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater final Request request = new Request(_id != null ? _id : -1, -1, commands, false, false); request.setSequence(getNextSequence()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending Startup: " + request.toString()); - } + logger.debug("Sending Startup: {}", request.toString()); lockStartupTask(link); try { link.send(request.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send request: " + request.toString()); + logger.warn("Unable to send request: {}", request.toString()); } if (_resource instanceof ResourceStatusUpdater) { @@ -490,11 +486,11 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater try { addr = InetAddress.getLocalHost(); } catch (final UnknownHostException e) { - s_logger.warn("unknown host? ", e); + logger.warn("unknown host? ", e); throw new CloudRuntimeException("Cannot get local IP address"); } - final Script command = new Script("hostname", 500, s_logger); + final Script command = new Script("hostname", 500, logger); final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); final String result = command.execute(parser); final String hostname = result == null ? parser.getLine() : addr.toString(); @@ -536,14 +532,14 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater _resource.disconnected(); - s_logger.info("Lost connection to host: " + _shell.getConnectedHost() + ". Attempting reconnection while we still have " + _inProgress.get() + " commands in progress."); + logger.info("Lost connection to host: {}. Attempting reconnection while we still have {} commands in progress.", _shell.getConnectedHost(), _inProgress.get()); _connection.stop(); try { _connection.cleanUp(); } catch (final IOException e) { - s_logger.warn("Fail to clean up old connection. " + e); + logger.warn("Fail to clean up old connection. {}", e); } while (_connection.isStartup()) { @@ -553,22 +549,22 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater do { final String host = _shell.getNextHost(); _connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this); - s_logger.info("Reconnecting to host:" + host); + logger.info("Reconnecting to host:{}", host); try { _connection.start(); } catch (final NioConnectionException e) { - s_logger.info("Attempted to re-connect to the server, but received an unexpected exception, trying again...", e); + logger.info("Attempted to re-connect to the server, but received an unexpected exception, trying again...", e); _connection.stop(); try { _connection.cleanUp(); } catch (final IOException ex) { - s_logger.warn("Fail to clean up old connection. " + ex); + logger.warn("Fail to clean up old connection. {}", ex); } } _shell.getBackoffAlgorithm().waitBeforeRetry(); } while (!_connection.isStartup()); _shell.updateConnectedHost(); - s_logger.info("Connected to the host: " + _shell.getConnectedHost()); + logger.info("Connected to the host: {}", _shell.getConnectedHost()); } public void processStartupAnswer(final Answer answer, final Response response, final Link link) { @@ -583,15 +579,15 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater } final StartupAnswer startup = (StartupAnswer)answer; if (!startup.getResult()) { - s_logger.error("Not allowed to connect to the server: " + answer.getDetails()); + logger.error("Not allowed to connect to the server: {}", answer.getDetails()); System.exit(1); } if (cancelled) { - s_logger.warn("Threw away a startup answer because we're reconnecting."); + logger.warn("Threw away a startup answer because we're reconnecting."); return; } - s_logger.info("Process agent startup answer, agent id = " + startup.getHostId()); + logger.info("Process agent startup answer, agent id = {}", startup.getHostId()); setId(startup.getHostId()); _pingInterval = (long)startup.getPingInterval() * 1000; // change to ms. @@ -601,7 +597,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater _ugentTaskPool.setKeepAliveTime(2 * _pingInterval, TimeUnit.MILLISECONDS); - s_logger.info("Startup Response Received: agent id = " + getId()); + logger.info("Startup Response Received: agent id = {}", getId()); } protected void processRequest(final Request request, final Link link) { @@ -616,18 +612,18 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater Answer answer; try { if (cmd.getContextParam("logid") != null) { - MDC.put("logcontextid", cmd.getContextParam("logid")); + ThreadContext.put("logcontextid", cmd.getContextParam("logid")); } - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (!requestLogged) // ensures request is logged only once per method call { final String requestMsg = request.toString(); if (requestMsg != null) { - s_logger.debug("Request:" + requestMsg); + logger.debug("Request:{}",requestMsg); } requestLogged = true; } - s_logger.debug("Processing command: " + cmd.toString()); + logger.debug("Processing command: {}", cmd.toString()); } if (cmd instanceof CronCommand) { @@ -636,7 +632,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater answer = new Answer(cmd, true, null); } else if (cmd instanceof ShutdownCommand) { final ShutdownCommand shutdown = (ShutdownCommand)cmd; - s_logger.debug("Received shutdownCommand, due to: " + shutdown.getReason()); + logger.debug("Received shutdownCommand, due to: {}", shutdown.getReason()); cancelTasks(); if (shutdown.isRemoveHost()) { cleanupAgentZoneProperties(); @@ -644,11 +640,11 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater _reconnectAllowed = false; answer = new Answer(cmd, true, null); } else if (cmd instanceof ReadyCommand && ((ReadyCommand)cmd).getDetails() != null) { - s_logger.debug("Not ready to connect to mgt server: " + ((ReadyCommand)cmd).getDetails()); + logger.debug("Not ready to connect to mgt server: {}", ((ReadyCommand)cmd).getDetails()); System.exit(1); return; } else if (cmd instanceof MaintainCommand) { - s_logger.debug("Received maintainCommand, do not cancel current tasks"); + logger.debug("Received maintainCommand, do not cancel current tasks"); answer = new MaintainAnswer((MaintainCommand)cmd); } else if (cmd instanceof AgentControlCommand) { answer = null; @@ -662,7 +658,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater } if (answer == null) { - s_logger.warn("No handler found to process cmd: " + cmd.toString()); + logger.warn("No handler found to process cmd: {}", cmd.toString()); answer = new AgentControlAnswer(cmd); } } else if (cmd instanceof SetupKeyStoreCommand && ((SetupKeyStoreCommand) cmd).isHandleByAgent()) { @@ -685,12 +681,12 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater _inProgress.decrementAndGet(); } if (answer == null) { - s_logger.debug("Response: unsupported command" + cmd.toString()); + logger.debug("Response: unsupported command {}", cmd.toString()); answer = Answer.createUnsupportedCommandAnswer(cmd); } } } catch (final Throwable th) { - s_logger.warn("Caught: ", th); + logger.warn("Caught: ", th); final StringWriter writer = new StringWriter(); th.printStackTrace(new PrintWriter(writer)); answer = new Answer(cmd, false, writer.toString()); @@ -706,10 +702,10 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater } response = new Response(request, answers); } finally { - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { final String responseMsg = response.toString(); if (responseMsg != null) { - s_logger.debug(response.toString()); + logger.debug(response.toString()); } } @@ -717,7 +713,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater try { link.send(response.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send response: " + response.toString()); + logger.warn("Unable to send response: {}", response.toString()); } } } @@ -727,7 +723,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater final String keyStorePassword = cmd.getKeystorePassword(); final long validityDays = cmd.getValidityDays(); - s_logger.debug("Setting up agent keystore file and generating CSR"); + logger.debug("Setting up agent keystore file and generating CSR"); final File agentFile = PropertiesUtil.findConfigFile("agent.properties"); if (agentFile == null) { @@ -742,7 +738,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater _shell.setPersistentProperty(null, KeyStoreUtils.KS_PASSPHRASE_PROPERTY, storedPassword); } - Script script = new Script(_keystoreSetupPath, 300000, s_logger); + Script script = new Script(_keystoreSetupPath, 300000, logger); script.add(agentFile.getAbsolutePath()); script.add(keyStoreFile); script.add(storedPassword); @@ -767,7 +763,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater final String privateKey = cmd.getPrivateKey(); final String caCertificates = cmd.getCaCertificates(); - s_logger.debug("Importing received certificate to agent's keystore"); + logger.debug("Importing received certificate to agent's keystore"); final File agentFile = PropertiesUtil.findConfigFile("agent.properties"); if (agentFile == null) { @@ -781,13 +777,13 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater try { FileUtils.writeStringToFile(new File(certFile), certificate, Charset.defaultCharset()); FileUtils.writeStringToFile(new File(caCertFile), caCertificates, Charset.defaultCharset()); - s_logger.debug("Saved received client certificate to: " + certFile); + logger.debug("Saved received client certificate to: {}", certFile); } catch (IOException e) { throw new CloudRuntimeException("Unable to save received agent client and ca certificates", e); } String ksPassphrase = _shell.getPersistentProperty(null, KeyStoreUtils.KS_PASSPHRASE_PROPERTY); - Script script = new Script(_keystoreCertImportPath, 300000, s_logger); + Script script = new Script(_keystoreCertImportPath, 300000, logger); script.add(agentFile.getAbsolutePath()); script.add(ksPassphrase); script.add(keyStoreFile); @@ -812,7 +808,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater _shell.setPersistentProperty(null, "host", newMSHosts); _shell.setHosts(newMSHosts); _shell.resetHostCounter(); - s_logger.info("Processed new management server list: " + newMSHosts); + logger.info("Processed new management server list: {}", newMSHosts); } catch (final Exception e) { throw new CloudRuntimeException("Could not persist received management servers list", e); } @@ -831,9 +827,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater public void processResponse(final Response response, final Link link) { final Answer answer = response.getAnswer(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Received response: " + response.toString()); - } + logger.debug("Received response: {}", response.toString()); if (answer instanceof StartupAnswer) { processStartupAnswer(answer, response, link); } else if (answer instanceof AgentControlAnswer) { @@ -844,7 +838,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater } } } else if (answer instanceof PingAnswer && (((PingAnswer) answer).isSendStartup()) && _reconnectAllowed) { - s_logger.info("Management server requested startup command to reinitialize the agent"); + logger.info("Management server requested startup command to reinitialize the agent"); sendStartup(link); } else { setLastPingResponseTime(); @@ -859,44 +853,42 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater NumbersUtil.enableHumanReadableSizes = humanReadable; } - s_logger.info("Processing agent ready command, agent id = " + ready.getHostId()); + logger.info("Processing agent ready command, agent id = {}", ready.getHostId()); if (ready.getHostId() != null) { setId(ready.getHostId()); } processManagementServerList(ready.getMsHostList(), ready.getLbAlgorithm(), ready.getLbCheckInterval()); - s_logger.info("Ready command is processed for agent id = " + getId()); + logger.info("Ready command is processed for agent id = {}", getId()); } public void processOtherTask(final Task task) { final Object obj = task.get(); if (obj instanceof Response) { if (System.currentTimeMillis() - _lastPingResponseTime > _pingInterval * _shell.getPingRetries()) { - s_logger.error("Ping Interval has gone past " + _pingInterval * _shell.getPingRetries() + ". Won't reconnect to mgt server, as connection is still alive"); + logger.error("Ping Interval has gone past {}. Won't reconnect to mgt server, as connection is still alive", _pingInterval * _shell.getPingRetries()); return; } final PingCommand ping = _resource.getCurrentStatus(getId()); final Request request = new Request(_id, -1, ping, false); request.setSequence(getNextSequence()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending ping: " + request.toString()); - } + logger.debug("Sending ping: {}", request.toString()); try { task.getLink().send(request.toBytes()); //if i can send pingcommand out, means the link is ok setLastPingResponseTime(); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send request: " + request.toString()); + logger.warn("Unable to send request: {}", request.toString()); } } else if (obj instanceof Request) { final Request req = (Request)obj; final Command command = req.getCommand(); if (command.getContextParam("logid") != null) { - MDC.put("logcontextid", command.getContextParam("logid")); + ThreadContext.put("logcontextid", command.getContextParam("logid")); } Answer answer = null; _inProgress.incrementAndGet(); @@ -908,17 +900,15 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater if (answer != null) { final Response response = new Response(req, answer); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Watch Sent: " + response.toString()); - } + logger.debug("Watch Sent: {}", response.toString()); try { task.getLink().send(response.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send response: " + response.toString()); + logger.warn("Unable to send response: {}", response.toString()); } } } else { - s_logger.warn("Ignoring an unknown task"); + logger.warn("Ignoring an unknown task"); } } @@ -958,7 +948,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater try { listener.wait(timeoutInMilliseconds); } catch (final InterruptedException e) { - s_logger.warn("sendRequest is interrupted, exit waiting"); + logger.warn("sendRequest is interrupted, exit waiting"); } } @@ -980,7 +970,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater try { _link.send(request.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to post agent control request: " + request.toString()); + logger.warn("Unable to post agent control request: {}", request.toString()); throw new AgentControlChannelException("Unable to post agent control request due to " + e.getMessage()); } } else { @@ -1044,9 +1034,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater @Override protected void runInContext() { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Scheduling " + (_request instanceof Response ? "Ping" : "Watch Task")); - } + logger.trace("Scheduling {}", (_request instanceof Response ? "Ping" : "Watch Task")); try { if (_request instanceof Response) { _ugentTaskPool.submit(new ServerHandler(Task.Type.OTHER, _link, _request)); @@ -1054,7 +1042,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater _link.schedule(new ServerHandler(Task.Type.OTHER, _link, _request)); } } catch (final ClosedChannelException e) { - s_logger.warn("Unable to schedule task because channel is closed"); + logger.warn("Unable to schedule task because channel is closed"); } } } @@ -1064,7 +1052,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater protected volatile boolean cancelled = false; public StartupTask(final Link link) { - s_logger.debug("Startup task created"); + logger.debug("Startup task created"); _link = link; } @@ -1074,7 +1062,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater if (!cancelled) { cancelled = true; _startupWait = _startupWaitDefault; - s_logger.debug("Startup task cancelled"); + logger.debug("Startup task cancelled"); return super.cancel(); } return true; @@ -1083,9 +1071,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater @Override protected synchronized void runInContext() { if (!cancelled) { - if (s_logger.isInfoEnabled()) { - s_logger.info("The startup command is now cancelled"); - } + logger.info("The startup command is now cancelled"); cancelled = true; _startup = null; _startupWait = _startupWaitDefault * 2; @@ -1136,9 +1122,9 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater _executor.submit(new AgentRequestHandler(getType(), getLink(), request)); } } catch (final ClassNotFoundException e) { - s_logger.error("Unable to find this request "); + logger.error("Unable to find this request "); } catch (final Exception e) { - s_logger.error("Error parsing task", e); + logger.error("Error parsing task", e); } } else if (task.getType() == Task.Type.DISCONNECT) { reconnect(task.getLink()); @@ -1166,7 +1152,7 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater while (true) { try { if (_inProgress.get() == 0) { - s_logger.debug("Running post certificate renewal task to restart services."); + logger.debug("Running post certificate renewal task to restart services."); // Let the resource perform any post certificate renewal cleanups _resource.executeRequest(new PostCertificateRenewalCommand()); @@ -1191,12 +1177,11 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater shell.launchNewAgent(resource); return; } - if (s_logger.isTraceEnabled()) { - s_logger.debug("Other tasks are in progress, will retry post certificate renewal command after few seconds"); - } + logger.debug("Other tasks are in progress, will retry post certificate renewal command after few seconds"); + Thread.sleep(5000); } catch (final Exception e) { - s_logger.warn("Failed to execute post certificate renewal command:", e); + logger.warn("Failed to execute post certificate renewal command:", e); break; } } @@ -1214,29 +1199,26 @@ public class Agent implements HandlerFactory, IAgentControl, AgentStatusUpdater } final String preferredHost = msList[0]; final String connectedHost = _shell.getConnectedHost(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Running preferred host checker task, connected host=" + connectedHost + ", preferred host=" + preferredHost); - } + logger.trace("Running preferred host checker task, connected host={}, preferred host={}", connectedHost, preferredHost); + if (preferredHost != null && !preferredHost.equals(connectedHost) && _link != null) { boolean isHostUp = true; try (final Socket socket = new Socket()) { socket.connect(new InetSocketAddress(preferredHost, _shell.getPort()), 5000); } catch (final IOException e) { isHostUp = false; - if (s_logger.isTraceEnabled()) { - s_logger.trace("Host: " + preferredHost + " is not reachable"); - } + logger.trace("Host: {} is not reachable", preferredHost); + } if (isHostUp && _link != null && _inProgress.get() == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Preferred host " + preferredHost + " is found to be reachable, trying to reconnect"); - } + logger.debug("Preferred host {} is found to be reachable, trying to reconnect", preferredHost); + _shell.resetHostCounter(); reconnect(_link); } } } catch (Throwable t) { - s_logger.error("Error caught while attempting to connect to preferred host", t); + logger.error("Error caught while attempting to connect to preferred host", t); } } diff --git a/agent/src/main/java/com/cloud/agent/AgentShell.java b/agent/src/main/java/com/cloud/agent/AgentShell.java index ef042496a37..0699e00250b 100644 --- a/agent/src/main/java/com/cloud/agent/AgentShell.java +++ b/agent/src/main/java/com/cloud/agent/AgentShell.java @@ -34,8 +34,9 @@ import org.apache.commons.daemon.DaemonInitException; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.config.Configurator; import javax.naming.ConfigurationException; import java.io.File; @@ -53,7 +54,7 @@ import java.util.Properties; import java.util.UUID; public class AgentShell implements IAgentShell, Daemon { - private static final Logger s_logger = Logger.getLogger(AgentShell.class.getName()); + protected static Logger LOGGER = LogManager.getLogger(AgentShell.class); private final Properties _properties = new Properties(); private final Map _cmdLineProperties = new HashMap(); @@ -221,7 +222,7 @@ public class AgentShell implements IAgentShell, Daemon { throw new ConfigurationException("Unable to find agent.properties."); } - s_logger.info("agent.properties found at " + file.getAbsolutePath()); + LOGGER.info("agent.properties found at {}", file.getAbsolutePath()); try { PropertiesUtil.loadFromFile(_properties, file); @@ -349,7 +350,7 @@ public class AgentShell implements IAgentShell, Daemon { @Override public void init(DaemonContext dc) throws DaemonInitException { - s_logger.debug("Initializing AgentShell from JSVC"); + LOGGER.debug("Initializing AgentShell from JSVC"); try { init(dc.getArguments()); } catch (ConfigurationException ex) { @@ -369,11 +370,11 @@ public class AgentShell implements IAgentShell, Daemon { } if (null != file) { - DOMConfigurator.configureAndWatch(file.getAbsolutePath()); + Configurator.initialize(null, file.getAbsolutePath()); - s_logger.info("Agent started"); + LOGGER.info("Agent started"); } else { - s_logger.error("Could not start the Agent because the absolute path of the \"log4j-cloud.xml\" file cannot be determined."); + LOGGER.error("Could not start the Agent because the absolute path of the \"log4j-cloud.xml\" file cannot be determined."); } final Class c = this.getClass(); @@ -381,19 +382,19 @@ public class AgentShell implements IAgentShell, Daemon { if (_version == null) { throw new CloudRuntimeException("Unable to find the implementation version of this agent"); } - s_logger.info("Implementation Version is " + _version); + LOGGER.info("Implementation Version is {}", _version); loadProperties(); parseCommand(args); - if (s_logger.isDebugEnabled()) { + if (LOGGER.isDebugEnabled()) { List properties = Collections.list((Enumeration)_properties.propertyNames()); for (String property : properties) { - s_logger.debug("Found property: " + property); + LOGGER.debug("Found property: {}", property); } } - s_logger.info("Defaulting to using properties file for storage"); + LOGGER.info("Defaulting to using properties file for storage"); _storage = new PropertiesStorage(); _storage.configure("Storage", new HashMap()); @@ -403,14 +404,14 @@ public class AgentShell implements IAgentShell, Daemon { _properties.put(cmdLineProp.getKey(), cmdLineProp.getValue()); } - s_logger.info("Defaulting to the constant time backoff algorithm"); + LOGGER.info("Defaulting to the constant time backoff algorithm"); _backoff = new ConstantTimeBackoff(); _backoff.configure("ConstantTimeBackoff", new HashMap()); } private void launchAgent() throws ConfigurationException { String resourceClassNames = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.RESOURCE); - s_logger.trace("resource=" + resourceClassNames); + LOGGER.trace("resource={}", resourceClassNames); if (resourceClassNames != null) { launchAgentFromClassInfo(resourceClassNames); return; @@ -440,10 +441,10 @@ public class AgentShell implements IAgentShell, Daemon { private void launchAgentFromTypeInfo() throws ConfigurationException { String typeInfo = getProperty(null, "type"); if (typeInfo == null) { - s_logger.error("Unable to retrieve the type"); + LOGGER.error("Unable to retrieve the type"); throw new ConfigurationException("Unable to retrieve the type of this agent."); } - s_logger.trace("Launching agent based on type=" + typeInfo); + LOGGER.trace("Launching agent based on type={}", typeInfo); } public void launchNewAgent(ServerResource resource) throws ConfigurationException { @@ -477,17 +478,17 @@ public class AgentShell implements IAgentShell, Daemon { } if (ipv6disabled) { - s_logger.info("Preferring IPv4 address family for agent connection"); + LOGGER.info("Preferring IPv4 address family for agent connection"); System.setProperty("java.net.preferIPv4Stack", "true"); if (ipv6prefer) { - s_logger.info("ipv6prefer is set to true, but ipv6disabled is false. Not preferring IPv6 for agent connection"); + LOGGER.info("ipv6prefer is set to true, but ipv6disabled is false. Not preferring IPv6 for agent connection"); } } else { if (ipv6prefer) { - s_logger.info("Preferring IPv6 address family for agent connection"); + LOGGER.info("Preferring IPv6 address family for agent connection"); System.setProperty("java.net.preferIPv6Addresses", "true"); } else { - s_logger.info("Using default Java settings for IPv6 preference for agent connection"); + LOGGER.info("Using default Java settings for IPv6 preference for agent connection"); } } @@ -505,7 +506,7 @@ public class AgentShell implements IAgentShell, Daemon { String pidDir = getProperty(null, "piddir"); final String run = "agent." + instance + "pid"; - s_logger.debug("Checking to see if " + run + " exists."); + LOGGER.debug("Checking to see if {} exists.", run); ProcessUtil.pidCheck(pidDir, run); launchAgent(); @@ -514,11 +515,11 @@ public class AgentShell implements IAgentShell, Daemon { while (!_exit) Thread.sleep(1000); } catch (InterruptedException e) { - s_logger.debug("[ignored] AgentShell was interrupted."); + LOGGER.debug("[ignored] AgentShell was interrupted."); } } catch (final Exception e) { - s_logger.error("Unable to start agent: ", e); + LOGGER.error("Unable to start agent: ", e); System.exit(ExitStatus.Error.value()); } } @@ -535,7 +536,7 @@ public class AgentShell implements IAgentShell, Daemon { public static void main(String[] args) { try { - s_logger.debug("Initializing AgentShell from main"); + LOGGER.debug("Initializing AgentShell from main"); AgentShell shell = new AgentShell(); shell.init(args); shell.start(); diff --git a/agent/src/main/java/com/cloud/agent/dao/impl/PropertiesStorage.java b/agent/src/main/java/com/cloud/agent/dao/impl/PropertiesStorage.java index 87610c29f34..17e0ceeeede 100644 --- a/agent/src/main/java/com/cloud/agent/dao/impl/PropertiesStorage.java +++ b/agent/src/main/java/com/cloud/agent/dao/impl/PropertiesStorage.java @@ -24,7 +24,8 @@ import java.util.Map; import java.util.Properties; import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.dao.StorageComponent; import com.cloud.utils.PropertiesUtil; @@ -36,7 +37,7 @@ import com.cloud.utils.PropertiesUtil; * path to the properties _file | String | db/db.properties || * } **/ public class PropertiesStorage implements StorageComponent { - private static final Logger s_logger = Logger.getLogger(PropertiesStorage.class); + protected Logger logger = LogManager.getLogger(getClass()); Properties _properties = new Properties(); File _file; String _name; @@ -49,7 +50,7 @@ public class PropertiesStorage implements StorageComponent { @Override public synchronized void persist(String key, String value) { if (!loadFromFile(_file)) { - s_logger.error("Failed to load changes and then write to them"); + logger.error("Failed to load changes and then write to them"); } _properties.setProperty(key, value); FileOutputStream output = null; @@ -59,7 +60,7 @@ public class PropertiesStorage implements StorageComponent { output.flush(); output.close(); } catch (IOException e) { - s_logger.error("Uh-oh: ", e); + logger.error("Uh-oh: ", e); } finally { IOUtils.closeQuietly(output); } @@ -70,10 +71,10 @@ public class PropertiesStorage implements StorageComponent { PropertiesUtil.loadFromFile(_properties, file); _file = file; } catch (FileNotFoundException e) { - s_logger.error("How did we get here? ", e); + logger.error("How did we get here? ", e); return false; } catch (IOException e) { - s_logger.error("IOException: ", e); + logger.error("IOException: ", e); return false; } return true; @@ -92,14 +93,12 @@ public class PropertiesStorage implements StorageComponent { file = new File(path); try { if (!file.createNewFile()) { - s_logger.error(String.format("Unable to create _file: %s", file.getAbsolutePath())); + logger.error("Unable to create _file: {}", file.getAbsolutePath()); return false; } } catch (IOException e) { - s_logger.error(String.format("Unable to create file: %s", file.getAbsolutePath())); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("IOException while trying to create file: %s", file.getAbsolutePath()), e); - } + logger.error("Unable to create file: {}", file.getAbsolutePath()); + logger.debug("IOException while trying to create file: {}", file.getAbsolutePath(), e); return false; } } diff --git a/agent/src/main/java/com/cloud/agent/dhcp/DhcpProtocolParserServer.java b/agent/src/main/java/com/cloud/agent/dhcp/DhcpProtocolParserServer.java index 0ee9fd6860d..00488f94382 100644 --- a/agent/src/main/java/com/cloud/agent/dhcp/DhcpProtocolParserServer.java +++ b/agent/src/main/java/com/cloud/agent/dhcp/DhcpProtocolParserServer.java @@ -25,12 +25,13 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import org.apache.log4j.Logger; import com.cloud.utils.concurrency.NamedThreadFactory; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class DhcpProtocolParserServer extends Thread { - private static final Logger s_logger = Logger.getLogger(DhcpProtocolParserServer.class);; + protected Logger logger = LogManager.getLogger(DhcpProtocolParserServer.class);; protected ExecutorService _executor; private int dhcpServerPort = 67; private int bufferSize = 300; @@ -54,7 +55,7 @@ public class DhcpProtocolParserServer extends Thread { dhcpSocket.receive(dgp); } } catch (IOException e) { - s_logger.debug(e.getMessage()); + logger.debug(e.getMessage()); } } } diff --git a/agent/src/main/java/com/cloud/agent/mockvm/MockVmMgr.java b/agent/src/main/java/com/cloud/agent/mockvm/MockVmMgr.java index b155cb725b1..54fdde3d3d2 100644 --- a/agent/src/main/java/com/cloud/agent/mockvm/MockVmMgr.java +++ b/agent/src/main/java/com/cloud/agent/mockvm/MockVmMgr.java @@ -22,14 +22,15 @@ import java.util.Map; import java.util.Random; import java.util.Set; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine.State; public class MockVmMgr implements VmMgr { - private static final Logger s_logger = Logger.getLogger(MockVmMgr.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int DEFAULT_DOM0_MEM_MB = 128; private static final Random randSeed = new Random(); @@ -56,14 +57,14 @@ public class MockVmMgr implements VmMgr { public String startVM(String vmName, String vnetId, String gateway, String dns, String privateIP, String privateMac, String privateMask, String publicIP, String publicMac, String publicMask, int cpuCount, int cpuUtilization, long ramSize, String localPath, String vncPassword) { - if (s_logger.isInfoEnabled()) { + if (logger.isInfoEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("Start VM. name: " + vmName + ", vnet: " + vnetId + ", dns: " + dns); sb.append(", privateIP: " + privateIP + ", privateMac: " + privateMac + ", privateMask: " + privateMask); sb.append(", publicIP: " + publicIP + ", publicMac: " + publicMac + ", publicMask: " + publicMask); sb.append(", cpu count: " + cpuCount + ", cpuUtilization: " + cpuUtilization + ", ram : " + ramSize); sb.append(", localPath: " + localPath); - s_logger.info(sb.toString()); + logger.info(sb.toString()); } synchronized (this) { @@ -86,8 +87,7 @@ public class MockVmMgr implements VmMgr { @Override public String stopVM(String vmName, boolean force) { - if (s_logger.isInfoEnabled()) - s_logger.info("Stop VM. name: " + vmName); + logger.info("Stop VM. name: {}", vmName); synchronized (this) { MockVm vm = vms.get(vmName); @@ -102,8 +102,7 @@ public class MockVmMgr implements VmMgr { @Override public String rebootVM(String vmName) { - if (s_logger.isInfoEnabled()) - s_logger.info("Reboot VM. name: " + vmName); + logger.info("Reboot VM. name: {}", vmName); synchronized (this) { MockVm vm = vms.get(vmName); @@ -115,8 +114,7 @@ public class MockVmMgr implements VmMgr { @Override public boolean migrate(String vmName, String params) { - if (s_logger.isInfoEnabled()) - s_logger.info("Migrate VM. name: " + vmName); + logger.info("Migrate VM. name: {}", vmName); synchronized (this) { MockVm vm = vms.get(vmName); @@ -258,13 +256,13 @@ public class MockVmMgr implements VmMgr { vm = vms.get(vmName); if (vm == null) { if (ramSize > getHostFreeMemory()) { - s_logger.debug("host is out of memory"); + logger.debug("host is out of memory"); throw new CloudRuntimeException("Host is out of Memory"); } int vncPort = allocVncPort(); if (vncPort < 0) { - s_logger.debug("Unable to allocate VNC port"); + logger.debug("Unable to allocate VNC port"); throw new CloudRuntimeException("Unable to allocate vnc port"); } diff --git a/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java b/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java index 0e979d370f4..24a09ae2ac1 100644 --- a/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java +++ b/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java @@ -659,6 +659,14 @@ public class AgentProperties{ */ public static final Property STOP_SCRIPT_TIMEOUT = new Property<>("stop.script.timeout", 120); + /** + * Time (in seconds) to wait for scripts to complete.
+ * This is currently used only while checking if the host supports UEFI.
+ * Data type: Integer.
+ * Default value: 60 + */ + public static final Property AGENT_SCRIPT_TIMEOUT = new Property<>("agent.script.timeout", 60); + /** * Definition of VMs video model type.
* Data type: String.
@@ -687,6 +695,13 @@ public class AgentProperties{ */ public static final Property DEVELOPER = new Property<>("developer", false); + /** + * If set to "true", the agent will register for libvirt domain events, allowing for immediate updates on crashed or unexpectedly + * stopped VMs. Experimental, requires agent restart. + * Default value: false + */ + public static final Property LIBVIRT_EVENTS_ENABLED = new Property<>("libvirt.events.enabled", false); + /** * Can only be used if developer = true. This property is used to define the local bridge name and private network name.
* Data type: String.
diff --git a/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java b/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java index 602aa1efcb0..b28018fcd94 100644 --- a/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java +++ b/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java @@ -22,7 +22,8 @@ import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.converters.IntegerConverter; import org.apache.commons.beanutils.converters.LongConverter; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; /** * This class provides a facility to read the agent's properties file and get @@ -31,7 +32,7 @@ import org.apache.log4j.Logger; */ public class AgentPropertiesFileHandler { - private static final Logger logger = Logger.getLogger(AgentPropertiesFileHandler.class); + protected static Logger LOGGER = LogManager.getLogger(AgentPropertiesFileHandler.class); /** * This method reads the property in the agent.properties file. @@ -47,7 +48,7 @@ public class AgentPropertiesFileHandler { File agentPropertiesFile = PropertiesUtil.findConfigFile(KeyStoreUtils.AGENT_PROPSFILE); if (agentPropertiesFile == null) { - logger.debug(String.format("File [%s] was not found, we will use default defined values. Property [%s]: [%s].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue)); + LOGGER.debug("File [{}] was not found, we will use default defined values. Property [{}]: [{}].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue); return defaultValue; } @@ -55,7 +56,7 @@ public class AgentPropertiesFileHandler { try { String configValue = PropertiesUtil.loadFromFile(agentPropertiesFile).getProperty(name); if (StringUtils.isBlank(configValue)) { - logger.debug(String.format("Property [%s] has empty or null value. Using default value [%s].", name, defaultValue)); + LOGGER.debug("Property [{}] has empty or null value. Using default value [{}].", name, defaultValue); return defaultValue; } @@ -67,11 +68,11 @@ public class AgentPropertiesFileHandler { ConvertUtils.register(new LongConverter(defaultValue), Long.class); } - logger.debug(String.format("Property [%s] was altered. Now using the value [%s].", name, configValue)); + LOGGER.debug("Property [{}] was altered. Now using the value [{}].", name, configValue); return (T)ConvertUtils.convert(configValue, property.getTypeClass()); } catch (IOException ex) { - logger.debug(String.format("Failed to get property [%s]. Using default value [%s].", name, defaultValue), ex); + LOGGER.debug("Failed to get property [{}]. Using default value [{}].", name, defaultValue, ex); } return defaultValue; diff --git a/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java b/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java index 5412c347012..ccd0d976e58 100644 --- a/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java +++ b/agent/src/main/java/com/cloud/agent/resource/consoleproxy/ConsoleProxyResource.java @@ -34,7 +34,6 @@ import javax.naming.ConfigurationException; import com.cloud.agent.api.proxy.AllowConsoleAccessCommand; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; import com.cloud.agent.Agent.ExitStatus; import com.cloud.agent.api.AgentControlAnswer; @@ -81,7 +80,6 @@ import com.google.gson.Gson; * */ public class ConsoleProxyResource extends ServerResourceBase implements ServerResource { - static final Logger s_logger = Logger.getLogger(ConsoleProxyResource.class); private final Properties properties = new Properties(); private Thread consoleProxyMain = null; @@ -101,7 +99,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe } else if (cmd instanceof WatchConsoleProxyLoadCommand) { return execute((WatchConsoleProxyLoadCommand)cmd); } else if (cmd instanceof ReadyCommand) { - s_logger.info("Receive ReadyCommand, response with ReadyAnswer"); + logger.info("Receive ReadyCommand, response with ReadyAnswer"); return new ReadyAnswer((ReadyCommand)cmd); } else if (cmd instanceof CheckHealthCommand) { return new CheckHealthAnswer((CheckHealthCommand)cmd, true); @@ -123,13 +121,13 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe return new Answer(cmd); } catch (SecurityException | NoSuchMethodException | ClassNotFoundException | InvocationTargetException | IllegalAccessException e) { String errorMsg = "Unable to add allowed session due to: " + e.getMessage(); - s_logger.error(errorMsg, e); + logger.error(errorMsg, e); return new Answer(cmd, false, errorMsg); } } private Answer execute(StartConsoleProxyAgentHttpHandlerCommand cmd) { - s_logger.info("Invoke launchConsoleProxy() in responding to StartConsoleProxyAgentHttpHandlerCommand"); + logger.info("Invoke launchConsoleProxy() in responding to StartConsoleProxyAgentHttpHandlerCommand"); launchConsoleProxy(cmd.getKeystoreBits(), cmd.getKeystorePassword(), cmd.getEncryptorPassword(), cmd.isSourceIpCheckEnabled()); return new Answer(cmd); } @@ -140,7 +138,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe { out.write("0"); } catch (IOException e) { - s_logger.warn("Unable to disable rp_filter"); + logger.warn("Unable to disable rp_filter"); } } @@ -177,12 +175,12 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe try { is.close(); } catch (final IOException e) { - s_logger.warn("Exception when closing , console proxy address : " + proxyManagementIp); + logger.warn("Exception when closing , console proxy address : {}", proxyManagementIp); success = false; } } } catch (final IOException e) { - s_logger.warn("Unable to open console proxy command port url, console proxy address : " + proxyManagementIp); + logger.warn("Unable to open console proxy command port url, console proxy address : {}", proxyManagementIp); success = false; } @@ -227,14 +225,14 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe if (eth1Ip != null) { params.put("private.network.device", "eth1"); } else { - s_logger.info("eth1ip parameter has not been configured, assuming that we are not inside a system vm"); + logger.info("eth1ip parameter has not been configured, assuming that we are not inside a system vm"); } String eth2ip = (String)params.get("eth2ip"); if (eth2ip != null) { params.put("public.network.device", "eth2"); } else { - s_logger.info("eth2ip parameter is not found, assuming that we are not inside a system vm"); + logger.info("eth2ip parameter is not found, assuming that we are not inside a system vm"); } super.configure(name, params); @@ -262,7 +260,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe } String internalDns1 = (String) params.get("internaldns1"); if (internalDns1 == null) { - s_logger.warn("No DNS entry found during configuration of ConsoleProxy"); + logger.warn("No DNS entry found during configuration of ConsoleProxy"); } else { addRouteToInternalIpOrCidr(localGateway, eth1Ip, eth1Mask, internalDns1); } @@ -280,20 +278,19 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe disableRpFilter(); } - if (s_logger.isInfoEnabled()) - s_logger.info("Receive proxyVmId in ConsoleProxyResource configuration as " + proxyVmId); + logger.info("Receive proxyVmId in ConsoleProxyResource configuration as {}", proxyVmId); return true; } private void addRouteToInternalIpOrCidr(String localgw, String eth1ip, String eth1mask, String destIpOrCidr) { - s_logger.debug("addRouteToInternalIp: localgw=" + localgw + ", eth1ip=" + eth1ip + ", eth1mask=" + eth1mask + ",destIp=" + destIpOrCidr); + logger.debug("addRouteToInternalIp: localgw={}, eth1ip={}, eth1mask={}, destIp={}", localgw, eth1ip, eth1mask, destIpOrCidr); if (destIpOrCidr == null) { - s_logger.debug("addRouteToInternalIp: destIp is null"); + logger.debug("addRouteToInternalIp: destIp is null"); return; } if (!NetUtils.isValidIp4(destIpOrCidr) && !NetUtils.isValidIp4Cidr(destIpOrCidr)) { - s_logger.warn(" destIp is not a valid ip address or cidr destIp=" + destIpOrCidr); + logger.warn(" destIp is not a valid ip address or cidr destIp={}", destIpOrCidr); return; } boolean inSameSubnet = false; @@ -301,27 +298,27 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe if (eth1ip != null && eth1mask != null) { inSameSubnet = NetUtils.sameSubnet(eth1ip, destIpOrCidr, eth1mask); } else { - s_logger.warn("addRouteToInternalIp: unable to determine same subnet: eth1ip=" + eth1ip + ", dest ip=" + destIpOrCidr + ", eth1mask=" + eth1mask); + logger.warn("addRouteToInternalIp: unable to determine same subnet: eth1ip={}, dest ip={}, eth1mask={}", eth1ip, destIpOrCidr, eth1mask); } } else { inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr, NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask)); } if (inSameSubnet) { - s_logger.debug("addRouteToInternalIp: dest ip " + destIpOrCidr + " is in the same subnet as eth1 ip " + eth1ip); + logger.debug("addRouteToInternalIp: dest ip {} is in the same subnet as eth1 ip {}", destIpOrCidr, eth1ip); return; } - Script command = new Script("/bin/bash", s_logger); + Script command = new Script("/bin/bash", logger); command.add("-c"); command.add("ip route delete " + destIpOrCidr); command.execute(); - command = new Script("/bin/bash", s_logger); + command = new Script("/bin/bash", logger); command.add("-c"); command.add("ip route add " + destIpOrCidr + " via " + localgw); String result = command.execute(); if (result != null) { - s_logger.warn("Error in configuring route to internal ip err=" + result); + logger.warn("Error in configuring route to internal ip err={}", result); } else { - s_logger.debug("addRouteToInternalIp: added route to internal ip=" + destIpOrCidr + " via " + localgw); + logger.debug("addRouteToInternalIp: added route to internal ip={} via {}", destIpOrCidr, localgw); } } @@ -332,36 +329,36 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe private void launchConsoleProxy(final byte[] ksBits, final String ksPassword, final String encryptorPassword, final Boolean isSourceIpCheckEnabled) { final Object resource = this; - s_logger.info("Building class loader for com.cloud.consoleproxy.ConsoleProxy"); + logger.info("Building class loader for com.cloud.consoleproxy.ConsoleProxy"); if (consoleProxyMain == null) { - s_logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password=" + encryptorPassword); + logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password={}", encryptorPassword); consoleProxyMain = new Thread(new ManagedContextRunnable() { @Override protected void runInContext() { try { Class consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy"); try { - s_logger.info("Invoke startWithContext()"); + logger.info("Invoke startWithContext()"); Method method = consoleProxyClazz.getMethod("startWithContext", Properties.class, Object.class, byte[].class, String.class, String.class, Boolean.class); method.invoke(null, properties, resource, ksBits, ksPassword, encryptorPassword, isSourceIpCheckEnabled); } catch (SecurityException e) { - s_logger.error("Unable to launch console proxy due to SecurityException", e); + logger.error("Unable to launch console proxy due to SecurityException", e); System.exit(ExitStatus.Error.value()); } catch (NoSuchMethodException e) { - s_logger.error("Unable to launch console proxy due to NoSuchMethodException", e); + logger.error("Unable to launch console proxy due to NoSuchMethodException", e); System.exit(ExitStatus.Error.value()); } catch (IllegalArgumentException e) { - s_logger.error("Unable to launch console proxy due to IllegalArgumentException", e); + logger.error("Unable to launch console proxy due to IllegalArgumentException", e); System.exit(ExitStatus.Error.value()); } catch (IllegalAccessException e) { - s_logger.error("Unable to launch console proxy due to IllegalAccessException", e); + logger.error("Unable to launch console proxy due to IllegalAccessException", e); System.exit(ExitStatus.Error.value()); } catch (InvocationTargetException e) { - s_logger.error("Unable to launch console proxy due to InvocationTargetException " + e.getTargetException().toString(), e); + logger.error("Unable to launch console proxy due to InvocationTargetException {}", e.getTargetException().toString(), e); System.exit(ExitStatus.Error.value()); } } catch (final ClassNotFoundException e) { - s_logger.error("Unable to launch console proxy due to ClassNotFoundException"); + logger.error("Unable to launch console proxy due to ClassNotFoundException"); System.exit(ExitStatus.Error.value()); } } @@ -369,7 +366,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe consoleProxyMain.setDaemon(true); consoleProxyMain.start(); } else { - s_logger.info("com.cloud.consoleproxy.ConsoleProxy is already running"); + logger.info("com.cloud.consoleproxy.ConsoleProxy is already running"); try { Class consoleProxyClazz = Class.forName("com.cloud.consoleproxy.ConsoleProxy"); @@ -378,22 +375,22 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe methodSetup = consoleProxyClazz.getMethod("setIsSourceIpCheckEnabled", Boolean.class); methodSetup.invoke(null, isSourceIpCheckEnabled); } catch (SecurityException e) { - s_logger.error("Unable to launch console proxy due to SecurityException", e); + logger.error("Unable to launch console proxy due to SecurityException", e); System.exit(ExitStatus.Error.value()); } catch (NoSuchMethodException e) { - s_logger.error("Unable to launch console proxy due to NoSuchMethodException", e); + logger.error("Unable to launch console proxy due to NoSuchMethodException", e); System.exit(ExitStatus.Error.value()); } catch (IllegalArgumentException e) { - s_logger.error("Unable to launch console proxy due to IllegalArgumentException", e); + logger.error("Unable to launch console proxy due to IllegalArgumentException", e); System.exit(ExitStatus.Error.value()); } catch (IllegalAccessException e) { - s_logger.error("Unable to launch console proxy due to IllegalAccessException", e); + logger.error("Unable to launch console proxy due to IllegalAccessException", e); System.exit(ExitStatus.Error.value()); } catch (InvocationTargetException e) { - s_logger.error("Unable to launch console proxy due to InvocationTargetException " + e.getTargetException().toString(), e); + logger.error("Unable to launch console proxy due to InvocationTargetException " + e.getTargetException().toString(), e); System.exit(ExitStatus.Error.value()); } catch (final ClassNotFoundException e) { - s_logger.error("Unable to launch console proxy due to ClassNotFoundException", e); + logger.error("Unable to launch console proxy due to ClassNotFoundException", e); System.exit(ExitStatus.Error.value()); } } @@ -420,10 +417,10 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe result.setTunnelUrl(authAnswer.getTunnelUrl()); result.setTunnelSession(authAnswer.getTunnelSession()); } else { - s_logger.error("Authentication failed for vm: " + vmId + " with sid: " + sid); + logger.error("Authentication failed for vm: {} with sid: {}", vmId, sid); } } catch (AgentControlChannelException e) { - s_logger.error("Unable to send out console access authentication request due to " + e.getMessage(), e); + logger.error("Unable to send out console access authentication request due to {}", e.getMessage(), e); } return new Gson().toJson(result); @@ -433,18 +430,15 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe ConsoleProxyLoadReportCommand cmd = new ConsoleProxyLoadReportCommand(proxyVmId, gsonLoadInfo); try { getAgentControl().postRequest(cmd); - - if (s_logger.isDebugEnabled()) - s_logger.debug("Report proxy load info, proxy : " + proxyVmId + ", load: " + gsonLoadInfo); + logger.debug("Report proxy load info, proxy : {}, load: {}", proxyVmId, gsonLoadInfo); } catch (AgentControlChannelException e) { - s_logger.error("Unable to send out load info due to " + e.getMessage(), e); + logger.error("Unable to send out load info due to {}", e.getMessage(), e); } } public void ensureRoute(String address) { if (localGateway != null) { - if (s_logger.isDebugEnabled()) - s_logger.debug("Ensure route for " + address + " via " + localGateway); + logger.debug("Ensure route for {} via {}", address, localGateway); // this method won't be called in high frequency, serialize access // to script execution @@ -452,7 +446,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe try { addRouteToInternalIpOrCidr(localGateway, eth1Ip, eth1Mask, address); } catch (Throwable e) { - s_logger.warn("Unexpected exception while adding internal route to " + address, e); + logger.warn("Unexpected exception while adding internal route to {}", address, e); } } } diff --git a/agent/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/agent/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/agent/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/api/pom.xml b/api/pom.xml index 427fbd24231..32897725e0c 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT diff --git a/api/src/main/java/com/cloud/agent/api/Command.java b/api/src/main/java/com/cloud/agent/api/Command.java index c873139099c..eb979c0060b 100644 --- a/api/src/main/java/com/cloud/agent/api/Command.java +++ b/api/src/main/java/com/cloud/agent/api/Command.java @@ -20,6 +20,8 @@ import java.util.HashMap; import java.util.Map; import com.cloud.agent.api.LogLevel.Log4jLevel; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; /** * implemented by classes that extends the Command class. Command specifies @@ -27,6 +29,8 @@ import com.cloud.agent.api.LogLevel.Log4jLevel; */ public abstract class Command { + protected transient Logger logger = LogManager.getLogger(getClass()); + public static enum OnError { Continue, Stop } diff --git a/api/src/main/java/com/cloud/agent/api/LogLevel.java b/api/src/main/java/com/cloud/agent/api/LogLevel.java index a8da272f39f..136cb6d7228 100644 --- a/api/src/main/java/com/cloud/agent/api/LogLevel.java +++ b/api/src/main/java/com/cloud/agent/api/LogLevel.java @@ -23,8 +23,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; /** */ @@ -41,7 +41,7 @@ public @interface LogLevel { } public boolean enabled(Logger logger) { - return _level != Level.OFF && logger.isEnabledFor(_level); + return _level != Level.OFF && logger.isEnabled(_level); } } diff --git a/api/src/main/java/com/cloud/agent/api/storage/OVFHelper.java b/api/src/main/java/com/cloud/agent/api/storage/OVFHelper.java index d4daf0e4270..6396e3deb72 100644 --- a/api/src/main/java/com/cloud/agent/api/storage/OVFHelper.java +++ b/api/src/main/java/com/cloud/agent/api/storage/OVFHelper.java @@ -39,7 +39,8 @@ import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -63,7 +64,7 @@ import com.cloud.utils.compression.CompressionUtil; import com.cloud.utils.exception.CloudRuntimeException; public class OVFHelper { - private static final Logger s_logger = Logger.getLogger(OVFHelper.class); + protected Logger logger = LogManager.getLogger(getClass()); private final OVFParser ovfParser; @@ -118,7 +119,7 @@ public class OVFHelper { boolean password = StringUtils.isNotBlank(passStr) && passStr.equalsIgnoreCase("true"); String label = ovfParser.getChildNodeValue(node, "Label"); String description = ovfParser.getChildNodeValue(node, "Description"); - s_logger.debug("Creating OVF property index " + index + (category == null ? "" : " for category " + category) + logger.debug("Creating OVF property index " + index + (category == null ? "" : " for category " + category) + " with key = " + key); return new OVFPropertyTO(key, type, value, qualifiers, userConfigurable, label, description, password, index, category); @@ -151,7 +152,7 @@ public class OVFHelper { if (child.getNodeName().equalsIgnoreCase("Category") || child.getNodeName().endsWith(":Category")) { lastCategoryFound = child.getTextContent(); - s_logger.info("Category found " + lastCategoryFound); + logger.info("Category found " + lastCategoryFound); } else if (child.getNodeName().equalsIgnoreCase("Property") || child.getNodeName().endsWith(":Property")) { OVFPropertyTO prop = createOVFPropertyFromNode(child, propertyIndex, lastCategoryFound); @@ -249,13 +250,13 @@ public class OVFHelper { int diskNumber = 0; for (OVFVirtualHardwareItemTO diskItem : diskHardwareItems) { if (StringUtils.isBlank(diskItem.getHostResource())) { - s_logger.error("Missing disk information for hardware item " + diskItem.getElementName() + " " + diskItem.getInstanceId()); + logger.error("Missing disk information for hardware item " + diskItem.getElementName() + " " + diskItem.getInstanceId()); continue; } String diskId = extractDiskIdFromDiskHostResource(diskItem.getHostResource()); OVFDisk diskDefinition = getDiskDefinitionFromDiskId(diskId, disks); if (diskDefinition == null) { - s_logger.error("Missing disk definition for disk ID " + diskId); + logger.error("Missing disk definition for disk ID " + diskId); } OVFFile fileDefinition = getFileDefinitionFromDiskDefinition(diskDefinition._fileRef, files); DatadiskTO datadiskTO = generateDiskTO(fileDefinition, diskDefinition, ovfParentPath, diskNumber, diskItem); @@ -277,7 +278,7 @@ public class OVFHelper { if (StringUtils.isNotBlank(path)) { File f = new File(path); if (!f.exists() || f.isDirectory()) { - s_logger.error("One of the attached disk or iso does not exists " + path); + logger.error("One of the attached disk or iso does not exists " + path); throw new InternalErrorException("One of the attached disk or iso as stated on OVF does not exists " + path); } } @@ -333,8 +334,8 @@ public class OVFHelper { od._controller = getControllerType(items, od._diskId); vd.add(od); } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("found %d disk definitions",vd.size())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("found %d disk definitions",vd.size())); } return vd; } @@ -365,8 +366,8 @@ public class OVFHelper { vf.add(of); } } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("found %d file definitions in %s",vf.size(), ovfFile.getPath())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("found %d file definitions in %s",vf.size(), ovfFile.getPath())); } return vf; } @@ -461,7 +462,7 @@ public class OVFHelper { Element disk = (Element)disks.item(i); String fileRef = ovfParser.getNodeAttribute(disk, "fileRef"); if (keepfile == null) { - s_logger.info("FATAL: OVA format error"); + logger.info("FATAL: OVA format error"); } else if (keepfile.equals(fileRef)) { keepdisk = ovfParser.getNodeAttribute(disk, "diskId"); } else { @@ -505,7 +506,7 @@ public class OVFHelper { outfile.write(writer.toString()); outfile.close(); } catch (IOException | TransformerException e) { - s_logger.info("Unexpected exception caught while rewriting OVF:" + e.getMessage(), e); + logger.info("Unexpected exception caught while rewriting OVF:" + e.getMessage(), e); throw new CloudRuntimeException(e); } } @@ -521,8 +522,8 @@ public class OVFHelper { public List getNetPrerequisitesFromDocument(Document doc) throws InternalErrorException { if (doc == null) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("no document to parse; returning no prerequisite networks"); + if (logger.isTraceEnabled()) { + logger.trace("no document to parse; returning no prerequisite networks"); } return Collections.emptyList(); } @@ -539,8 +540,8 @@ public class OVFHelper { private void matchNicsToNets(Map nets, Node systemElement) { final DocumentTraversal traversal = (DocumentTraversal) systemElement; final NodeIterator iterator = traversal.createNodeIterator(systemElement, NodeFilter.SHOW_ELEMENT, null, true); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("starting out with %d network-prerequisites, parsing hardware",nets.size())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("starting out with %d network-prerequisites, parsing hardware",nets.size())); } int nicCount = 0; for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) { @@ -549,8 +550,8 @@ public class OVFHelper { nicCount++; String name = e.getTextContent(); // should be in our nets if(nets.get(name) == null) { - if(s_logger.isInfoEnabled()) { - s_logger.info(String.format("found a nic definition without a network definition byname %s, adding it to the list.", name)); + if(logger.isInfoEnabled()) { + logger.info(String.format("found a nic definition without a network definition byname %s, adding it to the list.", name)); } nets.put(name, new OVFNetworkTO()); } @@ -560,8 +561,8 @@ public class OVFHelper { } } } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("ending up with %d network-prerequisites, parsed %d nics", nets.size(), nicCount)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("ending up with %d network-prerequisites, parsed %d nics", nets.size(), nicCount)); } } @@ -584,7 +585,7 @@ public class OVFHelper { int addressOnParent = Integer.parseInt(addressOnParentStr); nic.setAddressOnParent(addressOnParent); } catch (NumberFormatException e) { - s_logger.warn("Encountered element of type \"AddressOnParent\", that could not be parse to an integer number: " + addressOnParentStr); + logger.warn("Encountered element of type \"AddressOnParent\", that could not be parse to an integer number: " + addressOnParentStr); } boolean automaticAllocation = StringUtils.isNotBlank(automaticAllocationStr) && Boolean.parseBoolean(automaticAllocationStr); @@ -596,7 +597,7 @@ public class OVFHelper { int instanceId = Integer.parseInt(instanceIdStr); nic.setInstanceID(instanceId); } catch (NumberFormatException e) { - s_logger.warn("Encountered element of type \"InstanceID\", that could not be parse to an integer number: " + instanceIdStr); + logger.warn("Encountered element of type \"InstanceID\", that could not be parse to an integer number: " + instanceIdStr); } nic.setResourceSubType(resourceSubType); @@ -608,7 +609,7 @@ public class OVFHelper { NodeList systemElements = ovfParser.getElementsFromOVFDocument(doc, "VirtualSystem"); if (systemElements.getLength() != 1) { String msg = "found " + systemElements.getLength() + " system definitions in OVA, can only handle exactly one."; - s_logger.warn(msg); + logger.warn(msg); throw new InternalErrorException(msg); } } @@ -629,8 +630,8 @@ public class OVFHelper { nets.put(networkName,network); } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("found %d networks in template", nets.size())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("found %d networks in template", nets.size())); } return nets; } @@ -770,7 +771,7 @@ public class OVFHelper { try { return Long.parseLong(value); } catch (NumberFormatException e) { - s_logger.debug("Could not parse the value: " + value + ", ignoring it"); + logger.debug("Could not parse the value: " + value + ", ignoring it"); } } return null; @@ -781,7 +782,7 @@ public class OVFHelper { try { return Integer.parseInt(value); } catch (NumberFormatException e) { - s_logger.debug("Could not parse the value: " + value + ", ignoring it"); + logger.debug("Could not parse the value: " + value + ", ignoring it"); } } return null; @@ -819,7 +820,7 @@ public class OVFHelper { try { compressedLicense = compressOVFEula(eulaLicense); } catch (IOException e) { - s_logger.error("Could not compress the license for info " + eulaInfo); + logger.error("Could not compress the license for info " + eulaInfo); continue; } OVFEulaSectionTO eula = new OVFEulaSectionTO(eulaInfo, compressedLicense, eulaIndex); diff --git a/api/src/main/java/com/cloud/agent/api/storage/OVFParser.java b/api/src/main/java/com/cloud/agent/api/storage/OVFParser.java index b66fbe418d7..38f478d63cf 100644 --- a/api/src/main/java/com/cloud/agent/api/storage/OVFParser.java +++ b/api/src/main/java/com/cloud/agent/api/storage/OVFParser.java @@ -27,7 +27,8 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -36,7 +37,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class OVFParser { - private static final Logger s_logger = Logger.getLogger(OVFParser.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String DEFAULT_OVF_SCHEMA = "http://schemas.dmtf.org/ovf/envelope/1"; private static final String VMW_SCHEMA = "http://www.vmware.com/schema/ovf"; @@ -53,7 +54,7 @@ public class OVFParser { documentBuilderFactory.setNamespaceAware(true); documentBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { - s_logger.error("Cannot start the OVF parser: " + e.getMessage(), e); + logger.error("Cannot start the OVF parser: " + e.getMessage(), e); } } @@ -69,7 +70,7 @@ public class OVFParser { try { return documentBuilder.parse(new File(ovfFilePath)); } catch (SAXException | IOException e) { - s_logger.error("Error parsing " + ovfFilePath + " " + e.getMessage(), e); + logger.error("Error parsing " + ovfFilePath + " " + e.getMessage(), e); return null; } } diff --git a/api/src/main/java/com/cloud/agent/api/to/NicTO.java b/api/src/main/java/com/cloud/agent/api/to/NicTO.java index 3a616170d7e..573363c04fb 100644 --- a/api/src/main/java/com/cloud/agent/api/to/NicTO.java +++ b/api/src/main/java/com/cloud/agent/api/to/NicTO.java @@ -32,6 +32,9 @@ public class NicTO extends NetworkTO { Map details; boolean dpdkEnabled; Integer mtu; + Long networkId; + + String networkSegmentName; public NicTO() { super(); @@ -127,4 +130,20 @@ public class NicTO extends NetworkTO { public void setMtu(Integer mtu) { this.mtu = mtu; } + + public Long getNetworkId() { + return networkId; + } + + public void setNetworkId(Long networkId) { + this.networkId = networkId; + } + + public String getNetworkSegmentName() { + return networkSegmentName; + } + + public void setNetworkSegmentName(String networkSegmentName) { + this.networkSegmentName = networkSegmentName; + } } diff --git a/api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java b/api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java index db6cba77548..b4f4619be9a 100644 --- a/api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java +++ b/api/src/main/java/com/cloud/agent/api/to/VirtualMachineTO.java @@ -82,6 +82,7 @@ public class VirtualMachineTO { Map guestOsDetails = new HashMap(); Map extraConfig = new HashMap<>(); + Map networkIdToNetworkNameMap = new HashMap<>(); DeployAsIsInfoTO deployAsIsInfo; public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, @@ -392,6 +393,14 @@ public class VirtualMachineTO { return extraConfig; } + public Map getNetworkIdToNetworkNameMap() { + return networkIdToNetworkNameMap; + } + + public void setNetworkIdToNetworkNameMap(Map networkIdToNetworkNameMap) { + this.networkIdToNetworkNameMap = networkIdToNetworkNameMap; + } + public String getBootType() { return bootType; } diff --git a/api/src/main/java/com/cloud/capacity/Capacity.java b/api/src/main/java/com/cloud/capacity/Capacity.java index 684490a605c..a4e2c2a7f05 100644 --- a/api/src/main/java/com/cloud/capacity/Capacity.java +++ b/api/src/main/java/com/cloud/capacity/Capacity.java @@ -16,6 +16,8 @@ // under the License. package com.cloud.capacity; +import java.util.List; + import org.apache.cloudstack.api.Identity; import org.apache.cloudstack.api.InternalIdentity; @@ -35,6 +37,11 @@ public interface Capacity extends InternalIdentity, Identity { public static final short CAPACITY_TYPE_CPU_CORE = 90; + public static final List STORAGE_CAPACITY_TYPES = List.of(CAPACITY_TYPE_STORAGE, + CAPACITY_TYPE_STORAGE_ALLOCATED, + CAPACITY_TYPE_SECONDARY_STORAGE, + CAPACITY_TYPE_LOCAL_STORAGE); + public Long getHostOrPoolId(); public Long getDataCenterId(); @@ -54,4 +61,6 @@ public interface Capacity extends InternalIdentity, Identity { public Float getUsedPercentage(); public Long getAllocatedCapacity(); + + public String getTag(); } diff --git a/api/src/main/java/com/cloud/configuration/Resource.java b/api/src/main/java/com/cloud/configuration/Resource.java index 32db2fcafea..bf8fca9d905 100644 --- a/api/src/main/java/com/cloud/configuration/Resource.java +++ b/api/src/main/java/com/cloud/configuration/Resource.java @@ -85,5 +85,6 @@ public interface Resource { long getOwnerId(); ResourceOwnerType getResourceOwnerType(); + String getTag(); } diff --git a/api/src/main/java/com/cloud/deploy/DeploymentClusterPlanner.java b/api/src/main/java/com/cloud/deploy/DeploymentClusterPlanner.java index a668b79187d..2697311d2b9 100644 --- a/api/src/main/java/com/cloud/deploy/DeploymentClusterPlanner.java +++ b/api/src/main/java/com/cloud/deploy/DeploymentClusterPlanner.java @@ -57,6 +57,17 @@ public interface DeploymentClusterPlanner extends DeploymentPlanner { false, ConfigKey.Scope.Global); + static final ConfigKey VmAllocationAlgorithm = new ConfigKey<>( + String.class, + "vm.allocation.algorithm", + "Advanced", + "random", + "Order in which hosts within a cluster will be considered for VM/volume allocation. The value can be 'random', 'firstfit', 'userdispersing', 'userconcentratedpod_random', 'userconcentratedpod_firstfit', or 'firstfitleastconsumed'.", + true, + ConfigKey.Scope.Global, null, null, null, null, null, + ConfigKey.Kind.Select, + "random,firstfit,userdispersing,userconcentratedpod_random,userconcentratedpod_firstfit,firstfitleastconsumed"); + /** * This is called to determine list of possible clusters where a virtual * machine can be deployed. diff --git a/api/src/main/java/com/cloud/deploy/DeploymentPlanner.java b/api/src/main/java/com/cloud/deploy/DeploymentPlanner.java index e9f706ac1ce..354f9cfaac5 100644 --- a/api/src/main/java/com/cloud/deploy/DeploymentPlanner.java +++ b/api/src/main/java/com/cloud/deploy/DeploymentPlanner.java @@ -21,8 +21,12 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + import com.cloud.dc.DataCenter; import com.cloud.dc.Pod; +import com.cloud.exception.CloudException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientServerCapacityException; import com.cloud.exception.ResourceUnavailableException; @@ -75,7 +79,7 @@ public interface DeploymentPlanner extends Adapter { public static class ExcludeList implements Serializable { private static final long serialVersionUID = -482175549460148301L; - + protected static Logger LOGGER = LogManager.getLogger(ExcludeList.class); private Set _dcIds; private Set _podIds; private Set _clusterIds; @@ -104,13 +108,26 @@ public interface DeploymentPlanner extends Adapter { } } + private void logAvoid(Class scope, CloudException e) { + Long id = null; + if (e instanceof InsufficientCapacityException) { + id = ((InsufficientCapacityException) e).getId(); + } else if (e instanceof ResourceUnavailableException) { + id = ((ResourceUnavailableException) e).getResourceId(); + } else { + LOGGER.debug("Failed to log avoided component due to unexpected exception type [{}].", e.getMessage()); + return; + } + LOGGER.debug("Adding {} [{}] to the avoid set due to [{}].", scope.getSimpleName(), id, e.getMessage()); + } + public boolean add(InsufficientCapacityException e) { Class scope = e.getScope(); if (scope == null) { return false; } - + logAvoid(scope, e); if (Host.class.isAssignableFrom(scope)) { addHost(e.getId()); } else if (Pod.class.isAssignableFrom(scope)) { @@ -128,13 +145,14 @@ public interface DeploymentPlanner extends Adapter { return true; } + public boolean add(ResourceUnavailableException e) { Class scope = e.getScope(); if (scope == null) { return false; } - + logAvoid(scope, e); if (Host.class.isAssignableFrom(scope)) { addHost(e.getResourceId()); } else if (Pod.class.isAssignableFrom(scope)) { diff --git a/api/src/main/java/com/cloud/event/EventTypes.java b/api/src/main/java/com/cloud/event/EventTypes.java index 67fed5500ee..d385fa9ed07 100644 --- a/api/src/main/java/com/cloud/event/EventTypes.java +++ b/api/src/main/java/com/cloud/event/EventTypes.java @@ -31,6 +31,7 @@ import org.apache.cloudstack.config.Configuration; import org.apache.cloudstack.ha.HAConfig; import org.apache.cloudstack.storage.object.Bucket; import org.apache.cloudstack.storage.object.ObjectStore; +import org.apache.cloudstack.quota.QuotaTariff; import org.apache.cloudstack.usage.Usage; import org.apache.cloudstack.vm.schedule.VMSchedule; @@ -303,6 +304,7 @@ public class EventTypes { public static final String EVENT_VOLUME_CREATE = "VOLUME.CREATE"; public static final String EVENT_VOLUME_DELETE = "VOLUME.DELETE"; public static final String EVENT_VOLUME_ATTACH = "VOLUME.ATTACH"; + public static final String EVENT_VOLUME_CHECK = "VOLUME.CHECK"; public static final String EVENT_VOLUME_DETACH = "VOLUME.DETACH"; public static final String EVENT_VOLUME_EXTRACT = "VOLUME.EXTRACT"; public static final String EVENT_VOLUME_UPLOAD = "VOLUME.UPLOAD"; @@ -400,6 +402,7 @@ public class EventTypes { public static final String EVENT_IMAGE_STORE_DATA_MIGRATE = "IMAGE.STORE.MIGRATE.DATA"; public static final String EVENT_IMAGE_STORE_RESOURCES_MIGRATE = "IMAGE.STORE.MIGRATE.RESOURCES"; public static final String EVENT_IMAGE_STORE_OBJECT_DOWNLOAD = "IMAGE.STORE.OBJECT.DOWNLOAD"; + public static final String EVENT_UPDATE_IMAGE_STORE_ACCESS_STATE = "IMAGE.STORE.ACCESS.UPDATED"; // Configuration Table public static final String EVENT_CONFIGURATION_VALUE_EDIT = "CONFIGURATION.VALUE.EDIT"; @@ -727,6 +730,11 @@ public class EventTypes { public static final String EVENT_BUCKET_DELETE = "BUCKET.DELETE"; public static final String EVENT_BUCKET_UPDATE = "BUCKET.UPDATE"; + // Quota + public static final String EVENT_QUOTA_TARIFF_CREATE = "QUOTA.TARIFF.CREATE"; + public static final String EVENT_QUOTA_TARIFF_DELETE = "QUOTA.TARIFF.DELETE"; + public static final String EVENT_QUOTA_TARIFF_UPDATE = "QUOTA.TARIFF.UPDATE"; + static { // TODO: need a way to force author adding event types to declare the entity details as well, with out braking @@ -1164,6 +1172,7 @@ public class EventTypes { entityEventDetails.put(EVENT_IMAGE_STORE_DATA_MIGRATE, ImageStore.class); entityEventDetails.put(EVENT_IMAGE_STORE_OBJECT_DOWNLOAD, ImageStore.class); + entityEventDetails.put(EVENT_UPDATE_IMAGE_STORE_ACCESS_STATE, ImageStore.class); entityEventDetails.put(EVENT_LIVE_PATCH_SYSTEMVM, "SystemVMs"); //Object Store @@ -1175,6 +1184,11 @@ public class EventTypes { entityEventDetails.put(EVENT_BUCKET_CREATE, Bucket.class); entityEventDetails.put(EVENT_BUCKET_UPDATE, Bucket.class); entityEventDetails.put(EVENT_BUCKET_DELETE, Bucket.class); + + // Quota + entityEventDetails.put(EVENT_QUOTA_TARIFF_CREATE, QuotaTariff.class); + entityEventDetails.put(EVENT_QUOTA_TARIFF_DELETE, QuotaTariff.class); + entityEventDetails.put(EVENT_QUOTA_TARIFF_UPDATE, QuotaTariff.class); } public static String getEntityForEvent(String eventName) { diff --git a/api/src/main/java/com/cloud/hypervisor/Hypervisor.java b/api/src/main/java/com/cloud/hypervisor/Hypervisor.java index 2f0cc736af3..e1108b34a83 100644 --- a/api/src/main/java/com/cloud/hypervisor/Hypervisor.java +++ b/api/src/main/java/com/cloud/hypervisor/Hypervisor.java @@ -17,55 +17,45 @@ package com.cloud.hypervisor; import com.cloud.storage.Storage.ImageFormat; +import org.apache.commons.lang3.StringUtils; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Locale; import java.util.Map; +import java.util.Objects; public class Hypervisor { + public static class HypervisorType { + private static final Map hypervisorTypeMap = new LinkedHashMap<>(); + public static final HypervisorType None = new HypervisorType("None"); //for storage hosts + public static final HypervisorType XenServer = new HypervisorType("XenServer", ImageFormat.VHD); + public static final HypervisorType KVM = new HypervisorType("KVM", ImageFormat.QCOW2); + public static final HypervisorType VMware = new HypervisorType("VMware", ImageFormat.OVA); + public static final HypervisorType Hyperv = new HypervisorType("Hyperv"); + public static final HypervisorType VirtualBox = new HypervisorType("VirtualBox"); + public static final HypervisorType Parralels = new HypervisorType("Parralels"); + public static final HypervisorType BareMetal = new HypervisorType("BareMetal"); + public static final HypervisorType Simulator = new HypervisorType("Simulator"); + public static final HypervisorType Ovm = new HypervisorType("Ovm", ImageFormat.RAW); + public static final HypervisorType Ovm3 = new HypervisorType("Ovm3", ImageFormat.RAW); + public static final HypervisorType LXC = new HypervisorType("LXC"); + public static final HypervisorType Custom = new HypervisorType("Custom"); + public static final HypervisorType Any = new HypervisorType("Any"); /*If you don't care about the hypervisor type*/ + private final String name; + private final ImageFormat imageFormat; - static Map hypervisorTypeMap; - static Map supportedImageFormatMap; + public HypervisorType(String name) { + this(name, null); + } - public enum HypervisorType { - None, //for storage hosts - XenServer, - KVM, - VMware, - Hyperv, - VirtualBox, - Parralels, - BareMetal, - Simulator, - Ovm, - Ovm3, - LXC, - Custom, - - Any; /*If you don't care about the hypervisor type*/ - - static { - hypervisorTypeMap = new HashMap<>(); - hypervisorTypeMap.put("xenserver", HypervisorType.XenServer); - hypervisorTypeMap.put("kvm", HypervisorType.KVM); - hypervisorTypeMap.put("vmware", HypervisorType.VMware); - hypervisorTypeMap.put("hyperv", HypervisorType.Hyperv); - hypervisorTypeMap.put("virtualbox", HypervisorType.VirtualBox); - hypervisorTypeMap.put("parallels", HypervisorType.Parralels); - hypervisorTypeMap.put("baremetal", HypervisorType.BareMetal); - hypervisorTypeMap.put("simulator", HypervisorType.Simulator); - hypervisorTypeMap.put("ovm", HypervisorType.Ovm); - hypervisorTypeMap.put("lxc", HypervisorType.LXC); - hypervisorTypeMap.put("any", HypervisorType.Any); - hypervisorTypeMap.put("ovm3", HypervisorType.Ovm3); - hypervisorTypeMap.put("custom", HypervisorType.Custom); - - supportedImageFormatMap = new HashMap<>(); - supportedImageFormatMap.put(HypervisorType.XenServer, ImageFormat.VHD); - supportedImageFormatMap.put(HypervisorType.KVM, ImageFormat.QCOW2); - supportedImageFormatMap.put(HypervisorType.VMware, ImageFormat.OVA); - supportedImageFormatMap.put(HypervisorType.Ovm, ImageFormat.RAW); - supportedImageFormatMap.put(HypervisorType.Ovm3, ImageFormat.RAW); + public HypervisorType(String name, ImageFormat imageFormat) { + this.name = name; + this.imageFormat = imageFormat; + if (name.equals("Parralels")){ // typo in the original code + hypervisorTypeMap.put("parallels", this); + } else { + hypervisorTypeMap.putIfAbsent(name.toLowerCase(Locale.ROOT), this); + } } public static HypervisorType getType(String hypervisor) { @@ -75,24 +65,62 @@ public class Hypervisor { hypervisorTypeMap.getOrDefault(hypervisor.toLowerCase(Locale.ROOT), HypervisorType.None)); } + public static HypervisorType[] values() { + return hypervisorTypeMap.values().toArray(HypervisorType[]::new).clone(); + } + + public static HypervisorType valueOf(String name) { + if (StringUtils.isBlank(name)) { + return null; + } + + HypervisorType hypervisorType = hypervisorTypeMap.get(name.toLowerCase(Locale.ROOT)); + if (hypervisorType == null) { + throw new IllegalArgumentException("HypervisorType '" + name + "' not found"); + } + return hypervisorType; + } + /** * Returns the display name of a hypervisor type in case the custom hypervisor is used, * using the 'hypervisor.custom.display.name' setting. Otherwise, returns hypervisor name */ public String getHypervisorDisplayName() { - return !Hypervisor.HypervisorType.Custom.equals(this) ? - this.toString() : - HypervisorGuru.HypervisorCustomDisplayName.value(); + return HypervisorType.Custom.equals(this) ? HypervisorGuru.HypervisorCustomDisplayName.value() : name; } /** * This method really needs to be part of the properties of the hypervisor type itself. * - * @param hyperType * @return */ - public static ImageFormat getSupportedImageFormat(HypervisorType hyperType) { - return supportedImageFormatMap.getOrDefault(hyperType, null); + public ImageFormat getSupportedImageFormat() { + return imageFormat; + } + + public String name() { + return name; + } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } else if (o == null || getClass() != o.getClass()) { + return false; + } + HypervisorType that = (HypervisorType) o; + return Objects.equals(name, that.name); + } + + @Override + public String toString() { + return name; } } diff --git a/api/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterHelper.java b/api/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterHelper.java index e445e50f82c..e160227749d 100644 --- a/api/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterHelper.java +++ b/api/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterHelper.java @@ -22,4 +22,5 @@ import org.apache.cloudstack.acl.ControlledEntity; public interface KubernetesClusterHelper extends Adapter { ControlledEntity findByUuid(String uuid); + ControlledEntity findByVmId(long vmId); } diff --git a/api/src/main/java/com/cloud/network/IpAddress.java b/api/src/main/java/com/cloud/network/IpAddress.java index cf2e2f82db9..ae1af450577 100644 --- a/api/src/main/java/com/cloud/network/IpAddress.java +++ b/api/src/main/java/com/cloud/network/IpAddress.java @@ -97,4 +97,6 @@ public interface IpAddress extends ControlledEntity, Identity, InternalIdentity, void setRuleState(State ruleState); + boolean isForSystemVms(); + } diff --git a/api/src/main/java/com/cloud/network/Network.java b/api/src/main/java/com/cloud/network/Network.java index 458169c80aa..3b13ef7bd9c 100644 --- a/api/src/main/java/com/cloud/network/Network.java +++ b/api/src/main/java/com/cloud/network/Network.java @@ -205,6 +205,8 @@ public interface Network extends ControlledEntity, StateObject, I //Add Tungsten Fabric provider public static final Provider Tungsten = new Provider("Tungsten", false); + public static final Provider Nsx = new Provider("Nsx", false); + private final String name; private final boolean isExternal; @@ -427,6 +429,8 @@ public interface Network extends ControlledEntity, StateObject, I long getDataCenterId(); + long getAccountId(); + long getNetworkOfferingId(); @Override diff --git a/api/src/main/java/com/cloud/network/NetworkProfile.java b/api/src/main/java/com/cloud/network/NetworkProfile.java index 44853069575..1a5c80ea871 100644 --- a/api/src/main/java/com/cloud/network/NetworkProfile.java +++ b/api/src/main/java/com/cloud/network/NetworkProfile.java @@ -22,10 +22,8 @@ import java.util.Date; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.Mode; import com.cloud.network.Networks.TrafficType; -import org.apache.log4j.Logger; public class NetworkProfile implements Network { - static final Logger s_logger = Logger.getLogger(NetworkProfile.class); private final long id; private final String uuid; private final long dataCenterId; diff --git a/api/src/main/java/com/cloud/network/NetworkService.java b/api/src/main/java/com/cloud/network/NetworkService.java index 82d229da459..51799e25cda 100644 --- a/api/src/main/java/com/cloud/network/NetworkService.java +++ b/api/src/main/java/com/cloud/network/NetworkService.java @@ -19,6 +19,7 @@ package com.cloud.network; import java.util.List; import java.util.Map; +import com.cloud.dc.DataCenter; import org.apache.cloudstack.api.command.admin.address.ReleasePodIpCmdByAdmin; import org.apache.cloudstack.api.command.admin.network.DedicateGuestVlanRangeCmd; import org.apache.cloudstack.api.command.admin.network.ListDedicatedGuestVlanRangesCmd; @@ -55,6 +56,7 @@ import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.Nic; import com.cloud.vm.NicSecondaryIp; +import org.apache.cloudstack.network.element.InternalLoadBalancerElementService; /** * The NetworkService interface is the "public" api to entities that make requests to the orchestration engine @@ -87,6 +89,8 @@ public interface NetworkService { IpAddress reserveIpAddress(Account account, Boolean displayIp, Long ipAddressId) throws ResourceAllocationException; + IpAddress reserveIpAddressWithVlanDetail(Account account, DataCenter zone, Boolean displayIp, String vlanDetailKey) throws ResourceAllocationException; + boolean releaseReservedIpAddress(long ipAddressId) throws InsufficientAddressCapacityException; boolean releaseIpAddress(long ipAddressId) throws InsufficientAddressCapacityException; @@ -254,4 +258,9 @@ public interface NetworkService { PublicIpQuarantine updatePublicIpAddressInQuarantine(UpdateQuarantinedIpCmd cmd); void removePublicIpAddressFromQuarantine(RemoveQuarantinedIpCmd cmd); + + InternalLoadBalancerElementService getInternalLoadBalancerElementByType(VirtualRouterProvider.Type type); + InternalLoadBalancerElementService getInternalLoadBalancerElementByNetworkServiceProviderId(long networkProviderId); + InternalLoadBalancerElementService getInternalLoadBalancerElementById(long providerId); + List getInternalLoadBalancerElements(); } diff --git a/api/src/main/java/com/cloud/network/Networks.java b/api/src/main/java/com/cloud/network/Networks.java index aeed5d4aec6..dfa0ddb84ca 100644 --- a/api/src/main/java/com/cloud/network/Networks.java +++ b/api/src/main/java/com/cloud/network/Networks.java @@ -128,7 +128,8 @@ public class Networks { }, UnDecided(null, null), OpenDaylight("opendaylight", String.class), - TUNGSTEN("tf", String.class); + TUNGSTEN("tf", String.class), + NSX("nsx", String.class); private final String scheme; private final Class type; diff --git a/api/src/main/java/com/cloud/network/PublicIpQuarantine.java b/api/src/main/java/com/cloud/network/PublicIpQuarantine.java index d1ec98afe46..625a1bbbe50 100644 --- a/api/src/main/java/com/cloud/network/PublicIpQuarantine.java +++ b/api/src/main/java/com/cloud/network/PublicIpQuarantine.java @@ -30,6 +30,8 @@ public interface PublicIpQuarantine extends InternalIdentity, Identity { String getRemovalReason(); + Long getRemoverAccountId(); + Date getRemoved(); Date getCreated(); diff --git a/api/src/main/java/com/cloud/network/VirtualRouterProvider.java b/api/src/main/java/com/cloud/network/VirtualRouterProvider.java index aca526b1832..98410ca09f8 100644 --- a/api/src/main/java/com/cloud/network/VirtualRouterProvider.java +++ b/api/src/main/java/com/cloud/network/VirtualRouterProvider.java @@ -21,7 +21,7 @@ import org.apache.cloudstack.api.InternalIdentity; public interface VirtualRouterProvider extends InternalIdentity, Identity { public enum Type { - VirtualRouter, ElasticLoadBalancerVm, VPCVirtualRouter, InternalLbVm, NetScalerVm + VirtualRouter, ElasticLoadBalancerVm, VPCVirtualRouter, InternalLbVm, NetScalerVm, Nsx } public Type getType(); diff --git a/api/src/main/java/com/cloud/network/element/NetworkACLServiceProvider.java b/api/src/main/java/com/cloud/network/element/NetworkACLServiceProvider.java index 8c3243c99f4..852a650cfcd 100644 --- a/api/src/main/java/com/cloud/network/element/NetworkACLServiceProvider.java +++ b/api/src/main/java/com/cloud/network/element/NetworkACLServiceProvider.java @@ -21,6 +21,7 @@ import java.util.List; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; import com.cloud.network.vpc.NetworkACLItem; +import com.cloud.network.vpc.Vpc; public interface NetworkACLServiceProvider extends NetworkElement { @@ -32,4 +33,6 @@ public interface NetworkACLServiceProvider extends NetworkElement { */ boolean applyNetworkACLs(Network config, List rules) throws ResourceUnavailableException; + boolean reorderAclRules(Vpc vpc, List networks, List networkACLItems); + } diff --git a/api/src/main/java/com/cloud/network/element/VpcProvider.java b/api/src/main/java/com/cloud/network/element/VpcProvider.java index 14e86195a70..6debd1fbc2d 100644 --- a/api/src/main/java/com/cloud/network/element/VpcProvider.java +++ b/api/src/main/java/com/cloud/network/element/VpcProvider.java @@ -22,6 +22,7 @@ import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.IpAddress; import com.cloud.network.vpc.NetworkACLItem; import com.cloud.network.vpc.PrivateGateway; import com.cloud.network.vpc.StaticRouteProfile; @@ -52,4 +53,6 @@ public interface VpcProvider extends NetworkElement { boolean applyStaticRoutes(Vpc vpc, List routes) throws ResourceUnavailableException; boolean applyACLItemsToPrivateGw(PrivateGateway gateway, List rules) throws ResourceUnavailableException; + + boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address); } diff --git a/api/src/main/java/com/cloud/network/guru/NetworkGuru.java b/api/src/main/java/com/cloud/network/guru/NetworkGuru.java index 52f654007f2..cbadbb18a8f 100644 --- a/api/src/main/java/com/cloud/network/guru/NetworkGuru.java +++ b/api/src/main/java/com/cloud/network/guru/NetworkGuru.java @@ -79,20 +79,24 @@ public interface NetworkGuru extends Adapter { * be used to make determination can be isolation methods, services * provided on the guest network and the service provider that's on the * guest network. - * + *

* If a network is already fully substantiated with the necessary resources * during this design phase, then the state should be set to Setup. If * the resources are not allocated at this point, the state should be set * to Allocated. * - * @param offering network offering that contains the package of services - * the end user intends to use on that network. - * @param plan where is this network being deployed. + * @param offering network offering that contains the package of services + * the end user intends to use on that network. + * @param plan where is this network being deployed. * @param userSpecified user specified parameters for this network. - * @param owner owner of this network. + * @param name + * @param vpcId + * @param owner owner of this network. * @return Network */ - Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner); + Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, String name, Long vpcId, Account owner); + + void setup(Network network, long networkId); /** * For guest networks that are in Allocated state after the design stage, diff --git a/api/src/main/java/com/cloud/network/nsx/NsxProvider.java b/api/src/main/java/com/cloud/network/nsx/NsxProvider.java new file mode 100644 index 00000000000..19cb3b4b939 --- /dev/null +++ b/api/src/main/java/com/cloud/network/nsx/NsxProvider.java @@ -0,0 +1,34 @@ +// 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.network.nsx; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +public interface NsxProvider extends InternalIdentity, Identity { + String getHostname(); + + String getPort(); + String getProviderName(); + String getUsername(); + long getZoneId(); + + String getTier0Gateway(); + String getEdgeCluster(); + + String getTransportZone(); +} diff --git a/api/src/main/java/com/cloud/network/nsx/NsxService.java b/api/src/main/java/com/cloud/network/nsx/NsxService.java new file mode 100644 index 00000000000..79ad9547c73 --- /dev/null +++ b/api/src/main/java/com/cloud/network/nsx/NsxService.java @@ -0,0 +1,26 @@ +// 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.network.nsx; + +import com.cloud.network.IpAddress; +import com.cloud.network.vpc.Vpc; + +public interface NsxService { + + boolean createVpcNetwork(Long zoneId, long accountId, long domainId, Long vpcId, String vpcName, boolean sourceNatEnabled); + boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address); +} diff --git a/api/src/main/java/com/cloud/network/vpc/VpcOffering.java b/api/src/main/java/com/cloud/network/vpc/VpcOffering.java index b4df8e38dba..3aab57d5d3d 100644 --- a/api/src/main/java/com/cloud/network/vpc/VpcOffering.java +++ b/api/src/main/java/com/cloud/network/vpc/VpcOffering.java @@ -29,6 +29,8 @@ public interface VpcOffering extends InternalIdentity, Identity { public static final String defaultVPCOfferingName = "Default VPC offering"; public static final String defaultVPCNSOfferingName = "Default VPC offering with Netscaler"; public static final String redundantVPCOfferingName = "Redundant VPC offering"; + public static final String DEFAULT_VPC_NAT_NSX_OFFERING_NAME = "VPC offering with NSX - NAT Mode"; + public static final String DEFAULT_VPC_ROUTE_NSX_OFFERING_NAME = "VPC offering with NSX - Route Mode"; /** * @@ -53,6 +55,10 @@ public interface VpcOffering extends InternalIdentity, Identity { */ boolean isDefault(); + boolean isForNsx(); + + String getNsxMode(); + /** * @return service offering id used by VPC virtual router */ diff --git a/api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java b/api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java index 5cccd6c5a82..1ce3cf8ab0e 100644 --- a/api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java +++ b/api/src/main/java/com/cloud/network/vpc/VpcProvisioningService.java @@ -36,7 +36,8 @@ public interface VpcProvisioningService { VpcOffering createVpcOffering(String name, String displayText, List supportedServices, Map> serviceProviders, Map serviceCapabilitystList, NetUtils.InternetProtocol internetProtocol, - Long serviceOfferingId, List domainIds, List zoneIds, VpcOffering.State state); + Long serviceOfferingId, Boolean forNsx, String mode, + List domainIds, List zoneIds, VpcOffering.State state); Pair,Integer> listVpcOfferings(ListVPCOfferingsCmd cmd); diff --git a/api/src/main/java/com/cloud/offering/NetworkOffering.java b/api/src/main/java/com/cloud/offering/NetworkOffering.java index 207880ea28c..cf01fbf30e2 100644 --- a/api/src/main/java/com/cloud/offering/NetworkOffering.java +++ b/api/src/main/java/com/cloud/offering/NetworkOffering.java @@ -43,6 +43,11 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity, InternalLbProvider, PublicLbProvider, servicepackageuuid, servicepackagedescription, PromiscuousMode, MacAddressChanges, ForgedTransmits, MacLearning, RelatedNetworkOffering, domainid, zoneid, pvlanType, internetProtocol } + public enum NsxMode { + NATTED, + ROUTED + } + public final static String SystemPublicNetwork = "System-Public-Network"; public final static String SystemControlNetwork = "System-Control-Network"; public final static String SystemManagementNetwork = "System-Management-Network"; @@ -52,6 +57,11 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity, public final static String DefaultSharedNetworkOfferingWithSGService = "DefaultSharedNetworkOfferingWithSGService"; public static final String DEFAULT_TUNGSTEN_SHARED_NETWORK_OFFERING_WITH_SGSERVICE = "DefaultTungstenSharedNetworkOfferingWithSGService"; + public static final String DEFAULT_NAT_NSX_OFFERING_FOR_VPC = "DefaultNATNSXNetworkOfferingForVpc"; + public static final String DEFAULT_NAT_NSX_OFFERING_FOR_VPC_WITH_ILB = "DefaultNATNSXNetworkOfferingForVpcWithInternalLB"; + public static final String DEFAULT_ROUTED_NSX_OFFERING_FOR_VPC = "DefaultRoutedNSXNetworkOfferingForVpc"; + public static final String DEFAULT_NAT_NSX_OFFERING = "DefaultNATNSXNetworkOffering"; + public static final String DEFAULT_ROUTED_NSX_OFFERING = "DefaultRoutedNSXNetworkOffering"; public final static String QuickCloudNoServices = "QuickCloudNoServices"; public final static String DefaultIsolatedNetworkOfferingWithSourceNatService = "DefaultIsolatedNetworkOfferingWithSourceNatService"; public final static String OvsIsolatedNetworkOfferingWithSourceNatService = "OvsIsolatedNetworkOfferingWithSourceNatService"; @@ -90,6 +100,10 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity, boolean isForTungsten(); + boolean isForNsx(); + + String getNsxMode(); + TrafficType getTrafficType(); boolean isSpecifyVlan(); diff --git a/api/src/main/java/com/cloud/offering/ServiceOffering.java b/api/src/main/java/com/cloud/offering/ServiceOffering.java index 278acbe231e..58c7b0dbaf9 100644 --- a/api/src/main/java/com/cloud/offering/ServiceOffering.java +++ b/api/src/main/java/com/cloud/offering/ServiceOffering.java @@ -102,7 +102,7 @@ public interface ServiceOffering extends InfrastructureEntity, InternalIdentity, boolean getDefaultUse(); - String getSystemVmType(); + String getVmType(); String getDeploymentPlanner(); diff --git a/api/src/main/java/com/cloud/server/ManagementService.java b/api/src/main/java/com/cloud/server/ManagementService.java index e87f6b362da..18f3e901cd9 100644 --- a/api/src/main/java/com/cloud/server/ManagementService.java +++ b/api/src/main/java/com/cloud/server/ManagementService.java @@ -449,10 +449,11 @@ public interface ManagementService { * this method removes the child storage pools and adds the corresponding parent datastore cluster for API response listing * * @param Long volumeId + * @param String keyword if passed, will only return storage pools that contain this keyword in the name * @return Pair, List> List of storage pools in cluster and list * of pools with enough capacity. */ - Pair, List> listStoragePoolsForMigrationOfVolume(Long volumeId); + Pair, List> listStoragePoolsForMigrationOfVolume(Long volumeId, String keyword); Pair, List> listStoragePoolsForSystemMigrationOfVolume(Long volumeId, Long newDiskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, boolean keepSourceStoragePool, boolean bypassStorageTypeCheck); diff --git a/api/src/main/java/com/cloud/storage/DataStoreRole.java b/api/src/main/java/com/cloud/storage/DataStoreRole.java index 185e370159c..d9af495ab00 100644 --- a/api/src/main/java/com/cloud/storage/DataStoreRole.java +++ b/api/src/main/java/com/cloud/storage/DataStoreRole.java @@ -20,6 +20,7 @@ package com.cloud.storage; import com.cloud.utils.exception.CloudRuntimeException; + public enum DataStoreRole { Primary("primary"), Image("image"), ImageCache("imagecache"), Backup("backup"), Object("object"); diff --git a/api/src/main/java/com/cloud/storage/Storage.java b/api/src/main/java/com/cloud/storage/Storage.java index 8a2ec1a8905..c997f5e1dbf 100644 --- a/api/src/main/java/com/cloud/storage/Storage.java +++ b/api/src/main/java/com/cloud/storage/Storage.java @@ -16,10 +16,14 @@ // under the License. package com.cloud.storage; -import org.apache.commons.lang.NotImplementedException; - import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; +import java.util.Objects; + +import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang3.StringUtils; public class Storage { public static enum ImageFormat { @@ -135,37 +139,72 @@ public class Storage { ISODISK /* Template corresponding to a iso (non root disk) present in an OVA */ } - public static enum StoragePoolType { - Filesystem(false, true, true), // local directory - NetworkFilesystem(true, true, true), // NFS - IscsiLUN(true, false, false), // shared LUN, with a clusterfs overlay - Iscsi(true, false, false), // for e.g., ZFS Comstar - ISO(false, false, false), // for iso image - LVM(false, false, false), // XenServer local LVM SR - CLVM(true, false, false), - RBD(true, true, false), // http://libvirt.org/storage.html#StorageBackendRBD - SharedMountPoint(true, false, true), - VMFS(true, true, false), // VMware VMFS storage - PreSetup(true, true, false), // for XenServer, Storage Pool is set up by customers. - EXT(false, true, false), // XenServer local EXT SR - OCFS2(true, false, false), - SMB(true, false, false), - Gluster(true, false, false), - PowerFlex(true, true, true), // Dell EMC PowerFlex/ScaleIO (formerly VxFlexOS) - ManagedNFS(true, false, false), - Linstor(true, true, false), - DatastoreCluster(true, true, false), // for VMware, to abstract pool of clusters - StorPool(true, true, true), - FiberChannel(true, true, false); // Fiber Channel Pool for KVM hypervisors is used to find the volume by WWN value (/dev/disk/by-id/wwn-) + /** + * StoragePoolTypes carry some details about the format and capabilities of a storage pool. While not necessarily a + * 1:1 with PrimaryDataStoreDriver (and for KVM agent, KVMStoragePool and StorageAdaptor) implementations, it is + * often used to decide which storage plugin or storage command to call, so it may be necessary for new storage + * plugins to add a StoragePoolType. This can be done by adding it below, or by creating a new public static final + * instance of StoragePoolType in the plugin itself, which registers it with the map. + * + * Note that if the StoragePoolType is for KVM and defined in plugin code rather than below, care must be taken to + * ensure this is available on the agent side as well. This is best done by defining the StoragePoolType in a common + * package available on both management server and agent plugin jars. + */ + public static class StoragePoolType { + private static final Map map = new LinkedHashMap<>(); + public static final StoragePoolType Filesystem = new StoragePoolType("Filesystem", false, true, true); + public static final StoragePoolType NetworkFilesystem = new StoragePoolType("NetworkFilesystem", true, true, true); + public static final StoragePoolType IscsiLUN = new StoragePoolType("IscsiLUN", true, false, false); + public static final StoragePoolType Iscsi = new StoragePoolType("Iscsi", true, false, false); + public static final StoragePoolType ISO = new StoragePoolType("ISO", false, false, false); + public static final StoragePoolType LVM = new StoragePoolType("LVM", false, false, false); + public static final StoragePoolType CLVM = new StoragePoolType("CLVM", true, false, false); + public static final StoragePoolType RBD = new StoragePoolType("RBD", true, true, false); + public static final StoragePoolType SharedMountPoint = new StoragePoolType("SharedMountPoint", true, true, true); + public static final StoragePoolType VMFS = new StoragePoolType("VMFS", true, true, false); + public static final StoragePoolType PreSetup = new StoragePoolType("PreSetup", true, true, false); + public static final StoragePoolType EXT = new StoragePoolType("EXT", false, true, false); + public static final StoragePoolType OCFS2 = new StoragePoolType("OCFS2", true, false, false); + public static final StoragePoolType SMB = new StoragePoolType("SMB", true, false, false); + public static final StoragePoolType Gluster = new StoragePoolType("Gluster", true, false, false); + public static final StoragePoolType PowerFlex = new StoragePoolType("PowerFlex", true, true, true); + public static final StoragePoolType ManagedNFS = new StoragePoolType("ManagedNFS", true, false, false); + public static final StoragePoolType Linstor = new StoragePoolType("Linstor", true, true, false); + public static final StoragePoolType DatastoreCluster = new StoragePoolType("DatastoreCluster", true, true, false); + public static final StoragePoolType StorPool = new StoragePoolType("StorPool", true,true,true); + public static final StoragePoolType FiberChannel = new StoragePoolType("FiberChannel", true,true,false); + + + private final String name; private final boolean shared; - private final boolean overprovisioning; + private final boolean overProvisioning; private final boolean encryption; - StoragePoolType(boolean shared, boolean overprovisioning, boolean encryption) { + /** + * New StoragePoolType, set the name to check with it in Dao (Note: Do not register it into the map of pool types). + * @param name name of the StoragePoolType. + */ + public StoragePoolType(String name) { + this.name = name; + this.shared = false; + this.overProvisioning = false; + this.encryption = false; + } + + /** + * Define a new StoragePoolType, and register it into the map of pool types known to the management server. + * @param name Simple unique name of the StoragePoolType. + * @param shared Storage pool is shared/accessible to multiple hypervisors + * @param overProvisioning Storage pool supports overProvisioning + * @param encryption Storage pool supports encrypted volumes + */ + public StoragePoolType(String name, boolean shared, boolean overProvisioning, boolean encryption) { + this.name = name; this.shared = shared; - this.overprovisioning = overprovisioning; + this.overProvisioning = overProvisioning; this.encryption = encryption; + addStoragePoolType(this); } public boolean isShared() { @@ -173,14 +212,58 @@ public class Storage { } public boolean supportsOverProvisioning() { - return overprovisioning; + return overProvisioning; } - public boolean supportsEncryption() { return encryption; } + public boolean supportsEncryption() { + return encryption; + } + + private static void addStoragePoolType(StoragePoolType storagePoolType) { + map.putIfAbsent(storagePoolType.name, storagePoolType); + } + + public static StoragePoolType[] values() { + return map.values().toArray(StoragePoolType[]::new).clone(); + } + + public static StoragePoolType valueOf(String name) { + if (StringUtils.isBlank(name)) { + return null; + } + + StoragePoolType storage = map.get(name); + if (storage == null) { + throw new IllegalArgumentException("StoragePoolType '" + name + "' not found"); + } + return storage; + } + + @Override + public String toString() { + return name; + } + + public String name() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + StoragePoolType that = (StoragePoolType) o; + return Objects.equals(name, that.name); + } + + @Override + public int hashCode() { + return Objects.hash(name); + } } public static List getNonSharedStoragePoolTypes() { - List nonSharedStoragePoolTypes = new ArrayList(); + List nonSharedStoragePoolTypes = new ArrayList<>(); for (StoragePoolType storagePoolType : StoragePoolType.values()) { if (!storagePoolType.isShared()) { nonSharedStoragePoolTypes.add(storagePoolType); diff --git a/api/src/main/java/com/cloud/storage/Volume.java b/api/src/main/java/com/cloud/storage/Volume.java index 4a14197bd30..40c5660b2df 100644 --- a/api/src/main/java/com/cloud/storage/Volume.java +++ b/api/src/main/java/com/cloud/storage/Volume.java @@ -30,6 +30,8 @@ import com.cloud.utils.fsm.StateObject; public interface Volume extends ControlledEntity, Identity, InternalIdentity, BasedOn, StateObject, Displayable { + static final long DISK_OFFERING_SUITABILITY_CHECK_VOLUME_ID = -1; + // Managed storage volume parameters (specified in the compute/disk offering for PowerFlex) String BANDWIDTH_LIMIT_IN_MBPS = "bandwidthLimitInMbps"; String IOPS_LIMIT = "iopsLimit"; @@ -39,30 +41,38 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba }; enum State { - Allocated("The volume is allocated but has not been created yet."), - Creating("The volume is being created. getPoolId() should reflect the pool where it is being created."), - Ready("The volume is ready to be used."), - Migrating("The volume is migrating to other storage pool"), - Snapshotting("There is a snapshot created on this volume, not backed up to secondary storage yet"), - RevertSnapshotting("There is a snapshot created on this volume, the volume is being reverting from snapshot"), - Resizing("The volume is being resized"), - Expunging("The volume is being expunging"), - Expunged("The volume has been expunged, and can no longer be recovered"), - Destroy("The volume is destroyed, and can be recovered."), - Destroying("The volume is destroying, and can't be recovered."), - UploadOp("The volume upload operation is in progress or in short the volume is on secondary storage"), - Copying("Volume is copying from image store to primary, in case it's an uploaded volume"), - Uploaded("Volume is uploaded"), - NotUploaded("The volume entry is just created in DB, not yet uploaded"), - UploadInProgress("Volume upload is in progress"), - UploadError("Volume upload encountered some error"), - UploadAbandoned("Volume upload is abandoned since the upload was never initiated within a specified time"), - Attaching("The volume is attaching to a VM from Ready state."), - Restoring("The volume is being restored from backup."); + Allocated(false, "The volume is allocated but has not been created yet."), + Creating(true, "The volume is being created. getPoolId() should reflect the pool where it is being created."), + Ready(false, "The volume is ready to be used."), + Migrating(true, "The volume is migrating to other storage pool"), + Snapshotting(true, "There is a snapshot created on this volume, not backed up to secondary storage yet"), + RevertSnapshotting(true, "There is a snapshot created on this volume, the volume is being reverting from snapshot"), + Resizing(true, "The volume is being resized"), + Expunging(true, "The volume is being expunging"), + Expunged(false, "The volume has been expunged, and can no longer be recovered"), + Destroy(false, "The volume is destroyed, and can be recovered."), + Destroying(false, "The volume is destroying, and can't be recovered."), + UploadOp(true, "The volume upload operation is in progress or in short the volume is on secondary storage"), + Copying(true, "Volume is copying from image store to primary, in case it's an uploaded volume"), + Uploaded(false, "Volume is uploaded"), + NotUploaded(true, "The volume entry is just created in DB, not yet uploaded"), + UploadInProgress(true, "Volume upload is in progress"), + UploadError(false, "Volume upload encountered some error"), + UploadAbandoned(false, "Volume upload is abandoned since the upload was never initiated within a specified time"), + Attaching(true, "The volume is attaching to a VM from Ready state."), + Restoring(true, "The volume is being restored from backup."); + + boolean _transitional; String _description; - private State(String description) { + /** + * Volume State + * @param transitional true for transition/non-final state, otherwise false + * @param description description of the state + */ + private State(boolean transitional, String description) { + _transitional = transitional; _description = description; } @@ -70,6 +80,10 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba return s_fsm; } + public boolean isTransitional() { + return _transitional; + } + public String getDescription() { return _description; } diff --git a/api/src/main/java/com/cloud/storage/VolumeApiService.java b/api/src/main/java/com/cloud/storage/VolumeApiService.java index 8d5f7892f10..4f09702b7db 100644 --- a/api/src/main/java/com/cloud/storage/VolumeApiService.java +++ b/api/src/main/java/com/cloud/storage/VolumeApiService.java @@ -22,9 +22,11 @@ import java.net.MalformedURLException; import java.util.List; import java.util.Map; +import com.cloud.utils.Pair; import org.apache.cloudstack.api.command.user.volume.AssignVolumeCmd; import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd; import org.apache.cloudstack.api.command.user.volume.ChangeOfferingForVolumeCmd; +import org.apache.cloudstack.api.command.user.volume.CheckAndRepairVolumeCmd; import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd; import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd; import org.apache.cloudstack.api.command.user.volume.ExtractVolumeCmd; @@ -173,9 +175,13 @@ public interface VolumeApiService { boolean validateVolumeSizeInBytes(long size); + void validateDestroyVolume(Volume volume, Account caller, boolean expunge, boolean forceExpunge); + Volume changeDiskOfferingForVolume(ChangeOfferingForVolumeCmd cmd) throws ResourceAllocationException; void publishVolumeCreationUsageEvent(Volume volume); boolean stateTransitTo(Volume vol, Volume.Event event) throws NoTransitionException; + + Pair checkAndRepairVolume(CheckAndRepairVolumeCmd cmd) throws ResourceAllocationException; } diff --git a/api/src/main/java/com/cloud/user/ResourceLimitService.java b/api/src/main/java/com/cloud/user/ResourceLimitService.java index f2d87a4390d..04560df428f 100644 --- a/api/src/main/java/com/cloud/user/ResourceLimitService.java +++ b/api/src/main/java/com/cloud/user/ResourceLimitService.java @@ -18,13 +18,18 @@ package com.cloud.user; import java.util.List; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.framework.config.ConfigKey; + import com.cloud.configuration.Resource.ResourceType; import com.cloud.configuration.ResourceCount; import com.cloud.configuration.ResourceLimit; import com.cloud.domain.Domain; import com.cloud.exception.ResourceAllocationException; -import org.apache.cloudstack.framework.config.ConfigKey; -import org.apache.cloudstack.user.ResourceReservation; +import com.cloud.offering.DiskOffering; +import com.cloud.offering.ServiceOffering; +import com.cloud.template.VirtualMachineTemplate; public interface ResourceLimitService { @@ -33,7 +38,14 @@ public interface ResourceLimitService { static final ConfigKey MaxProjectSecondaryStorage = new ConfigKey<>("Project Defaults", Long.class, "max.project.secondary.storage", "400", "The default maximum secondary storage space (in GiB) that can be used for a project", false); static final ConfigKey ResourceCountCheckInterval = new ConfigKey<>("Advanced", Long.class, "resourcecount.check.interval", "300", - "Time (in seconds) to wait before running resource recalculation and fixing task. Default is 300 seconds, Setting this to 0 disables execution of the task", false); + "Time (in seconds) to wait before running resource recalculation and fixing task. Default is 300 seconds, Setting this to 0 disables execution of the task", true); + static final ConfigKey ResourceLimitHostTags = new ConfigKey<>("Advanced", String.class, "resource.limit.host.tags", "", + "A comma-separated list of tags for host resource limits", true); + static final ConfigKey ResourceLimitStorageTags = new ConfigKey<>("Advanced", String.class, "resource.limit.storage.tags", "", + "A comma-separated list of tags for storage resource limits", true); + + static final List HostTagsSupportingTypes = List.of(ResourceType.user_vm, ResourceType.cpu, ResourceType.memory); + static final List StorageTagsSupportingTypes = List.of(ResourceType.volume, ResourceType.primary_storage); /** * Updates an existing resource limit with the specified details. If a limit doesn't exist, will create one. @@ -46,22 +58,27 @@ public interface ResourceLimitService { * TODO * @param max * TODO + * @param tag + * tag for the resource type * * @return the updated/created resource limit */ - ResourceLimit updateResourceLimit(Long accountId, Long domainId, Integer resourceType, Long max); + ResourceLimit updateResourceLimit(Long accountId, Long domainId, Integer resourceType, Long max, String tag); /** * Updates an existing resource count details for the account/domain * * @param accountId - * TODO + * Id of the account for which resource recalculation to be done * @param domainId - * TODO + * Id of the domain for which resource recalculation to be doneDO * @param typeId - * TODO + * type of the resource for which recalculation to be done + * @param tag + * tag for the resource type for which recalculation to be done * @return the updated/created resource counts */ + List recalculateResourceCount(Long accountId, Long domainId, Integer typeId, String tag); List recalculateResourceCount(Long accountId, Long domainId, Integer typeId); /** @@ -77,7 +94,7 @@ public interface ResourceLimitService { * TODO * @return a list of limits that match the criteria */ - public List searchForLimits(Long id, Long accountId, Long domainId, ResourceType resourceType, Long startIndex, Long pageSizeVal); + public List searchForLimits(Long id, Long accountId, Long domainId, ResourceType resourceType, String tag, Long startIndex, Long pageSizeVal); /** * Finds the resource limit for a specified account and type. If the account has an infinite limit, will check @@ -85,9 +102,10 @@ public interface ResourceLimitService { * * @param account * @param type + * @param tag * @return resource limit */ - public long findCorrectResourceLimitForAccount(Account account, ResourceType type); + public long findCorrectResourceLimitForAccount(Account account, ResourceType type, String tag); /** * This call should be used when we have already queried resource limit for an account. This is to handle @@ -105,9 +123,10 @@ public interface ResourceLimitService { * * @param domain * @param type + * @param tag * @return resource limit */ - public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type); + public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type, String tag); /** * Finds the default resource limit for a specified type. @@ -122,9 +141,10 @@ public interface ResourceLimitService { * * @param domain * @param type + * @param tag * @return resource limit */ - public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type); + public long findCorrectResourceLimitForAccountAndDomain(Account account, Domain domain, ResourceType type, String tag); /** * Increments the resource count @@ -134,6 +154,7 @@ public interface ResourceLimitService { * @param delta */ public void incrementResourceCount(long accountId, ResourceType type, Long... delta); + public void incrementResourceCountWithTag(long accountId, ResourceType type, String tag, Long... delta); /** * Decrements the resource count @@ -143,6 +164,7 @@ public interface ResourceLimitService { * @param delta */ public void decrementResourceCount(long accountId, ResourceType type, Long... delta); + public void decrementResourceCountWithTag(long accountId, ResourceType type, String tag, Long... delta); /** * Checks if a limit has been exceeded for an account @@ -155,15 +177,17 @@ public interface ResourceLimitService { * @throws ResourceAllocationException */ public void checkResourceLimit(Account account, ResourceCount.ResourceType type, long... count) throws ResourceAllocationException; + public void checkResourceLimitWithTag(Account account, ResourceCount.ResourceType type, String tag, long... count) throws ResourceAllocationException; /** * Gets the count of resources for a resource type and account * * @param account * @param type + * @param tag * @return count of resources */ - public long getResourceCount(Account account, ResourceType type); + public long getResourceCount(Account account, ResourceType type, String tag); /** * Checks if a limit has been exceeded for an account if displayResource flag is on @@ -208,15 +232,25 @@ public interface ResourceLimitService { */ void decrementResourceCount(long accountId, ResourceType type, Boolean displayResource, Long... delta); - /** - * Adds a reservation that will be counted in subsequent calls to {count}getResourceCount{code} until {code}this[code} - * is closed. It will create a reservation record that will be counted when resource limits are checked. - * @param account The account for which the reservation is. - * @param displayResource whether this resource is shown to users at all (if not it is not counted to limits) - * @param type resource type - * @param delta amount to reserve (will not be <+ 0) - * @return a {code}AutoClosable{Code} object representing the resource the user needs - */ - ResourceReservation getReservation(Account account, Boolean displayResource, ResourceType type, Long delta) throws ResourceAllocationException; + List getResourceLimitHostTags(); + List getResourceLimitHostTags(ServiceOffering serviceOffering, VirtualMachineTemplate template); + List getResourceLimitStorageTags(); + List getResourceLimitStorageTags(DiskOffering diskOffering); + void updateTaggedResourceLimitsAndCountsForAccounts(List responses, String tag); + void updateTaggedResourceLimitsAndCountsForDomains(List responses, String tag); + void checkVolumeResourceLimit(Account owner, Boolean display, Long size, DiskOffering diskOffering) throws ResourceAllocationException; + void incrementVolumeResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering); + void decrementVolumeResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering); + void incrementVolumePrimaryStorageResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering); + void decrementVolumePrimaryStorageResourceCount(long accountId, Boolean display, Long size, DiskOffering diskOffering); + void checkVmResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template) throws ResourceAllocationException; + void incrementVmResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template); + void decrementVmResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template); + void checkVmCpuResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu) throws ResourceAllocationException; + void incrementVmCpuResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu); + void decrementVmCpuResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long cpu); + void checkVmMemoryResourceLimit(Account owner, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory) throws ResourceAllocationException; + void incrementVmMemoryResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory); + void decrementVmMemoryResourceCount(long accountId, Boolean display, ServiceOffering serviceOffering, VirtualMachineTemplate template, Long memory); } diff --git a/api/src/main/java/com/cloud/vm/NicProfile.java b/api/src/main/java/com/cloud/vm/NicProfile.java index 3f37331b1e4..d3c1daa1f5d 100644 --- a/api/src/main/java/com/cloud/vm/NicProfile.java +++ b/api/src/main/java/com/cloud/vm/NicProfile.java @@ -442,6 +442,6 @@ public class NicProfile implements InternalIdentity, Serializable { @Override public String toString() { - return String.format("NicProfile %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "vmId", "reservationId", "iPv4Address", "broadcastUri")); + return String.format("NicProfile %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "vmId", "deviceId", "broadcastUri", "reservationId", "iPv4Address")); } } diff --git a/api/src/main/java/com/cloud/vm/UserVmService.java b/api/src/main/java/com/cloud/vm/UserVmService.java index c32c099ed3a..787ed7bde37 100644 --- a/api/src/main/java/com/cloud/vm/UserVmService.java +++ b/api/src/main/java/com/cloud/vm/UserVmService.java @@ -492,7 +492,7 @@ public interface UserVmService { UserVm restoreVM(RestoreVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException; - UserVm restoreVirtualMachine(Account caller, long vmId, Long newTemplateId) throws InsufficientCapacityException, ResourceUnavailableException; + UserVm restoreVirtualMachine(Account caller, long vmId, Long newTemplateId, Long rootDiskOfferingId, boolean expunge, Map details) throws InsufficientCapacityException, ResourceUnavailableException; UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException; diff --git a/api/src/main/java/com/cloud/vm/VirtualMachineProfile.java b/api/src/main/java/com/cloud/vm/VirtualMachineProfile.java index 62519412fdb..f2ff3da8449 100644 --- a/api/src/main/java/com/cloud/vm/VirtualMachineProfile.java +++ b/api/src/main/java/com/cloud/vm/VirtualMachineProfile.java @@ -60,6 +60,8 @@ public interface VirtualMachineProfile { void setConfigDriveLocation(NetworkElement.Location location); + void setServiceOffering(ServiceOffering offering); + public static class Param { public static final Param VmPassword = new Param("VmPassword"); diff --git a/api/src/main/java/org/apache/cloudstack/acl/RoleService.java b/api/src/main/java/org/apache/cloudstack/acl/RoleService.java index 9becce643d4..07f62a7e7f8 100644 --- a/api/src/main/java/org/apache/cloudstack/acl/RoleService.java +++ b/api/src/main/java/org/apache/cloudstack/acl/RoleService.java @@ -38,7 +38,9 @@ public interface RoleService { * Moreover, we will check if the requested role is of 'Admin' type; roles with 'Admin' type should only be visible to 'root admins'. * Therefore, if a non-'root admin' user tries to search for an 'Admin' role, this method will return null. */ - Role findRole(Long id, boolean removePrivateRoles); + Role findRole(Long id, boolean ignorePrivateRoles); + + List findRoles(List ids, boolean ignorePrivateRoles); Role findRole(Long id); diff --git a/api/src/main/java/org/apache/cloudstack/acl/RoleType.java b/api/src/main/java/org/apache/cloudstack/acl/RoleType.java index ec82cd6605b..005d47c85bc 100644 --- a/api/src/main/java/org/apache/cloudstack/acl/RoleType.java +++ b/api/src/main/java/org/apache/cloudstack/acl/RoleType.java @@ -20,7 +20,8 @@ import org.apache.commons.lang3.StringUtils; import com.cloud.user.Account; import com.google.common.base.Enums; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.util.HashMap; import java.util.Map; @@ -37,7 +38,7 @@ public enum RoleType { private Account.Type accountType; private int mask; - private static Logger logger = Logger.getLogger(RoleType.class.getName()); + private static Logger LOGGER = LogManager.getLogger(RoleType.class.getName()); private static Map ACCOUNT_TYPE_MAP = new HashMap<>(); static { @@ -104,10 +105,10 @@ public enum RoleType { * */ public static Account.Type getAccountTypeByRole(final Role role, final Account.Type defautAccountType) { if (role != null) { - logger.debug(String.format("Role [%s] is not null; therefore, we use its account type [%s].", role, defautAccountType)); + LOGGER.debug(String.format("Role [%s] is not null; therefore, we use its account type [%s].", role, defautAccountType)); return role.getRoleType().getAccountType(); } - logger.debug(String.format("Role is null; therefore, we use the default account type [%s] value.", defautAccountType)); + LOGGER.debug(String.format("Role is null; therefore, we use the default account type [%s] value.", defautAccountType)); return defautAccountType; } } diff --git a/api/src/main/java/org/apache/cloudstack/alert/AlertService.java b/api/src/main/java/org/apache/cloudstack/alert/AlertService.java index 5b29426e6eb..1250284b5c2 100644 --- a/api/src/main/java/org/apache/cloudstack/alert/AlertService.java +++ b/api/src/main/java/org/apache/cloudstack/alert/AlertService.java @@ -52,7 +52,7 @@ public interface AlertService { public static final AlertType ALERT_TYPE_ROUTING = new AlertType((short)11, "ALERT.NETWORK.ROUTING", true); public static final AlertType ALERT_TYPE_STORAGE_MISC = new AlertType((short)12, "ALERT.STORAGE.MISC", true); public static final AlertType ALERT_TYPE_USAGE_SERVER = new AlertType((short)13, "ALERT.USAGE", true); - public static final AlertType ALERT_TYPE_MANAGMENT_NODE = new AlertType((short)14, "ALERT.MANAGEMENT", true); + public static final AlertType ALERT_TYPE_MANAGEMENT_NODE = new AlertType((short)14, "ALERT.MANAGEMENT", true); public static final AlertType ALERT_TYPE_DOMAIN_ROUTER_MIGRATE = new AlertType((short)15, "ALERT.NETWORK.DOMAINROUTERMIGRATE", true); public static final AlertType ALERT_TYPE_CONSOLE_PROXY_MIGRATE = new AlertType((short)16, "ALERT.SERVICE.CONSOLEPROXYMIGRATE", true); public static final AlertType ALERT_TYPE_USERVM_MIGRATE = new AlertType((short)17, "ALERT.USERVM.MIGRATE", true); @@ -91,6 +91,10 @@ public interface AlertService { return null; } + public static Set getAlertTypes() { + return defaultAlertTypes; + } + @Override public String toString() { return String.valueOf(this.getType()); diff --git a/api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java b/api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java index ed3381ae97c..083a1be00f5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/AbstractGetUploadParamsCmd.java @@ -25,11 +25,9 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.GetUploadParamsResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; public abstract class AbstractGetUploadParamsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AbstractGetUploadParamsCmd.class.getName()); @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the volume/template/iso") private String name; diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java b/api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java index affceb4e3f9..aafc039b36b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiCommandResourceType.java @@ -80,7 +80,8 @@ public enum ApiCommandResourceType { VpnCustomerGateway(com.cloud.network.Site2SiteCustomerGateway.class), ManagementServer(org.apache.cloudstack.management.ManagementServerHost.class), ObjectStore(org.apache.cloudstack.storage.object.ObjectStore.class), - Bucket(org.apache.cloudstack.storage.object.Bucket.class); + Bucket(org.apache.cloudstack.storage.object.Bucket.class), + QuotaTariff(org.apache.cloudstack.quota.QuotaTariff.class); private final Class clazz; diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java index d7767721667..f10769d7319 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java @@ -285,6 +285,7 @@ public class ApiConstants { public static final String LAST_SERVER_STOP = "lastserverstop"; public static final String LEVEL = "level"; public static final String LENGTH = "length"; + public static final String LIMIT = "limit"; public static final String LIMIT_CPU_USE = "limitcpuuse"; public static final String LIST_HOSTS = "listhosts"; public static final String LOCK = "lock"; @@ -302,6 +303,8 @@ public class ApiConstants { public static final String MIGRATIONS = "migrations"; public static final String MEMORY = "memory"; public static final String MODE = "mode"; + public static final String NSX_MODE = "nsxmode"; + public static final String NSX_ENABLED = "isnsxenabled"; public static final String NAME = "name"; public static final String METHOD_NAME = "methodname"; public static final String NETWORK_DOMAIN = "networkdomain"; @@ -321,6 +324,7 @@ public class ApiConstants { public static final String IS_DEFAULT_USE = "defaultuse"; public static final String OLD_FORMAT = "oldformat"; public static final String OP = "op"; + public static final String OPTION = "option"; public static final String OPTIONS = "options"; public static final String OS_CATEGORY_ID = "oscategoryid"; public static final String OS_CATEGORY_NAME = "oscategoryname"; @@ -378,7 +382,9 @@ public class ApiConstants { public static final String RECEIVED_BYTES = "receivedbytes"; public static final String RECONNECT = "reconnect"; public static final String RECOVER = "recover"; + public static final String REPAIR = "repair"; public static final String REQUIRES_HVM = "requireshvm"; + public static final String RESOURCE_COUNT = "resourcecount"; public static final String RESOURCE_NAME = "resourcename"; public static final String RESOURCE_TYPE = "resourcetype"; public static final String RESOURCE_TYPE_NAME = "resourcetypename"; @@ -419,8 +425,9 @@ public class ApiConstants { public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid"; public static final String SNAPSHOT_TYPE = "snapshottype"; public static final String SNAPSHOT_QUIESCEVM = "quiescevm"; - public static final String SUPPORTS_STORAGE_SNAPSHOT = "supportsstoragesnapshot"; public static final String SOURCE_ZONE_ID = "sourcezoneid"; + public static final String SUITABLE_FOR_VM = "suitableforvirtualmachine"; + public static final String SUPPORTS_STORAGE_SNAPSHOT = "supportsstoragesnapshot"; public static final String START_DATE = "startdate"; public static final String START_ID = "startid"; public static final String START_IP = "startip"; @@ -448,6 +455,7 @@ public class ApiConstants { public static final String TIMEOUT = "timeout"; public static final String TIMEZONE = "timezone"; public static final String TIMEZONEOFFSET = "timezoneoffset"; + public static final String TOTAL = "total"; public static final String TOTAL_SUBNETS = "totalsubnets"; public static final String TYPE = "type"; public static final String TRUST_STORE = "truststore"; @@ -501,6 +509,9 @@ public class ApiConstants { public static final String IS_VOLATILE = "isvolatile"; public static final String VOLUME_ID = "volumeid"; public static final String VOLUMES = "volumes"; + public static final String VOLUME_CHECK_RESULT = "volumecheckresult"; + public static final String VOLUME_REPAIR_RESULT = "volumerepairresult"; + public static final String ZONE = "zone"; public static final String ZONE_ID = "zoneid"; public static final String ZONE_NAME = "zonename"; @@ -695,6 +706,12 @@ public class ApiConstants { public static final String VSWITCH_TYPE_PUBLIC_TRAFFIC = "publicvswitchtype"; public static final String VSWITCH_NAME_GUEST_TRAFFIC = "guestvswitchname"; public static final String VSWITCH_NAME_PUBLIC_TRAFFIC = "publicvswitchname"; + + // NSX + public static final String EDGE_CLUSTER = "edgecluster"; + public static final String TIER0_GATEWAY = "tier0gateway"; + + public static final String TRANSPORT_ZONE = "transportzone"; // Tungsten-Fabric public static final String TUNGSTEN_VIRTUAL_ROUTER_UUID = "tungstenvirtualrouteruuid"; public static final String TUNGSTEN_PROVIDER_HOSTNAME = "tungstenproviderhostname"; @@ -718,6 +735,7 @@ public class ApiConstants { public static final String POLICY_UUID = "policyuuid"; public static final String RULE_UUID = "ruleuuid"; public static final String DIRECTION = "direction"; + public static final String TAGGED_RESOURCES = "taggedresources"; public static final String TAG_UUID = "taguuid"; public static final String TAG_TYPE = "tagtype"; public static final String TAG_VALUE = "tagvalue"; @@ -803,6 +821,7 @@ public class ApiConstants { public static final String IPSEC_PSK = "ipsecpsk"; public static final String GUEST_IP = "guestip"; public static final String REMOVED = "removed"; + public static final String REMOVER_ACCOUNT_ID = "removeraccountid"; public static final String REMOVAL_REASON = "removalreason"; public static final String COMPLETED = "completed"; public static final String IKE_VERSION = "ikeversion"; @@ -814,6 +833,9 @@ public class ApiConstants { public static final String FORCE_ENCAP = "forceencap"; public static final String SPLIT_CONNECTIONS = "splitconnections"; public static final String FOR_VPC = "forvpc"; + public static final String FOR_NSX = "fornsx"; + public static final String NSX_SUPPORT_LB = "nsxsupportlb"; + public static final String NSX_SUPPORTS_INTERNAL_LB = "nsxsupportsinternallb"; public static final String FOR_TUNGSTEN = "fortungsten"; public static final String SHRINK_OK = "shrinkok"; public static final String NICIRA_NVP_DEVICE_ID = "nvpdeviceid"; @@ -823,6 +845,11 @@ public class ApiConstants { public static final String NICIRA_NVP_L2_GATEWAYSERVICE_UUID = "l2gatewayserviceuuid"; public static final String NSX_LOGICAL_SWITCH = "nsxlogicalswitch"; public static final String NSX_LOGICAL_SWITCH_PORT = "nsxlogicalswitchport"; + public static final String NSX_PROVIDER_UUID = "nsxprovideruuid"; + public static final String NSX_PROVIDER_HOSTNAME = "nsxproviderhostname"; + + public static final String NSX_PROVIDER_PORT = "nsxproviderport"; + public static final String NSX_CONTROLLER_ID = "nsxcontrollerid"; public static final String S3_ACCESS_KEY = "accesskey"; public static final String S3_SECRET_KEY = "secretkey"; public static final String S3_END_POINT = "endpoint"; @@ -947,6 +974,7 @@ public class ApiConstants { public static final String SUPPORTS_REGION_LEVEL_VPC = "supportsregionLevelvpc"; public static final String SUPPORTS_STRECHED_L2_SUBNET = "supportsstrechedl2subnet"; public static final String SUPPORTS_PUBLIC_ACCESS = "supportspublicaccess"; + public static final String SUPPORTS_INTERNAL_LB = "supportsinternallb"; public static final String SUPPORTS_VM_AUTOSCALING = "supportsvmautoscaling"; public static final String REGION_LEVEL_VPC = "regionlevelvpc"; public static final String STRECHED_L2_SUBNET = "strechedl2subnet"; @@ -1065,14 +1093,13 @@ public class ApiConstants { public static final String SOURCE_NAT_IP = "sourcenatipaddress"; public static final String SOURCE_NAT_IP_ID = "sourcenatipaddressid"; public static final String HAS_RULES = "hasrules"; + public static final String NSX_DETAIL_KEY = "forNsx"; public static final String DISK_PATH = "diskpath"; public static final String IMPORT_SOURCE = "importsource"; public static final String TEMP_PATH = "temppath"; public static final String OBJECT_STORAGE = "objectstore"; - public static final String HEURISTIC_RULE = "heuristicrule"; public static final String HEURISTIC_TYPE_VALID_OPTIONS = "Valid options are: ISO, SNAPSHOT, TEMPLATE and VOLUME."; - public static final String MANAGEMENT = "management"; public static final String IS_VNF = "isvnf"; public static final String VNF_NICS = "vnfnics"; diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseAsyncCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseAsyncCmd.java index 865ec745640..6859b0a7f40 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseAsyncCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseAsyncCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api; -import org.apache.log4j.Logger; /** * queryAsyncJobResult API command. @@ -30,7 +29,6 @@ public abstract class BaseAsyncCmd extends BaseCmd { public static final String migrationSyncObject = "migration"; public static final String snapshotHostSyncObject = "snapshothost"; public static final String gslbSyncObject = "globalserverloadbalancer"; - private static final Logger s_logger = Logger.getLogger(BaseAsyncCmd.class.getName()); private Object job; diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseCmd.java index f32922819b0..b206cd011c1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseCmd.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.affinity.AffinityGroupService; import org.apache.cloudstack.alert.AlertService; import org.apache.cloudstack.annotation.AnnotationService; import org.apache.cloudstack.context.CallContext; -import org.apache.cloudstack.network.element.InternalLoadBalancerElementService; import org.apache.cloudstack.network.lb.ApplicationLoadBalancerService; import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService; import org.apache.cloudstack.query.QueryService; @@ -47,7 +46,8 @@ import org.apache.cloudstack.storage.ImageStoreService; import org.apache.cloudstack.storage.template.VnfTemplateManager; import org.apache.cloudstack.usage.UsageService; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.configuration.ConfigurationService; import com.cloud.exception.ConcurrentOperationException; @@ -95,7 +95,7 @@ import com.cloud.vm.UserVmService; import com.cloud.vm.snapshot.VMSnapshotService; public abstract class BaseCmd { - private static final Logger s_logger = Logger.getLogger(BaseCmd.class.getName()); + protected transient Logger logger = LogManager.getLogger(getClass()); public static final String RESPONSE_SUFFIX = "response"; public static final String RESPONSE_TYPE_XML = HttpUtils.RESPONSE_TYPE_XML; public static final String RESPONSE_TYPE_JSON = HttpUtils.RESPONSE_TYPE_JSON; @@ -200,8 +200,6 @@ public abstract class BaseCmd { @Inject public AffinityGroupService _affinityGroupService; @Inject - public InternalLoadBalancerElementService _internalLbElementSvc; - @Inject public InternalLoadBalancerVMService _internalLbSvc; @Inject public NetworkModel _ntwkModel; @@ -374,7 +372,7 @@ public abstract class BaseCmd { if (roleIsAllowed) { validFields.add(field); } else { - s_logger.debug("Ignoring parameter " + parameterAnnotation.name() + " as the caller is not authorized to pass it in"); + logger.debug("Ignoring parameter " + parameterAnnotation.name() + " as the caller is not authorized to pass it in"); } } @@ -419,7 +417,7 @@ public abstract class BaseCmd { if(!isDisplay) break; } catch (Exception e){ - s_logger.trace("Caught exception while checking first class entities for display property, continuing on", e); + logger.trace("Caught exception while checking first class entities for display property, continuing on", e); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java index 052d7d1e8b7..be95547a8a7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseListTemplateOrIsoPermissionsCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ResponseObject.ResponseView; import org.apache.cloudstack.api.command.ResponseViewProvider; @@ -28,7 +27,6 @@ import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; public abstract class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd implements ResponseViewProvider { - public Logger logger = getLogger(); protected static final String s_name = "listtemplatepermissionsresponse"; ///////////////////////////////////////////////////// @@ -59,9 +57,6 @@ public abstract class BaseListTemplateOrIsoPermissionsCmd extends BaseCmd implem return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked } - protected Logger getLogger() { - return Logger.getLogger(BaseListTemplateOrIsoPermissionsCmd.class); - } @Override public String getCommandName() { diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java index 08f390f1972..e3aead6881b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.response.GuestOSResponse; import org.apache.cloudstack.api.response.TemplateResponse; @@ -24,7 +23,6 @@ import java.util.Collection; import java.util.Map; public abstract class BaseUpdateTemplateOrIsoCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(BaseUpdateTemplateOrIsoCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java index 410ffefb00d..e6ee0897db0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/BaseUpdateTemplateOrIsoPermissionsCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.SuccessResponse; @@ -27,16 +26,12 @@ import org.apache.cloudstack.api.response.TemplateResponse; import com.cloud.exception.InvalidParameterValueException; public abstract class BaseUpdateTemplateOrIsoPermissionsCmd extends BaseCmd { - public Logger _logger = getLogger(); protected String _name = getResponseName(); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// - protected Logger getLogger() { - return Logger.getLogger(BaseUpdateTemplateOrIsoPermissionsCmd.class); - } protected String getResponseName() { return "updatetemplateorisopermissionsresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/InternalIdentity.java b/api/src/main/java/org/apache/cloudstack/api/InternalIdentity.java index 4149dd1c846..ce214e05b4f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/InternalIdentity.java +++ b/api/src/main/java/org/apache/cloudstack/api/InternalIdentity.java @@ -25,4 +25,18 @@ import java.io.Serializable; public interface InternalIdentity extends Serializable { long getId(); + + /* + Helper method to add conditions in joins where some column name is equal to a string value + */ + default Object setString(String str) { + return null; + } + + /* + Helper method to add conditions in joins where some column name is equal to a long value + */ + default Object setLong(Long l) { + return null; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java index 945bb956c3e..6dbc6acc59a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java @@ -21,7 +21,6 @@ import java.util.Map; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ import com.cloud.user.UserAccount; @APICommand(name = "createAccount", description = "Creates an account", responseObject = AccountResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = true, responseHasSensitiveInfo = true) public class CreateAccountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateAccountCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java index 9a0ea4e9ec0..36e22acff91 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.region.RegionService; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.user.Account; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteAccount", description = "Deletes a account, and all users associated with this account", responseObject = SuccessResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAccountCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAccountCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java index 91b0673e186..55293eca619 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.account; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -43,7 +42,6 @@ import com.cloud.user.Account; @APICommand(name = "disableAccount", description = "Disables an account", responseObject = AccountResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DisableAccountCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisableAccountCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java index cc37dc23713..da96383f134 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.account; import javax.inject.Inject; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "enableAccount", description = "Enables an account", responseObject = AccountResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class EnableAccountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(EnableAccountCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java index a430914a25a..d7847373e92 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/LockAccountCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.account; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.utils.exception.CloudRuntimeException; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class LockAccountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LockAccountCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java index 36d299bcfc8..91cbb90e4da 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java @@ -23,7 +23,6 @@ import javax.inject.Inject; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.response.RoleResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -43,7 +42,6 @@ import com.cloud.user.Account; @APICommand(name = "updateAccount", description = "Updates account information for the authenticated user", responseObject = AccountResponse.class, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateAccountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateAccountCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/CreateProjectRoleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/CreateProjectRoleCmd.java index c03e6112ea7..ed17a876b24 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/CreateProjectRoleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/CreateProjectRoleCmd.java @@ -20,6 +20,7 @@ package org.apache.cloudstack.api.command.admin.acl.project; import org.apache.cloudstack.acl.ProjectRole; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; @@ -70,4 +71,13 @@ public class CreateProjectRoleCmd extends ProjectRoleCmd { return Account.ACCOUNT_ID_SYSTEM; } + @Override + public Long getApiResourceId() { + return getProjectId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Project; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/CreateProjectRolePermissionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/CreateProjectRolePermissionCmd.java index 9b6c2e633fc..d39c2312aa9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/CreateProjectRolePermissionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/CreateProjectRolePermissionCmd.java @@ -22,6 +22,7 @@ import org.apache.cloudstack.acl.ProjectRolePermission; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.Parameter; @@ -96,4 +97,14 @@ public class CreateProjectRolePermissionCmd extends BaseRolePermissionCmd { response.setObjectName("projectrolepermission"); setResponseObject(response); } + + @Override + public Long getApiResourceId() { + return getProjectId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Project; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/DeleteProjectRoleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/DeleteProjectRoleCmd.java index 4bb460c63f7..9f8d8248958 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/DeleteProjectRoleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/DeleteProjectRoleCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.acl.ProjectRole; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; @@ -79,4 +80,14 @@ public class DeleteProjectRoleCmd extends BaseCmd { public long getEntityOwnerId() { return CallContext.current().getCallingAccountId(); } + + @Override + public Long getApiResourceId() { + return getProjectId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Project; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/DeleteProjectRolePermissionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/DeleteProjectRolePermissionCmd.java index 8b83253c869..ac68278535e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/DeleteProjectRolePermissionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/DeleteProjectRolePermissionCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.acl.ProjectRolePermission; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; @@ -80,4 +81,14 @@ public class DeleteProjectRolePermissionCmd extends BaseCmd { public long getEntityOwnerId() { return CallContext.current().getCallingAccountId(); } + + @Override + public Long getApiResourceId() { + return getProjectId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Project; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/UpdateProjectRoleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/UpdateProjectRoleCmd.java index 202daa3d49c..3bc8b3d6186 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/UpdateProjectRoleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/UpdateProjectRoleCmd.java @@ -21,6 +21,7 @@ import org.apache.cloudstack.acl.ProjectRole; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; @@ -76,4 +77,14 @@ public class UpdateProjectRoleCmd extends ProjectRoleCmd { public long getEntityOwnerId() { return 0; } + + @Override + public Long getApiResourceId() { + return getProjectId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Project; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/UpdateProjectRolePermissionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/UpdateProjectRolePermissionCmd.java index d27235e5aae..dd59310c66a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/UpdateProjectRolePermissionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/acl/project/UpdateProjectRolePermissionCmd.java @@ -26,6 +26,7 @@ import org.apache.cloudstack.acl.ProjectRolePermission; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; @@ -154,4 +155,14 @@ public class UpdateProjectRolePermissionCmd extends BaseCmd { public long getEntityOwnerId() { return CallContext.current().getCallingAccountId(); } + + @Override + public Long getApiResourceId() { + return getProjectId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Project; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AcquirePodIpCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AcquirePodIpCmdByAdmin.java index a965624a2a9..7397697bd2c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AcquirePodIpCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AcquirePodIpCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.exception.ResourceUnavailableException; @APICommand(name = "acquirePodIpAddress", description = "Allocates IP addresses in respective Pod of a Zone", responseObject = AcquirePodIpCmdResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AcquirePodIpCmdByAdmin extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AcquirePodIpCmdByAdmin.class.getName()); private static final String s_name = "acquirepodipaddress"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java index 56f41b5f58e..672691ffbd8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/AssociateIPAddrCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject.ResponseView; @@ -27,5 +26,4 @@ import org.apache.cloudstack.api.response.IPAddressResponse; @APICommand(name = "associateIpAddress", description = "Acquires and associates a public IP to an account.", responseObject = IPAddressResponse.class, responseView = ResponseView.Full, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AssociateIPAddrCmdByAdmin extends AssociateIPAddrCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmdByAdmin.class.getName()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ReleasePodIpCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ReleasePodIpCmdByAdmin.java index b6bfbcaa1e2..7d4cab6a0ac 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ReleasePodIpCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/address/ReleasePodIpCmdByAdmin.java @@ -16,7 +16,6 @@ //under the License. package org.apache.cloudstack.api.command.admin.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -31,7 +30,6 @@ import com.cloud.user.Account; @APICommand(name = "releasePodIpAddress", description = "Releases a Pod IP back to the Pod", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleasePodIpCmdByAdmin extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ReleasePodIpCmdByAdmin.class.getName()); private static final String s_name = "releasepodipresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java index 7bf9b64481b..43e70838e18 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/affinitygroup/UpdateVMAffinityGroupCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.affinitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject.ResponseView; @@ -33,5 +32,4 @@ import com.cloud.vm.VirtualMachine; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateVMAffinityGroupCmdByAdmin extends UpdateVMAffinityGroupCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVMAffinityGroupCmdByAdmin.class.getName()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/alert/GenerateAlertCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/alert/GenerateAlertCmd.java index 9446272df6e..30f3bbbec1b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/alert/GenerateAlertCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/alert/GenerateAlertCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.PodResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; @@ -35,7 +34,6 @@ import com.cloud.event.EventTypes; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GenerateAlertCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(GenerateAlertCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java index 617d1104eda..7fa66ffff1f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/CreateCounterCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "createCounter", description = "Adds metric counter for VM auto scaling", responseObject = CounterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateCounterCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateCounterCmd.class.getName()); private static final String s_name = "counterresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java index e1f7859a56b..b7b2ce5cb70 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/autoscale/DeleteCounterCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteCounter", description = "Deletes a counter for VM auto scaling", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteCounterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteCounterCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -55,7 +53,7 @@ public class DeleteCounterCmd extends BaseAsyncCmd { try { result = _autoScaleService.deleteCounter(getId()); } catch (ResourceInUseException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } @@ -63,7 +61,7 @@ public class DeleteCounterCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } else { - s_logger.warn("Failed to delete counter with Id: " + getId()); + logger.warn("Failed to delete counter with Id: " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete counter."); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java index 1cd6f4a8328..9de06715ee7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/backup/UpdateBackupOfferingCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.backup.BackupManager; import org.apache.cloudstack.backup.BackupOffering; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.user.Account; @@ -39,7 +38,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "updateBackupOffering", description = "Updates a backup offering.", responseObject = BackupOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0") public class UpdateBackupOfferingCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(UpdateBackupOfferingCmd.class.getName()); @Inject private BackupManager backupManager; @@ -100,7 +98,7 @@ public class UpdateBackupOfferingCmd extends BaseCmd { this.setResponseObject(response); } catch (CloudRuntimeException e) { ApiErrorCode paramError = e instanceof InvalidParameterValueException ? ApiErrorCode.PARAM_ERROR : ApiErrorCode.INTERNAL_ERROR; - LOGGER.error(String.format("Failed to update Backup Offering [id: %s] due to: [%s].", id, e.getMessage()), e); + logger.error(String.format("Failed to update Backup Offering [id: %s] due to: [%s].", id, e.getMessage()), e); throw new ServerApiException(paramError, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/ca/IssueCertificateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/ca/IssueCertificateCmd.java index 4c543fdb6a8..463af000f58 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/ca/IssueCertificateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/ca/IssueCertificateCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.framework.ca.Certificate; import org.apache.cloudstack.utils.security.CertUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; @@ -49,7 +48,6 @@ import com.cloud.event.EventTypes; since = "4.11.0", authorized = {RoleType.Admin}) public class IssueCertificateCmd extends BaseAsyncCmd { - private static final Logger LOG = Logger.getLogger(IssueCertificateCmd.class); @Inject @@ -132,7 +130,7 @@ public class IssueCertificateCmd extends BaseAsyncCmd { certificateResponse.setCaCertificate(CertUtils.x509CertificatesToPem(certificate.getCaCertificates())); } } catch (final IOException e) { - LOG.error("Failed to generate and convert client certificate(s) to PEM due to error: ", e); + logger.error("Failed to generate and convert client certificate(s) to PEM due to error: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to process and return client certificate"); } certificateResponse.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java index df48b2511b6..184a443d9db 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/AddClusterCmd.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.List; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "addCluster", description = "Adds a new cluster", responseObject = ClusterResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class AddClusterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddClusterCmd.class.getName()); @Parameter(name = ApiConstants.CLUSTER_NAME, type = CommandType.STRING, required = true, description = "the cluster name") @@ -226,10 +224,10 @@ public class AddClusterCmd extends BaseCmd { this.setResponseObject(response); } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ResourceInUseException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); ServerApiException e = new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); for (String proxyObj : ex.getIdProxyList()) { e.addProxyObject(proxyObj); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java index 497cef4c3ec..2b1cfe8bcb5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/DeleteClusterCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.cluster; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteCluster", description = "Deletes a cluster.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteClusterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteClusterCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java index d83330c664a..67d0678410c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/ListClustersCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.cluster; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listClusters", description = "Lists clusters.", responseObject = ClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListClustersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListClustersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java index dd527fb409a..77bb97fd39d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/cluster/UpdateClusterCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.cluster; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "updateCluster", description = "Updates an existing cluster", responseObject = ClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateClusterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddClusterCmd.class.getName()); @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = ClusterResponse.class, required = true, description = "the ID of the Cluster") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgGroupsByCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgGroupsByCmd.java index 46ab10cb2bc..d735218169d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgGroupsByCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgGroupsByCmd.java @@ -27,14 +27,12 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ConfigurationGroupResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.config.ConfigurationGroup; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; @APICommand(name = ListCfgGroupsByCmd.APINAME, description = "Lists all configuration groups (primarily used for UI).", responseObject = ConfigurationGroupResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0") public class ListCfgGroupsByCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListCfgGroupsByCmd.class.getName()); public static final String APINAME = "listConfigurationGroups"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java index 80abe5d3e8f..e365d8bc2dc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -47,7 +46,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class ListCfgsByCmd extends BaseListCmd { public static final String APINAME = "listConfigurations"; - public static final Logger s_logger = Logger.getLogger(ListCfgsByCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java index 4f5186a6df6..78fa31beeb4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListDeploymentPlannersCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.config; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseListCmd; @@ -29,7 +28,6 @@ import org.apache.cloudstack.api.response.ListResponse; @APICommand(name = "listDeploymentPlanners", description = "Lists all DeploymentPlanners available.", responseObject = DeploymentPlannersResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDeploymentPlannersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDeploymentPlannersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListHypervisorCapabilitiesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListHypervisorCapabilitiesCmd.java index 64f1c19b70c..e7cc9e0234e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListHypervisorCapabilitiesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListHypervisorCapabilitiesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.config; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.utils.Pair; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListHypervisorCapabilitiesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListHypervisorCapabilitiesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java index ada389e0093..f114b263b63 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ImageStoreResponse; import org.apache.cloudstack.framework.config.ConfigKey; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.ClusterResponse; @@ -41,7 +40,6 @@ import com.cloud.utils.Pair; @APICommand(name = "resetConfiguration", description = "Resets a configuration. The configuration will be set to default value for global setting, and removed from account_details or domain_details for Account/Domain settings", responseObject = ConfigurationResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0") public class ResetCfgCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ResetCfgCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java index 63dc51452f0..dbf478df701 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.config; import com.cloud.utils.crypt.DBEncryptionUtil; import org.apache.cloudstack.acl.RoleService; import org.apache.cloudstack.api.response.DomainResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ import com.cloud.user.Account; @APICommand(name = "updateConfiguration", description = "Updates a configuration.", responseObject = ConfigurationResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateCfgCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateCfgCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java index 02cdf1a0717..50984188bf5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateHypervisorCapabilitiesCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.config; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateHypervisorCapabilitiesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateHypervisorCapabilitiesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/diagnostics/RunDiagnosticsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/diagnostics/RunDiagnosticsCmd.java index 3d3c7410dc5..4537eb6f215 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/diagnostics/RunDiagnosticsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/diagnostics/RunDiagnosticsCmd.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.diagnostics.DiagnosticsService; import org.apache.cloudstack.diagnostics.DiagnosticsType; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InsufficientCapacityException; @@ -53,7 +52,6 @@ import com.cloud.vm.VirtualMachine; authorized = {RoleType.Admin}, since = "4.12.0.0") public class RunDiagnosticsCmd extends BaseAsyncCmd { - private static final Logger LOGGER = Logger.getLogger(RunDiagnosticsCmd.class); @Inject private DiagnosticsService diagnosticsService; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/ListTemplateDirectDownloadCertificatesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/ListTemplateDirectDownloadCertificatesCmd.java index 53b29a37f8f..145ff6ba782 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/ListTemplateDirectDownloadCertificatesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/ListTemplateDirectDownloadCertificatesCmd.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.direct.download.DirectDownloadCertificate; import org.apache.cloudstack.direct.download.DirectDownloadCertificateHostMap; import org.apache.cloudstack.direct.download.DirectDownloadManager; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -63,7 +62,6 @@ public class ListTemplateDirectDownloadCertificatesCmd extends BaseListCmd { description = "if set to true: include the hosts where the certificate is uploaded to") private Boolean listHosts; - private static final Logger LOG = Logger.getLogger(ListTemplateDirectDownloadCertificatesCmd.class); public boolean isListHosts() { return listHosts != null && listHosts; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/RevokeTemplateDirectDownloadCertificateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/RevokeTemplateDirectDownloadCertificateCmd.java index e44ebd31274..eb9031cbc58 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/RevokeTemplateDirectDownloadCertificateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/RevokeTemplateDirectDownloadCertificateCmd.java @@ -41,7 +41,6 @@ import org.apache.cloudstack.direct.download.DirectDownloadManager; import org.apache.cloudstack.direct.download.DirectDownloadManager.HostCertificateStatus; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -57,7 +56,6 @@ public class RevokeTemplateDirectDownloadCertificateCmd extends BaseCmd { @Inject DirectDownloadManager directDownloadManager; - private static final Logger LOG = Logger.getLogger(RevokeTemplateDirectDownloadCertificateCmd.class); @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DirectDownloadCertificateResponse.class, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/UploadTemplateDirectDownloadCertificateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/UploadTemplateDirectDownloadCertificateCmd.java index 0fa1797c7fe..c5c102be56d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/UploadTemplateDirectDownloadCertificateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/direct/download/UploadTemplateDirectDownloadCertificateCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.direct.download.DirectDownloadCertificate; import org.apache.cloudstack.direct.download.DirectDownloadManager; import org.apache.cloudstack.direct.download.DirectDownloadManager.HostCertificateStatus; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -49,7 +48,6 @@ public class UploadTemplateDirectDownloadCertificateCmd extends BaseCmd { @Inject DirectDownloadManager directDownloadManager; - private static final Logger LOG = Logger.getLogger(UploadTemplateDirectDownloadCertificateCmd.class); @Parameter(name = ApiConstants.CERTIFICATE, type = BaseCmd.CommandType.STRING, required = true, length = 65535, description = "SSL certificate") @@ -97,7 +95,7 @@ public class UploadTemplateDirectDownloadCertificateCmd extends BaseCmd { } try { - LOG.debug("Uploading certificate " + name + " to agents for Direct Download"); + logger.debug("Uploading certificate " + name + " to agents for Direct Download"); Pair> uploadStatus = directDownloadManager.uploadCertificateToHosts(certificate, name, hypervisor, zoneId, hostId); DirectDownloadCertificate certificate = uploadStatus.first(); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java index f6e09695f88..c7f06920bb8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/CreateDomainCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.domain; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = { RoleType.Admin, RoleType.DomainAdmin }) public class CreateDomainCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateDomainCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java index e0783b63098..db3bae25e39 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.region.RegionService; -import org.apache.log4j.Logger; import com.cloud.domain.Domain; import com.cloud.event.EventTypes; @@ -40,7 +39,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = { RoleType.Admin, RoleType.DomainAdmin }) public class DeleteDomainCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteDomainCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainChildrenCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainChildrenCmd.java index 72614627f31..8514bb6dda5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainChildrenCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainChildrenCmd.java @@ -22,7 +22,6 @@ import java.util.List; import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceTag; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listDomainChildren", description = "Lists all children domains belonging to a specified domain", responseObject = DomainResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDomainChildrenCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDomainChildrenCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java index 8b6661f27ff..b91e56dcaef 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmd.java @@ -20,11 +20,6 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.List; -import com.cloud.server.ResourceIcon; -import com.cloud.server.ResourceTag; -import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants.DomainDetails; @@ -34,14 +29,17 @@ import org.apache.cloudstack.api.ResponseObject.ResponseView; import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.ResourceIconResponse; +import org.apache.commons.collections.CollectionUtils; import com.cloud.domain.Domain; import com.cloud.exception.InvalidParameterValueException; +import com.cloud.server.ResourceIcon; +import com.cloud.server.ResourceTag; @APICommand(name = "listDomains", description = "Lists domains and provides detailed information for listed domains", responseObject = DomainResponse.class, responseView = ResponseView.Restricted, entityType = {Domain.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDomainsCmd extends BaseListCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListDomainsCmd.class.getName()); private static final String s_name = "listdomainsresponse"; @@ -73,6 +71,9 @@ public class ListDomainsCmd extends BaseListCmd implements UserCmd { description = "flag to display the resource icon for domains") private Boolean showIcon; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for resource type to return usage", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -112,10 +113,14 @@ public class ListDomainsCmd extends BaseListCmd implements UserCmd { return dv; } - public Boolean getShowIcon() { + public boolean getShowIcon() { return showIcon != null ? showIcon : false; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -130,12 +135,17 @@ public class ListDomainsCmd extends BaseListCmd implements UserCmd { ListResponse response = _queryService.searchForDomains(this); response.setResponseName(getCommandName()); this.setResponseObject(response); - if (response != null && response.getCount() > 0 && getShowIcon()) { - updateDomainResponse(response.getResponses()); - } + updateDomainResponse(response.getResponses()); } - private void updateDomainResponse(List response) { + protected void updateDomainResponse(List response) { + if (CollectionUtils.isEmpty(response)) { + return; + } + _resourceLimitService.updateTaggedResourceLimitsAndCountsForDomains(response, getTag()); + if (!getShowIcon()) { + return; + } for (DomainResponse domainResponse : response) { ResourceIcon resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Domain, domainResponse.getId()); if (resourceIcon == null) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java index db4030da772..353cb852bfd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.domain; import javax.inject.Inject; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "updateDomain", description = "Updates a domain with a new name", responseObject = DomainResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateDomainCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateDomainCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java index 0ad50071287..b854e8389c4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.guest; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ import java.util.Map; @APICommand(name = "addGuestOs", description = "Add a new guest OS type", responseObject = GuestOSResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddGuestOsCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddGuestOsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java index 0ddd21994e3..3fdfebb54bf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/AddGuestOsMappingCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.guest; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "addGuestOsMapping", description = "Adds a guest OS name to hypervisor OS name mapping", responseObject = GuestOsMappingResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddGuestOsMappingCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddGuestOsMappingCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/GetHypervisorGuestOsNamesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/GetHypervisorGuestOsNamesCmd.java index 79517708290..da920a2ec2d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/GetHypervisorGuestOsNamesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/GetHypervisorGuestOsNamesCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.HypervisorGuestOsNamesResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.user.Account; @@ -35,8 +34,6 @@ import com.cloud.utils.Pair; @APICommand(name = GetHypervisorGuestOsNamesCmd.APINAME, description = "Gets the guest OS names in the hypervisor", responseObject = HypervisorGuestOsNamesResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin}) public class GetHypervisorGuestOsNamesCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(GetHypervisorGuestOsNamesCmd.class.getName()); - public static final String APINAME = "getHypervisorGuestOsNames"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java index 29ae0b4f188..23e62cdc781 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/ListGuestOsMappingCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.guest; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listGuestOsMapping", description = "Lists all available OS mappings for given hypervisor", responseObject = GuestOsMappingResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListGuestOsMappingCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListGuestOsMappingCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java index 14beb83e073..d38682ce5bb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.guest; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveGuestOsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveGuestOsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java index 0a72b7e0451..a472ab672c5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/RemoveGuestOsMappingCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.guest; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveGuestOsMappingCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveGuestOsMappingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java index 25f022b3b51..c98cd149ef3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.guest; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -42,7 +41,6 @@ import java.util.Map; since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateGuestOsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateGuestOsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java index c83be131b4f..fc67ef0a7e7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/guest/UpdateGuestOsMappingCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.guest; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "updateGuestOsMapping", description = "Updates the information about Guest OS to Hypervisor specific name mapping", responseObject = GuestOsMappingResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateGuestOsMappingCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateGuestOsMappingCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java index 15955b9f0a8..ca27837aa88 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddHostCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.host; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.user.Account; @APICommand(name = "addHost", description = "Adds a new host.", responseObject = HostResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class AddHostCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddHostCmd.class.getName()); ///////////////////////////////////////////////////// @@ -150,7 +148,7 @@ public class AddHostCmd extends BaseCmd { this.setResponseObject(response); } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java index 225eb1dfecd..c965a39450b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/AddSecondaryStorageCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "addSecondaryStorage", description = "Adds secondary storage.", responseObject = ImageStoreResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddSecondaryStorageCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddSecondaryStorageCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -81,7 +79,7 @@ public class AddSecondaryStorageCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java index cca449f570b..a514a61b8a4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/CancelMaintenanceCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "cancelHostMaintenance", description = "Cancels host maintenance.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CancelMaintenanceCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CancelMaintenanceCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java index 934965cd24c..38325c2f072 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/DeleteHostCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteHost", description = "Deletes a host.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteHostCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteHostCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java index 2b6ccb68eea..db30e4f4c02 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/FindHostsForMigrationCmd.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.utils.Ternary; @APICommand(name = "findHostsForMigration", description = "Find hosts suitable for migrating a virtual machine.", responseObject = HostForMigrationResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class FindHostsForMigrationCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(FindHostsForMigrationCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostTagsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostTagsCmd.java index ed4f9a09bc5..9ea2b2a7fbb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostTagsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostTagsCmd.java @@ -18,7 +18,6 @@ */ package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.BaseListCmd; @@ -27,7 +26,6 @@ import org.apache.cloudstack.api.response.HostTagResponse; @APICommand(name = "listHostTags", description = "Lists host tags", responseObject = HostTagResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListHostTagsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListHostTagsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java index b8668f61ca4..af87bbf33bb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ListHostsCmd.java @@ -21,7 +21,6 @@ import java.util.EnumSet; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -45,7 +44,6 @@ import com.cloud.utils.Ternary; @APICommand(name = "listHosts", description = "Lists hosts.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListHostsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListHostsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java index a89965e822e..2641c54364e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/PrepareForMaintenanceCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.host.Host; @@ -35,7 +34,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "prepareHostForMaintenance", description = "Prepares a host for maintenance.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class PrepareForMaintenanceCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(PrepareForMaintenanceCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java index 7439d9da514..3550d61fdb9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.AgentUnavailableException; @@ -36,7 +35,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "reconnectHost", description = "Reconnects a host.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReconnectHostCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReconnectHostCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java index 90c388bc7dc..7fee0684c78 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReleaseHostReservationCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.host; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "releaseHostReservation", description = "Releases host reservation.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseHostReservationCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseHostReservationCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java index 9cf47a9c4b9..88eeadb9b13 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java @@ -27,14 +27,12 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.GuestOSCategoryResponse; import org.apache.cloudstack.api.response.HostResponse; -import org.apache.log4j.Logger; import java.util.List; @APICommand(name = "updateHost", description = "Updates a host.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateHostCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateHostCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -127,7 +125,7 @@ public class UpdateHostCmd extends BaseCmd { hostResponse.setResponseName(getCommandName()); this.setResponseObject(hostResponse); } catch (Exception e) { - s_logger.debug("Failed to update host:" + getId(), e); + logger.debug("Failed to update host:" + getId(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update host:" + getId() + "," + e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java index 2e05ad14475..c94fe2c5865 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostPasswordCmd.java @@ -24,14 +24,12 @@ import org.apache.cloudstack.api.response.ClusterResponse; import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.user.Account; @APICommand(name = "updateHostPassword", description = "Update password of a host/pool on management server.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class UpdateHostPasswordCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateHostPasswordCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java index 1c7e4a0ce21..c94d326ee62 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ConfigureInternalLoadBalancerElementCmd.java @@ -17,12 +17,6 @@ package org.apache.cloudstack.api.command.admin.internallb; -import java.util.List; - -import javax.inject.Inject; - -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -47,10 +41,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ConfigureInternalLoadBalancerElementCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ConfigureInternalLoadBalancerElementCmd.class.getName()); - - @Inject - private List _service; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -100,7 +90,8 @@ public class ConfigureInternalLoadBalancerElementCmd extends BaseAsyncCmd { @Override public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { CallContext.current().setEventDetails("Internal load balancer element: " + id); - VirtualRouterProvider result = _service.get(0).configureInternalLoadBalancerElement(getId(), getEnabled()); + InternalLoadBalancerElementService service = _networkService.getInternalLoadBalancerElementById(id); + VirtualRouterProvider result = service.configureInternalLoadBalancerElement(getId(), getEnabled()); if (result != null) { InternalLoadBalancerElementResponse routerResponse = _responseGenerator.createInternalLbElementResponse(result); routerResponse.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java index f11f081031a..924287b673b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/CreateInternalLoadBalancerElementCmd.java @@ -16,12 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.internallb; -import java.util.List; - -import javax.inject.Inject; - -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; @@ -45,10 +39,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateInternalLoadBalancerElementCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateInternalLoadBalancerElementCmd.class.getName()); - - @Inject - private List _service; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -85,7 +75,8 @@ public class CreateInternalLoadBalancerElementCmd extends BaseAsyncCreateCmd { @Override public void execute() { CallContext.current().setEventDetails("Virtual router element Id: " + getEntityId()); - VirtualRouterProvider result = _service.get(0).getInternalLoadBalancerElement(getEntityId()); + InternalLoadBalancerElementService service = _networkService.getInternalLoadBalancerElementByNetworkServiceProviderId(getNspId()); + VirtualRouterProvider result = service.getInternalLoadBalancerElement(getEntityId()); if (result != null) { InternalLoadBalancerElementResponse response = _responseGenerator.createInternalLbElementResponse(result); response.setResponseName(getCommandName()); @@ -97,7 +88,8 @@ public class CreateInternalLoadBalancerElementCmd extends BaseAsyncCreateCmd { @Override public void create() throws ResourceAllocationException { - VirtualRouterProvider result = _service.get(0).addInternalLoadBalancerElement(getNspId()); + InternalLoadBalancerElementService service = _networkService.getInternalLoadBalancerElementByNetworkServiceProviderId(getNspId()); + VirtualRouterProvider result = service.addInternalLoadBalancerElement(getNspId()); if (result != null) { setEntityId(result.getId()); setEntityUuid(result.getUuid()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLBVMsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLBVMsCmd.java index f5756909706..0eb00234382 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLBVMsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLBVMsCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.internallb; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "listInternalLoadBalancerVMs", description = "List internal LB VMs.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListInternalLBVMsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListInternalLBVMsCmd.class.getName()); private static final String s_name = "listinternallbvmsresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java index 82d373e3119..b17cc22e746 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/ListInternalLoadBalancerElementsCmd.java @@ -17,12 +17,9 @@ package org.apache.cloudstack.api.command.admin.internallb; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import javax.inject.Inject; - -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListCmd; @@ -46,10 +43,6 @@ import com.cloud.network.VirtualRouterProvider; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListInternalLoadBalancerElementsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListInternalLoadBalancerElementsCmd.class.getName()); - - @Inject - private InternalLoadBalancerElementService _service; ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -88,12 +81,21 @@ public class ListInternalLoadBalancerElementsCmd extends BaseListCmd { @Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { - List providers = _service.searchForInternalLoadBalancerElements(getId(), getNspId(), getEnabled()); + List services; + if (id == null && nspId == null) { + services = _networkService.getInternalLoadBalancerElements(); + } else { + InternalLoadBalancerElementService elementService = id != null ? _networkService.getInternalLoadBalancerElementById(id) : _networkService.getInternalLoadBalancerElementByNetworkServiceProviderId(nspId); + services = Collections.singletonList(elementService); + } ListResponse response = new ListResponse(); List providerResponses = new ArrayList(); - for (VirtualRouterProvider provider : providers) { - InternalLoadBalancerElementResponse providerResponse = _responseGenerator.createInternalLbElementResponse(provider); - providerResponses.add(providerResponse); + for (InternalLoadBalancerElementService service : services) { + List providers = service.searchForInternalLoadBalancerElements(getId(), getNspId(), getEnabled()); + for (VirtualRouterProvider provider : providers) { + InternalLoadBalancerElementResponse providerResponse = _responseGenerator.createInternalLbElementResponse(provider); + providerResponses.add(providerResponse); + } } response.setResponses(providerResponses); response.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java index fdec7947853..3dd7d2adf37 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StartInternalLBVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.internallb; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -42,7 +41,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "startInternalLoadBalancerVM", responseObject = DomainRouterResponse.class, description = "Starts an existing internal lb vm.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StartInternalLBVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StartInternalLBVMCmd.class.getName()); private static final String s_name = "startinternallbvmresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java index 76ad4d438d2..a746e5d906d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/internallb/StopInternalLBVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.internallb; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "stopInternalLoadBalancerVM", description = "Stops an Internal LB vm.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StopInternalLBVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StopInternalLBVMCmd.class.getName()); private static final String s_name = "stopinternallbvmresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java index 3af772d332f..a68ed62857a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/management/ListMgmtsCmd.java @@ -23,12 +23,10 @@ import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ManagementServerResponse; -import org.apache.log4j.Logger; @APICommand(name = "listManagementServers", description = "Lists management servers.", responseObject = ManagementServerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListMgmtsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListMgmtsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java index be0cd9f2fa7..33477297043 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkDeviceCmd.java @@ -20,7 +20,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -44,7 +43,6 @@ import com.cloud.utils.exception.CloudRuntimeException; responseObject = NetworkDeviceResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddNetworkDeviceCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddNetworkDeviceCmd.class); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java index 176375ce181..40a82239345 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/AddNetworkServiceProviderCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddNetworkServiceProviderCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddNetworkServiceProviderCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateGuestNetworkIpv6PrefixCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateGuestNetworkIpv6PrefixCmd.java index d7c7bec99f9..f6b035c5783 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateGuestNetworkIpv6PrefixCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateGuestNetworkIpv6PrefixCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.DataCenterGuestIpv6PrefixResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenterGuestIpv6Prefix; import com.cloud.event.EventTypes; @@ -45,7 +44,6 @@ import com.cloud.user.Account; responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class CreateGuestNetworkIpv6PrefixCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateGuestNetworkIpv6PrefixCmd.class); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateManagementNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateManagementNetworkIpRangeCmd.java index 2bab4f05352..85cfddfb714 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateManagementNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateManagementNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.ApiArgValidator; @@ -44,7 +43,6 @@ import com.cloud.user.Account; responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class CreateManagementNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateManagementNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java index 53b02718ea3..cd9770877ed 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkCmdByAdmin.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.network; import org.apache.cloudstack.api.ApiArgValidator; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.network.Network; @APICommand(name = "createNetwork", description = "Creates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Full, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkCmdByAdmin extends CreateNetworkCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkCmdByAdmin.class.getName()); @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network") private String vlan; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java index 2112be34543..9117bcfc193 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateNetworkOfferingCmd.java @@ -24,12 +24,15 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import com.cloud.network.Network; +import com.cloud.network.VirtualRouterProvider; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -47,10 +50,19 @@ import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.Availability; import com.cloud.user.Account; +import static com.cloud.network.Network.Service.Dhcp; +import static com.cloud.network.Network.Service.Dns; +import static com.cloud.network.Network.Service.Lb; +import static com.cloud.network.Network.Service.StaticNat; +import static com.cloud.network.Network.Service.SourceNat; +import static com.cloud.network.Network.Service.PortForwarding; +import static com.cloud.network.Network.Service.NetworkACL; +import static com.cloud.network.Network.Service.UserData; +import static com.cloud.network.Network.Service.Firewall; + @APICommand(name = "createNetworkOffering", description = "Creates a network offering.", responseObject = NetworkOfferingResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -128,6 +140,30 @@ public class CreateNetworkOfferingCmd extends BaseCmd { description = "true if network offering is meant to be used for VPC, false otherwise.") private Boolean forVpc; + @Parameter(name = ApiConstants.FOR_NSX, + type = CommandType.BOOLEAN, + description = "true if network offering is meant to be used for NSX, false otherwise.", + since = "4.20.0") + private Boolean forNsx; + + @Parameter(name = ApiConstants.NSX_MODE, + type = CommandType.STRING, + description = "Indicates the mode with which the network will operate. Valid option: NATTED or ROUTED", + since = "4.20.0") + private String nsxMode; + + @Parameter(name = ApiConstants.NSX_SUPPORT_LB, + type = CommandType.BOOLEAN, + description = "true if network offering for NSX network offering supports Load balancer service.", + since = "4.20.0") + private Boolean nsxSupportsLbService; + + @Parameter(name = ApiConstants.NSX_SUPPORTS_INTERNAL_LB, + type = CommandType.BOOLEAN, + description = "true if network offering for NSX network offering supports Internal Load balancer service.", + since = "4.20.0") + private Boolean nsxSupportsInternalLbService; + @Parameter(name = ApiConstants.FOR_TUNGSTEN, type = CommandType.BOOLEAN, description = "true if network offering is meant to be used for Tungsten-Fabric, false otherwise.") @@ -212,7 +248,27 @@ public class CreateNetworkOfferingCmd extends BaseCmd { } public List getSupportedServices() { - return supportedServices == null ? new ArrayList() : supportedServices; + if (!isForNsx()) { + return supportedServices == null ? new ArrayList() : supportedServices; + } else { + List services = new ArrayList<>(List.of( + Dhcp.getName(), + Dns.getName(), + StaticNat.getName(), + SourceNat.getName(), + PortForwarding.getName(), + UserData.getName() + )); + if (getNsxSupportsLbService()) { + services.add(Lb.getName()); + } + if (Boolean.TRUE.equals(forVpc)) { + services.add(NetworkACL.getName()); + } else { + services.add(Firewall.getName()); + } + return services; + } } public String getGuestIpType() { @@ -242,6 +298,22 @@ public class CreateNetworkOfferingCmd extends BaseCmd { return forVpc; } + public boolean isForNsx() { + return BooleanUtils.isTrue(forNsx); + } + + public String getNsxMode() { + return nsxMode; + } + + public boolean getNsxSupportsLbService() { + return BooleanUtils.isTrue(nsxSupportsLbService); + } + + public boolean getNsxSupportsInternalLbService() { + return BooleanUtils.isTrue(nsxSupportsInternalLbService); + } + public Boolean getForTungsten() { return forTungsten; } @@ -262,9 +334,8 @@ public class CreateNetworkOfferingCmd extends BaseCmd { } public Map> getServiceProviders() { - Map> serviceProviderMap = null; - if (serviceProviderList != null && !serviceProviderList.isEmpty()) { - serviceProviderMap = new HashMap>(); + Map> serviceProviderMap = new HashMap<>(); + if (serviceProviderList != null && !serviceProviderList.isEmpty() && !isForNsx()) { Collection servicesCollection = serviceProviderList.values(); Iterator iter = servicesCollection.iterator(); while (iter.hasNext()) { @@ -280,11 +351,37 @@ public class CreateNetworkOfferingCmd extends BaseCmd { providerList.add(provider); serviceProviderMap.put(service, providerList); } + } else if (Boolean.TRUE.equals(forNsx)) { + getServiceProviderMapForNsx(serviceProviderMap); } - return serviceProviderMap; } + private void getServiceProviderMapForNsx(Map> serviceProviderMap) { + String routerProvider = Boolean.TRUE.equals(getForVpc()) ? VirtualRouterProvider.Type.VPCVirtualRouter.name() : + VirtualRouterProvider.Type.VirtualRouter.name(); + List unsupportedServices = new ArrayList<>(List.of("Vpn", "SecurityGroup", "Connectivity", + "Gateway", "BaremetalPxeService")); + List routerSupported = List.of("Dhcp", "Dns", "UserData"); + List allServices = Service.listAllServices().stream().map(Service::getName).collect(Collectors.toList()); + if (routerProvider.equals(VirtualRouterProvider.Type.VPCVirtualRouter.name())) { + unsupportedServices.add("Firewall"); + } else { + unsupportedServices.add("NetworkACL"); + } + for (String service : allServices) { + if (unsupportedServices.contains(service)) + continue; + if (routerSupported.contains(service)) + serviceProviderMap.put(service, List.of(routerProvider)); + else + serviceProviderMap.put(service, List.of(Network.Provider.Nsx.getName())); + if (!getNsxSupportsLbService()) { + serviceProviderMap.remove(Lb.getName()); + } + } + } + public Map getServiceCapabilities(Service service) { Map capabilityMap = null; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java index 294ee047fe6..7eb52b92456 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreatePhysicalNetworkCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -40,7 +39,6 @@ import com.cloud.user.Account; @APICommand(name = "createPhysicalNetwork", description = "Creates a physical network", responseObject = PhysicalNetworkResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreatePhysicalNetworkCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java index d2dc3d8688f..42262cc2bf1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/CreateStorageNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateStorageNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateStorageNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// @@ -119,7 +117,7 @@ public class CreateStorageNetworkIpRangeCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Create storage network IP range failed", e); + logger.warn("Create storage network IP range failed", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java index e6a289d096b..355f738679e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DedicateGuestVlanRangeCmd.java @@ -18,7 +18,6 @@ */ package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "dedicateGuestVlanRange", description = "Dedicates a guest vlan range to an account", responseObject = GuestVlanRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicateGuestVlanRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DedicateGuestVlanRangeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteGuestNetworkIpv6PrefixCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteGuestNetworkIpv6PrefixCmd.java index 67d309456d6..e2ada4191a8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteGuestNetworkIpv6PrefixCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteGuestNetworkIpv6PrefixCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.DataCenterGuestIpv6PrefixResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -45,7 +44,6 @@ import com.cloud.utils.exception.CloudRuntimeException; responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class DeleteGuestNetworkIpv6PrefixCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteGuestNetworkIpv6PrefixCmd.class); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteManagementNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteManagementNetworkIpRangeCmd.java index abb72eb2724..41cf5e518b3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteManagementNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteManagementNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.ApiArgValidator; @@ -42,7 +41,6 @@ import com.cloud.user.Account; responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class DeleteManagementNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteManagementNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// @@ -112,13 +110,13 @@ public class DeleteManagementNetworkIpRangeCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (Exception e) { - s_logger.warn("Failed to delete management ip range from " + getStartIp() + " to " + getEndIp() + " of Pod: " + getPodId(), e); + logger.warn("Failed to delete management ip range from " + getStartIp() + " to " + getEndIp() + " of Pod: " + getPodId(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java index d7e8744d6b7..89a36d0b94f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkDeviceCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.network; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "deleteNetworkDevice", description = "Deletes network device.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkDeviceCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkDeviceCmd.class); @Inject ExternalNetworkDeviceManager nwDeviceMgr; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java index 80ce48cc7d9..e0598b71ea1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkOfferingCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteNetworkOffering", description = "Deletes a network offering.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java index 1ccfff5d7ba..4b56612fdda 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteNetworkServiceProviderCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteNetworkServiceProvider", description = "Deletes a Network Service Provider.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkServiceProviderCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkServiceProviderCmd.class.getName()); ///////////////////////////////////////////////////// @@ -78,10 +76,10 @@ public class DeleteNetworkServiceProviderCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete network service provider"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java index 79f0685c6c6..3233130211c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeletePhysicalNetworkCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "deletePhysicalNetwork", description = "Deletes a Physical Network.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePhysicalNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePhysicalNetworkCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java index b5de43dc5e2..454dfba92f2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/DeleteStorageNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteStorageNetworkIpRange", description = "Deletes a storage network IP Range.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteStorageNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteStorageNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// @@ -77,7 +75,7 @@ public class DeleteStorageNetworkIpRangeCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Failed to delete storage network ip range " + getId(), e); + logger.warn("Failed to delete storage network ip range " + getId(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListDedicatedGuestVlanRangesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListDedicatedGuestVlanRangesCmd.java index 67324d81927..0247a306921 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListDedicatedGuestVlanRangesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListDedicatedGuestVlanRangesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listDedicatedGuestVlanRanges", description = "Lists dedicated guest vlan ranges", responseObject = GuestVlanRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedGuestVlanRangesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedGuestVlanRangesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListGuestVlansCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListGuestVlansCmd.java index 1daeac9c53d..4b368f5e034 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListGuestVlansCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListGuestVlansCmd.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.utils.Pair; since = "4.17.0", authorized = {RoleType.Admin}) public class ListGuestVlansCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListGuestVlansCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java index 405c2654bdf..768bab64108 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkDeviceCmd.java @@ -22,7 +22,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -45,7 +44,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "listNetworkDevice", description = "List network devices", responseObject = NetworkDeviceResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkDeviceCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkDeviceCmd.class); private static final String s_name = "listnetworkdevice"; @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkServiceProvidersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkServiceProvidersCmd.java index 67fc8292a93..68495a62215 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkServiceProvidersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListNetworkServiceProvidersCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.utils.Pair; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkServiceProvidersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkServiceProvidersCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java index b8f30d3f7a1..51a6ddabd9f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListPhysicalNetworksCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listPhysicalNetworks", description = "Lists physical networks", responseObject = PhysicalNetworkResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPhysicalNetworksCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListPhysicalNetworksCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java index c22ec8ee19b..556162ca360 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListStorageNetworkIpRangeCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "listStorageNetworkIpRange", description = "List a storage network IP range.", responseObject = StorageNetworkIpRangeResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListStorageNetworkIpRangeCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListStorageNetworkIpRangeCmd.class); String _name = "liststoragenetworkiprangeresponse"; @@ -99,7 +97,7 @@ public class ListStorageNetworkIpRangeCmd extends BaseListCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Failed to list storage network ip range for rangeId=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + getZoneId()); + logger.warn("Failed to list storage network ip range for rangeId=" + getRangeId() + " podId=" + getPodId() + " zoneId=" + getZoneId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListSupportedNetworkServicesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListSupportedNetworkServicesCmd.java index 361da2d0db4..120c6af41ad 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListSupportedNetworkServicesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ListSupportedNetworkServicesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSupportedNetworkServicesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSupportedNetworkServicesCmd.class.getName()); @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, description = "network service provider name") private String providerName; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateNetworkCmd.java index b38e8f453b0..8ef853b99da 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateNetworkCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -48,7 +47,6 @@ import com.cloud.user.User; since = "4.11.0", authorized = {RoleType.Admin}) public class MigrateNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateNetworkCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateVPCCmd.java index cca367ce750..3e0801be40b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/MigrateVPCCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker; @@ -50,7 +49,6 @@ import com.cloud.user.User; since = "4.11.0", authorized = {RoleType.Admin}) public class MigrateVPCCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateVPCCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java index 916357920a1..b3125ec3668 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/ReleaseDedicatedGuestVlanRangeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "releaseDedicatedGuestVlanRange", description = "Releases a dedicated guest vlan range to the system", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedGuestVlanRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedGuestVlanRangeCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java index e8f9e5f8cfe..75fb45e1f11 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkOfferingCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NetworkOfferingResponse; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "updateNetworkOffering", description = "Updates a network offering.", responseObject = NetworkOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java index 1bbf21b85ed..b4801d9368e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateNetworkServiceProviderCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -40,7 +39,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkServiceProviderCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkServiceProviderCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java index 24fd93f49d1..162116470bd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePhysicalNetworkCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.network; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "updatePhysicalNetwork", description = "Updates a physical network", responseObject = PhysicalNetworkResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdatePhysicalNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdatePhysicalNetworkCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePodManagementNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePodManagementNetworkIpRangeCmd.java index 4e880f122d8..6f90a070f0d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePodManagementNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdatePodManagementNetworkIpRangeCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.PodResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -42,7 +41,6 @@ import com.cloud.user.Account; authorized = {RoleType.Admin}) public class UpdatePodManagementNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdatePodManagementNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// @@ -138,10 +136,10 @@ public class UpdatePodManagementNetworkIpRangeCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); this.setResponseObject(response); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (Exception e) { - s_logger.warn("Failed to update pod management IP range " + getNewStartIP() + "-" + getNewEndIP() + " of Pod: " + getPodId(), e); + logger.warn("Failed to update pod management IP range " + getNewStartIP() + "-" + getNewEndIP() + " of Pod: " + getPodId(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java index 459c89debc9..65e2437417d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/network/UpdateStorageNetworkIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateStorageNetworkIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateStorageNetworkIpRangeCmd.class); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -107,7 +105,7 @@ public class UpdateStorageNetworkIpRangeCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Update storage network IP range failed", e); + logger.warn("Update storage network IP range failed", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java index c2d8b3b6839..c46e4cd6b44 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateDiskOfferingCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.offering.DiskOffering; import com.cloud.offering.ServiceOffering; @@ -47,7 +46,6 @@ import com.cloud.user.Account; @APICommand(name = "createDiskOffering", description = "Creates a disk offering.", responseObject = DiskOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateDiskOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateDiskOfferingCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java index d947f6f0659..4562aa7da19 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.offering.ServiceOffering; @@ -47,7 +46,6 @@ import com.cloud.user.Account; @APICommand(name = "createServiceOffering", description = "Creates a service offering.", responseObject = ServiceOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateServiceOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateServiceOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java index 0159cd297f9..591b09c60a5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteDiskOfferingCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.offering; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteDiskOffering", description = "Updates a disk offering.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteDiskOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteDiskOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java index 9b7f9d48e30..19203289d10 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/DeleteServiceOfferingCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.offering; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteServiceOffering", description = "Deletes a service offering.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteServiceOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteServiceOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java index 1d5898ea4a0..370453804cf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateDiskOfferingCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.offering; import java.util.ArrayList; import java.util.List; +import com.cloud.offering.DiskOffering.State; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; @@ -27,8 +28,8 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.DiskOfferingResponse; +import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; @@ -39,7 +40,6 @@ import com.cloud.user.Account; @APICommand(name = "updateDiskOffering", description = "Updates a disk offering.", responseObject = DiskOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateDiskOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateDiskOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -123,6 +123,9 @@ public class UpdateDiskOfferingCmd extends BaseCmd { @Parameter(name = ApiConstants.CACHE_MODE, type = CommandType.STRING, description = "the cache mode to use for this disk offering", since = "4.15") private String cacheMode; + @Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "state of the disk offering") + private String diskOfferingState; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -262,6 +265,13 @@ public class UpdateDiskOfferingCmd extends BaseCmd { public Long getIopsWriteRateMaxLength() { return iopsWriteRateMaxLength; } + public State getState() { + State state = EnumUtils.getEnumIgnoreCase(State.class, diskOfferingState); + if (StringUtils.isNotBlank(diskOfferingState) && state == null) { + throw new InvalidParameterValueException("Invalid state value: " + diskOfferingState); + } + return state; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java index d86564a60c6..7d6bae86083 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/offering/UpdateServiceOfferingCmd.java @@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.admin.offering; import java.util.ArrayList; import java.util.List; +import com.cloud.offering.ServiceOffering.State; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; @@ -27,8 +28,8 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ServiceOfferingResponse; +import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; @@ -39,7 +40,6 @@ import com.cloud.user.Account; @APICommand(name = "updateServiceOffering", description = "Updates a service offering.", responseObject = ServiceOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateServiceOfferingCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateServiceOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -84,6 +84,11 @@ public class UpdateServiceOfferingCmd extends BaseCmd { since = "4.16") private String hostTags; + @Parameter(name = ApiConstants.STATE, + type = CommandType.STRING, + description = "state of the service offering") + private String serviceOfferingState; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -172,6 +177,14 @@ public class UpdateServiceOfferingCmd extends BaseCmd { return hostTags; } + public State getState() { + State state = EnumUtils.getEnumIgnoreCase(State.class, serviceOfferingState); + if (StringUtils.isNotBlank(serviceOfferingState) && state == null) { + throw new InvalidParameterValueException("Invalid state value: " + serviceOfferingState); + } + return state; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/ChangeOutOfBandManagementPasswordCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/ChangeOutOfBandManagementPasswordCmd.java index dad6506729a..e2c31d6cf07 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/ChangeOutOfBandManagementPasswordCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/ChangeOutOfBandManagementPasswordCmd.java @@ -26,6 +26,7 @@ import com.cloud.host.Host; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; @@ -102,4 +103,14 @@ public class ChangeOutOfBandManagementPasswordCmd extends BaseAsyncCmd { public String getEventDescription() { return "change out-of-band management password for host: " + getHostId(); } + + @Override + public Long getApiResourceId() { + return getHostId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Host; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/ConfigureOutOfBandManagementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/ConfigureOutOfBandManagementCmd.java index 699e2855185..157d3c627db 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/ConfigureOutOfBandManagementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/ConfigureOutOfBandManagementCmd.java @@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableMap; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; @@ -112,4 +113,14 @@ public class ConfigureOutOfBandManagementCmd extends BaseCmd { builder.put(option, value); } } + + @Override + public Long getApiResourceId() { + return getHostId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Host; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForClusterCmd.java index 604aae66889..445e7b92665 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForClusterCmd.java @@ -27,6 +27,7 @@ import com.cloud.org.Cluster; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; @@ -94,4 +95,14 @@ public class DisableOutOfBandManagementForClusterCmd extends BaseAsyncCmd { public String getEventDescription() { return "disable out-of-band management password for cluster: " + getClusterId(); } + + @Override + public Long getApiResourceId() { + return getClusterId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Cluster; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForHostCmd.java index 51c0fbcc3db..7e4444e93fb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForHostCmd.java @@ -27,6 +27,7 @@ import com.cloud.host.Host; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; @@ -95,4 +96,14 @@ public class DisableOutOfBandManagementForHostCmd extends BaseAsyncCmd { public String getEventDescription() { return "disable out-of-band management password for host: " + getHostId(); } + + @Override + public Long getApiResourceId() { + return getHostId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Host; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForZoneCmd.java index 4c3e92cf05d..2028f8fc2a0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForZoneCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/DisableOutOfBandManagementForZoneCmd.java @@ -27,6 +27,7 @@ import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; @@ -94,4 +95,14 @@ public class DisableOutOfBandManagementForZoneCmd extends BaseAsyncCmd { public String getEventDescription() { return "disable out-of-band management password for zone: " + getZoneId(); } + + @Override + public Long getApiResourceId() { + return getZoneId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Zone; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForClusterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForClusterCmd.java index a69f27fb3ac..549743b3172 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForClusterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForClusterCmd.java @@ -27,6 +27,7 @@ import com.cloud.org.Cluster; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; @@ -94,4 +95,14 @@ public class EnableOutOfBandManagementForClusterCmd extends BaseAsyncCmd { public String getEventDescription() { return "enable out-of-band management password for cluster: " + getClusterId(); } + + @Override + public Long getApiResourceId() { + return getClusterId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Cluster; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForHostCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForHostCmd.java index 5e32c8943bf..834181a5e1c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForHostCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForHostCmd.java @@ -27,6 +27,7 @@ import com.cloud.host.Host; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; @@ -95,4 +96,14 @@ public class EnableOutOfBandManagementForHostCmd extends BaseAsyncCmd { public String getEventDescription() { return "enable out-of-band management password for host: " + getHostId(); } + + @Override + public Long getApiResourceId() { + return getHostId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Host; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForZoneCmd.java index 4eea4d50fe0..de4c4d801de 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForZoneCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/EnableOutOfBandManagementForZoneCmd.java @@ -27,6 +27,7 @@ import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseAsyncCmd; @@ -94,4 +95,14 @@ public class EnableOutOfBandManagementForZoneCmd extends BaseAsyncCmd { public String getEventDescription() { return "enable out-of-band management password for zone: " + getZoneId(); } + + @Override + public Long getApiResourceId() { + return getZoneId(); + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Zone; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/IssueOutOfBandManagementPowerActionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/IssueOutOfBandManagementPowerActionCmd.java index d10664f0a25..97a813c9d47 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/IssueOutOfBandManagementPowerActionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/outofbandmanagement/IssueOutOfBandManagementPowerActionCmd.java @@ -114,4 +114,9 @@ public class IssueOutOfBandManagementPowerActionCmd extends BaseAsyncCmd { public ApiCommandResourceType getApiResourceType() { return ApiCommandResourceType.Host; } + + @Override + public Long getApiResourceId() { + return getHostId(); + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java index b15854ca875..c1d9a6db429 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/CreatePodCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.pod; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "createPod", description = "Creates a new Pod.", responseObject = PodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreatePodCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreatePodCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java index bdb9ef26694..c1de800d745 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/DeletePodCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.pod; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ import com.cloud.user.Account; @APICommand(name = "deletePod", description = "Deletes a Pod.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePodCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeletePodCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java index c0e26a32eee..5ad0b457ced 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/ListPodsByCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.pod; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listPods", description = "Lists all Pods.", responseObject = PodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPodsByCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListPodsByCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java index 99ab5e1cee4..7dae6f4c7cf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/pod/UpdatePodCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.pod; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ import com.cloud.user.Account; @APICommand(name = "updatePod", description = "Updates a Pod.", responseObject = PodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdatePodCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdatePodCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/AddRegionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/AddRegionCmd.java index 61bf32ab822..3a93a275042 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/AddRegionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/AddRegionCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.region; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "addRegion", description = "Adds a Region", responseObject = RegionResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddRegionCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddRegionCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/CreatePortableIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/CreatePortableIpRangeCmd.java index 61deceb0691..fd103c83830 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/CreatePortableIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/CreatePortableIpRangeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.region; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ import com.cloud.user.Account; responseHasSensitiveInfo = false) public class CreatePortableIpRangeCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreatePortableIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// @@ -126,7 +124,7 @@ public class CreatePortableIpRangeCmd extends BaseAsyncCreateCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create portable public IP range"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/DeletePortableIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/DeletePortableIpRangeCmd.java index 6cc884645e9..3ff46fcc94d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/DeletePortableIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/DeletePortableIpRangeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.region; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "deletePortableIpRange", description = "deletes a range of portable public IP's associated with a region", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePortableIpRangeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePortableIpRangeCmd.class.getName()); private static final String s_name = "deleteportablepublicipresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java index ed0ddd68aca..e654da6df44 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/ListPortableIpRangesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.region; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPortableIpRangesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListPortableIpRangesCmd.class.getName()); private static final String s_name = "listportableipresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/RemoveRegionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/RemoveRegionCmd.java index 180e34c7a8f..3ea323eebfb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/RemoveRegionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/RemoveRegionCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.region; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "removeRegion", description = "Removes specified region", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveRegionCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RemoveRegionCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/UpdateRegionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/UpdateRegionCmd.java index c772efd5e1f..4267f6a2c28 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/region/UpdateRegionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/region/UpdateRegionCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.region; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "updateRegion", description = "Updates a region", responseObject = RegionResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateRegionCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateRegionCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ArchiveAlertsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ArchiveAlertsCmd.java index 003b823e106..dc8c15cf09d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ArchiveAlertsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ArchiveAlertsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.resource; import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ArchiveAlertsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ArchiveAlertsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/CleanVMReservationsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/CleanVMReservationsCmd.java index 9acc71ce693..1ae8c944123 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/CleanVMReservationsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/CleanVMReservationsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.resource; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; @@ -31,7 +30,6 @@ import com.cloud.user.Account; @APICommand(name = "cleanVMReservations", description = "Cleanups VM reservations in the database.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CleanVMReservationsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CleanVMReservationsCmd.class.getName()); private static final String s_name = "cleanvmreservationresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/DeleteAlertsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/DeleteAlertsCmd.java index eb384892758..9262a120f72 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/DeleteAlertsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/DeleteAlertsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.resource; import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAlertsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAlertsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertTypesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertTypesCmd.java new file mode 100644 index 00000000000..e7bfbdbc625 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertTypesCmd.java @@ -0,0 +1,54 @@ +// 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 org.apache.cloudstack.api.command.admin.resource; + +import com.cloud.user.Account; +import org.apache.cloudstack.alert.AlertService; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.response.AlertResponse; +import org.apache.cloudstack.api.response.AlertTypeResponse; +import org.apache.cloudstack.api.response.ListResponse; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +@APICommand(name = "listAlertTypes", description = "Lists all alerts types", responseObject = AlertResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class ListAlertTypesCmd extends BaseCmd { + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute() { + Set result = AlertService.AlertType.getAlertTypes(); + ListResponse response = new ListResponse<>(); + List typeResponseList = new ArrayList<>(); + for (AlertService.AlertType alertType : result) { + AlertTypeResponse alertResponse = new AlertTypeResponse(alertType.getType(), alertType.getName()); + alertResponse.setObjectName("alerttype"); + typeResponseList.add(alertResponse); + } + response.setResponses(typeResponseList, result.size()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertsCmd.java index 3471ab60837..64cf691e6a7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListAlertsCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.AlertResponse; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; import com.cloud.alert.Alert; import com.cloud.utils.Pair; @@ -34,7 +33,6 @@ import com.cloud.utils.Pair; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAlertsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListAlertsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java index 253677616f0..6b31c4cc43c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmd.java @@ -21,7 +21,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.exception.InvalidParameterValueException; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListCapacityCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListCapacityCmd.class.getName()); private static final DecimalFormat s_percentFormat = new DecimalFormat("##.##"); @@ -73,6 +71,9 @@ public class ListCapacityCmd extends BaseListCmd { @Parameter(name = ApiConstants.SORT_BY, type = CommandType.STRING, since = "3.0.0", description = "Sort the results. Available values: Usage") private String sortBy; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -109,6 +110,10 @@ public class ListCapacityCmd extends BaseListCmd { return null; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/StartRollingMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/StartRollingMaintenanceCmd.java index 7ee3e50e0cd..04fa1002611 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/StartRollingMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/StartRollingMaintenanceCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.PodResponse; import org.apache.cloudstack.api.response.RollingMaintenanceResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -55,7 +54,6 @@ public class StartRollingMaintenanceCmd extends BaseAsyncCmd { @Inject RollingMaintenanceManager manager; - public static final Logger s_logger = Logger.getLogger(StartRollingMaintenanceCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java index 5dfada57216..c5ae6890c3e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/UploadCustomCertificateCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.resource; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; description = "Uploads a custom certificate for the console proxy VMs to use for SSL. Can be used to upload a single certificate signed by a known CA. Can also be used, through multiple calls, to upload a chain of certificates from CA to the custom certificate itself.", requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public class UploadCustomCertificateCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UploadCustomCertificateCmd.class.getName()); @Parameter(name = ApiConstants.CERTIFICATE, type = CommandType.STRING, required = true, description = "The certificate to be uploaded.", length = 65535) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/DeleteResourceIconCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/DeleteResourceIconCmd.java index 8fb02ea7054..e97a68bddcb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/DeleteResourceIconCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/DeleteResourceIconCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import java.util.List; @@ -37,7 +36,6 @@ import java.util.List; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}) public class DeleteResourceIconCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteResourceIconCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/ListResourceIconCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/ListResourceIconCmd.java index 0af11ceec22..6cc3173cf15 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/ListResourceIconCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/ListResourceIconCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import java.util.List; @@ -35,7 +34,6 @@ import java.util.List; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}) public class ListResourceIconCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListResourceIconCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/UploadResourceIconCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/UploadResourceIconCmd.java index ea5d8995a2a..5a6acd961bf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/UploadResourceIconCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/resource/icon/UploadResourceIconCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.awt.image.BufferedImage; @@ -46,7 +45,6 @@ import java.util.List; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}) public class UploadResourceIconCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(UploadResourceIconCmd.class.getName()); ///////////////////////////////////////////////////// @@ -120,7 +118,7 @@ public class UploadResourceIconCmd extends BaseCmd { return false; } } catch (Exception e) { - LOGGER.warn("Data uploaded not a valid image"); + logger.warn("Data uploaded not a valid image"); return false; } return true; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureOvsElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureOvsElementCmd.java index a1b01a1c04f..4a8c0bc3a3b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureOvsElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureOvsElementCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.OvsProviderResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -42,8 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "configureOvsElement", responseObject = OvsProviderResponse.class, description = "Configures an ovs element.", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ConfigureOvsElementCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger - .getLogger(ConfigureOvsElementCmd.class.getName()); @Inject private List _service; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java index b7f7a050d07..aa119f3aca7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ConfigureVirtualRouterElementCmd.java @@ -20,7 +20,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ import com.cloud.user.Account; @APICommand(name = "configureVirtualRouterElement", responseObject = VirtualRouterProviderResponse.class, description = "Configures a virtual router element.", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ConfigureVirtualRouterElementCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ConfigureVirtualRouterElementCmd.class.getName()); @Inject private List _service; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java index f93ca35a06a..e85531c83c4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/CreateVirtualRouterElementCmd.java @@ -20,7 +20,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -43,7 +42,6 @@ import com.cloud.user.Account; @APICommand(name = "createVirtualRouterElement", responseObject = VirtualRouterProviderResponse.class, description = "Create a virtual router element.", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVirtualRouterElementCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVirtualRouterElementCmd.class.getName()); @Inject private List _service; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java index d2dce6b9ff3..39ccee47fbe 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/DestroyRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -38,7 +37,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "destroyRouter", description = "Destroys a router.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DestroyRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DestroyRouterCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/GetRouterHealthCheckResultsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/GetRouterHealthCheckResultsCmd.java index 93a48eba49c..4bef26e0555 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/GetRouterHealthCheckResultsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/GetRouterHealthCheckResultsCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.RouterHealthCheckResultResponse; import org.apache.cloudstack.api.response.RouterHealthCheckResultsListResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.ResourceUnavailableException; @@ -47,7 +46,6 @@ import com.cloud.vm.VirtualMachine; responseHasSensitiveInfo = false, since = "4.14.0") public class GetRouterHealthCheckResultsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetRouterHealthCheckResultsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListOvsElementsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListOvsElementsCmd.java index 89b39f87e44..a267aa52669 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListOvsElementsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListOvsElementsCmd.java @@ -26,11 +26,9 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; -import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.OvsProviderResponse; import org.apache.cloudstack.api.response.ProviderResponse; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -42,8 +40,7 @@ import com.cloud.network.element.VirtualRouterElementService; @APICommand(name = "listOvsElements", description = "Lists all available ovs elements.", responseObject = OvsProviderResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListOvsElementsCmd extends BaseListCmd { - public static final Logger s_logger = Logger - .getLogger(ListNetworkOfferingsCmd.class.getName()); + @Inject private List _service; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListRoutersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListRoutersCmd.java index 6e955e46212..e0cdc0dcf80 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListRoutersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListRoutersCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.router; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -40,7 +39,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "listRouters", description = "List routers.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListRoutersCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListRoutersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListVirtualRouterElementsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListVirtualRouterElementsCmd.java index 6eb24dce074..424b8c29d04 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListVirtualRouterElementsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/ListVirtualRouterElementsCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.network.element.VirtualRouterElementService; @APICommand(name = "listVirtualRouterElements", description = "Lists all available virtual router elements.", responseObject = VirtualRouterProviderResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVirtualRouterElementsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListVirtualRouterElementsCmd.class.getName()); // TODO, VirtualRouterElementServer is not singleton in system! @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java index 6e334d7e442..1d97dd80309 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/RebootRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "rebootRouter", description = "Starts a router.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RebootRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RebootRouterCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java index 121b2a1bd11..24ab7881037 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StartRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -41,7 +40,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "startRouter", responseObject = DomainRouterResponse.class, description = "Starts a router.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StartRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StartRouterCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java index 2da38d90426..971086a57cf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/StopRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -40,7 +39,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "stopRouter", description = "Stops a router.", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StopRouterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StopRouterCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java index 2d5255614c6..3265a089d67 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.router; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "changeServiceForRouter", description = "Upgrades domain router to a new service offering", responseObject = DomainRouterResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpgradeRouterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpgradeRouterCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterTemplateCmd.java index fa0fe5800ee..74464cab315 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/router/UpgradeRouterTemplateCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.router; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ import com.cloud.user.Account; @APICommand(name = "upgradeRouterTemplate", description = "Upgrades router to use newer template", responseObject = BaseResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpgradeRouterTemplateCmd extends org.apache.cloudstack.api.BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpgradeRouterTemplateCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java index b8ab1461a2b..7c8f0e21afb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreCmd.java @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "addImageStore", description = "Adds backup image store.", responseObject = ImageStoreResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddImageStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddImageStoreCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -137,7 +135,7 @@ public class AddImageStoreCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java index 34ff171b91f..2fe3c7cd106 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddImageStoreS3CMD.java @@ -38,7 +38,6 @@ import java.util.HashMap; import java.util.Map; import com.cloud.utils.storage.S3.ClientOptions; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -59,7 +58,6 @@ import com.cloud.storage.ImageStore; @APICommand(name = "addImageStoreS3", description = "Adds S3 Image Store", responseObject = ImageStoreResponse.class, since = "4.7.0", requestHasSensitiveInfo = true, responseHasSensitiveInfo = false) public final class AddImageStoreS3CMD extends BaseCmd implements ClientOptions { - public static final Logger s_logger = Logger.getLogger(AddImageStoreS3CMD.class.getName()); private static final String s_name = "addImageStoreS3Response"; @@ -141,7 +139,7 @@ public final class AddImageStoreS3CMD extends BaseCmd implements ClientOptions { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add S3 Image Store."); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmd.java index a538962e076..b779ba2a2b4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ObjectStoreResponse; -import org.apache.log4j.Logger; import java.util.Collection; import java.util.HashMap; @@ -35,7 +34,6 @@ import java.util.Map; @APICommand(name = "addObjectStoragePool", description = "Adds a object storage pool", responseObject = ObjectStoreResponse.class, since = "4.19.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddObjectStoragePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddObjectStoragePoolCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -125,7 +123,7 @@ public class AddObjectStoragePoolCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add object storage"); } } catch (Exception ex) { - s_logger.error("Exception: ", ex); + logger.error("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java index a694aba30fb..7e925f286d0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CancelPrimaryStorageMaintenanceCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "cancelStorageMaintenance", description = "Cancels maintenance for primary storage", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CancelPrimaryStorageMaintenanceCmd.class.getName()); private static final String s_name = "cancelprimarystoragemaintenanceresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmd.java index 08069446893..5776eb6464c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateSecondaryStagingStoreCmd.java @@ -21,7 +21,6 @@ package org.apache.cloudstack.api.command.admin.storage; import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "createSecondaryStagingStore", description = "create secondary staging store.", responseObject = ImageStoreResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSecondaryStagingStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateSecondaryStagingStoreCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -113,7 +111,7 @@ public class CreateSecondaryStagingStoreCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (Exception ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java index 477d7570dfa..75813a7aabf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.storage; import java.net.UnknownHostException; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ import com.cloud.user.Account; @APICommand(name = "createStoragePool", description = "Creates a storage pool.", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateStoragePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateStoragePoolCmd.class.getName()); ///////////////////////////////////////////////////// @@ -170,13 +168,13 @@ public class CreateStoragePoolCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add storage pool"); } } catch (ResourceUnavailableException ex1) { - s_logger.warn("Exception: ", ex1); + logger.warn("Exception: ", ex1); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex1.getMessage()); } catch (ResourceInUseException ex2) { - s_logger.warn("Exception: ", ex2); + logger.warn("Exception: ", ex2); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex2.getMessage()); } catch (UnknownHostException ex3) { - s_logger.warn("Exception: ", ex3); + logger.warn("Exception: ", ex3); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex3.getMessage()); } catch (Exception ex4) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex4.getMessage()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteImageStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteImageStoreCmd.java index 194f0baf603..50a9d9a6f39 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteImageStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteImageStoreCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteImageStore", description = "Deletes an image store or Secondary Storage.", responseObject = SuccessResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteImageStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteImageStoreCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmd.java index ed305d9689d..6cb38d4c862 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmd.java @@ -25,12 +25,10 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ObjectStoreResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; @APICommand(name = "deleteObjectStoragePool", description = "Deletes an Object Storage Pool", responseObject = SuccessResponse.class, since = "4.19.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteObjectStoragePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteObjectStoragePoolCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java index d87768e7f39..28f71e0740f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeletePoolCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteStoragePool", description = "Deletes a storage pool.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeletePoolCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteSecondaryStagingStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteSecondaryStagingStoreCmd.java index 34a26461fa8..a0c2731ccda 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteSecondaryStagingStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/DeleteSecondaryStagingStoreCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteSecondaryStagingStore", description = "Deletes a secondary staging store .", responseObject = SuccessResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSecondaryStagingStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSecondaryStagingStoreCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmd.java index 699f4831415..a45f72766dc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.storage.StoragePool; import com.cloud.utils.Pair; @@ -38,7 +37,6 @@ import com.cloud.utils.Pair; @APICommand(name = "findStoragePoolsForMigration", description = "Lists storage pools available for migration of a volume.", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class FindStoragePoolsForMigrationCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(FindStoragePoolsForMigrationCmd.class.getName()); ///////////////////////////////////////////////////// @@ -67,7 +65,7 @@ public class FindStoragePoolsForMigrationCmd extends BaseListCmd { @Override public void execute() { - Pair, List> pools = _mgr.listStoragePoolsForMigrationOfVolume(getId()); + Pair, List> pools = _mgr.listStoragePoolsForMigrationOfVolume(getId(), getKeyword()); ListResponse response = new ListResponse(); List poolResponses = new ArrayList(); @@ -87,7 +85,8 @@ public class FindStoragePoolsForMigrationCmd extends BaseListCmd { poolResponses.add(poolResponse); } sortPoolsBySuitabilityAndName(poolResponses); - response.setResponses(poolResponses); + List pagingList = com.cloud.utils.StringUtils.applyPagination(poolResponses, this.getStartIndex(), this.getPageSizeVal()); + response.setResponses(pagingList, poolResponses.size()); response.setResponseName(getCommandName()); this.setResponseObject(response); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListImageStoresCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListImageStoresCmd.java index a9eac3ed76d..5270569de44 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListImageStoresCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListImageStoresCmd.java @@ -23,12 +23,10 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ImageStoreResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; @APICommand(name = "listImageStores", description = "Lists image stores.", responseObject = ImageStoreResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListImageStoresCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListImageStoresCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListObjectStoragePoolsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListObjectStoragePoolsCmd.java index 9d8d8eccc3c..005a1a54444 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListObjectStoragePoolsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListObjectStoragePoolsCmd.java @@ -23,13 +23,11 @@ import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ObjectStoreResponse; -import org.apache.log4j.Logger; @APICommand(name = "listObjectStoragePools", description = "Lists object storage pools.", responseObject = ObjectStoreResponse.class, since = "4.19.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListObjectStoragePoolsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListObjectStoragePoolsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListSecondaryStagingStoresCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListSecondaryStagingStoresCmd.java index e315c8a6d47..0cad16a247f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListSecondaryStagingStoresCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListSecondaryStagingStoresCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -29,7 +28,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; @APICommand(name = "listSecondaryStagingStores", description = "Lists secondary staging stores.", responseObject = ImageStoreResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSecondaryStagingStoresCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSecondaryStagingStoresCmd.class.getName()); private static final String s_name = "listsecondarystagingstoreresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java index 6923353b3bf..293ed3103cb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStoragePoolsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -33,7 +32,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; @APICommand(name = "listStoragePools", description = "Lists storage pools.", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListStoragePoolsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListStoragePoolsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageProvidersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageProvidersCmd.java index 347b66061f6..efe7a23b5cb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageProvidersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageProvidersCmd.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.api.command.admin.storage; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.exception.ResourceUnavailableException; @APICommand(name = "listStorageProviders", description = "Lists storage providers.", responseObject = StorageProviderResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListStorageProvidersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListStorageProvidersCmd.class.getName()); @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "the type of storage provider: either primary or image", required = true) private String type; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageTagsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageTagsCmd.java index 43981ee1a3d..d9bb5d4cd93 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageTagsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/ListStorageTagsCmd.java @@ -18,7 +18,6 @@ */ package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.BaseListCmd; @@ -27,7 +26,6 @@ import org.apache.cloudstack.api.response.StorageTagResponse; @APICommand(name = "listStorageTags", description = "Lists storage tags", responseObject = StorageTagResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListStorageTagsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListStorageTagsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/MigrateSecondaryStorageDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/MigrateSecondaryStorageDataCmd.java index de9b55a9ff1..8f5a7aced3f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/MigrateSecondaryStorageDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/MigrateSecondaryStorageDataCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ImageStoreResponse; import org.apache.cloudstack.api.response.MigrationResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; @@ -41,7 +40,6 @@ import com.cloud.event.EventTypes; authorized = {RoleType.Admin}) public class MigrateSecondaryStorageDataCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(MigrateSecondaryStorageDataCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java index ddabefb14c8..818b3a5bbea 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/PreparePrimaryStorageForMaintenanceCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.storage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "enableStorageMaintenance", description = "Puts storage pool into maintenance state", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(PreparePrimaryStorageForMaintenanceCmd.class.getName()); private static final String s_name = "prepareprimarystorageformaintenanceresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/SyncStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/SyncStoragePoolCmd.java index d7a783a4ff4..9f81f2f6c86 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/SyncStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/SyncStoragePoolCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.context.CallContext; -import java.util.logging.Logger; @APICommand(name = "syncStoragePool", description = "Sync storage pool with management server (currently supported for Datastore Cluster in VMware and syncs the datastores in it)", @@ -45,7 +44,6 @@ import java.util.logging.Logger; ) public class SyncStoragePoolCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(SyncStoragePoolCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java index 3351d389c6f..5ac34f27bad 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateCloudToUseObjectStoreCmd.java @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "updateCloudToUseObjectStore", description = "Migrate current NFS secondary storages to use object store.", responseObject = ImageStoreResponse.class, since = "4.3.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateCloudToUseObjectStoreCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateCloudToUseObjectStoreCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -130,7 +128,7 @@ public class UpdateCloudToUseObjectStoreCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateImageStoreCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateImageStoreCmd.java index d7dca93b485..bcc438b957b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateImageStoreCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateImageStoreCmd.java @@ -25,14 +25,12 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ImageStoreResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.storage.ImageStore; @APICommand(name = UpdateImageStoreCmd.APINAME, description = "Updates image store read-only status", responseObject = ImageStoreResponse.class, entityType = {ImageStore.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.15.0") public class UpdateImageStoreCmd extends BaseCmd { - private static final Logger LOG = Logger.getLogger(UpdateImageStoreCmd.class.getName()); public static final String APINAME = "updateImageStore"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStorageCapabilitiesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStorageCapabilitiesCmd.java index 8403d3c6241..716c95b45c3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStorageCapabilitiesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStorageCapabilitiesCmd.java @@ -29,14 +29,12 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "updateStorageCapabilities", description = "Syncs capabilities of storage pools", responseObject = StoragePoolResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0") public class UpdateStorageCapabilitiesCmd extends BaseCmd { - private static final Logger LOG = Logger.getLogger(UpdateStorageCapabilitiesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java index 7a907e0f76a..13f02ef83c2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "updateStoragePool", description = "Updates a storage pool.", responseObject = StoragePoolResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateStoragePoolCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateStoragePoolCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java index 7eb87006d0d..bd72f3213de 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/AddSwiftCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.swift; import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "addSwift", description = "Adds Swift.", responseObject = ImageStoreResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddSwiftCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddSwiftCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -102,7 +100,7 @@ public class AddSwiftCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Swift secondary storage"); } } catch (DiscoveryException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java index 6d7bfbaf1b1..e21a23349bb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/swift/ListSwiftsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.swift; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -31,7 +30,6 @@ import com.cloud.user.Account; @APICommand(name = "listSwifts", description = "List Swift.", responseObject = ImageStoreResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSwiftsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSwiftsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java index 7ed536f6d4c..7e0faab2fb5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/DestroySystemVmCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.systemvm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "destroySystemVm", responseObject = SystemVmResponse.class, description = "Destroys a system virtual machine.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DestroySystemVmCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DestroySystemVmCmd.class.getName()); @ACL(accessType = AccessType.OperateEntry) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java index b6f8c92fa17..e8e5ee0ebad 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ListSystemVMsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.systemvm; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "listSystemVms", description = "List system virtual machines.", responseObject = SystemVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSystemVMsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSystemVMsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java index f0f7aca16c8..ccc6093aa83 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/MigrateSystemVMCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.SystemVmResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -47,7 +46,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "migrateSystemVm", description = "Attempts Migration of a system virtual machine to the host specified.", responseObject = SystemVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class MigrateSystemVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateSystemVMCmd.class.getName()); ///////////////////////////////////////////////////// @@ -171,16 +169,16 @@ public class MigrateSystemVMCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate the system vm"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (ManagementServerException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (VirtualMachineMigrationException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/PatchSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/PatchSystemVMCmd.java index ae3c36b4948..4f4b2631667 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/PatchSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/PatchSystemVMCmd.java @@ -30,13 +30,11 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.SystemVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "patchSystemVm", description = "Attempts to live patch systemVMs - CPVM, SSVM ", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = { RoleType.Admin }, since = "4.17.0") public class PatchSystemVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(PatchSystemVMCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java index 0ba7e0c2edf..30bd51184ac 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/RebootSystemVmCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.systemvm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "rebootSystemVm", description = "Reboots a system VM.", responseObject = SystemVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RebootSystemVmCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RebootSystemVmCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java index f694988efa0..06e57674c53 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/ScaleSystemVMCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.systemvm; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -46,7 +45,6 @@ import com.cloud.vm.VirtualMachine; + "The system vm must be in a \"Stopped\" state for " + "this command to take effect.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ScaleSystemVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ScaleSystemVMCmd.class.getName()); private static final String s_name = "changeserviceforsystemvmresponse"; ///////////////////////////////////////////////////// @@ -111,16 +109,16 @@ public class ScaleSystemVMCmd extends BaseAsyncCmd { try { result = _mgr.upgradeSystemVM(this); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ManagementServerException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (VirtualMachineMigrationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } if (result != null) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java index 0cb517f4058..eac3d64ab59 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StartSystemVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.systemvm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "startSystemVm", responseObject = SystemVmResponse.class, description = "Starts a system virtual machine.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StartSystemVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StartSystemVMCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java index 4bb533ce5b6..1d84382f5d2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/StopSystemVmCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.systemvm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "stopSystemVm", description = "Stops a system VM.", responseObject = SystemVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class StopSystemVmCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(StopSystemVmCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java index 12f80f32b06..5abe90e3f58 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/systemvm/UpgradeSystemVMCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.systemvm; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ import com.cloud.vm.VirtualMachine; + "The system vm must be in a \"Stopped\" state for " + "this command to take effect.", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpgradeSystemVMCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpgradeSystemVMCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java index 9b8d402864a..9a59efb19f2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.template; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "prepareTemplate", responseObject = TemplateResponse.class, description = "load template into primary storage", entityType = {VirtualMachineTemplate.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class PrepareTemplateCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(PrepareTemplateCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java index 95593714feb..5c0f1fc1cd2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficMonitorCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "addTrafficMonitor", description = "Adds Traffic Monitor Host for Direct Network Usage", responseObject = TrafficMonitorResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddTrafficMonitorCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AddTrafficMonitorCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java index 809129402a8..b1810676b74 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/AddTrafficTypeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "addTrafficType", description = "Adds traffic type to a physical network", responseObject = TrafficTypeResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddTrafficTypeCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddTrafficTypeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java index ff371d6e83d..8fdb3af399c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficMonitorCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteTrafficMonitor", description = "Deletes an traffic monitor host.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTrafficMonitorCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTrafficMonitorCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java index a728690a09d..a1e4ebda09a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/DeleteTrafficTypeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteTrafficType", description = "Deletes traffic type of a physical network", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTrafficTypeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTrafficTypeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java index 65b864f2ab6..491b0fe85ba 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/GenerateUsageRecordsCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.usage; import java.util.Date; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GenerateUsageRecordsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GenerateUsageRecordsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java index f3a65bbfffd..ed42bc42dbd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficMonitorsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.usage; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.host.Host; @APICommand(name = "listTrafficMonitors", description = "List traffic monitor Hosts.", responseObject = TrafficMonitorResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTrafficMonitorsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTrafficMonitorsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypeImplementorsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypeImplementorsCmd.java index 97f43155be6..1ad8872db96 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypeImplementorsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypeImplementorsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.usage; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -44,7 +43,6 @@ import com.cloud.utils.Pair; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTrafficTypeImplementorsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTrafficTypeImplementorsCmd.class); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypesCmd.java index 6e36ca3bd8d..d106a736fca 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListTrafficTypesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.usage; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listTrafficTypes", description = "Lists traffic types of a given physical network.", responseObject = ProviderResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTrafficTypesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListTrafficTypesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java index 15f9dd20e29..2772743c75a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/ListUsageTypesCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.usage; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; @@ -30,7 +29,6 @@ import com.cloud.user.Account; @APICommand(name = "listUsageTypes", description = "List Usage Types", responseObject = UsageTypeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListUsageTypesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListUsageTypesCmd.class.getName()); @Override public long getEntityOwnerId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/RemoveRawUsageRecordsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/RemoveRawUsageRecordsCmd.java index 710a11c0d7f..3e698e61442 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/RemoveRawUsageRecordsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/RemoveRawUsageRecordsCmd.java @@ -29,11 +29,9 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; @APICommand(name = "removeRawUsageRecords", description = "Safely removes raw records from cloud_usage table", responseObject = SuccessResponse.class, since = "4.6.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveRawUsageRecordsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RemoveRawUsageRecordsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java index 103e58c4e03..c7b3c2b433b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/usage/UpdateTrafficTypeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.usage; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "updateTrafficType", description = "Updates traffic type of a physical network", responseObject = TrafficTypeResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateTrafficTypeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateTrafficTypeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java index e8f5944e407..e2a2baecc86 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.user.User; @@ -35,7 +34,6 @@ import com.cloud.user.User; @APICommand(name = "createUser", description = "Creates a user for an account that already exists", responseObject = UserResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = true) public class CreateUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java index a4f13d5e9c7..ddf21affb53 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.user; import javax.inject.Inject; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.user.User; @APICommand(name = "deleteUser", description = "Deletes a user for an account", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteUserCmd.class.getName()); ///////////////////////////////////////////////////// @@ -86,11 +84,10 @@ public class DeleteUserCmd extends BaseCmd { public void execute() { CallContext.current().setEventDetails("UserId: " + getId()); boolean result = _regionService.deleteUser(this); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); - } else { + if (!result) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete user"); } + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java index f7a51d0b1d3..974c1c7bebe 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.user; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ import com.cloud.user.UserAccount; @APICommand(name = "disableUser", description = "Disables a user account", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DisableUserCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisableUserCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java index f13eac8f2a9..77d8d530daf 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.user; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.UserAccount; @APICommand(name = "enableUser", description = "Enables a user account", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class EnableUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(EnableUserCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java index 5fcad8068b1..3427cef3366 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.user; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -30,7 +29,6 @@ import com.cloud.user.UserAccount; @APICommand(name = "getUser", description = "Find user account by API key", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class GetUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserKeysCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserKeysCmd.java index 253a55652ea..3a3414d95d8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserKeysCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/GetUserKeysCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.RegisterResponse; import org.apache.cloudstack.api.response.UserResponse; import java.util.Map; -import org.apache.log4j.Logger; @APICommand(name = "getUserKeys", description = "This command allows the user to query the seceret and API keys for the account", @@ -44,7 +43,6 @@ public class GetUserKeysCmd extends BaseCmd{ @Parameter(name= ApiConstants.ID, type = CommandType.UUID, entityType = UserResponse.class, required = true, description = "ID of the user whose keys are required") private Long id; - public static final Logger s_logger = Logger.getLogger(GetUserKeysCmd.class.getName()); public Long getID(){ return id; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java index a516a30e769..ef9e3fa2240 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/ListUsersCmd.java @@ -20,7 +20,6 @@ import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceTag; import com.cloud.user.Account; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import java.util.List; @APICommand(name = "listUsers", description = "Lists user accounts", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListUsersCmd extends BaseListAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListUsersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java index df6ef4f7b0b..5c8bff0732a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/LockUserCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.user; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ import com.cloud.user.UserAccount; @APICommand(name = "lockUser", description = "Locks a user account", responseObject = UserResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class LockUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(LockUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/MoveUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/MoveUserCmd.java index 56552ba95df..e57258a4571 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/MoveUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/MoveUserCmd.java @@ -32,21 +32,19 @@ import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.region.RegionService; import org.apache.commons.lang3.ObjectUtils; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.user.User; import com.google.common.base.Preconditions; @APICommand(name = "moveUser", - description = "Moves a user to another account", + description = "Moves a user to another account in the same domain.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.11", authorized = {RoleType.Admin}) public class MoveUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(MoveUserCmd.class.getName()); ///////////////////////////////////////////////////// @@ -56,18 +54,18 @@ public class MoveUserCmd extends BaseCmd { type = CommandType.UUID, entityType = UserResponse.class, required = true, - description = "id of the user to be deleted") + description = "id of the user to be moved.") private Long id; @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, - description = "Creates the user under the specified account. If no account is specified, the username will be used as the account name.") + description = "Moves the user under the specified account. If no account name is specified, it is necessary to provide an account id.") private String accountName; @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, - description = "Creates the user under the specified domain. Has to be accompanied with the account parameter") + description = "Moves the user under the specified account. If no account id is specified, it is necessary to provide an account name.") private Long accountId; @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterCmd.java index 4199015b9ca..b3e7d2bec82 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.user; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.User; description = "This command allows a user to register for the developer API, returning a secret key and an API key. This request is made through the integration API port, so it is a privileged command and must be made on behalf of a user. It is up to the implementer just how the username and password are entered, and then how that translates to an integration API request. Both secret key and API key should be returned to the user", requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RegisterCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RegisterCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java index cb9f6e189f0..3f8d386d266 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.region.RegionService; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.user.User; @@ -37,7 +36,6 @@ import com.cloud.user.UserAccount; @APICommand(name = "updateUser", description = "Updates a user account", responseObject = UserResponse.class, requestHasSensitiveInfo = true, responseHasSensitiveInfo = true) public class UpdateUserCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java index 66aefd46966..c0ba99a8233 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/CreateVlanIpRangeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vlan; import com.cloud.utils.net.NetUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,10 +39,11 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.user.Account; +import java.util.Objects; + @APICommand(name = "createVlanIpRange", description = "Creates a VLAN IP range.", responseObject = VlanIpRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVlanIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateVlanIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// @@ -114,6 +114,9 @@ public class CreateVlanIpRangeCmd extends BaseCmd { @Parameter(name = ApiConstants.FOR_SYSTEM_VMS, type = CommandType.BOOLEAN, description = "true if IP range is set to system vms, false if not") private Boolean forSystemVms; + @Parameter(name = ApiConstants.FOR_NSX, type = CommandType.BOOLEAN, description = "true if the IP range is used for NSX resource", since = "4.20.0") + private boolean forNsx; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -154,8 +157,12 @@ public class CreateVlanIpRangeCmd extends BaseCmd { return startIp; } + public boolean isForNsx() { + return !Objects.isNull(forNsx) && forNsx; + } + public String getVlan() { - if (vlan == null || vlan.isEmpty()) { + if ((vlan == null || vlan.isEmpty()) && !isForNsx()) { vlan = "untagged"; } return vlan; @@ -226,10 +233,10 @@ public class CreateVlanIpRangeCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vlan ip range"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { - s_logger.info(ex); + logger.info(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DedicatePublicIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DedicatePublicIpRangeCmd.java index 7c122dfc22e..cac029f3aa1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DedicatePublicIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DedicatePublicIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vlan; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "dedicatePublicIpRange", description = "Dedicates a Public IP range to an account", responseObject = VlanIpRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicatePublicIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DedicatePublicIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java index 15f0bde37a1..7ab0b053004 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/DeleteVlanIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vlan; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -29,10 +28,9 @@ import org.apache.cloudstack.api.response.VlanIpRangeResponse; import com.cloud.user.Account; -@APICommand(name = "deleteVlanIpRange", description = "Creates a VLAN IP range.", responseObject = SuccessResponse.class, +@APICommand(name = "deleteVlanIpRange", description = "Deletes a VLAN IP range.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVlanIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVlanIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ListVlanIpRangesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ListVlanIpRangesCmd.java index 3b5370e3f15..c11b505c684 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ListVlanIpRangesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ListVlanIpRangesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.vlan; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listVlanIpRanges", description = "Lists all VLAN IP ranges.", responseObject = VlanIpRangeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVlanIpRangesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListVlanIpRangesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ReleasePublicIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ReleasePublicIpRangeCmd.java index 846433a60fc..be4cea41cd8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ReleasePublicIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/ReleasePublicIpRangeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vlan; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.user.Account; @APICommand(name = "releasePublicIpRange", description = "Releases a Public IP range back to the system pool", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleasePublicIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ReleasePublicIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/UpdateVlanIpRangeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/UpdateVlanIpRangeCmd.java index caaf4c5ae01..df6d99f8e2a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/UpdateVlanIpRangeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vlan/UpdateVlanIpRangeCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.VlanIpRangeResponse; -import org.apache.log4j.Logger; import com.cloud.dc.Vlan; import com.cloud.exception.ConcurrentOperationException; @@ -39,7 +38,6 @@ import com.cloud.utils.net.NetUtils; authorized = {RoleType.Admin}) public class UpdateVlanIpRangeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVlanIpRangeCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -149,7 +147,7 @@ public class UpdateVlanIpRangeCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to Update vlan ip range"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java index 1d53bbb39ad..ac63a5efac3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/AssignVMCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.vm; import java.util.List; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -46,7 +45,6 @@ import com.cloud.vm.VirtualMachine; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class AssignVMCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(AssignVMCmd.class.getName()); ///////////////////////////////////////////////////// @@ -133,7 +131,7 @@ public class AssignVMCmd extends BaseCmd { e.printStackTrace(); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (Exception e) { - s_logger.error("Failed to move vm due to: " + e.getStackTrace()); + logger.error("Failed to move vm due to: " + e.getStackTrace()); if (e.getMessage() != null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm due to " + e.getMessage()); } else if (e.getCause() != null) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java index acdc0e07427..6bb7657b86b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/DeployVMCmdByAdmin.java @@ -20,7 +20,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ClusterResponse; import org.apache.cloudstack.api.response.PodResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject.ResponseView; @@ -34,7 +33,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DeployVMCmdByAdmin extends DeployVMCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(DeployVMCmdByAdmin.class.getName()); @Parameter(name = ApiConstants.POD_ID, type = CommandType.UUID, entityType = PodResponse.class, description = "destination Pod ID to deploy the VM to - parameter available for root admin only", since = "4.13") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ExpungeVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ExpungeVMCmd.java index 4cd7f541c4e..a964e873bad 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ExpungeVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ExpungeVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -43,7 +42,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "expungeVirtualMachine", description = "Expunge a virtual machine. Once expunged, it cannot be recoverd.", responseObject = SuccessResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ExpungeVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ExpungeVMCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java index 98af820201c..8745ef12ce4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/GetVMUserDataCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VMUserDataResponse; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.uservm.UserVm; @@ -32,7 +31,6 @@ import com.cloud.uservm.UserVm; @APICommand(name = "getVirtualMachineUserData", description = "Returns user data associated with the VM", responseObject = VMUserDataResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetVMUserDataCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetVMUserDataCmd.class); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportUnmanagedInstanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportUnmanagedInstanceCmd.java index d632c786a16..dd897218a4d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportUnmanagedInstanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportUnmanagedInstanceCmd.java @@ -41,7 +41,6 @@ import org.apache.cloudstack.vm.VmImportService; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -65,7 +64,6 @@ import com.cloud.vm.VmDetailConstants; authorized = {RoleType.Admin}, since = "4.14.0") public class ImportUnmanagedInstanceCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(ImportUnmanagedInstanceCmd.class); @Inject public VmImportService vmImportService; @@ -203,8 +201,8 @@ public class ImportUnmanagedInstanceCmd extends BaseAsyncCmd { for (Map entry : (Collection>)nicNetworkList.values()) { String nic = entry.get(VmDetailConstants.NIC); String networkUuid = entry.get(VmDetailConstants.NETWORK); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); } if (StringUtils.isAnyEmpty(nic, networkUuid) || _entityMgr.findByUuid(Network.class, networkUuid) == null) { throw new InvalidParameterValueException(String.format("Network ID: %s for NIC ID: %s is invalid", networkUuid, nic)); @@ -221,8 +219,8 @@ public class ImportUnmanagedInstanceCmd extends BaseAsyncCmd { for (Map entry : (Collection>)nicIpAddressList.values()) { String nic = entry.get(VmDetailConstants.NIC); String ipAddress = StringUtils.defaultIfEmpty(entry.get(VmDetailConstants.IP4_ADDRESS), null); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("nic, '%s', gets ip, '%s'", nic, ipAddress)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("nic, '%s', gets ip, '%s'", nic, ipAddress)); } if (StringUtils.isEmpty(nic)) { throw new InvalidParameterValueException(String.format("NIC ID: '%s' is invalid for IP address mapping", nic)); @@ -246,8 +244,8 @@ public class ImportUnmanagedInstanceCmd extends BaseAsyncCmd { for (Map entry : (Collection>)dataDiskToDiskOfferingList.values()) { String disk = entry.get(VmDetailConstants.DISK); String offeringUuid = entry.get(VmDetailConstants.DISK_OFFERING); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("disk, '%s', gets offering, '%s'", disk, offeringUuid)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("disk, '%s', gets offering, '%s'", disk, offeringUuid)); } if (StringUtils.isAnyEmpty(disk, offeringUuid) || _entityMgr.findByUuid(DiskOffering.class, offeringUuid) == null) { throw new InvalidParameterValueException(String.format("Disk offering ID: %s for disk ID: %s is invalid", offeringUuid, disk)); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java index e8b9f3addde..1a34b7ea6cc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java @@ -39,7 +39,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.vm.VmImportService; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -52,7 +51,6 @@ import javax.inject.Inject; authorized = {RoleType.Admin}, since = "4.19.0") public class ImportVmCmd extends ImportUnmanagedInstanceCmd { - public static final Logger LOGGER = Logger.getLogger(ImportVmCmd.class); @Inject public VmImportService vmImportService; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListUnmanagedInstancesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListUnmanagedInstancesCmd.java index 13b6748c74d..6932aa383fa 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListUnmanagedInstancesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListUnmanagedInstancesCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.UnmanagedInstanceResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.vm.UnmanagedInstanceTO; import org.apache.cloudstack.vm.VmImportService; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -51,7 +50,6 @@ import com.cloud.user.Account; authorized = {RoleType.Admin}, since = "4.14.0") public class ListUnmanagedInstancesCmd extends BaseListCmd { - public static final Logger LOGGER = Logger.getLogger(ListUnmanagedInstancesCmd.class.getName()); @Inject public VmImportService vmImportService; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java index 5b3e607416b..b48941e7d17 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVMsCmdByAdmin.java @@ -27,14 +27,12 @@ import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.api.response.PodResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.log4j.Logger; import com.cloud.vm.VirtualMachine; @APICommand(name = "listVirtualMachines", description = "List the virtual machines owned by the account.", responseObject = UserVmResponse.class, responseView = ResponseView.Full, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListVMsCmdByAdmin extends ListVMsCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(ListVMsCmdByAdmin.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVmsForImportCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVmsForImportCmd.java index 88df04d9ef5..f40f1c0cb4a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVmsForImportCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListVmsForImportCmd.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.vm.UnmanagedInstanceTO; import org.apache.cloudstack.vm.VmImportService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -50,7 +49,6 @@ import javax.inject.Inject; authorized = {RoleType.Admin}, since = "4.19.0") public class ListVmsForImportCmd extends BaseListCmd { - public static final Logger LOGGER = Logger.getLogger(ListVmsForImportCmd.class.getName()); @Inject public VmImportService vmImportService; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java index b685b366cd1..8881a2bc354 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVMCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vm; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -50,7 +49,6 @@ import com.cloud.vm.VirtualMachine; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class MigrateVMCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateVMCmd.class.getName()); ///////////////////////////////////////////////////// @@ -184,10 +182,10 @@ public class MigrateVMCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate vm"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (VirtualMachineMigrationException | ConcurrentOperationException | ManagementServerException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java index 549d02b4579..b736e860636 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/MigrateVirtualMachineWithVolumeCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.HostResponse; import org.apache.cloudstack.api.response.SystemVmResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -52,7 +51,6 @@ import com.cloud.vm.VirtualMachine; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class MigrateVirtualMachineWithVolumeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MigrateVirtualMachineWithVolumeCmd.class.getName()); ///////////////////////////////////////////////////// @@ -157,7 +155,7 @@ public class MigrateVirtualMachineWithVolumeCmd extends BaseAsyncCmd { Host destinationHost = _resourceService.getHost(getHostId()); // OfflineVmwareMigration: destination host would have to not be a required parameter for stopped VMs if (destinationHost == null) { - s_logger.error(String.format("Unable to find the host with ID [%s].", getHostId())); + logger.error(String.format("Unable to find the host with ID [%s].", getHostId())); throw new InvalidParameterValueException("Unable to find the specified host to migrate the VM."); } return destinationHost; @@ -193,10 +191,10 @@ public class MigrateVirtualMachineWithVolumeCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate vm"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException | ManagementServerException | VirtualMachineMigrationException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java index b0698ed1e7a..f34d555dc70 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/RecoverVMCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vm; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "recoverVirtualMachine", description = "Recovers a virtual machine.", responseObject = UserVmResponse.class, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RecoverVMCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RecoverVMCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UnmanageVMInstanceCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UnmanageVMInstanceCmd.java index 20c7c536c45..bbcb8840f66 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UnmanageVMInstanceCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vm/UnmanageVMInstanceCmd.java @@ -40,7 +40,6 @@ import org.apache.cloudstack.api.response.UnmanageVMInstanceResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.vm.UnmanagedVMsManager; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -53,7 +52,6 @@ import javax.inject.Inject; since = "4.15.0") public class UnmanageVMInstanceCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(UnmanageVMInstanceCmd.class); @Inject private UnmanagedVMsManager unmanagedVMsManager; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DestroyVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DestroyVolumeCmdByAdmin.java index 44ce32f90c2..0840b4ce6f9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DestroyVolumeCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/DestroyVolumeCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ import com.cloud.storage.Volume; responseHasSensitiveInfo = true) public class DestroyVolumeCmdByAdmin extends DestroyVolumeCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(DestroyVolumeCmdByAdmin.class.getName()); @Override public void execute() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/RecoverVolumeCmdByAdmin.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/RecoverVolumeCmdByAdmin.java index f51aeec9719..e276c8a00b6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/RecoverVolumeCmdByAdmin.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/volume/RecoverVolumeCmdByAdmin.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -36,7 +35,6 @@ import com.cloud.storage.Volume; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RecoverVolumeCmdByAdmin extends RecoverVolumeCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(RecoverVolumeCmdByAdmin.class.getName()); @Override public void execute() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayByAdminCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayByAdminCmd.java index b5ba70cf5e2..1b2163853ec 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayByAdminCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreatePrivateGatewayByAdminCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vpc; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.network.vpc.VpcGateway; since = "4.17.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreatePrivateGatewayByAdminCmd extends CreatePrivateGatewayCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(CreatePrivateGatewayByAdminCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java index b69e7f4a828..dd5c815238e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmd.java @@ -24,12 +24,16 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.network.Network; +import com.cloud.network.VirtualRouterProvider; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -45,10 +49,18 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.network.vpc.VpcOffering; import com.cloud.user.Account; +import static com.cloud.network.Network.Service.Dhcp; +import static com.cloud.network.Network.Service.Dns; +import static com.cloud.network.Network.Service.Lb; +import static com.cloud.network.Network.Service.StaticNat; +import static com.cloud.network.Network.Service.SourceNat; +import static com.cloud.network.Network.Service.PortForwarding; +import static com.cloud.network.Network.Service.NetworkACL; +import static com.cloud.network.Network.Service.UserData; + @APICommand(name = "createVPCOffering", description = "Creates VPC offering", responseObject = VpcOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVPCOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -62,7 +74,6 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { @Parameter(name = ApiConstants.SUPPORTED_SERVICES, type = CommandType.LIST, - required = true, collectionType = CommandType.STRING, description = "services supported by the vpc offering") private List supportedServices; @@ -101,6 +112,24 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { since = "4.13") private List zoneIds; + @Parameter(name = ApiConstants.FOR_NSX, + type = CommandType.BOOLEAN, + description = "true if network offering is meant to be used for NSX, false otherwise.", + since = "4.20.0") + private Boolean forNsx; + + @Parameter(name = ApiConstants.NSX_MODE, + type = CommandType.STRING, + description = "Indicates the mode with which the network will operate. Valid option: NATTED or ROUTED", + since = "4.20.0") + private String nsxMode; + + @Parameter(name = ApiConstants.NSX_SUPPORT_LB, + type = CommandType.BOOLEAN, + description = "true if network offering for NSX VPC offering supports Load balancer service.", + since = "4.20.0") + private Boolean nsxSupportsLbService; + @Parameter(name = ApiConstants.ENABLE, type = CommandType.BOOLEAN, description = "set to true if the offering is to be enabled during creation. Default is false", @@ -120,21 +149,49 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { } public List getSupportedServices() { + if (!isForNsx() && CollectionUtils.isEmpty(supportedServices)) { + throw new InvalidParameterValueException("Supported services needs to be provided"); + } + if (isForNsx()) { + supportedServices = new ArrayList<>(List.of( + Dhcp.getName(), + Dns.getName(), + StaticNat.getName(), + SourceNat.getName(), + NetworkACL.getName(), + PortForwarding.getName(), + UserData.getName() + )); + if (getNsxSupportsLbService()) { + supportedServices.add(Lb.getName()); + } + } return supportedServices; } + public boolean isForNsx() { + return BooleanUtils.isTrue(forNsx); + } + + public String getNsxMode() { + return nsxMode; + } + + public boolean getNsxSupportsLbService() { + return org.apache.commons.lang3.BooleanUtils.isTrue(nsxSupportsLbService); + } + public Map> getServiceProviders() { - Map> serviceProviderMap = null; - if (serviceProviderList != null && !serviceProviderList.isEmpty()) { - serviceProviderMap = new HashMap>(); + Map> serviceProviderMap = new HashMap<>(); + if (serviceProviderList != null && !serviceProviderList.isEmpty() && !isForNsx()) { Collection> servicesCollection = serviceProviderList.values(); Iterator> iter = servicesCollection.iterator(); while (iter.hasNext()) { Map obj = iter.next(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("service provider entry specified: " + obj); + if (logger.isTraceEnabled()) { + logger.trace("service provider entry specified: " + obj); } - HashMap services = (HashMap)obj; + HashMap services = (HashMap) obj; String service = services.get("service"); String provider = services.get("provider"); List providerList = null; @@ -146,11 +203,31 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd { providerList.add(provider); serviceProviderMap.put(service, providerList); } + } else if (Boolean.TRUE.equals(forNsx)) { + getServiceProviderMapForNsx(serviceProviderMap); } return serviceProviderMap; } + private void getServiceProviderMapForNsx(Map> serviceProviderMap) { + List unsupportedServices = List.of("Vpn", "BaremetalPxeService", "SecurityGroup", "Connectivity", + "Gateway", "Firewall"); + List routerSupported = List.of("Dhcp", "Dns", "UserData"); + List allServices = Network.Service.listAllServices().stream().map(Network.Service::getName).collect(Collectors.toList()); + for (String service : allServices) { + if (unsupportedServices.contains(service)) + continue; + if (routerSupported.contains(service)) + serviceProviderMap.put(service, List.of(VirtualRouterProvider.Type.VPCVirtualRouter.name())); + else + serviceProviderMap.put(service, List.of(Network.Provider.Nsx.getName())); + } + if (!getNsxSupportsLbService()) { + serviceProviderMap.remove(Lb.getName()); + } + } + public Map> getServiceCapabilityList() { return serviceCapabilityList; } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java index d6c3cac68c7..d104edc381b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeletePrivateGatewayCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -41,7 +40,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class DeletePrivateGatewayCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePrivateGatewayCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java index aba4c857b0b..6aa0c3f3afc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/DeleteVPCOfferingCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.vpc; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteVPCOffering", description = "Deletes VPC offering", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVPCOfferingCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVPCOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListPrivateGatewaysCmdByAdminCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListPrivateGatewaysCmdByAdminCmd.java index 13a63e9cdd8..1211bd3311c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListPrivateGatewaysCmdByAdminCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/ListPrivateGatewaysCmdByAdminCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject; @@ -30,6 +29,5 @@ import com.cloud.network.vpc.VpcGateway; responseView = ResponseObject.ResponseView.Full, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPrivateGatewaysCmdByAdminCmd extends ListPrivateGatewaysCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(ListPrivateGatewaysCmdByAdminCmd.class.getName()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java index 12babad504e..b59837281ef 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/vpc/UpdateVPCOfferingCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.VpcOfferingResponse; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.domain.Domain; @@ -40,7 +39,6 @@ import com.cloud.user.Account; @APICommand(name = "updateVPCOffering", description = "Updates VPC offering", responseObject = VpcOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVPCOfferingCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVPCOfferingCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java index aca3e00d095..24660e41ed9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/CreateZoneCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.zone; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "createZone", description = "Creates a Zone.", responseObject = ZoneResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateZoneCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateZoneCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java index c530e999bf8..b89636c6fe5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/DeleteZoneCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.admin.zone; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteZone", description = "Deletes a Zone.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteZoneCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteZoneCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java index 264aea3f449..5d3f5dcd47f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/MarkDefaultZoneForAccountCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.admin.zone; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "markDefaultZoneForAccount", description = "Marks a default zone for this account", responseObject = AccountResponse.class, since = "4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class MarkDefaultZoneForAccountCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(MarkDefaultZoneForAccountCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java index 1379050cbf7..1b2793d3e15 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/admin/zone/UpdateZoneCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.admin.zone; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "updateZone", description = "Updates a Zone.", responseObject = ZoneResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateZoneCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateZoneCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java index 57c0e484843..2fbcb6df1cc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/AddAccountToProjectCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.response.ProjectRoleResponse; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -44,7 +43,6 @@ import com.cloud.projects.ProjectAccount; @APICommand(name = "addAccountToProject", description = "Adds account to a project", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddAccountToProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddAccountToProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java index 34935f506ec..5e0977938a3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteAccountFromProjectCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.account; import java.util.List; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.projects.Project; @APICommand(name = "deleteAccountFromProject", description = "Deletes account from the project", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAccountFromProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAccountFromProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteUserFromProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteUserFromProjectCmd.java index 596fb876008..8319911c5c8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteUserFromProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/DeleteUserFromProjectCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -41,7 +40,6 @@ import com.cloud.projects.Project; @APICommand(name = "deleteUserFromProject", description = "Deletes user from the project", responseObject = SuccessResponse.class, since = "4.15.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}) public class DeleteUserFromProjectCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(DeleteUserFromProjectCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java index 66a4d91172a..0a962b19e4f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmd.java @@ -31,7 +31,7 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; +import org.apache.commons.collections.CollectionUtils; import com.cloud.exception.InvalidParameterValueException; import com.cloud.server.ResourceIcon; @@ -41,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "listAccounts", description = "Lists accounts and provides detailed account information for listed accounts", responseObject = AccountResponse.class, responseView = ResponseView.Restricted, entityType = {Account.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListAccountsCmd.class.getName()); private static final String s_name = "listaccountsresponse"; ///////////////////////////////////////////////////// @@ -75,6 +74,9 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserC description = "flag to display the resource icon for accounts") private Boolean showIcon; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for resource type to return usage", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -118,10 +120,14 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserC return dv; } - public Boolean getShowIcon() { + public boolean getShowIcon() { return showIcon != null ? showIcon : false; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -136,12 +142,17 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd implements UserC ListResponse response = _queryService.searchForAccounts(this); response.setResponseName(getCommandName()); setResponseObject(response); - if (response != null && response.getCount() > 0 && getShowIcon()) { - updateAccountResponse(response.getResponses()); - } + updateAccountResponse(response.getResponses()); } - private void updateAccountResponse(List response) { + protected void updateAccountResponse(List response) { + if (CollectionUtils.isEmpty(response)) { + return; + } + _resourceLimitService.updateTaggedResourceLimitsAndCountsForAccounts(response, getTag()); + if (!getShowIcon()) { + return; + } for (AccountResponse accountResponse : response) { ResourceIcon resourceIcon = resourceIconManager.getByResourceTypeAndUuid(ResourceTag.ResourceObjectType.Account, accountResponse.getObjectId()); if (resourceIcon == null) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java index 3d50fc553b8..21aedc7d772 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/account/ListProjectAccountsCmd.java @@ -26,14 +26,12 @@ import org.apache.cloudstack.api.response.ProjectAccountResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ProjectRoleResponse; import org.apache.cloudstack.api.response.UserResponse; -import org.apache.log4j.Logger; import com.cloud.user.Account; @APICommand(name = "listProjectAccounts", description = "Lists project's accounts", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListProjectAccountsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListProjectAccountsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java index 75b83b40f3e..5ea14478516 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/AssociateIPAddrCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.address; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -65,7 +64,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AssociateIPAddrCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(AssociateIPAddrCmd.class.getName()); private static final String s_name = "associateipaddressresponse"; ///////////////////////////////////////////////////// @@ -325,11 +323,11 @@ public class AssociateIPAddrCmd extends BaseAsyncCreateCmd implements UserCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to allocate IP address"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientAddressCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java index f9bfcb253b4..f4c06e512f0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/DisassociateIPAddrCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "disassociateIpAddress", description = "Disassociates an IP address from the account.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, entityType = { IpAddress.class }) public class DisassociateIPAddrCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisassociateIPAddrCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java index 22eb70cc0c2..5760ca3ba1c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ListPublicIpAddressesCmd.java @@ -19,7 +19,7 @@ package org.apache.cloudstack.api.command.user.address; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; +import org.apache.commons.lang.BooleanUtils; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -43,7 +43,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listPublicIpAddresses", description = "Lists all public IP addresses", responseObject = IPAddressResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, entityType = { IpAddress.class }) public class ListPublicIpAddressesCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListPublicIpAddressesCmd.class.getName()); private static final String s_name = "listpublicipaddressesresponse"; @@ -106,6 +105,9 @@ public class ListPublicIpAddressesCmd extends BaseListRetrieveOnlyResourceCountC @Parameter(name = ApiConstants.FOR_DISPLAY, type = CommandType.BOOLEAN, description = "list resources by display flag; only ROOT admin is eligible to pass this parameter", since = "4.4", authorized = {RoleType.Admin}) private Boolean display; + @Parameter(name = ApiConstants.FOR_SYSTEM_VMS, type = CommandType.BOOLEAN, description = "true if range is dedicated for system VMs", since = "4.20.0") + private Boolean forSystemVMs; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -177,6 +179,10 @@ public class ListPublicIpAddressesCmd extends BaseListRetrieveOnlyResourceCountC return state; } + public boolean getForSystemVMs() { + return BooleanUtils.isTrue(forSystemVMs); + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReleaseIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReleaseIPAddrCmd.java index eb908300283..effe45c51ed 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReleaseIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReleaseIPAddrCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.address; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -41,7 +40,6 @@ import com.cloud.network.IpAddress; responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ReleaseIPAddrCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseIPAddrCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReserveIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReserveIPAddrCmd.java index 5e72986fb58..e323d413b9a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReserveIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/ReserveIPAddrCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.address; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -51,7 +50,6 @@ import com.cloud.user.Account; responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ReserveIPAddrCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ReserveIPAddrCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java index 7055e1d5cb2..194967e2e4a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/address/UpdateIPAddrCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.address; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -42,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "updateIpAddress", description = "Updates an IP address", responseObject = IPAddressResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, entityType = { IpAddress.class }) public class UpdateIPAddrCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateIPAddrCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java index 60dbc2a6e9a..ee0a38ef35d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.affinitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "createAffinityGroup", responseObject = AffinityGroupResponse.class, description = "Creates an affinity/anti-affinity group", entityType = {AffinityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateAffinityGroupCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateAffinityGroupCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java index c8967b08020..2f24158cadb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.affinitygroup; import org.apache.cloudstack.api.response.ProjectResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupResponse; @@ -40,7 +39,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteAffinityGroup", description = "Deletes affinity group", responseObject = SuccessResponse.class, entityType = {AffinityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAffinityGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAffinityGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java index 2d6f45cc06e..c90294171b3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.affinitygroup; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupTypeResponse; import org.apache.cloudstack.api.APICommand; @@ -31,7 +30,6 @@ import com.cloud.user.Account; @APICommand(name = "listAffinityGroupTypes", description = "Lists affinity group types available", responseObject = AffinityGroupTypeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAffinityGroupTypesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListAffinityGroupTypesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java index ed6c3145198..ee23e3794ce 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.affinitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroup; import org.apache.cloudstack.affinity.AffinityGroupResponse; @@ -31,7 +30,6 @@ import org.apache.cloudstack.api.response.UserVmResponse; @APICommand(name = "listAffinityGroups", description = "Lists affinity groups", responseObject = AffinityGroupResponse.class, entityType = {AffinityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAffinityGroupsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListAffinityGroupsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java index c70e4fbda66..6cd9bce6259 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/affinitygroup/UpdateVMAffinityGroupCmd.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.EnumSet; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.affinity.AffinityGroupResponse; @@ -55,7 +54,6 @@ import com.cloud.vm.VirtualMachine; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateVMAffinityGroupCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVMAffinityGroupCmd.class.getName()); private static final String s_name = "updatevirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java index eff93522b62..a000e265f93 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScalePolicyCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -43,7 +42,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateAutoScalePolicyCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateAutoScalePolicyCmd.class.getName()); private static final String s_name = "autoscalepolicyresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java index cdbe153f017..7c9362d4b69 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmGroupCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -45,7 +44,6 @@ import com.cloud.network.rules.LoadBalancer; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateAutoScaleVmGroupCmd.class.getName()); private static final String s_name = "autoscalevmgroupresponse"; @@ -233,7 +231,7 @@ public class CreateAutoScaleVmGroupCmd extends BaseAsyncCreateCmd { } } catch (Exception ex) { // TODO what will happen if Resource Layer fails in a step in between - s_logger.warn("Failed to create autoscale vm group", ex); + logger.warn("Failed to create autoscale vm group", ex); } finally { if (!success || vmGroup == null) { _autoScaleService.deleteAutoScaleVmGroup(getEntityId(), true); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java index db6ccd9ce53..f5b8c3da855 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateAutoScaleVmProfileCmd.java @@ -20,7 +20,6 @@ import java.util.HashMap; import java.util.Map; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -51,7 +50,6 @@ import com.cloud.network.as.AutoScaleVmProfile; responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateAutoScaleVmProfileCmd.class.getName()); private static final String s_name = "autoscalevmprofileresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java index 77bc15b1e0f..0ffb9afdac4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/CreateConditionCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -39,7 +38,6 @@ import com.cloud.network.as.Condition; @APICommand(name = "createCondition", description = "Creates a condition for VM auto scaling", responseObject = ConditionResponse.class, entityType = {Condition.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateConditionCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateConditionCmd.class.getName()); private static final String s_name = "conditionresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java index cf5ff366096..cee9460dbe6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScalePolicyCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteAutoScalePolicy", description = "Deletes a autoscale policy.", responseObject = SuccessResponse.class, entityType = {AutoScalePolicy.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAutoScalePolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAutoScalePolicyCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// @@ -93,7 +91,7 @@ public class DeleteAutoScalePolicyCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { - s_logger.warn("Failed to delete autoscale policy " + getId()); + logger.warn("Failed to delete autoscale policy " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete AutoScale Policy"); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java index badfcc0957e..6bf2157533e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteAutoScaleVmGroup", description = "Deletes a autoscale vm group.", responseObject = SuccessResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAutoScaleVmGroupCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// @@ -103,7 +101,7 @@ public class DeleteAutoScaleVmGroupCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { - s_logger.warn("Failed to delete autoscale vm group " + getId()); + logger.warn("Failed to delete autoscale vm group " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete autoscale vm group"); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java index 06bf7a9d378..b90f6aa8ffa 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteAutoScaleVmProfileCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteAutoScaleVmProfile", description = "Deletes a autoscale vm profile.", responseObject = SuccessResponse.class, entityType = {AutoScaleVmProfile.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteAutoScaleVmProfileCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteAutoScaleVmProfileCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// @@ -92,7 +90,7 @@ public class DeleteAutoScaleVmProfileCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { - s_logger.warn("Failed to delete autoscale vm profile " + getId()); + logger.warn("Failed to delete autoscale vm profile " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete autoscale vm profile"); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java index 840484e45ad..9590012e037 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DeleteConditionCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteCondition", description = "Removes a condition for VM auto scaling", responseObject = SuccessResponse.class, entityType = {Condition.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteConditionCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteConditionCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -59,14 +57,14 @@ public class DeleteConditionCmd extends BaseAsyncCmd { try { result = _autoScaleService.deleteCondition(getId()); } catch (ResourceInUseException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } if (result) { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { - s_logger.warn("Failed to delete condition " + getId()); + logger.warn("Failed to delete condition " + getId()); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete condition."); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java index b0daf2ec664..2414c0d82b6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/DisableAutoScaleVmGroupCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "disableAutoScaleVmGroup", description = "Disables an AutoScale Vm Group", responseObject = AutoScaleVmGroupResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DisableAutoScaleVmGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisableAutoScaleVmGroupCmd.class.getName()); private static final String s_name = "disableautoscalevmGroupresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java index b6f2a82ac49..96d329d3e0c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/EnableAutoScaleVmGroupCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "enableAutoScaleVmGroup", description = "Enables an AutoScale Vm Group", responseObject = AutoScaleVmGroupResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class EnableAutoScaleVmGroupCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(EnableAutoScaleVmGroupCmd.class.getName()); private static final String s_name = "enableautoscalevmGroupresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScalePoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScalePoliciesCmd.java index dc0baf4c786..4935889c525 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScalePoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScalePoliciesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.network.as.AutoScalePolicy; @APICommand(name = "listAutoScalePolicies", description = "Lists autoscale policies.", responseObject = AutoScalePolicyResponse.class, entityType = {AutoScalePolicy.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAutoScalePoliciesCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListAutoScalePoliciesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmGroupsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmGroupsCmd.java index 8404fbbb49f..6aa4abcccd8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmGroupsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmGroupsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -39,7 +38,6 @@ import com.cloud.network.as.AutoScaleVmGroup; @APICommand(name = "listAutoScaleVmGroups", description = "Lists autoscale vm groups.", responseObject = AutoScaleVmGroupResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAutoScaleVmGroupsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListAutoScaleVmGroupsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmProfilesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmProfilesCmd.java index 435471faf13..bcaea273ce8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmProfilesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListAutoScaleVmProfilesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ import com.cloud.network.as.AutoScaleVmProfile; @APICommand(name = "listAutoScaleVmProfiles", description = "Lists autoscale vm profiles.", responseObject = AutoScaleVmProfileResponse.class, entityType = {AutoScaleVmProfile.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListAutoScaleVmProfilesCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListAutoScaleVmProfilesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListConditionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListConditionsCmd.java index fc1ca7097c8..febf937d75f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListConditionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListConditionsCmd.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.network.as.Condition; @APICommand(name = "listConditions", description = "List Conditions for VM auto scaling", responseObject = ConditionResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListConditionsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListConditionsCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListCountersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListCountersCmd.java index 7da8bd40b61..d03584fd63d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListCountersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/ListCountersCmd.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "listCounters", description = "List the counters for VM auto scaling", responseObject = CounterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListCountersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListCountersCmd.class.getName()); private static final String s_name = "counterresponse"; // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java index a64b5cb1680..927a9191fcc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScalePolicyCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ import com.cloud.user.Account; @APICommand(name = "updateAutoScalePolicy", description = "Updates an existing autoscale policy.", responseObject = AutoScalePolicyResponse.class, entityType = {AutoScalePolicy.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateAutoScalePolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateAutoScalePolicyCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java index 87cd1fd3f4e..69ae8aa36aa 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmGroupCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -42,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "updateAutoScaleVmGroup", description = "Updates an existing autoscale vm group.", responseObject = AutoScaleVmGroupResponse.class, entityType = {AutoScaleVmGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateAutoScaleVmGroupCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateAutoScaleVmGroupCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java index 3e65d38e520..e8ca502b5cd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateAutoScaleVmProfileCmd.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.api.command.user.autoscale; import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -46,7 +45,6 @@ import com.cloud.user.Account; @APICommand(name = "updateAutoScaleVmProfile", description = "Updates an existing autoscale vm profile.", responseObject = AutoScaleVmProfileResponse.class, entityType = {AutoScaleVmProfile.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateAutoScaleVmProfileCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateAutoScaleVmProfileCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java index e946dd370c1..4ed8244ff0c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/autoscale/UpdateConditionCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.autoscale; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -41,7 +40,6 @@ import com.cloud.user.Account; authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0") public class UpdateConditionCmd extends BaseAsyncCmd { - public static final Logger LOGGER = Logger.getLogger(UpdateConditionCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -69,7 +67,7 @@ public class UpdateConditionCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); setResponseObject(response); } catch (ResourceInUseException ex) { - LOGGER.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/CreateBucketCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/CreateBucketCmd.java index e9a140cf46e..d2c91e57871 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/CreateBucketCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/CreateBucketCmd.java @@ -34,14 +34,12 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ObjectStoreResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "createBucket", responseObject = BucketResponse.class, description = "Creates a bucket in the specified object storage pool. ", responseView = ResponseView.Restricted, entityType = {Bucket.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreateBucketCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateBucketCmd.class.getName()); private static final String s_name = "createbucketresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/DeleteBucketCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/DeleteBucketCmd.java index bf9552b779e..8cd2790e4ae 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/DeleteBucketCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/DeleteBucketCmd.java @@ -30,13 +30,11 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.BucketResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "deleteBucket", description = "Deletes an empty Bucket.", responseObject = SuccessResponse.class, entityType = {Bucket.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class DeleteBucketCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteBucketCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/ListBucketsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/ListBucketsCmd.java index 897b9fc6696..bda0c7ed381 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/ListBucketsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/ListBucketsCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.BucketResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.StoragePoolResponse; -import org.apache.log4j.Logger; import java.util.List; @@ -36,7 +35,6 @@ import java.util.List; Bucket.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListBucketsCmd extends BaseListTaggedResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListBucketsCmd.class.getName()); private static final String s_name = "listbucketsresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/UpdateBucketCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/UpdateBucketCmd.java index b3b7e00770d..8e281b20e91 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/UpdateBucketCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/bucket/UpdateBucketCmd.java @@ -32,13 +32,11 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.BucketResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "updateBucket", description = "Updates Bucket properties", responseObject = SuccessResponse.class, entityType = {Bucket.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class UpdateBucketCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateBucketCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java index 65920a97c98..cf25dfaf5b5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/config/ListCapabilitiesCmd.java @@ -23,14 +23,12 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.response.CapabilitiesResponse; import org.apache.cloudstack.config.ApiServiceConfiguration; -import org.apache.log4j.Logger; import com.cloud.user.Account; @APICommand(name = "listCapabilities", description = "Lists capabilities", responseObject = CapabilitiesResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListCapabilitiesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListCapabilitiesCmd.class.getName()); @Override diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java index 11e84f1bef9..63b47e163b6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/consoleproxy/CreateConsoleEndpointCmd.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.consoleproxy.ConsoleAccessManager; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.utils.consoleproxy.ConsoleAccessUtils; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.Map; @@ -46,7 +45,6 @@ import java.util.Map; authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreateConsoleEndpointCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateConsoleEndpointCmd.class.getName()); @Inject private ConsoleAccessManager consoleManager; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java index cdff7882e65..669b1782e9e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ArchiveEventsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.event; import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ArchiveEventsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ArchiveEventsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java index 9d049ac5f06..c9c3f1d6955 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/event/DeleteEventsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.event; import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteEventsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteEventsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventTypesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventTypesCmd.java index dd0f5179278..e3f14f711ce 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventTypesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventTypesCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.event; import java.util.ArrayList; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; @@ -30,7 +29,6 @@ import com.cloud.user.Account; @APICommand(name = "listEventTypes", description = "List Event Types", responseObject = EventTypeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListEventTypesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListEventTypesCmd.class.getName()); @Override public long getEntityOwnerId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java index 89f1c7090e0..b5273c64922 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java @@ -24,14 +24,12 @@ import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.EventResponse; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; import com.cloud.event.Event; @APICommand(name = "listEvents", description = "A command to list events.", responseObject = EventResponse.class, entityType = {Event.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListEventsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListEventsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java index bedb073b880..8cbbcea6a59 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateEgressFirewallRuleCmd.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -48,7 +47,6 @@ import com.cloud.utils.net.NetUtils; @APICommand(name = "createEgressFirewallRule", description = "Creates a egress firewall rule for a given network ", responseObject = FirewallResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements FirewallRule { - public static final Logger s_logger = Logger.getLogger(CreateEgressFirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// @@ -257,10 +255,10 @@ public class CreateEgressFirewallRuleCmd extends BaseAsyncCreateCmd implements F } } catch (NetworkRuleConflictException ex) { String message = "Network rule conflict: "; - if (!s_logger.isTraceEnabled()) { - s_logger.info(message + ex.getMessage()); + if (!logger.isTraceEnabled()) { + logger.info(message + ex.getMessage()); } else { - s_logger.trace(message, ex); + logger.trace(message, ex); } throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java index b77041ee174..24b5a78c085 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.firewall; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -46,7 +45,6 @@ import com.cloud.utils.net.NetUtils; @APICommand(name = "createFirewallRule", description = "Creates a firewall rule for a given IP address", responseObject = FirewallResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements FirewallRule { - public static final Logger s_logger = Logger.getLogger(CreateFirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// @@ -248,7 +246,7 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal setEntityUuid(result.getUuid()); } } catch (NetworkRuleConflictException ex) { - s_logger.trace("Network Rule Conflict: ", ex); + logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage(), ex); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java index 5e136210150..3545b3d21fb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreatePortForwardingRuleCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.firewall; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -54,7 +53,6 @@ import com.cloud.vm.VirtualMachine; VirtualMachine.class, IpAddress.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements PortForwardingRule { - public static final Logger s_logger = Logger.getLogger(CreatePortForwardingRuleCmd.class.getName()); // /////////////////////////////////////////////////// @@ -352,7 +350,7 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements P setEntityId(result.getId()); setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException ex) { - s_logger.trace("Network Rule Conflict: ", ex); + logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage(), ex); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java index f0ba8a92d01..b93d943eab9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteEgressFirewallRuleCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.firewall; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ import com.cloud.network.rules.FirewallRule; @APICommand(name = "deleteEgressFirewallRule", description = "Deletes an egress firewall rule", responseObject = SuccessResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteEgressFirewallRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteEgressFirewallRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java index da1f6b62eca..c4a4dfd75cb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeleteFirewallRuleCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.firewall; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -40,7 +39,6 @@ import com.cloud.network.rules.FirewallRule; @APICommand(name = "deleteFirewallRule", description = "Deletes a firewall rule", responseObject = SuccessResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteFirewallRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteFirewallRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java index aebf8da159b..267d18d8a8a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/DeletePortForwardingRuleCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.firewall; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ import com.cloud.network.rules.PortForwardingRule; @APICommand(name = "deletePortForwardingRule", description = "Deletes a port forwarding rule", responseObject = SuccessResponse.class, entityType = {PortForwardingRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeletePortForwardingRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePortForwardingRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java index c8c0e85252b..aa0fd28fdec 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListEgressFirewallRulesCmd.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.api.command.user.firewall; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -39,7 +38,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listEgressFirewallRules", description = "Lists all egress firewall rules for network ID.", responseObject = FirewallResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListEgressFirewallRulesCmd extends BaseListTaggedResourcesCmd implements IListFirewallRulesCmd { - public static final Logger s_logger = Logger.getLogger(ListEgressFirewallRulesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListFirewallRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListFirewallRulesCmd.java index f79b77893d2..19a05b15890 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListFirewallRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListFirewallRulesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.firewall; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -38,7 +37,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listFirewallRules", description = "Lists all firewall rules for an IP address.", responseObject = FirewallResponse.class, entityType = {FirewallRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListFirewallRulesCmd extends BaseListTaggedResourcesCmd implements IListFirewallRulesCmd { - public static final Logger s_logger = Logger.getLogger(ListFirewallRulesCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListPortForwardingRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListPortForwardingRulesCmd.java index 3a942c485fc..a2e9152a9e4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListPortForwardingRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/ListPortForwardingRulesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.firewall; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listPortForwardingRules", description = "Lists all port forwarding rules for an IP address.", responseObject = FirewallRuleResponse.class, entityType = {PortForwardingRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPortForwardingRulesCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListPortForwardingRulesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java index 1aa06074367..a8db4ec2b29 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateEgressFirewallRuleCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.FirewallResponse; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -37,7 +36,6 @@ import com.cloud.network.rules.FirewallRule.TrafficType; @APICommand(name = "updateEgressFirewallRule", description = "Updates egress firewall rule ", responseObject = FirewallResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateEgressFirewallRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateEgressFirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java index b39efa01350..89c9bc891eb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdateFirewallRuleCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.FirewallResponse; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -37,7 +36,6 @@ import com.cloud.network.rules.FirewallRule.TrafficType; @APICommand(name = "updateFirewallRule", description = "Updates firewall rule ", responseObject = FirewallResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateFirewallRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateFirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java index 2afc0bb66ad..3fb66bd861f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/firewall/UpdatePortForwardingRuleCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -38,7 +37,6 @@ import com.cloud.utils.net.Ip; description = "Updates a port forwarding rule. Only the private port and the virtual machine can be updated.", entityType = {PortForwardingRule.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdatePortForwardingRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdatePortForwardingRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCategoriesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCategoriesCmd.java index 18a209011c1..c74514d662c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCategoriesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCategoriesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.guest; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listOsCategories", description = "Lists all supported OS categories for this cloud.", responseObject = GuestOSCategoryResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListGuestOsCategoriesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListGuestOsCategoriesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCmd.java index 9d6cd438561..b31a4669220 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/guest/ListGuestOsCmd.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listOsTypes", description = "Lists all supported OS types for this cloud.", responseObject = GuestOSResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListGuestOsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListGuestOsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java index d4c59cd8d47..4e3cf4621ef 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/CreateIpv6FirewallRuleCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -50,7 +49,6 @@ import com.cloud.utils.net.NetUtils; responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreateIpv6FirewallRuleCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateIpv6FirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// @@ -224,7 +222,7 @@ public class CreateIpv6FirewallRuleCmd extends BaseAsyncCreateCmd { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.trace("Network Rule Conflict: ", e); + logger.trace("Network Rule Conflict: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage(), e); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/DeleteIpv6FirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/DeleteIpv6FirewallRuleCmd.java index 5e176a3fabf..aaee19b5948 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/DeleteIpv6FirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/DeleteIpv6FirewallRuleCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceUnavailableException; @@ -41,7 +40,6 @@ import com.cloud.user.Account; responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class DeleteIpv6FirewallRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteIpv6FirewallRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/ListIpv6FirewallRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/ListIpv6FirewallRulesCmd.java index 23941316275..7ade2e3ed04 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/ListIpv6FirewallRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/ListIpv6FirewallRulesCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.FirewallResponse; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.NetworkResponse; -import org.apache.log4j.Logger; import com.cloud.network.rules.FirewallRule; import com.cloud.utils.Pair; @@ -41,7 +40,6 @@ import com.cloud.utils.Pair; responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListIpv6FirewallRulesCmd extends BaseListTaggedResourcesCmd implements IListFirewallRulesCmd { - public static final Logger s_logger = Logger.getLogger(ListIpv6FirewallRulesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/UpdateIpv6FirewallRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/UpdateIpv6FirewallRuleCmd.java index 49765c58daf..2d63d703dc5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/UpdateIpv6FirewallRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ipv6/UpdateIpv6FirewallRuleCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.FirewallResponse; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceUnavailableException; @@ -41,7 +40,6 @@ import com.cloud.user.Account; responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class UpdateIpv6FirewallRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateIpv6FirewallRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java index cdc72de4a10..d795fbabb52 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/AttachIsoCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.iso; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.uservm.UserVm; @APICommand(name = "attachIso", description = "Attaches an ISO to a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class AttachIsoCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(AttachIsoCmd.class.getName()); private static final String s_name = "attachisoresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/CopyIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/CopyIsoCmd.java index b7c13ce4adb..2db7b7e1eb9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/CopyIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/CopyIsoCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ResponseObject.ResponseView; @@ -26,6 +25,5 @@ import org.apache.cloudstack.api.response.TemplateResponse; @APICommand(name = "copyIso", description = "Copies an ISO from one zone to another.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CopyIsoCmd extends CopyTemplateCmd { - public static final Logger s_logger = Logger.getLogger(CopyIsoCmd.class.getName()); private static final String s_name = "copyisoresponse"; } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java index 504e7c1b5cf..feae31026b9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DeleteIsoCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteIso", description = "Deletes an ISO file.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteIsoCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteIsoCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java index e3b22c4a49f..292e1c6f099 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/DetachIsoCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.iso; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.uservm.UserVm; @APICommand(name = "detachIso", description = "Detaches any ISO file (if any) currently attached to a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DetachIsoCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(DetachIsoCmd.class.getName()); private static final String s_name = "detachisoresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java index 03ba2fab722..5db680066a6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ExtractIsoCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "extractIso", description = "Extracts an ISO", responseObject = ExtractResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ExtractIsoCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ExtractIsoCmd.class.getName()); ///////////////////////////////////////////////////// @@ -130,7 +128,7 @@ public class ExtractIsoCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract ISO"); } } catch (InternalErrorException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java index e1759566299..01a47f22b72 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/GetUploadParamsForIsoCmd.java @@ -117,7 +117,7 @@ public class GetUploadParamsForIsoCmd extends AbstractGetUploadParamsCmd { response.setResponseName(getCommandName()); setResponseObject(response); } catch (ResourceAllocationException | MalformedURLException e) { - s_logger.error("Exception while registering ISO", e); + logger.error("Exception while registering ISO", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Exception while registering ISO: " + e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java index fbbe0880aef..6f220c774b8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsoPermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseListTemplateOrIsoPermissionsCmd; @@ -40,10 +39,6 @@ public class ListIsoPermissionsCmd extends BaseListTemplateOrIsoPermissionsCmd i return "iso"; } - @Override - protected Logger getLogger() { - return Logger.getLogger(ListIsoPermissionsCmd.class.getName()); - } @Override protected boolean templateIsCorrectType(VirtualMachineTemplate template) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java index f723cb93ae9..04dcbf8ca96 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.iso; import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceTag; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -41,7 +40,6 @@ import java.util.List; @APICommand(name = "listIsos", description = "Lists all available ISO files.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListIsosCmd extends BaseListTaggedResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListIsosCmd.class.getName()); private static final String s_name = "listisosresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java index 1d750038042..becfdcd653d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.ResourceAllocationException; import com.cloud.template.VirtualMachineTemplate; @@ -43,7 +42,6 @@ import com.cloud.template.VirtualMachineTemplate; @APICommand(name = "registerIso", responseObject = TemplateResponse.class, description = "Registers an existing ISO into the CloudStack Cloud.", responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RegisterIsoCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RegisterIsoCmd.class.getName()); private static final String s_name = "registerisoresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java index 58c475c661e..95d9feed7e3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.iso; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; @@ -33,7 +32,6 @@ import com.cloud.user.Account; @APICommand(name = "updateIso", description = "Updates an ISO file.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateIsoCmd extends BaseUpdateTemplateOrIsoCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateIsoCmd.class.getName()); private static final String s_name = "updateisoresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoPermissionsCmd.java index dd07faf9a87..02ada253fd2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/iso/UpdateIsoPermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.iso; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoPermissionsCmd; @@ -33,10 +32,6 @@ public class UpdateIsoPermissionsCmd extends BaseUpdateTemplateOrIsoPermissionsC return "updateisopermissionsresponse"; } - @Override - protected Logger getLogger() { - return Logger.getLogger(UpdateIsoPermissionsCmd.class.getName()); - } @Override public long getEntityOwnerId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/job/QueryAsyncJobResultCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/job/QueryAsyncJobResultCmd.java index f578078e3a1..3d328543dc2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/job/QueryAsyncJobResultCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/job/QueryAsyncJobResultCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.job; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -29,7 +28,6 @@ import com.cloud.user.Account; @APICommand(name = "queryAsyncJobResult", description = "Retrieves the current status of asynchronous job.", responseObject = AsyncJobResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QueryAsyncJobResultCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QueryAsyncJobResultCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignCertToLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignCertToLoadBalancerCmd.java index 50d69c8d3ae..4f9d2f37d13 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignCertToLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignCertToLoadBalancerCmd.java @@ -17,7 +17,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AssignCertToLoadBalancerCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AssignCertToLoadBalancerCmd.class.getName()); @Parameter(name = ApiConstants.LBID, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java index c245ab236fe..81a52ce2dfe 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/AssignToLoadBalancerRuleCmd.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -51,7 +50,6 @@ import com.cloud.vm.VirtualMachine; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AssignToLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AssignToLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateApplicationLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateApplicationLoadBalancerCmd.java index 8c63c8f7951..2199dfb4e8b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateApplicationLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateApplicationLoadBalancerCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InsufficientAddressCapacityException; @@ -44,7 +43,6 @@ import com.cloud.utils.net.NetUtils; @APICommand(name = "createLoadBalancer", description = "Creates an internal load balancer", responseObject = ApplicationLoadBalancerResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateApplicationLoadBalancerCmd.class.getName()); ///////////////////////////////////////////////////// @@ -202,7 +200,7 @@ public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd { setResponseObject(lbResponse); lbResponse.setResponseName(getCommandName()); } catch (Exception ex) { - s_logger.warn("Failed to create load balancer due to exception ", ex); + logger.warn("Failed to create load balancer due to exception ", ex); } finally { if (rule == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create load balancer"); @@ -220,13 +218,13 @@ public class CreateApplicationLoadBalancerCmd extends BaseAsyncCreateCmd { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } catch (InsufficientAddressCapacityException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } catch (InsufficientVirtualNetworkCapacityException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java index 57cb8078738..c24a5f19f07 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBHealthCheckPolicyCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.LBHealthCheckResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -44,7 +43,6 @@ import com.cloud.user.Account; responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class CreateLBHealthCheckPolicyCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateLBHealthCheckPolicyCmd.class.getName()); // /////////////////////////////////////////////////// @@ -181,7 +179,7 @@ public class CreateLBHealthCheckPolicyCmd extends BaseAsyncCreateCmd { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (InvalidParameterValueException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java index 66a15984ae4..c6b5036bc95 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLBStickinessPolicyCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.LBStickinessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -44,7 +43,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateLBStickinessPolicyCmd.class.getName()); private static final String s_name = "createLBStickinessPolicy"; @@ -164,7 +162,7 @@ public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd { this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java index ef9e46f3a76..f86d1ae85da 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/CreateLoadBalancerRuleCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.LoadBalancerResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.dc.DataCenter.NetworkType; @@ -52,7 +51,6 @@ import com.cloud.utils.net.NetUtils; @APICommand(name = "createLoadBalancerRule", description = "Creates a load balancer rule", responseObject = LoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements LoadBalancer */{ - public static final Logger s_logger = Logger.getLogger(CreateLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// @@ -284,7 +282,7 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements L } lbResponse.setResponseName(getCommandName()); } catch (Exception ex) { - s_logger.warn("Failed to create LB rule due to exception ", ex); + logger.warn("Failed to create LB rule due to exception ", ex); } finally { if (!success || rule == null) { @@ -309,10 +307,10 @@ public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements L this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } catch (InsufficientAddressCapacityException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } catch (InvalidParameterValueException e) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteApplicationLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteApplicationLoadBalancerCmd.java index 912c760168b..410df086393 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteApplicationLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteApplicationLoadBalancerCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -36,7 +35,6 @@ import com.cloud.exception.InvalidParameterValueException; @APICommand(name = "deleteLoadBalancer", description = "Deletes an internal load balancer", responseObject = SuccessResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteApplicationLoadBalancerCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteApplicationLoadBalancerCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java index 159d6b21cbc..3cf1f345037 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBHealthCheckPolicyCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteLBHealthCheckPolicy", description = "Deletes a load balancer health check policy.", responseObject = SuccessResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteLBHealthCheckPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteLBHealthCheckPolicyCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java index 10c342911b4..5d04de3cae5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLBStickinessPolicyCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteLBStickinessPolicy", description = "Deletes a load balancer stickiness policy.", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteLBStickinessPolicyCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteLBStickinessPolicyCmd.class.getName()); private static final String s_name = "deleteLBstickinessrruleresponse"; // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java index f05d4cd2be3..b4079430ee3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteLoadBalancerRuleCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteLoadBalancerRule", description = "Deletes a load balancer rule.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteSslCertCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteSslCertCmd.java index 3db733182a1..887007e537e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteSslCertCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/DeleteSslCertCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.loadbalancer; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "deleteSslCert", description = "Delete a certificate to CloudStack", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSslCertCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSslCertCmd.class.getName()); @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListApplicationLoadBalancersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListApplicationLoadBalancersCmd.java index ad68b301844..d54f3e1155e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListApplicationLoadBalancersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListApplicationLoadBalancersCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.rules.LoadBalancerContainer.Scheme; @@ -38,7 +37,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listLoadBalancers", description = "Lists internal load balancers", responseObject = ApplicationLoadBalancerResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListApplicationLoadBalancersCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListApplicationLoadBalancersCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java index 1c1f5d1f9af..cb2cdb446d1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBHealthCheckPoliciesCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.LBHealthCheckResponse; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; @@ -37,7 +36,6 @@ import com.cloud.network.rules.LoadBalancer; @APICommand(name = "listLBHealthCheckPolicies", description = "Lists load balancer health check policies.", responseObject = LBHealthCheckResponse.class, since = "4.2.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListLBHealthCheckPoliciesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListLBHealthCheckPoliciesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java index 3d08d925797..a48e2ea37b7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLBStickinessPoliciesCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.LBStickinessResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.network.rules.LoadBalancer; import com.cloud.network.rules.StickinessPolicy; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "listLBStickinessPolicies", description = "Lists load balancer stickiness policies.", responseObject = LBStickinessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListLBStickinessPoliciesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListLBStickinessPoliciesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java index 723e0efec12..3bfc68a95ba 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRuleInstancesCmd.java @@ -23,7 +23,6 @@ import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.LoadBalancerRuleVmMapResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ import com.cloud.utils.Pair; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListLoadBalancerRuleInstancesCmd.class.getName()); private static final String s_name = "listloadbalancerruleinstancesresponse"; @@ -97,10 +95,10 @@ public class ListLoadBalancerRuleInstancesCmd extends BaseListCmd implements Use public void execute() { Pair, List> vmServiceMap = _lbService.listLoadBalancerInstances(this); List result = vmServiceMap.first(); - s_logger.debug(String.format("A total of [%s] user VMs were obtained when listing the load balancer instances: [%s].", result.size(), result)); + logger.debug(String.format("A total of [%s] user VMs were obtained when listing the load balancer instances: [%s].", result.size(), result)); List serviceStates = vmServiceMap.second(); - s_logger.debug(String.format("A total of [%s] service states were obtained when listing the load balancer instances: [%s].", serviceStates.size(), serviceStates)); + logger.debug(String.format("A total of [%s] service states were obtained when listing the load balancer instances: [%s].", serviceStates.size(), serviceStates)); if (!isListLbVmip()) { ListResponse response = new ListResponse<>(); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRulesCmd.java index 51a8fa4bfc8..b8b82f0c4a8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListLoadBalancerRulesCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.LoadBalancerResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.network.rules.LoadBalancer; import com.cloud.utils.Pair; @@ -39,7 +38,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listLoadBalancerRules", description = "Lists load balancer rules.", responseObject = LoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListLoadBalancerRulesCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListLoadBalancerRulesCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java index 3f422801780..1bc300fdc69 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/ListSslCertsCmd.java @@ -20,7 +20,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "listSslCerts", description = "Lists SSL certificates", responseObject = SslCertResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSslCertsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListSslCertsCmd.class.getName()); @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveCertFromLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveCertFromLoadBalancerCmd.java index 38593629f78..dfaafe89923 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveCertFromLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveCertFromLoadBalancerCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.loadbalancer; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveCertFromLoadBalancerCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveCertFromLoadBalancerCmd.class.getName()); @Parameter(name = ApiConstants.LBID, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java index 01c30c4b3c7..d29f2676ed5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/RemoveFromLoadBalancerRuleCmd.java @@ -24,7 +24,6 @@ import java.util.Iterator; import java.util.ArrayList; import com.cloud.vm.VirtualMachine; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -49,7 +48,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveFromLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveFromLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java index 27d49096ed6..d129cd8988f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateApplicationLoadBalancerCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRule; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -34,7 +33,6 @@ import com.cloud.network.rules.FirewallRule; @APICommand(name = "updateLoadBalancer", description = "Updates an internal load balancer", responseObject = ApplicationLoadBalancerResponse.class, since = "4.4.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateApplicationLoadBalancerCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateApplicationLoadBalancerCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBHealthCheckPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBHealthCheckPolicyCmd.java index b6bb59e60dc..fdd98fc3a0a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBHealthCheckPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBHealthCheckPolicyCmd.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.LBHealthCheckResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.rules.HealthCheckPolicy; @@ -30,7 +29,6 @@ import com.cloud.user.Account; @APICommand(name = "updateLBHealthCheckPolicy", description = "Updates load balancer health check policy", responseObject = LBHealthCheckResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateLBHealthCheckPolicyCmd extends BaseAsyncCustomIdCmd{ - public static final Logger s_logger = Logger.getLogger(UpdateLBHealthCheckPolicyCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBStickinessPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBStickinessPolicyCmd.java index 2b1f1cc38f6..b2137cf262d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBStickinessPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLBStickinessPolicyCmd.java @@ -19,7 +19,6 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.LBStickinessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.rules.LoadBalancer; @@ -29,7 +28,6 @@ import com.cloud.user.Account; @APICommand(name = "updateLBStickinessPolicy", description = "Updates load balancer stickiness policy", responseObject = LBStickinessResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateLBStickinessPolicyCmd extends BaseAsyncCustomIdCmd{ - public static final Logger s_logger = Logger.getLogger(UpdateLBStickinessPolicyCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java index b09c01adee6..25254ba9eb7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.FirewallRuleResponse; import org.apache.cloudstack.api.response.LoadBalancerResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "updateLoadBalancerRule", description = "Updates load balancer", responseObject = LoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateLoadBalancerRuleCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UploadSslCertCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UploadSslCertCmd.java index abafde85615..e51b4dee9db 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UploadSslCertCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UploadSslCertCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.loadbalancer; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -41,7 +40,6 @@ import org.apache.cloudstack.network.tls.CertService; @APICommand(name = "uploadSslCert", description = "Upload a certificate to CloudStack", responseObject = SslCertResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UploadSslCertCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UploadSslCertCmd.class.getName()); @Inject diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java index 62c4906b1b7..e883a7a0e4d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/CreateIpForwardingRuleCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.nat; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -45,7 +44,6 @@ import com.cloud.user.Account; @APICommand(name = "createIpForwardingRule", description = "Creates an IP forwarding rule", responseObject = FirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements StaticNatRule { - public static final Logger s_logger = Logger.getLogger(CreateIpForwardingRuleCmd.class.getName()); ///////////////////////////////////////////////////// @@ -150,7 +148,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Sta setEntityId(rule.getId()); setEntityUuid(rule.getUuid()); } catch (NetworkRuleConflictException e) { - s_logger.info("Unable to create static NAT rule due to ", e); + logger.info("Unable to create static NAT rule due to ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java index 5b1335ccf22..e4c16a31751 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DeleteIpForwardingRuleCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.nat; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -37,7 +36,6 @@ import com.cloud.network.rules.FirewallRule; @APICommand(name = "deleteIpForwardingRule", description = "Deletes an IP forwarding rule", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteIpForwardingRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteIpForwardingRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java index 9afdfa3642e..2bee7dfcc89 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/DisableStaticNatCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.nat; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.network.IpAddress; @APICommand(name = "disableStaticNat", description = "Disables static rule for given IP address", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DisableStaticNatCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DisableStaticNatCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java index ba97356582a..48c6cc20bf1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.nat; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.uservm.UserVm; @APICommand(name = "enableStaticNat", description = "Enables static NAT for given IP address", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class EnableStaticNatCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(EnableStaticNatCmd.class.getName()); ///////////////////////////////////////////////////// @@ -133,8 +131,8 @@ public class EnableStaticNatCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to enable static NAT"); } } catch (NetworkRuleConflictException ex) { - s_logger.info("Network rule conflict: " + ex.getMessage()); - s_logger.trace("Network Rule Conflict: ", ex); + logger.info("Network rule conflict: " + ex.getMessage()); + logger.trace("Network Rule Conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/ListIpForwardingRulesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/ListIpForwardingRulesCmd.java index 5e9da328bc8..89981a6453b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/nat/ListIpForwardingRulesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/nat/ListIpForwardingRulesCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.nat; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listIpForwardingRules", description = "List the IP forwarding rules", responseObject = FirewallRuleResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListIpForwardingRulesCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListIpForwardingRulesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java index 70e67151c1d..127661b1820 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -43,7 +42,6 @@ import com.cloud.utils.net.NetUtils; @APICommand(name = "createNetworkACL", description = "Creates a ACL rule in the given network (the network has to belong to VPC)", responseObject = NetworkACLItemResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkACLCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkACLCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java index e5dbcc7b6d1..cd25a604e77 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkACLListCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.VpcResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -41,7 +40,6 @@ import com.cloud.user.Account; responseObject = NetworkACLResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkACLListCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkACLListCmd.class.getName()); // /////////////////////////////////////////////////// @@ -130,7 +128,7 @@ public class CreateNetworkACLListCmd extends BaseAsyncCreateCmd { } else { account = CallContext.current().getCallingAccount(); if (!Account.Type.ADMIN.equals(account.getType())) { - s_logger.warn(String.format("Only Root Admin can create global ACLs. Account [%s] cannot create any global ACL.", account)); + logger.warn(String.format("Only Root Admin can create global ACLs. Account [%s] cannot create any global ACL.", account)); throw new PermissionDeniedException("Only Root Admin can create global ACLs."); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java index ca379fb1596..2395339a477 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.network; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -51,7 +50,6 @@ import com.cloud.utils.net.NetUtils; @APICommand(name = "createNetwork", description = "Creates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateNetworkCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateNetworkCmd.class.getName()); private static final String s_name = "createnetworkresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkPermissionsCmd.java index 4a1f65ba7a2..1df472cbb22 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/CreateNetworkPermissionsCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network; @@ -43,7 +42,6 @@ import java.util.List; since = "4.17.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreateNetworkPermissionsCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(CreateNetworkPermissionsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java index f171492b2f6..ca42626eacb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.network; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteNetworkACL", description = "Deletes a network ACL", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkACLCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkACLCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java index 5c24efae6eb..45bc86e8c91 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkACLListCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.network; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteNetworkACLList", description = "Deletes a network ACL", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkACLListCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkACLListCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java index 5f15c23e23f..8e8e18c6702 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/DeleteNetworkCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -37,7 +36,6 @@ import com.cloud.network.Network; @APICommand(name = "deleteNetwork", description = "Deletes a network", responseObject = SuccessResponse.class, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteNetworkCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLListsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLListsCmd.java index f3a06142d78..c88f956943b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLListsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLListsCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.VpcResponse; -import org.apache.log4j.Logger; import com.cloud.network.vpc.NetworkACL; import com.cloud.utils.Pair; @@ -36,7 +35,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listNetworkACLLists", description = "Lists all network ACLs", responseObject = NetworkACLResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkACLListsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkACLListsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLsCmd.java index 945142f4df0..1ef2b9b7bfb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkACLsCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.NetworkACLItemResponse; import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.NetworkResponse; -import org.apache.log4j.Logger; import com.cloud.network.vpc.NetworkACLItem; import com.cloud.utils.Pair; @@ -36,7 +35,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listNetworkACLs", description = "Lists all network ACL items", responseObject = NetworkACLItemResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkACLsCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkACLsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java index 70c01fd1d88..33f452008d9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.NetworkOfferingResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.offering.NetworkOffering; import com.cloud.utils.Pair; @@ -36,7 +35,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listNetworkOfferings", description = "Lists all available network offerings.", responseObject = NetworkOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworkOfferingsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworkOfferingsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkPermissionsCmd.java index 9e6b01d3676..6ea4937e115 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkPermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -42,7 +41,6 @@ import java.util.List; since = "4.17.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListNetworkPermissionsCmd extends BaseCmd implements UserCmd { - public static final Logger LOGGER = Logger.getLogger(ListNetworkPermissionsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmd.java new file mode 100644 index 00000000000..a7c359d66c2 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmd.java @@ -0,0 +1,107 @@ +// 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 org.apache.cloudstack.api.command.user.network; + +import com.cloud.utils.net.NetworkProtocols; +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.NetworkProtocolResponse; +import org.apache.cloudstack.context.CallContext; + +import java.util.ArrayList; +import java.util.List; + +@APICommand(name = "listNetworkProtocols", description = "Lists details of network protocols", responseObject = NetworkProtocolResponse.class, + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, + authorized = { RoleType.Admin, RoleType.DomainAdmin, RoleType.ResourceAdmin, RoleType.User}, since = "4.19.0") +public class ListNetworkProtocolsCmd extends BaseCmd { + + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.OPTION, type = CommandType.STRING, required = true, + description = "The option of network protocols. Supported values are: protocolnumber, icmptype.") + private String option; + + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + + public String getOption() { + return option; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() { + ListResponse response = new ListResponse<>(); + List networkProtocolResponses = new ArrayList<>(); + + NetworkProtocols.Option option = NetworkProtocols.Option.getOption(getOption()); + switch (option) { + case ProtocolNumber: + updateResponseWithProtocolNumbers(networkProtocolResponses); + break; + case IcmpType: + updateResponseWithIcmpTypes(networkProtocolResponses); + break; + default: + break; + } + + response.setResponses(networkProtocolResponses); + response.setResponseName(getCommandName()); + setResponseObject(response); + } + + @Override + public long getEntityOwnerId() { + return CallContext.current().getCallingAccount().getId(); + } + + private void updateResponseWithProtocolNumbers(List responses) { + for (NetworkProtocols.ProtocolNumber protocolNumber : NetworkProtocols.ProtocolNumbers) { + NetworkProtocolResponse networkProtocolResponse = new NetworkProtocolResponse(protocolNumber.getNumber(), + protocolNumber.getKeyword(), protocolNumber.getProtocol()); + networkProtocolResponse.setObjectName("networkprotocol"); + responses.add(networkProtocolResponse); + } + } + + private void updateResponseWithIcmpTypes(List responses) { + for (NetworkProtocols.IcmpType icmpType : NetworkProtocols.IcmpTypes) { + NetworkProtocolResponse networkProtocolResponse = new NetworkProtocolResponse(icmpType.getType(), + null, icmpType.getDescription()); + for (NetworkProtocols.IcmpCode code : icmpType.getIcmpCodes()) { + networkProtocolResponse.addDetail(String.valueOf(code.getCode()), code.getDescription()); + } + networkProtocolResponse.setObjectName("networkprotocol"); + responses.add(networkProtocolResponse); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java index c1e85a9b4c3..0e8425b14b4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ListNetworksCmd.java @@ -24,7 +24,6 @@ import com.cloud.server.ResourceTag; import org.apache.cloudstack.api.response.NetworkOfferingResponse; import org.apache.cloudstack.api.response.ResourceIconResponse; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -46,7 +45,6 @@ import org.apache.commons.lang3.StringUtils; @APICommand(name = "listNetworks", description = "Lists all available networks.", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNetworksCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListNetworksCmd.class.getName()); private static final String s_name = "listnetworksresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/MoveNetworkAclItemCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/MoveNetworkAclItemCmd.java index da6ac437aa0..5d36dcfd8e9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/MoveNetworkAclItemCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/MoveNetworkAclItemCmd.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.NetworkACLItemResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.vpc.NetworkACLItem; @@ -32,7 +31,6 @@ import com.cloud.user.Account; @APICommand(name = "moveNetworkAclItem", description = "Move an ACL rule to a position bettwen two other ACL rules of the same ACL network list", responseObject = NetworkACLItemResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class MoveNetworkAclItemCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(MoveNetworkAclItemCmd.class.getName()); private static final String s_name = "moveNetworkAclItemResponse"; @Parameter(name = ApiConstants.ID, type = CommandType.STRING, required = true, description = "The ID of the network ACL rule that is being moved to a new position.") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/RemoveNetworkPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/RemoveNetworkPermissionsCmd.java index 05785c81588..c199d872e0c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/RemoveNetworkPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/RemoveNetworkPermissionsCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.network.Network; @@ -43,7 +42,6 @@ import java.util.List; since = "4.17.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class RemoveNetworkPermissionsCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(RemoveNetworkPermissionsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java index ea4e74149f4..f6e9557aadb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ReplaceNetworkACLListCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.network; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "replaceNetworkACLList", description = "Replaces ACL associated with a network or private gateway", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReplaceNetworkACLListCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReplaceNetworkACLListCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ResetNetworkPermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ResetNetworkPermissionsCmd.java index f9817f9be5f..a23b98c84a8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/ResetNetworkPermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/ResetNetworkPermissionsCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.network.Network; import com.cloud.user.Account; @@ -38,7 +37,6 @@ import com.cloud.user.Account; since = "4.17.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ResetNetworkPermissionsCmd extends BaseCmd { - public static final Logger LOGGER = Logger.getLogger(ResetNetworkPermissionsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java index 141dee3c9a0..ffc2e36dee5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/RestartNetworkCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -43,7 +42,6 @@ import com.cloud.network.Network; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RestartNetworkCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RestartNetworkCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java index f675fa23e34..42cb0697edb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLItemCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.NetworkACLItemResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceUnavailableException; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "updateNetworkACLItem", description = "Updates ACL item with specified ID", responseObject = NetworkACLItemResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkACLItemCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLItemCmd.class.getName()); private static final String s_name = "createnetworkaclresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java index ddcb202aa8d..adab885542d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkACLListCmd.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.NetworkACLResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceUnavailableException; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "updateNetworkACLList", description = "Updates network ACL list", responseObject = SuccessResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkACLListCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkACLListCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java index d3cc169b7da..0d92a635e7f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/network/UpdateNetworkCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.NetworkOfferingResponse; import org.apache.cloudstack.api.response.NetworkResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -43,7 +42,6 @@ import com.cloud.offering.NetworkOffering; @APICommand(name = "updateNetwork", description = "Updates a network", responseObject = NetworkResponse.class, responseView = ResponseView.Restricted, entityType = {Network.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateNetworkCmd extends BaseAsyncCustomIdCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateNetworkCmd.class.getName()); private static final String s_name = "updatenetworkresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java index e7284d515a2..f9b9ec59a40 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmd.java @@ -16,23 +16,26 @@ // under the License. package org.apache.cloudstack.api.command.user.offering; -import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; -import org.apache.cloudstack.api.response.StoragePoolResponse; -import org.apache.cloudstack.api.response.VolumeResponse; -import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; +import static com.cloud.offering.DiskOffering.State.Active; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.BaseCmd.CommandType; import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.StoragePoolResponse; +import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.commons.lang3.EnumUtils; +import org.apache.commons.lang3.StringUtils; + +import com.cloud.offering.DiskOffering.State; @APICommand(name = "listDiskOfferings", description = "Lists all available disk offerings.", responseObject = DiskOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListDiskOfferingsCmd.class.getName()); ///////////////////////////////////////////////////// @@ -67,6 +70,18 @@ public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd since = "4.19") private String storageType; + @Parameter(name = ApiConstants.STATE, type = CommandType.STRING, + description = "Filter by state of the disk offering. Defaults to 'Active'. If set to 'all' shows both Active & Inactive offerings.", + since = "4.19") + private String diskOfferingState; + + @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, + type = CommandType.UUID, + entityType = UserVmResponse.class, + description = "The ID of a virtual machine. Pass this in if you want to see the suitable disk offering that can be used to create and add a disk to the virtual machine. Suitability is returned with suitableforvirtualmachine flag in the response", + since = "4.20.0") + private Long virtualMachineId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -95,13 +110,27 @@ public class ListDiskOfferingsCmd extends BaseListProjectAndAccountResourcesCmd return storageType; } + public State getState() { + if (StringUtils.isBlank(diskOfferingState)) { + return Active; + } + State state = EnumUtils.getEnumIgnoreCase(State.class, diskOfferingState); + if (!diskOfferingState.equalsIgnoreCase("all") && state == null) { + throw new IllegalArgumentException("Invalid state value: " + diskOfferingState); + } + return state; + } + + public Long getVirtualMachineId() { + return virtualMachineId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @Override public void execute() { - ListResponse response = _queryService.searchForDiskOfferings(this); response.setResponseName(getCommandName()); this.setResponseObject(response); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java index a9a699ed3ef..1b3f531e370 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java @@ -16,22 +16,25 @@ // under the License. package org.apache.cloudstack.api.command.user.offering; -import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; -import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; +import static com.cloud.offering.ServiceOffering.State.Active; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.BaseCmd.CommandType; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ServiceOfferingResponse; +import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.UserVmResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.commons.lang3.EnumUtils; +import org.apache.commons.lang3.StringUtils; + +import com.cloud.offering.ServiceOffering.State; @APICommand(name = "listServiceOfferings", description = "Lists all available service offerings.", responseObject = ServiceOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListServiceOfferingsCmd.class.getName()); ///////////////////////////////////////////////////// @@ -95,6 +98,18 @@ public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesC since = "4.19") private String storageType; + @Parameter(name = ApiConstants.STATE, type = CommandType.STRING, + description = "Filter by state of the service offering. Defaults to 'Active'. If set to 'all' shows both Active & Inactive offerings.", + since = "4.19") + private String serviceOfferingState; + + @Parameter(name = ApiConstants.TEMPLATE_ID, + type = CommandType.UUID, + entityType = TemplateResponse.class, + description = "The ID of the template that listed offerings must support", + since = "4.20.0") + private Long templateId; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -141,6 +156,21 @@ public class ListServiceOfferingsCmd extends BaseListProjectAndAccountResourcesC return storageType; } + public State getState() { + if (StringUtils.isBlank(serviceOfferingState)) { + return Active; + } + State state = EnumUtils.getEnumIgnoreCase(State.class, serviceOfferingState); + if (!serviceOfferingState.equalsIgnoreCase("all") && state == null) { + throw new IllegalArgumentException("Invalid state value: " + serviceOfferingState); + } + return state; + } + + public Long getTemplateId() { + return templateId; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java index 58cc93ff95d..42e045d4389 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ActivateProjectCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.project; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.projects.Project; @APICommand(name = "activateProject", description = "Activates a project", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ActivateProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ActivateProjectCmd.class.getName()); private static final String s_name = "activaterojectresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java index a5742e8d0de..cb93729381a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "createProject", description = "Creates a project", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateProjectCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateProjectCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java index 85b411b075d..1fd205fdae4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.project; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.projects.Project; @APICommand(name = "deleteProject", description = "Deletes a project", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java index 600fac350de..d1b17eda76b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/DeleteProjectInvitationCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.project; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteProjectInvitation", description = "Deletes project invitation", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteProjectInvitationCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteProjectInvitationCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java index b8d2f9b5f1a..210394ec2dd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectInvitationsCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.project; import org.apache.cloudstack.api.response.UserResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import org.apache.cloudstack.api.response.ProjectResponse; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListProjectInvitationsCmd extends BaseListAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListProjectInvitationsCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java index 39d1c0dfeda..d4679dbe057 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/ListProjectsCmd.java @@ -24,7 +24,6 @@ import java.util.Map; import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceTag; import org.apache.cloudstack.api.response.ResourceIconResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -44,7 +43,6 @@ import com.cloud.exception.InvalidParameterValueException; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListProjectsCmd extends BaseListAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListProjectsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java index 4937b164aab..a3eee8c80bb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/SuspendProjectCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.project; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.projects.Project; @APICommand(name = "suspendProject", description = "Suspends a project", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class SuspendProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(SuspendProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java index 6520aa63a64..4fabf7da788 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -40,7 +39,6 @@ import com.cloud.projects.ProjectAccount; @APICommand(name = "updateProject", description = "Updates a project", responseObject = ProjectResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateProjectCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateProjectCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java index e783aa64467..0cbd9f702c2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/project/UpdateProjectInvitationCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.UserResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.user.Account; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "updateProjectInvitation", description = "Accepts or declines project invitation", responseObject = SuccessResponse.class, since = "3.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateProjectInvitationCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateProjectInvitationCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ListRegionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ListRegionsCmd.java index d3eb8bf8b0f..777f437851c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ListRegionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ListRegionsCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import org.apache.cloudstack.region.RegionService; @APICommand(name = "listRegions", description = "Lists Regions", responseObject = RegionResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListRegionsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListRegionsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java index aedc363e5cc..649b2a7bd9b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java @@ -25,7 +25,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -53,7 +52,6 @@ import com.cloud.user.Account; responseHasSensitiveInfo = false) public class AssignToGlobalLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AssignToGlobalLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java index 3aaf0607392..ddaadde7852 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse; import org.apache.cloudstack.api.response.RegionResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceAllocationException; @@ -42,7 +41,6 @@ import com.cloud.region.ha.GlobalLoadBalancingRulesService; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateGlobalLoadBalancerRuleCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateGlobalLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// @@ -157,7 +155,7 @@ public class CreateGlobalLoadBalancerRuleCmd extends BaseAsyncCreateCmd { this.setEntityUuid(gslbRule.getUuid()); CallContext.current().setEventDetails("Rule Id: " + getEntityId()); } catch (Exception ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage()); } finally { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java index 87c4e60a90b..7f3308614cc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.region.ha.gslb; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -41,7 +40,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteGlobalLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteGlobalLoadBalancerRuleCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java index 7a1bcfc37a7..bf0cf22a2ec 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java @@ -22,7 +22,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.region.ha.GlobalLoadBalancingRulesService; @APICommand(name = "listGlobalLoadBalancerRules", description = "Lists load balancer rules.", responseObject = GlobalLoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListGlobalLoadBalancerRuleCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListGlobalLoadBalancerRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java index b9bbfec847f..d4b02139892 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -47,7 +46,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveFromGlobalLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveFromGlobalLoadBalancerRuleCmd.class.getName()); private static final String s_name = "removefromloadbalancerruleresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java index c8d307e4084..7996998e5d9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.region.ha.gslb; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "updateGlobalLoadBalancerRule", description = "update global load balancer rules.", responseObject = GlobalLoadBalancerResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateGlobalLoadBalancerRuleCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateGlobalLoadBalancerRuleCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java index b513b811e46..b9e43336217 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/GetCloudIdentifierCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.resource; import java.util.ArrayList; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "getCloudIdentifier", description = "Retrieves a cloud identifier.", responseObject = CloudIdentifierResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetCloudIdentifierCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetCloudIdentifierCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListHypervisorsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListHypervisorsCmd.java index a0e750eb19f..556f3b081f0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListHypervisorsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListHypervisorsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.resource; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "listHypervisors", description = "List hypervisors", responseObject = HypervisorResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListHypervisorsCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListHypervisorsCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java index adf1c93e4d0..71b886ed12b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmd.java @@ -19,22 +19,20 @@ package org.apache.cloudstack.api.command.user.resource; import java.util.ArrayList; import java.util.List; -import com.cloud.configuration.Resource; -import com.cloud.exception.InvalidParameterValueException; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ResourceLimitResponse; -import org.apache.log4j.Logger; +import com.cloud.configuration.Resource; import com.cloud.configuration.ResourceLimit; +import com.cloud.exception.InvalidParameterValueException; @APICommand(name = "listResourceLimits", description = "Lists resource limits.", responseObject = ResourceLimitResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListResourceLimitsCmd.class.getName()); ///////////////////////////////////////////////////// @@ -74,6 +72,10 @@ public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd + "secondary_storage - SecondaryStorage. Total secondary storage space (in GiB) a user can use. ") private String resourceTypeName; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0") + private String tag; + + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -90,6 +92,10 @@ public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd return resourceTypeName; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -98,7 +104,7 @@ public class ListResourceLimitsCmd extends BaseListProjectAndAccountResourcesCmd public void execute() { List result = _resourceLimitService.searchForLimits(id, _accountService.finalyzeAccountId(this.getAccountName(), this.getDomainId(), this.getProjectId(), false), this.getDomainId(), - getResourceTypeEnum(), this.getStartIndex(), this.getPageSizeVal()); + getResourceTypeEnum(), getTag(), this.getStartIndex(), this.getPageSizeVal()); ListResponse response = new ListResponse(); List limitResponses = new ArrayList(); for (ResourceLimit limit : result) { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java index 424087bc71e..0ea22b38a37 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ResourceCountResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.configuration.ResourceCount; import com.cloud.user.Account; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "updateResourceCount", description = "Recalculate and update resource count for an account or domain.", responseObject = ResourceCountResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateResourceCountCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateResourceCountCmd.class.getName()); ///////////////////////////////////////////////////// @@ -77,6 +75,9 @@ public class UpdateResourceCountCmd extends BaseCmd { @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "Update resource limits for project") private Long projectId; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -93,6 +94,10 @@ public class UpdateResourceCountCmd extends BaseCmd { return resourceType; } + public String getTag() { + return tag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -119,7 +124,7 @@ public class UpdateResourceCountCmd extends BaseCmd { @Override public void execute() { List result = - _resourceLimitService.recalculateResourceCount(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), getResourceType()); + _resourceLimitService.recalculateResourceCount(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), getResourceType(), getTag()); if ((result != null) && (result.size() > 0)) { ListResponse response = new ListResponse(); @@ -127,7 +132,6 @@ public class UpdateResourceCountCmd extends BaseCmd { for (ResourceCount count : result) { ResourceCountResponse resourceCountResponse = _responseGenerator.createResourceCountResponse(count); - resourceCountResponse.setObjectName("resourcecount"); countResponses.add(resourceCountResponse); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java index 41676ed23ca..52afd2b1760 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmd.java @@ -26,14 +26,12 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.ResourceLimitResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.configuration.ResourceLimit; @APICommand(name = "updateResourceLimit", description = "Updates resource limits for an account or domain.", responseObject = ResourceLimitResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateResourceLimitCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateResourceLimitCmd.class.getName()); ///////////////////////////////////////////////////// @@ -72,6 +70,9 @@ public class UpdateResourceLimitCmd extends BaseCmd { + "11 - SecondaryStorage. Total secondary storage space (in GiB) a user can use. ") private Integer resourceType; + @Parameter(name = ApiConstants.TAG, type = CommandType.STRING, description = "Tag for the resource type", since = "4.20.0") + private String tag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -84,6 +85,10 @@ public class UpdateResourceLimitCmd extends BaseCmd { return domainId; } + public String getTag() { + return tag; + } + public Integer getResourceType() { return resourceType; } @@ -104,7 +109,7 @@ public class UpdateResourceLimitCmd extends BaseCmd { @Override public void execute() { - ResourceLimit result = _resourceLimitService.updateResourceLimit(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max); + ResourceLimit result = _resourceLimitService.updateResourceLimit(_accountService.finalyzeAccountId(accountName, domainId, projectId, true), getDomainId(), resourceType, max, getTag()); if (result != null || (result == null && max != null && max.longValue() == -1L)) { ResourceLimitResponse response = _responseGenerator.createResourceLimitResponse(result); response.setResponseName(getCommandName()); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java index 737bdc8773b..13faafe348c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupEgressCmd.java @@ -22,7 +22,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -50,7 +49,6 @@ import com.cloud.network.security.SecurityRule; responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class AuthorizeSecurityGroupEgressCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AuthorizeSecurityGroupEgressCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java index b6918905f29..640870fc3de 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/AuthorizeSecurityGroupIngressCmd.java @@ -22,7 +22,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -50,7 +49,6 @@ import com.cloud.network.security.SecurityRule; responseHasSensitiveInfo = false) @SuppressWarnings("rawtypes") public class AuthorizeSecurityGroupIngressCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AuthorizeSecurityGroupIngressCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java index 4978aa174fc..673eaaef33d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/CreateSecurityGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "createSecurityGroup", responseObject = SecurityGroupResponse.class, description = "Creates a security group", entityType = {SecurityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSecurityGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateSecurityGroupCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java index 57d365d5ce1..b2ea90792b8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/DeleteSecurityGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ import com.cloud.network.security.SecurityGroup; @APICommand(name = "deleteSecurityGroup", description = "Deletes security group", responseObject = SuccessResponse.class, entityType = {SecurityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSecurityGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSecurityGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -124,7 +122,7 @@ public class DeleteSecurityGroupCmd extends BaseCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete security group"); } } catch (ResourceInUseException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/ListSecurityGroupsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/ListSecurityGroupsCmd.java index c4c103cf98e..f93e7b39586 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/ListSecurityGroupsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/ListSecurityGroupsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -32,7 +31,6 @@ import com.cloud.network.security.SecurityGroup; @APICommand(name = "listSecurityGroups", description = "Lists security groups", responseObject = SecurityGroupResponse.class, entityType = {SecurityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSecurityGroupsCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListSecurityGroupsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java index f4a0362fce9..bf435406174 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupEgressCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -38,7 +37,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RevokeSecurityGroupEgressCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RevokeSecurityGroupEgressCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java index c5f88c9673f..c426647fe36 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/RevokeSecurityGroupIngressCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "revokeSecurityGroupIngress", responseObject = SuccessResponse.class, description = "Deletes a particular ingress rule from this security group", entityType = {SecurityGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RevokeSecurityGroupIngressCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RevokeSecurityGroupIngressCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/UpdateSecurityGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/UpdateSecurityGroupCmd.java index 9b3000b1bf7..801fb6ac5e5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/UpdateSecurityGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/securitygroup/UpdateSecurityGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.securitygroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -37,7 +36,6 @@ import com.cloud.user.Account; since = "4.14.0.0", authorized = {RoleType.Admin}) public class UpdateSecurityGroupCmd extends BaseCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateSecurityGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ArchiveSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ArchiveSnapshotCmd.java index 78aa208ac1f..f72de2278cc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ArchiveSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ArchiveSnapshotCmd.java @@ -35,13 +35,11 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "archiveSnapshot", description = "Archives (moves) a snapshot on primary storage to secondary storage", responseObject = SnapshotResponse.class, entityType = {Snapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ArchiveSnapshotCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ArchiveSnapshotCmd.class.getName()); private static final String s_name = "createsnapshotresponse"; @ACL(accessType = SecurityChecker.AccessType.OperateEntry) diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java index f6d16c3eb49..07973fcbfca 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CopySnapshotCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -43,13 +42,15 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; import com.cloud.storage.Snapshot; import com.cloud.user.Account; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; @APICommand(name = "copySnapshot", description = "Copies a snapshot from one zone to another.", responseObject = SnapshotResponse.class, responseView = ResponseObject.ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.19.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CopySnapshotCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CopySnapshotCmd.class.getName()); + public static final Logger logger = LogManager.getLogger(CopySnapshotCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -170,10 +171,10 @@ public class CopySnapshotCmd extends BaseAsyncCmd implements UserCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy snapshot"); } } catch (StorageUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java index eed3aa49fa5..3289ac2fe10 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotCmd.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -50,7 +49,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @APICommand(name = "createSnapshot", description = "Creates an instant snapshot of a volume.", responseObject = SnapshotResponse.class, entityType = {Snapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSnapshotCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateSnapshotCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -240,7 +238,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd { } String errorMessage = "Failed to create snapshot due to an internal error creating snapshot for volume " + getVolumeUuid(); - s_logger.error(errorMessage, e); + logger.error(errorMessage, e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage); } } @@ -257,7 +255,7 @@ public class CreateSnapshotCmd extends BaseAsyncCreateCmd { } catch (IllegalArgumentException e) { String errMesg = "Invalid locationType " + locationType + "Specified for volume " + getVolumeId() + " Valid values are: primary,secondary "; - s_logger.warn(errMesg); + logger.warn(errMesg); throw new CloudRuntimeException(errMesg); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java index 7b89e87202d..6bebdc09f59 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.api.response.VMSnapshotResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -43,7 +42,6 @@ import com.cloud.vm.snapshot.VMSnapshot; @APICommand(name = "createSnapshotFromVMSnapshot", description = "Creates an instant snapshot of a volume from existing vm snapshot.", responseObject = SnapshotResponse.class, entityType = {Snapshot.class}, since = "4.10.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSnapshotFromVMSnapshotCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateSnapshotFromVMSnapshotCmd.class.getName()); // /////////////////////////////////////////////////// // ////////////// API parameters ///////////////////// @@ -166,7 +164,7 @@ public class CreateSnapshotFromVMSnapshotCmd extends BaseAsyncCreateCmd { @Override public void execute() { - s_logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot id:" + getVMSnapshotId() + " and snapshot id:" + getEntityId() + " starts:" + System.currentTimeMillis()); + logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot id:" + getVMSnapshotId() + " and snapshot id:" + getEntityId() + " starts:" + System.currentTimeMillis()); CallContext.current().setEventDetails("Vm Snapshot Id: "+ this._uuidMgr.getUuid(VMSnapshot.class, getVMSnapshotId())); Snapshot snapshot = null; try { @@ -181,14 +179,14 @@ public class CreateSnapshotFromVMSnapshotCmd extends BaseAsyncCreateCmd { } catch (InvalidParameterValueException ex) { throw ex; } catch (Exception e) { - s_logger.debug("Failed to create snapshot", e); + logger.debug("Failed to create snapshot", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId()); } finally { if (snapshot == null) { try { _snapshotService.deleteSnapshot(getEntityId(), null); } catch (Exception e) { - s_logger.debug("Failed to clean failed snapshot" + getEntityId()); + logger.debug("Failed to clean failed snapshot" + getEntityId()); } } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java index 00bfb9e7e2c..e30b897db2e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotPolicyCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.SnapshotPolicyResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; @@ -45,7 +44,6 @@ import com.cloud.user.Account; @APICommand(name = "createSnapshotPolicy", description = "Creates a snapshot policy for the account.", responseObject = SnapshotPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateSnapshotPolicyCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateSnapshotPolicyCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java index 6d71b1363b4..a0a8cfac9bd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.snapshot; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteSnapshot", description = "Deletes a snapshot of a disk volume.", responseObject = SuccessResponse.class, entityType = {Snapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSnapshotCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSnapshotCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java index 1a72b22f06c..6f4b60dc8b2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/DeleteSnapshotPoliciesCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.snapshot; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteSnapshotPolicies", description = "Deletes snapshot policies for the account.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSnapshotPoliciesCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSnapshotPoliciesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java index e30ee75dee7..126a4080e6d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotPoliciesCmd.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listSnapshotPolicies", description = "Lists snapshot policies.", responseObject = SnapshotPolicyResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSnapshotPoliciesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListSnapshotPoliciesCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java index cf665127a17..826c54c2e05 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java @@ -28,14 +28,12 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.storage.Snapshot; @APICommand(name = "listSnapshots", description = "Lists all available snapshots for the account.", responseObject = SnapshotResponse.class, entityType = { Snapshot.class }, responseView = ResponseObject.ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSnapshotsCmd extends BaseListTaggedResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListSnapshotsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java index e65a03812d6..fe3b4da0160 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/RevertSnapshotCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SnapshotResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.storage.Snapshot; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "revertSnapshot", description = "This is supposed to revert a volume snapshot. This command is only supported with KVM so far", responseObject = SnapshotResponse.class, entityType = {Snapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RevertSnapshotCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RevertSnapshotCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/UpdateSnapshotPolicyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/UpdateSnapshotPolicyCmd.java index 0bedbe66199..e7feb11f4af 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/UpdateSnapshotPolicyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/UpdateSnapshotPolicyCmd.java @@ -33,13 +33,11 @@ import org.apache.cloudstack.api.ResponseObject; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SnapshotPolicyResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "updateSnapshotPolicy", description = "Updates the snapshot policy.", responseObject = SnapshotPolicyResponse.class, responseView = ResponseObject.ResponseView.Restricted, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateSnapshotPolicyCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateSnapshotPolicyCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java index 521148b596d..5212779e965 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/CreateSSHKeyPairCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.ssh; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.user.SSHKeyPair; @APICommand(name = "createSSHKeyPair", description = "Create a new keypair and returns the private key", responseObject = CreateSSHKeyPairResponse.class, entityType = {SSHKeyPair.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class CreateSSHKeyPairCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateSSHKeyPairCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java index 39c65c181c5..364ca77ae1f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/DeleteSSHKeyPairCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.ssh; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.SSHKeyPair; @APICommand(name = "deleteSSHKeyPair", description = "Deletes a keypair by name", responseObject = SuccessResponse.class, entityType = {SSHKeyPair.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteSSHKeyPairCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteSSHKeyPairCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/ListSSHKeyPairsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/ListSSHKeyPairsCmd.java index 71fbb66a337..6bf8dca864b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/ListSSHKeyPairsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/ListSSHKeyPairsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.ssh; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listSSHKeyPairs", description = "List registered keypairs", responseObject = SSHKeyPairResponse.class, entityType = {SSHKeyPair.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListSSHKeyPairsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListSSHKeyPairsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java index 8bacfde7f73..6a0c0541bb4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/ssh/RegisterSSHKeyPairCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.ssh; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -32,7 +31,6 @@ import com.cloud.user.SSHKeyPair; @APICommand(name = "registerSSHKeyPair", description = "Register a public key in a keypair under a certain name", responseObject = SSHKeyPairResponse.class, entityType = {SSHKeyPair.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RegisterSSHKeyPairCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RegisterSSHKeyPairCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java index 67705859419..30904db46c4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/CreateTagsCmd.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.api.command.user.tag; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.server.ResourceTag.ResourceObjectType; @APICommand(name = "createTags", description = "Creates resource tag(s)", responseObject = SuccessResponse.class, since = "4.0.0", entityType = {ResourceTag.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTagsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(CreateTagsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java index 55dec6e9645..f8f319eba23 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/tag/DeleteTagsCmd.java @@ -23,7 +23,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -40,7 +39,6 @@ import com.cloud.server.ResourceTag.ResourceObjectType; @APICommand(name = "deleteTags", description = "Deleting resource tag(s)", responseObject = SuccessResponse.class, since = "4.0.0", entityType = {ResourceTag.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTagsCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTagsCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java index f672d4c8890..f094bc43507 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -43,7 +42,6 @@ import com.cloud.user.Account; @APICommand(name = "copyTemplate", description = "Copies a template from one zone to another.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CopyTemplateCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CopyTemplateCmd.class.getName()); private static final String s_name = "copytemplateresponse"; ///////////////////////////////////////////////////// @@ -191,7 +189,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd implements UserCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to copy template"); } } catch (StorageUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java index 6c39ab6d3c7..0a7bf291843 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/CreateTemplateCmd.java @@ -40,7 +40,6 @@ import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -55,7 +54,6 @@ import com.cloud.user.Account; + "A template created from this command is automatically designated as a private template visible to the account that created it.", responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateTemplateCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateTemplateCmd.class.getName()); private static final String s_name = "createtemplateresponse"; // /////////////////////////////////////////////////// @@ -348,11 +346,11 @@ public class CreateTemplateCmd extends BaseAsyncCreateCmd implements UserCmd { try { accountIdToUse = _accountService.finalyzeAccountId(accountName, domainId, projectId, true); } catch (InvalidParameterValueException | PermissionDeniedException ex) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("An exception occurred while finalizing account id with accountName, domainId and projectId" + + if (logger.isDebugEnabled()) { + logger.debug(String.format("An exception occurred while finalizing account id with accountName, domainId and projectId" + "using callingAccountId=%s", callingAccount.getUuid()), ex); } - s_logger.warn("Unable to find accountId associated with accountName=" + accountName + " and domainId=" + logger.warn("Unable to find accountId associated with accountName=" + accountName + " and domainId=" + domainId + " or projectId=" + projectId + ", using callingAccountId=" + callingAccount.getUuid()); } return accountIdToUse != null ? accountIdToUse : callingAccount.getAccountId(); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java index 3d7aaaec31c..245baf1e07e 100755 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/DeleteTemplateCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.template; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -40,7 +39,6 @@ import com.cloud.user.Account; description = "Deletes a template from the system. All virtual machines using the deleted template will not be affected.", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteTemplateCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteTemplateCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java index 91e8d168ecb..ce6ba5e300c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ExtractTemplateCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.ExtractResponse; import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -38,7 +37,6 @@ import com.cloud.user.Account; @APICommand(name = "extractTemplate", description = "Extracts a template", responseObject = ExtractResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ExtractTemplateCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ExtractTemplateCmd.class.getName()); ///////////////////////////////////////////////////// @@ -129,7 +127,7 @@ public class ExtractTemplateCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract template"); } } catch (InternalErrorException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java index ab872b84edb..c878fda8240 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/GetUploadParamsForTemplateCmd.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.response.GetUploadParamsResponse; import org.apache.cloudstack.api.response.GuestOSResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.ResourceAllocationException; @@ -43,7 +42,6 @@ import com.cloud.exception.ResourceAllocationException; authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetUploadParamsForTemplateCmd extends AbstractGetUploadParamsCmd { - public static final Logger s_logger = Logger.getLogger(GetUploadParamsForTemplateCmd.class.getName()); private static final String s_name = "postuploadtemplateresponse"; @@ -172,7 +170,7 @@ public class GetUploadParamsForTemplateCmd extends AbstractGetUploadParamsCmd { response.setResponseName(getCommandName()); setResponseObject(response); } catch (ResourceAllocationException | MalformedURLException e) { - s_logger.error("exception while registering template", e); + logger.error("exception while registering template", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "exception while registering template: " + e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java index 970c6b34743..6d544df4187 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatePermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.template; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseListTemplateOrIsoPermissionsCmd; @@ -40,11 +39,6 @@ public class ListTemplatePermissionsCmd extends BaseListTemplateOrIsoPermissions return "template"; } - @Override - protected Logger getLogger() { - return Logger.getLogger(ListTemplatePermissionsCmd.class.getName()); - } - @Override protected boolean templateIsCorrectType(VirtualMachineTemplate template) { return !template.getFormat().equals(ImageFormat.ISO); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java index dae7cc97a4c..113080257d0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java @@ -21,7 +21,6 @@ import com.cloud.server.ResourceIcon; import com.cloud.server.ResourceTag; import org.apache.cloudstack.api.response.ResourceIconResponse; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.Collections; @@ -46,7 +45,6 @@ import com.cloud.user.Account; @APICommand(name = "listTemplates", description = "List all public, private, and privileged templates.", responseObject = TemplateResponse.class, entityType = {VirtualMachineTemplate.class}, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListTemplatesCmd extends BaseListTaggedResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListTemplatesCmd.class.getName()); private static final String s_name = "listtemplatesresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java index 0a087888d52..1e5c4af9c15 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java @@ -41,7 +41,6 @@ import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.ResourceAllocationException; import com.cloud.template.VirtualMachineTemplate; @@ -49,7 +48,6 @@ import com.cloud.template.VirtualMachineTemplate; @APICommand(name = "registerTemplate", description = "Registers an existing template into the CloudStack cloud. ", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RegisterTemplateCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RegisterTemplateCmd.class.getName()); private static final String s_name = "registertemplateresponse"; @@ -335,7 +333,7 @@ public class RegisterTemplateCmd extends BaseCmd implements UserCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template"); } } catch (URISyntaxException ex1) { - s_logger.info(ex1); + logger.info(ex1); throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java index 2afa6a98b13..dbbd771293a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java @@ -16,8 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.template; -import org.apache.log4j.Logger; - import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "updateTemplate", description = "Updates attributes of a template.", responseObject = TemplateResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateTemplateCmd.class.getName()); private static final String s_name = "updatetemplateresponse"; ///////////////////////////////////////////////////// @@ -46,6 +43,9 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements Use description = "the type of the template. Valid options are: USER/VNF (for all users) and SYSTEM/ROUTING/BUILTIN (for admins only).") private String templateType; + @Parameter(name = ApiConstants.TEMPLATE_TAG, type = CommandType.STRING, description = "the tag for this template.", since = "4.20.0") + private String templateTag; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -59,6 +59,10 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd implements Use return templateType; } + public String getTemplateTag() { + return templateTag; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java index 7cf5e0bc3f5..de8f09a6400 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/template/UpdateTemplatePermissionsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.template; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseUpdateTemplateOrIsoPermissionsCmd; @@ -35,10 +34,6 @@ public class UpdateTemplatePermissionsCmd extends BaseUpdateTemplateOrIsoPermiss return "updatetemplatepermissionsresponse"; } - @Override - protected Logger getLogger() { - return Logger.getLogger(UpdateTemplatePermissionsCmd.class.getName()); - } @Override public long getEntityOwnerId() { diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/DeleteUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/DeleteUserDataCmd.java index d27b90f07a1..a1d1afc7b05 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/DeleteUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/DeleteUserDataCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.UserDataResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.user.Account; import com.cloud.user.UserData; @@ -39,7 +38,6 @@ import com.cloud.user.UserData; authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class DeleteUserDataCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteUserDataCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/LinkUserDataToTemplateCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/LinkUserDataToTemplateCmd.java index be1a95c3694..e322de00bb1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/LinkUserDataToTemplateCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/LinkUserDataToTemplateCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.admin.AdminCmd; import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.UserDataResponse; -import org.apache.log4j.Logger; import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.Account; @@ -39,7 +38,6 @@ import com.cloud.utils.exception.CloudRuntimeException; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class LinkUserDataToTemplateCmd extends BaseCmd implements AdminCmd { - public static final Logger s_logger = Logger.getLogger(LinkUserDataToTemplateCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/ListUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/ListUserDataCmd.java index 87d8883e2e3..64ab3ec3d70 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/ListUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/ListUserDataCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.UserDataResponse; -import org.apache.log4j.Logger; import com.cloud.user.UserData; import com.cloud.utils.Pair; @@ -35,7 +34,6 @@ import com.cloud.utils.Pair; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18", authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListUserDataCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListUserDataCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java index f294f7dd8e0..8df25541a19 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/userdata/RegisterUserDataCmd.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.UserDataResponse; import org.apache.cloudstack.context.CallContext; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -52,7 +51,6 @@ import com.cloud.user.UserData; authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class RegisterUserDataCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RegisterUserDataCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java index fc009c7e5db..0dc3dcdbdcc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.NicResponse; import org.apache.cloudstack.api.response.NicSecondaryIpResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -46,7 +45,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "addIpToNic", description = "Assigns secondary IP to NIC", responseObject = NicSecondaryIpResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddIpToVmNicCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddIpToVmNicCmd.class.getName()); private static final String s_name = "addiptovmnicresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java index 1e395831a6f..ecd066d98cd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/AddNicToVMCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -51,7 +50,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "addNicToVirtualMachine", description = "Adds VM to specified network by creating a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class AddNicToVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(AddNicToVMCmd.class); private static final String s_name = "addnictovirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index 1cbe28f4dde..446bdf30f07 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -56,7 +56,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.LogLevel; import com.cloud.event.EventTypes; @@ -80,7 +79,6 @@ import com.cloud.vm.VmDetailConstants; @APICommand(name = "deployVirtualMachine", description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityGroupAction, UserCmd { - public static final Logger s_logger = Logger.getLogger(DeployVMCmd.class.getName()); private static final String s_name = "deployvirtualmachineresponse"; @@ -313,7 +311,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG } catch (IllegalArgumentException e) { String errMesg = "Invalid bootType " + bootType + "Specified for vm " + getName() + " Valid values are: " + Arrays.toString(ApiConstants.BootType.values()); - s_logger.warn(errMesg); + logger.warn(errMesg); throw new InvalidParameterValueException(errMesg); } } @@ -360,14 +358,14 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG } catch (IllegalArgumentException e) { String msg = String.format("Invalid %s: %s specified for VM: %s. Valid values are: %s", ApiConstants.BOOT_MODE, bootMode, getName(), Arrays.toString(ApiConstants.BootMode.values())); - s_logger.error(msg); + logger.error(msg); throw new InvalidParameterValueException(msg); } } if (ApiConstants.BootType.UEFI.equals(getBootType())) { String msg = String.format("%s must be specified for the VM with boot type: %s. Valid values are: %s", ApiConstants.BOOT_MODE, getBootType(), Arrays.toString(ApiConstants.BootMode.values())); - s_logger.error(msg); + logger.error(msg); throw new InvalidParameterValueException(msg); } return null; @@ -400,8 +398,8 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG nic = null; } String networkUuid = entry.get(VmDetailConstants.NETWORK); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("nic, '%s', goes on net, '%s'", nic, networkUuid)); } if (nic == null || StringUtils.isEmpty(networkUuid) || _entityMgr.findByUuid(Network.class, networkUuid) == null) { throw new InvalidParameterValueException(String.format("Network ID: %s for NIC ID: %s is invalid", networkUuid, nic)); @@ -711,7 +709,7 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG return ApiConstants.IoDriverPolicy.valueOf(policyType); } catch (IllegalArgumentException e) { String errMesg = String.format("Invalid io policy %s specified for vm %s. Valid values are: %s", ioDriverPolicy, getName(), Arrays.toString(ApiConstants.IoDriverPolicy.values())); - s_logger.warn(errMesg); + logger.warn(errMesg); throw new InvalidParameterValueException(errMesg); } } @@ -777,13 +775,13 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG try { result = _userVmService.startVirtualMachine(this); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { StringBuilder message = new StringBuilder(ex.getMessage()); @@ -792,12 +790,12 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them"); } } - s_logger.info(String.format("%s: %s", message.toString(), ex.getLocalizedMessage())); - s_logger.debug(message.toString(), ex); + logger.info(String.format("%s: %s", message.toString(), ex.getLocalizedMessage())); + logger.debug(message.toString(), ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString()); } } else { - s_logger.info("VM " + getEntityUuid() + " already created, load UserVm from DB"); + logger.info("VM " + getEntityUuid() + " already created, load UserVm from DB"); result = _userVmService.finalizeCreateVirtualMachine(getEntityId()); } @@ -823,17 +821,17 @@ public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd implements SecurityG throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to deploy vm"); } } catch (InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex.getMessage(), ex); + logger.info(ex); + logger.trace(ex.getMessage(), ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java index 07fd55276f8..aa121162cb4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/DestroyVMCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.vm; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -46,7 +45,6 @@ import com.cloud.vm.VirtualMachine; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DestroyVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(DestroyVMCmd.class.getName()); private static final String s_name = "destroyvirtualmachineresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/GetVMPasswordCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/GetVMPasswordCmd.java index d3cbf82f755..ce6114c7fd8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/GetVMPasswordCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/GetVMPasswordCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.vm; import java.security.InvalidParameterException; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -36,7 +35,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "getVMPassword", responseObject = GetVMPasswordResponse.class, description = "Returns an encrypted password for the VM", entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetVMPasswordCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(GetVMPasswordCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java index 44710d018d3..0e659fc02a1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListNicsCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.NicResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -45,7 +44,6 @@ import com.cloud.vm.Nic; @APICommand(name = "listNics", description = "list the vm nics IP to NIC", responseObject = NicResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListNicsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListNicsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -157,7 +155,7 @@ public class ListNicsCmd extends BaseListCmd { this.setResponseObject(response); } } catch (Exception e) { - s_logger.warn("Failed to list secondary ip address per nic "); + logger.warn("Failed to list secondary ip address per nic "); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java index 9ec625cf3cf..2d1160fb7a7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ListVMsCmd.java @@ -45,7 +45,6 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VpcResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.exception.InvalidParameterValueException; import com.cloud.server.ResourceIcon; @@ -56,7 +55,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "listVirtualMachines", description = "List the virtual machines owned by the account.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListVMsCmd.class.getName()); private static final String s_name = "listvirtualmachinesresponse"; @@ -96,8 +94,8 @@ public class ListVMsCmd extends BaseListRetrieveOnlyResourceCountCmd implements @Parameter(name = ApiConstants.DETAILS, type = CommandType.LIST, collectionType = CommandType.STRING, - description = "comma separated list of host details requested, " - + "value can be a list of [all, group, nics, stats, secgrp, tmpl, servoff, diskoff, iso, volume, min, affgrp]." + description = "comma separated list of vm details requested, " + + "value can be a list of [all, group, nics, stats, secgrp, tmpl, servoff, diskoff, backoff, iso, volume, min, affgrp]." + " If no parameter is passed in, the details will be defaulted to all") private List viewDetails; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java index 9bdcc1aed56..10900f61b22 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RebootVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -42,7 +41,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "rebootVirtualMachine", description = "Reboots a virtual machine.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RebootVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RebootVMCmd.class.getName()); private static final String s_name = "rebootvirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java index e964cc69231..a4cd6159dfc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveIpFromVmNicCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -41,7 +40,6 @@ import com.cloud.vm.NicSecondaryIp; @APICommand(name = "removeIpFromNic", description = "Removes secondary IP from the NIC.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveIpFromVmNicCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveIpFromVmNicCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java index 5fd016c38ed..d9024f34022 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RemoveNicFromVMCmd.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.EnumSet; import com.cloud.vm.Nic; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -45,7 +44,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "removeNicFromVirtualMachine", description = "Removes VM from specified network by deleting a NIC", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RemoveNicFromVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RemoveNicFromVMCmd.class); private static final String s_name = "removenicfromvirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java index 1cf4c929b32..7270004aeed 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMPasswordCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vm; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -45,7 +44,6 @@ import com.cloud.vm.VirtualMachine; "support this feature for this command to take effect. [async]", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ResetVMPasswordCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ResetVMPasswordCmd.class.getName()); private static final String s_name = "resetpasswordforvirtualmachineresponse"; @@ -122,9 +120,9 @@ public class ResetVMPasswordCmd extends BaseAsyncCmd implements UserCmd { UserVm vm = _responseGenerator.findUserVmById(getId()); if (StringUtils.isBlank(password)) { password = _mgr.generateRandomPassword(); - s_logger.debug(String.format("Resetting VM [%s] password to a randomly generated password.", vm.getUuid())); + logger.debug(String.format("Resetting VM [%s] password to a randomly generated password.", vm.getUuid())); } else { - s_logger.debug(String.format("Resetting VM [%s] password to password defined by user.", vm.getUuid())); + logger.debug(String.format("Resetting VM [%s] password to password defined by user.", vm.getUuid())); } CallContext.current().setEventDetails("Vm Id: " + getId()); UserVm result = _userVmService.resetVMPassword(this, password); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java index 259cfebbad5..a4019411e1d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMSSHKeyCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -50,7 +49,6 @@ import java.util.List; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class ResetVMSSHKeyCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ResetVMSSHKeyCmd.class.getName()); private static final String s_name = "resetSSHKeyforvirtualmachineresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMUserDataCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMUserDataCmd.java index 3ead67e2106..089dfaecf94 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMUserDataCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ResetVMUserDataCmd.java @@ -37,7 +37,6 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.UserDataResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import java.util.Map; @@ -46,7 +45,6 @@ import java.util.Map; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true, since = "4.18.0") public class ResetVMUserDataCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ResetVMUserDataCmd.class.getName()); private static final String s_name = "resetuserdataforvirtualmachineresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java index 4b59bf560cb..3839049eee5 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/RestoreVMCmd.java @@ -16,10 +16,9 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; -import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; - +import com.cloud.vm.VmDetailConstants; import org.apache.cloudstack.acl.SecurityChecker.AccessType; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ACL; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -29,6 +28,7 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ResponseObject.ResponseView; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.user.UserCmd; +import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.TemplateResponse; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.context.CallContext; @@ -42,11 +42,12 @@ import com.cloud.user.Account; import com.cloud.uservm.UserVm; import com.cloud.vm.VirtualMachine; +import java.util.Map; + @APICommand(name = "restoreVirtualMachine", description = "Restore a VM to original template/ISO or new template/ISO", responseObject = UserVmResponse.class, since = "3.0.0", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RestoreVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RestoreVMCmd.class); private static final String s_name = "restorevmresponse"; @ACL(accessType = AccessType.OperateEntry) @@ -60,6 +61,28 @@ public class RestoreVMCmd extends BaseAsyncCmd implements UserCmd { description = "an optional template Id to restore vm from the new template. This can be an ISO id in case of restore vm deployed using ISO") private Long templateId; + @Parameter(name = ApiConstants.DISK_OFFERING_ID, + type = CommandType.UUID, + entityType = DiskOfferingResponse.class, + description = "Override root volume's diskoffering.", since = "4.19.1") + private Long rootDiskOfferingId; + + @Parameter(name = ApiConstants.ROOT_DISK_SIZE, + type = CommandType.LONG, + description = "Override root volume's size (in GB). Analogous to details[0].rootdisksize, which takes precedence over this parameter if both are provided", + since = "4.19.1") + private Long rootDiskSize; + + @Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, since = "4.19.1", + description = "used to specify the custom parameters") + private Map details; + + @Parameter(name = ApiConstants.EXPUNGE, + type = CommandType.BOOLEAN, + description = "Optional field to expunge old root volume after restore.", + since = "4.19.1") + private Boolean expungeRootDisk; + @Override public String getEventType() { return EventTypes.EVENT_VM_RESTORE; @@ -112,6 +135,22 @@ public class RestoreVMCmd extends BaseAsyncCmd implements UserCmd { return getVmId(); } + public Long getRootDiskOfferingId() { + return rootDiskOfferingId; + } + + public Map getDetails() { + Map customparameterMap = convertDetailsToMap(details); + if (rootDiskSize != null && !customparameterMap.containsKey(VmDetailConstants.ROOT_DISK_SIZE)) { + customparameterMap.put(VmDetailConstants.ROOT_DISK_SIZE, rootDiskSize.toString()); + } + return customparameterMap; + } + + public Boolean getExpungeRootDisk() { + return expungeRootDisk != null && expungeRootDisk; + } + @Override public Long getApiResourceId() { return getId(); diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java index 5af45762ece..3af6d5245f0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/ScaleVMCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.ServiceOfferingResponse; import org.apache.cloudstack.api.response.UserVmResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -49,7 +48,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "scaleVirtualMachine", description = "Scales the virtual machine to a new service offering. This command also considers the volume size in the service offering or disk offering linked to the new service offering and apply all characteristics to the root volume.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ScaleVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ScaleVMCmd.class.getName()); private static final String s_name = "scalevirtualmachineresponse"; ///////////////////////////////////////////////////// @@ -169,16 +167,16 @@ public class ScaleVMCmd extends BaseAsyncCmd implements UserCmd { try { result = _userVmService.upgradeVirtualMachine(this); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ManagementServerException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (VirtualMachineMigrationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } if (result != null){ diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java index 10c50dc380b..8bc4f0ff3b1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StartVMCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.vm; import org.apache.cloudstack.api.response.ClusterResponse; import org.apache.cloudstack.api.response.PodResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -51,7 +50,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "startVirtualMachine", responseObject = UserVmResponse.class, description = "Starts a virtual machine.", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class StartVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(StartVMCmd.class.getName()); private static final String s_name = "startvirtualmachineresponse"; @@ -188,19 +186,19 @@ public class StartVMCmd extends BaseAsyncCmd implements UserCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to start a vm"); } } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (StorageUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ExecutionException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ResourceAllocationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { StringBuilder message = new StringBuilder(ex.getMessage()); @@ -209,8 +207,8 @@ public class StartVMCmd extends BaseAsyncCmd implements UserCmd { message.append(", Please check the affinity groups provided, there may not be sufficient capacity to follow them"); } } - s_logger.info(ex); - s_logger.info(message.toString(), ex); + logger.info(ex); + logger.info(message.toString(), ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, message.toString()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java index 113ba9ed25d..bfd5d8d07f6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/StopVMCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vm; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "stopVirtualMachine", responseObject = UserVmResponse.class, description = "Stops a virtual machine.", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class StopVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(StopVMCmd.class.getName()); private static final String s_name = "stopvirtualmachineresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java index ff533f82095..837bde06a6c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateDefaultNicForVMCmd.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.EnumSet; import com.cloud.vm.Nic; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -45,7 +44,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "updateDefaultNicForVirtualMachine", description = "Changes the default NIC on a VM", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateDefaultNicForVMCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateDefaultNicForVMCmd.class); private static final String s_name = "updatedefaultnicforvirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java index 32ce1f6db52..9f72ac17c8f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVMCmd.java @@ -23,7 +23,6 @@ import java.util.Map; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.api.response.UserDataResponse; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -54,7 +53,6 @@ import com.cloud.vm.VirtualMachine; "Therefore, stop the VM manually before issuing this call.", responseObject = UserVmResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpdateVMCmd extends BaseCustomIdCmd implements SecurityGroupAction, UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVMCmd.class.getName()); private static final String s_name = "updatevirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVmNicIpCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVmNicIpCmd.java index 40658f9b58d..5c654701de9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVmNicIpCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpdateVmNicIpCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.vm; import java.util.ArrayList; import java.util.EnumSet; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -49,7 +48,6 @@ import com.cloud.vm.Nic; @APICommand(name = "updateVmNicIp", description = "Update the default Ip of a VM Nic", responseObject = UserVmResponse.class) public class UpdateVmNicIpCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVmNicIpCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java index 4b31c12ec0a..6a7422e70bb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vm/UpgradeVMCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.vm; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -47,7 +46,6 @@ import com.cloud.vm.VirtualMachine; "this command to take effect.", responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class UpgradeVMCmd extends BaseCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpgradeVMCmd.class.getName()); private static final String s_name = "changeserviceforvirtualmachineresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java index 154ec45873a..e2952b5bd81 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/CreateVMGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vmgroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.vm.InstanceGroup; @APICommand(name = "createInstanceGroup", description = "Creates a vm group", responseObject = InstanceGroupResponse.class, entityType = {InstanceGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVMGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(CreateVMGroupCmd.class.getName()); // /////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java index 0bdda0bb9e7..b74bc43eeb7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/DeleteVMGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vmgroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -35,7 +34,6 @@ import com.cloud.vm.InstanceGroup; @APICommand(name = "deleteInstanceGroup", description = "Deletes a vm group", responseObject = SuccessResponse.class, entityType = {InstanceGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVMGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVMGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/ListVMGroupsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/ListVMGroupsCmd.java index 2e61c898ae0..31845a956e9 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/ListVMGroupsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/ListVMGroupsCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vmgroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -30,7 +29,6 @@ import com.cloud.vm.InstanceGroup; @APICommand(name = "listInstanceGroups", description = "Lists vm groups", responseObject = InstanceGroupResponse.class, entityType = {InstanceGroup.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVMGroupsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVMGroupsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java index 8873c852460..5c553f06404 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmgroup/UpdateVMGroupCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vmgroup; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -35,7 +34,6 @@ import com.cloud.vm.InstanceGroup; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVMGroupCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVMGroupCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/CreateVMSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/CreateVMSnapshotCmd.java index 2c0ea6bc4ae..18a478e9dae 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/CreateVMSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/CreateVMSnapshotCmd.java @@ -30,7 +30,6 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VMSnapshotResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceAllocationException; @@ -42,7 +41,6 @@ import com.cloud.vm.snapshot.VMSnapshot; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVMSnapshotCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVMSnapshotCmd.class.getName()); @ACL(accessType = AccessType.OperateEntry) @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, required = true, entityType = UserVmResponse.class, description = "The ID of the vm") @@ -138,4 +136,10 @@ public class CreateVMSnapshotCmd extends BaseAsyncCreateCmd { public ApiCommandResourceType getApiResourceType() { return ApiCommandResourceType.VmSnapshot; } + + @Override + public Long getApiResourceId() { + return getEntityId(); + } + } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/DeleteVMSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/DeleteVMSnapshotCmd.java index bcddc75a8e7..94b8824f868 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/DeleteVMSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/DeleteVMSnapshotCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.vmsnapshot; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ import com.cloud.vm.snapshot.VMSnapshot; @APICommand(name = "deleteVMSnapshot", description = "Deletes a vmsnapshot.", responseObject = SuccessResponse.class, since = "4.2.0", entityType = {VMSnapshot.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVMSnapshotCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVMSnapshotCmd.class.getName()); @ACL(accessType = AccessType.OperateEntry) @Parameter(name = ApiConstants.VM_SNAPSHOT_ID, diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java index 42cd18bfa2f..310b45687d4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vmsnapshot/RevertToVMSnapshotCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vmsnapshot; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -45,7 +44,6 @@ import com.cloud.vm.snapshot.VMSnapshot; @APICommand(name = "revertToVMSnapshot", description = "Revert VM from a vmsnapshot.", responseObject = UserVmResponse.class, since = "4.2.0", responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RevertToVMSnapshotCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(RevertToVMSnapshotCmd.class.getName()); private static final String s_name = "reverttovmsnapshotresponse"; @ACL(accessType = AccessType.OperateEntry, pointerToEntity = "getVmId()") diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java index 8d472d96eef..287991fa984 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AddResourceDetailCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.volume; import java.util.Map; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -33,7 +32,6 @@ import com.cloud.server.ResourceTag; @APICommand(name = "addResourceDetail", description = "Adds detail for the Resource.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddResourceDetailCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddResourceDetailCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AssignVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AssignVolumeCmd.java index 03413682c4f..1a51aa03c22 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AssignVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AssignVolumeCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.VolumeResponse; -import org.apache.log4j.Logger; import com.cloud.storage.Volume; @@ -38,7 +37,6 @@ import java.util.Map; @APICommand(name = AssignVolumeCmd.CMD_NAME, responseObject = VolumeResponse.class, description = "Changes ownership of a Volume from one account to another.", entityType = { Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0.0") public class AssignVolumeCmd extends BaseCmd implements UserCmd { - public static final Logger LOGGER = Logger.getLogger(AssignVolumeCmd.class.getName()); public static final String CMD_NAME = "assignVolume"; ///////////////////////////////////////////////////// @@ -96,7 +94,7 @@ public class AssignVolumeCmd extends BaseCmd implements UserCmd { } catch (CloudRuntimeException | ResourceAllocationException e) { String msg = String.format("Assign volume command for volume [%s] failed due to [%s].", getFullUrlParams().get("volumeid"), e.getMessage()); - LOGGER.error(msg, e); + logger.error(msg, e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, msg); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java index 687d683309c..1a3b9220877 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/AttachVolumeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "attachVolume", description = "Attaches a disk volume to a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AttachVolumeCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(AttachVolumeCmd.class.getName()); private static final String s_name = "attachvolumeresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java new file mode 100644 index 00000000000..56fdf6bc126 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmd.java @@ -0,0 +1,138 @@ +// 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 org.apache.cloudstack.api.command.user.volume; + +import java.util.Arrays; + +import org.apache.cloudstack.acl.RoleType; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.ApiErrorCode; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ResponseObject.ResponseView; +import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.response.VolumeResponse; +import org.apache.cloudstack.context.CallContext; +import org.apache.commons.lang3.EnumUtils; + +import com.cloud.event.EventTypes; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.storage.Volume; +import com.cloud.user.Account; +import com.cloud.utils.Pair; +import com.cloud.utils.StringUtils; + +@APICommand(name = "checkVolume", description = "Check the volume for any errors or leaks and also repairs when repair parameter is passed, this is currently supported for KVM only", responseObject = VolumeResponse.class, entityType = {Volume.class}, + since = "4.19.1", + authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) +public class CheckAndRepairVolumeCmd extends BaseAsyncCmd { + + private static final String s_name = "checkandrepairvolumeresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = VolumeResponse.class, required = true, description = "The ID of the volume") + private Long id; + + @Parameter(name = ApiConstants.REPAIR, type = CommandType.STRING, required = false, description = "parameter to repair the volume, leaks or all are the possible values") + private String repair; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public enum RepairValues { + LEAKS, ALL + } + + public Long getId() { + return id; + } + + public String getRepair() { + if (org.apache.commons.lang3.StringUtils.isNotEmpty(repair)) { + RepairValues repairType = EnumUtils.getEnumIgnoreCase(RepairValues.class, repair); + if (repairType == null) { + throw new InvalidParameterValueException(String.format("Repair parameter can only take the following values: %s", Arrays.toString(RepairValues.values()))); + } + return repair.toLowerCase(); + } + return null; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + Volume volume = _entityMgr.findById(Volume.class, getId()); + if (volume != null) { + return volume.getAccountId(); + } + + return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked + } + + @Override + public String getEventType() { + return EventTypes.EVENT_VOLUME_CHECK; + } + + @Override + public String getEventDescription() { + return String.format("check and repair operation on volume: %s", this._uuidMgr.getUuid(Volume.class, getId())); + } + + @Override + public Long getApiResourceId() { + return id; + } + + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.Volume; + } + + @Override + public void execute() throws ResourceAllocationException { + CallContext.current().setEventDetails("Volume Id: " + getId()); + Pair result = _volumeService.checkAndRepairVolume(this); + Volume volume = _responseGenerator.findVolumeById(getId()); + if (result != null) { + VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume); + response.setVolumeCheckResult(StringUtils.parseJsonToMap(result.first())); + if (getRepair() != null) { + response.setVolumeRepairResult(StringUtils.parseJsonToMap(result.second())); + } + response.setResponseName(getCommandName()); + setResponseObject(response); + } else { + throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to check volume and repair"); + } + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java index 566e8a46bd9..7ffcea50b21 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -48,7 +47,6 @@ import com.cloud.vm.VirtualMachine; Volume.class, VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateVolumeCmd.class.getName()); private static final String s_name = "createvolumeresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java index 4bcc8a88545..6111488a802 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DeleteVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteVolume", description = "Deletes a detached disk volume.", responseObject = SuccessResponse.class, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVolumeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVolumeCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DestroyVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DestroyVolumeCmd.java index f4007ce9f40..2eafb76e591 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DestroyVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DestroyVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -42,7 +41,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class DestroyVolumeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DestroyVolumeCmd.class.getName()); private static final String s_name = "destroyvolumeresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java index e92f6a3cb0d..2fddcace84d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/DetachVolumeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -42,7 +41,6 @@ import com.cloud.vm.VirtualMachine; @APICommand(name = "detachVolume", description = "Detaches a disk volume from a virtual machine.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {VirtualMachine.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DetachVolumeCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(DetachVolumeCmd.class.getName()); private static final String s_name = "detachvolumeresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java index 8f6e3a6c120..1146f80f0e2 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ExtractVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -41,7 +40,6 @@ import com.cloud.user.Account; @APICommand(name = "extractVolume", description = "Extracts volume", responseObject = ExtractResponse.class, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ExtractVolumeCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ExtractVolumeCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/GetUploadParamsForVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/GetUploadParamsForVolumeCmd.java index 1342ffc4748..4ccd5f97993 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/GetUploadParamsForVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/GetUploadParamsForVolumeCmd.java @@ -30,12 +30,10 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.DiskOfferingResponse; import org.apache.cloudstack.api.response.GetUploadParamsResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "getUploadParamsForVolume", description = "Upload a data disk to the cloudstack cloud.", responseObject = GetUploadParamsResponse.class, since = "4.6.0", requestHasSensitiveInfo= false, responseHasSensitiveInfo = false) public class GetUploadParamsForVolumeCmd extends AbstractGetUploadParamsCmd { - public static final Logger s_logger = Logger.getLogger(GetUploadParamsForVolumeCmd.class.getName()); private static final String s_name = "postuploadvolumeresponse"; @@ -62,7 +60,7 @@ public class GetUploadParamsForVolumeCmd extends AbstractGetUploadParamsCmd { response.setResponseName(getCommandName()); setResponseObject(response); } catch (MalformedURLException | ResourceAllocationException e) { - s_logger.error("exception while uploading volume", e); + logger.error("exception while uploading volume", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "exception while uploading a volume: " + e.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java index b62a909d71f..a583675da76 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ListVolumesCmd.java @@ -36,14 +36,12 @@ import org.apache.cloudstack.api.response.UserVmResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.storage.Volume; @APICommand(name = "listVolumes", description = "Lists all volumes.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = { Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVolumesCmd extends BaseListRetrieveOnlyResourceCountCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListVolumesCmd.class.getName()); private static final String s_name = "listvolumesresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RecoverVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RecoverVolumeCmd.java index 2589f816bc6..cd5a7735e38 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RecoverVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RecoverVolumeCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -39,7 +38,6 @@ import com.cloud.user.Account; requestHasSensitiveInfo = false, responseHasSensitiveInfo = true) public class RecoverVolumeCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(RecoverVolumeCmd.class.getName()); private static final String s_name = "recovervolumeresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RemoveResourceDetailCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RemoveResourceDetailCmd.java index 98fe6a7e821..bad839f8ac7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RemoveResourceDetailCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/RemoveResourceDetailCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -31,7 +30,6 @@ import com.cloud.server.ResourceTag; @APICommand(name = "removeResourceDetail", description = "Removes detail for the Resource.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveResourceDetailCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveResourceDetailCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java index 0daf141ba4a..9254bad207b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/ResizeVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -44,7 +43,6 @@ import com.cloud.user.Account; @APICommand(name = "resizeVolume", description = "Resizes a volume", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ResizeVolumeCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ResizeVolumeCmd.class.getName()); private static final String s_name = "resizevolumeresponse"; @@ -195,10 +193,10 @@ public class ResizeVolumeCmd extends BaseAsyncCmd implements UserCmd { volume = _volumeService.resizeVolume(this); } catch (ResourceAllocationException ex) { - s_logger.error(ex.getMessage()); + logger.error(ex.getMessage()); throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, ex.getMessage()); } catch (InvalidParameterValueException ex) { - s_logger.info(ex.getMessage()); + logger.info(ex.getMessage()); throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java index e7782674828..467c587cc73 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.volume; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -41,7 +40,6 @@ import com.cloud.storage.Volume; @APICommand(name = "updateVolume", description = "Updates the volume.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVolumeCmd.class.getName()); private static final String s_name = "updatevolumeresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java index c622081079d..339c276d59e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/volume/UploadVolumeCmd.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.VolumeResponse; import org.apache.cloudstack.api.response.ZoneResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.event.EventTypes; @@ -45,7 +44,6 @@ import com.cloud.storage.Volume; @APICommand(name = "uploadVolume", description = "Uploads a data disk.", responseObject = VolumeResponse.class, responseView = ResponseView.Restricted, entityType = {Volume.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UploadVolumeCmd extends BaseAsyncCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UploadVolumeCmd.class.getName()); private static final String s_name = "uploadvolumeresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreatePrivateGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreatePrivateGatewayCmd.java index cf1315c9d55..dceaabf648d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreatePrivateGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreatePrivateGatewayCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -52,7 +51,6 @@ import com.cloud.network.vpc.VpcGateway; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreatePrivateGatewayCmd.class.getName()); private static final String s_name = "createprivategatewayresponse"; @@ -149,11 +147,11 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd implements UserC try { result = _vpcService.createVpcPrivateGateway(this); } catch (InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java index 68d7a77d946..b28c02cb800 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiCommandResourceType; @@ -42,7 +41,6 @@ import com.cloud.network.vpc.VpcGateway; @APICommand(name = "createStaticRoute", description = "Creates a static route", responseObject = StaticRouteResponse.class, entityType = {StaticRoute.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateStaticRouteCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateStaticRouteCmd.class.getName()); @Parameter(name = ApiConstants.GATEWAY_ID, type = CommandType.UUID, @@ -75,8 +73,8 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd { setEntityId(result.getId()); setEntityUuid(result.getUuid()); } catch (NetworkRuleConflictException ex) { - s_logger.info("Network rule conflict: " + ex.getMessage()); - s_logger.trace("Network rule conflict: ", ex); + logger.info("Network rule conflict: " + ex.getMessage()); + logger.trace("Network rule conflict: ", ex); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java index 7ca66b2a471..94f05f707a0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpc; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -46,7 +45,6 @@ import com.cloud.network.vpc.Vpc; @APICommand(name = "createVPC", description = "Creates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(CreateVPCCmd.class.getName()); private static final String s_name = "createvpcresponse"; // /////////////////////////////////////////////////// @@ -213,18 +211,18 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd implements UserCmd { if (isStart()) { _vpcService.startVpc(getEntityId(), true); } else { - s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API"); + logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API"); } vpc = _entityMgr.findById(Vpc.class, getEntityId()); } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java index 6210d80586f..01b6aae425b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteStaticRouteCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -40,7 +39,6 @@ import com.cloud.network.vpc.StaticRoute; @APICommand(name = "deleteStaticRoute", description = "Deletes a static route", responseObject = SuccessResponse.class, entityType = {StaticRoute.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteStaticRouteCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteStaticRouteCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java index f408e32f62d..c35d9084bcc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/DeleteVPCCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpc; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteVPC", description = "Deletes a VPC", responseObject = SuccessResponse.class, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVPCCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVPCCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -81,10 +79,10 @@ public class DeleteVPCCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete VPC"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java index 8813cccc779..2304cef3c6d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.vpc; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -39,7 +38,6 @@ import com.cloud.utils.Pair; responseView = ResponseObject.ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListPrivateGatewaysCmd extends BaseListProjectAndAccountResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListPrivateGatewaysCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java index c0f95fcd361..f48e113286a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.VpcOfferingResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.network.vpc.VpcOffering; import com.cloud.utils.Pair; @@ -35,7 +34,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listVPCOfferings", description = "Lists VPC offerings", responseObject = VpcOfferingResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVPCOfferingsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListVPCOfferingsCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java index 76cbcca61bb..d128be1414d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.response.ResourceIconResponse; import org.apache.cloudstack.api.response.VpcOfferingResponse; import org.apache.cloudstack.api.response.VpcResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; import com.cloud.network.vpc.Vpc; import com.cloud.utils.Pair; @@ -42,7 +41,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listVPCs", description = "Lists VPCs", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVPCsCmd extends BaseListTaggedResourcesCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListVPCsCmd.class.getName()); private static final String s_name = "listvpcsresponse"; ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java index 04946619c0a..5ccd496eeb4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.VpcResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "restartVPC", description = "Restarts a VPC", responseObject = SuccessResponse.class, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RestartVPCCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RestartVPCCmd.class.getName()); ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// @@ -101,14 +99,14 @@ public class RestartVPCCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to restart VPC"); } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (final ConcurrentOperationException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); } catch (final InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java index d4c7d0d5c59..6fcfb5311f6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpc; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.SecurityChecker.AccessType; @@ -42,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "updateVPC", description = "Updates a VPC", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVPCCmd extends BaseAsyncCustomIdCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVPCCmd.class.getName()); private static final String s_name = "updatevpcresponse"; ///////////////////////////////////////////////////// @@ -129,11 +127,11 @@ public class UpdateVPCCmd extends BaseAsyncCustomIdCmd implements UserCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update VPC"); } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } catch (final InsufficientCapacityException ex) { - s_logger.info(ex); - s_logger.trace(ex); + logger.info(ex); + logger.trace(ex); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java index f3b452008c9..9e950310cdc 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/AddVpnUserCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "addVpnUser", description = "Adds vpn users", responseObject = VpnUsersResponse.class, entityType = {VpnUser.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddVpnUserCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(AddVpnUserCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java index 8ecf4b051ce..417ba2773c4 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpn; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -41,7 +40,6 @@ import com.cloud.network.RemoteAccessVpn; @APICommand(name = "createRemoteAccessVpn", description = "Creates a l2tp/ipsec remote access vpn", responseObject = RemoteAccessVpnResponse.class, entityType = {RemoteAccessVpn.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateRemoteAccessVpnCmd.class.getName()); ///////////////////////////////////////////////////// @@ -148,8 +146,8 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create remote access vpn"); } } catch (NetworkRuleConflictException e) { - s_logger.info("Network rule conflict: " + e.getMessage()); - s_logger.trace("Network Rule Conflict: ", e); + logger.info("Network rule conflict: " + e.getMessage()); + logger.trace("Network Rule Conflict: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } @@ -166,7 +164,7 @@ public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create remote access vpn"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java index 84aaafc60ed..0b5c46d36eb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -41,7 +40,6 @@ import com.cloud.network.vpc.Vpc; @APICommand(name = "createVpnConnection", description = "Create site to site vpn connection", responseObject = Site2SiteVpnConnectionResponse.class, entityType = {Site2SiteVpnConnection.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVpnConnectionCmd.class.getName()); ///////////////////////////////////////////////////// @@ -135,8 +133,8 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create site to site vpn connection"); } } catch (NetworkRuleConflictException e) { - s_logger.info("Network rule conflict: " + e.getMessage()); - s_logger.trace("Network Rule Conflict: ", e); + logger.info("Network rule conflict: " + e.getMessage()); + logger.trace("Network Rule Conflict: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } } @@ -153,7 +151,7 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create site to site vpn connection"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java index 88c6c12fac7..a2fa0d9829c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ProjectResponse; import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.ResourceAllocationException; @@ -37,7 +36,6 @@ import com.cloud.network.Site2SiteCustomerGateway; @APICommand(name = "createVpnCustomerGateway", description = "Creates site to site vpn customer gateway", responseObject = Site2SiteCustomerGatewayResponse.class, entityType = {Site2SiteCustomerGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVpnCustomerGatewayCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVpnCustomerGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java index c354e972737..6f31176c4ff 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java @@ -31,12 +31,10 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse; import org.apache.cloudstack.api.response.VpcResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; @APICommand(name = "createVpnGateway", description = "Creates site to site vpn local gateway", responseObject = Site2SiteVpnGatewayResponse.class, entityType = {Site2SiteVpnGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class CreateVpnGatewayCmd extends BaseAsyncCreateCmd { - public static final Logger s_logger = Logger.getLogger(CreateVpnGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java index dfc80b2fabc..bf8d0157923 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpn; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -38,7 +37,6 @@ import com.cloud.network.RemoteAccessVpn; @APICommand(name = "deleteRemoteAccessVpn", description = "Destroys a l2tp/ipsec remote access vpn", responseObject = SuccessResponse.class, entityType = {RemoteAccessVpn.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteRemoteAccessVpnCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java index 8a57dfc8edd..2528d93a042 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteVpnConnection", description = "Delete site to site vpn connection", responseObject = SuccessResponse.class, entityType = {Site2SiteVpnConnection.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVpnConnectionCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVpnConnectionCmd.class.getName()); ///////////////////////////////////////////////////// @@ -86,7 +84,7 @@ public class DeleteVpnConnectionCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete site to site VPN connection"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java index e2f0aee90ec..2b657fd3c08 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.api.command.user.vpn; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.SecurityChecker.AccessType; import org.apache.cloudstack.api.ACL; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteVpnCustomerGateway", description = "Delete site to site vpn customer gateway", responseObject = SuccessResponse.class, entityType = {Site2SiteCustomerGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVpnCustomerGatewayCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVpnCustomerGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java index b7acc5c4506..27ded12dc58 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.user.Account; @APICommand(name = "deleteVpnGateway", description = "Delete site to site vpn gateway", responseObject = SuccessResponse.class, entityType = {Site2SiteVpnGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DeleteVpnGatewayCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteVpnGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java index 1f2f95188e7..4efc70c8419 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.vpn; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -37,7 +36,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listRemoteAccessVpns", description = "Lists remote access vpns", responseObject = RemoteAccessVpnResponse.class, entityType = {RemoteAccessVpn.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListRemoteAccessVpnsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListRemoteAccessVpnsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java index 763a374645b..aeeae44d004 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.vpn; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -36,7 +35,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listVpnConnections", description = "Lists site to site vpn connection gateways", responseObject = Site2SiteVpnConnectionResponse.class, entityType = {Site2SiteVpnConnection.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVpnConnectionsCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVpnConnectionsCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java index b66c47899f7..258a8a753eb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.vpn; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listVpnCustomerGateways", description = "Lists site to site vpn customer gateways", responseObject = Site2SiteCustomerGatewayResponse.class, entityType = {Site2SiteCustomerGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVpnCustomerGatewaysCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVpnCustomerGatewaysCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java index fb9c8262003..d30fbf8d32b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.vpn; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; @@ -36,7 +35,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listVpnGateways", description = "Lists site 2 site vpn gateways", responseObject = Site2SiteVpnGatewayResponse.class, entityType = {Site2SiteVpnGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVpnGatewaysCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVpnGatewaysCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnUsersCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnUsersCmd.java index 9f8581eb014..48591765ec3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnUsersCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ListVpnUsersCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.vpn; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -34,7 +33,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listVpnUsers", description = "Lists vpn users", responseObject = VpnUsersResponse.class, entityType = {VpnUser.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListVpnUsersCmd extends BaseListProjectAndAccountResourcesCmd { - public static final Logger s_logger = Logger.getLogger(ListVpnUsersCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java index 4adf385b127..48e7a9ee519 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/RemoveVpnUserCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; @APICommand(name = "removeVpnUser", description = "Removes vpn user", responseObject = SuccessResponse.class, entityType = {VpnUser.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class RemoveVpnUserCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(RemoveVpnUserCmd.class.getName()); ///////////////////////////////////////////////////// @@ -109,7 +107,7 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd { boolean result = _ravService.removeVpnUser(ownerId, userName, CallContext.current().getCallingAccount()); if (!result) { String errorMessage = String.format("Failed to remove VPN user=[%s]. VPN owner id=[%s].", userName, ownerId); - s_logger.error(errorMessage); + logger.error(errorMessage); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage); } @@ -118,13 +116,13 @@ public class RemoveVpnUserCmd extends BaseAsyncCmd { appliedVpnUsers = _ravService.applyVpnUsers(ownerId, userName, true); } catch (ResourceUnavailableException ex) { String errorMessage = String.format("Failed to refresh VPN user=[%s] due to resource unavailable. VPN owner id=[%s].", userName, ownerId); - s_logger.error(errorMessage, ex); + logger.error(errorMessage, ex); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage, ex); } if (!appliedVpnUsers) { String errorMessage = String.format("Failed to refresh VPN user=[%s]. VPN owner id=[%s].", userName, ownerId); - s_logger.debug(errorMessage); + logger.debug(errorMessage); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage); } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java index c63126578f2..736295b4119 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.api.command.user.vpn; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "resetVpnConnection", description = "Reset site to site vpn connection", responseObject = Site2SiteVpnConnectionResponse.class, entityType = {Site2SiteVpnConnection.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ResetVpnConnectionCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ResetVpnConnectionCmd.class.getName()); ///////////////////////////////////////////////////// @@ -105,7 +103,7 @@ public class ResetVpnConnectionCmd extends BaseAsyncCmd { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset site to site VPN connection"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Exception: ", ex); + logger.warn("Exception: ", ex); throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage()); } } diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java index d5b36f662f9..defde70b63a 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateRemoteAccessVpnCmd.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.AccountResponse; import org.apache.cloudstack.api.response.RemoteAccessVpnResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.exception.InvalidParameterValueException; @@ -32,7 +31,6 @@ import com.cloud.network.RemoteAccessVpn; @APICommand(name = "updateRemoteAccessVpn", description = "Updates remote access vpn", responseObject = RemoteAccessVpnResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateRemoteAccessVpnCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateRemoteAccessVpnCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java index 67cb65bdb93..62dd6167b75 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnConnectionCmd.java @@ -22,7 +22,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.Site2SiteVpnConnection; @@ -31,7 +30,6 @@ import com.cloud.user.Account; @APICommand(name = "updateVpnConnection", description = "Updates site to site vpn connection", responseObject = Site2SiteVpnConnectionResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVpnConnectionCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVpnConnectionCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java index 179bc0407b4..9f3ac2ec436 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnCustomerGatewayCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.vpn; import org.apache.cloudstack.api.ApiArgValidator; import org.apache.cloudstack.api.ApiCommandResourceType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.network.Site2SiteCustomerGateway; @APICommand(name = "updateVpnCustomerGateway", description = "Update site to site vpn customer gateway", responseObject = Site2SiteCustomerGatewayResponse.class, entityType = {Site2SiteCustomerGateway.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVpnCustomerGatewayCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVpnCustomerGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java index c69bbb5689f..9fe5ae0480f 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/vpn/UpdateVpnGatewayCmd.java @@ -22,7 +22,6 @@ import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseAsyncCustomIdCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse; -import org.apache.log4j.Logger; import com.cloud.event.EventTypes; import com.cloud.network.Site2SiteVpnGateway; @@ -31,7 +30,6 @@ import com.cloud.user.Account; @APICommand(name = "updateVpnGateway", description = "Updates site to site vpn local gateway", responseObject = Site2SiteVpnGatewayResponse.class, since = "4.4", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class UpdateVpnGatewayCmd extends BaseAsyncCustomIdCmd { - public static final Logger s_logger = Logger.getLogger(UpdateVpnGatewayCmd.class.getName()); ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java index c29f3a85106..d926257437e 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/zone/ListZonesCmd.java @@ -29,12 +29,10 @@ import org.apache.cloudstack.api.command.user.UserCmd; import org.apache.cloudstack.api.response.DomainResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ZoneResponse; -import org.apache.log4j.Logger; @APICommand(name = "listZones", description = "Lists zones", responseObject = ZoneResponse.class, responseView = ResponseView.Restricted, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListZonesCmd extends BaseListCmd implements UserCmd { - public static final Logger s_logger = Logger.getLogger(ListZonesCmd.class.getName()); private static final String s_name = "listzonesresponse"; diff --git a/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java index 7ffe7d095e4..7a84e85a4a6 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/AccountResponse.java @@ -267,6 +267,10 @@ public class AccountResponse extends BaseResponse implements ResourceLimitAndCou @Param(description = "Base64 string representation of the resource icon", since = "4.16.0.0") ResourceIconResponse icon; + @SerializedName(ApiConstants.TAGGED_RESOURCES) + @Param(description = "The tagged resource limit and count for the account", since = "4.20.0") + List taggedResources; + @Override public String getObjectId() { return id; @@ -545,4 +549,9 @@ public class AccountResponse extends BaseResponse implements ResourceLimitAndCou public void setResourceIconResponse(ResourceIconResponse icon) { this.icon = icon; } + + @Override + public void setTaggedResourceLimitsAndCounts(List taggedResourceLimitsAndCounts) { + this.taggedResources = taggedResourceLimitsAndCounts; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/AlertTypeResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/AlertTypeResponse.java new file mode 100644 index 00000000000..3f91cde0178 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/AlertTypeResponse.java @@ -0,0 +1,55 @@ +// 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 org.apache.cloudstack.api.response; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; + +public class AlertTypeResponse extends BaseResponse { + + @SerializedName("alerttypeid") + @Param(description = "alert type") + private short alertType; + + @SerializedName(ApiConstants.NAME) + @Param(description = "description of alert type") + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public short getUsageType() { + return alertType; + } + + public void setUsageType(short alertType) { + this.alertType = alertType; + } + + public AlertTypeResponse(short alertType, String name) { + this.alertType = alertType; + this.name = name; + setObjectName("alerttype"); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java index e9724497c38..2d0e2158651 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/CapacityResponse.java @@ -16,12 +16,11 @@ // under the License. package org.apache.cloudstack.api.response; -import com.google.gson.annotations.SerializedName; - import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; public class CapacityResponse extends BaseResponse { @SerializedName(ApiConstants.TYPE) @@ -72,6 +71,10 @@ public class CapacityResponse extends BaseResponse { @Param(description = "the percentage of capacity currently in use") private String percentUsed; + @SerializedName(ApiConstants.TAG) + @Param(description = "The tag for the capacity type", since = "4.20.0") + private String tag; + public Short getCapacityType() { return capacityType; } @@ -167,4 +170,8 @@ public class CapacityResponse extends BaseResponse { public void setPercentUsed(String percentUsed) { this.percentUsed = percentUsed; } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java index b8244aebc60..0fed9827ef1 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/DiskOfferingResponse.java @@ -53,6 +53,10 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "the name of the disk offering") private String name; + @SerializedName(ApiConstants.STATE) + @Param(description = "state of the disk offering") + private String state; + @SerializedName(ApiConstants.DISPLAY_TEXT) @Param(description = "an alternate display text of the disk offering.") private String displayText; @@ -169,6 +173,10 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "additional key/value details tied with this disk offering", since = "4.17") private Map details; + @SerializedName(ApiConstants.SUITABLE_FOR_VM) + @Param(description = "Returns true if the disk offering is suitable for the given virtual machine for disk creation otherwise false", since = "4.20.0") + private Boolean suitableForVm; + public Boolean getDisplayOffering() { return displayOffering; } @@ -226,6 +234,14 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations { this.name = name; } + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + public String getDisplayText() { return displayText; } @@ -391,4 +407,8 @@ public class DiskOfferingResponse extends BaseResponseWithAnnotations { public void setDetails(Map details) { this.details = details; } + + public void setSuitableForVm(Boolean suitableForVm) { + this.suitableForVm = suitableForVm; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java index e4e409a40ee..7c6ad3a91c3 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/DomainResponse.java @@ -26,6 +26,7 @@ import com.cloud.domain.Domain; import com.cloud.serializer.Param; import java.util.Date; +import java.util.List; import java.util.Map; @EntityReference(value = Domain.class) @@ -184,6 +185,10 @@ public class DomainResponse extends BaseResponseWithAnnotations implements Resou @Param(description = "details for the domain") private Map details; + @SerializedName(ApiConstants.TAGGED_RESOURCES) + @Param(description = "The tagged resource limit and count for the domain", since = "4.20.0") + List taggedResources; + public String getId() { return this.id; } @@ -447,4 +452,9 @@ public class DomainResponse extends BaseResponseWithAnnotations implements Resou public void setDetails(Map details) { this.details = details; } + + @Override + public void setTaggedResourceLimitsAndCounts(List taggedResourceLimitsAndCounts) { + this.taggedResources = taggedResourceLimitsAndCounts; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java index e2bf6ef5c60..8a9bf7789dd 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java @@ -167,6 +167,10 @@ public class IPAddressResponse extends BaseResponseWithAnnotations implements Co @Param(description="whether the ip address has Firewall/PortForwarding/LoadBalancing rules defined") private boolean hasRules; + @SerializedName(ApiConstants.FOR_SYSTEM_VMS) + @Param(description="true if range is dedicated for System VMs") + private boolean forSystemVms; + public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; } @@ -316,4 +320,8 @@ public class IPAddressResponse extends BaseResponseWithAnnotations implements Co public void setHasRules(final boolean hasRules) { this.hasRules = hasRules; } + + public void setForSystemVms(boolean forSystemVms) { + this.forSystemVms = forSystemVms; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/IpQuarantineResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/IpQuarantineResponse.java index 55720296315..c93f259382c 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/IpQuarantineResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/IpQuarantineResponse.java @@ -60,6 +60,10 @@ public class IpQuarantineResponse extends BaseResponse { @Param(description = "The reason for removing the IP from quarantine prematurely.") private String removalReason; + @SerializedName(ApiConstants.REMOVER_ACCOUNT_ID) + @Param(description = "ID of the account that removed the IP from quarantine.") + private String removerAccountId; + public IpQuarantineResponse() { super("quarantinedips"); } @@ -127,4 +131,12 @@ public class IpQuarantineResponse extends BaseResponse { public void setRemovalReason(String removalReason) { this.removalReason = removalReason; } + + public String getRemoverAccountId() { + return removerAccountId; + } + + public void setRemoverAccountId(String removerAccountId) { + this.removerAccountId = removerAccountId; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/NetworkOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/NetworkOfferingResponse.java index b92725d883e..b73163a5d05 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/NetworkOfferingResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/NetworkOfferingResponse.java @@ -99,10 +99,18 @@ public class NetworkOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "true if network offering can be used by VPC networks only") private Boolean forVpc; + @SerializedName(ApiConstants.FOR_NSX) + @Param(description = "true if network offering can be used by NSX networks only") + private Boolean forNsx; + @SerializedName(ApiConstants.FOR_TUNGSTEN) @Param(description = "true if network offering can be used by Tungsten-Fabric networks only") private Boolean forTungsten; + @SerializedName(ApiConstants.NSX_MODE) + @Param(description = "Mode in which the network will operate. This parameter is only relevant for NSX offerings") + private String nsxMode; + @SerializedName(ApiConstants.IS_PERSISTENT) @Param(description = "true if network offering supports persistent networks, false otherwise") private Boolean isPersistent; @@ -127,6 +135,10 @@ public class NetworkOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "true if network offering supports public access for guest networks", since = "4.10.0") private Boolean supportsPublicAccess; + @SerializedName(ApiConstants.SUPPORTS_INTERNAL_LB) + @Param(description = "true if network offering supports public access for guest networks", since = "4.20.0") + private Boolean supportsInternalLb; + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description = "the domain ID(s) this disk offering belongs to. Ignore this information as it is not currently applicable.") private String domainId; @@ -215,10 +227,18 @@ public class NetworkOfferingResponse extends BaseResponseWithAnnotations { this.forVpc = forVpc; } + public void setForNsx(Boolean forNsx) { + this.forNsx = forNsx; + } + public void setForTungsten(Boolean forTungsten) { this.forTungsten = forTungsten; } + public void setNsxMode(String nsxMode) { + this.nsxMode = nsxMode; + } + public void setIsPersistent(Boolean isPersistent) { this.isPersistent = isPersistent; } @@ -243,6 +263,10 @@ public class NetworkOfferingResponse extends BaseResponseWithAnnotations { this.supportsPublicAccess = supportsPublicAccess; } + public void setSupportsInternalLb(Boolean supportsInternalLb) { + this.supportsInternalLb = supportsInternalLb; + } + public String getDomainId() { return domainId; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/NetworkProtocolResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/NetworkProtocolResponse.java new file mode 100644 index 00000000000..775333f7192 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/NetworkProtocolResponse.java @@ -0,0 +1,89 @@ +// 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 org.apache.cloudstack.api.response; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class NetworkProtocolResponse extends BaseResponse { + @SerializedName(ApiConstants.INDEX) + @Param(description = "the index (ID, Value, Code, Type, Option, etc) of the protocol parameter") + private Integer index; + + @SerializedName(ApiConstants.NAME) + @Param(description = "the name of the protocol parameter") + private String name; + + @SerializedName(ApiConstants.DESCRIPTION) + @Param(description = "the description of the protocol parameter") + private String description; + + @SerializedName(ApiConstants.DETAILS) + @Param(description = "the details of the protocol parameter") + private Map details; + + public NetworkProtocolResponse(Integer index, String name, String description) { + this.index = index; + this.name = name; + this.description = description; + } + + public Integer getIndex() { + return index; + } + + public void setIndex(Integer index) { + this.index = index; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Map getDetails() { + return details; + } + + public void setDetails(Map details) { + this.details = details; + } + + public void addDetail(String key, String value) { + if (this.details == null) { + this.details = new LinkedHashMap(); + } + this.details.put(key, value); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java index c43dd09b127..1c63697559b 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ProjectResponse.java @@ -216,6 +216,10 @@ public class ProjectResponse extends BaseResponse implements ResourceLimitAndCou @Param(description = "the date this project was created", since = "4.16.0") private Date created; + @SerializedName(ApiConstants.TAGGED_RESOURCES) + @Param(description = "The tagged resource limit and count for the project", since = "4.20.0") + List taggedResources; + public void setId(String id) { this.id = id; } @@ -447,4 +451,9 @@ public class ProjectResponse extends BaseResponse implements ResourceLimitAndCou public void setCreated(Date created) { this.created = created; } + + @Override + public void setTaggedResourceLimitsAndCounts(List taggedResourceLimitsAndCounts) { + this.taggedResources = taggedResourceLimitsAndCounts; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java index d0a4982f872..3a698618585 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ResourceCountResponse.java @@ -16,13 +16,12 @@ // under the License. package org.apache.cloudstack.api.response; -import com.cloud.configuration.Resource; -import com.google.gson.annotations.SerializedName; - import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; +import com.cloud.configuration.Resource; import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") public class ResourceCountResponse extends BaseResponse implements ControlledEntityResponse { @@ -54,10 +53,14 @@ public class ResourceCountResponse extends BaseResponse implements ControlledEnt @Param(description = "resource type name. Values include user_vm, public_ip, volume, snapshot, template, project, network, vpc, cpu, memory, primary_storage, secondary_storage.") private String resourceTypeName; - @SerializedName("resourcecount") - @Param(description = "resource count") + @SerializedName(ApiConstants.RESOURCE_COUNT) + @Param(description = "The resource count") private long resourceCount; + @SerializedName(ApiConstants.TAG) + @Param(description = "Tag for the resource", since = "4.20.0") + private String tag; + @Override public void setAccountName(String accountName) { this.accountName = accountName; @@ -92,4 +95,7 @@ public class ResourceCountResponse extends BaseResponse implements ControlledEnt this.projectName = projectName; } + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java index f247be834cb..f9e6df3a038 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitAndCountResponse.java @@ -20,6 +20,8 @@ have limits and resource count **/ package org.apache.cloudstack.api.response; +import java.util.List; + public interface ResourceLimitAndCountResponse { public void setNetworkLimit(String networkLimit); @@ -92,4 +94,6 @@ public interface ResourceLimitAndCountResponse { public void setVmRunning(Integer vmRunning); + public void setTaggedResourceLimitsAndCounts(List taggedResourceLimitsAndCounts); + } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java index 13e1198177d..72c1c66f5e8 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ResourceLimitResponse.java @@ -16,15 +16,14 @@ // under the License. package org.apache.cloudstack.api.response; -import com.cloud.configuration.Resource; -import com.google.gson.annotations.SerializedName; - import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.EntityReference; +import com.cloud.configuration.Resource; import com.cloud.configuration.ResourceLimit; import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; @EntityReference(value = ResourceLimit.class) @SuppressWarnings("unused") @@ -61,6 +60,10 @@ public class ResourceLimitResponse extends BaseResponse implements ControlledEnt @Param(description = "the project name of the resource limit") private String projectName; + @SerializedName(ApiConstants.TAG) + @Param(description = "The tag for the resource limit", since = "4.20.0") + private String tag; + @Override public void setAccountName(String accountName) { this.accountName = accountName; @@ -94,4 +97,8 @@ public class ResourceLimitResponse extends BaseResponse implements ControlledEnt public void setProjectId(String projectId) { this.projectId = projectId; } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java index 53767adf17d..c7740c19214 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ServiceOfferingResponse.java @@ -37,6 +37,10 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations { @Param(description = "the name of the service offering") private String name; + @SerializedName("state") + @Param(description = "state of the service offering") + private String state; + @SerializedName("displaytext") @Param(description = "an alternate display text of the service offering.") private String displayText; @@ -249,6 +253,14 @@ public class ServiceOfferingResponse extends BaseResponseWithAnnotations { this.name = name; } + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } + public Boolean getIsSystem() { return isSystem; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/TaggedResourceLimitAndCountResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/TaggedResourceLimitAndCountResponse.java new file mode 100644 index 00000000000..bfb03b7667c --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/api/response/TaggedResourceLimitAndCountResponse.java @@ -0,0 +1,86 @@ +// 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 org.apache.cloudstack.api.response; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseResponse; + +import com.cloud.configuration.Resource; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class TaggedResourceLimitAndCountResponse extends BaseResponse { + + @SerializedName(ApiConstants.RESOURCE_TYPE) + @Param(description = "Numerical value for the type of the resource. See the ResourceType for more information on these values.") + private Integer resourceType; + + @SerializedName(ApiConstants.RESOURCE_TYPE_NAME) + @Param(description = "Name for the type of the resource") + private String resourceTypeName; + + @SerializedName(ApiConstants.TAG) + @Param(description = "The tag for the resource type") + private String tag; + + @SerializedName(ApiConstants.LIMIT) + @Param(description = "The limit for the resource count for the type and tag for the owner") + private Long limit; + + @SerializedName(ApiConstants.TOTAL) + @Param(description = "The total amount of the resource for the type and tag that is used by the owner") + private Long total; + + @SerializedName(ApiConstants.AVAILABLE) + @Param(description = "The available amount of the resource for the type and tag that is available for the owner") + private Long available; + + + public void setResourceType(Resource.ResourceType resourceType) { + this.resourceType = resourceType.getOrdinal(); + this.resourceTypeName = resourceType.getName(); + } + + public void setTag(String tag) { + this.tag = tag; + } + + public void setLimit(Long limit) { + this.limit = limit; + } + + public void setTotal(Long total) { + this.total = total; + } + + public void setAvailable(Long available) { + this.available = available; + } + + public Long getLimit() { + return limit; + } + + public Long getTotal() { + return total; + } + + public Long getAvailable() { + return available; + } +} diff --git a/api/src/main/java/org/apache/cloudstack/api/response/UserDataResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/UserDataResponse.java index bbe27f84520..e69094c8f80 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/UserDataResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/UserDataResponse.java @@ -24,7 +24,7 @@ import org.apache.cloudstack.api.BaseResponseWithAnnotations; import org.apache.cloudstack.api.EntityReference; @EntityReference(value = UserData.class) -public class UserDataResponse extends BaseResponseWithAnnotations { +public class UserDataResponse extends BaseResponseWithAnnotations implements ControlledEntityResponse { @SerializedName(ApiConstants.ID) @Param(description = "ID of the ssh keypair") @@ -40,6 +40,14 @@ public class UserDataResponse extends BaseResponseWithAnnotations { @SerializedName(ApiConstants.ACCOUNT) @Param(description="the owner of the userdata") private String accountName; + @SerializedName(ApiConstants.PROJECT_ID) + @Param(description = "the project id of the userdata", since = "4.19.1") + private String projectId; + + @SerializedName(ApiConstants.PROJECT) + @Param(description = "the project name of the userdata", since = "4.19.1") + private String projectName; + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain id of the userdata owner") private String domainId; @@ -118,6 +126,16 @@ public class UserDataResponse extends BaseResponseWithAnnotations { this.accountName = accountName; } + @Override + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + @Override + public void setProjectName(String projectName) { + this.projectName = projectName; + } + public String getDomainName() { return domain; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/VlanIpRangeResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/VlanIpRangeResponse.java index a22e2eb7024..aac6dd3c577 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/VlanIpRangeResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/VlanIpRangeResponse.java @@ -123,6 +123,10 @@ public class VlanIpRangeResponse extends BaseResponse implements ControlledEntit @Param(description = "indicates whether VLAN IP range is dedicated to system vms or not") private Boolean forSystemVms; + @SerializedName(ApiConstants.FOR_NSX) + @Param(description = "indicates whether IP range is dedicated to NSX resources or not") + private Boolean forNsx; + public void setId(String id) { this.id = id; } @@ -235,4 +239,8 @@ public class VlanIpRangeResponse extends BaseResponse implements ControlledEntit public void setIp6Cidr(String ip6Cidr) { this.ip6Cidr = ip6Cidr; } + + public void setForNsx(Boolean forNsx) { + this.forNsx = forNsx; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java index 00a1eabc40b..0d502a6d7a7 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/VolumeResponse.java @@ -18,6 +18,7 @@ package org.apache.cloudstack.api.response; import java.util.Date; import java.util.LinkedHashSet; +import java.util.Map; import java.util.Set; import org.apache.cloudstack.acl.RoleType; @@ -288,6 +289,14 @@ public class VolumeResponse extends BaseResponseWithTagInformation implements Co @Param(description = "volume uuid that is given by virtualisation provider (only for VMware)") private String externalUuid; + @SerializedName(ApiConstants.VOLUME_CHECK_RESULT) + @Param(description = "details for the volume check result, they may vary for different hypervisors, since = 4.19.1") + private Map volumeCheckResult; + + @SerializedName(ApiConstants.VOLUME_REPAIR_RESULT) + @Param(description = "details for the volume repair result, they may vary for different hypervisors, since = 4.19.1") + private Map volumeRepairResult; + public String getPath() { return path; } @@ -817,4 +826,20 @@ public class VolumeResponse extends BaseResponseWithTagInformation implements Co public void setExternalUuid(String externalUuid) { this.externalUuid = externalUuid; } + + public Map getVolumeCheckResult() { + return volumeCheckResult; + } + + public void setVolumeCheckResult(Map volumeCheckResult) { + this.volumeCheckResult = volumeCheckResult; + } + + public Map getVolumeRepairResult() { + return volumeRepairResult; + } + + public void setVolumeRepairResult(Map volumeRepairResult) { + this.volumeRepairResult = volumeRepairResult; + } } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java index 6881969646b..ce00827f06d 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/VpcOfferingResponse.java @@ -63,9 +63,17 @@ public class VpcOfferingResponse extends BaseResponse { private Boolean supportsDistributedRouter; @SerializedName((ApiConstants.SUPPORTS_REGION_LEVEL_VPC)) - @Param(description = " indicated if the offering can support region level vpc", since = "4.4") + @Param(description = "indicated if the offering can support region level vpc", since = "4.4") private Boolean supportsRegionLevelVpc; + @SerializedName(ApiConstants.FOR_NSX) + @Param(description = "true if vpc offering can be used by NSX networks only") + private Boolean forNsx; + + @SerializedName(ApiConstants.NSX_MODE) + @Param(description = "Mode in which the network will operate. This parameter is only relevant for NSX offerings") + private String nsxMode; + @SerializedName(ApiConstants.DOMAIN_ID) @Param(description = "the domain ID(s) this disk offering belongs to. Ignore this information as it is not currently applicable.") private String domainId; @@ -138,6 +146,14 @@ public class VpcOfferingResponse extends BaseResponse { this.domain = domain; } + public void setForNsx(Boolean forNsx) { + this.forNsx = forNsx; + } + + public void setNsxMode(String nsxMode) { + this.nsxMode = nsxMode; + } + public String getZoneId() { return zoneId; } diff --git a/api/src/main/java/org/apache/cloudstack/api/response/ZoneResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/ZoneResponse.java index 4e8e665836c..a898cd9d577 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/ZoneResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/ZoneResponse.java @@ -145,6 +145,10 @@ public class ZoneResponse extends BaseResponseWithAnnotations implements SetReso @Param(description = "the type of the zone - core or edge", since = "4.18.0") String type; + @SerializedName(ApiConstants.NSX_ENABLED) + @Param(description = "true, if zone is NSX enabled", since = "4.20.0") + private boolean nsxEnabled = false; + public ZoneResponse() { tags = new LinkedHashSet(); } @@ -368,4 +372,8 @@ public class ZoneResponse extends BaseResponseWithAnnotations implements SetReso public String getType() { return type; } + + public void setNsxEnabled(boolean nsxEnabled) { + this.nsxEnabled = nsxEnabled; + } } diff --git a/api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsAlgorithm.java b/api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsAlgorithm.java index ad5edc9224b..15f7fcd8174 100644 --- a/api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsAlgorithm.java +++ b/api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsAlgorithm.java @@ -33,6 +33,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsMetric; +import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsMetricType; +import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsMetricUseRatio; + public interface ClusterDrsAlgorithm extends Adapter { /** @@ -42,16 +46,17 @@ public interface ClusterDrsAlgorithm extends Adapter { * @param clusterId * the ID of the cluster to check * @param cpuList - * a list of CPU allocated values for each host in the cluster + * a list of Ternary of used, reserved & total CPU for each host in the cluster * @param memoryList - * a list of memory allocated values for each host in the cluster + * a list of Ternary of used, reserved & total memory values for each host in the cluster * * @return true if a DRS operation is needed, false otherwise * * @throws ConfigurationException * if there is an error in the configuration */ - boolean needsDrs(long clusterId, List cpuList, List memoryList) throws ConfigurationException; + boolean needsDrs(long clusterId, List> cpuList, + List> memoryList) throws ConfigurationException; /** @@ -65,18 +70,19 @@ public interface ClusterDrsAlgorithm extends Adapter { * the service offering for the virtual machine * @param destHost * the destination host for the virtual machine - * @param hostCpuUsedMap - * a map of host IDs to the amount of CPU used on each host - * @param hostMemoryUsedMap - * a map of host IDs to the amount of memory used on each host + * @param hostCpuMap + * a map of host IDs to the Ternary of used, reserved and total CPU on each host + * @param hostMemoryMap + * a map of host IDs to the Ternary of used, reserved and total memory on each host * @param requiresStorageMotion * whether storage motion is required for the virtual machine * * @return a ternary containing improvement, cost, benefit */ Ternary getMetrics(long clusterId, VirtualMachine vm, ServiceOffering serviceOffering, - Host destHost, Map hostCpuUsedMap, - Map hostMemoryUsedMap, Boolean requiresStorageMotion); + Host destHost, Map> hostCpuMap, + Map> hostMemoryMap, + Boolean requiresStorageMotion) throws ConfigurationException; /** * Calculates the imbalance of the cluster after a virtual machine migration. @@ -87,54 +93,93 @@ public interface ClusterDrsAlgorithm extends Adapter { * the virtual machine being migrated * @param destHost * the destination host for the virtual machine - * @param hostCpuUsedMap - * a map of host IDs to the amount of CPU used on each host - * @param hostMemoryUsedMap - * a map of host IDs to the amount of memory used on each host + * @param hostCpuMap + * a map of host IDs to the Ternary of used, reserved and total CPU on each host + * @param hostMemoryMap + * a map of host IDs to the Ternary of used, reserved and total memory on each host * * @return a pair containing the CPU and memory imbalance of the cluster after the migration */ - default Pair getImbalancePostMigration(ServiceOffering serviceOffering, VirtualMachine vm, - Host destHost, Map hostCpuUsedMap, - Map hostMemoryUsedMap) { - List postCpuList = new ArrayList<>(); - List postMemoryList = new ArrayList<>(); - final int vmCpu = serviceOffering.getCpu() * serviceOffering.getSpeed(); - final long vmRam = serviceOffering.getRamSize() * 1024L * 1024L; + default Double getImbalancePostMigration(ServiceOffering serviceOffering, VirtualMachine vm, + Host destHost, Map> hostCpuMap, + Map> hostMemoryMap) throws ConfigurationException { + Pair>> pair = getHostMetricsMapAndType(destHost.getClusterId(), serviceOffering, hostCpuMap, hostMemoryMap); + long vmMetric = pair.first(); + Map> hostMetricsMap = pair.second(); - for (Long hostId : hostCpuUsedMap.keySet()) { - long cpu = hostCpuUsedMap.get(hostId); - long memory = hostMemoryUsedMap.get(hostId); - if (hostId == destHost.getId()) { - postCpuList.add(cpu + vmCpu); - postMemoryList.add(memory + vmRam); - } else if (hostId.equals(vm.getHostId())) { - postCpuList.add(cpu - vmCpu); - postMemoryList.add(memory - vmRam); - } else { - postCpuList.add(cpu); - postMemoryList.add(memory); - } + List list = new ArrayList<>(); + for (Long hostId : hostMetricsMap.keySet()) { + list.add(getMetricValuePostMigration(destHost.getClusterId(), hostMetricsMap.get(hostId), vmMetric, hostId, destHost.getId(), vm.getHostId())); } - return new Pair<>(getClusterImbalance(postCpuList), getClusterImbalance(postMemoryList)); + return getImbalance(list); } - /** - * The cluster imbalance is defined as the percentage deviation from the mean - * for a configured metric of the cluster. The standard deviation is used as a - * mathematical tool to normalize the metric data for all the resource and the - * percentage deviation provides an easy tool to compare a cluster’s current - * state against the defined imbalance threshold. Because this is essentially a - * percentage, the value is a number between 0.0 and 1.0. - * Cluster Imbalance, Ic = σc / mavg , where σc is the standard deviation and - * mavg is the mean metric value for the cluster. - */ - default Double getClusterImbalance(List metricList) { + private Pair>> getHostMetricsMapAndType(Long clusterId, + ServiceOffering serviceOffering, Map> hostCpuMap, + Map> hostMemoryMap) throws ConfigurationException { + String metric = getClusterDrsMetric(clusterId); + Pair>> pair; + switch (metric) { + case "cpu": + pair = new Pair<>((long) serviceOffering.getCpu() * serviceOffering.getSpeed(), hostCpuMap); + break; + case "memory": + pair = new Pair<>(serviceOffering.getRamSize() * 1024L * 1024L, hostMemoryMap); + break; + default: + throw new ConfigurationException( + String.format("Invalid metric: %s for cluster: %d", metric, clusterId)); + } + return pair; + } + + private Double getMetricValuePostMigration(Long clusterId, Ternary metrics, long vmMetric, + long hostId, long destHostId, long vmHostId) { + long used = metrics.first(); + long actualTotal = metrics.third() - metrics.second(); + long free = actualTotal - metrics.first(); + + if (hostId == destHostId) { + used += vmMetric; + free -= vmMetric; + } else if (hostId == vmHostId) { + used -= vmMetric; + free += vmMetric; + } + return getMetricValue(clusterId, used, free, actualTotal, null); + } + + private static Double getImbalance(List metricList) { Double clusterMeanMetric = getClusterMeanMetric(metricList); Double clusterStandardDeviation = getClusterStandardDeviation(metricList, clusterMeanMetric); return clusterStandardDeviation / clusterMeanMetric; } + static String getClusterDrsMetric(long clusterId) { + return ClusterDrsMetric.valueIn(clusterId); + } + + static Double getMetricValue(long clusterId, long used, long free, long total, Float skipThreshold) { + boolean useRatio = getDrsMetricUseRatio(clusterId); + switch (getDrsMetricType(clusterId)) { + case "free": + if (skipThreshold != null && free < skipThreshold * total) return null; + if (useRatio) { + return (double) free / total; + } else { + return (double) free; + } + case "used": + if (skipThreshold != null && used > skipThreshold * total) return null; + if (useRatio) { + return (double) used / total; + } else { + return (double) used; + } + } + return null; + } + /** * Mean is the average of a collection or set of metrics. In context of a DRS * cluster, the cluster metrics defined as the average metrics value for some @@ -142,7 +187,7 @@ public interface ClusterDrsAlgorithm extends Adapter { * Cluster Mean Metric, mavg = (∑mi) / N, where mi is a measurable metric for a * resource ‘i’ in a cluster with total N number of resources. */ - default Double getClusterMeanMetric(List metricList) { + static Double getClusterMeanMetric(List metricList) { return new Mean().evaluate(metricList.stream().mapToDouble(i -> i).toArray()); } @@ -157,11 +202,62 @@ public interface ClusterDrsAlgorithm extends Adapter { * mean metric value and mi is a measurable metric for some resource ‘i’ in the * cluster with total N number of resources. */ - default Double getClusterStandardDeviation(List metricList, Double mean) { + static Double getClusterStandardDeviation(List metricList, Double mean) { if (mean != null) { return new StandardDeviation(false).evaluate(metricList.stream().mapToDouble(i -> i).toArray(), mean); } else { return new StandardDeviation(false).evaluate(metricList.stream().mapToDouble(i -> i).toArray()); } } + + static boolean getDrsMetricUseRatio(long clusterId) { + return ClusterDrsMetricUseRatio.valueIn(clusterId); + } + + static String getDrsMetricType(long clusterId) { + return ClusterDrsMetricType.valueIn(clusterId); + } + + /** + * The cluster imbalance is defined as the percentage deviation from the mean + * for a configured metric of the cluster. The standard deviation is used as a + * mathematical tool to normalize the metric data for all the resource and the + * percentage deviation provides an easy tool to compare a cluster’s current + * state against the defined imbalance threshold. Because this is essentially a + * percentage, the value is a number between 0.0 and 1.0. + * Cluster Imbalance, Ic = σc / mavg , where σc is the standard deviation and + * mavg is the mean metric value for the cluster. + */ + static Double getClusterImbalance(Long clusterId, List> cpuList, + List> memoryList, Float skipThreshold) throws ConfigurationException { + String metric = getClusterDrsMetric(clusterId); + List list; + switch (metric) { + case "cpu": + list = getMetricList(clusterId, cpuList, skipThreshold); + break; + case "memory": + list = getMetricList(clusterId, memoryList, skipThreshold); + break; + default: + throw new ConfigurationException( + String.format("Invalid metric: %s for cluster: %d", metric, clusterId)); + } + return getImbalance(list); + } + + static List getMetricList(Long clusterId, List> hostMetricsList, + Float skipThreshold) { + List list = new ArrayList<>(); + for (Ternary ternary : hostMetricsList) { + long used = ternary.first(); + long actualTotal = ternary.third() - ternary.second(); + long free = actualTotal - ternary.first(); + Double metricValue = getMetricValue(clusterId, used, free, actualTotal, skipThreshold); + if (metricValue != null) { + list.add(metricValue); + } + } + return list; + } } diff --git a/api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsService.java b/api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsService.java index 91be8c535a4..ba6a6464fc2 100644 --- a/api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsService.java +++ b/api/src/main/java/org/apache/cloudstack/cluster/ClusterDrsService.java @@ -66,6 +66,29 @@ public interface ClusterDrsService extends Manager, Configurable, Scheduler { true, ConfigKey.Scope.Cluster, null, "DRS metric", null, null, null, ConfigKey.Kind.Select, "memory,cpu"); + ConfigKey ClusterDrsMetricType = new ConfigKey<>(String.class, "drs.metric.type", ConfigKey.CATEGORY_ADVANCED, + "used", + "The metric type used to measure imbalance in a cluster. This can completely change the imbalance value. Possible values are free, used.", + true, ConfigKey.Scope.Cluster, null, "DRS metric type", null, null, null, ConfigKey.Kind.Select, + "free,used"); + + ConfigKey ClusterDrsMetricUseRatio = new ConfigKey<>(Boolean.class, "drs.metric.use.ratio", ConfigKey.CATEGORY_ADVANCED, + "true", + "Whether to use ratio of selected metric & total. Useful when the cluster has hosts with different capacities", + true, ConfigKey.Scope.Cluster, null, "DRS metric use ratio", null, null, null, ConfigKey.Kind.Select, + "true,false"); + + ConfigKey ClusterDrsImbalanceSkipThreshold = new ConfigKey<>(Float.class, + "drs.imbalance.condensed.skip.threshold", ConfigKey.CATEGORY_ADVANCED, "0.95", + "Threshold to ignore the metric for a host while calculating the imbalance to decide " + + "whether DRS is required for a cluster.This is to avoid cases when the calculated imbalance" + + " gets skewed due to a single host having a very high/low metric value resulting in imbalance" + + " being higher than 1. If " + ClusterDrsMetricType.key() + " is 'free', set a lower value and if it is 'used' " + + "set a higher value. The value should be between 0.0 and 1.0", + true, ConfigKey.Scope.Cluster, null, "DRS imbalance skip threshold for Condensed algorithm", + null, null, null); + + /** * Generate a DRS plan for a cluster and save it as per the parameters * diff --git a/api/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManager.java b/api/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManager.java index f19b5398dd9..5bd9699b201 100644 --- a/api/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManager.java +++ b/api/src/main/java/org/apache/cloudstack/consoleproxy/ConsoleAccessManager.java @@ -20,6 +20,7 @@ import com.cloud.utils.component.Manager; import org.apache.cloudstack.api.command.user.consoleproxy.ConsoleEndpoint; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; +import java.util.Date; public interface ConsoleAccessManager extends Manager, Configurable { @@ -44,4 +45,7 @@ public interface ConsoleAccessManager extends Manager, Configurable { void removeSessions(String[] sessionUuids); void acquireSession(String sessionUuid); + + String genAccessTicket(String host, String port, String sid, String tag, String sessionUuid); + String genAccessTicket(String host, String port, String sid, String tag, Date normalizedHashTime, String sessionUuid); } diff --git a/api/src/main/java/org/apache/cloudstack/context/CallContext.java b/api/src/main/java/org/apache/cloudstack/context/CallContext.java index ecc109977eb..69376e4f6d7 100644 --- a/api/src/main/java/org/apache/cloudstack/context/CallContext.java +++ b/api/src/main/java/org/apache/cloudstack/context/CallContext.java @@ -23,8 +23,8 @@ import java.util.UUID; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal; -import org.apache.log4j.Logger; -import org.apache.log4j.NDC; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.exception.CloudAuthenticationException; import com.cloud.projects.Project; @@ -33,6 +33,7 @@ import com.cloud.user.User; import com.cloud.utils.UuidUtils; import com.cloud.utils.db.EntityManager; import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.logging.log4j.ThreadContext; /** * CallContext records information about the environment the call is made. This @@ -40,7 +41,7 @@ import com.cloud.utils.exception.CloudRuntimeException; * entry point must set the context and remove it when the thread finishes. */ public class CallContext { - private static final Logger s_logger = Logger.getLogger(CallContext.class); + protected static Logger LOGGER = LogManager.getLogger(CallContext.class); private static ManagedThreadLocal s_currentContext = new ManagedThreadLocal(); private static ManagedThreadLocal> s_currentContextStack = new ManagedThreadLocal>() { @Override @@ -178,9 +179,9 @@ public class CallContext { callingContext = new CallContext(userId, accountId, contextId); } s_currentContext.set(callingContext); - NDC.push("ctx-" + UuidUtils.first(contextId)); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Registered: " + callingContext); + ThreadContext.push("ctx-" + UuidUtils.first(contextId)); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Registered: " + callingContext); } s_currentContextStack.get().push(callingContext); @@ -209,7 +210,7 @@ public class CallContext { assert context.getCallingUserId() == User.UID_SYSTEM : "You are calling a very specific method that registers a one time system context. This method is meant for background threads that does processing."; return context; } catch (Exception e) { - s_logger.error("Failed to register the system call context.", e); + LOGGER.error("Failed to register the system call context.", e); throw new CloudRuntimeException("Failed to register system call context", e); } } @@ -278,18 +279,18 @@ public class CallContext { return null; } s_currentContext.remove(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Unregistered: " + context); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Unregistered: " + context); } String contextId = context.getContextId(); String sessionIdOnStack = null; String sessionIdPushedToNDC = "ctx-" + UuidUtils.first(contextId); - while ((sessionIdOnStack = NDC.pop()) != null) { + while ((sessionIdOnStack = ThreadContext.pop()) != null) { if (sessionIdOnStack.isEmpty() || sessionIdPushedToNDC.equals(sessionIdOnStack)) { break; } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Popping from NDC: " + contextId); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Popping from NDC: " + contextId); } } diff --git a/api/src/main/java/org/apache/cloudstack/context/LogContext.java b/api/src/main/java/org/apache/cloudstack/context/LogContext.java index c81d0f499cb..c367975aba3 100644 --- a/api/src/main/java/org/apache/cloudstack/context/LogContext.java +++ b/api/src/main/java/org/apache/cloudstack/context/LogContext.java @@ -20,8 +20,8 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import org.apache.log4j.Logger; -import org.apache.log4j.MDC; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal; @@ -31,13 +31,14 @@ import com.cloud.user.User; import com.cloud.utils.UuidUtils; import com.cloud.utils.db.EntityManager; import com.cloud.utils.exception.CloudRuntimeException; +import org.apache.logging.log4j.ThreadContext; /** * LogContext records information about the environment the API call is made. This * class must be always be available in all CloudStack code. */ public class LogContext { - private static final Logger s_logger = Logger.getLogger(LogContext.class); + protected static Logger LOGGER = LogManager.getLogger(LogContext.class); private static ManagedThreadLocal s_currentContext = new ManagedThreadLocal(); private String logContextId; @@ -134,9 +135,9 @@ public class LogContext { callingContext = new LogContext(userId, accountId, contextId); } s_currentContext.set(callingContext); - MDC.put("logcontextid", UuidUtils.first(contextId)); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Registered for log: " + callingContext); + ThreadContext.put("logcontextid", UuidUtils.first(contextId)); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Registered for log: " + callingContext); } return callingContext; } @@ -160,7 +161,7 @@ public class LogContext { assert context.getCallingUserId() == User.UID_SYSTEM : "You are calling a very specific method that registers a one time system context. This method is meant for background threads that does processing."; return context; } catch (Exception e) { - s_logger.error("Failed to register the system log context.", e); + LOGGER.error("Failed to register the system log context.", e); throw new CloudRuntimeException("Failed to register system log context", e); } } @@ -206,11 +207,11 @@ public class LogContext { LogContext context = s_currentContext.get(); if (context != null) { s_currentContext.remove(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Unregistered: " + context); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Unregistered: " + context); } } - MDC.clear(); + ThreadContext.clearMap(); } public void setStartEventId(long startEventId) { diff --git a/api/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java b/api/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java index 76706a4cfc9..1fff54f5f8f 100644 --- a/api/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java +++ b/api/src/main/java/org/apache/cloudstack/network/element/InternalLoadBalancerElementService.java @@ -52,4 +52,6 @@ public interface InternalLoadBalancerElementService extends PluggableService { * @return */ List searchForInternalLoadBalancerElements(Long id, Long ntwkSvsProviderId, Boolean enabled); + + VirtualRouterProvider.Type getProviderType(); } diff --git a/api/src/main/java/org/apache/cloudstack/quota/QuotaTariff.java b/api/src/main/java/org/apache/cloudstack/quota/QuotaTariff.java new file mode 100644 index 00000000000..7de66a168f9 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/quota/QuotaTariff.java @@ -0,0 +1,25 @@ +// 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 +// 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 org.apache.cloudstack.quota; + +import org.apache.cloudstack.api.Identity; +import org.apache.cloudstack.api.InternalIdentity; + +public interface QuotaTariff extends InternalIdentity, Identity { + +} diff --git a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java b/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java index 170193570cf..fb4fe121cc7 100644 --- a/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java +++ b/api/src/main/java/org/apache/cloudstack/user/ResourceReservation.java @@ -18,9 +18,10 @@ // package org.apache.cloudstack.user; -import com.cloud.configuration.Resource; import org.apache.cloudstack.api.InternalIdentity; +import com.cloud.configuration.Resource; + /** * an interface defining an {code}AutoClosable{code} reservation object */ @@ -33,5 +34,9 @@ ResourceReservation extends InternalIdentity { Resource.ResourceType getResourceType(); + Long getResourceId(); + + String getTag(); + Long getReservedAmount(); } diff --git a/api/src/test/java/com/cloud/storage/StorageTest.java b/api/src/test/java/com/cloud/storage/StorageTest.java index 951ee9fe76a..2bcc28e2b4b 100644 --- a/api/src/test/java/com/cloud/storage/StorageTest.java +++ b/api/src/test/java/com/cloud/storage/StorageTest.java @@ -52,7 +52,7 @@ public class StorageTest { } @Test - public void supportsOverprovisioningStoragePool() { + public void supportsOverProvisioningTestAllStoragePoolTypes() { Assert.assertTrue(StoragePoolType.Filesystem.supportsOverProvisioning()); Assert.assertTrue(StoragePoolType.NetworkFilesystem.supportsOverProvisioning()); Assert.assertFalse(StoragePoolType.IscsiLUN.supportsOverProvisioning()); @@ -63,7 +63,7 @@ public class StorageTest { Assert.assertFalse(StoragePoolType.CLVM.supportsOverProvisioning()); Assert.assertTrue(StoragePoolType.RBD.supportsOverProvisioning()); Assert.assertTrue(StoragePoolType.PowerFlex.supportsOverProvisioning()); - Assert.assertFalse(StoragePoolType.SharedMountPoint.supportsOverProvisioning()); + Assert.assertTrue(StoragePoolType.SharedMountPoint.supportsOverProvisioning()); Assert.assertTrue(StoragePoolType.VMFS.supportsOverProvisioning()); Assert.assertTrue(StoragePoolType.PreSetup.supportsOverProvisioning()); Assert.assertTrue(StoragePoolType.EXT.supportsOverProvisioning()); @@ -74,4 +74,13 @@ public class StorageTest { Assert.assertTrue(StoragePoolType.DatastoreCluster.supportsOverProvisioning()); Assert.assertTrue(StoragePoolType.Linstor.supportsOverProvisioning()); } + + @Test + public void equalityTest() { + StoragePoolType t1 = StoragePoolType.NetworkFilesystem; + StoragePoolType t2 = StoragePoolType.NetworkFilesystem; + Assert.assertTrue(t1 == StoragePoolType.NetworkFilesystem); + Assert.assertTrue(t1.equals(StoragePoolType.NetworkFilesystem)); + Assert.assertFalse(t1.equals(StoragePoolType.EXT)); + } } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmdTest.java index d26065da21c..365646de7a3 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/account/CreateAccountCmdTest.java @@ -22,7 +22,8 @@ import org.apache.cloudstack.acl.RoleService; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -38,7 +39,7 @@ import com.cloud.user.AccountService; import com.cloud.user.User; public class CreateAccountCmdTest { - public static final Logger s_logger = Logger.getLogger(CreateAccountCmdTest.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); @Mock private AccountService accountService; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdTest.java new file mode 100644 index 00000000000..3c9d4cb67ae --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/domain/ListDomainsCmdTest.java @@ -0,0 +1,77 @@ +// 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 org.apache.cloudstack.api.command.admin.domain; + +import java.util.List; + +import org.apache.cloudstack.api.response.DomainResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.ResourceLimitService; + +@RunWith(MockitoJUnitRunner.class) +public class ListDomainsCmdTest { + + @Mock + ResourceLimitService resourceLimitService; + + + @Test + public void testGetShowIcon() { + ListDomainsCmd cmd = new ListDomainsCmd(); + ReflectionTestUtils.setField(cmd, "showIcon", null); + Assert.assertFalse(cmd.getShowIcon()); + ReflectionTestUtils.setField(cmd, "showIcon", false); + Assert.assertFalse(cmd.getShowIcon()); + ReflectionTestUtils.setField(cmd, "showIcon", true); + Assert.assertTrue(cmd.getShowIcon()); + } + + @Test + public void testGetTag() { + ListDomainsCmd cmd = new ListDomainsCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } + + @Test + public void testUpdateDomainResponseNoDomains() { + ListDomainsCmd cmd = new ListDomainsCmd(); + cmd._resourceLimitService = resourceLimitService; + cmd.updateDomainResponse(null); + Mockito.verify(resourceLimitService, Mockito.never()).updateTaggedResourceLimitsAndCountsForDomains(Mockito.anyList(), Mockito.anyString()); + } + + @Test + public void testUpdateDomainResponseWithDomains() { + ListDomainsCmd cmd = new ListDomainsCmd(); + cmd._resourceLimitService = resourceLimitService; + ReflectionTestUtils.setField(cmd, "tag", "abc"); + cmd.updateDomainResponse(List.of(Mockito.mock(DomainResponse.class))); + Mockito.verify(resourceLimitService, Mockito.times(1)).updateTaggedResourceLimitsAndCountsForDomains(Mockito.any(), Mockito.any()); + } + +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java index 8b95456a84c..ef10ebff467 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateNetworkOfferingCmdTest.java @@ -23,14 +23,16 @@ import org.junit.Test; import org.mockito.InjectMocks; import org.springframework.test.util.ReflectionTestUtils; + public class CreateNetworkOfferingCmdTest { @InjectMocks private CreateNetworkOfferingCmd createNetworkOfferingCmd = new CreateNetworkOfferingCmd(); + String netName = "network"; + @Test public void createVpcNtwkOffWithEmptyDisplayText() { - String netName = "network"; ReflectionTestUtils.setField(createNetworkOfferingCmd, "networkOfferingName", netName); Assert.assertEquals(createNetworkOfferingCmd.getDisplayText(), netName); } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java index 717b5c3262d..f69e8cea4f3 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmdTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmdTest.java new file mode 100644 index 00000000000..fc0e6face52 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/resource/ListCapacityCmdTest.java @@ -0,0 +1,34 @@ +// 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 org.apache.cloudstack.api.command.admin.resource; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.test.util.ReflectionTestUtils; + +public class ListCapacityCmdTest { + + @Test + public void testGetTag() { + ListCapacityCmd cmd = new ListCapacityCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java index f64df167e25..a69a7a858ce 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/AddObjectStoragePoolCmdTest.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.ResponseGenerator; import org.apache.cloudstack.api.response.ObjectStoreResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.storage.object.ObjectStore; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -39,11 +38,10 @@ import org.springframework.test.util.ReflectionTestUtils; import java.util.HashMap; import java.util.Map; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; @RunWith(MockitoJUnitRunner.class) public class AddObjectStoragePoolCmdTest { - public static final Logger s_logger = Logger.getLogger(AddObjectStoragePoolCmdTest.class.getName()); @Mock StorageService storageService; @@ -65,9 +63,11 @@ public class AddObjectStoragePoolCmdTest { Map details; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); details = new HashMap<>(); addObjectStoragePoolCmdSpy = Mockito.spy(new AddObjectStoragePoolCmd()); ReflectionTestUtils.setField(addObjectStoragePoolCmdSpy, "name", name); @@ -81,14 +81,15 @@ public class AddObjectStoragePoolCmdTest { @After public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test public void testAddObjectStore() throws DiscoveryException { Mockito.doReturn(objectStore).when(storageService).discoverObjectStore(Mockito.anyString(), - Mockito.anyString(), Mockito.anyString(), anyObject()); + Mockito.anyString(), Mockito.anyString(), any()); ObjectStoreResponse objectStoreResponse = new ObjectStoreResponse(); - Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(anyObject()); + Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(any()); addObjectStoragePoolCmdSpy.execute(); Mockito.verify(storageService, Mockito.times(1)) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java index 35be56d0c75..dc5b9f5fa32 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/DeleteObjectStoragePoolCmdTest.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.api.command.admin.storage; import com.cloud.storage.StorageService; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -30,16 +29,17 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; public class DeleteObjectStoragePoolCmdTest { - public static final Logger s_logger = Logger.getLogger(DeleteObjectStoragePoolCmdTest.class.getName()); @Mock private StorageService storageService; @Spy DeleteObjectStoragePoolCmd deleteObjectStoragePoolCmd; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); deleteObjectStoragePoolCmd = Mockito.spy(new DeleteObjectStoragePoolCmd()); deleteObjectStoragePoolCmd._storageService = storageService; } @@ -47,6 +47,7 @@ public class DeleteObjectStoragePoolCmdTest { @After public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java index 5244ff1ef9a..fbf4d2c495d 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/FindStoragePoolsForMigrationCmdTest.java @@ -23,7 +23,7 @@ import org.apache.cloudstack.api.response.StoragePoolResponse; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class FindStoragePoolsForMigrationCmdTest { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java index ef66c2a1a64..307d80aa3f8 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/storage/UpdateObjectStoragePoolCmdTest.java @@ -23,7 +23,6 @@ import org.apache.cloudstack.api.ResponseGenerator; import org.apache.cloudstack.api.response.ObjectStoreResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.storage.object.ObjectStore; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -33,10 +32,9 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.springframework.test.util.ReflectionTestUtils; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; public class UpdateObjectStoragePoolCmdTest { - public static final Logger s_logger = Logger.getLogger(UpdateObjectStoragePoolCmdTest.class.getName()); @Mock private StorageService storageService; @@ -56,9 +54,11 @@ public class UpdateObjectStoragePoolCmdTest { private String provider = "Simulator"; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); updateObjectStoragePoolCmd = Mockito.spy(new UpdateObjectStoragePoolCmd()); updateObjectStoragePoolCmd._storageService = storageService; updateObjectStoragePoolCmd._responseGenerator = responseGenerator; @@ -70,13 +70,14 @@ public class UpdateObjectStoragePoolCmdTest { @After public void tearDown() throws Exception { CallContext.unregister(); + closeable.close(); } @Test public void testUpdateObjectStore() { Mockito.doReturn(objectStore).when(storageService).updateObjectStore(1L, updateObjectStoragePoolCmd); ObjectStoreResponse objectStoreResponse = new ObjectStoreResponse(); - Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(anyObject()); + Mockito.doReturn(objectStoreResponse).when(responseGenerator).createObjectStoreResponse(any()); updateObjectStoragePoolCmd.execute(); Mockito.verify(storageService, Mockito.times(1)) .updateObjectStore(1L, updateObjectStoragePoolCmd); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmdTest.java index bc1e1854aa7..8a57ac3eb22 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/user/CreateUserCmdTest.java @@ -22,7 +22,8 @@ package org.apache.cloudstack.api.command.admin.user; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -38,7 +39,7 @@ import com.cloud.user.AccountService; import com.cloud.user.User; public class CreateUserCmdTest { - public static final Logger s_logger = Logger.getLogger(CreateUserCmdTest.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); @Mock private AccountService accountService; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java index 16b716d7d63..290a2850c9a 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/admin/vpc/CreateVPCOfferingCmdTest.java @@ -52,15 +52,15 @@ public class CreateVPCOfferingCmdTest { IllegalAccessException { CreateVPCOfferingCmd cmd = new CreateVPCOfferingCmd(); ApiCmdTestUtil.set(cmd, ApiConstants.SERVICE_PROVIDER_LIST, new HashMap>()); - Assert.assertNull(cmd.getServiceProviders()); + Assert.assertTrue(cmd.getServiceProviders().isEmpty()); } @Test - public void getDetailsNull() throws IllegalArgumentException, + public void getDetailsEmpty() throws IllegalArgumentException, IllegalAccessException { CreateVPCOfferingCmd cmd = new CreateVPCOfferingCmd(); ApiCmdTestUtil.set(cmd, ApiConstants.SERVICE_PROVIDER_LIST, null); - Assert.assertNull(cmd.getServiceProviders()); + Assert.assertTrue(cmd.getServiceProviders().isEmpty()); } @Test diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java index 1e4bb326f7e..2c43278a582 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/ActivateProjectCmdTest.java @@ -23,7 +23,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.command.user.project.ActivateProjectCmd; @@ -57,7 +57,7 @@ public class ActivateProjectCmdTest extends TestCase { @Test public void testGetEntityOwnerIdForNullProject() { ProjectService projectService = Mockito.mock(ProjectService.class); - Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(null); + Mockito.when(projectService.getProject(ArgumentMatchers.anyLong())).thenReturn(null); activateProjectCmd._projectService = projectService; try { @@ -74,9 +74,9 @@ public class ActivateProjectCmdTest extends TestCase { ProjectService projectService = Mockito.mock(ProjectService.class); Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(2L); - Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(project); + Mockito.when(projectService.getProject(ArgumentMatchers.anyLong())).thenReturn(project); - Mockito.when(projectService.getProjectOwner(Matchers.anyLong())).thenReturn(account); + Mockito.when(projectService.getProjectOwner(ArgumentMatchers.anyLong())).thenReturn(account); activateProjectCmd._projectService = projectService; Assert.assertEquals(2L, activateProjectCmd.getEntityOwnerId()); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java index 199ee00551d..f100822b8c7 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddAccountToProjectCmdTest.java @@ -23,7 +23,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.command.user.account.AddAccountToProjectCmd; @@ -101,9 +101,9 @@ public class AddAccountToProjectCmdTest extends TestCase { Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(2L); - Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(project); + Mockito.when(projectService.getProject(ArgumentMatchers.anyLong())).thenReturn(project); - Mockito.when(projectService.getProjectOwner(Matchers.anyLong())).thenReturn(account); + Mockito.when(projectService.getProjectOwner(ArgumentMatchers.anyLong())).thenReturn(account); addAccountToProjectCmd._projectService = projectService; Assert.assertEquals(2L, addAccountToProjectCmd.getEntityOwnerId()); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java index d0cc8be716a..9ea3a6446e8 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddIpToVmNicTest.java @@ -21,7 +21,7 @@ import junit.framework.TestCase; import org.junit.Before; import org.junit.Test; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.ResponseGenerator; import org.apache.cloudstack.api.command.user.vm.AddIpToVmNicCmd; @@ -59,7 +59,7 @@ public class AddIpToVmNicTest extends TestCase { NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class); Mockito.when( - networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.any())) + networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any())) .thenReturn(secIp); ipTonicCmd._networkService = networkService; @@ -79,7 +79,7 @@ public class AddIpToVmNicTest extends TestCase { AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class); Mockito.when( - networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.any())) + networkService.allocateSecondaryGuestIP(ArgumentMatchers.anyLong(), ArgumentMatchers.any())) .thenReturn(null); ipTonicCmd._networkService = networkService; @@ -98,7 +98,7 @@ public class AddIpToVmNicTest extends TestCase { NetworkService networkService = Mockito.mock(NetworkService.class); RemoveIpFromVmNicCmd removeIpFromNic = Mockito.mock(RemoveIpFromVmNicCmd.class); - Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(true); + Mockito.when(networkService.releaseSecondaryIpFromNic(ArgumentMatchers.anyInt())).thenReturn(true); removeIpFromNic._networkService = networkService; removeIpFromNic.execute(); @@ -109,7 +109,7 @@ public class AddIpToVmNicTest extends TestCase { NetworkService networkService = Mockito.mock(NetworkService.class); RemoveIpFromVmNicCmd removeIpFromNic = Mockito.mock(RemoveIpFromVmNicCmd.class); - Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(false); + Mockito.when(networkService.releaseSecondaryIpFromNic(ArgumentMatchers.anyInt())).thenReturn(false); removeIpFromNic._networkService = networkService; successResponseGenerator = Mockito.mock(SuccessResponse.class); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java index 8760fc87556..a62c29e487a 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddNetworkServiceProviderCmdTest.java @@ -26,7 +26,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.apache.cloudstack.api.ServerApiException; @@ -86,7 +86,7 @@ public class AddNetworkServiceProviderCmdTest extends TestCase { addNetworkServiceProviderCmd._networkService = networkService; PhysicalNetworkServiceProvider physicalNetworkServiceProvider = Mockito.mock(PhysicalNetworkServiceProvider.class); - Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn( + Mockito.when(networkService.addProviderToPhysicalNetwork(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyList())).thenReturn( physicalNetworkServiceProvider); try { @@ -103,7 +103,7 @@ public class AddNetworkServiceProviderCmdTest extends TestCase { NetworkService networkService = Mockito.mock(NetworkService.class); addNetworkServiceProviderCmd._networkService = networkService; - Mockito.when(networkService.addProviderToPhysicalNetwork(Matchers.anyLong(), Matchers.anyString(), Matchers.anyLong(), Matchers.anyList())).thenReturn(null); + Mockito.when(networkService.addProviderToPhysicalNetwork(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyLong(), ArgumentMatchers.anyList())).thenReturn(null); try { addNetworkServiceProviderCmd.create(); diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java index 46fd6905683..86a53787e08 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/AddSecondaryStorageCmdTest.java @@ -18,7 +18,7 @@ package org.apache.cloudstack.api.command.test; import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.isNull; @@ -86,7 +86,7 @@ public class AddSecondaryStorageCmdTest extends TestCase { StorageService resourceService = Mockito.mock(StorageService.class); addImageStoreCmd._storageService = resourceService; - Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map)anyObject())) + Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map)any())) .thenReturn(null); try { diff --git a/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java index c5288067e94..34baebe5257 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/test/CreateSnapshotCmdTest.java @@ -17,10 +17,10 @@ package org.apache.cloudstack.api.command.test; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.isNull; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; import java.util.HashMap; import java.util.List; @@ -126,7 +126,7 @@ public class CreateSnapshotCmdTest extends TestCase { try { Mockito.when(volumeApiService.takeSnapshot(nullable(Long.class), nullable(Long.class), nullable(Long.class), - nullable(Account.class), nullable(Boolean.class), nullable(Snapshot.LocationType.class), nullable(Boolean.class), anyObject(), Mockito.anyList())).thenReturn(null); + nullable(Account.class), nullable(Boolean.class), nullable(Snapshot.LocationType.class), nullable(Boolean.class), any(), Mockito.anyList())).thenReturn(null); } catch (Exception e) { Assert.fail("Received exception when success expected " + e.getMessage()); } diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmdTest.java new file mode 100644 index 00000000000..896a7a6c826 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/account/ListAccountsCmdTest.java @@ -0,0 +1,76 @@ +// 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 org.apache.cloudstack.api.command.user.account; + +import java.util.List; + +import org.apache.cloudstack.api.response.AccountResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.user.ResourceLimitService; + +@RunWith(MockitoJUnitRunner.class) +public class ListAccountsCmdTest { + + @Mock + ResourceLimitService resourceLimitService; + + + @Test + public void testGetShowIcon() { + ListAccountsCmd cmd = new ListAccountsCmd(); + ReflectionTestUtils.setField(cmd, "showIcon", null); + Assert.assertFalse(cmd.getShowIcon()); + ReflectionTestUtils.setField(cmd, "showIcon", false); + Assert.assertFalse(cmd.getShowIcon()); + ReflectionTestUtils.setField(cmd, "showIcon", true); + Assert.assertTrue(cmd.getShowIcon()); + } + + @Test + public void testGetTag() { + ListAccountsCmd cmd = new ListAccountsCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } + + @Test + public void testUpdateDomainResponseNoDomains() { + ListAccountsCmd cmd = new ListAccountsCmd(); + cmd._resourceLimitService = resourceLimitService; + cmd.updateAccountResponse(null); + Mockito.verify(resourceLimitService, Mockito.never()).updateTaggedResourceLimitsAndCountsForAccounts(Mockito.anyList(), Mockito.anyString()); + } + + @Test + public void testUpdateDomainResponseWithDomains() { + ListAccountsCmd cmd = new ListAccountsCmd(); + cmd._resourceLimitService = resourceLimitService; + ReflectionTestUtils.setField(cmd, "tag", "abc"); + cmd.updateAccountResponse(List.of(Mockito.mock(AccountResponse.class))); + Mockito.verify(resourceLimitService, Mockito.times(1)).updateTaggedResourceLimitsAndCountsForAccounts(Mockito.any(), Mockito.any()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java index 55a41c61ce6..76836caef28 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmdTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmdTest.java new file mode 100644 index 00000000000..7c29de69ade --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/network/ListNetworkProtocolsCmdTest.java @@ -0,0 +1,95 @@ +// 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 org.apache.cloudstack.api.command.user.network; + +import com.cloud.utils.net.NetworkProtocols; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.NetworkProtocolResponse; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ListNetworkProtocolsCmdTest { + + @Test + public void testListNetworkProtocolNumbers() { + ListNetworkProtocolsCmd cmd = new ListNetworkProtocolsCmd(); + String option = NetworkProtocols.Option.ProtocolNumber.toString(); + ReflectionTestUtils.setField(cmd, "option", option); + Assert.assertEquals(cmd.getOption(), option); + + try { + cmd.execute(); + } catch (Exception e) { + e.printStackTrace(); + } + Object response = cmd.getResponseObject(); + Assert.assertTrue(response instanceof ListResponse); + ListResponse listResponse = (ListResponse) response; + Assert.assertEquals(BaseCmd.getResponseNameByClass(cmd.getClass()), listResponse.getResponseName()); + Assert.assertNotNull(listResponse.getResponses()); + Assert.assertNotEquals(0, listResponse.getResponses().size()); + Object firstResponse = listResponse.getResponses().get(0); + Assert.assertTrue(firstResponse instanceof NetworkProtocolResponse); + Assert.assertEquals("networkprotocol", ((NetworkProtocolResponse) firstResponse).getObjectName()); + Assert.assertEquals(Integer.valueOf(0), ((NetworkProtocolResponse) firstResponse).getIndex()); + Assert.assertEquals("HOPOPT", ((NetworkProtocolResponse) firstResponse).getName()); + } + + @Test + public void testListIcmpTypes() { + ListNetworkProtocolsCmd cmd = new ListNetworkProtocolsCmd(); + String option = NetworkProtocols.Option.IcmpType.toString(); + ReflectionTestUtils.setField(cmd, "option", option); + Assert.assertEquals(cmd.getOption(), option); + + try { + cmd.execute(); + } catch (Exception e) { + e.printStackTrace(); + } + Object response = cmd.getResponseObject(); + Assert.assertTrue(response instanceof ListResponse); + ListResponse listResponse = (ListResponse) response; + Assert.assertEquals(BaseCmd.getResponseNameByClass(cmd.getClass()), listResponse.getResponseName()); + Assert.assertNotNull(listResponse.getResponses()); + Assert.assertNotEquals(0, listResponse.getResponses().size()); + Object firstResponse = listResponse.getResponses().get(0); + Assert.assertTrue(firstResponse instanceof NetworkProtocolResponse); + Assert.assertEquals("networkprotocol", ((NetworkProtocolResponse) firstResponse).getObjectName()); + Assert.assertEquals(Integer.valueOf(0), ((NetworkProtocolResponse) firstResponse).getIndex()); + Assert.assertNotNull(((NetworkProtocolResponse) firstResponse).getDetails()); + System.out.println(((NetworkProtocolResponse) firstResponse).getDetails()); + Assert.assertEquals("Echo reply", ((NetworkProtocolResponse) firstResponse).getDetails().get("0")); + } + + @Test(expected = IllegalArgumentException.class) + public void testListInvalidOption() { + ListNetworkProtocolsCmd cmd = new ListNetworkProtocolsCmd(); + String option = "invalid-option"; + ReflectionTestUtils.setField(cmd, "option", option); + Assert.assertEquals(cmd.getOption(), option); + + cmd.execute(); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmdTest.java new file mode 100644 index 00000000000..598fdd8ac4f --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListDiskOfferingsCmdTest.java @@ -0,0 +1,37 @@ +// 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 org.apache.cloudstack.api.command.user.offering; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ListDiskOfferingsCmdTest { + + @Test + public void testGetVirtualMachineId() { + ListDiskOfferingsCmd cmd = new ListDiskOfferingsCmd(); + ReflectionTestUtils.setField(cmd, "virtualMachineId", null); + Assert.assertNull(cmd.getVirtualMachineId()); + Long id = 100L; + ReflectionTestUtils.setField(cmd, "virtualMachineId", id); + Assert.assertEquals(id, cmd.getVirtualMachineId()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmdTest.java new file mode 100644 index 00000000000..f408132e5fc --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmdTest.java @@ -0,0 +1,38 @@ +// 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 org.apache.cloudstack.api.command.user.offering; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + + +@RunWith(MockitoJUnitRunner.class) +public class ListServiceOfferingsCmdTest { + + @Test + public void testGetTemplateId() { + ListServiceOfferingsCmd cmd = new ListServiceOfferingsCmd(); + ReflectionTestUtils.setField(cmd, "templateId", null); + Assert.assertNull(cmd.getTemplateId()); + Long id = 100L; + ReflectionTestUtils.setField(cmd, "templateId", id); + Assert.assertEquals(id, cmd.getTemplateId()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java index ee3193123e0..dc1f2ca5189 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/project/CreateProjectCmdTest.java @@ -21,7 +21,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmdTest.java new file mode 100644 index 00000000000..3e999be2cfd --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/ListResourceLimitsCmdTest.java @@ -0,0 +1,37 @@ +// 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 org.apache.cloudstack.api.command.user.resource; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class ListResourceLimitsCmdTest { + + @Test + public void testGetTag() { + ListResourceLimitsCmd cmd = new ListResourceLimitsCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmdTest.java new file mode 100644 index 00000000000..ab7d3253ab5 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceCountCmdTest.java @@ -0,0 +1,37 @@ +// 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 org.apache.cloudstack.api.command.user.resource; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateResourceCountCmdTest { + + @Test + public void testGetTag() { + UpdateResourceCountCmd cmd = new UpdateResourceCountCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmdTest.java new file mode 100644 index 00000000000..dff27a20044 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/resource/UpdateResourceLimitCmdTest.java @@ -0,0 +1,37 @@ +// 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 org.apache.cloudstack.api.command.user.resource; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateResourceLimitCmdTest { + + @Test + public void testGetTag() { + UpdateResourceLimitCmd cmd = new UpdateResourceLimitCmd(); + ReflectionTestUtils.setField(cmd, "tag", null); + Assert.assertNull(cmd.getTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "tag", tag); + Assert.assertEquals(tag, cmd.getTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java index 8639e135599..29b6144fd07 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdByAdminTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java index 269a7b8a9e6..fb55e86dc0c 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/CopyTemplateCmdTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java index 1ba7963b2b9..1dc05888608 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdByAdminTest.java @@ -29,7 +29,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; @RunWith(MockitoJUnitRunner.class) diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java index 0c31e501519..a063f6c2d6b 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmdTest.java @@ -29,7 +29,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmdTest.java new file mode 100644 index 00000000000..03e558b58a8 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmdTest.java @@ -0,0 +1,49 @@ +// 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 org.apache.cloudstack.api.command.user.template; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import com.cloud.storage.Storage; + +@RunWith(MockitoJUnitRunner.class) +public class UpdateTemplateCmdTest { + + @Test + public void testGetTemplateType() { + UpdateTemplateCmd cmd = new UpdateTemplateCmd(); + ReflectionTestUtils.setField(cmd, "templateType", null); + Assert.assertNull(cmd.getTemplateType()); + String type = Storage.TemplateType.ROUTING.toString(); + ReflectionTestUtils.setField(cmd, "templateTag", type); + Assert.assertEquals(type, cmd.getTemplateTag()); + } + + @Test + public void testGetTemplateTag() { + UpdateTemplateCmd cmd = new UpdateTemplateCmd(); + ReflectionTestUtils.setField(cmd, "templateTag", null); + Assert.assertNull(cmd.getTemplateTag()); + String tag = "ABC"; + ReflectionTestUtils.setField(cmd, "templateTag", tag); + Assert.assertEquals(tag, cmd.getTemplateTag()); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java index 2fdef2acaa9..c9eb672c9e9 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java @@ -23,6 +23,7 @@ import com.cloud.utils.db.EntityManager; import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -41,9 +42,16 @@ public class CreateVMScheduleCmdTest { @InjectMocks private CreateVMScheduleCmd createVMScheduleCmd = new CreateVMScheduleCmd(); + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java index 6adfc2b905c..9b4decc83aa 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java @@ -25,6 +25,7 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.vm.schedule.VMSchedule; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -44,9 +45,16 @@ public class DeleteVMScheduleCmdTest { @InjectMocks private DeleteVMScheduleCmd deleteVMScheduleCmd = new DeleteVMScheduleCmd(); + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java index 18657b4c397..f9a1d945f03 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java @@ -21,6 +21,7 @@ package org.apache.cloudstack.api.command.user.vm; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -38,10 +39,16 @@ public class ListVMScheduleCmdTest { public VMScheduleManager vmScheduleManager; @InjectMocks private ListVMScheduleCmd listVMScheduleCmd = new ListVMScheduleCmd(); + private AutoCloseable closeable; @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java index 044685b579c..5ce133382f3 100644 --- a/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java @@ -24,6 +24,7 @@ import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.api.response.VMScheduleResponse; import org.apache.cloudstack.vm.schedule.VMSchedule; import org.apache.cloudstack.vm.schedule.VMScheduleManager; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -42,9 +43,16 @@ public class UpdateVMScheduleCmdTest { @InjectMocks private UpdateVMScheduleCmd updateVMScheduleCmd = new UpdateVMScheduleCmd(); + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } /** diff --git a/api/src/test/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmdTest.java b/api/src/test/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmdTest.java new file mode 100644 index 00000000000..226ff882fa7 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/api/command/user/volume/CheckAndRepairVolumeCmdTest.java @@ -0,0 +1,63 @@ +// 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 org.apache.cloudstack.api.command.user.volume; + +import com.cloud.exception.InvalidParameterValueException; +import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class CheckAndRepairVolumeCmdTest extends TestCase { + private CheckAndRepairVolumeCmd checkAndRepairVolumeCmd; + private AutoCloseable closeable; + + @Before + public void setup() { + closeable = MockitoAnnotations.openMocks(this); + checkAndRepairVolumeCmd = new CheckAndRepairVolumeCmd(); + } + + @After + public void tearDown() throws Exception { + closeable.close(); + } + + @Test + public void testGetRepair() { + ReflectionTestUtils.setField(checkAndRepairVolumeCmd, "repair", "all"); + assertEquals("all", checkAndRepairVolumeCmd.getRepair()); + + ReflectionTestUtils.setField(checkAndRepairVolumeCmd, "repair", "LEAKS"); + assertEquals("leaks", checkAndRepairVolumeCmd.getRepair()); + + ReflectionTestUtils.setField(checkAndRepairVolumeCmd, "repair", null); + assertNull(checkAndRepairVolumeCmd.getRepair()); + } + + @Test(expected = InvalidParameterValueException.class) + public void testGetRepairInvalid() { + ReflectionTestUtils.setField(checkAndRepairVolumeCmd, "repair", "RANDOM STRING"); + checkAndRepairVolumeCmd.getRepair(); + } +} diff --git a/api/src/test/java/org/apache/cloudstack/cluster/ClusterDrsAlgorithmTest.java b/api/src/test/java/org/apache/cloudstack/cluster/ClusterDrsAlgorithmTest.java new file mode 100644 index 00000000000..88379810944 --- /dev/null +++ b/api/src/test/java/org/apache/cloudstack/cluster/ClusterDrsAlgorithmTest.java @@ -0,0 +1,97 @@ +/* + * 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 org.apache.cloudstack.cluster; + +import com.cloud.utils.Ternary; +import junit.framework.TestCase; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.List; + +import static org.apache.cloudstack.cluster.ClusterDrsAlgorithm.getMetricValue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyFloat; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ClusterDrsAlgorithmTest extends TestCase { + + @Test + public void testGetMetricValue() { + List> testData = List.of( + new Ternary<>(true, "free", 0.4), + new Ternary<>(false, "free", 40.0), + new Ternary<>(true, "used", 0.3), + new Ternary<>(false, "used", 30.0) + ); + + long used = 30; + long free = 40; + long total = 100; + + for (Ternary data : testData) { + boolean useRatio = data.first(); + String metricType = data.second(); + double expectedValue = data.third(); + + try (MockedStatic ignored = Mockito.mockStatic(ClusterDrsAlgorithm.class)) { + when(ClusterDrsAlgorithm.getDrsMetricUseRatio(1L)).thenReturn(useRatio); + when(ClusterDrsAlgorithm.getDrsMetricType(1L)).thenReturn(metricType); + when(ClusterDrsAlgorithm.getMetricValue(anyLong(), anyLong(), anyLong(), anyLong(), any())).thenCallRealMethod(); + + assertEquals(expectedValue, getMetricValue(1, used, free, total, null)); + } + } + } + + @Test + public void testGetMetricValueWithSkipThreshold() { + List> testData = List.of( + new Ternary<>(true, "free", 0.15), + new Ternary<>(false, "free", 15.0), + new Ternary<>(true, "used", null), + new Ternary<>(false, "used", null) + ); + + long used = 80; + long free = 15; + long total = 100; + + for (Ternary data : testData) { + boolean useRatio = data.first(); + String metricType = data.second(); + Double expectedValue = data.third(); + float skipThreshold = metricType.equals("free") ? 0.1f : 0.7f; + + try (MockedStatic ignored = Mockito.mockStatic(ClusterDrsAlgorithm.class)) { + when(ClusterDrsAlgorithm.getDrsMetricUseRatio(1L)).thenReturn(useRatio); + when(ClusterDrsAlgorithm.getDrsMetricType(1L)).thenReturn(metricType); + when(ClusterDrsAlgorithm.getMetricValue(anyLong(), anyLong(), anyLong(), anyLong(), anyFloat())).thenCallRealMethod(); + + assertEquals(expectedValue, ClusterDrsAlgorithm.getMetricValue(1L, used, free, total, skipThreshold)); + } + } + } +} diff --git a/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java b/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java index eb1336f90e9..d3537d6f831 100644 --- a/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java +++ b/api/src/test/java/org/apache/cloudstack/context/CallContextTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.Account; import com.cloud.user.User; diff --git a/api/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/api/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/api/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/client/conf/log4j-cloud.xml.in b/client/conf/log4j-cloud.xml.in index 223692881de..dbcf8c6198b 100755 --- a/client/conf/log4j-cloud.xml.in +++ b/client/conf/log4j-cloud.xml.in @@ -17,183 +17,118 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - + + - - + + net.sf.cglib.proxy + - - - + + + - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - + + + + + + + - - - - - - - - + + + - - - + + + + - - - - - - - - + + + - - - + + + + - - - - - - - - - - + + + - - - + + + + - - - - - - - + + + - - - + + + + - - - + - - - + - - - + - - - + - - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - + + + - - - - + - - - - + - - - - + + + + + + + - - - + + + - - - - - - - - + + + + + - - - - - - - - - - - - + + diff --git a/client/conf/server.properties.in b/client/conf/server.properties.in index 42d98a6eb29..57d81c81217 100644 --- a/client/conf/server.properties.in +++ b/client/conf/server.properties.in @@ -29,19 +29,22 @@ http.port=8080 # Max inactivity time in minutes for the session session.timeout=30 -# Options to configure and enable HTTPS on management server +# Max allowed API request payload/content size in bytes +request.content.size=1048576 + +# Options to configure and enable HTTPS on the management server # -# For management server to pickup these configuration settings, the configured -# keystore file should exists and be readable by the management server. +# For the management server to pick up these configuration settings, the configured +# keystore file should exist and be readable by the management server. https.enable=false https.port=8443 # The keystore and manager passwords are assumed to be same. https.keystore=/etc/cloudstack/management/cloud.jks -# If you want to encrypt the password follow the steps mentioned at: -# http://docs.cloudstack.apache.org/projects/archived-cloudstack-administration/en/latest/management.html?highlight=jasypt#changing-the-database-password +# If you want to encrypt the password itself, follow the steps mentioned at: +http://docs.cloudstack.apache.org/en/latest/adminguide/management.html?highlight=jasypt#changing-the-database-password https.keystore.password=vmops.com -# If an encrypted password is used, specify the encryption type - valid types: file, env (set environment variable CLOUD_SECRET_KEY), web +# If an encrypted password is used, specify the encryption type. Valid types: file, web, env (set environment variable CLOUD_SECRET_KEY) # password.encryption.type=none # The path to webapp directory diff --git a/client/pom.xml b/client/pom.xml index f0ba65e0a8c..a73aed7d032 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT @@ -68,8 +68,8 @@ jetty-util - mysql - mysql-connector-java + com.mysql + mysql-connector-j org.apache.cloudstack @@ -709,8 +709,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j ${cs.mysql.version} @@ -752,7 +752,7 @@ - log4j.configuration + log4j2.configurationFile log4j-cloud.xml @@ -898,8 +898,8 @@ ${project.build.directory}/pythonlibs - mysql - mysql-connector-java + com.mysql + mysql-connector-j false ${project.build.directory}/lib @@ -973,7 +973,7 @@ org.bouncycastle:bcprov-jdk15on org.bouncycastle:bcpkix-jdk15on org.bouncycastle:bctls-jdk15on - mysql:mysql-connector-java + com.mysql:mysql-connector-j org.apache.cloudstack:cloud-plugin-storage-volume-storpool org.apache.cloudstack:cloud-plugin-storage-volume-linstor org.apache.cloudstack:cloud-usage @@ -1097,6 +1097,11 @@ cloud-plugin-network-cisco-vnmc ${project.version} + + org.apache.cloudstack + cloud-plugin-network-nsx + ${project.version} + org.apache.cloudstack cloud-plugin-api-vmware-sioc diff --git a/client/src/main/java/org/apache/cloudstack/ServerDaemon.java b/client/src/main/java/org/apache/cloudstack/ServerDaemon.java index 63cdc45b8dc..d2e4483835e 100644 --- a/client/src/main/java/org/apache/cloudstack/ServerDaemon.java +++ b/client/src/main/java/org/apache/cloudstack/ServerDaemon.java @@ -26,12 +26,10 @@ import java.lang.management.ManagementFactory; import java.net.URL; import java.util.Properties; -import com.cloud.utils.Pair; -import com.cloud.utils.server.ServerProperties; import org.apache.commons.daemon.Daemon; import org.apache.commons.daemon.DaemonContext; +import org.apache.commons.lang3.StringUtils; import org.eclipse.jetty.jmx.MBeanContainer; -import org.eclipse.jetty.server.ForwardedRequestCustomizer; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.NCSARequestLog; @@ -40,6 +38,7 @@ import org.eclipse.jetty.server.SecureRequestCustomizer; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.SslConnectionFactory; +import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.MovedContextHandler; import org.eclipse.jetty.server.handler.RequestLogHandler; @@ -50,10 +49,12 @@ import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; import org.eclipse.jetty.webapp.WebAppContext; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import com.cloud.utils.Pair; import com.cloud.utils.PropertiesUtil; -import org.apache.commons.lang3.StringUtils; +import com.cloud.utils.server.ServerProperties; /*** * The ServerDaemon class implements the embedded server, it can be started either @@ -61,7 +62,7 @@ import org.apache.commons.lang3.StringUtils; * Configuration parameters are read from server.properties file available on the classpath. */ public class ServerDaemon implements Daemon { - private static final Logger LOG = Logger.getLogger(ServerDaemon.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String WEB_XML = "META-INF/webapp/WEB-INF/web.xml"; ///////////////////////////////////////////////////// @@ -79,6 +80,8 @@ public class ServerDaemon implements Daemon { private static final String KEYSTORE_PASSWORD = "https.keystore.password"; private static final String WEBAPP_DIR = "webapp.dir"; private static final String ACCESS_LOG = "access.log"; + private static final String REQUEST_CONTENT_SIZE_KEY = "request.content.size"; + private static final int DEFAULT_REQUEST_CONTENT_SIZE = 1048576; //////////////////////////////////////////////////////// /////////////// Server Configuration /////////////////// @@ -90,6 +93,7 @@ public class ServerDaemon implements Daemon { private int httpPort = 8080; private int httpsPort = 8443; private int sessionTimeout = 30; + private int maxFormContentSize = DEFAULT_REQUEST_CONTENT_SIZE; private boolean httpsEnable = false; private String accessLogFile = "access.log"; private String bindInterface = null; @@ -112,12 +116,12 @@ public class ServerDaemon implements Daemon { public void init(final DaemonContext context) { final File confFile = PropertiesUtil.findConfigFile("server.properties"); if (confFile == null) { - LOG.warn(String.format("Server configuration file not found. Initializing server daemon on %s, with http.enable=%s, http.port=%s, https.enable=%s, https.port=%s, context.path=%s", + logger.warn(String.format("Server configuration file not found. Initializing server daemon on %s, with http.enable=%s, http.port=%s, https.enable=%s, https.port=%s, context.path=%s", bindInterface, httpEnable, httpPort, httpsEnable, httpsPort, contextPath)); return; } - LOG.info("Server configuration file found: " + confFile.getAbsolutePath()); + logger.info("Server configuration file found: " + confFile.getAbsolutePath()); try { InputStream is = new FileInputStream(confFile); @@ -136,16 +140,17 @@ public class ServerDaemon implements Daemon { setWebAppLocation(properties.getProperty(WEBAPP_DIR)); setAccessLogFile(properties.getProperty(ACCESS_LOG, "access.log")); setSessionTimeout(Integer.valueOf(properties.getProperty(SESSION_TIMEOUT, "30"))); + setMaxFormContentSize(Integer.valueOf(properties.getProperty(REQUEST_CONTENT_SIZE_KEY, String.valueOf(DEFAULT_REQUEST_CONTENT_SIZE)))); } catch (final IOException e) { - LOG.warn("Failed to read configuration from server.properties file", e); + logger.warn("Failed to read configuration from server.properties file", e); } finally { // make sure that at least HTTP is enabled if both of them are set to false (misconfiguration) if (!httpEnable && !httpsEnable) { setHttpEnable(true); - LOG.warn("Server configuration malformed, neither http nor https is enabled, http will be enabled."); + logger.warn("Server configuration malformed, neither http nor https is enabled, http will be enabled."); } } - LOG.info(String.format("Initializing server daemon on %s, with http.enable=%s, http.port=%s, https.enable=%s, https.port=%s, context.path=%s", + logger.info(String.format("Initializing server daemon on %s, with http.enable=%s, http.port=%s, https.enable=%s, https.port=%s, context.path=%s", bindInterface, httpEnable, httpPort, httpsEnable, httpsPort, contextPath)); } @@ -168,7 +173,7 @@ public class ServerDaemon implements Daemon { // HTTP config final HttpConfiguration httpConfig = new HttpConfiguration(); - httpConfig.addCustomizer( new ForwardedRequestCustomizer() ); +// it would be nice to make this dynamic but we take care of this ourselves for now: httpConfig.addCustomizer( new ForwardedRequestCustomizer() ); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(httpsPort); httpConfig.setOutputBufferSize(32768); @@ -186,6 +191,7 @@ public class ServerDaemon implements Daemon { // Extra config options server.setStopAtShutdown(true); + server.setAttribute(ContextHandler.MAX_FORM_CONTENT_SIZE_KEY, maxFormContentSize); // HTTPS Connector createHttpsConnector(httpConfig); @@ -248,7 +254,7 @@ public class ServerDaemon implements Daemon { KeyStoreScanner scanner = new KeyStoreScanner(sslContextFactory); server.addBean(scanner); } catch (Exception ex) { - LOG.error("failed to set up keystore scanner, manual refresh of certificates will be required", ex); + logger.error("failed to set up keystore scanner, manual refresh of certificates will be required", ex); } } } @@ -257,6 +263,7 @@ public class ServerDaemon implements Daemon { final WebAppContext webApp = new WebAppContext(); webApp.setContextPath(contextPath); webApp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); + webApp.setMaxFormContentSize(maxFormContentSize); // GZIP handler final GzipHandler gzipHandler = new GzipHandler(); @@ -355,4 +362,8 @@ public class ServerDaemon implements Daemon { public void setSessionTimeout(int sessionTimeout) { this.sessionTimeout = sessionTimeout; } + + public void setMaxFormContentSize(int maxFormContentSize) { + this.maxFormContentSize = maxFormContentSize; + } } diff --git a/client/src/main/webapp/WEB-INF/web.xml b/client/src/main/webapp/WEB-INF/web.xml index 9a3d8bc5b29..43bee7e59d8 100644 --- a/client/src/main/webapp/WEB-INF/web.xml +++ b/client/src/main/webapp/WEB-INF/web.xml @@ -21,7 +21,7 @@ version="2.5"> - log4jConfigLocation + log4jConfiguration classpath:log4j-cloud.xml diff --git a/core/pom.xml b/core/pom.xml index 339439abbee..83cdee8cf4f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT diff --git a/core/src/main/java/com/cloud/agent/api/SecurityGroupRulesCmd.java b/core/src/main/java/com/cloud/agent/api/SecurityGroupRulesCmd.java index ea4ab96c5a7..5d202172c35 100644 --- a/core/src/main/java/com/cloud/agent/api/SecurityGroupRulesCmd.java +++ b/core/src/main/java/com/cloud/agent/api/SecurityGroupRulesCmd.java @@ -27,7 +27,6 @@ import java.util.zip.DeflaterOutputStream; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.digest.DigestUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.LogLevel.Log4jLevel; import com.cloud.agent.api.to.VirtualMachineTO; @@ -39,7 +38,6 @@ public class SecurityGroupRulesCmd extends Command { public static final char RULE_COMMAND_SEPARATOR = ';'; protected static final String EGRESS_RULE = "E:"; protected static final String INGRESS_RULE = "I:"; - private static final Logger LOGGER = Logger.getLogger(SecurityGroupRulesCmd.class); private final String guestIp; private final String guestIp6; @@ -233,7 +231,7 @@ public class SecurityGroupRulesCmd extends Command { dzip.close(); encodedResult = Base64.encodeBase64String(out.toByteArray()); } catch (final IOException e) { - LOGGER.warn("Exception while compressing security group rules"); + logger.warn("Exception while compressing security group rules"); } return encodedResult; } diff --git a/core/src/main/java/com/cloud/agent/api/SetupGuestNetworkCommand.java b/core/src/main/java/com/cloud/agent/api/SetupGuestNetworkCommand.java index e9781993239..06583f2d0d3 100644 --- a/core/src/main/java/com/cloud/agent/api/SetupGuestNetworkCommand.java +++ b/core/src/main/java/com/cloud/agent/api/SetupGuestNetworkCommand.java @@ -35,6 +35,7 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand { String routerIpv6 = null; String routerIpv6Gateway = null; String routerIpv6Cidr = null; + boolean isVrGuestGateway = false; public NicTO getNic() { return nic; @@ -114,4 +115,12 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand { public void setDefaultIp6Dns2(String defaultIp6Dns2) { this.defaultIp6Dns2 = defaultIp6Dns2; } + + public boolean isVrGuestGateway() { + return isVrGuestGateway; + } + + public void setVrGuestGateway(boolean vrGuestGateway) { + isVrGuestGateway = vrGuestGateway; + } } diff --git a/core/src/main/java/com/cloud/agent/api/storage/CheckAndRepairVolumeAnswer.java b/core/src/main/java/com/cloud/agent/api/storage/CheckAndRepairVolumeAnswer.java new file mode 100644 index 00000000000..3dc7752bfef --- /dev/null +++ b/core/src/main/java/com/cloud/agent/api/storage/CheckAndRepairVolumeAnswer.java @@ -0,0 +1,57 @@ +// +// 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.api.storage; + +import com.cloud.agent.api.Answer; + +public class CheckAndRepairVolumeAnswer extends Answer { + private String volumeCheckExecutionResult; + private String volumeRepairExecutionResult; + + protected CheckAndRepairVolumeAnswer() { + super(); + } + + public CheckAndRepairVolumeAnswer(CheckAndRepairVolumeCommand cmd, boolean result, String details, String volumeCheckExecutionResult, String volumeRepairedExecutionResult) { + super(cmd, result, details); + this.volumeCheckExecutionResult = volumeCheckExecutionResult; + this.volumeRepairExecutionResult = volumeRepairedExecutionResult; + } + + public CheckAndRepairVolumeAnswer(CheckAndRepairVolumeCommand cmd, boolean result, String details) { + super(cmd, result, details); + } + + public String getVolumeCheckExecutionResult() { + return volumeCheckExecutionResult; + } + + public String getVolumeRepairExecutionResult() { + return volumeRepairExecutionResult; + } + + public void setVolumeCheckExecutionResult(String volumeCheckExecutionResult) { + this.volumeCheckExecutionResult = volumeCheckExecutionResult; + } + + public void setVolumeRepairExecutionResult(String volumeRepairExecutionResult) { + this.volumeRepairExecutionResult = volumeRepairExecutionResult; + } +} diff --git a/core/src/main/java/com/cloud/agent/api/storage/CheckAndRepairVolumeCommand.java b/core/src/main/java/com/cloud/agent/api/storage/CheckAndRepairVolumeCommand.java new file mode 100644 index 00000000000..2553fdf477c --- /dev/null +++ b/core/src/main/java/com/cloud/agent/api/storage/CheckAndRepairVolumeCommand.java @@ -0,0 +1,77 @@ +// +// 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.api.storage; + +import com.cloud.agent.api.Command; +import com.cloud.agent.api.LogLevel; +import com.cloud.agent.api.to.StorageFilerTO; + +import java.util.Arrays; + +public class CheckAndRepairVolumeCommand extends Command { + private String path; + private StorageFilerTO pool; + private String repair; + @LogLevel(LogLevel.Log4jLevel.Off) + private byte[] passphrase; + private String encryptFormat; + + public CheckAndRepairVolumeCommand(String path, StorageFilerTO pool, String repair, byte[] passphrase, String encryptFormat) { + this.path = path; + this.pool = pool; + this.repair = repair; + this.passphrase = passphrase; + this.encryptFormat = encryptFormat; + } + + public String getPath() { + return path; + } + + public String getPoolUuid() { + return pool.getUuid(); + } + + public StorageFilerTO getPool() { + return pool; + } + + public String getRepair() { + return repair; + } + + public String getEncryptFormat() { return encryptFormat; } + + public byte[] getPassphrase() { return passphrase; } + + public void clearPassphrase() { + if (this.passphrase != null) { + Arrays.fill(this.passphrase, (byte) 0); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean executeInSequence() { + return false; + } +} diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java index 4492947b2cc..3c86b3a0dcc 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java @@ -51,7 +51,8 @@ import org.apache.cloudstack.diagnostics.PrepareFilesCommand; import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.net.util.SubnetUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.joda.time.Duration; import com.cloud.agent.api.Answer; @@ -85,7 +86,7 @@ import com.cloud.utils.exception.CloudRuntimeException; **/ public class VirtualRoutingResource { - private static final Logger s_logger = Logger.getLogger(VirtualRoutingResource.class); + protected Logger logger = LogManager.getLogger(getClass()); private VirtualRouterDeployer _vrDeployer; private Map> _vrAggregateCommandsSet; protected Map _vrLockMap = new HashMap(); @@ -117,7 +118,7 @@ public class VirtualRoutingResource { try { ExecutionResult rc = _vrDeployer.prepareCommand(cmd); if (!rc.isSuccess()) { - s_logger.error("Failed to prepare VR command due to " + rc.getDetails()); + logger.error("Failed to prepare VR command due to " + rc.getDetails()); return new Answer(cmd, false, rc.getDetails()); } @@ -164,7 +165,7 @@ public class VirtualRoutingResource { if (!aggregated) { ExecutionResult rc = _vrDeployer.cleanupCommand(cmd); if (!rc.isSuccess()) { - s_logger.error("Failed to cleanup VR command due to " + rc.getDetails()); + logger.error("Failed to cleanup VR command due to " + rc.getDetails()); } } } @@ -220,15 +221,15 @@ public class VirtualRoutingResource { } else if (cmd instanceof GetRouterMonitorResultsCommand) { return execute((GetRouterMonitorResultsCommand)cmd); } else { - s_logger.error("Unknown query command in VirtualRoutingResource!"); + logger.error("Unknown query command in VirtualRoutingResource!"); return Answer.createUnsupportedCommandAnswer(cmd); } } - private static String getRouterSshControlIp(NetworkElementCommand cmd) { + private String getRouterSshControlIp(NetworkElementCommand cmd) { String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); - if (s_logger.isDebugEnabled()) - s_logger.debug("Use router's private IP for SSH control. IP : " + routerIp); + if (logger.isDebugEnabled()) + logger.debug("Use router's private IP for SSH control. IP : " + routerIp); return routerIp; } @@ -243,24 +244,24 @@ public class VirtualRoutingResource { String subnet = address.split("/")[1]; ExecutionResult result = _vrDeployer.executeInVR(routerIp, VRScripts.VR_UPDATE_INTERFACE_CONFIG, ipAddressTO.getPublicIp() + " " + subnet + " " + ipAddressTO.getMtu() + " " + 15); - if (s_logger.isDebugEnabled()) - s_logger.debug("result: " + result.isSuccess() + ", output: " + result.getDetails()); + if (logger.isDebugEnabled()) + logger.debug("result: " + result.isSuccess() + ", output: " + result.getDetails()); if (!Boolean.TRUE.equals(result.isSuccess())) { if (result.getDetails().contains(String.format("Interface with IP %s not found", ipAddressTO.getPublicIp()))) { - s_logger.warn(String.format("Skipping IP: %s as it isn't configured on router interface", ipAddressTO.getPublicIp())); + logger.warn(String.format("Skipping IP: %s as it isn't configured on router interface", ipAddressTO.getPublicIp())); } else if (ipAddressTO.getDetails().get(ApiConstants.REDUNDANT_STATE).equals(VirtualRouter.RedundantState.PRIMARY.name())) { - s_logger.warn(String.format("Failed to update interface mtu to %s on interface with ip: %s", + logger.warn(String.format("Failed to update interface mtu to %s on interface with ip: %s", ipAddressTO.getMtu(), ipAddressTO.getPublicIp())); finalResult = false; } continue; } - s_logger.info(String.format("Successfully updated mtu to %s on interface with ip: %s", + logger.info(String.format("Successfully updated mtu to %s on interface with ip: %s", ipAddressTO.getMtu(), ipAddressTO.getPublicIp())); finalResult &= true; } catch (Exception e) { String msg = "Prepare UpdateNetwork failed due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, e); } } @@ -296,9 +297,9 @@ public class VirtualRoutingResource { for (ConfigItem configItem : cfg) { long startTimestamp = System.currentTimeMillis(); ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), configItem, VRScripts.VR_SCRIPT_EXEC_TIMEOUT); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { long elapsed = System.currentTimeMillis() - startTimestamp; - s_logger.debug("Processing " + configItem + " took " + elapsed + "ms"); + logger.debug("Processing " + configItem + " took " + elapsed + "ms"); } if (result == null) { result = new ExecutionResult(false, "null execution result"); @@ -310,7 +311,7 @@ public class VirtualRoutingResource { // Not sure why this matters, but log it anyway if (cmd.getAnswersCount() != results.size()) { - s_logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing " + cmd.getClass().getSimpleName() + " but received " + results.size()); + logger.warn("Expected " + cmd.getAnswersCount() + " answers while executing " + cmd.getClass().getSimpleName() + " but received " + results.size()); } if (results.size() == 1) { @@ -359,7 +360,7 @@ public class VirtualRoutingResource { } else if (!readingFailedChecks && readingMonitorResults) { // Reading monitor checks result monitorResults.append(line); } else { - s_logger.error("Unexpected lines reached while parsing health check response. Skipping line:- " + line); + logger.error("Unexpected lines reached while parsing health check response. Skipping line:- " + line); } } @@ -379,16 +380,16 @@ public class VirtualRoutingResource { } String args = cmd.shouldPerformFreshChecks() ? "true" : "false"; - s_logger.info("Fetching health check result for " + routerIp + " and executing fresh checks: " + args); + logger.info("Fetching health check result for " + routerIp + " and executing fresh checks: " + args); ExecutionResult result = _vrDeployer.executeInVR(routerIp, VRScripts.ROUTER_MONITOR_RESULTS, args); if (!result.isSuccess()) { - s_logger.warn("Result of " + cmd + " failed with details: " + result.getDetails()); + logger.warn("Result of " + cmd + " failed with details: " + result.getDetails()); return new GetRouterMonitorResultsAnswer(cmd, false, null, result.getDetails()); } if (result.getDetails().isEmpty()) { - s_logger.warn("Result of " + cmd + " received no details."); + logger.warn("Result of " + cmd + " received no details."); return new GetRouterMonitorResultsAnswer(cmd, false, null, "No results available."); } @@ -398,12 +399,12 @@ public class VirtualRoutingResource { private Pair checkRouterFileSystem(String routerIp) { ExecutionResult fileSystemWritableTestResult = _vrDeployer.executeInVR(routerIp, VRScripts.ROUTER_FILESYSTEM_WRITABLE_CHECK, null); if (fileSystemWritableTestResult.isSuccess()) { - s_logger.debug("Router connectivity and file system writable check passed"); + logger.debug("Router connectivity and file system writable check passed"); return new Pair(true, "success"); } String resultDetails = fileSystemWritableTestResult.getDetails(); - s_logger.warn("File system writable check failed with details: " + resultDetails); + logger.warn("File system writable check failed with details: " + resultDetails); if (StringUtils.isNotBlank(resultDetails)) { final String readOnlyFileSystemError = "Read-only file system"; if (resultDetails.contains(readOnlyFileSystemError)) { @@ -488,8 +489,8 @@ public class VirtualRoutingResource { if (params.get("router.aggregation.command.each.timeout") != null) { String value = (String)params.get("router.aggregation.command.each.timeout"); _eachTimeout = Duration.standardSeconds(NumbersUtil.parseLong(value, 600)); - if (s_logger.isDebugEnabled()){ - s_logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); + if (logger.isDebugEnabled()){ + logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); } } @@ -510,8 +511,8 @@ public class VirtualRoutingResource { value = (String)params.get("router.aggregation.command.each.timeout"); _eachTimeout = Duration.standardSeconds(NumbersUtil.parseInt(value, (int)VRScripts.VR_SCRIPT_EXEC_TIMEOUT.getStandardSeconds())); - if (s_logger.isDebugEnabled()){ - s_logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); + if (logger.isDebugEnabled()){ + logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); } if (_vrDeployer == null) { @@ -534,8 +535,8 @@ public class VirtualRoutingResource { for (int i = 0; i <= retry; i++) { SocketChannel sch = null; try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Trying to connect to " + ipAddress); + if (logger.isDebugEnabled()) { + logger.debug("Trying to connect to " + ipAddress); } sch = SocketChannel.open(); sch.configureBlocking(true); @@ -544,8 +545,8 @@ public class VirtualRoutingResource { sch.connect(addr); return true; } catch (final IOException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Could not connect to " + ipAddress); + if (logger.isDebugEnabled()) { + logger.debug("Could not connect to " + ipAddress); } } finally { if (sch != null) { @@ -561,7 +562,7 @@ public class VirtualRoutingResource { } } - s_logger.debug("Unable to logon to " + ipAddress); + logger.debug("Unable to logon to " + ipAddress); return false; } @@ -571,7 +572,7 @@ public class VirtualRoutingResource { * [TODO] Still have to migrate LoadBalancerConfigCommand and BumpUpPriorityCommand * [FIXME] Have a look at SetSourceNatConfigItem */ - s_logger.debug("Transforming " + cmd.getClass().getCanonicalName() + " to ConfigItems"); + logger.debug("Transforming " + cmd.getClass().getCanonicalName() + " to ConfigItems"); final AbstractConfigItemFacade configItemFacade = AbstractConfigItemFacade.getInstance(cmd.getClass()); @@ -601,7 +602,7 @@ public class VirtualRoutingResource { answerCounts += command.getAnswersCount(); List cfg = generateCommandCfg(command); if (cfg == null) { - s_logger.warn("Unknown commands for VirtualRoutingResource, but continue: " + cmd.toString()); + logger.warn("Unknown commands for VirtualRoutingResource, but continue: " + cmd.toString()); continue; } @@ -616,8 +617,8 @@ public class VirtualRoutingResource { ScriptConfigItem scriptConfigItem = new ScriptConfigItem(VRScripts.VR_CFG, "-c " + VRScripts.CONFIG_CACHE_LOCATION + cfgFileName); // 120s is the minimal timeout Duration timeout = _eachTimeout.withDurationAdded(_eachTimeout.getStandardSeconds(), answerCounts); - if (s_logger.isDebugEnabled()){ - s_logger.debug("Aggregate action timeout in seconds is " + timeout.getStandardSeconds()); + if (logger.isDebugEnabled()){ + logger.debug("Aggregate action timeout in seconds is " + timeout.getStandardSeconds()); } ExecutionResult result = applyConfigToVR(cmd.getRouterAccessIp(), fileConfigItem, timeout); diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/AbstractConfigItemFacade.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/AbstractConfigItemFacade.java index bed472b6880..46dd801bebf 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/AbstractConfigItemFacade.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/AbstractConfigItemFacade.java @@ -24,7 +24,6 @@ import java.util.LinkedList; import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.agent.api.BumpUpPriorityCommand; import com.cloud.agent.api.SetupGuestNetworkCommand; @@ -59,10 +58,12 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public abstract class AbstractConfigItemFacade { - private static final Logger s_logger = Logger.getLogger(AbstractConfigItemFacade.class); + protected Logger logger = LogManager.getLogger(getClass()); private final static Gson gson; @@ -123,8 +124,8 @@ public abstract class AbstractConfigItemFacade { final List cfg = new LinkedList<>(); final String remoteFilename = appendUuidToJsonFiles(destinationFile); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Transformed filename: " + destinationFile + " to: " + remoteFilename); + if (logger.isDebugEnabled()) { + logger.debug("Transformed filename: " + destinationFile + " to: " + remoteFilename); } final ConfigItem configFile = new FileConfigItem(VRScripts.CONFIG_PERSIST_LOCATION, remoteFilename, gson.toJson(configuration)); diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetGuestNetworkConfigItem.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetGuestNetworkConfigItem.java index aee1e779571..1a6824ceb7f 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetGuestNetworkConfigItem.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetGuestNetworkConfigItem.java @@ -75,6 +75,7 @@ public class SetGuestNetworkConfigItem extends AbstractConfigItemFacade { guestNetwork.setRouterIp6(command.getRouterIpv6()); guestNetwork.setRouterIp6Gateway(command.getRouterIpv6Gateway()); guestNetwork.setRouterIp6Cidr(command.getRouterIpv6Cidr()); + guestNetwork.setVrGuestGateway(command.isVrGuestGateway()); return generateConfigItems(guestNetwork); } diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetMonitorServiceConfigItem.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetMonitorServiceConfigItem.java index 52d8442b5ac..227675ebf4e 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetMonitorServiceConfigItem.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetMonitorServiceConfigItem.java @@ -21,7 +21,6 @@ package com.cloud.agent.resource.virtualnetwork.facade; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.routing.SetMonitorServiceCommand; @@ -32,7 +31,6 @@ import com.cloud.agent.resource.virtualnetwork.model.ConfigBase; import com.cloud.agent.resource.virtualnetwork.model.MonitorService; public class SetMonitorServiceConfigItem extends AbstractConfigItemFacade { - private static final Logger s_logger = Logger.getLogger(SetMonitorServiceConfigItem.class); @Override public List generateConfig(final NetworkElementCommand cmd) { @@ -58,14 +56,14 @@ public class SetMonitorServiceConfigItem extends AbstractConfigItemFacade { try { monitorService.setHealthChecksBasicRunInterval(Integer.parseInt(command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_BASIC_INTERVAL))); } catch (NumberFormatException exception) { - s_logger.error("Unexpected health check basic interval set" + command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_BASIC_INTERVAL) + + logger.error("Unexpected health check basic interval set" + command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_BASIC_INTERVAL) + ". Exception: " + exception + "Will use default value"); } try { monitorService.setHealthChecksAdvancedRunInterval(Integer.parseInt(command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_ADVANCED_INTERVAL))); } catch (NumberFormatException exception) { - s_logger.error("Unexpected health check advanced interval set" + command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_ADVANCED_INTERVAL) + + logger.error("Unexpected health check advanced interval set" + command.getAccessDetail(SetMonitorServiceCommand.ROUTER_HEALTH_CHECKS_ADVANCED_INTERVAL) + ". Exception: " + exception + "Will use default value"); } diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java index a64328d516a..f4c3275aa2b 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/facade/SetNetworkAclConfigItem.java @@ -22,7 +22,6 @@ package com.cloud.agent.resource.virtualnetwork.facade; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.agent.api.routing.SetNetworkACLCommand; @@ -41,7 +40,6 @@ import com.cloud.utils.net.NetUtils; public class SetNetworkAclConfigItem extends AbstractConfigItemFacade { - public static final Logger s_logger = Logger.getLogger(SetNetworkAclConfigItem.class.getName()); @Override public List generateConfig(final NetworkElementCommand cmd) { @@ -81,7 +79,7 @@ public class SetNetworkAclConfigItem extends AbstractConfigItemFacade { try { aclRule = new ProtocolAclRule(ruleParts[4], "ACCEPT".equals(ruleParts[5]), Integer.parseInt(ruleParts[1])); } catch (final Exception e) { - s_logger.warn("Problem occurred when reading the entries in the ruleParts array. Actual array size is '" + ruleParts.length + "', but trying to read from index 5."); + logger.warn("Problem occurred when reading the entries in the ruleParts array. Actual array size is '" + ruleParts.length + "', but trying to read from index 5."); continue; } } diff --git a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java index bb5e443c2e8..a416b4bc5e4 100644 --- a/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java +++ b/core/src/main/java/com/cloud/agent/resource/virtualnetwork/model/GuestNetwork.java @@ -37,6 +37,7 @@ public class GuestNetwork extends ConfigBase { private String routerIp6; private String routerIp6Gateway; private String routerIp6Cidr; + private boolean isVrGuestGateway; private Integer mtu; @@ -202,4 +203,12 @@ public class GuestNetwork extends ConfigBase { public Integer getMtu() { return mtu; } + + public boolean isVrGuestGateway() { + return isVrGuestGateway; + } + + public void setVrGuestGateway(boolean vrGuestGateway) { + isVrGuestGateway = vrGuestGateway; + } } diff --git a/core/src/main/java/com/cloud/agent/transport/LoggingExclusionStrategy.java b/core/src/main/java/com/cloud/agent/transport/LoggingExclusionStrategy.java index 90e964e7139..2301c1fc205 100644 --- a/core/src/main/java/com/cloud/agent/transport/LoggingExclusionStrategy.java +++ b/core/src/main/java/com/cloud/agent/transport/LoggingExclusionStrategy.java @@ -19,7 +19,8 @@ package com.cloud.agent.transport; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; @@ -29,7 +30,9 @@ import com.cloud.agent.api.LogLevel; import com.cloud.agent.api.LogLevel.Log4jLevel; public class LoggingExclusionStrategy implements ExclusionStrategy { - Logger _logger = null; + protected Logger exclusionLogger = null; + + protected Logger logger = LogManager.getLogger(getClass()); @Override public boolean shouldSkipClass(Class clazz) { @@ -40,20 +43,24 @@ public class LoggingExclusionStrategy implements ExclusionStrategy { LogLevel level = clazz.getAnnotation(LogLevel.class); if (level == null) { log4jLevel = LogLevel.Log4jLevel.Debug; + logger.trace("Class {} does not have any log level annotation, considering level as debug.", clazz); } else { log4jLevel = level.value(); } - return !log4jLevel.enabled(_logger); + return !log4jLevel.enabled(exclusionLogger); } @Override public boolean shouldSkipField(FieldAttributes field) { LogLevel level = field.getAnnotation(LogLevel.class); - return level != null && !level.value().enabled(_logger); + return level != null && !level.value().enabled(exclusionLogger); } public LoggingExclusionStrategy(Logger logger) { - _logger = logger; + exclusionLogger = logger; + } + + public LoggingExclusionStrategy() { } } diff --git a/core/src/main/java/com/cloud/agent/transport/Request.java b/core/src/main/java/com/cloud/agent/transport/Request.java index 241ccd4bbd8..3769dbbd612 100644 --- a/core/src/main/java/com/cloud/agent/transport/Request.java +++ b/core/src/main/java/com/cloud/agent/transport/Request.java @@ -33,8 +33,9 @@ import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.BadCommand; @@ -75,7 +76,7 @@ import com.google.gson.stream.JsonReader; * */ public class Request { - private static final Logger s_logger = Logger.getLogger(Request.class); + protected static Logger LOGGER = LogManager.getLogger(Request.class); protected static final Gson s_gson = GsonHelper.getGson(); protected static final Gson s_gogger = GsonHelper.getGsonLogger(); @@ -251,10 +252,10 @@ public class Request { jsonReader.setLenient(true); _cmds = s_gson.fromJson(jsonReader, (Type)Command[].class); } catch (JsonParseException e) { - s_logger.error("Caught problem while parsing JSON command " + _content, e); + LOGGER.error("Caught problem while parsing JSON command " + _content, e); _cmds = new Command[] { new BadCommand() }; } catch (RuntimeException e) { - s_logger.error("Caught problem with " + _content, e); + LOGGER.error("Caught problem with " + _content, e); throw e; } } @@ -300,7 +301,7 @@ public class Request { } in.close(); } catch (IOException e) { - s_logger.error("Fail to decompress the request!", e); + LOGGER.error("Fail to decompress the request!", e); } retBuff.flip(); return retBuff; @@ -321,7 +322,7 @@ public class Request { out.finish(); out.close(); } catch (IOException e) { - s_logger.error("Fail to compress the request!", e); + LOGGER.error("Fail to compress the request!", e); } return ByteBuffer.wrap(byteOut.toByteArray()); } @@ -369,24 +370,24 @@ public class Request { } public void logD(String msg, boolean logContent) { - if (s_logger.isDebugEnabled()) { + if (LOGGER.isDebugEnabled()) { String log = log(msg, logContent, Level.DEBUG); if (log != null) { - s_logger.debug(log); + LOGGER.debug(log); } } } public void logT(String msg, boolean logD) { - if (s_logger.isTraceEnabled()) { + if (LOGGER.isTraceEnabled()) { String log = log(msg, true, Level.TRACE); if (log != null) { - s_logger.trace(log); + LOGGER.trace(log); } - } else if (logD && s_logger.isDebugEnabled()) { + } else if (logD && LOGGER.isDebugEnabled()) { String log = log(msg, false, Level.DEBUG); if (log != null) { - s_logger.debug(log); + LOGGER.debug(log); } } } @@ -403,7 +404,7 @@ public class Request { try { _cmds = s_gson.fromJson(_content, this instanceof Response ? Answer[].class : Command[].class); } catch (RuntimeException e) { - s_logger.error("Unable to deserialize from json: " + _content); + LOGGER.error("Unable to deserialize from json: " + _content); throw e; } } @@ -414,7 +415,7 @@ public class Request { for (Command cmd : _cmds) { buff.append(cmd.getClass().getSimpleName()).append("/"); } - s_logger.error("Gson serialization error " + buff.toString(), e); + LOGGER.error("Gson serialization error " + buff.toString(), e); assert false : "More gson errors on " + buff.toString(); return ""; } diff --git a/core/src/main/java/com/cloud/agent/transport/StoragePoolTypeAdaptor.java b/core/src/main/java/com/cloud/agent/transport/StoragePoolTypeAdaptor.java new file mode 100644 index 00000000000..635f6d06cf5 --- /dev/null +++ b/core/src/main/java/com/cloud/agent/transport/StoragePoolTypeAdaptor.java @@ -0,0 +1,53 @@ +// 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.transport; + +import com.cloud.storage.Storage.StoragePoolType; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +/** + * {@link StoragePoolType} acts as extendable set of singleton objects and should return same result when used "==" + * or {@link Object#equals(Object)}. + * To support that, need to return existing object for a given name instead of creating new. + */ +public class StoragePoolTypeAdaptor implements JsonDeserializer, JsonSerializer { + @Override + public StoragePoolType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + if (json instanceof JsonPrimitive && ((JsonPrimitive) json).isString()) { + return StoragePoolType.valueOf(json.getAsString()); + } + return null; + } + + @Override + public JsonElement serialize(StoragePoolType src, Type typeOfSrc, JsonSerializationContext context) { + String name = src.name(); + if (name == null) { + return new JsonNull(); + } + return new JsonPrimitive(name); + } +} diff --git a/core/src/main/java/com/cloud/network/HAProxyConfigurator.java b/core/src/main/java/com/cloud/network/HAProxyConfigurator.java index 8352895e621..9d07fc95c2f 100644 --- a/core/src/main/java/com/cloud/network/HAProxyConfigurator.java +++ b/core/src/main/java/com/cloud/network/HAProxyConfigurator.java @@ -28,7 +28,8 @@ import java.util.Map; import java.util.Set; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.routing.LoadBalancerConfigCommand; import com.cloud.agent.api.to.LoadBalancerTO; @@ -41,7 +42,7 @@ import com.cloud.utils.net.NetUtils; public class HAProxyConfigurator implements LoadBalancerConfigurator { - private static final Logger s_logger = Logger.getLogger(HAProxyConfigurator.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String blankLine = "\t "; private static String[] globalSection = {"global", "\tlog 127.0.0.1:3914 local0 warning", "\tmaxconn 4096", "\tmaxpipes 1024", "\tchroot /var/lib/haproxy", "\tuser haproxy", "\tgroup haproxy", "\tstats socket /run/haproxy/admin.sock", "\tdaemon"}; @@ -458,7 +459,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { * Not supposed to reach here, validation of methods are * done at the higher layer */ - s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() + ": Not Applied, cause:invalid method "); + logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() + ": Not Applied, cause:invalid method "); return null; } } @@ -541,7 +542,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { result.addAll(dstSubRule); } if (stickinessSubRule != null && !destsAvailable) { - s_logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() + ": Not Applied, cause: backends are unavailable"); + logger.warn("Haproxy stickiness policy for lb rule: " + lbTO.getSrcIp() + ":" + lbTO.getSrcPort() + ": Not Applied, cause: backends are unavailable"); } if (publicPort == NetUtils.HTTP_PORT && !keepAliveEnabled || httpbasedStickiness) { sb = new StringBuilder(); @@ -566,7 +567,7 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { final StringBuilder rule = new StringBuilder("\nlisten ").append(ruleName).append("\n\tbind ").append(statsIp).append(":").append(lbCmd.lbStatsPort); // TODO DH: write test for this in both cases if (!lbCmd.keepAliveEnabled) { - s_logger.info("Haproxy mode http enabled"); + logger.info("Haproxy mode http enabled"); rule.append("\n\tmode http\n\toption httpclose"); } rule.append("\n\tstats enable\n\tstats uri ") @@ -575,8 +576,8 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { .append(lbCmd.lbStatsAuth); rule.append("\n"); final String result = rule.toString(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Haproxystats rule: " + result); + if (logger.isDebugEnabled()) { + logger.debug("Haproxystats rule: " + result); } return result; } @@ -590,9 +591,9 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { // TODO DH: write test for this function final String pipesLine = "\tmaxpipes " + Long.toString(Long.parseLong(lbCmd.maxconn) / 4); gSection.set(3, pipesLine); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { for (final String s : gSection) { - s_logger.debug("global section: " + s); + logger.debug("global section: " + s); } } result.addAll(gSection); @@ -606,9 +607,9 @@ public class HAProxyConfigurator implements LoadBalancerConfigurator { dSection.set(7, "\tno option httpclose"); } - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { for (final String s : dSection) { - s_logger.debug("default section: " + s); + logger.debug("default section: " + s); } } result.addAll(dSection); diff --git a/core/src/main/java/com/cloud/network/resource/TrafficSentinelResource.java b/core/src/main/java/com/cloud/network/resource/TrafficSentinelResource.java index c6596b3c630..43fb459978a 100644 --- a/core/src/main/java/com/cloud/network/resource/TrafficSentinelResource.java +++ b/core/src/main/java/com/cloud/network/resource/TrafficSentinelResource.java @@ -35,7 +35,8 @@ import java.util.StringTokenizer; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -66,7 +67,7 @@ public class TrafficSentinelResource implements ServerResource { private String _inclZones; private String _exclZones; - private static final Logger s_logger = Logger.getLogger(TrafficSentinelResource.class); + protected Logger logger = LogManager.getLogger(getClass()); @Override public boolean configure(String name, Map params) throws ConfigurationException { @@ -242,10 +243,10 @@ public class TrafficSentinelResource implements ServerResource { } } } catch (MalformedURLException e1) { - s_logger.info("Invalid Traffic Sentinel URL", e1); + logger.info("Invalid Traffic Sentinel URL", e1); throw new ExecutionException(e1.getMessage()); } catch (IOException e) { - s_logger.debug("Error in direct network usage accounting", e); + logger.debug("Error in direct network usage accounting", e); throw new ExecutionException(e.getMessage()); } finally { if (os != null) { @@ -256,7 +257,7 @@ public class TrafficSentinelResource implements ServerResource { } } } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new ExecutionException(e.getMessage()); } return answer; diff --git a/core/src/main/java/com/cloud/resource/CommandWrapper.java b/core/src/main/java/com/cloud/resource/CommandWrapper.java index d9c1ea234e8..a839234117b 100644 --- a/core/src/main/java/com/cloud/resource/CommandWrapper.java +++ b/core/src/main/java/com/cloud/resource/CommandWrapper.java @@ -21,10 +21,11 @@ package com.cloud.resource; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public abstract class CommandWrapper { - protected Logger logger = Logger.getLogger(getClass()); + protected Logger logger = LogManager.getLogger(getClass()); /** * @param T is the command to be used. diff --git a/core/src/main/java/com/cloud/resource/RequestWrapper.java b/core/src/main/java/com/cloud/resource/RequestWrapper.java index e43cf02e13c..54d8b289c8d 100644 --- a/core/src/main/java/com/cloud/resource/RequestWrapper.java +++ b/core/src/main/java/com/cloud/resource/RequestWrapper.java @@ -23,7 +23,8 @@ import java.text.MessageFormat; import java.util.Hashtable; import java.util.Set; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -39,7 +40,7 @@ public abstract class RequestWrapper { } } - private static final Logger s_logger = Logger.getLogger(RequestWrapper.class); + protected Logger logger = LogManager.getLogger(RequestWrapper.class); @SuppressWarnings("rawtypes") protected Hashtable, Hashtable, CommandWrapper>> resources = new Hashtable, Hashtable, CommandWrapper>>(); @@ -141,9 +142,9 @@ public abstract class RequestWrapper { try { commands.put(annotation.handles(), wrapper.newInstance()); } catch (final InstantiationException e) { - s_logger.warn(MessageFormat.format(errorMessage, e.getLocalizedMessage(), wrapper.toString())); + logger.warn(MessageFormat.format(errorMessage, e.getLocalizedMessage(), wrapper.toString())); } catch (final IllegalAccessException e) { - s_logger.warn(MessageFormat.format(errorMessage, e.getLocalizedMessage(), wrapper.toString())); + logger.warn(MessageFormat.format(errorMessage, e.getLocalizedMessage(), wrapper.toString())); } } diff --git a/core/src/main/java/com/cloud/resource/ServerResourceBase.java b/core/src/main/java/com/cloud/resource/ServerResourceBase.java index 18121e21e51..bb44b307047 100644 --- a/core/src/main/java/com/cloud/resource/ServerResourceBase.java +++ b/core/src/main/java/com/cloud/resource/ServerResourceBase.java @@ -37,7 +37,8 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsAnswer; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -47,7 +48,7 @@ import com.cloud.utils.net.NetUtils; import com.cloud.utils.script.Script; public abstract class ServerResourceBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(ServerResourceBase.class); + protected Logger logger = LogManager.getLogger(getClass()); protected String name; private ArrayList warnings = new ArrayList(); private ArrayList errors = new ArrayList(); @@ -80,7 +81,7 @@ public abstract class ServerResourceBase implements ServerResource { String infos[] = NetUtils.getNetworkParams(privateNic); if (infos == null) { - s_logger.warn("Incorrect details for private Nic during initialization of ServerResourceBase"); + logger.warn("Incorrect details for private Nic during initialization of ServerResourceBase"); return false; } params.put("host.ip", infos[0]); @@ -106,7 +107,7 @@ public abstract class ServerResourceBase implements ServerResource { } protected void tryToAutoDiscoverResourcePrivateNetworkInterface() throws ConfigurationException { - s_logger.info("Trying to autodiscover this resource's private network interface."); + logger.info("Trying to autodiscover this resource's private network interface."); List nics; try { @@ -118,11 +119,11 @@ public abstract class ServerResourceBase implements ServerResource { throw new ConfigurationException(String.format("Could not retrieve the environment NICs due to [%s].", e.getMessage())); } - s_logger.debug(String.format("Searching the private NIC along the environment NICs [%s].", Arrays.toString(nics.toArray()))); + logger.debug(String.format("Searching the private NIC along the environment NICs [%s].", Arrays.toString(nics.toArray()))); for (NetworkInterface nic : nics) { if (isValidNicToUseAsPrivateNic(nic)) { - s_logger.info(String.format("Using NIC [%s] as private NIC.", nic)); + logger.info(String.format("Using NIC [%s] as private NIC.", nic)); privateNic = nic; return; } @@ -134,18 +135,18 @@ public abstract class ServerResourceBase implements ServerResource { protected boolean isValidNicToUseAsPrivateNic(NetworkInterface nic) { String nicName = nic.getName(); - s_logger.debug(String.format("Verifying if NIC [%s] can be used as private NIC.", nic)); + logger.debug(String.format("Verifying if NIC [%s] can be used as private NIC.", nic)); String[] nicNameStartsToAvoid = {"vnif", "vnbr", "peth", "vif", "virbr"}; if (nic.isVirtual() || StringUtils.startsWithAny(nicName, nicNameStartsToAvoid) || nicName.contains(":")) { - s_logger.debug(String.format("Not using NIC [%s] because it is either virtual, starts with %s, or contains \":\"" + + logger.debug(String.format("Not using NIC [%s] because it is either virtual, starts with %s, or contains \":\"" + " in its name.", Arrays.toString(nicNameStartsToAvoid), nic)); return false; } String[] info = NetUtils.getNicParams(nicName); if (info == null || info[0] == null) { - s_logger.debug(String.format("Not using NIC [%s] because it does not have a valid IP to use as the private IP.", nic)); + logger.debug(String.format("Not using NIC [%s] because it does not have a valid IP to use as the private IP.", nic)); return false; } @@ -190,8 +191,8 @@ public abstract class ServerResourceBase implements ServerResource { if (privateNic != null) { info = NetUtils.getNetworkParams(privateNic); if (info != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Parameters for private nic: " + info[0] + " - " + info[1] + "-" + info[2]); + if (logger.isDebugEnabled()) { + logger.debug("Parameters for private nic: " + info[0] + " - " + info[1] + "-" + info[2]); } cmd.setPrivateIpAddress(info[0]); cmd.setPrivateMacAddress(info[1]); @@ -200,16 +201,16 @@ public abstract class ServerResourceBase implements ServerResource { } if (storageNic != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Storage has its now nic: " + storageNic.getName()); + if (logger.isDebugEnabled()) { + logger.debug("Storage has its now nic: " + storageNic.getName()); } info = NetUtils.getNetworkParams(storageNic); } // NOTE: In case you're wondering, this is not here by mistake. if (info != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Parameters for storage nic: " + info[0] + " - " + info[1] + "-" + info[2]); + if (logger.isDebugEnabled()) { + logger.debug("Parameters for storage nic: " + info[0] + " - " + info[1] + "-" + info[2]); } cmd.setStorageIpAddress(info[0]); cmd.setStorageMacAddress(info[1]); @@ -219,8 +220,8 @@ public abstract class ServerResourceBase implements ServerResource { if (publicNic != null) { info = NetUtils.getNetworkParams(publicNic); if (info != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Parameters for public nic: " + info[0] + " - " + info[1] + "-" + info[2]); + if (logger.isDebugEnabled()) { + logger.debug("Parameters for public nic: " + info[0] + " - " + info[1] + "-" + info[2]); } cmd.setPublicIpAddress(info[0]); cmd.setPublicMacAddress(info[1]); @@ -231,8 +232,8 @@ public abstract class ServerResourceBase implements ServerResource { if (storageNic2 != null) { info = NetUtils.getNetworkParams(storageNic2); if (info != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Parameters for storage nic 2: " + info[0] + " - " + info[1] + "-" + info[2]); + if (logger.isDebugEnabled()) { + logger.debug("Parameters for storage nic 2: " + info[0] + " - " + info[1] + "-" + info[2]); } cmd.setStorageIpAddressDeux(info[0]); cmd.setStorageMacAddressDeux(info[1]); diff --git a/core/src/main/java/com/cloud/serializer/GsonHelper.java b/core/src/main/java/com/cloud/serializer/GsonHelper.java index 7ac85d39317..2d2cecf2618 100644 --- a/core/src/main/java/com/cloud/serializer/GsonHelper.java +++ b/core/src/main/java/com/cloud/serializer/GsonHelper.java @@ -21,7 +21,10 @@ package com.cloud.serializer; import java.util.List; -import org.apache.log4j.Logger; +import com.cloud.hypervisor.Hypervisor; +import org.apache.cloudstack.transport.HypervisorTypeAdaptor; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -37,10 +40,12 @@ import com.cloud.agent.transport.InterfaceTypeAdaptor; import com.cloud.agent.transport.LoggingExclusionStrategy; import com.cloud.agent.transport.Request.NwGroupsCommandTypeAdaptor; import com.cloud.agent.transport.Request.PortConfigListTypeAdaptor; +import com.cloud.agent.transport.StoragePoolTypeAdaptor; +import com.cloud.storage.Storage; import com.cloud.utils.Pair; public class GsonHelper { - private static final Logger s_logger = Logger.getLogger(GsonHelper.class); + protected static Logger LOGGER = LogManager.getLogger(GsonHelper.class); protected static final Gson s_gson; protected static final Gson s_gogger; @@ -48,11 +53,13 @@ public class GsonHelper { static { GsonBuilder gsonBuilder = new GsonBuilder(); s_gson = setDefaultGsonConfig(gsonBuilder); - GsonBuilder loggerBuilder = new GsonBuilder(); - loggerBuilder.disableHtmlEscaping(); - loggerBuilder.setExclusionStrategies(new LoggingExclusionStrategy(s_logger)); - s_gogger = setDefaultGsonConfig(loggerBuilder); - s_logger.info("Default Builder inited."); + GsonBuilder LOGGERBuilder = new GsonBuilder(); + LOGGERBuilder.disableHtmlEscaping(); + LOGGERBuilder.setExclusionStrategies(new LoggingExclusionStrategy(LOGGER)); + LOGGERBuilder.serializeSpecialFloatingPointValues(); + // maybe add LOGGERBuilder.serializeNulls(); as well? + s_gogger = setDefaultGsonConfig(LOGGERBuilder); + LOGGER.info("Default Builder inited."); } static Gson setDefaultGsonConfig(GsonBuilder builder) { @@ -69,6 +76,8 @@ public class GsonHelper { }.getType(), new PortConfigListTypeAdaptor()); builder.registerTypeAdapter(new TypeToken>() { }.getType(), new NwGroupsCommandTypeAdaptor()); + builder.registerTypeAdapter(Storage.StoragePoolType.class, new StoragePoolTypeAdaptor()); + builder.registerTypeAdapter(Hypervisor.HypervisorType.class, new HypervisorTypeAdaptor()); Gson gson = builder.create(); dsAdaptor.initGson(gson); dtAdaptor.initGson(gson); @@ -86,6 +95,6 @@ public class GsonHelper { } public final static Logger getLogger() { - return s_logger; + return LOGGER; } } diff --git a/core/src/main/java/com/cloud/storage/JavaStorageLayer.java b/core/src/main/java/com/cloud/storage/JavaStorageLayer.java index d4c2639d478..0e51ef7eb20 100644 --- a/core/src/main/java/com/cloud/storage/JavaStorageLayer.java +++ b/core/src/main/java/com/cloud/storage/JavaStorageLayer.java @@ -34,10 +34,11 @@ import java.util.Set; import java.util.UUID; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class JavaStorageLayer implements StorageLayer { - private static final Logger s_logger = Logger.getLogger(JavaStorageLayer.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String STD_TMP_DIR_PATH = "/tmp"; String _name; boolean _makeWorldWriteable = true; @@ -198,9 +199,9 @@ public class JavaStorageLayer implements StorageLayer { if (dir.exists()) { if (isWorldReadable(dir)) { if (STD_TMP_DIR_PATH.equals(dir.getAbsolutePath())) { - s_logger.warn(String.format("The temp dir is %s", STD_TMP_DIR_PATH)); + logger.warn(String.format("The temp dir is %s", STD_TMP_DIR_PATH)); } else { - s_logger.warn("The temp dir " + dir.getAbsolutePath() + " is World Readable"); + logger.warn("The temp dir " + dir.getAbsolutePath() + " is World Readable"); } } String uniqDirName = dir.getAbsolutePath() + File.separator + UUID.randomUUID().toString(); diff --git a/core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java b/core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java index 75d5f49d4c6..7d8225462ca 100644 --- a/core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java +++ b/core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java @@ -35,7 +35,6 @@ import org.apache.cloudstack.storage.command.SnapshotAndCopyCommand; import org.apache.cloudstack.storage.command.StorageSubSystemCommand; import org.apache.cloudstack.storage.command.SyncVolumePathCommand; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -47,9 +46,11 @@ import com.cloud.serializer.GsonHelper; import com.cloud.storage.DataStoreRole; import com.cloud.storage.Volume; import com.google.gson.Gson; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class StorageSubsystemCommandHandlerBase implements StorageSubsystemCommandHandler { - private static final Logger s_logger = Logger.getLogger(StorageSubsystemCommandHandlerBase.class); + protected Logger logger = LogManager.getLogger(getClass()); protected static final Gson s_gogger = GsonHelper.getGsonLogger(); protected StorageProcessor processor; @@ -141,7 +142,7 @@ public class StorageSubsystemCommandHandlerBase implements StorageSubsystemComma } return new CreateObjectAnswer("not supported type"); } catch (Exception e) { - s_logger.debug("Failed to create object: " + data.getObjectType() + ": " + e.toString()); + logger.debug("Failed to create object: " + data.getObjectType() + ": " + e.toString()); return new CreateObjectAnswer(e.toString()); } } @@ -184,9 +185,9 @@ public class StorageSubsystemCommandHandlerBase implements StorageSubsystemComma private void logCommand(Command cmd) { try { - s_logger.debug(String.format("Executing command %s: [%s].", cmd.getClass().getSimpleName(), s_gogger.toJson(cmd))); + logger.debug(String.format("Executing command %s: [%s].", cmd.getClass().getSimpleName(), s_gogger.toJson(cmd))); } catch (Exception e) { - s_logger.debug(String.format("Executing command %s.", cmd.getClass().getSimpleName())); + logger.debug(String.format("Executing command %s.", cmd.getClass().getSimpleName())); } } } diff --git a/core/src/main/java/com/cloud/storage/template/FtpTemplateUploader.java b/core/src/main/java/com/cloud/storage/template/FtpTemplateUploader.java index eb0c4f84601..14bf6fe1b74 100644 --- a/core/src/main/java/com/cloud/storage/template/FtpTemplateUploader.java +++ b/core/src/main/java/com/cloud/storage/template/FtpTemplateUploader.java @@ -29,11 +29,12 @@ import java.net.URL; import java.net.URLConnection; import java.util.Date; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class FtpTemplateUploader implements TemplateUploader { - public static final Logger s_logger = Logger.getLogger(FtpTemplateUploader.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); public TemplateUploader.Status status = TemplateUploader.Status.NOT_STARTED; public String errorString = ""; public long totalBytes = 0; @@ -110,11 +111,11 @@ public class FtpTemplateUploader implements TemplateUploader { } catch (MalformedURLException e) { status = TemplateUploader.Status.UNRECOVERABLE_ERROR; errorString = e.getMessage(); - s_logger.error(errorString); + logger.error(errorString); } catch (IOException e) { status = TemplateUploader.Status.UNRECOVERABLE_ERROR; errorString = e.getMessage(); - s_logger.error(errorString); + logger.error(errorString); } finally { try { if (inputStream != null) { @@ -124,7 +125,7 @@ public class FtpTemplateUploader implements TemplateUploader { outputStream.close(); } } catch (IOException ioe) { - s_logger.error(" Caught exception while closing the resources"); + logger.error(" Caught exception while closing the resources"); } if (callback != null) { callback.uploadComplete(status); @@ -139,7 +140,7 @@ public class FtpTemplateUploader implements TemplateUploader { try { upload(completionCallback); } catch (Throwable t) { - s_logger.warn("Caught exception during upload " + t.getMessage(), t); + logger.warn("Caught exception during upload " + t.getMessage(), t); errorString = "Failed to install: " + t.getMessage(); status = TemplateUploader.Status.UNRECOVERABLE_ERROR; } @@ -207,7 +208,7 @@ public class FtpTemplateUploader implements TemplateUploader { inputStream.close(); } } catch (IOException e) { - s_logger.error(" Caught exception while closing the resources"); + logger.error(" Caught exception while closing the resources"); } status = TemplateUploader.Status.ABORTED; return true; diff --git a/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java index d55c387d820..9b126846827 100755 --- a/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/HttpTemplateDownloader.java @@ -28,6 +28,7 @@ import java.io.RandomAccessFile; import java.net.URI; import java.net.URISyntaxException; import java.util.Date; +import java.util.List; import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType; @@ -45,7 +46,6 @@ import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; -import org.apache.log4j.Logger; import com.cloud.storage.StorageLayer; import com.cloud.utils.Pair; @@ -58,7 +58,6 @@ import com.cloud.utils.net.Proxy; * */ public class HttpTemplateDownloader extends ManagedContextRunnable implements TemplateDownloader { - public static final Logger s_logger = Logger.getLogger(HttpTemplateDownloader.class.getName()); private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); private static final int CHUNK_SIZE = 1024 * 1024; //1M @@ -80,6 +79,7 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te private long maxTemplateSizeInBytes; private ResourceType resourceType = ResourceType.TEMPLATE; private final HttpMethodRetryHandler myretryhandler; + private boolean followRedirects = false; public HttpTemplateDownloader(StorageLayer storageLayer, String downloadUrl, String toDir, DownloadCompleteCallback callback, long maxTemplateSizeInBytes, String user, String password, Proxy proxy, ResourceType resourceType) { @@ -102,16 +102,16 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te } catch (Exception ex) { errorString = "Unable to start download -- check url? "; status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; - s_logger.warn("Exception in constructor -- " + ex.toString()); + logger.warn("Exception in constructor -- " + ex.toString()); } catch (Throwable th) { - s_logger.warn("throwable caught ", th); + logger.warn("throwable caught ", th); } } private GetMethod createRequest(String downloadUrl) { GetMethod request = new GetMethod(downloadUrl); request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler); - request.setFollowRedirects(true); + request.setFollowRedirects(followRedirects); return request; } @@ -127,7 +127,7 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te } catch (IOException ex) { errorString = "Unable to start download -- check url? "; status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; - s_logger.warn("Exception in constructor -- " + ex.toString()); + logger.warn("Exception in constructor -- " + ex.toString()); } } @@ -138,9 +138,9 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te client.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(user, password); client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds); - s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); + logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second()); } else { - s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second()); + logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second()); } } catch (IllegalArgumentException iae) { errorString = iae.getMessage(); @@ -206,7 +206,7 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te ) { out.seek(localFileSize); - s_logger.info("Starting download from " + downloadUrl + " to " + toFile + " remoteSize=" + toHumanReadableSize(remoteSize) + " , max size=" + toHumanReadableSize(maxTemplateSizeInBytes)); + logger.info("Starting download from " + downloadUrl + " to " + toFile + " remoteSize=" + toHumanReadableSize(remoteSize) + " , max size=" + toHumanReadableSize(maxTemplateSizeInBytes)); if (copyBytes(file, in, out)) return 0; @@ -278,7 +278,7 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te private boolean canHandleDownloadSize() { if (remoteSize > maxTemplateSizeInBytes) { - s_logger.info("Remote size is too large: " + toHumanReadableSize(remoteSize) + " , max=" + toHumanReadableSize(maxTemplateSizeInBytes)); + logger.info("Remote size is too large: " + toHumanReadableSize(remoteSize) + " , max=" + toHumanReadableSize(maxTemplateSizeInBytes)); status = Status.UNRECOVERABLE_ERROR; errorString = "Download file size is too large"; return false; @@ -337,6 +337,12 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te } else if ((responseCode = client.executeMethod(request)) != HttpStatus.SC_OK) { status = Status.UNRECOVERABLE_ERROR; errorString = " HTTP Server returned " + responseCode + " (expected 200 OK) "; + if (List.of(HttpStatus.SC_MOVED_PERMANENTLY, HttpStatus.SC_MOVED_TEMPORARILY).contains(responseCode) + && !followRedirects) { + errorString = String.format("Failed to download %s due to redirection, response code: %d", + downloadUrl, responseCode); + logger.error(errorString); + } return true; //FIXME: retry? } return false; @@ -347,7 +353,7 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te long localFileSize = 0; if (file.exists() && resume) { localFileSize = file.length(); - s_logger.info("Resuming download to file (current size)=" + toHumanReadableSize(localFileSize)); + logger.info("Resuming download to file (current size)=" + toHumanReadableSize(localFileSize)); } return localFileSize; } @@ -431,7 +437,7 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te try { download(resume, completionCallback); } catch (Throwable t) { - s_logger.warn("Caught exception during download " + t.getMessage(), t); + logger.warn("Caught exception during download " + t.getMessage(), t); errorString = "Failed to install: " + t.getMessage(); status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; } @@ -519,23 +525,31 @@ public class HttpTemplateDownloader extends ManagedContextRunnable implements Te URI str = new URI(downloadUrl); uripath = str.getPath(); } catch (URISyntaxException e) { - s_logger.warn("Invalid download url: " + downloadUrl + ", This should not happen since we have validated the url before!!"); + logger.warn("Invalid download url: " + downloadUrl + ", This should not happen since we have validated the url before!!"); } String unsupportedFormat = ImageStoreUtil.checkTemplateFormat(file.getAbsolutePath(), uripath); if (unsupportedFormat == null || !unsupportedFormat.isEmpty()) { try { request.abort(); } catch (Exception ex) { - s_logger.debug("Error on http connection : " + ex.getMessage()); + logger.debug("Error on http connection : " + ex.getMessage()); } status = Status.UNRECOVERABLE_ERROR; errorString = "Template content is unsupported, or mismatch between selected format and template content. Found : " + unsupportedFormat; throw new CloudRuntimeException(errorString); } else { - s_logger.debug("Verified format of downloading file " + file.getAbsolutePath() + " is supported"); + logger.debug("Verified format of downloading file " + file.getAbsolutePath() + " is supported"); verifiedFormat = true; } return this; } } + + @Override + public void setFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + if (this.request != null) { + this.request.setFollowRedirects(followRedirects); + } + } } diff --git a/core/src/main/java/com/cloud/storage/template/IsoProcessor.java b/core/src/main/java/com/cloud/storage/template/IsoProcessor.java index 4cd2f1a2a02..6ab42effb52 100644 --- a/core/src/main/java/com/cloud/storage/template/IsoProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/IsoProcessor.java @@ -24,14 +24,12 @@ import java.util.Map; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageLayer; import com.cloud.utils.component.AdapterBase; public class IsoProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(IsoProcessor.class); StorageLayer _storage; @@ -43,14 +41,14 @@ public class IsoProcessor extends AdapterBase implements Processor { @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) { if (format != null) { - s_logger.debug("We don't handle conversion from " + format + " to ISO."); + logger.debug("We don't handle conversion from " + format + " to ISO."); return null; } String isoPath = templatePath + File.separator + templateName + "." + ImageFormat.ISO.getFileExtension(); if (!_storage.exists(isoPath)) { - s_logger.debug("Unable to find the iso file: " + isoPath); + logger.debug("Unable to find the iso file: " + isoPath); return null; } diff --git a/core/src/main/java/com/cloud/storage/template/LocalTemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/LocalTemplateDownloader.java index 564eba3d5ee..e4044412c52 100644 --- a/core/src/main/java/com/cloud/storage/template/LocalTemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/LocalTemplateDownloader.java @@ -29,12 +29,10 @@ import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import org.apache.log4j.Logger; import com.cloud.storage.StorageLayer; public class LocalTemplateDownloader extends TemplateDownloaderBase implements TemplateDownloader { - public static final Logger s_logger = Logger.getLogger(LocalTemplateDownloader.class); public LocalTemplateDownloader(StorageLayer storageLayer, String downloadUrl, String toDir, long maxTemplateSizeInBytes, DownloadCompleteCallback callback) { super(storageLayer, downloadUrl, toDir, maxTemplateSizeInBytes, callback); @@ -55,7 +53,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T try { src = new File(new URI(_downloadUrl)); } catch (URISyntaxException e1) { - s_logger.warn("Invalid URI " + _downloadUrl); + logger.warn("Invalid URI " + _downloadUrl); _status = Status.UNRECOVERABLE_ERROR; return 0; } @@ -77,7 +75,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T try { fis = new FileInputStream(src); } catch (FileNotFoundException e) { - s_logger.warn("Unable to find " + _downloadUrl); + logger.warn("Unable to find " + _downloadUrl); _errorString = "Unable to find " + _downloadUrl; return -1; } @@ -85,7 +83,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T try { fos = new FileOutputStream(dst); } catch (FileNotFoundException e) { - s_logger.warn("Unable to find " + _toFile); + logger.warn("Unable to find " + _toFile); return -1; } foc = fos.getChannel(); @@ -102,7 +100,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T buffer.clear(); } } catch (IOException e) { - s_logger.warn("Unable to download", e); + logger.warn("Unable to download", e); } String downloaded = "(incomplete download)"; @@ -123,7 +121,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T try { fic.close(); } catch (IOException e) { - s_logger.info("[ignore] error while closing file input channel."); + logger.info("[ignore] error while closing file input channel."); } } @@ -131,7 +129,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T try { foc.close(); } catch (IOException e) { - s_logger.info("[ignore] error while closing file output channel."); + logger.info("[ignore] error while closing file output channel."); } } @@ -139,7 +137,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T try { fis.close(); } catch (IOException e) { - s_logger.info("[ignore] error while closing file input stream."); + logger.info("[ignore] error while closing file input stream."); } } @@ -147,7 +145,7 @@ public class LocalTemplateDownloader extends TemplateDownloaderBase implements T try { fos.close(); } catch (IOException e) { - s_logger.info("[ignore] error while closing file output stream."); + logger.info("[ignore] error while closing file output stream."); } } diff --git a/core/src/main/java/com/cloud/storage/template/MetalinkTemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/MetalinkTemplateDownloader.java index dd452f2e2d9..2e62809dfed 100644 --- a/core/src/main/java/com/cloud/storage/template/MetalinkTemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/MetalinkTemplateDownloader.java @@ -28,7 +28,6 @@ import org.apache.commons.httpclient.NoHttpResponseException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; import org.springframework.util.CollectionUtils; import java.io.File; @@ -47,7 +46,6 @@ public class MetalinkTemplateDownloader extends TemplateDownloaderBase implement protected GetMethod request; private boolean toFileSet = false; - private static final Logger LOGGER = Logger.getLogger(MetalinkTemplateDownloader.class.getName()); public MetalinkTemplateDownloader(StorageLayer storageLayer, String downloadUrl, String toDir, DownloadCompleteCallback callback, long maxTemplateSize) { super(storageLayer, downloadUrl, toDir, maxTemplateSize, callback); @@ -60,7 +58,7 @@ public class MetalinkTemplateDownloader extends TemplateDownloaderBase implement protected GetMethod createRequest(String downloadUrl) { GetMethod request = new GetMethod(downloadUrl); request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, myretryhandler); - request.setFollowRedirects(true); + request.setFollowRedirects(followRedirects); if (!toFileSet) { String[] parts = downloadUrl.split("/"); String filename = parts[parts.length - 1]; @@ -97,7 +95,7 @@ public class MetalinkTemplateDownloader extends TemplateDownloaderBase implement try { client.executeMethod(request); } catch (IOException e) { - LOGGER.error("Error on HTTP request: " + e.getMessage()); + logger.error("Error on HTTP request: " + e.getMessage()); return false; } return performDownload(); @@ -110,7 +108,7 @@ public class MetalinkTemplateDownloader extends TemplateDownloaderBase implement ) { IOUtils.copy(in, out); } catch (IOException e) { - LOGGER.error("Error downloading template from: " + _downloadUrl + " due to: " + e.getMessage()); + logger.error("Error downloading template from: " + _downloadUrl + " due to: " + e.getMessage()); return false; } return true; @@ -121,13 +119,13 @@ public class MetalinkTemplateDownloader extends TemplateDownloaderBase implement return 0; } - LOGGER.info("Starting metalink download from: " + _downloadUrl); + logger.info("Starting metalink download from: " + _downloadUrl); _start = System.currentTimeMillis(); status = Status.IN_PROGRESS; List metalinkUrls = UriUtils.getMetalinkUrls(_downloadUrl); if (CollectionUtils.isEmpty(metalinkUrls)) { - LOGGER.error("No URLs found for metalink: " + _downloadUrl); + logger.error("No URLs found for metalink: " + _downloadUrl); status = Status.UNRECOVERABLE_ERROR; return 0; } @@ -140,11 +138,11 @@ public class MetalinkTemplateDownloader extends TemplateDownloaderBase implement i++; } if (!downloaded) { - LOGGER.error("Template couldn't be downloaded"); + logger.error("Template couldn't be downloaded"); status = Status.UNRECOVERABLE_ERROR; return 0; } - LOGGER.info("Template downloaded successfully on: " + _toFile); + logger.info("Template downloaded successfully on: " + _toFile); status = Status.DOWNLOAD_FINISHED; _downloadTime = System.currentTimeMillis() - _start; if (_callback != null) { @@ -173,4 +171,12 @@ public class MetalinkTemplateDownloader extends TemplateDownloaderBase implement public void setStatus(Status status) { this.status = status; } + + @Override + public void setFollowRedirects(boolean followRedirects) { + super.setFollowRedirects(followRedirects); + if (this.request != null) { + this.request.setFollowRedirects(followRedirects); + } + } } diff --git a/core/src/main/java/com/cloud/storage/template/OVAProcessor.java b/core/src/main/java/com/cloud/storage/template/OVAProcessor.java index 33f7e28ac03..ab3aa0d0e3a 100644 --- a/core/src/main/java/com/cloud/storage/template/OVAProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/OVAProcessor.java @@ -34,7 +34,6 @@ import com.cloud.agent.api.to.deployasis.OVFVirtualHardwareSectionTO; import com.cloud.agent.api.to.deployasis.OVFNetworkTO; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -52,7 +51,6 @@ import com.cloud.utils.script.Script; * processes the content of an OVA for registration of a template */ public class OVAProcessor extends AdapterBase implements Processor { - private static final Logger LOGGER = Logger.getLogger(OVAProcessor.class); StorageLayer _storage; @Override @@ -66,11 +64,11 @@ public class OVAProcessor extends AdapterBase implements Processor { return null; } - LOGGER.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); + logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); String templateFilePath = templatePath + File.separator + templateName + "." + ImageFormat.OVA.getFileExtension(); if (!_storage.exists(templateFilePath)) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info("Unable to find the vmware template file: " + templateFilePath); + if (logger.isInfoEnabled()) { + logger.info("Unable to find the vmware template file: " + templateFilePath); } return null; } @@ -114,46 +112,46 @@ public class OVAProcessor extends AdapterBase implements Processor { List disks = ovfHelper.getOVFVolumeInfoFromFile(ovfFilePath, doc, null); if (CollectionUtils.isNotEmpty(disks)) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Found %d disks in template %s", disks.size(), ovfFilePath)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Found %d disks in template %s", disks.size(), ovfFilePath)); } ovfInformationTO.setDisks(disks); } List nets = ovfHelper.getNetPrerequisitesFromDocument(doc); if (CollectionUtils.isNotEmpty(nets)) { - LOGGER.info("Found " + nets.size() + " prerequisite networks"); + logger.info("Found " + nets.size() + " prerequisite networks"); ovfInformationTO.setNetworks(nets); - } else if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("no net prerequisites found in template %s", ovfFilePath)); + } else if (logger.isTraceEnabled()) { + logger.trace(String.format("no net prerequisites found in template %s", ovfFilePath)); } List ovfProperties = ovfHelper.getConfigurableOVFPropertiesFromDocument(doc); if (CollectionUtils.isNotEmpty(ovfProperties)) { - LOGGER.info("Found " + ovfProperties.size() + " configurable OVF properties"); + logger.info("Found " + ovfProperties.size() + " configurable OVF properties"); ovfInformationTO.setProperties(ovfProperties); - } else if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("no ovf properties found in template %s", ovfFilePath)); + } else if (logger.isTraceEnabled()) { + logger.trace(String.format("no ovf properties found in template %s", ovfFilePath)); } OVFVirtualHardwareSectionTO hardwareSection = ovfHelper.getVirtualHardwareSectionFromDocument(doc); List configurations = hardwareSection.getConfigurations(); if (CollectionUtils.isNotEmpty(configurations)) { - LOGGER.info("Found " + configurations.size() + " deployment option configurations"); + logger.info("Found " + configurations.size() + " deployment option configurations"); } List hardwareItems = hardwareSection.getCommonHardwareItems(); if (CollectionUtils.isNotEmpty(hardwareItems)) { - LOGGER.info("Found " + hardwareItems.size() + " virtual hardware items"); + logger.info("Found " + hardwareItems.size() + " virtual hardware items"); } if (StringUtils.isNotBlank(hardwareSection.getMinimiumHardwareVersion())) { - LOGGER.info("Found minimum hardware version " + hardwareSection.getMinimiumHardwareVersion()); + logger.info("Found minimum hardware version " + hardwareSection.getMinimiumHardwareVersion()); } ovfInformationTO.setHardwareSection(hardwareSection); List eulaSections = ovfHelper.getEulaSectionsFromDocument(doc); if (CollectionUtils.isNotEmpty(eulaSections)) { - LOGGER.info("Found " + eulaSections.size() + " license agreements"); + logger.info("Found " + eulaSections.size() + " license agreements"); ovfInformationTO.setEulaSections(eulaSections); } Pair guestOsPair = ovfHelper.getOperatingSystemInfoFromDocument(doc); if (guestOsPair != null) { - LOGGER.info("Found guest OS information: " + guestOsPair.first() + " - " + guestOsPair.second()); + logger.info("Found guest OS information: " + guestOsPair.first() + " - " + guestOsPair.second()); ovfInformationTO.setGuestOsInfo(guestOsPair); } return ovfInformationTO; @@ -163,33 +161,33 @@ public class OVAProcessor extends AdapterBase implements Processor { Script command; String result; - command = new Script("chmod", 0, LOGGER); + command = new Script("chmod", 0, logger); command.add("-R"); command.add("666", templatePath); result = command.execute(); if (result != null) { - LOGGER.warn("Unable to set permissions for files in " + templatePath + " due to " + result); + logger.warn("Unable to set permissions for files in " + templatePath + " due to " + result); } - command = new Script("chmod", 0, LOGGER); + command = new Script("chmod", 0, logger); command.add("777", templatePath); result = command.execute(); if (result != null) { - LOGGER.warn("Unable to set permissions for " + templatePath + " due to " + result); + logger.warn("Unable to set permissions for " + templatePath + " due to " + result); } } private String unpackOva(String templatePath, String templateName, long processTimeout) throws InternalErrorException { - LOGGER.info("Template processing - untar OVA package. templatePath: " + templatePath + ", templateName: " + templateName); + logger.info("Template processing - untar OVA package. templatePath: " + templatePath + ", templateName: " + templateName); String templateFileFullPath = templatePath + File.separator + templateName + "." + ImageFormat.OVA.getFileExtension(); File templateFile = new File(templateFileFullPath); - Script command = new Script("tar", processTimeout, LOGGER); + Script command = new Script("tar", processTimeout, logger); command.add("--no-same-owner"); command.add("--no-same-permissions"); command.add("-xf", templateFileFullPath); command.setWorkDir(templateFile.getParent()); String result = command.execute(); if (result != null) { - LOGGER.info("failed to untar OVA package due to " + result + ". templatePath: " + templatePath + ", templateName: " + templateName); + logger.info("failed to untar OVA package due to " + result + ". templatePath: " + templatePath + ", templateName: " + templateName); throw new InternalErrorException("failed to untar OVA package"); } return templateFileFullPath; @@ -197,13 +195,13 @@ public class OVAProcessor extends AdapterBase implements Processor { private boolean conversionChecks(ImageFormat format) { if (format != null) { - if (LOGGER.isInfoEnabled()) { - LOGGER.info("We currently don't handle conversion from " + format + " to OVA."); + if (logger.isInfoEnabled()) { + logger.info("We currently don't handle conversion from " + format + " to OVA."); } return false; } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("We are handling format " + format + "."); + if (logger.isTraceEnabled()) { + logger.trace("We are handling format " + format + "."); } return true; } @@ -214,7 +212,7 @@ public class OVAProcessor extends AdapterBase implements Processor { long size = getTemplateVirtualSize(file.getParent(), file.getName()); return size; } catch (Exception e) { - LOGGER.info("[ignored]" + logger.info("[ignored]" + "failed to get virtual template size for ova: " + e.getLocalizedMessage()); } return file.length(); @@ -234,7 +232,7 @@ public class OVAProcessor extends AdapterBase implements Processor { OVFHelper ovfHelper = new OVFHelper(); if (ovfFileName == null) { String msg = "Unable to locate OVF file in template package directory: " + templatePath; - LOGGER.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } try { @@ -248,7 +246,7 @@ public class OVAProcessor extends AdapterBase implements Processor { diskSize = Long.parseLong(diskSizeValue); } catch (NumberFormatException e) { // ASSUMEably the diskSize contains a property for replacement - LOGGER.warn(String.format("the disksize for disk %s is not a valid number: %s", disk.getAttribute("diskId"), diskSizeValue)); + logger.warn(String.format("the disksize for disk %s is not a valid number: %s", disk.getAttribute("diskId"), diskSizeValue)); // TODO parse the property to get any value can not be done at registration time // and will have to be done at deploytime, so for orchestration purposes // we now assume, a value of one @@ -260,7 +258,7 @@ public class OVAProcessor extends AdapterBase implements Processor { return virtualSize; } catch (InternalErrorException | NumberFormatException e) { String msg = "getTemplateVirtualSize: Unable to parse OVF XML document " + templatePath + " to get the virtual disk " + templateName + " size due to " + e; - LOGGER.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } } diff --git a/core/src/main/java/com/cloud/storage/template/QCOW2Processor.java b/core/src/main/java/com/cloud/storage/template/QCOW2Processor.java index 56ae078dc51..df1722a0201 100644 --- a/core/src/main/java/com/cloud/storage/template/QCOW2Processor.java +++ b/core/src/main/java/com/cloud/storage/template/QCOW2Processor.java @@ -27,7 +27,6 @@ import java.util.Map; import javax.naming.ConfigurationException; import com.cloud.exception.InternalErrorException; -import org.apache.log4j.Logger; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageLayer; @@ -35,7 +34,6 @@ import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.AdapterBase; public class QCOW2Processor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(QCOW2Processor.class); private static final int VIRTUALSIZE_HEADER_LOCATION = 24; private StorageLayer _storage; @@ -48,14 +46,14 @@ public class QCOW2Processor extends AdapterBase implements Processor { @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) throws InternalErrorException { if (format != null) { - s_logger.debug("We currently don't handle conversion from " + format + " to QCOW2."); + logger.debug("We currently don't handle conversion from " + format + " to QCOW2."); return null; } String qcow2Path = templatePath + File.separator + templateName + "." + ImageFormat.QCOW2.getFileExtension(); if (!_storage.exists(qcow2Path)) { - s_logger.debug("Unable to find the qcow2 file: " + qcow2Path); + logger.debug("Unable to find the qcow2 file: " + qcow2Path); return null; } @@ -70,7 +68,7 @@ public class QCOW2Processor extends AdapterBase implements Processor { try { info.virtualSize = getTemplateVirtualSize(qcow2File); } catch (IOException e) { - s_logger.error("Unable to get virtual size from " + qcow2File.getName()); + logger.error("Unable to get virtual size from " + qcow2File.getName()); throw new InternalErrorException("unable to get virtual size from qcow2 file"); } @@ -83,7 +81,7 @@ public class QCOW2Processor extends AdapterBase implements Processor { long size = getTemplateVirtualSize(file); return size; } catch (Exception e) { - s_logger.info("[ignored]" + "failed to get template virtual size for QCOW2: " + e.getLocalizedMessage()); + logger.info("[ignored]" + "failed to get template virtual size for QCOW2: " + e.getLocalizedMessage()); } return file.length(); } diff --git a/core/src/main/java/com/cloud/storage/template/RawImageProcessor.java b/core/src/main/java/com/cloud/storage/template/RawImageProcessor.java index 5fbc626f271..d6c1f7a808f 100644 --- a/core/src/main/java/com/cloud/storage/template/RawImageProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/RawImageProcessor.java @@ -24,7 +24,6 @@ import java.util.Map; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.exception.InternalErrorException; import com.cloud.storage.Storage.ImageFormat; @@ -32,7 +31,6 @@ import com.cloud.storage.StorageLayer; import com.cloud.utils.component.AdapterBase; public class RawImageProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(RawImageProcessor.class); StorageLayer _storage; @Override @@ -53,13 +51,13 @@ public class RawImageProcessor extends AdapterBase implements Processor { @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) throws InternalErrorException { if (format != null) { - s_logger.debug("We currently don't handle conversion from " + format + " to raw image."); + logger.debug("We currently don't handle conversion from " + format + " to raw image."); return null; } String imgPath = templatePath + File.separator + templateName + "." + ImageFormat.RAW.getFileExtension(); if (!_storage.exists(imgPath)) { - s_logger.debug("Unable to find raw image:" + imgPath); + logger.debug("Unable to find raw image:" + imgPath); return null; } FormatInfo info = new FormatInfo(); @@ -67,7 +65,7 @@ public class RawImageProcessor extends AdapterBase implements Processor { info.filename = templateName + "." + ImageFormat.RAW.getFileExtension(); info.size = _storage.getSize(imgPath); info.virtualSize = info.size; - s_logger.debug("Process raw image " + info.filename + " successfully"); + logger.debug("Process raw image " + info.filename + " successfully"); return info; } diff --git a/core/src/main/java/com/cloud/storage/template/S3TemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/S3TemplateDownloader.java index 44565c4416c..c24a4cc221f 100644 --- a/core/src/main/java/com/cloud/storage/template/S3TemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/S3TemplateDownloader.java @@ -34,16 +34,17 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Date; +import java.util.List; import static com.cloud.utils.NumbersUtil.toHumanReadableSize; import static java.util.Arrays.asList; @@ -56,7 +57,6 @@ import static java.util.Arrays.asList; * Execution of the instance is started when runInContext() is called. */ public class S3TemplateDownloader extends ManagedContextRunnable implements TemplateDownloader { - private static final Logger LOGGER = Logger.getLogger(S3TemplateDownloader.class.getName()); private final String downloadUrl; private final String s3Key; @@ -72,8 +72,8 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp private long downloadTime; private long totalBytes; private long maxTemplateSizeInByte; - private boolean resume = false; + private boolean followRedirects = false; public S3TemplateDownloader(S3TO s3TO, String downloadUrl, String installPath, DownloadCompleteCallback downloadCompleteCallback, long maxTemplateSizeInBytes, String username, String password, Proxy proxy, ResourceType resourceType) { @@ -91,7 +91,7 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp this.getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, HTTPUtils.getHttpMethodRetryHandler(5)); // Follow redirects - this.getMethod.setFollowRedirects(true); + this.getMethod.setFollowRedirects(followRedirects); // Set file extension. this.fileExtension = StringUtils.substringAfterLast(StringUtils.substringAfterLast(downloadUrl, "/"), "."); @@ -110,7 +110,7 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp public long download(boolean resume, DownloadCompleteCallback callback) { if (!status.equals(Status.NOT_STARTED)) { // Only start downloading if we haven't started yet. - LOGGER.debug("Template download is already started, not starting again. Template: " + downloadUrl); + logger.debug("Template download is already started, not starting again. Template: " + downloadUrl); return 0; } @@ -118,16 +118,17 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp int responseCode; if ((responseCode = HTTPUtils.executeMethod(httpClient, getMethod)) == -1) { errorString = "Exception while executing HttpMethod " + getMethod.getName() + " on URL " + downloadUrl; - LOGGER.warn(errorString); + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; } - if (!HTTPUtils.verifyResponseCode(responseCode)) { + boolean failedDueToRedirection = List.of(HttpStatus.SC_MOVED_PERMANENTLY, + HttpStatus.SC_MOVED_TEMPORARILY).contains(responseCode) && !followRedirects; + if (!HTTPUtils.verifyResponseCode(responseCode) || failedDueToRedirection) { errorString = "Response code for GetMethod of " + downloadUrl + " is incorrect, responseCode: " + responseCode; - LOGGER.warn(errorString); - + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; } @@ -139,7 +140,7 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp // Check the contentLengthHeader and transferEncodingHeader. if (contentLengthHeader == null) { errorString = "The ContentLengthHeader of " + downloadUrl + " isn't supplied"; - LOGGER.warn(errorString); + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; @@ -150,7 +151,7 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp if (remoteSize > maxTemplateSizeInByte) { errorString = "Remote size is too large for template " + downloadUrl + " remote size is " + remoteSize + " max allowed is " + maxTemplateSizeInByte; - LOGGER.warn(errorString); + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; @@ -162,13 +163,13 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp inputStream = new BufferedInputStream(getMethod.getResponseBodyAsStream()); } catch (IOException e) { errorString = "Exception occurred while opening InputStream for template " + downloadUrl; - LOGGER.warn(errorString); + logger.warn(errorString); status = Status.UNRECOVERABLE_ERROR; return 0; } - LOGGER.info("Starting download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " and size " + toHumanReadableSize(remoteSize) + " bytes"); + logger.info("Starting download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " and size " + toHumanReadableSize(remoteSize) + " bytes"); // Time the upload starts. final Date start = new Date(); @@ -197,7 +198,7 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp // Record the amount of bytes transferred. totalBytes += progressEvent.getBytesTransferred(); - LOGGER.trace("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + ((new Date().getTime() - start.getTime()) / 1000) + " seconds"); + logger.trace("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + ((new Date().getTime() - start.getTime()) / 1000) + " seconds"); if (progressEvent.getEventType() == ProgressEventType.TRANSFER_STARTED_EVENT) { status = Status.IN_PROGRESS; @@ -216,15 +217,15 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp upload.waitForCompletion(); } catch (InterruptedException e) { // Interruption while waiting for the upload to complete. - LOGGER.warn("Interruption occurred while waiting for upload of " + downloadUrl + " to complete"); + logger.warn("Interruption occurred while waiting for upload of " + downloadUrl + " to complete"); } downloadTime = new Date().getTime() - start.getTime(); if (status == Status.DOWNLOAD_FINISHED) { - LOGGER.info("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed successfully!"); + logger.info("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed successfully!"); } else { - LOGGER.warn("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed with status " + status.toString()); + logger.warn("Template download from " + downloadUrl + " to S3 bucket " + s3TO.getBucketName() + " transferred " + toHumanReadableSize(totalBytes) + " in " + (downloadTime / 1000) + " seconds, completed with status " + status.toString()); } // Close input stream @@ -278,7 +279,7 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp } public void cleanupAfterError() { - LOGGER.warn("Cleanup after error, trying to remove object: " + s3Key); + logger.warn("Cleanup after error, trying to remove object: " + s3Key); S3Utils.deleteObject(s3TO, s3TO.getBucketName(), s3Key); } @@ -373,4 +374,12 @@ public class S3TemplateDownloader extends ManagedContextRunnable implements Temp public String getFileExtension() { return fileExtension; } + + @Override + public void setFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + if (this.getMethod != null) { + this.getMethod.setFollowRedirects(followRedirects); + } + } } diff --git a/core/src/main/java/com/cloud/storage/template/ScpTemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/ScpTemplateDownloader.java index 912809ca722..44379efcd55 100644 --- a/core/src/main/java/com/cloud/storage/template/ScpTemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/ScpTemplateDownloader.java @@ -23,7 +23,6 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -31,7 +30,6 @@ import com.cloud.storage.StorageLayer; import com.cloud.utils.exception.CloudRuntimeException; public class ScpTemplateDownloader extends TemplateDownloaderBase implements TemplateDownloader { - private static final Logger s_logger = Logger.getLogger(ScpTemplateDownloader.class); public ScpTemplateDownloader(StorageLayer storageLayer, String downloadUrl, String toDir, long maxTemplateSizeInBytes, DownloadCompleteCallback callback) { super(storageLayer, downloadUrl, toDir, maxTemplateSizeInBytes, callback); @@ -40,7 +38,7 @@ public class ScpTemplateDownloader extends TemplateDownloaderBase implements Tem try { uri = new URI(_downloadUrl); } catch (URISyntaxException e) { - s_logger.warn("URI syntax error: " + _downloadUrl); + logger.warn("URI syntax error: " + _downloadUrl); _status = Status.UNRECOVERABLE_ERROR; return; } @@ -108,7 +106,7 @@ public class ScpTemplateDownloader extends TemplateDownloaderBase implements Tem if (!file.exists()) { _status = Status.UNRECOVERABLE_ERROR; - s_logger.debug("unable to scp the file " + _downloadUrl); + logger.debug("unable to scp the file " + _downloadUrl); return 0; } @@ -123,7 +121,7 @@ public class ScpTemplateDownloader extends TemplateDownloaderBase implements Tem return _totalBytes; } catch (Exception e) { - s_logger.warn("Unable to download " + _downloadUrl, e); + logger.warn("Unable to download " + _downloadUrl, e); _status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; _errorString = e.getMessage(); return 0; diff --git a/core/src/main/java/com/cloud/storage/template/SimpleHttpMultiFileDownloader.java b/core/src/main/java/com/cloud/storage/template/SimpleHttpMultiFileDownloader.java index 7a0ce47ec99..8719947cb4f 100644 --- a/core/src/main/java/com/cloud/storage/template/SimpleHttpMultiFileDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/SimpleHttpMultiFileDownloader.java @@ -25,6 +25,7 @@ import java.io.InputStream; import java.io.RandomAccessFile; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.cloudstack.managed.context.ManagedContextRunnable; @@ -41,12 +42,10 @@ import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.storage.StorageLayer; public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implements TemplateDownloader { - public static final Logger s_logger = Logger.getLogger(SimpleHttpMultiFileDownloader.class.getName()); private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); private static final int CHUNK_SIZE = 1024 * 1024; //1M @@ -73,6 +72,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem private final HttpMethodRetryHandler retryHandler; private HashMap urlFileMap; + private boolean followRedirects = false; public SimpleHttpMultiFileDownloader(StorageLayer storageLayer, String[] downloadUrls, String toDir, DownloadCompleteCallback callback, long maxTemplateSizeInBytes, @@ -94,7 +94,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem private GetMethod createRequest(String downloadUrl) { GetMethod request = new GetMethod(downloadUrl); request.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler); - request.setFollowRedirects(true); + request.setFollowRedirects(followRedirects); return request; } @@ -108,7 +108,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem } catch (IOException ex) { errorString = "Unable to start download -- check url? "; currentStatus = TemplateDownloader.Status.UNRECOVERABLE_ERROR; - s_logger.warn("Exception in constructor -- " + ex.toString()); + logger.warn("Exception in constructor -- " + ex.toString()); } } @@ -151,7 +151,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem } totalRemoteSize += Long.parseLong(contentLengthHeader.getValue()); } catch (IOException e) { - s_logger.warn(String.format("Cannot reach URL: %s while trying to get remote sizes due to: %s", downloadUrl, e.getMessage()), e); + logger.warn(String.format("Cannot reach URL: %s while trying to get remote sizes due to: %s", downloadUrl, e.getMessage()), e); } finally { headMethod.releaseConnection(); } @@ -159,7 +159,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem } private long downloadFile(String downloadUrl) { - s_logger.debug("Starting download for " + downloadUrl); + logger.debug("Starting download for " + downloadUrl); currentTotalBytes = 0; currentRemoteSize = 0; File file = null; @@ -170,7 +170,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem urlFileMap.put(downloadUrl, currentToFile); file = new File(currentToFile); long localFileSize = checkLocalFileSizeForResume(resume, file); - if (checkServerResponse(localFileSize)) return 0; + if (checkServerResponse(localFileSize, downloadUrl)) return 0; if (!tryAndGetRemoteSize()) return 0; if (!canHandleDownloadSize()) return 0; checkAndSetDownloadSize(); @@ -178,7 +178,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem RandomAccessFile out = new RandomAccessFile(file, "rw"); ) { out.seek(localFileSize); - s_logger.info("Starting download from " + downloadUrl + " to " + currentToFile + " remoteSize=" + toHumanReadableSize(currentRemoteSize) + " , max size=" + toHumanReadableSize(maxTemplateSizeInBytes)); + logger.info("Starting download from " + downloadUrl + " to " + currentToFile + " remoteSize=" + toHumanReadableSize(currentRemoteSize) + " , max size=" + toHumanReadableSize(maxTemplateSizeInBytes)); if (copyBytes(file, in, out)) return 0; checkDownloadCompletion(); } @@ -207,11 +207,11 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem public long download(boolean resume, DownloadCompleteCallback callback) { if (skipDownloadOnStatus()) return 0; if (resume) { - s_logger.error("Resume not allowed for this downloader"); + logger.error("Resume not allowed for this downloader"); status = Status.UNRECOVERABLE_ERROR; return 0; } - s_logger.debug("Starting downloads"); + logger.debug("Starting downloads"); status = Status.IN_PROGRESS; Date start = new Date(); tryAndGetTotalRemoteSize(); @@ -270,7 +270,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem private boolean canHandleDownloadSize() { if (currentRemoteSize > maxTemplateSizeInBytes) { - s_logger.info("Remote size is too large: " + toHumanReadableSize(currentRemoteSize) + " , max=" + toHumanReadableSize(maxTemplateSizeInBytes)); + logger.info("Remote size is too large: " + toHumanReadableSize(currentRemoteSize) + " , max=" + toHumanReadableSize(maxTemplateSizeInBytes)); currentStatus = Status.UNRECOVERABLE_ERROR; errorString = "Download file size is too large"; return false; @@ -317,7 +317,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem return true; } - private boolean checkServerResponse(long localFileSize) throws IOException { + private boolean checkServerResponse(long localFileSize, String downloadUrl) throws IOException { int responseCode = 0; if (localFileSize > 0) { @@ -331,6 +331,12 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem } else if ((responseCode = client.executeMethod(request)) != HttpStatus.SC_OK) { currentStatus = Status.UNRECOVERABLE_ERROR; errorString = " HTTP Server returned " + responseCode + " (expected 200 OK) "; + if (List.of(HttpStatus.SC_MOVED_PERMANENTLY, HttpStatus.SC_MOVED_TEMPORARILY).contains(responseCode) + && !followRedirects) { + errorString = String.format("Failed to download %s due to redirection, response code: %d", + downloadUrl, responseCode); + logger.error(errorString); + } return true; //FIXME: retry? } return false; @@ -341,7 +347,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem long localFileSize = 0; if (file.exists() && resume) { localFileSize = file.length(); - s_logger.info("Resuming download to file (current size)=" + toHumanReadableSize(localFileSize)); + logger.info("Resuming download to file (current size)=" + toHumanReadableSize(localFileSize)); } return localFileSize; } @@ -425,7 +431,7 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem try { download(resume, completionCallback); } catch (Throwable t) { - s_logger.warn("Caught exception during download " + t.getMessage(), t); + logger.warn("Caught exception during download " + t.getMessage(), t); errorString = "Failed to install: " + t.getMessage(); currentStatus = TemplateDownloader.Status.UNRECOVERABLE_ERROR; } @@ -478,4 +484,12 @@ public class SimpleHttpMultiFileDownloader extends ManagedContextRunnable implem public Map getDownloadedFilesMap() { return urlFileMap; } + + @Override + public void setFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + if (this.request != null) { + this.request.setFollowRedirects(followRedirects); + } + } } diff --git a/core/src/main/java/com/cloud/storage/template/TARProcessor.java b/core/src/main/java/com/cloud/storage/template/TARProcessor.java index 51aeb234c50..70b59336323 100644 --- a/core/src/main/java/com/cloud/storage/template/TARProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/TARProcessor.java @@ -22,14 +22,12 @@ package com.cloud.storage.template; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageLayer; import com.cloud.utils.component.AdapterBase; -import org.apache.log4j.Logger; import javax.naming.ConfigurationException; import java.io.File; import java.util.Map; public class TARProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(TARProcessor.class); private StorageLayer _storage; @@ -41,14 +39,14 @@ public class TARProcessor extends AdapterBase implements Processor { @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) { if (format != null) { - s_logger.debug("We currently don't handle conversion from " + format + " to TAR."); + logger.debug("We currently don't handle conversion from " + format + " to TAR."); return null; } String tarPath = templatePath + File.separator + templateName + "." + ImageFormat.TAR.getFileExtension(); if (!_storage.exists(tarPath)) { - s_logger.debug("Unable to find the tar file: " + tarPath); + logger.debug("Unable to find the tar file: " + tarPath); return null; } diff --git a/core/src/main/java/com/cloud/storage/template/TemplateDownloader.java b/core/src/main/java/com/cloud/storage/template/TemplateDownloader.java index 5db3d2425a5..9fb1ca42442 100644 --- a/core/src/main/java/com/cloud/storage/template/TemplateDownloader.java +++ b/core/src/main/java/com/cloud/storage/template/TemplateDownloader.java @@ -92,4 +92,6 @@ public interface TemplateDownloader extends Runnable { boolean isInited(); long getMaxTemplateSizeInBytes(); + + void setFollowRedirects(boolean followRedirects); } diff --git a/core/src/main/java/com/cloud/storage/template/TemplateDownloaderBase.java b/core/src/main/java/com/cloud/storage/template/TemplateDownloaderBase.java index f56e4911ca7..f1cb21a1815 100644 --- a/core/src/main/java/com/cloud/storage/template/TemplateDownloaderBase.java +++ b/core/src/main/java/com/cloud/storage/template/TemplateDownloaderBase.java @@ -21,14 +21,12 @@ package com.cloud.storage.template; import java.io.File; -import org.apache.log4j.Logger; import org.apache.cloudstack.managed.context.ManagedContextRunnable; import com.cloud.storage.StorageLayer; public abstract class TemplateDownloaderBase extends ManagedContextRunnable implements TemplateDownloader { - private static final Logger s_logger = Logger.getLogger(TemplateDownloaderBase.class); protected String _downloadUrl; protected String _toFile; @@ -43,6 +41,7 @@ public abstract class TemplateDownloaderBase extends ManagedContextRunnable impl protected long _start; protected StorageLayer _storage; protected boolean _inited = false; + protected boolean followRedirects = false; private long maxTemplateSizeInBytes; public TemplateDownloaderBase(StorageLayer storage, String downloadUrl, String toDir, long maxTemplateSizeInBytes, DownloadCompleteCallback callback) { @@ -133,7 +132,7 @@ public abstract class TemplateDownloaderBase extends ManagedContextRunnable impl try { download(_resume, _callback); } catch (Exception e) { - s_logger.warn("Unable to complete download due to ", e); + logger.warn("Unable to complete download due to ", e); _errorString = "Failed to install: " + e.getMessage(); _status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; } @@ -149,4 +148,9 @@ public abstract class TemplateDownloaderBase extends ManagedContextRunnable impl public boolean isInited() { return _inited; } + + @Override + public void setFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + } } diff --git a/core/src/main/java/com/cloud/storage/template/TemplateLocation.java b/core/src/main/java/com/cloud/storage/template/TemplateLocation.java index 6ff53a0410a..563c642f292 100644 --- a/core/src/main/java/com/cloud/storage/template/TemplateLocation.java +++ b/core/src/main/java/com/cloud/storage/template/TemplateLocation.java @@ -31,15 +31,16 @@ import java.util.Iterator; import java.util.Properties; import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType; -import org.apache.log4j.Logger; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageLayer; import com.cloud.storage.template.Processor.FormatInfo; import com.cloud.utils.NumbersUtil; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class TemplateLocation { - private static final Logger s_logger = Logger.getLogger(TemplateLocation.class); + protected Logger logger = LogManager.getLogger(getClass()); public final static String Filename = "template.properties"; StorageLayer _storage; @@ -90,8 +91,8 @@ public class TemplateLocation { if (!isRemoved) { purged = false; } - if (s_logger.isDebugEnabled()) { - s_logger.debug((isRemoved ? "Removed " : "Unable to remove") + file); + if (logger.isDebugEnabled()) { + logger.debug((isRemoved ? "Removed " : "Unable to remove") + file); } } @@ -102,27 +103,27 @@ public class TemplateLocation { try (FileInputStream strm = new FileInputStream(_file);) { _props.load(strm); } catch (IOException e) { - s_logger.warn("Unable to load the template properties for '" + _file + "': ", e); + logger.warn("Unable to load the template properties for '" + _file + "': ", e); } for (ImageFormat format : ImageFormat.values()) { String currentExtension = format.getFileExtension(); String ext = _props.getProperty(currentExtension); if (ext != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("File extension '" + currentExtension + "' was found in '" + _file + "'."); + if (logger.isDebugEnabled()) { + logger.debug("File extension '" + currentExtension + "' was found in '" + _file + "'."); } FormatInfo info = new FormatInfo(); info.format = format; info.filename = _props.getProperty(currentExtension + ".filename"); if (info.filename == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Property '" + currentExtension + ".filename' was not found in '" + _file + "'. Current format is ignored."); + if (logger.isDebugEnabled()) { + logger.debug("Property '" + currentExtension + ".filename' was not found in '" + _file + "'. Current format is ignored."); } continue; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Property '" + currentExtension + ".filename' was found in '" + _file + "'. Current format will be parsed."); + if (logger.isDebugEnabled()) { + logger.debug("Property '" + currentExtension + ".filename' was found in '" + _file + "'. Current format will be parsed."); } info.size = NumbersUtil.parseLong(_props.getProperty(currentExtension + ".size"), -1); _props.setProperty("physicalSize", Long.toString(info.size)); @@ -131,18 +132,18 @@ public class TemplateLocation { if (!checkFormatValidity(info)) { _isCorrupted = true; - s_logger.warn("Cleaning up inconsistent information for " + format); + logger.warn("Cleaning up inconsistent information for " + format); } } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Format extension '" + currentExtension + "' wasn't found in '" + _file + "'."); + if (logger.isDebugEnabled()) { + logger.debug("Format extension '" + currentExtension + "' wasn't found in '" + _file + "'."); } } } if (_props.getProperty("uniquename") == null || _props.getProperty("virtualsize") == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Property 'uniquename' or 'virtualsize' weren't found in '" + _file + "'. Loading failed."); + if (logger.isDebugEnabled()) { + logger.debug("Property 'uniquename' or 'virtualsize' weren't found in '" + _file + "'. Loading failed."); } return false; } @@ -160,7 +161,7 @@ public class TemplateLocation { try (FileOutputStream strm = new FileOutputStream(_file);) { _props.store(strm, ""); } catch (IOException e) { - s_logger.warn("Unable to save the template properties ", e); + logger.warn("Unable to save the template properties ", e); return false; } return true; @@ -204,9 +205,9 @@ public class TemplateLocation { deleteFormat(newInfo.format); if (!checkFormatValidity(newInfo)) { - s_logger.warn("Format is invalid"); - s_logger.debug("Format: " + newInfo.format + " size: " + toHumanReadableSize(newInfo.size) + " virtualsize: " + toHumanReadableSize(newInfo.virtualSize) + " filename: " + newInfo.filename); - s_logger.debug("format, filename cannot be null and size, virtual size should be > 0 "); + logger.warn("Format is invalid"); + logger.debug("Format: " + newInfo.format + " size: " + toHumanReadableSize(newInfo.size) + " virtualsize: " + toHumanReadableSize(newInfo.virtualSize) + " filename: " + newInfo.filename); + logger.debug("format, filename cannot be null and size, virtual size should be > 0 "); return false; } diff --git a/core/src/main/java/com/cloud/storage/template/VhdProcessor.java b/core/src/main/java/com/cloud/storage/template/VhdProcessor.java index baea7bf0db5..9f18d782b42 100644 --- a/core/src/main/java/com/cloud/storage/template/VhdProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/VhdProcessor.java @@ -27,7 +27,6 @@ import com.cloud.utils.component.AdapterBase; import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorStreamFactory; -import org.apache.log4j.Logger; import javax.naming.ConfigurationException; import java.io.BufferedInputStream; @@ -46,7 +45,6 @@ import java.util.Map; */ public class VhdProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(VhdProcessor.class); StorageLayer _storage; private int vhdFooterSize = 512; private int vhdCookieOffset = 8; @@ -64,13 +62,13 @@ public class VhdProcessor extends AdapterBase implements Processor { @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) throws InternalErrorException { if (format != null) { - s_logger.debug("We currently don't handle conversion from " + format + " to VHD."); + logger.debug("We currently don't handle conversion from " + format + " to VHD."); return null; } String vhdPath = templatePath + File.separator + templateName + "." + ImageFormat.VHD.getFileExtension(); if (!_storage.exists(vhdPath)) { - s_logger.debug("Unable to find the vhd file: " + vhdPath); + logger.debug("Unable to find the vhd file: " + vhdPath); return null; } @@ -84,7 +82,7 @@ public class VhdProcessor extends AdapterBase implements Processor { try { info.virtualSize = getTemplateVirtualSize(vhdFile); } catch (IOException e) { - s_logger.error("Unable to get the virtual size for " + vhdPath); + logger.error("Unable to get the virtual size for " + vhdPath); throw new InternalErrorException("unable to get virtual size from vhd file"); } @@ -97,7 +95,7 @@ public class VhdProcessor extends AdapterBase implements Processor { long size = getTemplateVirtualSize(file); return size; } catch (Exception e) { - s_logger.info("[ignored]" + "failed to get template virtual size for VHD: " + e.getLocalizedMessage()); + logger.info("[ignored]" + "failed to get template virtual size for VHD: " + e.getLocalizedMessage()); } return file.length(); } @@ -117,7 +115,7 @@ public class VhdProcessor extends AdapterBase implements Processor { try { strm = new CompressorStreamFactory().createCompressorInputStream(fileStream); } catch (CompressorException e) { - s_logger.info("error opening compressed VHD file " + file.getName()); + logger.info("error opening compressed VHD file " + file.getName()); return file.length(); } } try { @@ -146,7 +144,7 @@ public class VhdProcessor extends AdapterBase implements Processor { throw new IOException("Unexpected end-of-file"); } } catch (IOException e) { - s_logger.warn("Error reading virtual size from VHD file " + e.getMessage() + " VHD: " + file.getName()); + logger.warn("Error reading virtual size from VHD file " + e.getMessage() + " VHD: " + file.getName()); return file.length(); } finally { if (strm != null) { @@ -180,11 +178,11 @@ public class VhdProcessor extends AdapterBase implements Processor { cin = new CompressorStreamFactory().createCompressorInputStream(bin); } catch (CompressorException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); return false; } catch (FileNotFoundException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); return false; } finally { if (cin != null) diff --git a/core/src/main/java/com/cloud/storage/template/VmdkProcessor.java b/core/src/main/java/com/cloud/storage/template/VmdkProcessor.java index 927515f7544..4f53c556667 100644 --- a/core/src/main/java/com/cloud/storage/template/VmdkProcessor.java +++ b/core/src/main/java/com/cloud/storage/template/VmdkProcessor.java @@ -30,7 +30,6 @@ import java.util.regex.Pattern; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.exception.InternalErrorException; import com.cloud.storage.Storage.ImageFormat; @@ -40,7 +39,6 @@ import com.cloud.utils.component.AdapterBase; import static com.cloud.utils.NumbersUtil.toHumanReadableSize; public class VmdkProcessor extends AdapterBase implements Processor { - private static final Logger s_logger = Logger.getLogger(VmdkProcessor.class); StorageLayer _storage; @@ -52,17 +50,17 @@ public class VmdkProcessor extends AdapterBase implements Processor { @Override public FormatInfo process(String templatePath, ImageFormat format, String templateName, long processTimeout) throws InternalErrorException { if (format != null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("We currently don't handle conversion from " + format + " to VMDK."); + if (logger.isInfoEnabled()) { + logger.info("We currently don't handle conversion from " + format + " to VMDK."); } return null; } - s_logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); + logger.info("Template processing. templatePath: " + templatePath + ", templateName: " + templateName); String templateFilePath = templatePath + File.separator + templateName + "." + ImageFormat.VMDK.getFileExtension(); if (!_storage.exists(templateFilePath)) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Unable to find the vmware template file: " + templateFilePath); + if (logger.isInfoEnabled()) { + logger.info("Unable to find the vmware template file: " + templateFilePath); } return null; } @@ -82,7 +80,7 @@ public class VmdkProcessor extends AdapterBase implements Processor { long size = getTemplateVirtualSize(file.getParent(), file.getName()); return size; } catch (Exception e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "failed to get template virtual size for vmdk: " + e.getLocalizedMessage()); } return file.length(); @@ -108,15 +106,15 @@ public class VmdkProcessor extends AdapterBase implements Processor { } } catch(FileNotFoundException ex) { String msg = "Unable to open file '" + templateFileFullPath + "' " + ex.toString(); - s_logger.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } catch(IOException ex) { String msg = "Unable read open file '" + templateFileFullPath + "' " + ex.toString(); - s_logger.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } - s_logger.debug("vmdk file had size=" + toHumanReadableSize(virtualSize)); + logger.debug("vmdk file had size=" + toHumanReadableSize(virtualSize)); return virtualSize; } diff --git a/core/src/main/java/org/apache/cloudstack/agent/directdownload/CheckUrlCommand.java b/core/src/main/java/org/apache/cloudstack/agent/directdownload/CheckUrlCommand.java index b1b76da8211..325f61427a9 100644 --- a/core/src/main/java/org/apache/cloudstack/agent/directdownload/CheckUrlCommand.java +++ b/core/src/main/java/org/apache/cloudstack/agent/directdownload/CheckUrlCommand.java @@ -28,6 +28,7 @@ public class CheckUrlCommand extends Command { private Integer connectTimeout; private Integer connectionRequestTimeout; private Integer socketTimeout; + private boolean followRedirects; public String getFormat() { return format; @@ -43,19 +44,25 @@ public class CheckUrlCommand extends Command { public Integer getSocketTimeout() { return socketTimeout; } - public CheckUrlCommand(final String format,final String url) { + public boolean isFollowRedirects() { + return followRedirects; + } + + public CheckUrlCommand(final String format, final String url, final boolean followRedirects) { super(); this.format = format; this.url = url; + this.followRedirects = followRedirects; } - public CheckUrlCommand(final String format,final String url, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout) { + public CheckUrlCommand(final String format,final String url, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout, final boolean followRedirects) { super(); this.format = format; this.url = url; this.connectTimeout = connectTimeout; this.socketTimeout = socketTimeout; this.connectionRequestTimeout = connectionRequestTimeout; + this.followRedirects = followRedirects; } @Override diff --git a/core/src/main/java/org/apache/cloudstack/agent/directdownload/DirectDownloadCommand.java b/core/src/main/java/org/apache/cloudstack/agent/directdownload/DirectDownloadCommand.java index 7e1ff0b34c4..b6748dca434 100644 --- a/core/src/main/java/org/apache/cloudstack/agent/directdownload/DirectDownloadCommand.java +++ b/core/src/main/java/org/apache/cloudstack/agent/directdownload/DirectDownloadCommand.java @@ -45,7 +45,11 @@ public abstract class DirectDownloadCommand extends StorageSubSystemCommand { private Long templateSize; private Storage.ImageFormat format; - protected DirectDownloadCommand (final String url, final Long templateId, final PrimaryDataStoreTO destPool, final String checksum, final Map headers, final Integer connectTimeout, final Integer soTimeout, final Integer connectionRequestTimeout) { + private boolean followRedirects; + + protected DirectDownloadCommand (final String url, final Long templateId, final PrimaryDataStoreTO destPool, + final String checksum, final Map headers, final Integer connectTimeout, + final Integer soTimeout, final Integer connectionRequestTimeout, final boolean followRedirects) { this.url = url; this.templateId = templateId; this.destData = destData; @@ -55,6 +59,7 @@ public abstract class DirectDownloadCommand extends StorageSubSystemCommand { this.connectTimeout = connectTimeout; this.soTimeout = soTimeout; this.connectionRequestTimeout = connectionRequestTimeout; + this.followRedirects = followRedirects; } public String getUrl() { @@ -137,4 +142,12 @@ public abstract class DirectDownloadCommand extends StorageSubSystemCommand { public int getWaitInMillSeconds() { return getWait() * 1000; } + + public boolean isFollowRedirects() { + return followRedirects; + } + + public void setFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + } } diff --git a/core/src/main/java/org/apache/cloudstack/agent/directdownload/HttpDirectDownloadCommand.java b/core/src/main/java/org/apache/cloudstack/agent/directdownload/HttpDirectDownloadCommand.java index f131b3b0a7f..bdc00b3bc47 100644 --- a/core/src/main/java/org/apache/cloudstack/agent/directdownload/HttpDirectDownloadCommand.java +++ b/core/src/main/java/org/apache/cloudstack/agent/directdownload/HttpDirectDownloadCommand.java @@ -24,8 +24,10 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; public class HttpDirectDownloadCommand extends DirectDownloadCommand { - public HttpDirectDownloadCommand(String url, Long templateId, PrimaryDataStoreTO destPool, String checksum, Map headers, int connectTimeout, int soTimeout) { - super(url, templateId, destPool, checksum, headers, connectTimeout, soTimeout, null); + public HttpDirectDownloadCommand(String url, Long templateId, PrimaryDataStoreTO destPool, String checksum, + Map headers, int connectTimeout, int soTimeout, boolean followRedirects) { + super(url, templateId, destPool, checksum, headers, connectTimeout, soTimeout, + null, followRedirects); } } diff --git a/core/src/main/java/org/apache/cloudstack/agent/directdownload/HttpsDirectDownloadCommand.java b/core/src/main/java/org/apache/cloudstack/agent/directdownload/HttpsDirectDownloadCommand.java index dd88ad2a155..a7e16eac91a 100644 --- a/core/src/main/java/org/apache/cloudstack/agent/directdownload/HttpsDirectDownloadCommand.java +++ b/core/src/main/java/org/apache/cloudstack/agent/directdownload/HttpsDirectDownloadCommand.java @@ -25,7 +25,10 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; public class HttpsDirectDownloadCommand extends DirectDownloadCommand { - public HttpsDirectDownloadCommand(String url, Long templateId, PrimaryDataStoreTO destPool, String checksum, Map headers, int connectTimeout, int soTimeout, int connectionRequestTimeout) { - super(url, templateId, destPool, checksum, headers, connectTimeout, soTimeout, connectionRequestTimeout); + public HttpsDirectDownloadCommand(String url, Long templateId, PrimaryDataStoreTO destPool, String checksum, + Map headers, int connectTimeout, int soTimeout, int connectionRequestTimeout, + boolean followRedirects) { + super(url, templateId, destPool, checksum, headers, connectTimeout, soTimeout, + connectionRequestTimeout, followRedirects); } } diff --git a/core/src/main/java/org/apache/cloudstack/agent/directdownload/MetalinkDirectDownloadCommand.java b/core/src/main/java/org/apache/cloudstack/agent/directdownload/MetalinkDirectDownloadCommand.java index a3edcebe7de..7742994c76b 100644 --- a/core/src/main/java/org/apache/cloudstack/agent/directdownload/MetalinkDirectDownloadCommand.java +++ b/core/src/main/java/org/apache/cloudstack/agent/directdownload/MetalinkDirectDownloadCommand.java @@ -24,8 +24,9 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; public class MetalinkDirectDownloadCommand extends DirectDownloadCommand { - public MetalinkDirectDownloadCommand(String url, Long templateId, PrimaryDataStoreTO destPool, String checksum, Map headers, int connectTimeout, int soTimeout) { - super(url, templateId, destPool, checksum, headers, connectTimeout, soTimeout, null); + public MetalinkDirectDownloadCommand(String url, Long templateId, PrimaryDataStoreTO destPool, String checksum, + Map headers, int connectTimeout, int soTimeout, boolean followRedirects) { + super(url, templateId, destPool, checksum, headers, connectTimeout, soTimeout, null, followRedirects); } } diff --git a/core/src/main/java/org/apache/cloudstack/agent/directdownload/NfsDirectDownloadCommand.java b/core/src/main/java/org/apache/cloudstack/agent/directdownload/NfsDirectDownloadCommand.java index 0bf9c4d934b..0e51d786230 100644 --- a/core/src/main/java/org/apache/cloudstack/agent/directdownload/NfsDirectDownloadCommand.java +++ b/core/src/main/java/org/apache/cloudstack/agent/directdownload/NfsDirectDownloadCommand.java @@ -24,8 +24,9 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; public class NfsDirectDownloadCommand extends DirectDownloadCommand { - public NfsDirectDownloadCommand(final String url, final Long templateId, final PrimaryDataStoreTO destPool, final String checksum, final Map headers) { - super(url, templateId, destPool, checksum, headers, null, null, null); + public NfsDirectDownloadCommand(final String url, final Long templateId, final PrimaryDataStoreTO destPool, + final String checksum, final Map headers) { + super(url, templateId, destPool, checksum, headers, null, null, null, false); } } diff --git a/core/src/main/java/org/apache/cloudstack/backup/PrepareForBackupRestorationCommand.java b/core/src/main/java/org/apache/cloudstack/backup/PrepareForBackupRestorationCommand.java new file mode 100644 index 00000000000..25306fb5f73 --- /dev/null +++ b/core/src/main/java/org/apache/cloudstack/backup/PrepareForBackupRestorationCommand.java @@ -0,0 +1,43 @@ +// +// 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 org.apache.cloudstack.backup; + +import com.cloud.agent.api.Command; + +public class PrepareForBackupRestorationCommand extends Command { + + private String vmName; + + protected PrepareForBackupRestorationCommand() { + } + + public PrepareForBackupRestorationCommand(String vmName) { + this.vmName = vmName; + } + + public String getVmName() { + return vmName; + } + + @Override + public boolean executeInSequence() { + return true; + } +} diff --git a/core/src/main/java/org/apache/cloudstack/diagnostics/DiagnosticsAnswer.java b/core/src/main/java/org/apache/cloudstack/diagnostics/DiagnosticsAnswer.java index 7390e4fcdd2..6421f45ed0a 100644 --- a/core/src/main/java/org/apache/cloudstack/diagnostics/DiagnosticsAnswer.java +++ b/core/src/main/java/org/apache/cloudstack/diagnostics/DiagnosticsAnswer.java @@ -21,13 +21,11 @@ import com.cloud.agent.api.Answer; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.lang3.StringUtils; import org.apache.cloudstack.api.ApiConstants; -import org.apache.log4j.Logger; import java.util.HashMap; import java.util.Map; public class DiagnosticsAnswer extends Answer { - public static final Logger LOGGER = Logger.getLogger(DiagnosticsAnswer.class); public DiagnosticsAnswer(DiagnosticsCommand cmd, boolean result, String details) { super(cmd, result, details); diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadHelper.java b/core/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadHelper.java index 27e35b7074b..0e0e2f0b57b 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadHelper.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadHelper.java @@ -24,37 +24,41 @@ import org.apache.cloudstack.agent.directdownload.HttpDirectDownloadCommand; import org.apache.cloudstack.agent.directdownload.HttpsDirectDownloadCommand; import org.apache.cloudstack.agent.directdownload.MetalinkDirectDownloadCommand; import org.apache.cloudstack.agent.directdownload.NfsDirectDownloadCommand; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class DirectDownloadHelper { - public static final Logger LOGGER = Logger.getLogger(DirectDownloadHelper.class.getName()); + protected static Logger LOGGER = LogManager.getLogger(DirectDownloadHelper.class); /** * Get direct template downloader from direct download command and destination pool */ public static DirectTemplateDownloader getDirectTemplateDownloaderFromCommand(DirectDownloadCommand cmd, - String destPoolLocalPath, - String temporaryDownloadPath) { + String destPoolLocalPath, String temporaryDownloadPath) { if (cmd instanceof HttpDirectDownloadCommand) { - return new HttpDirectTemplateDownloader(cmd.getUrl(), cmd.getTemplateId(), destPoolLocalPath, cmd.getChecksum(), cmd.getHeaders(), - cmd.getConnectTimeout(), cmd.getSoTimeout(), temporaryDownloadPath); + return new HttpDirectTemplateDownloader(cmd.getUrl(), cmd.getTemplateId(), destPoolLocalPath, + cmd.getChecksum(), cmd.getHeaders(), cmd.getConnectTimeout(), cmd.getSoTimeout(), + temporaryDownloadPath, cmd.isFollowRedirects()); } else if (cmd instanceof HttpsDirectDownloadCommand) { - return new HttpsDirectTemplateDownloader(cmd.getUrl(), cmd.getTemplateId(), destPoolLocalPath, cmd.getChecksum(), cmd.getHeaders(), - cmd.getConnectTimeout(), cmd.getSoTimeout(), cmd.getConnectionRequestTimeout(), temporaryDownloadPath); + return new HttpsDirectTemplateDownloader(cmd.getUrl(), cmd.getTemplateId(), destPoolLocalPath, + cmd.getChecksum(), cmd.getHeaders(), cmd.getConnectTimeout(), cmd.getSoTimeout(), + cmd.getConnectionRequestTimeout(), temporaryDownloadPath, cmd.isFollowRedirects()); } else if (cmd instanceof NfsDirectDownloadCommand) { - return new NfsDirectTemplateDownloader(cmd.getUrl(), destPoolLocalPath, cmd.getTemplateId(), cmd.getChecksum(), temporaryDownloadPath); + return new NfsDirectTemplateDownloader(cmd.getUrl(), destPoolLocalPath, cmd.getTemplateId(), + cmd.getChecksum(), temporaryDownloadPath); } else if (cmd instanceof MetalinkDirectDownloadCommand) { - return new MetalinkDirectTemplateDownloader(cmd.getUrl(), destPoolLocalPath, cmd.getTemplateId(), cmd.getChecksum(), cmd.getHeaders(), - cmd.getConnectTimeout(), cmd.getSoTimeout(), temporaryDownloadPath); + return new MetalinkDirectTemplateDownloader(cmd.getUrl(), destPoolLocalPath, cmd.getTemplateId(), + cmd.getChecksum(), cmd.getHeaders(), cmd.getConnectTimeout(), cmd.getSoTimeout(), + temporaryDownloadPath, cmd.isFollowRedirects()); } else { throw new IllegalArgumentException("Unsupported protocol, please provide HTTP(S), NFS or a metalink"); } } - public static boolean checkUrlExistence(String url) { + public static boolean checkUrlExistence(String url, boolean followRedirects) { try { - DirectTemplateDownloader checker = getCheckerDownloader(url, null, null, null); + DirectTemplateDownloader checker = getCheckerDownloader(url, null, null, null, followRedirects); return checker.checkUrl(url); } catch (CloudRuntimeException e) { LOGGER.error(String.format("Cannot check URL %s is reachable due to: %s", url, e.getMessage()), e); @@ -62,9 +66,9 @@ public class DirectDownloadHelper { } } - public static boolean checkUrlExistence(String url, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout) { + public static boolean checkUrlExistence(String url, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout, boolean followRedirects) { try { - DirectTemplateDownloader checker = getCheckerDownloader(url, connectTimeout, connectionRequestTimeout, socketTimeout); + DirectTemplateDownloader checker = getCheckerDownloader(url, connectTimeout, connectionRequestTimeout, socketTimeout, followRedirects); return checker.checkUrl(url); } catch (CloudRuntimeException e) { LOGGER.error(String.format("Cannot check URL %s is reachable due to: %s", url, e.getMessage()), e); @@ -72,27 +76,27 @@ public class DirectDownloadHelper { } } - private static DirectTemplateDownloader getCheckerDownloader(String url, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout) { + private static DirectTemplateDownloader getCheckerDownloader(String url, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout, boolean followRedirects) { if (url.toLowerCase().startsWith("https:")) { - return new HttpsDirectTemplateDownloader(url, connectTimeout, connectionRequestTimeout, socketTimeout); + return new HttpsDirectTemplateDownloader(url, connectTimeout, connectionRequestTimeout, socketTimeout, followRedirects); } else if (url.toLowerCase().startsWith("http:")) { - return new HttpDirectTemplateDownloader(url, connectTimeout, socketTimeout); + return new HttpDirectTemplateDownloader(url, connectTimeout, socketTimeout, followRedirects); } else if (url.toLowerCase().startsWith("nfs:")) { return new NfsDirectTemplateDownloader(url); } else if (url.toLowerCase().endsWith(".metalink")) { - return new MetalinkDirectTemplateDownloader(url, connectTimeout, socketTimeout); + return new MetalinkDirectTemplateDownloader(url, connectTimeout, socketTimeout, followRedirects); } else { throw new CloudRuntimeException(String.format("Cannot find a download checker for url: %s", url)); } } - public static Long getFileSize(String url, String format) { - DirectTemplateDownloader checker = getCheckerDownloader(url, null, null, null); + public static Long getFileSize(String url, String format, boolean followRedirects) { + DirectTemplateDownloader checker = getCheckerDownloader(url, null, null, null, followRedirects); return checker.getRemoteFileSize(url, format); } - public static Long getFileSize(String url, String format, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout) { - DirectTemplateDownloader checker = getCheckerDownloader(url, connectTimeout, connectionRequestTimeout, socketTimeout); + public static Long getFileSize(String url, String format, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout, boolean followRedirects) { + DirectTemplateDownloader checker = getCheckerDownloader(url, connectTimeout, connectionRequestTimeout, socketTimeout, followRedirects); return checker.getRemoteFileSize(url, format); } } diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/DirectTemplateDownloaderImpl.java b/core/src/main/java/org/apache/cloudstack/direct/download/DirectTemplateDownloaderImpl.java index 9476dbaa5ce..d22c803818b 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/DirectTemplateDownloaderImpl.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/DirectTemplateDownloaderImpl.java @@ -22,7 +22,8 @@ import com.cloud.utils.UriUtils; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.utils.security.DigestHelper; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.io.File; import java.io.FileInputStream; @@ -42,16 +43,19 @@ public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDown private String checksum; private boolean redownload = false; protected String temporaryDownloadPath; + private boolean followRedirects; - public static final Logger s_logger = Logger.getLogger(DirectTemplateDownloaderImpl.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); protected DirectTemplateDownloaderImpl(final String url, final String destPoolPath, final Long templateId, - final String checksum, final String temporaryDownloadPath) { + final String checksum, final String temporaryDownloadPath, + final boolean followRedirects) { this.url = url; this.destPoolPath = destPoolPath; this.templateId = templateId; this.checksum = checksum; this.temporaryDownloadPath = temporaryDownloadPath; + this.followRedirects = followRedirects; } private static String directDownloadDir = "template"; @@ -111,6 +115,14 @@ public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDown return redownload; } + public boolean isFollowRedirects() { + return followRedirects; + } + + public void setFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + } + /** * Create download directory (if it does not exist) */ @@ -135,16 +147,16 @@ public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDown try { while (!valid && retry > 0) { retry--; - s_logger.info("Performing checksum validation for downloaded template " + templateId + " using " + checksum + ", retries left: " + retry); + logger.info("Performing checksum validation for downloaded template " + templateId + " using " + checksum + ", retries left: " + retry); valid = DigestHelper.check(checksum, new FileInputStream(downloadedFilePath)); if (!valid && retry > 0) { - s_logger.info("Checksum validation failed, re-downloading template"); + logger.info("Checksum validation failed, re-downloading template"); redownload = true; resetDownloadFile(); downloadTemplate(); } } - s_logger.info("Checksum validation for template " + templateId + ": " + (valid ? "succeeded" : "failed")); + logger.info("Checksum validation for template " + templateId + ": " + (valid ? "succeeded" : "failed")); return valid; } catch (IOException e) { throw new CloudRuntimeException("could not check sum for file: " + downloadedFilePath, e); @@ -152,7 +164,7 @@ public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDown throw new CloudRuntimeException("Unknown checksum algorithm: " + checksum, e); } } - s_logger.info("No checksum provided, skipping checksum validation"); + logger.info("No checksum provided, skipping checksum validation"); return true; } @@ -161,14 +173,14 @@ public abstract class DirectTemplateDownloaderImpl implements DirectTemplateDown */ private void resetDownloadFile() { File f = new File(getDownloadedFilePath()); - s_logger.info("Resetting download file: " + getDownloadedFilePath() + ", in order to re-download and persist template " + templateId + " on it"); + logger.info("Resetting download file: " + getDownloadedFilePath() + ", in order to re-download and persist template " + templateId + " on it"); try { if (f.exists()) { f.delete(); } f.createNewFile(); } catch (IOException e) { - s_logger.error("Error creating file to download on: " + getDownloadedFilePath() + " due to: " + e.getMessage()); + logger.error("Error creating file to download on: " + getDownloadedFilePath() + " due to: " + e.getMessage()); throw new CloudRuntimeException("Failed to create download file for direct download"); } } diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/HttpDirectTemplateDownloader.java b/core/src/main/java/org/apache/cloudstack/direct/download/HttpDirectTemplateDownloader.java index e1b2f1fe429..8c4147fad60 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/HttpDirectTemplateDownloader.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/HttpDirectTemplateDownloader.java @@ -40,23 +40,22 @@ import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { protected HttpClient client; private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); - public static final Logger s_logger = Logger.getLogger(HttpDirectTemplateDownloader.class.getName()); protected GetMethod request; protected Map reqHeaders = new HashMap<>(); - protected HttpDirectTemplateDownloader(String url, Integer connectTimeout, Integer socketTimeout) { - this(url, null, null, null, null, connectTimeout, socketTimeout, null); + protected HttpDirectTemplateDownloader(String url, Integer connectTimeout, Integer socketTimeout, boolean followRedirects) { + this(url, null, null, null, null, connectTimeout, socketTimeout, null, followRedirects); } public HttpDirectTemplateDownloader(String url, Long templateId, String destPoolPath, String checksum, - Map headers, Integer connectTimeout, Integer soTimeout, String downloadPath) { - super(url, destPoolPath, templateId, checksum, downloadPath); + Map headers, Integer connectTimeout, Integer soTimeout, String downloadPath, + boolean followRedirects) { + super(url, destPoolPath, templateId, checksum, downloadPath, followRedirects); s_httpClientManager.getParams().setConnectionTimeout(connectTimeout == null ? 5000 : connectTimeout); s_httpClientManager.getParams().setSoTimeout(soTimeout == null ? 5000 : soTimeout); client = new HttpClient(s_httpClientManager); @@ -68,7 +67,7 @@ public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { protected GetMethod createRequest(String downloadUrl, Map headers) { GetMethod request = new GetMethod(downloadUrl); - request.setFollowRedirects(true); + request.setFollowRedirects(this.isFollowRedirects()); if (MapUtils.isNotEmpty(headers)) { for (String key : headers.keySet()) { request.setRequestHeader(key, headers.get(key)); @@ -83,7 +82,7 @@ public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { try { int status = client.executeMethod(request); if (status != HttpStatus.SC_OK) { - s_logger.warn("Not able to download template, status code: " + status); + logger.warn("Not able to download template, status code: " + status); return new Pair<>(false, null); } return performDownload(); @@ -95,14 +94,14 @@ public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { } protected Pair performDownload() { - s_logger.info("Downloading template " + getTemplateId() + " from " + getUrl() + " to: " + getDownloadedFilePath()); + logger.info("Downloading template " + getTemplateId() + " from " + getUrl() + " to: " + getDownloadedFilePath()); try ( InputStream in = request.getResponseBodyAsStream(); OutputStream out = new FileOutputStream(getDownloadedFilePath()) ) { IOUtils.copy(in, out); } catch (IOException e) { - s_logger.error("Error downloading template " + getTemplateId() + " due to: " + e.getMessage()); + logger.error("Error downloading template " + getTemplateId() + " due to: " + e.getMessage()); return new Pair<>(false, null); } return new Pair<>(true, getDownloadedFilePath()); @@ -111,14 +110,16 @@ public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { @Override public boolean checkUrl(String url) { HeadMethod httpHead = new HeadMethod(url); + httpHead.setFollowRedirects(this.isFollowRedirects()); try { - if (client.executeMethod(httpHead) != HttpStatus.SC_OK) { - s_logger.error(String.format("Invalid URL: %s", url)); + int responseCode = client.executeMethod(httpHead); + if (responseCode != HttpStatus.SC_OK) { + logger.error(String.format("HTTP HEAD request to URL: %s failed, response code: %d", url, responseCode)); return false; } return true; } catch (IOException e) { - s_logger.error(String.format("Cannot reach URL: %s due to: %s", url, e.getMessage()), e); + logger.error(String.format("Cannot reach URL: %s due to: %s", url, e.getMessage()), e); return false; } finally { httpHead.releaseConnection(); @@ -128,9 +129,9 @@ public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { @Override public Long getRemoteFileSize(String url, String format) { if ("qcow2".equalsIgnoreCase(format)) { - return QCOW2Utils.getVirtualSize(url); + return QCOW2Utils.getVirtualSizeFromUrl(url, this.isFollowRedirects()); } else { - return UriUtils.getRemoteSize(url); + return UriUtils.getRemoteSize(url, this.isFollowRedirects()); } } @@ -142,7 +143,7 @@ public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { try { status = client.executeMethod(getMethod); } catch (IOException e) { - s_logger.error("Error retrieving urls form metalink: " + metalinkUrl); + logger.error("Error retrieving urls form metalink: " + metalinkUrl); getMethod.releaseConnection(); return null; } @@ -152,7 +153,7 @@ public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { addMetalinkUrlsToListFromInputStream(is, urls); } } catch (IOException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); } finally { getMethod.releaseConnection(); } @@ -168,7 +169,7 @@ public class HttpDirectTemplateDownloader extends DirectTemplateDownloaderImpl { return generateChecksumListFromInputStream(is); } } catch (IOException e) { - s_logger.error(String.format("Error obtaining metalink checksums on URL %s: %s", metalinkUrl, e.getMessage()), e); + logger.error(String.format("Error obtaining metalink checksums on URL %s: %s", metalinkUrl, e.getMessage()), e); } finally { getMethod.releaseConnection(); } diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java b/core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java index 70a3eb29bc7..b8a25a11b5c 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/HttpsDirectTemplateDownloader.java @@ -68,20 +68,26 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl protected CloseableHttpClient httpsClient; private HttpUriRequest req; - protected HttpsDirectTemplateDownloader(String url, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout) { - this(url, null, null, null, null, connectTimeout, socketTimeout, connectionRequestTimeout, null); + protected HttpsDirectTemplateDownloader(String url, Integer connectTimeout, Integer connectionRequestTimeout, Integer socketTimeout, boolean followRedirects) { + this(url, null, null, null, null, connectTimeout, socketTimeout, connectionRequestTimeout, null, followRedirects); } - public HttpsDirectTemplateDownloader(String url, Long templateId, String destPoolPath, String checksum, Map headers, - Integer connectTimeout, Integer soTimeout, Integer connectionRequestTimeout, String temporaryDownloadPath) { - super(url, destPoolPath, templateId, checksum, temporaryDownloadPath); + public HttpsDirectTemplateDownloader(String url, Long templateId, String destPoolPath, String checksum, + Map headers, Integer connectTimeout, Integer soTimeout, + Integer connectionRequestTimeout, String temporaryDownloadPath, boolean followRedirects) { + super(url, destPoolPath, templateId, checksum, temporaryDownloadPath, followRedirects); SSLContext sslcontext = getSSLContext(); SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); RequestConfig config = RequestConfig.custom() .setConnectTimeout(connectTimeout == null ? 5000 : connectTimeout) .setConnectionRequestTimeout(connectionRequestTimeout == null ? 5000 : connectionRequestTimeout) - .setSocketTimeout(soTimeout == null ? 5000 : soTimeout).build(); - httpsClient = HttpClients.custom().setSSLSocketFactory(factory).setDefaultRequestConfig(config).build(); + .setSocketTimeout(soTimeout == null ? 5000 : soTimeout) + .setRedirectsEnabled(followRedirects) + .build(); + httpsClient = HttpClients.custom() + .setSSLSocketFactory(factory) + .setDefaultRequestConfig(config) + .build(); createUriRequest(url, headers); String downloadDir = getDirectDownloadTempPath(templateId); File tempFile = createTemporaryDirectoryAndFile(downloadDir); @@ -90,6 +96,7 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl protected void createUriRequest(String downloadUrl, Map headers) { req = new HttpGet(downloadUrl); + setFollowRedirects(this.isFollowRedirects()); if (MapUtils.isNotEmpty(headers)) { for (String headerKey: headers.keySet()) { req.setHeader(headerKey, headers.get(headerKey)); @@ -118,7 +125,7 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl sslContext.init(null, tm, null); return sslContext; } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | KeyManagementException e) { - s_logger.error(String.format("Failure getting SSL context for HTTPS downloader, using default SSL context: %s", e.getMessage()), e); + logger.error(String.format("Failure getting SSL context for HTTPS downloader, using default SSL context: %s", e.getMessage()), e); try { return SSLContext.getDefault(); } catch (NoSuchAlgorithmException ex) { @@ -143,7 +150,7 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl * Consume response and persist it on getDownloadedFilePath() file */ protected Pair consumeResponse(CloseableHttpResponse response) { - s_logger.info("Downloading template " + getTemplateId() + " from " + getUrl() + " to: " + getDownloadedFilePath()); + logger.info("Downloading template " + getTemplateId() + " from " + getUrl() + " to: " + getDownloadedFilePath()); if (response.getStatusLine().getStatusCode() != 200) { throw new CloudRuntimeException("Error on HTTPS response"); } @@ -153,7 +160,7 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl OutputStream out = new FileOutputStream(getDownloadedFilePath()); IOUtils.copy(in, out); } catch (Exception e) { - s_logger.error("Error parsing response for template " + getTemplateId() + " due to: " + e.getMessage()); + logger.error("Error parsing response for template " + getTemplateId() + " due to: " + e.getMessage()); return new Pair<>(false, null); } return new Pair<>(true, getDownloadedFilePath()); @@ -164,13 +171,14 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl HttpHead httpHead = new HttpHead(url); try { CloseableHttpResponse response = httpsClient.execute(httpHead); - if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { - s_logger.error(String.format("Invalid URL: %s", url)); + int responseCode = response.getStatusLine().getStatusCode(); + if (responseCode != HttpStatus.SC_OK) { + logger.error(String.format("HTTP HEAD request to URL: %s failed, response code: %d", url, responseCode)); return false; } return true; } catch (IOException e) { - s_logger.error(String.format("Cannot reach URL: %s due to: %s", url, e.getMessage()), e); + logger.error(String.format("Cannot reach URL: %s due to: %s", url, e.getMessage()), e); return false; } finally { httpHead.releaseConnection(); @@ -215,11 +223,11 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl response = httpsClient.execute(getMethod); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { String msg = String.format("Cannot access metalink content on URL %s", metalinkUrl); - s_logger.error(msg); + logger.error(msg); throw new IOException(msg); } } catch (IOException e) { - s_logger.error(String.format("Error retrieving urls form metalink URL %s: %s", metalinkUrl, e.getMessage()), e); + logger.error(String.format("Error retrieving urls form metalink URL %s: %s", metalinkUrl, e.getMessage()), e); getMethod.releaseConnection(); return null; } @@ -229,7 +237,7 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl ByteArrayInputStream inputStream = new ByteArrayInputStream(responseStr.getBytes(StandardCharsets.UTF_8)); addMetalinkUrlsToListFromInputStream(inputStream, urls); } catch (IOException e) { - s_logger.warn(e.getMessage(), e); + logger.warn(e.getMessage(), e); } finally { getMethod.releaseConnection(); } @@ -246,7 +254,7 @@ public class HttpsDirectTemplateDownloader extends DirectTemplateDownloaderImpl return generateChecksumListFromInputStream(is); } } catch (IOException e) { - s_logger.error(String.format("Error obtaining metalink checksums on URL %s: %s", metalinkUrl, e.getMessage()), e); + logger.error(String.format("Error obtaining metalink checksums on URL %s: %s", metalinkUrl, e.getMessage()), e); } finally { getMethod.releaseConnection(); } diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloader.java b/core/src/main/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloader.java index 06578d8c2b2..5335da99150 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloader.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloader.java @@ -23,7 +23,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.File; import java.util.List; @@ -39,34 +38,32 @@ public class MetalinkDirectTemplateDownloader extends DirectTemplateDownloaderIm private Integer connectTimeout; private Integer soTimeout; - private static final Logger s_logger = Logger.getLogger(MetalinkDirectTemplateDownloader.class.getName()); - protected DirectTemplateDownloader createDownloaderForMetalinks(String url, Long templateId, - String destPoolPath, String checksum, - Map headers, - Integer connectTimeout, Integer soTimeout, - Integer connectionRequestTimeout, String temporaryDownloadPath) { + String destPoolPath, String checksum, Map headers, Integer connectTimeout, + Integer soTimeout, Integer connectionRequestTimeout, String temporaryDownloadPath) { if (url.toLowerCase().startsWith("https:")) { return new HttpsDirectTemplateDownloader(url, templateId, destPoolPath, checksum, headers, - connectTimeout, soTimeout, connectionRequestTimeout, temporaryDownloadPath); + connectTimeout, soTimeout, connectionRequestTimeout, temporaryDownloadPath, + this.isFollowRedirects()); } else if (url.toLowerCase().startsWith("http:")) { return new HttpDirectTemplateDownloader(url, templateId, destPoolPath, checksum, headers, - connectTimeout, soTimeout, temporaryDownloadPath); + connectTimeout, soTimeout, temporaryDownloadPath, this.isFollowRedirects()); } else if (url.toLowerCase().startsWith("nfs:")) { return new NfsDirectTemplateDownloader(url); } else { - s_logger.error(String.format("Cannot find a suitable downloader to handle the metalink URL %s", url)); + logger.error(String.format("Cannot find a suitable downloader to handle the metalink URL %s", url)); return null; } } - protected MetalinkDirectTemplateDownloader(String url, Integer connectTimeout, Integer socketTimeout) { - this(url, null, null, null, null, connectTimeout, socketTimeout, null); + protected MetalinkDirectTemplateDownloader(String url, Integer connectTimeout, Integer socketTimeout, boolean followRedirects) { + this(url, null, null, null, null, connectTimeout, socketTimeout, null, followRedirects); } public MetalinkDirectTemplateDownloader(String url, String destPoolPath, Long templateId, String checksum, - Map headers, Integer connectTimeout, Integer soTimeout, String downloadPath) { - super(url, destPoolPath, templateId, checksum, downloadPath); + Map headers, Integer connectTimeout, Integer soTimeout, String downloadPath, + boolean followRedirects) { + super(url, destPoolPath, templateId, checksum, downloadPath, followRedirects); this.headers = headers; this.connectTimeout = connectTimeout; this.soTimeout = soTimeout; @@ -75,10 +72,10 @@ public class MetalinkDirectTemplateDownloader extends DirectTemplateDownloaderIm metalinkUrls = downloader.getMetalinkUrls(url); metalinkChecksums = downloader.getMetalinkChecksums(url); if (CollectionUtils.isEmpty(metalinkUrls)) { - s_logger.error(String.format("No urls found on metalink file: %s. Not possible to download template %s ", url, templateId)); + logger.error(String.format("No urls found on metalink file: %s. Not possible to download template %s ", url, templateId)); } else { setUrl(metalinkUrls.get(0)); - s_logger.info("Metalink downloader created, metalink url: " + url + " parsed - " + + logger.info("Metalink downloader created, metalink url: " + url + " parsed - " + metalinkUrls.size() + " urls and " + (CollectionUtils.isNotEmpty(metalinkChecksums) ? metalinkChecksums.size() : "0") + " checksums found"); } @@ -96,7 +93,7 @@ public class MetalinkDirectTemplateDownloader extends DirectTemplateDownloaderIm if (!isRedownload()) { setUrl(metalinkUrls.get(i)); } - s_logger.info("Trying to download template from url: " + getUrl()); + logger.info("Trying to download template from url: " + getUrl()); DirectTemplateDownloader urlDownloader = createDownloaderForMetalinks(getUrl(), getTemplateId(), getDestPoolPath(), getChecksum(), headers, connectTimeout, soTimeout, null, temporaryDownloadPath); try { @@ -109,10 +106,10 @@ public class MetalinkDirectTemplateDownloader extends DirectTemplateDownloaderIm Pair downloadResult = urlDownloader.downloadTemplate(); downloaded = downloadResult.first(); if (downloaded) { - s_logger.info("Successfully downloaded template from url: " + getUrl()); + logger.info("Successfully downloaded template from url: " + getUrl()); } } catch (Exception e) { - s_logger.error(String.format("Error downloading template: %s from URL: %s due to: %s", getTemplateId(), getUrl(), e.getMessage()), e); + logger.error(String.format("Error downloading template: %s from URL: %s due to: %s", getTemplateId(), getUrl(), e.getMessage()), e); } i++; } @@ -125,7 +122,7 @@ public class MetalinkDirectTemplateDownloader extends DirectTemplateDownloaderIm if (StringUtils.isBlank(getChecksum()) && CollectionUtils.isNotEmpty(metalinkChecksums)) { String chk = metalinkChecksums.get(random.nextInt(metalinkChecksums.size())); setChecksum(chk); - s_logger.info("Checksum not provided but " + metalinkChecksums.size() + " found on metalink file, performing checksum using one of them: " + chk); + logger.info("Checksum not provided but " + metalinkChecksums.size() + " found on metalink file, performing checksum using one of them: " + chk); } return super.validateChecksum(); } @@ -133,7 +130,7 @@ public class MetalinkDirectTemplateDownloader extends DirectTemplateDownloaderIm @Override public boolean checkUrl(String metalinkUrl) { if (!downloader.checkUrl(metalinkUrl)) { - s_logger.error(String.format("Metalink URL check failed for: %s", metalinkUrl)); + logger.error(String.format("Metalink URL check failed for: %s", metalinkUrl)); return false; } diff --git a/core/src/main/java/org/apache/cloudstack/direct/download/NfsDirectTemplateDownloader.java b/core/src/main/java/org/apache/cloudstack/direct/download/NfsDirectTemplateDownloader.java index d606136e297..21184ef07fe 100644 --- a/core/src/main/java/org/apache/cloudstack/direct/download/NfsDirectTemplateDownloader.java +++ b/core/src/main/java/org/apache/cloudstack/direct/download/NfsDirectTemplateDownloader.java @@ -57,8 +57,9 @@ public class NfsDirectTemplateDownloader extends DirectTemplateDownloaderImpl { this(url, null, null, null, null); } - public NfsDirectTemplateDownloader(String url, String destPool, Long templateId, String checksum, String downloadPath) { - super(url, destPool, templateId, checksum, downloadPath); + public NfsDirectTemplateDownloader(String url, String destPool, Long templateId, String checksum, + String downloadPath) { + super(url, destPool, templateId, checksum, downloadPath, false); parseUrl(); } @@ -80,7 +81,7 @@ public class NfsDirectTemplateDownloader extends DirectTemplateDownloaderImpl { parseUrl(); return true; } catch (CloudRuntimeException e) { - s_logger.error(String.format("Cannot check URL %s is reachable due to: %s", url, e.getMessage()), e); + logger.error(String.format("Cannot check URL %s is reachable due to: %s", url, e.getMessage()), e); return false; } } diff --git a/core/src/main/java/org/apache/cloudstack/storage/command/DownloadCommand.java b/core/src/main/java/org/apache/cloudstack/storage/command/DownloadCommand.java index 4032ac0b632..f44220f31d0 100644 --- a/core/src/main/java/org/apache/cloudstack/storage/command/DownloadCommand.java +++ b/core/src/main/java/org/apache/cloudstack/storage/command/DownloadCommand.java @@ -49,6 +49,8 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal private DataStoreTO _store; private DataStoreTO cacheStore; + private boolean followRedirects = false; + protected DownloadCommand() { } @@ -65,6 +67,7 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal installPath = that.installPath; _store = that._store; _proxy = that._proxy; + followRedirects = that.followRedirects; } public DownloadCommand(TemplateObjectTO template, Long maxDownloadSizeInBytes) { @@ -80,6 +83,7 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal setSecUrl(((NfsTO)_store).getUrl()); } this.maxDownloadSizeInBytes = maxDownloadSizeInBytes; + this.followRedirects = template.isFollowRedirects(); } public DownloadCommand(TemplateObjectTO template, String user, String passwd, Long maxDownloadSizeInBytes) { @@ -95,6 +99,7 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal _store = volume.getDataStore(); this.maxDownloadSizeInBytes = maxDownloadSizeInBytes; resourceType = ResourceType.VOLUME; + this.followRedirects = volume.isFollowRedirects(); } public DownloadCommand(SnapshotObjectTO snapshot, Long maxDownloadSizeInBytes, String url) { @@ -194,4 +199,12 @@ public class DownloadCommand extends AbstractDownloadCommand implements Internal public DataStoreTO getCacheStore() { return cacheStore; } + + public boolean isFollowRedirects() { + return followRedirects; + } + + public void setFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + } } diff --git a/core/src/main/java/org/apache/cloudstack/storage/to/DownloadableObjectTO.java b/core/src/main/java/org/apache/cloudstack/storage/to/DownloadableObjectTO.java new file mode 100644 index 00000000000..70db8fafffc --- /dev/null +++ b/core/src/main/java/org/apache/cloudstack/storage/to/DownloadableObjectTO.java @@ -0,0 +1,30 @@ +// 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 org.apache.cloudstack.storage.to; + +public class DownloadableObjectTO { + protected boolean followRedirects = false; + + public boolean isFollowRedirects() { + return followRedirects; + } + + public void setFollowRedirects(boolean followRedirects) { + this.followRedirects = followRedirects; + } +} diff --git a/core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java b/core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java index 70cb6d155b0..76b93909b8c 100644 --- a/core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java +++ b/core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java @@ -30,7 +30,7 @@ import com.cloud.agent.api.to.DataStoreTO; import com.cloud.agent.api.to.DataTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; -public class SnapshotObjectTO implements DataTO { +public class SnapshotObjectTO extends DownloadableObjectTO implements DataTO { private String path; private VolumeObjectTO volume; private String parentSnapshotPath; diff --git a/core/src/main/java/org/apache/cloudstack/storage/to/TemplateObjectTO.java b/core/src/main/java/org/apache/cloudstack/storage/to/TemplateObjectTO.java index a405785bf64..eafe8f83269 100644 --- a/core/src/main/java/org/apache/cloudstack/storage/to/TemplateObjectTO.java +++ b/core/src/main/java/org/apache/cloudstack/storage/to/TemplateObjectTO.java @@ -28,7 +28,7 @@ import com.cloud.hypervisor.Hypervisor; import com.cloud.storage.Storage.ImageFormat; import com.cloud.template.VirtualMachineTemplate; -public class TemplateObjectTO implements DataTO { +public class TemplateObjectTO extends DownloadableObjectTO implements DataTO { private String path; private String origUrl; private String uuid; @@ -87,6 +87,7 @@ public class TemplateObjectTO implements DataTO { this.deployAsIs = template.isDeployAsIs(); this.deployAsIsConfiguration = template.getDeployAsIsConfiguration(); this.directDownload = template.isDirectDownload(); + this.followRedirects = template.isFollowRedirects(); } @Override diff --git a/core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java b/core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java index 8473ea7a49e..2bb67c80ce4 100644 --- a/core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java +++ b/core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java @@ -33,7 +33,7 @@ import com.cloud.storage.Volume; import java.util.Arrays; -public class VolumeObjectTO implements DataTO { +public class VolumeObjectTO extends DownloadableObjectTO implements DataTO { private String uuid; private Volume.Type volumeType; private DataStoreTO dataStore; @@ -119,6 +119,7 @@ public class VolumeObjectTO implements DataTO { this.vSphereStoragePolicyId = volume.getvSphereStoragePolicyId(); this.passphrase = volume.getPassphrase(); this.encryptFormat = volume.getEncryptFormat(); + this.followRedirects = volume.isFollowRedirects(); } public String getUuid() { diff --git a/core/src/main/java/org/apache/cloudstack/transport/HypervisorTypeAdaptor.java b/core/src/main/java/org/apache/cloudstack/transport/HypervisorTypeAdaptor.java new file mode 100644 index 00000000000..bc4d3c3a6e3 --- /dev/null +++ b/core/src/main/java/org/apache/cloudstack/transport/HypervisorTypeAdaptor.java @@ -0,0 +1,53 @@ +// 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 org.apache.cloudstack.transport; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +/** + * {@link HypervisorType} acts as extendable set of singleton objects and should return same result when used "==" + * or {@link Object#equals(Object)}. + * To support that, need to return existing object for a given name instead of creating new. + */ +public class HypervisorTypeAdaptor implements JsonDeserializer, JsonSerializer { + @Override + public HypervisorType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + if (json instanceof JsonPrimitive && ((JsonPrimitive) json).isString()) { + return HypervisorType.valueOf(json.getAsString()); + } + return null; + } + + @Override + public JsonElement serialize(HypervisorType src, Type typeOfSrc, JsonSerializationContext context) { + String name = src.name(); + if (name == null) { + return new JsonNull(); + } + return new JsonPrimitive(name); + } +} diff --git a/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml b/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml index a36d1243155..49775fe41e1 100644 --- a/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml +++ b/core/src/main/resources/META-INF/cloudstack/core/spring-core-registry-core-context.xml @@ -350,4 +350,12 @@ + + + + + + + + diff --git a/core/src/main/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml b/core/src/main/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml index 8dbaf610581..2240d1f2606 100644 --- a/core/src/main/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml +++ b/core/src/main/resources/META-INF/cloudstack/network/spring-core-lifecycle-network-context-inheritable.xml @@ -103,4 +103,9 @@ + + + + + diff --git a/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java b/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java index 50c82a76455..1ce3cfb06b9 100644 --- a/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java +++ b/core/src/test/java/com/cloud/agent/api/SecurityGroupRulesCmdTest.java @@ -27,7 +27,7 @@ import java.util.Vector; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.api.SecurityGroupRulesCmd.IpPortAndProto; diff --git a/core/src/test/java/com/cloud/agent/transport/LoggingExclusionStrategyTest.java b/core/src/test/java/com/cloud/agent/transport/LoggingExclusionStrategyTest.java new file mode 100644 index 00000000000..e02fe4516ab --- /dev/null +++ b/core/src/test/java/com/cloud/agent/transport/LoggingExclusionStrategyTest.java @@ -0,0 +1,83 @@ +// 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.transport; + +import com.cloud.agent.api.BadCommand; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.GetStorageStatsCommand; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.ArrayList; +import java.util.List; + +@RunWith(MockitoJUnitRunner.class) +public class LoggingExclusionStrategyTest { + + @Mock + Logger loggerMock; + @Spy + @InjectMocks + LoggingExclusionStrategy loggingExclusionStrategySpy; + + @Test + public void shouldSkipClassTestArrayClazz() { + List array = new ArrayList<>(); + + boolean result = loggingExclusionStrategySpy.shouldSkipClass(array.getClass()); + + Assert.assertFalse(result); + } + + @Test + public void shouldSkipClassTestNotSubclassOfCommand() { + Integer integer = 1; + + boolean result = loggingExclusionStrategySpy.shouldSkipClass(integer.getClass()); + + Assert.assertFalse(result); + } + + @Test + public void shouldSkipClassTestNullClassAnnotation() { + Command cmd = new BadCommand(); + Mockito.doReturn(true).when(loggerMock).isEnabled(Level.DEBUG); + + boolean result = loggingExclusionStrategySpy.shouldSkipClass(cmd.getClass()); + + Assert.assertFalse(result); + } + + @Test + public void shouldSkipClassTestWithClassAnnotation() { + Command cmd = new GetStorageStatsCommand(); + Mockito.doReturn(true).when(loggerMock).isEnabled(Level.TRACE); + + boolean result = loggingExclusionStrategySpy.shouldSkipClass(cmd.getClass()); + + Assert.assertFalse(result); + } + +} diff --git a/core/src/test/java/com/cloud/agent/transport/RequestTest.java b/core/src/test/java/com/cloud/agent/transport/RequestTest.java index 21766ba038f..0fe42c7cede 100644 --- a/core/src/test/java/com/cloud/agent/transport/RequestTest.java +++ b/core/src/test/java/com/cloud/agent/transport/RequestTest.java @@ -22,8 +22,8 @@ package com.cloud.agent.transport; import java.nio.ByteBuffer; import junit.framework.TestCase; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.Assert; import org.mockito.Mockito; @@ -43,7 +43,6 @@ import com.cloud.agent.api.to.NfsTO; import com.cloud.agent.transport.Request.Version; import com.cloud.exception.UnsupportedVersionException; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.serializer.GsonHelper; import com.cloud.storage.DataStoreRole; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.TemplateType; @@ -58,47 +57,22 @@ import com.cloud.template.VirtualMachineTemplate; */ public class RequestTest extends TestCase { - private static final Logger s_logger = Logger.getLogger(RequestTest.class); + protected Logger logger = LogManager.getLogger(getClass()); public void testSerDeser() { - s_logger.info("Testing serializing and deserializing works as expected"); + logger.info("Testing serializing and deserializing works as expected"); - s_logger.info("UpdateHostPasswordCommand should have two parameters that doesn't show in logging"); + logger.info("UpdateHostPasswordCommand should have two parameters that doesn't show in logging"); UpdateHostPasswordCommand cmd1 = new UpdateHostPasswordCommand("abc", "def"); - s_logger.info("SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level"); + logger.info("SecStorageFirewallCfgCommand has a context map that shouldn't show up in debug level"); SecStorageFirewallCfgCommand cmd2 = new SecStorageFirewallCfgCommand(); - s_logger.info("GetHostStatsCommand should not show up at all in debug level"); + logger.info("GetHostStatsCommand should not show up at all in debug level"); GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101); cmd2.addPortConfig("abc", "24", true, "eth0"); cmd2.addPortConfig("127.0.0.1", "44", false, "eth1"); Request sreq = new Request(2, 3, new Command[] {cmd1, cmd2, cmd3}, true, true); sreq.setSequence(892403717); - Logger logger = Logger.getLogger(GsonHelper.class); - Level level = logger.getLevel(); - - logger.setLevel(Level.DEBUG); - String log = sreq.log("Debug", true, Level.DEBUG); - assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName())); - assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName())); - assert (!log.contains(GetHostStatsCommand.class.getSimpleName())); - assert (!log.contains("username")); - assert (!log.contains("password")); - - logger.setLevel(Level.TRACE); - log = sreq.log("Trace", true, Level.TRACE); - assert (log.contains(UpdateHostPasswordCommand.class.getSimpleName())); - assert (log.contains(SecStorageFirewallCfgCommand.class.getSimpleName())); - assert (log.contains(GetHostStatsCommand.class.getSimpleName())); - assert (!log.contains("username")); - assert (!log.contains("password")); - - logger.setLevel(Level.INFO); - log = sreq.log("Info", true, Level.INFO); - assert (log == null); - - logger.setLevel(level); - byte[] bytes = sreq.getBytes(); assert Request.getSequence(bytes) == 892403717; @@ -109,9 +83,9 @@ public class RequestTest extends TestCase { try { creq = Request.parse(bytes); } catch (ClassNotFoundException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } catch (UnsupportedVersionException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } assert creq != null : "Couldn't get the request back"; @@ -127,9 +101,9 @@ public class RequestTest extends TestCase { try { sresp = Response.parse(bytes); } catch (ClassNotFoundException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } catch (UnsupportedVersionException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } assert sresp != null : "Couldn't get the response back"; @@ -138,7 +112,7 @@ public class RequestTest extends TestCase { } public void testSerDeserTO() { - s_logger.info("Testing serializing and deserializing interface TO works as expected"); + logger.info("Testing serializing and deserializing interface TO works as expected"); NfsTO nfs = new NfsTO("nfs://192.168.56.10/opt/storage/secondary", DataStoreRole.Image); // SecStorageSetupCommand cmd = new SecStorageSetupCommand(nfs, "nfs://192.168.56.10/opt/storage/secondary", null); @@ -156,9 +130,9 @@ public class RequestTest extends TestCase { try { creq = Request.parse(bytes); } catch (ClassNotFoundException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } catch (UnsupportedVersionException e) { - s_logger.error("Unable to parse bytes: ", e); + logger.error("Unable to parse bytes: ", e); } assert creq != null : "Couldn't get the request back"; @@ -168,7 +142,7 @@ public class RequestTest extends TestCase { } public void testDownload() { - s_logger.info("Testing Download answer"); + logger.info("Testing Download answer"); VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class); Mockito.when(template.getId()).thenReturn(1L); Mockito.when(template.getFormat()).thenReturn(ImageFormat.QCOW2); @@ -193,7 +167,7 @@ public class RequestTest extends TestCase { } public void testCompress() { - s_logger.info("testCompress"); + logger.info("testCompress"); int len = 800000; ByteBuffer inputBuffer = ByteBuffer.allocate(len); for (int i = 0; i < len; i++) { @@ -202,7 +176,7 @@ public class RequestTest extends TestCase { inputBuffer.limit(len); ByteBuffer compressedBuffer = ByteBuffer.allocate(len); compressedBuffer = Request.doCompress(inputBuffer, len); - s_logger.info("compressed length: " + compressedBuffer.limit()); + logger.info("compressed length: " + compressedBuffer.limit()); ByteBuffer decompressedBuffer = ByteBuffer.allocate(len); decompressedBuffer = Request.doDecompress(compressedBuffer, len); for (int i = 0; i < len; i++) { @@ -212,29 +186,6 @@ public class RequestTest extends TestCase { } } - public void testLogging() { - s_logger.info("Testing Logging"); - GetHostStatsCommand cmd3 = new GetHostStatsCommand("hostguid", "hostname", 101); - Request sreq = new Request(2, 3, new Command[] {cmd3}, true, true); - sreq.setSequence(1); - Logger logger = Logger.getLogger(GsonHelper.class); - Level level = logger.getLevel(); - - logger.setLevel(Level.DEBUG); - String log = sreq.log("Debug", true, Level.DEBUG); - assert (log == null); - - log = sreq.log("Debug", false, Level.DEBUG); - assert (log != null); - - logger.setLevel(Level.TRACE); - log = sreq.log("Trace", true, Level.TRACE); - assert (log.contains(GetHostStatsCommand.class.getSimpleName())); - s_logger.debug(log); - - logger.setLevel(level); - } - protected void compareRequest(Request req1, Request req2) { assert req1.getSequence() == req2.getSequence(); assert req1.getAgentId() == req2.getAgentId(); @@ -253,24 +204,24 @@ public class RequestTest extends TestCase { } public void testGoodCommand() { - s_logger.info("Testing good Command"); + logger.info("Testing good Command"); String content = "[{\"com.cloud.agent.api.GetVolumeStatsCommand\":{\"volumeUuids\":[\"dcc860ac-4a20-498f-9cb3-bab4d57aa676\"]," - + "\"poolType\":\"NetworkFilesystem\",\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; + + "\"poolType\":{\"name\":\"NetworkFilesystem\"},\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; Request sreq = new Request(Version.v2, 1L, 2L, 3L, 1L, (short)1, content); sreq.setSequence(1); Command cmds[] = sreq.getCommands(); - s_logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); + logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); assert cmds[0].getClass().equals(GetVolumeStatsCommand.class); } public void testBadCommand() { - s_logger.info("Testing Bad Command"); + logger.info("Testing Bad Command"); String content = "[{\"com.cloud.agent.api.SomeJunkCommand\":{\"volumeUuids\":[\"dcc860ac-4a20-498f-9cb3-bab4d57aa676\"]," - + "\"poolType\":\"NetworkFilesystem\",\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; + + "\"poolType\":{\"name\":\"NetworkFilesystem\"},\"poolUuid\":\"e007c270-2b1b-3ce9-ae92-a98b94eef7eb\",\"contextMap\":{},\"wait\":5}}]"; Request sreq = new Request(Version.v2, 1L, 2L, 3L, 1L, (short)1, content); sreq.setSequence(1); Command cmds[] = sreq.getCommands(); - s_logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); + logger.debug("Command class = " + cmds[0].getClass().getSimpleName()); assert cmds[0].getClass().equals(BadCommand.class); } diff --git a/core/src/test/java/org/apache/cloudstack/direct/download/BaseDirectTemplateDownloaderTest.java b/core/src/test/java/org/apache/cloudstack/direct/download/BaseDirectTemplateDownloaderTest.java index 2c7245662a2..4b0f4cd9744 100644 --- a/core/src/test/java/org/apache/cloudstack/direct/download/BaseDirectTemplateDownloaderTest.java +++ b/core/src/test/java/org/apache/cloudstack/direct/download/BaseDirectTemplateDownloaderTest.java @@ -27,6 +27,7 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpHead; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.message.BasicStatusLine; +import org.junit.After; import org.junit.Before; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -56,11 +57,13 @@ public class BaseDirectTemplateDownloaderTest { private HttpEntity httpEntity; @InjectMocks - protected HttpsDirectTemplateDownloader httpsDownloader = new HttpsDirectTemplateDownloader(httpUrl, 1000, 1000, 1000); + protected HttpsDirectTemplateDownloader httpsDownloader = new HttpsDirectTemplateDownloader(httpUrl, 1000, 1000, 1000, false); + + private AutoCloseable closeable; @Before public void init() throws IOException { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); Mockito.when(httpsClient.execute(Mockito.any(HttpGet.class))).thenReturn(response); Mockito.when(httpsClient.execute(Mockito.any(HttpHead.class))).thenReturn(response); StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK"); @@ -69,4 +72,9 @@ public class BaseDirectTemplateDownloaderTest { ByteArrayInputStream inputStream = new ByteArrayInputStream(httpMetalinkContent.getBytes(StandardCharsets.UTF_8)); Mockito.when(httpEntity.getContent()).thenReturn(inputStream); } + + @After + public void tearDown() throws Exception { + closeable.close(); + } } diff --git a/core/src/test/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloaderTest.java b/core/src/test/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloaderTest.java index 68982fb915f..2fc0f7b00a0 100644 --- a/core/src/test/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloaderTest.java +++ b/core/src/test/java/org/apache/cloudstack/direct/download/MetalinkDirectTemplateDownloaderTest.java @@ -25,8 +25,7 @@ import org.mockito.InjectMocks; public class MetalinkDirectTemplateDownloaderTest extends BaseDirectTemplateDownloaderTest { @InjectMocks - protected MetalinkDirectTemplateDownloader metalinkDownloader = new MetalinkDirectTemplateDownloader(httpsUrl, 1000, 1000); - + protected MetalinkDirectTemplateDownloader metalinkDownloader = new MetalinkDirectTemplateDownloader(httpsUrl, 1000, 1000, false); @Test public void testCheckUrlMetalink() { metalinkDownloader.downloader = httpsDownloader; diff --git a/core/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/core/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/core/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/debian/changelog b/debian/changelog index 0b67488a7fe..cbc4fcfdb2d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,12 +1,18 @@ -cloudstack (4.19.0.0-SNAPSHOT) unstable; urgency=low +cloudstack (4.20.0.0-SNAPSHOT) unstable; urgency=low - * Update the version to 4.19.0.0-SNAPSHOT + * Update the version to 4.20.0.0-SNAPSHOT - -- the Apache CloudStack project Wed, 21 Jun 2023 12:31:00 +0200 + -- the Apache CloudStack project Mon, 29 Jan 2024 10:21:52 +0530 -cloudstack (4.18.1.0-SNAPSHOT) unstable; urgency=low +cloudstack (4.19.0.0) unstable; urgency=low - * Update the version to 4.18.1.0-SNAPSHOT + * Update the version to 4.19.0.0 + + -- the Apache CloudStack project Mon, 29 Jan 2024 10:21:52 +0530 + +cloudstack (4.18.1.0) unstable; urgency=low + + * Update the version to 4.18.1.0 -- the Apache CloudStack project Wed, 21 Jun 2023 12:30:00 +0200 diff --git a/debian/cloudstack-management.install b/debian/cloudstack-management.install index e637541076e..3d0d7e23814 100644 --- a/debian/cloudstack-management.install +++ b/debian/cloudstack-management.install @@ -35,4 +35,5 @@ /usr/bin/cloudstack-migrate-databases /usr/bin/cloudstack-setup-encryption /usr/bin/cloudstack-sysvmadm +/usr/bin/cmk /usr/share/cloudstack-management/* diff --git a/debian/cloudstack-management.postinst b/debian/cloudstack-management.postinst index 4527cbe068c..fadb7e57eca 100755 --- a/debian/cloudstack-management.postinst +++ b/debian/cloudstack-management.postinst @@ -57,7 +57,7 @@ if [ "$1" = configure ]; then chgrp cloud ${CONFDIR}/${DBPROPS} chown -R cloud:cloud /var/log/cloudstack/management - ln -sf ${CONFDIR}/log4j-cloud.xml ${CONFDIR}/log4j.xml + ln -sf ${CONFDIR}/log4j-cloud.xml ${CONFDIR}/log4j2.xml # Add jdbc MySQL driver settings to db.properties if not present grep -s -q "db.cloud.driver=jdbc:mysql" ${CONFDIR}/${DBPROPS} || sed -i -e "\$adb.cloud.driver=jdbc:mysql" ${CONFDIR}/${DBPROPS} diff --git a/debian/control b/debian/control index 9fec540975e..3508c7b5f75 100644 --- a/debian/control +++ b/debian/control @@ -17,14 +17,14 @@ Description: A common package which contains files which are shared by several C Package: cloudstack-management Architecture: all -Depends: ${python3:Depends}, openjdk-11-jre-headless | java11-runtime-headless | java11-runtime | openjdk-11-jre-headless | zulu-11, cloudstack-common (= ${source:Version}), net-tools, sudo, python3-mysql.connector, augeas-tools, mysql-client | mariadb-client, adduser, bzip2, ipmitool, file, gawk, iproute2, qemu-utils, rng-tools, python3-dnspython, lsb-release, init-system-helpers (>= 1.14~), python3-setuptools +Depends: ${python3:Depends}, openjdk-17-jre-headless | java17-runtime-headless | java17-runtime | zulu-17, cloudstack-common (= ${source:Version}), net-tools, sudo, python3-mysql.connector, augeas-tools, mysql-client | mariadb-client, adduser, bzip2, ipmitool, file, gawk, iproute2, qemu-utils, rng-tools, python3-dnspython, lsb-release, init-system-helpers (>= 1.14~), python3-setuptools Conflicts: cloud-server, cloud-client, cloud-client-ui Description: CloudStack server library The CloudStack management server Package: cloudstack-agent Architecture: all -Depends: ${python:Depends}, ${python3:Depends}, openjdk-11-jre-headless | java11-runtime-headless | java11-runtime | openjdk-11-jre-headless | zulu-11, cloudstack-common (= ${source:Version}), lsb-base (>= 9), openssh-client, qemu-kvm (>= 2.5) | qemu-system-x86 (>= 5.2), libvirt-bin (>= 1.3) | libvirt-daemon-system (>= 3.0), iproute2, ebtables, vlan, ipset, python3-libvirt, ethtool, iptables, cryptsetup, rng-tools, lsb-release, ufw, apparmor +Depends: ${python:Depends}, ${python3:Depends}, openjdk-17-jre-headless | java17-runtime-headless | java17-runtime | zulu-17, cloudstack-common (= ${source:Version}), lsb-base (>= 9), openssh-client, qemu-kvm (>= 2.5) | qemu-system-x86 (>= 5.2), libvirt-bin (>= 1.3) | libvirt-daemon-system (>= 3.0), iproute2, ebtables, vlan, ipset, python3-libvirt, ethtool, iptables, cryptsetup, rng-tools, lsb-release, ufw, apparmor Recommends: init-system-helpers Conflicts: cloud-agent, cloud-agent-libs, cloud-agent-deps, cloud-agent-scripts Description: CloudStack agent @@ -34,7 +34,7 @@ Description: CloudStack agent Package: cloudstack-usage Architecture: all -Depends: openjdk-11-jre-headless | java11-runtime-headless | java11-runtime | openjdk-11-jre-headless | zulu-11, cloudstack-common (= ${source:Version}), init-system-helpers +Depends: openjdk-17-jre-headless | java17-runtime-headless | java17-runtime | zulu-17, cloudstack-common (= ${source:Version}), init-system-helpers Description: CloudStack usage monitor The CloudStack usage monitor provides usage accounting across the entire cloud for cloud operators to charge based on usage parameters. diff --git a/debian/rules b/debian/rules index 2d07c5e5728..f8228e61e46 100755 --- a/debian/rules +++ b/debian/rules @@ -84,6 +84,10 @@ override_dh_auto_install: cp -r engine/schema/dist/systemvm-templates/* $(DESTDIR)/usr/share/$(PACKAGE)-management/templates/systemvm/ rm -rf $(DESTDIR)/usr/share/$(PACKAGE)-management/templates/systemvm/md5sum.txt + # Bundle cmk in cloudstack-management + wget https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64 -O $(DESTDIR)/usr/bin/cmk + chmod +x $(DESTDIR)/usr/bin/cmk + # nast hack for a couple of configuration files mv $(DESTDIR)/$(SYSCONFDIR)/$(PACKAGE)/server/cloudstack-limits.conf $(DESTDIR)/$(SYSCONFDIR)/security/limits.d/ mv $(DESTDIR)/$(SYSCONFDIR)/$(PACKAGE)/server/cloudstack-sudoers $(DESTDIR)/$(SYSCONFDIR)/sudoers.d/$(PACKAGE) diff --git a/developer/pom.xml b/developer/pom.xml index 44f9e56d017..a70e9153bb4 100644 --- a/developer/pom.xml +++ b/developer/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT @@ -112,8 +112,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j ${cs.mysql.version} @@ -180,8 +180,8 @@ 1.2.1 - mysql - mysql-connector-java + com.mysql + mysql-connector-j ${cs.mysql.version} @@ -238,8 +238,8 @@ 1.2.1 - mysql - mysql-connector-java + com.mysql + mysql-connector-j ${cs.mysql.version} diff --git a/engine/api/pom.xml b/engine/api/pom.xml index fb3ed5d2f8d..1112e6eff8b 100644 --- a/engine/api/pom.xml +++ b/engine/api/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml @@ -71,7 +71,7 @@ com.sun.xml.bind jaxb-impl - ${cs.jaxb.version} + ${cs.jaxb.impl.version} diff --git a/engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java b/engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java index 8cd67f25331..cbdd803c5b5 100644 --- a/engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java +++ b/engine/api/src/main/java/com/cloud/vm/VirtualMachineManager.java @@ -254,7 +254,7 @@ public interface VirtualMachineManager extends Manager { */ boolean unmanage(String vmUuid); - UserVm restoreVirtualMachine(long vmId, Long newTemplateId) throws ResourceUnavailableException, InsufficientCapacityException; + UserVm restoreVirtualMachine(long vmId, Long newTemplateId, Long rootDiskOfferingId, boolean expunge, Map details) throws ResourceUnavailableException, InsufficientCapacityException; boolean checkIfVmHasClusterWideVolumes(Long vmId); @@ -290,4 +290,6 @@ public interface VirtualMachineManager extends Manager { HashMap> getVmNetworkStatistics(long hostId, String hostName, Map vmMap); + Map getDiskOfferingSuitabilityForVm(long vmId, List diskOfferingIds); + } diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java b/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java index 6d7c540613b..110592161f9 100644 --- a/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java +++ b/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java @@ -20,6 +20,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import com.cloud.dc.DataCenter; import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey.Scope; @@ -49,6 +50,7 @@ import com.cloud.network.rules.LoadBalancerContainer.Scheme; import com.cloud.offering.NetworkOffering; import com.cloud.user.Account; import com.cloud.user.User; +import com.cloud.utils.fsm.NoTransitionException; import com.cloud.utils.Pair; import com.cloud.vm.Nic; import com.cloud.vm.NicProfile; @@ -103,6 +105,9 @@ public interface NetworkOrchestrationService { static final ConfigKey TUNGSTEN_ENABLED = new ConfigKey<>(Boolean.class, "tungsten.plugin.enable", "Advanced", "false", "Indicates whether to enable the Tungsten plugin", false, ConfigKey.Scope.Zone, null); + static final ConfigKey NSX_ENABLED = new ConfigKey<>(Boolean.class, "nsx.plugin.enable", "Advanced", "false", + "Indicates whether to enable the NSX plugin", false, ConfigKey.Scope.Zone, null); + List setupNetwork(Account owner, NetworkOffering offering, DeploymentPlan plan, String name, String displayText, boolean isDefault) throws ConcurrentOperationException; @@ -267,6 +272,8 @@ public interface NetworkOrchestrationService { Map finalizeServicesAndProvidersForNetwork(NetworkOffering offering, Long physicalNetworkId); + boolean stateTransitTo(Network network, Network.Event e) throws NoTransitionException; + List getProvidersForServiceInNetwork(Network network, Service service); StaticNatServiceProvider getStaticNatProviderForNetwork(Network network); @@ -338,7 +345,7 @@ public interface NetworkOrchestrationService { */ void cleanupNicDhcpDnsEntry(Network network, VirtualMachineProfile vmProfile, NicProfile nicProfile); - Pair importNic(final String macAddress, int deviceId, final Network network, final Boolean isDefaultNic, final VirtualMachine vm, final Network.IpAddresses ipAddresses, boolean forced) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException; + Pair importNic(final String macAddress, int deviceId, final Network network, final Boolean isDefaultNic, final VirtualMachine vm, final Network.IpAddresses ipAddresses, final DataCenter datacenter, boolean forced) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException; void unmanageNics(VirtualMachineProfile vm); } diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java b/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java index 01123401fac..8a9d5fed028 100644 --- a/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java +++ b/engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java @@ -130,6 +130,8 @@ public interface VolumeOrchestrationService { boolean canVmRestartOnAnotherServer(long vmId); + void saveVolumeDetails(Long diskOfferingId, Long volumeId); + /** * Allocate a volume or multiple volumes in case of template is registered with the 'deploy-as-is' option, allowing multiple disks */ @@ -153,7 +155,7 @@ public interface VolumeOrchestrationService { * @param type Type of the volume - ROOT, DATADISK, etc * @param name Name of the volume * @param offering DiskOffering for the volume - * @param size DiskOffering for the volume + * @param sizeInBytes size of the volume in bytes * @param minIops minimum IOPS for the disk, if not passed DiskOffering value will be used * @param maxIops maximum IOPS for the disk, if not passed DiskOffering value will be used * @param vm VirtualMachine this volume is attached to @@ -165,7 +167,7 @@ public interface VolumeOrchestrationService { * @param chainInfo chain info for the volume. Hypervisor specific. * @return DiskProfile of imported volume */ - DiskProfile importVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template, + DiskProfile importVolume(Type type, String name, DiskOffering offering, Long sizeInBytes, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template, Account owner, Long deviceId, Long poolId, String path, String chainInfo); DiskProfile updateImportedVolume(Type type, DiskOffering offering, VirtualMachine vm, VirtualMachineTemplate template, diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DownloadableDataInfo.java b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DownloadableDataInfo.java new file mode 100644 index 00000000000..63b0867d1ab --- /dev/null +++ b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/DownloadableDataInfo.java @@ -0,0 +1,24 @@ +// 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 org.apache.cloudstack.engine.subsystem.api.storage; + +public interface DownloadableDataInfo extends DataObject { + default public boolean isFollowRedirects() { + return true; + } +} diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java index f5812a106b8..2c7d3c60278 100644 --- a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java +++ b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java @@ -44,6 +44,10 @@ public interface PrimaryDataStoreDriver extends DataStoreDriver { void revokeAccess(DataObject dataObject, Host host, DataStore dataStore); + default boolean requiresAccessForMigration(DataObject dataObject) { + return false; + } + /** * intended for managed storage (cloud.storage_pool.managed = true) * if not managed, return volume.getSize() @@ -138,4 +142,19 @@ public interface PrimaryDataStoreDriver extends DataStoreDriver { boolean isStorageSupportHA(StoragePoolType type); void detachVolumeFromAllStorageNodes(Volume volume); + /** + * Data store driver needs its grantAccess() method called for volumes in order for them to be used with a host. + * @return true if we should call grantAccess() to use a volume + */ + default boolean volumesRequireGrantAccessWhenUsed() { + return false; + } + + /** + * Zone-wide data store supports using a volume across clusters without the need for data motion + * @return true if we don't need to data motion volumes across clusters for zone-wide use + */ + default boolean zoneWideVolumesAvailableWithoutClusterMotion() { + return false; + } } diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java index fde71fe0d4c..6a78f6fe253 100644 --- a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java +++ b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/StoragePoolAllocator.java @@ -52,9 +52,12 @@ public interface StoragePoolAllocator extends Adapter { * avoid * @param int returnUpTo (use -1 to return all possible pools) * @param boolean bypassStorageTypeCheck allows bypassing useLocalStorage check for provided DiskProfile when true + * @param String keyword if passed, will only return storage pools that contain this keyword in the name * @return List List of storage pools that are suitable for the * VM **/ + List allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword); + List allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck); diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java index 1d49e19d2da..3bd3100e84e 100644 --- a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java +++ b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java @@ -21,7 +21,7 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import com.cloud.template.VirtualMachineTemplate; import com.cloud.user.UserData; -public interface TemplateInfo extends DataObject, VirtualMachineTemplate { +public interface TemplateInfo extends DownloadableDataInfo, VirtualMachineTemplate { @Override String getUniqueName(); diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java index be16c20d173..19b852bd912 100644 --- a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java +++ b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java @@ -26,7 +26,7 @@ import com.cloud.storage.Storage; import com.cloud.storage.Volume; import com.cloud.vm.VirtualMachine; -public interface VolumeInfo extends DataObject, Volume { +public interface VolumeInfo extends DownloadableDataInfo, Volume { boolean isAttachedVM(); diff --git a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java index 2c12b70e9eb..7c4d56e12b9 100644 --- a/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java +++ b/engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java @@ -18,13 +18,13 @@ */ package org.apache.cloudstack.engine.subsystem.api.storage; -import com.cloud.agent.api.Answer; import java.util.Map; import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; import org.apache.cloudstack.framework.async.AsyncCallFuture; import org.apache.cloudstack.storage.command.CommandResult; +import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.exception.StorageAccessException; import com.cloud.host.Host; @@ -35,6 +35,9 @@ import com.cloud.user.Account; import com.cloud.utils.Pair; public interface VolumeService { + + String SNAPSHOT_ID = "SNAPSHOT_ID"; + class VolumeApiResult extends CommandResult { private final VolumeInfo volume; @@ -54,6 +57,8 @@ public interface VolumeService { void revokeAccess(DataObject dataObject, Host host, DataStore dataStore); + boolean requiresAccessForMigration(DataObject dataObject, DataStore dataStore); + /** * Creates the volume based on the given criteria * @@ -112,4 +117,8 @@ public interface VolumeService { VolumeInfo sourceVolume, VolumeInfo destinationVolume, boolean retryExpungeVolumeAsync); void moveVolumeOnSecondaryStorageToAnotherAccount(Volume volume, Account sourceAccount, Account destAccount); + + Pair checkAndRepairVolume(VolumeInfo volume); + + void checkAndRepairVolumeBasedOnConfig(DataObject dataObject, Host host); } diff --git a/engine/components-api/pom.xml b/engine/components-api/pom.xml index 93be1b5e445..b06b644d67f 100644 --- a/engine/components-api/pom.xml +++ b/engine/components-api/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java b/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java index 6ba0c3b4fa0..2182dfc542d 100644 --- a/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java +++ b/engine/components-api/src/main/java/com/cloud/agent/AgentManager.java @@ -47,6 +47,9 @@ public interface AgentManager { "according to the hosts health check results", true, ConfigKey.Scope.Cluster, null); + ConfigKey ReadyCommandWait = new ConfigKey("Advanced", Integer.class, "ready.command.wait", + "60", "Time in seconds to wait for Ready command to return", true); + public enum TapAgentsAction { Add, Del, Contains, } diff --git a/engine/components-api/src/main/java/com/cloud/configuration/ConfigurationManager.java b/engine/components-api/src/main/java/com/cloud/configuration/ConfigurationManager.java index 5343fb632b5..ebbae0b31c2 100644 --- a/engine/components-api/src/main/java/com/cloud/configuration/ConfigurationManager.java +++ b/engine/components-api/src/main/java/com/cloud/configuration/ConfigurationManager.java @@ -63,6 +63,9 @@ public interface ConfigurationManager { static final String VM_USERDATA_MAX_LENGTH_STRING = "vm.userdata.max.length"; static final ConfigKey VM_USERDATA_MAX_LENGTH = new ConfigKey<>("Advanced", Integer.class, VM_USERDATA_MAX_LENGTH_STRING, "32768", "Max length of vm userdata after base64 decoding. Default is 32768 and maximum is 1048576", true); + public static final ConfigKey AllowNonRFC1918CompliantIPs = new ConfigKey<>(Boolean.class, + "allow.non.rfc1918.compliant.ips", "Advanced", "false", + "Allows non-compliant RFC 1918 IPs for Shared, Isolated networks and VPCs", true, null); /** * @param offering @@ -97,7 +100,6 @@ public interface ConfigurationManager { // * @param volatileVm // * @param hostTag // * @param networkRate -// * TODO // * @param id // * @param useVirtualNetwork // * @param deploymentPlanner @@ -167,11 +169,9 @@ public interface ConfigurationManager { * @param zoneType * @param allocationState * @param networkDomain - * TODO * @param isSecurityGroupEnabled - * TODO - * @param ip6Dns1 TODO - * @param ip6Dns2 TODO + * @param ip6Dns1 + * @param ip6Dns2 * @return * @throws * @throws @@ -186,7 +186,7 @@ public interface ConfigurationManager { * * @param userId * @param vlanDbId - * @param caller TODO + * @param caller * @return success/failure */ boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller); @@ -197,30 +197,25 @@ public interface ConfigurationManager { /** * Creates a new network offering + * * @param name * @param displayText * @param trafficType * @param tags * @param specifyVlan * @param networkRate - * TODO * @param serviceProviderMap - * TODO * @param isDefault - * TODO * @param type - * TODO * @param systemOnly - * TODO * @param serviceOfferingId - * @param conserveMode - * ; + * @param conserveMode ; * @param specifyIpRanges - * TODO - * @param isPersistent - * ; - * @param details TODO + * @param isPersistent ; + * @param details * @param forVpc + * @param forTungsten + * @param forNsx * @param domainIds * @param zoneIds * @return network offering object @@ -230,10 +225,10 @@ public interface ConfigurationManager { Integer networkRate, Map> serviceProviderMap, boolean isDefault, Network.GuestType type, boolean systemOnly, Long serviceOfferingId, boolean conserveMode, Map> serviceCapabilityMap, boolean specifyIpRanges, boolean isPersistent, Map details, boolean egressDefaultPolicy, Integer maxconn, boolean enableKeepAlive, Boolean forVpc, - Boolean forTungsten, List domainIds, List zoneIds, boolean enableOffering, final NetUtils.InternetProtocol internetProtocol); + Boolean forTungsten, boolean forNsx, String mode, List domainIds, List zoneIds, boolean enableOffering, final NetUtils.InternetProtocol internetProtocol); Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, boolean forSystemVms, Long podId, String startIP, String endIP, - String vlanGateway, String vlanNetmask, String vlanId, boolean bypassVlanOverlapCheck, Domain domain, Account vlanOwner, String startIPv6, String endIPv6, String vlanIp6Gateway, String vlanIp6Cidr) + String vlanGateway, String vlanNetmask, String vlanId, boolean bypassVlanOverlapCheck, Domain domain, Account vlanOwner, String startIPv6, String endIPv6, String vlanIp6Gateway, String vlanIp6Cidr, boolean forNsx) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException; void createDefaultSystemNetworks(long zoneId) throws ConcurrentOperationException; @@ -281,4 +276,6 @@ public interface ConfigurationManager { Pair getConfigurationGroupAndSubGroup(String configName); List getConfigurationSubGroups(Long groupId); + + void validateExtraConfigInServiceOfferingDetail(String detailName); } diff --git a/engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java b/engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java index 1a2fab150a7..27f63c8c64b 100644 --- a/engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java +++ b/engine/components-api/src/main/java/com/cloud/event/UsageEventUtils.java @@ -26,7 +26,8 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; @@ -46,7 +47,7 @@ public class UsageEventUtils { private static UsageEventDao s_usageEventDao; private static AccountDao s_accountDao; private static DataCenterDao s_dcDao; - private static final Logger s_logger = Logger.getLogger(UsageEventUtils.class); + protected static Logger LOGGER = LogManager.getLogger(UsageEventUtils.class); protected static EventBus s_eventBus = null; protected static ConfigurationDao s_configDao; @@ -240,7 +241,7 @@ public class UsageEventUtils { try { s_eventBus.publish(event); } catch (EventBusException e) { - s_logger.warn("Failed to publish usage event on the event bus."); + LOGGER.warn("Failed to publish usage event on the event bus."); } } diff --git a/engine/components-api/src/main/java/com/cloud/network/NetworkStateListener.java b/engine/components-api/src/main/java/com/cloud/network/NetworkStateListener.java index 1e1251d8cdc..24be76e4d3b 100644 --- a/engine/components-api/src/main/java/com/cloud/network/NetworkStateListener.java +++ b/engine/components-api/src/main/java/com/cloud/network/NetworkStateListener.java @@ -27,7 +27,8 @@ import javax.inject.Inject; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.events.EventBus; import org.apache.cloudstack.framework.events.EventBusException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import com.cloud.event.EventCategory; @@ -44,7 +45,7 @@ public class NetworkStateListener implements StateListener networks, List networkACLItems); } diff --git a/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java b/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java index f5cf443211c..daeb4b19a18 100644 --- a/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java +++ b/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java @@ -199,6 +199,10 @@ public interface StorageManager extends StorageService { true, ConfigKey.Scope.Global, null); + static final ConfigKey DataStoreDownloadFollowRedirects = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, + Boolean.class, "store.download.follow.redirects", "false", + "Whether HTTP redirect is followed during store downloads for objects such as template, volume etc.", + true, ConfigKey.Scope.Global); ConfigKey HEURISTICS_SCRIPT_TIMEOUT = new ConfigKey<>("Advanced", Long.class, "heuristics.script.timeout", "3000", "The maximum runtime, in milliseconds, to execute the heuristic rule; if it is reached, a timeout will happen.", true); @@ -277,6 +281,8 @@ public interface StorageManager extends StorageService { CapacityVO getStoragePoolUsedStats(Long poolId, Long clusterId, Long podId, Long zoneId); + CapacityVO getStoragePoolUsedStats(Long zoneId, Long podId, Long clusterId, List poolIds); + List ListByDataCenterHypervisor(long datacenterId, HypervisorType type); List listByStoragePool(long storagePoolId); @@ -303,6 +309,9 @@ public interface StorageManager extends StorageService { boolean storagePoolHasEnoughIops(List> volumeDiskProfilePairs, StoragePool pool); + boolean storagePoolHasEnoughIops(Long requestedIops, StoragePool pool); + boolean storagePoolHasEnoughSpace(Long size, StoragePool pool); + boolean storagePoolHasEnoughSpace(List> volumeDiskProfilePairs, StoragePool pool); /** @@ -335,6 +344,8 @@ public interface StorageManager extends StorageService { boolean isStoragePoolCompliantWithStoragePolicy(List> volumes, StoragePool pool) throws StorageUnavailableException; + boolean isStoragePoolCompliantWithStoragePolicy(long diskOfferingId, StoragePool pool) throws StorageUnavailableException; + boolean registerHostListener(String providerUuid, HypervisorHostListener listener); boolean connectHostToSharedPool(long hostId, long poolId) throws StorageUnavailableException, StorageConflictException; diff --git a/engine/components-api/src/main/java/com/cloud/storage/StorageUtil.java b/engine/components-api/src/main/java/com/cloud/storage/StorageUtil.java index e59ec925748..40e4a0f3dfc 100644 --- a/engine/components-api/src/main/java/com/cloud/storage/StorageUtil.java +++ b/engine/components-api/src/main/java/com/cloud/storage/StorageUtil.java @@ -33,7 +33,7 @@ import com.cloud.storage.dao.VolumeDao; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.dao.VMInstanceDao; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; public class StorageUtil { @Inject private ClusterDao clusterDao; diff --git a/engine/components-api/src/main/java/com/cloud/vm/VirtualMachineProfileImpl.java b/engine/components-api/src/main/java/com/cloud/vm/VirtualMachineProfileImpl.java index bc689fef873..2d51c3c0870 100644 --- a/engine/components-api/src/main/java/com/cloud/vm/VirtualMachineProfileImpl.java +++ b/engine/components-api/src/main/java/com/cloud/vm/VirtualMachineProfileImpl.java @@ -26,7 +26,6 @@ import com.cloud.host.Host; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.element.NetworkElement; import com.cloud.offering.ServiceOffering; -import com.cloud.service.ServiceOfferingVO; import com.cloud.template.VirtualMachineTemplate; import com.cloud.template.VirtualMachineTemplate.BootloaderType; import com.cloud.user.Account; @@ -260,7 +259,8 @@ public class VirtualMachineProfileImpl implements VirtualMachineProfile { return _params; } - public void setServiceOffering(ServiceOfferingVO offering) { + @Override + public void setServiceOffering(ServiceOffering offering) { _offering = offering; } diff --git a/engine/components-api/src/main/java/com/cloud/vm/VmWork.java b/engine/components-api/src/main/java/com/cloud/vm/VmWork.java index a0b5e979524..11914cb3436 100644 --- a/engine/components-api/src/main/java/com/cloud/vm/VmWork.java +++ b/engine/components-api/src/main/java/com/cloud/vm/VmWork.java @@ -16,10 +16,26 @@ // under the License. package com.cloud.vm; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; + +import com.cloud.serializer.GsonHelper; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; public class VmWork implements Serializable { + protected transient Logger logger = LogManager.getLogger(getClass()); private static final long serialVersionUID = -6946320465729853589L; + private static final Gson gsonLogger = GsonHelper.getGsonLogger(); long userId; long accountId; @@ -56,4 +72,31 @@ public class VmWork implements Serializable { public String getHandlerName() { return handlerName; } + + @Override + public String toString() { + return gsonLogger.toJson(this); + } + + protected String toStringAfterRemoveParams(String paramsObjName, List params) { + String ObjJsonStr = gsonLogger.toJson(this); + if (StringUtils.isBlank(ObjJsonStr) || StringUtils.isBlank(paramsObjName) || CollectionUtils.isEmpty(params)) { + return ObjJsonStr; + } + + try { + Map ObjMap = new ObjectMapper().readValue(ObjJsonStr, HashMap.class); + if (ObjMap != null && ObjMap.containsKey(paramsObjName)) { + for (String param : params) { + ((Map)ObjMap.get(paramsObjName)).remove(param); + } + String resultJson = new ObjectMapper().writeValueAsString(ObjMap); + return resultJson; + } + } catch (final JsonProcessingException e) { + // Ignore json exception + } + + return ObjJsonStr; + } } diff --git a/engine/components-api/src/main/java/com/cloud/vm/VmWorkCheckAndRepairVolume.java b/engine/components-api/src/main/java/com/cloud/vm/VmWorkCheckAndRepairVolume.java new file mode 100644 index 00000000000..eaee4d19eb3 --- /dev/null +++ b/engine/components-api/src/main/java/com/cloud/vm/VmWorkCheckAndRepairVolume.java @@ -0,0 +1,42 @@ +// 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.vm; + +public class VmWorkCheckAndRepairVolume extends VmWork { + + private static final long serialVersionUID = 341816293003023824L; + + private Long volumeId; + + private String repair; + + public VmWorkCheckAndRepairVolume(long userId, long accountId, long vmId, String handlerName, + Long volumeId, String repair) { + super(userId, accountId, vmId, handlerName); + this.repair = repair; + this.volumeId = volumeId; + } + + public Long getVolumeId() { + return volumeId; + } + + public String getRepair() { + return repair; + } +} diff --git a/engine/components-api/src/main/java/com/cloud/vm/VmWorkJobHandlerProxy.java b/engine/components-api/src/main/java/com/cloud/vm/VmWorkJobHandlerProxy.java index ce10a83c7cd..c82edc70ded 100644 --- a/engine/components-api/src/main/java/com/cloud/vm/VmWorkJobHandlerProxy.java +++ b/engine/components-api/src/main/java/com/cloud/vm/VmWorkJobHandlerProxy.java @@ -21,15 +21,14 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; - -import com.google.gson.Gson; - import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper; import org.apache.cloudstack.jobs.JobInfo; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.cloud.serializer.GsonHelper; import com.cloud.utils.Pair; +import com.google.gson.Gson; /** * VmWorkJobHandlerProxy can not be used as standalone due to run-time @@ -40,7 +39,7 @@ import com.cloud.utils.Pair; */ public class VmWorkJobHandlerProxy implements VmWorkJobHandler { - private static final Logger s_logger = Logger.getLogger(VmWorkJobHandlerProxy.class); + protected Logger logger = LogManager.getLogger(getClass()); private Object _target; private Map, Method> _handlerMethodMap = new HashMap, Method>(); @@ -101,30 +100,30 @@ public class VmWorkJobHandlerProxy implements VmWorkJobHandler { if (method != null) { try { - if (s_logger.isDebugEnabled()) - s_logger.debug("Execute VM work job: " + work.getClass().getName() + _gsonLogger.toJson(work)); + if (logger.isDebugEnabled()) + logger.debug("Execute VM work job: " + work.getClass().getName() + work); Object obj = method.invoke(_target, work); - if (s_logger.isDebugEnabled()) - s_logger.debug("Done executing VM work job: " + work.getClass().getName() + _gsonLogger.toJson(work)); + if (logger.isDebugEnabled()) + logger.debug("Done executing VM work job: " + work.getClass().getName() + work); assert (obj instanceof Pair); return (Pair)obj; } catch (InvocationTargetException e) { - s_logger.error("Invocation exception, caused by: " + e.getCause()); + logger.error("Invocation exception, caused by: " + e.getCause()); // legacy CloudStack code relies on checked exception for error handling // we need to re-throw the real exception here if (e.getCause() != null && e.getCause() instanceof Exception) { - s_logger.info("Rethrow exception " + e.getCause()); + logger.info("Rethrow exception " + e.getCause()); throw (Exception)e.getCause(); } throw e; } } else { - s_logger.error("Unable to find handler for VM work job: " + work.getClass().getName() + _gsonLogger.toJson(work)); + logger.error("Unable to find handler for VM work job: " + work.getClass().getName() + _gsonLogger.toJson(work)); RuntimeException ex = new RuntimeException("Unable to find handler for VM work job: " + work.getClass().getName()); return new Pair(JobInfo.Status.FAILED, JobSerializerHelper.toObjectSerializedString(ex)); diff --git a/engine/orchestration/pom.xml b/engine/orchestration/pom.xml index e5eeb88f6c5..e4953fc0cbe 100755 --- a/engine/orchestration/pom.xml +++ b/engine/orchestration/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentAttache.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentAttache.java index b12a72136dd..1b7069c6e73 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentAttache.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentAttache.java @@ -34,7 +34,8 @@ import java.util.concurrent.TimeUnit; import com.cloud.agent.api.CleanupPersistentNetworkResourceCommand; import org.apache.cloudstack.agent.lb.SetupMSListCommand; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.Listener; import com.cloud.agent.api.Answer; @@ -69,7 +70,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory; * AgentAttache provides basic commands to be implemented. */ public abstract class AgentAttache { - private static final Logger s_logger = Logger.getLogger(AgentAttache.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final ScheduledExecutorService s_listenerExecutor = Executors.newScheduledThreadPool(10, new NamedThreadFactory("ListenerTimer")); private static final Random s_rand = new Random(System.currentTimeMillis()); @@ -196,8 +197,8 @@ public abstract class AgentAttache { } protected synchronized void cancel(final long seq) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Cancelling.")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Cancelling.")); } final Listener listener = _waitForList.remove(seq); if (listener != null) { @@ -222,8 +223,8 @@ public abstract class AgentAttache { } protected void registerListener(final long seq, final Listener listener) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(log(seq, "Registering listener")); + if (logger.isTraceEnabled()) { + logger.trace(log(seq, "Registering listener")); } if (listener.getTimeout() != -1) { s_listenerExecutor.schedule(new Alarm(seq), listener.getTimeout(), TimeUnit.SECONDS); @@ -232,8 +233,8 @@ public abstract class AgentAttache { } protected Listener unregisterListener(final long sequence) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(log(sequence, "Unregistering listener")); + if (logger.isTraceEnabled()) { + logger.trace(log(sequence, "Unregistering listener")); } return _waitForList.remove(sequence); } @@ -266,7 +267,7 @@ public abstract class AgentAttache { final Listener monitor = entry.getValue(); if (!monitor.isRecurring()) { //TODO - remove this debug statement later - s_logger.debug("Listener is " + entry.getValue() + " waiting on " + entry.getKey()); + logger.debug("Listener is " + entry.getValue() + " waiting on " + entry.getKey()); nonRecurringListenersList.add(monitor); } } @@ -289,13 +290,13 @@ public abstract class AgentAttache { if (answers[0] != null && answers[0].getResult()) { processed = true; } - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Unable to find listener.")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Unable to find listener.")); } } else { processed = monitor.processAnswers(_id, seq, answers); - if (s_logger.isTraceEnabled()) { - s_logger.trace(log(seq, (processed ? "" : " did not ") + " processed ")); + if (logger.isTraceEnabled()) { + logger.trace(log(seq, (processed ? "" : " did not ") + " processed ")); } if (!monitor.isRecurring()) { @@ -323,8 +324,8 @@ public abstract class AgentAttache { final Map.Entry entry = it.next(); it.remove(); final Listener monitor = entry.getValue(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(entry.getKey(), "Sending disconnect to " + monitor.getClass())); + if (logger.isDebugEnabled()) { + logger.debug(log(entry.getKey(), "Sending disconnect to " + monitor.getClass())); } monitor.processDisconnect(_id, state); } @@ -356,8 +357,8 @@ public abstract class AgentAttache { long seq = req.getSequence(); if (listener != null) { registerListener(seq, listener); - } else if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Routed from " + req.getManagementServerId())); + } else if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Routed from " + req.getManagementServerId())); } synchronized (this) { @@ -380,16 +381,16 @@ public abstract class AgentAttache { if (req.executeInSequence() && _currentSequence == null) { _currentSequence = seq; - if (s_logger.isTraceEnabled()) { - s_logger.trace(log(seq, " is current sequence")); + if (logger.isTraceEnabled()) { + logger.trace(log(seq, " is current sequence")); } } } catch (AgentUnavailableException e) { - s_logger.info(log(seq, "Unable to send due to " + e.getMessage())); + logger.info(log(seq, "Unable to send due to " + e.getMessage())); cancel(seq); throw e; } catch (Exception e) { - s_logger.warn(log(seq, "Unable to send due to "), e); + logger.warn(log(seq, "Unable to send due to "), e); cancel(seq); throw new AgentUnavailableException("Problem due to other exception " + e.getMessage(), _id); } @@ -408,10 +409,10 @@ public abstract class AgentAttache { try { answers = sl.waitFor(wait); } catch (final InterruptedException e) { - s_logger.debug(log(seq, "Interrupted")); + logger.debug(log(seq, "Interrupted")); } if (answers != null) { - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { new Response(req, answers).logD("Received: ", false); } return answers; @@ -419,7 +420,7 @@ public abstract class AgentAttache { answers = sl.getAnswers(); // Try it again. if (answers != null) { - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { new Response(req, answers).logD("Received after timeout: ", true); } @@ -429,21 +430,21 @@ public abstract class AgentAttache { final Long current = _currentSequence; if (current != null && seq != current) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Waited too long.")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Waited too long.")); } throw new OperationTimedoutException(req.getCommands(), _id, seq, wait, false); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Waiting some more time because this is the current command")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Waiting some more time because this is the current command")); } } throw new OperationTimedoutException(req.getCommands(), _id, seq, wait * 2, true); } catch (OperationTimedoutException e) { - s_logger.warn(log(seq, "Timed out on " + req.toString())); + logger.warn(log(seq, "Timed out on " + req.toString())); cancel(seq); final Long current = _currentSequence; if (req.executeInSequence() && (current != null && current == seq)) { @@ -451,7 +452,7 @@ public abstract class AgentAttache { } throw e; } catch (Exception e) { - s_logger.warn(log(seq, "Exception while waiting for answer"), e); + logger.warn(log(seq, "Exception while waiting for answer"), e); cancel(seq); final Long current = _currentSequence; if (req.executeInSequence() && (current != null && current == seq)) { @@ -466,21 +467,21 @@ public abstract class AgentAttache { protected synchronized void sendNext(final long seq) { _currentSequence = null; if (_requests.isEmpty()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "No more commands found")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "No more commands found")); } return; } Request req = _requests.pop(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(req.getSequence(), "Sending now. is current sequence.")); + if (logger.isDebugEnabled()) { + logger.debug(log(req.getSequence(), "Sending now. is current sequence.")); } try { send(req); } catch (AgentUnavailableException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(req.getSequence(), "Unable to send the next sequence")); + if (logger.isDebugEnabled()) { + logger.debug(log(req.getSequence(), "Unable to send the next sequence")); } cancel(req.getSequence()); } @@ -527,7 +528,7 @@ public abstract class AgentAttache { listener.processTimeout(_id, _seq); } } catch (Exception e) { - s_logger.warn("Exception ", e); + logger.warn("Exception ", e); } } } diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java index 023f9c18e0a..50c7b151d77 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java @@ -53,8 +53,6 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao; import org.apache.cloudstack.utils.identity.ManagementServerNode; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; -import org.apache.log4j.MDC; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -124,12 +122,12 @@ import com.cloud.utils.nio.NioServer; import com.cloud.utils.nio.Task; import com.cloud.utils.time.InaccurateClock; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.ThreadContext; /** * Implementation of the Agent Manager. This class controls the connection to the agents. **/ public class AgentManagerImpl extends ManagerBase implements AgentManager, HandlerFactory, Configurable { - protected static final Logger s_logger = Logger.getLogger(AgentManagerImpl.class); /** * _agents is a ConcurrentHashMap, but it is used from within a synchronized block. This will be reported by findbugs as JLM_JSR166_UTILCONCURRENT_MONITORENTER. Maybe a @@ -210,12 +208,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override public boolean configure(final String name, final Map params) throws ConfigurationException { - s_logger.info("Ping Timeout is " + mgmtServiceConf.getPingTimeout()); + logger.info("Ping Timeout is " + mgmtServiceConf.getPingTimeout()); final int threads = DirectAgentLoadSize.value(); _nodeId = ManagementServerNode.getManagementServerId(); - s_logger.info("Configuring AgentManagerImpl. management server node id(msid): " + _nodeId); + logger.info("Configuring AgentManagerImpl. management server node id(msid): " + _nodeId); final long lastPing = (System.currentTimeMillis() >> 10) - mgmtServiceConf.getTimeout(); _hostDao.markHostsAsDisconnected(_nodeId, lastPing); @@ -231,13 +229,13 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl _connectExecutor.allowCoreThreadTimeOut(true); _connection = new NioServer("AgentManager", Port.value(), Workers.value() + 10, this, caService); - s_logger.info("Listening on " + Port.value() + " with " + Workers.value() + " workers"); + logger.info("Listening on " + Port.value() + " with " + Workers.value() + " workers"); // executes all agent commands other than cron and ping _directAgentExecutor = new ScheduledThreadPoolExecutor(DirectAgentPoolSize.value(), new NamedThreadFactory("DirectAgent")); // executes cron and ping agent commands _cronJobExecutor = new ScheduledThreadPoolExecutor(DirectAgentPoolSize.value(), new NamedThreadFactory("DirectAgentCronJob")); - s_logger.debug("Created DirectAgentAttache pool with size: " + DirectAgentPoolSize.value()); + logger.debug("Created DirectAgentAttache pool with size: " + DirectAgentPoolSize.value()); _directAgentThreadCap = Math.round(DirectAgentPoolSize.value() * DirectAgentThreadCap.value()) + 1; // add 1 to always make the value > 0 _monitorExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("AgentMonitor")); @@ -268,8 +266,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl _cmdMonitors.add(new Pair(_monitorId, listener)); } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Registering listener " + listener.getClass().getSimpleName() + " with id " + _monitorId); + if (logger.isDebugEnabled()) { + logger.debug("Registering listener " + listener.getClass().getSimpleName() + " with id " + _monitorId); } return _monitorId; } @@ -290,7 +288,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override public void unregisterForHostEvents(final int id) { - s_logger.debug("Deregistering " + id); + logger.debug("Deregistering " + id); _hostMonitors.remove(id); } @@ -305,15 +303,15 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } } - s_logger.warn("No handling of agent control command: " + cmd + " sent from " + attache.getId()); + logger.warn("No handling of agent control command: " + cmd + " sent from " + attache.getId()); return new AgentControlAnswer(cmd); } public void handleCommands(final AgentAttache attache, final long sequence, final Command[] cmds) { for (final Pair listener : _cmdMonitors) { final boolean processed = listener.second().processCommands(attache.getId(), sequence, cmds); - if (s_logger.isTraceEnabled()) { - s_logger.trace("SeqA " + attache.getId() + "-" + sequence + ": " + (processed ? "processed" : "not processed") + " by " + listener.getClass()); + if (logger.isTraceEnabled()) { + logger.trace("SeqA " + attache.getId() + "-" + sequence + ": " + (processed ? "processed" : "not processed") + " by " + listener.getClass()); } } } @@ -350,9 +348,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } catch (final Exception e) { String errorMsg = String.format("Error sending command %s to host %s, due to %s", cmd.getClass().getName(), host.getUuid(), e.getLocalizedMessage()); - s_logger.error(errorMsg); - if (s_logger.isDebugEnabled()) { - s_logger.debug(errorMsg, e); + logger.error(errorMsg); + if (logger.isDebugEnabled()) { + logger.debug(errorMsg, e); } } if (answer != null) { @@ -374,7 +372,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } if (answers != null && answers[0] instanceof UnsupportedAnswer) { - s_logger.warn("Unsupported Command: " + answers[0].getDetails()); + logger.warn("Unsupported Command: " + answers[0].getDetails()); return answers[0]; } @@ -398,7 +396,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl cmd.setContextParam("job", "job-" + job.getId()); } } - String logcontextid = (String) MDC.get("logcontextid"); + String logcontextid = ThreadContext.get("logcontextid"); if (StringUtils.isNotEmpty(logcontextid)) { cmd.setContextParam("logid", logcontextid); } @@ -471,14 +469,14 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl final Long hostId = agent.getId(); final HostVO host = _hostDao.findById(hostId); if (host != null && host.getType() != null && !host.getType().isVirtual()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("checking if agent (" + hostId + ") is alive"); + if (logger.isDebugEnabled()) { + logger.debug("checking if agent (" + hostId + ") is alive"); } final Answer answer = easySend(hostId, new CheckHealthCommand()); if (answer != null && answer.getResult()) { final Status status = Status.Up; - if (s_logger.isDebugEnabled()) { - s_logger.debug("agent (" + hostId + ") responded to checkHeathCommand, reporting that agent is " + status); + if (logger.isDebugEnabled()) { + logger.debug("agent (" + hostId + ") responded to checkHeathCommand, reporting that agent is " + status); } return status; } @@ -493,7 +491,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } final AgentAttache agent = findAttache(hostId); if (agent == null) { - s_logger.debug("Unable to find agent for " + hostId); + logger.debug("Unable to find agent for " + hostId); throw new AgentUnavailableException("Unable to find agent ", hostId); } @@ -521,8 +519,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl return; } final long hostId = attache.getId(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Remove Agent : " + hostId); + if (logger.isDebugEnabled()) { + logger.debug("Remove Agent : " + hostId); } AgentAttache removed = null; boolean conflict = false; @@ -535,15 +533,15 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } } if (conflict) { - s_logger.debug("Agent for host " + hostId + " is created when it is being disconnected"); + logger.debug("Agent for host " + hostId + " is created when it is being disconnected"); } if (removed != null) { removed.disconnect(nextState); } for (final Pair monitor : _hostMonitors) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending Disconnect to listener: " + monitor.second().getClass().getName()); + if (logger.isDebugEnabled()) { + logger.debug("Sending Disconnect to listener: " + monitor.second().getClass().getName()); } monitor.second().processDisconnect(hostId, nextState); } @@ -552,8 +550,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override public void notifyMonitorsOfNewlyAddedHost(long hostId) { for (final Pair monitor : _hostMonitors) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending host added to listener: " + monitor.second().getClass().getSimpleName()); + if (logger.isDebugEnabled()) { + logger.debug("Sending host added to listener: " + monitor.second().getClass().getSimpleName()); } monitor.second().processHostAdded(hostId); @@ -564,8 +562,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl final long hostId = attache.getId(); final HostVO host = _hostDao.findById(hostId); for (final Pair monitor : _hostMonitors) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending Connect to listener: " + monitor.second().getClass().getSimpleName()); + if (logger.isDebugEnabled()) { + logger.debug("Sending Connect to listener: " + monitor.second().getClass().getSimpleName()); } for (int i = 0; i < cmd.length; i++) { try { @@ -574,11 +572,11 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl if (e instanceof ConnectionException) { final ConnectionException ce = (ConnectionException)e; if (ce.isSetupError()) { - s_logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage()); + logger.warn("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage()); handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true); throw ce; } else { - s_logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage()); + logger.info("Monitor " + monitor.second().getClass().getSimpleName() + " says not to continue the connect process for " + hostId + " due to " + e.getMessage()); handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true); return attache; } @@ -586,7 +584,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl handleDisconnectWithoutInvestigation(attache, Event.ShutdownRequested, true, true); throw new CloudRuntimeException("Unable to connect " + attache.getId(), e); } else { - s_logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e); + logger.error("Monitor " + monitor.second().getClass().getSimpleName() + " says there is an error in the connect process for " + hostId + " due to " + e.getMessage(), e); handleDisconnectWithoutInvestigation(attache, Event.AgentDisconnected, true, true); throw new CloudRuntimeException("Unable to connect " + attache.getId(), e); } @@ -596,6 +594,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl final Long dcId = host.getDataCenterId(); final ReadyCommand ready = new ReadyCommand(dcId, host.getId(), NumbersUtil.enableHumanReadableSizes); + ready.setWait(ReadyCommandWait.value()); final Answer answer = easySend(hostId, ready); if (answer == null || !answer.getResult()) { // this is tricky part for secondary storage @@ -608,7 +607,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl Map detailsMap = readyAnswer.getDetailsMap(); if (detailsMap != null) { String uefiEnabled = detailsMap.get(Host.HOST_UEFI_ENABLE); - s_logger.debug(String.format("Got HOST_UEFI_ENABLE [%s] for hostId [%s]:", uefiEnabled, host.getUuid())); + logger.debug(String.format("Got HOST_UEFI_ENABLE [%s] for hostId [%s]:", uefiEnabled, host.getUuid())); if (uefiEnabled != null) { _hostDao.loadDetails(host); if (!uefiEnabled.equals(host.getDetails().get(Host.HOST_UEFI_ENABLE))) { @@ -632,7 +631,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl try { _connection.start(); } catch (final NioConnectionException e) { - s_logger.error("Error when connecting to the NioServer!", e); + logger.error("Error when connecting to the NioServer!", e); } } @@ -656,19 +655,19 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl final Constructor constructor = clazz.getConstructor(); resource = (ServerResource)constructor.newInstance(); } catch (final ClassNotFoundException e) { - s_logger.warn("Unable to find class " + host.getResource(), e); + logger.warn("Unable to find class " + host.getResource(), e); } catch (final InstantiationException e) { - s_logger.warn("Unable to instantiate class " + host.getResource(), e); + logger.warn("Unable to instantiate class " + host.getResource(), e); } catch (final IllegalAccessException e) { - s_logger.warn("Illegal access " + host.getResource(), e); + logger.warn("Illegal access " + host.getResource(), e); } catch (final SecurityException e) { - s_logger.warn("Security error on " + host.getResource(), e); + logger.warn("Security error on " + host.getResource(), e); } catch (final NoSuchMethodException e) { - s_logger.warn("NoSuchMethodException error on " + host.getResource(), e); + logger.warn("NoSuchMethodException error on " + host.getResource(), e); } catch (final IllegalArgumentException e) { - s_logger.warn("IllegalArgumentException error on " + host.getResource(), e); + logger.warn("IllegalArgumentException error on " + host.getResource(), e); } catch (final InvocationTargetException e) { - s_logger.warn("InvocationTargetException error on " + host.getResource(), e); + logger.warn("InvocationTargetException error on " + host.getResource(), e); } if (resource != null) { @@ -702,12 +701,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl try { resource.configure(host.getName(), params); } catch (final ConfigurationException e) { - s_logger.warn("Unable to configure resource due to " + e.getMessage()); + logger.warn("Unable to configure resource due to " + e.getMessage()); return null; } if (!resource.start()) { - s_logger.warn("Unable to start the resource"); + logger.warn("Unable to start the resource"); return null; } } @@ -725,14 +724,14 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl // load the respective discoverer final Discoverer discoverer = _resourceMgr.getMatchingDiscover(host.getHypervisorType()); if (discoverer == null) { - s_logger.info("Could not to find a Discoverer to load the resource: " + host.getId() + " for hypervisor type: " + host.getHypervisorType()); + logger.info("Could not to find a Discoverer to load the resource: " + host.getId() + " for hypervisor type: " + host.getHypervisorType()); resource = loadResourcesWithoutHypervisor(host); } else { resource = discoverer.reloadResource(host); } if (resource == null) { - s_logger.warn("Unable to load the resource: " + host.getId()); + logger.warn("Unable to load the resource: " + host.getId()); return false; } @@ -758,7 +757,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } protected AgentAttache createAttacheForDirectConnect(final Host host, final ServerResource resource) throws ConnectionException { - s_logger.debug("create DirectAgentAttache for " + host.getId()); + logger.debug("create DirectAgentAttache for " + host.getId()); final DirectAgentAttache attache = new DirectAgentAttache(this, host.getId(), host.getName(), resource, host.isInMaintenanceStates()); AgentAttache old = null; @@ -779,13 +778,13 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl _connection.stop(); } - s_logger.info("Disconnecting agents: " + _agents.size()); + logger.info("Disconnecting agents: " + _agents.size()); synchronized (_agents) { for (final AgentAttache agent : _agents.values()) { final HostVO host = _hostDao.findById(agent.getId()); if (host == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cant not find host " + agent.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Cant not find host " + agent.getId()); } } else { if (!agent.forForward()) { @@ -804,8 +803,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl final Status currentStatus = host.getStatus(); Status nextStatus; if (currentStatus == Status.Down || currentStatus == Status.Alert || currentStatus == Status.Removed) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Host %s is already %s", host.getUuid(), currentStatus)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Host %s is already %s", host.getUuid(), currentStatus)); } nextStatus = currentStatus; } else { @@ -813,12 +812,12 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl nextStatus = currentStatus.getNextStatus(event); } catch (final NoTransitionException e) { final String err = String.format("Cannot find next status for %s as current status is %s for agent %s", event, currentStatus, host.getUuid()); - s_logger.debug(err); + logger.debug(err); throw new CloudRuntimeException(err); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("The next status of agent %s is %s, current status is %s", host.getUuid(), nextStatus, currentStatus)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("The next status of agent %s is %s, current status is %s", host.getUuid(), nextStatus, currentStatus)); } } return nextStatus; @@ -831,19 +830,19 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl GlobalLock joinLock = getHostJoinLock(hostId); if (joinLock.lock(60)) { try { - s_logger.info(String.format("Host %d is disconnecting with event %s", hostId, event)); + logger.info(String.format("Host %d is disconnecting with event %s", hostId, event)); Status nextStatus = null; final HostVO host = _hostDao.findById(hostId); if (host == null) { - s_logger.warn(String.format("Can't find host with %d", hostId)); + logger.warn(String.format("Can't find host with %d", hostId)); nextStatus = Status.Removed; } else { nextStatus = getNextStatusOnDisconnection(host, event); caService.purgeHostCertificate(host); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Deregistering link for %d with state %s", hostId, nextStatus)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Deregistering link for %d with state %s", hostId, nextStatus)); } removeAgent(attache, nextStatus); @@ -874,50 +873,50 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl * Agent may be currently in status of Down, Alert, Removed, namely there is no next status for some events. Why this can happen? Ask God not me. I hate there was * no piece of comment for code handling race condition. God knew what race condition the code dealt with! */ - s_logger.debug("Caught exception while getting agent's next status", ne); + logger.debug("Caught exception while getting agent's next status", ne); } if (nextStatus == Status.Alert) { /* OK, we are going to the bad status, let's see what happened */ - s_logger.info("Investigating why host " + hostId + " has disconnected with event " + event); + logger.info("Investigating why host " + hostId + " has disconnected with event " + event); Status determinedState = investigate(attache); // if state cannot be determined do nothing and bail out if (determinedState == null) { if ((System.currentTimeMillis() >> 10) - host.getLastPinged() > AlertWait.value()) { - s_logger.warn("Agent " + hostId + " state cannot be determined for more than " + AlertWait + "(" + AlertWait.value() + ") seconds, will go to Alert state"); + logger.warn("Agent " + hostId + " state cannot be determined for more than " + AlertWait + "(" + AlertWait.value() + ") seconds, will go to Alert state"); determinedState = Status.Alert; } else { - s_logger.warn("Agent " + hostId + " state cannot be determined, do nothing"); + logger.warn("Agent " + hostId + " state cannot be determined, do nothing"); return false; } } final Status currentStatus = host.getStatus(); - s_logger.info("The agent from host " + hostId + " state determined is " + determinedState); + logger.info("The agent from host " + hostId + " state determined is " + determinedState); if (determinedState == Status.Down) { final String message = "Host is down: " + host.getId() + "-" + host.getName() + ". Starting HA on the VMs"; - s_logger.error(message); + logger.error(message); if (host.getType() != Host.Type.SecondaryStorage && host.getType() != Host.Type.ConsoleProxy) { _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host down, " + host.getId(), message); } event = Status.Event.HostDown; } else if (determinedState == Status.Up) { /* Got ping response from host, bring it back */ - s_logger.info("Agent is determined to be up and running"); + logger.info("Agent is determined to be up and running"); agentStatusTransitTo(host, Status.Event.Ping, _nodeId); return false; } else if (determinedState == Status.Disconnected) { - s_logger.warn("Agent is disconnected but the host is still up: " + host.getId() + "-" + host.getName() + + logger.warn("Agent is disconnected but the host is still up: " + host.getId() + "-" + host.getName() + '-' + host.getResourceState()); if (currentStatus == Status.Disconnected || (currentStatus == Status.Up && host.getResourceState() == ResourceState.PrepareForMaintenance)) { if ((System.currentTimeMillis() >> 10) - host.getLastPinged() > AlertWait.value()) { - s_logger.warn("Host " + host.getId() + " has been disconnected past the wait time it should be disconnected."); + logger.warn("Host " + host.getId() + " has been disconnected past the wait time it should be disconnected."); event = Status.Event.WaitedTooLong; } else { - s_logger.debug("Host " + host.getId() + " has been determined to be disconnected but it hasn't passed the wait time yet."); + logger.debug("Host " + host.getId() + " has been determined to be disconnected but it hasn't passed the wait time yet."); return false; } } else if (currentStatus == Status.Up) { @@ -940,7 +939,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl "In availability zone " + host.getDataCenterId() + ", host is in alert state: " + host.getId() + "-" + host.getName()); } } else { - s_logger.debug("The next status of agent " + host.getId() + " is not Alert, no need to investigate what happened"); + logger.debug("The next status of agent " + host.getId() + " is not Alert, no need to investigate what happened"); } } handleDisconnectWithoutInvestigation(attache, event, true, true); @@ -971,7 +970,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl handleDisconnectWithoutInvestigation(_attache, _event, true, false); } } catch (final Exception e) { - s_logger.error("Exception caught while handling disconnect: ", e); + logger.error("Exception caught while handling disconnect: ", e); } } } @@ -981,34 +980,34 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl try { final Host h = _hostDao.findById(hostId); if (h == null || h.getRemoved() != null) { - s_logger.debug("Host with id " + hostId + " doesn't exist"); + logger.debug("Host with id " + hostId + " doesn't exist"); return null; } final Status status = h.getStatus(); if (!status.equals(Status.Up) && !status.equals(Status.Connecting)) { - s_logger.debug("Can not send command " + cmd + " due to Host " + hostId + " is not up"); + logger.debug("Can not send command " + cmd + " due to Host " + hostId + " is not up"); return null; } final Answer answer = send(hostId, cmd); if (answer == null) { - s_logger.warn("send returns null answer"); + logger.warn("send returns null answer"); return null; } - if (s_logger.isDebugEnabled() && answer.getDetails() != null) { - s_logger.debug("Details from executing " + cmd.getClass() + ": " + answer.getDetails()); + if (logger.isDebugEnabled() && answer.getDetails() != null) { + logger.debug("Details from executing " + cmd.getClass() + ": " + answer.getDetails()); } return answer; } catch (final AgentUnavailableException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); return null; } catch (final OperationTimedoutException e) { - s_logger.warn("Operation timed out: " + e.getMessage()); + logger.warn("Operation timed out: " + e.getMessage()); return null; } catch (final Exception e) { - s_logger.warn("Exception while sending", e); + logger.warn("Exception while sending", e); return null; } } @@ -1036,7 +1035,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } if (host.getStatus() == Status.Disconnected) { - s_logger.debug("Host is already disconnected, no work to be done: " + hostId); + logger.debug("Host is already disconnected, no work to be done: " + hostId); return; } @@ -1054,8 +1053,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override public void notifyMonitorsOfHostAboutToBeRemoved(long hostId) { for (final Pair monitor : _hostMonitors) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending host about to be removed to listener: " + monitor.second().getClass().getSimpleName()); + if (logger.isDebugEnabled()) { + logger.debug("Sending host about to be removed to listener: " + monitor.second().getClass().getSimpleName()); } monitor.second().processHostAboutToBeRemoved(hostId); @@ -1065,8 +1064,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override public void notifyMonitorsOfRemovedHost(long hostId, long clusterId) { for (final Pair monitor : _hostMonitors) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending host removed to listener: " + monitor.second().getClass().getSimpleName()); + if (logger.isDebugEnabled()) { + logger.debug("Sending host removed to listener: " + monitor.second().getClass().getSimpleName()); } monitor.second().processHostRemoved(hostId, clusterId); @@ -1075,8 +1074,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl public boolean executeUserRequest(final long hostId, final Event event) throws AgentUnavailableException { if (event == Event.AgentDisconnected) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Received agent disconnect event for host " + hostId); + if (logger.isDebugEnabled()) { + logger.debug("Received agent disconnect event for host " + hostId); } AgentAttache attache = null; attache = findAttache(hostId); @@ -1089,7 +1088,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl try { reconnect(hostId); } catch (CloudRuntimeException e) { - s_logger.debug("Error on shutdown request for hostID: " + hostId, e); + logger.debug("Error on shutdown request for hostID: " + hostId, e); return false; } return true; @@ -1104,7 +1103,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } protected AgentAttache createAttacheForConnect(final HostVO host, final Link link) throws ConnectionException { - s_logger.debug("create ConnectedAgentAttache for " + host.getId()); + logger.debug("create ConnectedAgentAttache for " + host.getId()); final AgentAttache attache = new ConnectedAgentAttache(this, host.getId(), host.getName(), link, host.isInMaintenanceStates()); link.attach(attache); @@ -1142,7 +1141,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl ready.setMsHostList(newMSList); ready.setLbAlgorithm(indirectAgentLB.getLBAlgorithmName()); ready.setLbCheckInterval(indirectAgentLB.getLBPreferredHostCheckInterval(host.getClusterId())); - s_logger.debug("Agent's management server host list is not up to date, sending list update:" + newMSList); + logger.debug("Agent's management server host list is not up to date, sending list update:" + newMSList); } attache = createAttacheForConnect(host, link); @@ -1167,7 +1166,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl attache = sendReadyAndGetAttache(host, ready, link, startup); } } catch (final Exception e) { - s_logger.debug("Failed to handle host connection: ", e); + logger.debug("Failed to handle host connection: ", e); ready = new ReadyCommand(null); ready.setDetails(e.toString()); } finally { @@ -1184,7 +1183,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl easySend(attache.getId(), ready); } } catch (final Exception e) { - s_logger.debug("Failed to send ready command:" + e.toString()); + logger.debug("Failed to send ready command:" + e.toString()); } return attache; } @@ -1203,28 +1202,28 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override protected void runInContext() { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Simulating start for resource " + resource.getName() + " id " + id); + if (logger.isDebugEnabled()) { + logger.debug("Simulating start for resource " + resource.getName() + " id " + id); } if (tapLoadingAgents(id, TapAgentsAction.Add)) { try { final AgentAttache agentattache = findAttache(id); if (agentattache == null) { - s_logger.debug("Creating agent for host " + id); + logger.debug("Creating agent for host " + id); _resourceMgr.createHostAndAgent(id, resource, details, false, null, false); - s_logger.debug("Completed creating agent for host " + id); + logger.debug("Completed creating agent for host " + id); } else { - s_logger.debug("Agent already created in another thread for host " + id + ", ignore this"); + logger.debug("Agent already created in another thread for host " + id + ", ignore this"); } } finally { tapLoadingAgents(id, TapAgentsAction.Del); } } else { - s_logger.debug("Agent creation already getting processed in another thread for host " + id + ", ignore this"); + logger.debug("Agent creation already getting processed in another thread for host " + id + ", ignore this"); } } catch (final Exception e) { - s_logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e); + logger.warn("Unable to simulate start on resource " + id + " name " + resource.getName(), e); } } } @@ -1250,7 +1249,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl final AgentAttache attache = handleConnectedAgent(_link, startups, _request); if (attache == null) { - s_logger.warn("Unable to create attache for agent: " + _request); + logger.warn("Unable to create attache for agent: " + _request); } } } @@ -1273,7 +1272,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl try { link.send(response.toBytes()); } catch (final ClosedChannelException e) { - s_logger.debug("Failed to send startupanswer: " + e.toString()); + logger.debug("Failed to send startupanswer: " + e.toString()); } _connectExecutor.execute(new HandleAgentConnectTask(link, cmds, request)); } @@ -1289,11 +1288,11 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } HostVO host = _hostDao.findById(hostId); if (host == null) { - s_logger.error(String.format("Unable to find host with ID: %s", hostId)); + logger.error(String.format("Unable to find host with ID: %s", hostId)); return; } if (!BooleanUtils.toBoolean(EnableKVMAutoEnableDisable.valueIn(host.getClusterId()))) { - s_logger.debug(String.format("%s is disabled for the cluster %s, cannot process the health check result " + + logger.debug(String.format("%s is disabled for the cluster %s, cannot process the health check result " + "received for the host %s", EnableKVMAutoEnableDisable.key(), host.getClusterId(), host.getName())); return; } @@ -1301,19 +1300,19 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl ResourceState.Event resourceEvent = hostHealthCheckResult ? ResourceState.Event.Enable : ResourceState.Event.Disable; try { - s_logger.info(String.format("Host health check %s, auto %s KVM host: %s", + logger.info(String.format("Host health check %s, auto %s KVM host: %s", hostHealthCheckResult ? "succeeds" : "fails", hostHealthCheckResult ? "enabling" : "disabling", host.getName())); _resourceMgr.autoUpdateHostAllocationState(hostId, resourceEvent); } catch (NoTransitionException e) { - s_logger.error(String.format("Cannot Auto %s host: %s", resourceEvent, host.getName()), e); + logger.error(String.format("Cannot Auto %s host: %s", resourceEvent, host.getName()), e); } } private void processStartupRoutingCommand(StartupRoutingCommand startup, long hostId) { if (startup == null) { - s_logger.error("Empty StartupRoutingCommand received"); + logger.error("Empty StartupRoutingCommand received"); return; } Boolean hostHealthCheckResult = startup.getHostHealthCheckResult(); @@ -1322,7 +1321,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl private void processPingRoutingCommand(PingRoutingCommand pingRoutingCommand, long hostId) { if (pingRoutingCommand == null) { - s_logger.error("Empty PingRoutingCommand received"); + logger.error("Empty PingRoutingCommand received"); return; } Boolean hostHealthCheckResult = pingRoutingCommand.getHostHealthCheckResult(); @@ -1337,7 +1336,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl if (attache == null) { if (!(cmd instanceof StartupCommand)) { - s_logger.warn("Throwing away a request because it came through as the first command on a connect: " + request); + logger.warn("Throwing away a request because it came through as the first command on a connect: " + request); } else { // submit the task for execution request.logD("Scheduling the first command "); @@ -1351,17 +1350,17 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl final long hostId = attache.getId(); final String hostName = attache.getName(); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (cmd instanceof PingRoutingCommand) { logD = false; - s_logger.debug("Ping from Routing host " + hostId + "(" + hostName + ")"); - s_logger.trace("SeqA " + hostId + "-" + request.getSequence() + ": Processing " + request); + logger.debug("Ping from Routing host " + hostId + "(" + hostName + ")"); + logger.trace("SeqA " + hostId + "-" + request.getSequence() + ": Processing " + request); } else if (cmd instanceof PingCommand) { logD = false; - s_logger.debug("Ping from " + hostId + "(" + hostName + ")"); - s_logger.trace("SeqA " + hostId + "-" + request.getSequence() + ": Processing " + request); + logger.debug("Ping from " + hostId + "(" + hostName + ")"); + logger.trace("SeqA " + hostId + "-" + request.getSequence() + ": Processing " + request); } else { - s_logger.debug("SeqA " + hostId + "-" + request.getSequence() + ": Processing " + request); + logger.debug("SeqA " + hostId + "-" + request.getSequence() + ": Processing " + request); } } @@ -1386,7 +1385,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } else if (cmd instanceof ShutdownCommand) { final ShutdownCommand shutdown = (ShutdownCommand)cmd; final String reason = shutdown.getReason(); - s_logger.info("Host " + attache.getId() + " has informed us that it is shutting down with reason " + reason + " and detail " + shutdown.getDetail()); + logger.info("Host " + attache.getId() + " has informed us that it is shutting down with reason " + reason + " and detail " + shutdown.getDetail()); if (reason.equals(ShutdownCommand.Update)) { // disconnectWithoutInvestigation(attache, Event.UpdateNeeded); throw new CloudRuntimeException("Agent update not implemented"); @@ -1424,7 +1423,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl _alertMgr.clearAlert(AlertManager.AlertType.ALERT_TYPE_ROUTING, host.getDataCenterId(), host.getPodId()); } } else { - s_logger.debug("Not processing " + PingRoutingCommand.class.getSimpleName() + " for agent id=" + cmdHostId + "; can't find the host in the DB"); + logger.debug("Not processing " + PingRoutingCommand.class.getSimpleName() + " for agent id=" + cmdHostId + "; can't find the host in the DB"); } } if (host!= null && host.getStatus() != Status.Up && gatewayAccessible) { @@ -1434,8 +1433,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } else if (cmd instanceof ReadyAnswer) { final HostVO host = _hostDao.findById(attache.getId()); if (host == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cant not find host " + attache.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Cant not find host " + attache.getId()); } } answer = new Answer(cmd); @@ -1444,33 +1443,33 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } } } catch (final Throwable th) { - s_logger.warn("Caught: ", th); + logger.warn("Caught: ", th); answer = new Answer(cmd, false, th.getMessage()); } answers[i] = answer; } final Response response = new Response(request, answers, _nodeId, attache.getId()); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (logD) { - s_logger.debug("SeqA " + attache.getId() + "-" + response.getSequence() + ": Sending " + response); + logger.debug("SeqA " + attache.getId() + "-" + response.getSequence() + ": Sending " + response); } else { - s_logger.trace("SeqA " + attache.getId() + "-" + response.getSequence() + ": Sending " + response); + logger.trace("SeqA " + attache.getId() + "-" + response.getSequence() + ": Sending " + response); } } try { link.send(response.toBytes()); } catch (final ClosedChannelException e) { - s_logger.warn("Unable to send response because connection is closed: " + response); + logger.warn("Unable to send response because connection is closed: " + response); } } protected void processResponse(final Link link, final Response response) { final AgentAttache attache = (AgentAttache)link.attachment(); if (attache == null) { - s_logger.warn("Unable to process: " + response); + logger.warn("Unable to process: " + response); } else if (!attache.processAnswers(response.getSequence(), response)) { - s_logger.info("Host " + attache.getId() + " - Seq " + response.getSequence() + ": Response is not processed: " + response); + logger.info("Host " + attache.getId() + " - Seq " + response.getSequence() + ": Response is not processed: " + response); } } @@ -1489,11 +1488,11 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl processRequest(task.getLink(), event); } } catch (final UnsupportedVersionException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); // upgradeAgent(task.getLink(), data, e.getReason()); } catch (final ClassNotFoundException e) { final String message = String.format("Exception occurred when executing tasks! Error '%s'", e.getMessage()); - s_logger.error(message); + logger.error(message); throw new TaskExecutionException(message, e); } } else if (type == Task.Type.CONNECT) { @@ -1503,7 +1502,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl if (attache != null) { disconnectWithInvestigation(attache, Event.AgentDisconnected); } else { - s_logger.info("Connection from " + link.getIpAddress() + " closed but no cleanup was done."); + logger.info("Connection from " + link.getIpAddress() + " closed but no cleanup was done."); link.close(); link.terminated(); } @@ -1540,20 +1539,20 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl public boolean agentStatusTransitTo(final HostVO host, final Status.Event e, final long msId) { try { _agentStatusLock.lock(); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { final ResourceState state = host.getResourceState(); final StringBuilder msg = new StringBuilder("Transition:"); msg.append("[Resource state = ").append(state); msg.append(", Agent event = ").append(e.toString()); msg.append(", Host id = ").append(host.getId()).append(", name = " + host.getName()).append("]"); - s_logger.debug(msg); + logger.debug(msg); } host.setManagementServerId(msId); try { return _statusStateMachine.transitTo(host, e, host.getId(), _hostDao); } catch (final NoTransitionException e1) { - s_logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() + ", management server id is " + msId); + logger.debug("Cannot transit agent status with event " + e + " for host " + host.getId() + ", name=" + host.getName() + ", management server id is " + msId); throw new CloudRuntimeException("Cannot transit agent status with event " + e + " for host " + host.getId() + ", management server id is " + msId + "," + e1.getMessage()); } } finally { @@ -1582,7 +1581,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl protected boolean isHostOwnerSwitched(final long hostId) { final HostVO host = _hostDao.findById(hostId); if (host == null) { - s_logger.warn("Can't find the host " + hostId); + logger.warn("Can't find the host " + hostId); return false; } return isHostOwnerSwitched(host); @@ -1607,7 +1606,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } else { /* Agent is still in connecting process, don't allow to disconnect right away */ if (tapLoadingAgents(hostId, TapAgentsAction.Contains)) { - s_logger.info("Host " + hostId + " is being loaded so no disconnects needed."); + logger.info("Host " + hostId + " is being loaded so no disconnects needed."); return; } @@ -1685,14 +1684,14 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl public void pingBy(final long agentId) { // Update PingMap with the latest time if agent entry exists in the PingMap if (_pingMap.replace(agentId, InaccurateClock.getTimeInSeconds()) == null) { - s_logger.info("PingMap for agent: " + agentId + " will not be updated because agent is no longer in the PingMap"); + logger.info("PingMap for agent: " + agentId + " will not be updated because agent is no longer in the PingMap"); } } protected class MonitorTask extends ManagedContextRunnable { @Override protected void runInContext() { - s_logger.trace("Agent Monitor is started."); + logger.trace("Agent Monitor is started."); try { final List behindAgents = findAgentsBehindOnPing(); @@ -1706,17 +1705,17 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl /* * Host is in non-operation state, so no investigation and direct put agent to Disconnected */ - s_logger.debug("Ping timeout but agent " + agentId + " is in resource state of " + resourceState + ", so no investigation"); + logger.debug("Ping timeout but agent " + agentId + " is in resource state of " + resourceState + ", so no investigation"); disconnectWithoutInvestigation(agentId, Event.ShutdownRequested); } else { final HostVO host = _hostDao.findById(agentId); if (host != null && (host.getType() == Host.Type.ConsoleProxy || host.getType() == Host.Type.SecondaryStorageVM || host.getType() == Host.Type.SecondaryStorageCmdExecutor)) { - s_logger.warn("Disconnect agent for CPVM/SSVM due to physical connection close. host: " + host.getId()); + logger.warn("Disconnect agent for CPVM/SSVM due to physical connection close. host: " + host.getId()); disconnectWithoutInvestigation(agentId, Event.ShutdownRequested); } else { - s_logger.debug("Ping timeout for agent " + agentId + ", do invstigation"); + logger.debug("Ping timeout for agent " + agentId + ", do invstigation"); disconnectWithInvestigation(agentId, Event.PingTimeout); } } @@ -1739,10 +1738,10 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } } } catch (final Throwable th) { - s_logger.error("Caught the following exception: ", th); + logger.error("Caught the following exception: ", th); } - s_logger.trace("Agent Monitor is leaving the building!"); + logger.trace("Agent Monitor is leaving the building!"); } protected List findAgentsBehindOnPing() { @@ -1755,7 +1754,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl } if (agentsBehind.size() > 0) { - s_logger.info("Found the following agents behind on ping: " + agentsBehind); + logger.info("Found the following agents behind on ping: " + agentsBehind); } return agentsBehind; @@ -1837,7 +1836,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override public ConfigKey[] getConfigKeys() { return new ConfigKey[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize, - DirectAgentPoolSize, DirectAgentThreadCap, EnableKVMAutoEnableDisable }; + DirectAgentPoolSize, DirectAgentThreadCap, EnableKVMAutoEnableDisable, ReadyCommandWait }; } protected class SetHostParamsListener implements Listener { @@ -1879,7 +1878,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl Commands c = new Commands(cmds); send(host.getId(), c, this); } catch (AgentUnavailableException e) { - s_logger.debug("Failed to send host params on host: " + host.getId()); + logger.debug("Failed to send host params on host: " + host.getId()); } } } @@ -1938,7 +1937,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl for (Long hostId : hostIds) { Answer answer = easySend(hostId, cmds); if (answer == null || !answer.getResult()) { - s_logger.error("Error sending parameters to agent " + hostId); + logger.error("Error sending parameters to agent " + hostId); } } } @@ -1947,7 +1946,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl @Override public void propagateChangeToAgents(Map params) { if (params != null && ! params.isEmpty()) { - s_logger.debug("Propagating changes on host parameters to the agents"); + logger.debug("Propagating changes on host parameters to the agents"); Map> hostsPerZone = getHostsPerZone(); sendCommandToAgents(hostsPerZone, params); } diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentAttache.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentAttache.java index 306c47ff60c..beafb4da8eb 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentAttache.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentAttache.java @@ -25,7 +25,6 @@ import java.util.LinkedList; import javax.net.ssl.SSLEngine; -import org.apache.log4j.Logger; import com.cloud.agent.Listener; import com.cloud.agent.api.Command; @@ -35,7 +34,6 @@ import com.cloud.host.Status; import com.cloud.utils.nio.Link; public class ClusteredAgentAttache extends ConnectedAgentAttache implements Routable { - private final static Logger s_logger = Logger.getLogger(ClusteredAgentAttache.class); private static ClusteredAgentManagerImpl s_clusteredAgentMgr; protected ByteBuffer _buffer = ByteBuffer.allocate(2048); private boolean _forward = false; @@ -92,10 +90,10 @@ public class ClusteredAgentAttache extends ConnectedAgentAttache implements Rout String peerName = synchronous.getPeer(); if (peerName != null) { if (s_clusteredAgentMgr != null) { - s_logger.debug(log(seq, "Forwarding to peer to cancel due to timeout")); + logger.debug(log(seq, "Forwarding to peer to cancel due to timeout")); s_clusteredAgentMgr.cancel(peerName, _id, seq, "Timed Out"); } else { - s_logger.error("Unable to forward cancel, ClusteredAgentAttache is not properly initialized"); + logger.error("Unable to forward cancel, ClusteredAgentAttache is not properly initialized"); } } @@ -107,13 +105,13 @@ public class ClusteredAgentAttache extends ConnectedAgentAttache implements Rout @Override public void routeToAgent(final byte[] data) throws AgentUnavailableException { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(Request.getSequence(data), "Routing from " + Request.getManagementServerId(data))); + if (logger.isDebugEnabled()) { + logger.debug(log(Request.getSequence(data), "Routing from " + Request.getManagementServerId(data))); } if (_link == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(Request.getSequence(data), "Link is closed")); + if (logger.isDebugEnabled()) { + logger.debug(log(Request.getSequence(data), "Link is closed")); } throw new AgentUnavailableException("Link is closed", _id); } @@ -121,14 +119,14 @@ public class ClusteredAgentAttache extends ConnectedAgentAttache implements Rout try { _link.send(data); } catch (ClosedChannelException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(Request.getSequence(data), "Channel is closed")); + if (logger.isDebugEnabled()) { + logger.debug(log(Request.getSequence(data), "Channel is closed")); } throw new AgentUnavailableException("Channel to agent is closed", _id); } catch (NullPointerException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(Request.getSequence(data), "Link is closed")); + if (logger.isDebugEnabled()) { + logger.debug(log(Request.getSequence(data), "Link is closed")); } // Note: since this block is not in synchronized. It is possible for _link to become null. throw new AgentUnavailableException("Channel to agent is null", _id); @@ -150,8 +148,8 @@ public class ClusteredAgentAttache extends ConnectedAgentAttache implements Rout if (_transferMode) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Holding request as the corresponding agent is in transfer mode: ")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Holding request as the corresponding agent is in transfer mode: ")); } synchronized (this) { @@ -176,8 +174,8 @@ public class ClusteredAgentAttache extends ConnectedAgentAttache implements Rout ch = s_clusteredAgentMgr.connectToPeer(peerName, ch); if (ch == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Unable to forward " + req.toString())); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Unable to forward " + req.toString())); } continue; } @@ -188,8 +186,8 @@ public class ClusteredAgentAttache extends ConnectedAgentAttache implements Rout } try { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Forwarding " + req.toString() + " to " + peerName)); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Forwarding " + req.toString() + " to " + peerName)); } if (req.executeInSequence() && listener != null && listener instanceof SynchronousListener) { SynchronousListener synchronous = (SynchronousListener)listener; @@ -199,12 +197,12 @@ public class ClusteredAgentAttache extends ConnectedAgentAttache implements Rout error = false; return; } catch (IOException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Error on connecting to management node: " + req.toString() + " try = " + i)); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Error on connecting to management node: " + req.toString() + " try = " + i)); } - if (s_logger.isInfoEnabled()) { - s_logger.info("IOException " + e.getMessage() + " when sending data to peer " + peerName + ", close peer connection and let it re-open"); + if (logger.isInfoEnabled()) { + logger.info("IOException " + e.getMessage() + " when sending data to peer " + peerName + ", close peer connection and let it re-open"); } } } diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java index bd4e259a788..1fe6b19ab68 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java @@ -57,7 +57,6 @@ import org.apache.cloudstack.shutdown.command.BaseShutdownManagementServerHostCo import org.apache.cloudstack.shutdown.command.TriggerShutdownManagementServerHostCommand; import org.apache.cloudstack.utils.identity.ManagementServerNode; import org.apache.cloudstack.utils.security.SSLUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CancelCommand; @@ -102,7 +101,6 @@ import com.cloud.utils.nio.Task; import com.google.gson.Gson; public class ClusteredAgentManagerImpl extends AgentManagerImpl implements ClusterManagerListener, ClusteredAgentRebalanceService { - final static Logger s_logger = Logger.getLogger(ClusteredAgentManagerImpl.class); private static final ScheduledExecutorService s_transferExecutor = Executors.newScheduledThreadPool(2, new NamedThreadFactory("Cluster-AgentRebalancingExecutor")); private final long rebalanceTimeOut = 300000; // 5 mins - after this time remove the agent from the transfer list @@ -154,7 +152,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust _sslEngines = new HashMap(7); _nodeId = ManagementServerNode.getManagementServerId(); - s_logger.info("Configuring ClusterAgentManagerImpl. management server node id(msid): " + _nodeId); + logger.info("Configuring ClusterAgentManagerImpl. management server node id(msid): " + _nodeId); ClusteredAgentAttache.initialize(this); @@ -172,8 +170,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust return false; } _timer.schedule(new DirectAgentScanTimerTask(), STARTUP_DELAY, ScanInterval.value()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Scheduled direct agent scan task to run at an interval of " + ScanInterval.value() + " seconds"); + if (logger.isDebugEnabled()) { + logger.debug("Scheduled direct agent scan task to run at an interval of " + ScanInterval.value() + " seconds"); } // Schedule tasks for agent rebalancing @@ -188,8 +186,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust public void scheduleHostScanTask() { _timer.schedule(new DirectAgentScanTimerTask(), 0); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Scheduled a direct agent scan task"); + if (logger.isDebugEnabled()) { + logger.debug("Scheduled a direct agent scan task"); } } @@ -198,8 +196,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } private void scanDirectAgentToLoad() { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Begin scanning directly connected hosts"); + if (logger.isTraceEnabled()) { + logger.trace("Begin scanning directly connected hosts"); } // for agents that are self-managed, threshold to be considered as disconnected after pingtimeout @@ -210,15 +208,15 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust if (hosts != null) { hosts.addAll(appliances); if (hosts.size() > 0) { - s_logger.debug("Found " + hosts.size() + " unmanaged direct hosts, processing connect for them..."); + logger.debug("Found " + hosts.size() + " unmanaged direct hosts, processing connect for them..."); for (final HostVO host : hosts) { try { final AgentAttache agentattache = findAttache(host.getId()); if (agentattache != null) { // already loaded, skip if (agentattache.forForward()) { - if (s_logger.isInfoEnabled()) { - s_logger.info(host + " is detected down, but we have a forward attache running, disconnect this one before launching the host"); + if (logger.isInfoEnabled()) { + logger.info(host + " is detected down, but we have a forward attache running, disconnect this one before launching the host"); } removeAgent(agentattache, Status.Disconnected); } else { @@ -226,18 +224,18 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ")"); + if (logger.isDebugEnabled()) { + logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ")"); } loadDirectlyConnectedHost(host, false); } catch (final Throwable e) { - s_logger.warn(" can not load directly connected host " + host.getId() + "(" + host.getName() + ") due to ", e); + logger.warn(" can not load directly connected host " + host.getId() + "(" + host.getName() + ") due to ", e); } } } } - if (s_logger.isTraceEnabled()) { - s_logger.trace("End scanning directly connected hosts"); + if (logger.isTraceEnabled()) { + logger.trace("End scanning directly connected hosts"); } } @@ -247,7 +245,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust try { runDirectAgentScanTimerTask(); } catch (final Throwable e) { - s_logger.error("Unexpected exception " + e.getMessage(), e); + logger.error("Unexpected exception " + e.getMessage(), e); } } } @@ -258,7 +256,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } protected AgentAttache createAttache(final long id) { - s_logger.debug("create forwarding ClusteredAgentAttache for " + id); + logger.debug("create forwarding ClusteredAgentAttache for " + id); final HostVO host = _hostDao.findById(id); final AgentAttache attache = new ClusteredAgentAttache(this, id, host.getName()); AgentAttache old = null; @@ -267,8 +265,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust _agents.put(id, attache); } if (old != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Remove stale agent attache from current management server"); + if (logger.isDebugEnabled()) { + logger.debug("Remove stale agent attache from current management server"); } removeAgent(old, Status.Removed); } @@ -277,7 +275,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override protected AgentAttache createAttacheForConnect(final HostVO host, final Link link) { - s_logger.debug("create ClusteredAgentAttache for " + host.getId()); + logger.debug("create ClusteredAgentAttache for " + host.getId()); final AgentAttache attache = new ClusteredAgentAttache(this, host.getId(), host.getName(), link, host.isInMaintenanceStates()); link.attach(attache); AgentAttache old = null; @@ -293,7 +291,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override protected AgentAttache createAttacheForDirectConnect(final Host host, final ServerResource resource) { - s_logger.debug(String.format("Create ClusteredDirectAgentAttache for %s.", host)); + logger.debug(String.format("Create ClusteredDirectAgentAttache for %s.", host)); final DirectAgentAttache attache = new ClusteredDirectAgentAttache(this, host.getId(), host.getName(), _nodeId, resource, host.isInMaintenanceStates()); AgentAttache old = null; synchronized (_agents) { @@ -337,8 +335,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override public boolean executeUserRequest(final long hostId, final Event event) throws AgentUnavailableException { if (event == Event.AgentDisconnected) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Received agent disconnect event for host " + hostId); + if (logger.isDebugEnabled()) { + logger.debug("Received agent disconnect event for host " + hostId); } final AgentAttache attache = findAttache(hostId); if (attache != null) { @@ -347,7 +345,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final HostTransferMapVO transferVO = _hostTransferDao.findById(hostId); if (transferVO != null) { if (transferVO.getFutureOwner() == _nodeId && transferVO.getState() == HostTransferState.TransferStarted) { - s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is being connected to " + _nodeId); + logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is being connected to " + _nodeId); return true; } } @@ -356,7 +354,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust // don't process disconnect if the disconnect came for the host via delayed cluster notification, // but the host has already reconnected to the current management server if (!attache.forForward()) { - s_logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is directly connected to the current management server " + _nodeId); + logger.debug("Not processing " + Event.AgentDisconnected + " event for the host id=" + hostId + " as the host is directly connected to the current management server " + _nodeId); return true; } @@ -382,32 +380,32 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } public void notifyNodesInCluster(final AgentAttache attache) { - s_logger.debug("Notifying other nodes of to disconnect"); + logger.debug("Notifying other nodes of to disconnect"); final Command[] cmds = new Command[] {new ChangeAgentCommand(attache.getId(), Event.AgentDisconnected)}; _clusterMgr.broadcast(attache.getId(), _gson.toJson(cmds)); } // notifies MS peers to schedule a host scan task immediately, triggered during addHost operation public void notifyNodesInClusterToScheduleHostScanTask() { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notifying other MS nodes to run host scan task"); + if (logger.isDebugEnabled()) { + logger.debug("Notifying other MS nodes to run host scan task"); } final Command[] cmds = new Command[] {new ScheduleHostScanTaskCommand()}; _clusterMgr.broadcast(0, _gson.toJson(cmds)); } - protected static void logT(final byte[] bytes, final String msg) { - s_logger.trace("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " + protected void logT(final byte[] bytes, final String msg) { + logger.trace("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg); } - protected static void logD(final byte[] bytes, final String msg) { - s_logger.debug("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " + protected void logD(final byte[] bytes, final String msg) { + logger.debug("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg); } - protected static void logI(final byte[] bytes, final String msg) { - s_logger.info("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " + protected void logI(final byte[] bytes, final String msg) { + logger.info("Seq " + Request.getAgentId(bytes) + "-" + Request.getSequence(bytes) + ": MgmtId " + Request.getManagementServerId(bytes) + ": " + (Request.isRequest(bytes) ? "Req: " : "Resp: ") + msg); } @@ -432,7 +430,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust return false; } try { - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { logD(bytes, "Routing to peer"); } Link.write(ch, new ByteBuffer[] {ByteBuffer.wrap(bytes)}, sslEngine); @@ -471,7 +469,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust try { ch.close(); } catch (final IOException e) { - s_logger.warn("Unable to close peer socket connection to " + peerName); + logger.warn("Unable to close peer socket connection to " + peerName); } } _peers.remove(peerName); @@ -487,13 +485,13 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust try { prevCh.close(); } catch (final Exception e) { - s_logger.info("[ignored]" + "failed to get close resource for previous channel Socket: " + e.getLocalizedMessage()); + logger.info("[ignored]" + "failed to get close resource for previous channel Socket: " + e.getLocalizedMessage()); } } if (ch == null || ch == prevCh) { final ManagementServerHost ms = _clusterMgr.getPeer(peerName); if (ms == null) { - s_logger.info("Unable to find peer: " + peerName); + logger.info("Unable to find peer: " + peerName); return null; } final String ip = ms.getServiceIP(); @@ -520,13 +518,13 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust ch1.close(); throw new IOException(String.format("SSL: Handshake failed with peer management server '%s' on %s:%d ", peerName, ip, port)); } - s_logger.info(String.format("SSL: Handshake done with peer management server '%s' on %s:%d ", peerName, ip, port)); + logger.info(String.format("SSL: Handshake done with peer management server '%s' on %s:%d ", peerName, ip, port)); } catch (final Exception e) { ch1.close(); throw new IOException("SSL: Fail to init SSL! " + e); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Connection to peer opened: " + peerName + ", ip: " + ip); + if (logger.isDebugEnabled()) { + logger.debug("Connection to peer opened: " + peerName + ", ip: " + ip); } _peers.put(peerName, ch1); _sslEngines.put(peerName, sslEngine); @@ -536,16 +534,16 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust try { ch1.close(); } catch (final IOException ex) { - s_logger.error("failed to close failed peer socket: " + ex); + logger.error("failed to close failed peer socket: " + ex); } } - s_logger.warn("Unable to connect to peer management server: " + peerName + ", ip: " + ip + " due to " + e.getMessage(), e); + logger.warn("Unable to connect to peer management server: " + peerName + ", ip: " + ip + " due to " + e.getMessage(), e); return null; } } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Found open channel for peer: " + peerName); + if (logger.isTraceEnabled()) { + logger.trace("Found open channel for peer: " + peerName); } return ch; } @@ -571,8 +569,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust AgentAttache agent = findAttache(hostId); if (agent == null || !agent.forForward()) { if (isHostOwnerSwitched(host)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Host " + hostId + " has switched to another management server, need to update agent map with a forwarding agent attache"); + if (logger.isDebugEnabled()) { + logger.debug("Host " + hostId + " has switched to another management server, need to update agent map with a forwarding agent attache"); } agent = createAttache(hostId); } @@ -591,10 +589,10 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust if (_peers != null) { for (final SocketChannel ch : _peers.values()) { try { - s_logger.info("Closing: " + ch.toString()); + logger.info("Closing: " + ch.toString()); ch.close(); } catch (final IOException e) { - s_logger.info("[ignored] error on closing channel: " + ch.toString(), e); + logger.info("[ignored] error on closing channel: " + ch.toString(), e); } } } @@ -631,7 +629,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final byte[] data = task.getData(); final Version ver = Request.getVersion(data); if (ver.ordinal() != Version.v1.ordinal() && ver.ordinal() != Version.v3.ordinal()) { - s_logger.warn("Wrong version for clustered agent request"); + logger.warn("Wrong version for clustered agent request"); super.doTask(task); return; } @@ -651,7 +649,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final Request req = Request.parse(data); final Command[] cmds = req.getCommands(); final CancelCommand cancel = (CancelCommand)cmds[0]; - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { logD(data, "Cancel request received"); } agent.cancel(cancel.getSequence()); @@ -699,7 +697,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final AgentAttache attache = (AgentAttache)link.attachment(); if (attache != null) { attache.sendNext(Request.getSequence(data)); - } else if (s_logger.isDebugEnabled()) { + } else if (logger.isDebugEnabled()) { logD(data, "No attache to process " + Request.parse(data).toString()); } } @@ -712,11 +710,11 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final Response response = Response.parse(data); final AgentAttache attache = findAttache(response.getAgentId()); if (attache == null) { - s_logger.info("SeqA " + response.getAgentId() + "-" + response.getSequence() + "Unable to find attache to forward " + response.toString()); + logger.info("SeqA " + response.getAgentId() + "-" + response.getSequence() + "Unable to find attache to forward " + response.toString()); return; } if (!attache.processAnswers(response.getSequence(), response)) { - s_logger.info("SeqA " + attache.getId() + "-" + response.getSequence() + ": Response is not processed: " + response.toString()); + logger.info("SeqA " + attache.getId() + "-" + response.getSequence() + ": Response is not processed: " + response.toString()); } } return; @@ -724,11 +722,11 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } } catch (final ClassNotFoundException e) { final String message = String.format("ClassNotFoundException occurred when executing tasks! Error '%s'", e.getMessage()); - s_logger.error(message); + logger.error(message); throw new TaskExecutionException(message, e); } catch (final UnsupportedVersionException e) { final String message = String.format("UnsupportedVersionException occurred when executing tasks! Error '%s'", e.getMessage()); - s_logger.error(message); + logger.error(message); throw new TaskExecutionException(message, e); } finally { txn.close(); @@ -743,12 +741,12 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override public void onManagementNodeLeft(final List nodeList, final long selfNodeId) { for (final ManagementServerHost vo : nodeList) { - s_logger.info("Marking hosts as disconnected on Management server" + vo.getMsid()); + logger.info("Marking hosts as disconnected on Management server" + vo.getMsid()); final long lastPing = (System.currentTimeMillis() >> 10) - mgmtServiceConf.getTimeout(); _hostDao.markHostsAsDisconnected(vo.getMsid(), lastPing); outOfBandManagementDao.expireServerOwnership(vo.getMsid()); haConfigDao.expireServerOwnership(vo.getMsid()); - s_logger.info("Deleting entries from op_host_transfer table for Management server " + vo.getMsid()); + logger.info("Deleting entries from op_host_transfer table for Management server " + vo.getMsid()); cleanupTransferMap(vo.getMsid()); } } @@ -775,7 +773,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust try { result = rebalanceHost(agentId, currentOwnerId, futureOwnerId); } catch (final Exception e) { - s_logger.warn("Unable to rebalance host id=" + agentId, e); + logger.warn("Unable to rebalance host id=" + agentId, e); } } return result; @@ -790,14 +788,14 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust protected volatile boolean cancelled = false; public AgentLoadBalancerTask() { - s_logger.debug("Agent load balancer task created"); + logger.debug("Agent load balancer task created"); } @Override public synchronized boolean cancel() { if (!cancelled) { cancelled = true; - s_logger.debug("Agent load balancer task cancelled"); + logger.debug("Agent load balancer task cancelled"); return super.cancel(); } return true; @@ -808,19 +806,19 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust try { if (!cancelled) { startRebalanceAgents(); - if (s_logger.isInfoEnabled()) { - s_logger.info("The agent load balancer task is now being cancelled"); + if (logger.isInfoEnabled()) { + logger.info("The agent load balancer task is now being cancelled"); } cancelled = true; } } catch (final Throwable e) { - s_logger.error("Unexpected exception " + e.toString(), e); + logger.error("Unexpected exception " + e.toString(), e); } } } public void startRebalanceAgents() { - s_logger.debug("Management server " + _nodeId + " is asking other peers to rebalance their agents"); + logger.debug("Management server " + _nodeId + " is asking other peers to rebalance their agents"); final List allMS = _mshostDao.listBy(ManagementServerHost.State.Up); final QueryBuilder sc = QueryBuilder.create(HostVO.class); sc.and(sc.entity().getManagementServerId(), Op.NNULL); @@ -832,16 +830,16 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust if (!allManagedAgents.isEmpty() && !allMS.isEmpty()) { avLoad = allManagedAgents.size() / allMS.size(); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("There are no hosts to rebalance in the system. Current number of active management server nodes in the system is " + allMS.size() + "; number of managed agents is " + if (logger.isDebugEnabled()) { + logger.debug("There are no hosts to rebalance in the system. Current number of active management server nodes in the system is " + allMS.size() + "; number of managed agents is " + allManagedAgents.size()); } return; } if (avLoad == 0L) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("As calculated average load is less than 1, rounding it to 1"); + if (logger.isDebugEnabled()) { + logger.debug("As calculated average load is less than 1, rounding it to 1"); } avLoad = 1; } @@ -855,19 +853,19 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust if (hostsToRebalance != null && !hostsToRebalance.isEmpty()) { break; } else { - s_logger.debug("Agent load balancer planner " + lbPlanner.getName() + " found no hosts to be rebalanced from management server " + node.getMsid()); + logger.debug("Agent load balancer planner " + lbPlanner.getName() + " found no hosts to be rebalanced from management server " + node.getMsid()); } } if (hostsToRebalance != null && !hostsToRebalance.isEmpty()) { - s_logger.debug("Found " + hostsToRebalance.size() + " hosts to rebalance from management server " + node.getMsid()); + logger.debug("Found " + hostsToRebalance.size() + " hosts to rebalance from management server " + node.getMsid()); for (final HostVO host : hostsToRebalance) { final long hostId = host.getId(); - s_logger.debug("Asking management server " + node.getMsid() + " to give away host id=" + hostId); + logger.debug("Asking management server " + node.getMsid() + " to give away host id=" + hostId); boolean result = true; if (_hostTransferDao.findById(hostId) != null) { - s_logger.warn("Somebody else is already rebalancing host id: " + hostId); + logger.warn("Somebody else is already rebalancing host id: " + hostId); continue; } @@ -876,18 +874,18 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust transfer = _hostTransferDao.startAgentTransfering(hostId, node.getMsid(), _nodeId); final Answer[] answer = sendRebalanceCommand(node.getMsid(), hostId, node.getMsid(), _nodeId, Event.RequestAgentRebalance); if (answer == null) { - s_logger.warn("Failed to get host id=" + hostId + " from management server " + node.getMsid()); + logger.warn("Failed to get host id=" + hostId + " from management server " + node.getMsid()); result = false; } } catch (final Exception ex) { - s_logger.warn("Failed to get host id=" + hostId + " from management server " + node.getMsid(), ex); + logger.warn("Failed to get host id=" + hostId + " from management server " + node.getMsid(), ex); result = false; } finally { if (transfer != null) { final HostTransferMapVO transferState = _hostTransferDao.findByIdAndFutureOwnerId(transfer.getId(), _nodeId); if (!result && transferState != null && transferState.getState() == HostTransferState.TransferRequested) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Removing mapping from op_host_transfer as it failed to be set to transfer mode"); + if (logger.isDebugEnabled()) { + logger.debug("Removing mapping from op_host_transfer as it failed to be set to transfer mode"); } // just remove the mapping (if exists) as nothing was done on the peer management // server yet @@ -897,7 +895,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } } } else { - s_logger.debug("Found no hosts to rebalance from the management server " + node.getMsid()); + logger.debug("Found no hosts to rebalance from the management server " + node.getMsid()); } } } @@ -911,8 +909,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final Command[] cmds = commands.toCommands(); try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Forwarding " + cmds[0].toString() + " to " + peer); + if (logger.isDebugEnabled()) { + logger.debug("Forwarding " + cmds[0].toString() + " to " + peer); } final String peerName = Long.toString(peer); final String cmdStr = _gson.toJson(cmds); @@ -920,7 +918,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final Answer[] answers = _gson.fromJson(ansStr, Answer[].class); return answers; } catch (final Exception e) { - s_logger.warn("Caught exception while talking to " + currentOwnerId, e); + logger.warn("Caught exception while talking to " + currentOwnerId, e); return null; } } @@ -944,8 +942,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust return null; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Propagating agent change request event:" + event.toString() + " to agent:" + agentId); + if (logger.isDebugEnabled()) { + logger.debug("Propagating agent change request event:" + event.toString() + " to agent:" + agentId); } final Command[] cmds = new Command[1]; cmds[0] = new ChangeAgentCommand(agentId, event); @@ -957,8 +955,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final Answer[] answers = _gson.fromJson(ansStr, Answer[].class); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Result for agent change is " + answers[0].getResult()); + if (logger.isDebugEnabled()) { + logger.debug("Result for agent change is " + answers[0].getResult()); } return answers[0].getResult(); @@ -969,12 +967,12 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override protected void runInContext() { try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Clustered agent transfer scan check, management server id:" + _nodeId); + if (logger.isTraceEnabled()) { + logger.trace("Clustered agent transfer scan check, management server id:" + _nodeId); } synchronized (_agentToTransferIds) { if (_agentToTransferIds.size() > 0) { - s_logger.debug("Found " + _agentToTransferIds.size() + " agents to transfer"); + logger.debug("Found " + _agentToTransferIds.size() + " agents to transfer"); // for (Long hostId : _agentToTransferIds) { for (final Iterator iterator = _agentToTransferIds.iterator(); iterator.hasNext();) { final Long hostId = iterator.next(); @@ -990,14 +988,14 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final HostTransferMapVO transferMap = _hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut)); if (transferMap == null) { - s_logger.debug("Timed out waiting for the host id=" + hostId + " to be ready to transfer, skipping rebalance for the host"); + logger.debug("Timed out waiting for the host id=" + hostId + " to be ready to transfer, skipping rebalance for the host"); iterator.remove(); _hostTransferDao.completeAgentTransfer(hostId); continue; } if (transferMap.getInitialOwner() != _nodeId || attache == null || attache.forForward()) { - s_logger.debug("Management server " + _nodeId + " doesn't own host id=" + hostId + " any more, skipping rebalance for the host"); + logger.debug("Management server " + _nodeId + " doesn't own host id=" + hostId + " any more, skipping rebalance for the host"); iterator.remove(); _hostTransferDao.completeAgentTransfer(hostId); continue; @@ -1005,7 +1003,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final ManagementServerHostVO ms = _mshostDao.findByMsid(transferMap.getFutureOwner()); if (ms != null && ms.getState() != ManagementServerHost.State.Up) { - s_logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms + ", skipping rebalance for the host"); + logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms + ", skipping rebalance for the host"); iterator.remove(); _hostTransferDao.completeAgentTransfer(hostId); continue; @@ -1016,31 +1014,31 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust try { _executor.execute(new RebalanceTask(hostId, transferMap.getInitialOwner(), transferMap.getFutureOwner())); } catch (final RejectedExecutionException ex) { - s_logger.warn("Failed to submit rebalance task for host id=" + hostId + "; postponing the execution"); + logger.warn("Failed to submit rebalance task for host id=" + hostId + "; postponing the execution"); continue; } } else { - s_logger.debug("Agent " + hostId + " can't be transferred yet as its request queue size is " + attache.getQueueSize() + " and listener queue size is " + logger.debug("Agent " + hostId + " can't be transferred yet as its request queue size is " + attache.getQueueSize() + " and listener queue size is " + attache.getNonRecurringListenersSize()); } } } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Found no agents to be transferred by the management server " + _nodeId); + if (logger.isTraceEnabled()) { + logger.trace("Found no agents to be transferred by the management server " + _nodeId); } } } } catch (final Throwable e) { - s_logger.error("Problem with the clustered agent transfer scan check!", e); + logger.error("Problem with the clustered agent transfer scan check!", e); } } }; } private boolean setToWaitForRebalance(final long hostId, final long currentOwnerId, final long futureOwnerId) { - s_logger.debug("Adding agent " + hostId + " to the list of agents to transfer"); + logger.debug("Adding agent " + hostId + " to the list of agents to transfer"); synchronized (_agentToTransferIds) { return _agentToTransferIds.add(hostId); } @@ -1051,7 +1049,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust boolean result = true; if (currentOwnerId == _nodeId) { if (!startRebalance(hostId)) { - s_logger.debug("Failed to start agent rebalancing"); + logger.debug("Failed to start agent rebalancing"); finishRebalance(hostId, futureOwnerId, Event.RebalanceFailed); return false; } @@ -1062,23 +1060,23 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } } catch (final Exception ex) { - s_logger.warn("Host " + hostId + " failed to connect to the management server " + futureOwnerId + " as a part of rebalance process", ex); + logger.warn("Host " + hostId + " failed to connect to the management server " + futureOwnerId + " as a part of rebalance process", ex); result = false; } if (result) { - s_logger.debug("Successfully transferred host id=" + hostId + " to management server " + futureOwnerId); + logger.debug("Successfully transferred host id=" + hostId + " to management server " + futureOwnerId); finishRebalance(hostId, futureOwnerId, Event.RebalanceCompleted); } else { - s_logger.warn("Failed to transfer host id=" + hostId + " to management server " + futureOwnerId); + logger.warn("Failed to transfer host id=" + hostId + " to management server " + futureOwnerId); finishRebalance(hostId, futureOwnerId, Event.RebalanceFailed); } } else if (futureOwnerId == _nodeId) { final HostVO host = _hostDao.findById(hostId); try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Disconnecting host " + host.getId() + "(" + host.getName() + " as a part of rebalance process without notification"); + if (logger.isDebugEnabled()) { + logger.debug("Disconnecting host " + host.getId() + "(" + host.getName() + " as a part of rebalance process without notification"); } final AgentAttache attache = findAttache(hostId); @@ -1087,24 +1085,24 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } if (result) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process"); + if (logger.isDebugEnabled()) { + logger.debug("Loading directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process"); } result = loadDirectlyConnectedHost(host, true); } else { - s_logger.warn("Failed to disconnect " + host.getId() + "(" + host.getName() + " as a part of rebalance process without notification"); + logger.warn("Failed to disconnect " + host.getId() + "(" + host.getName() + " as a part of rebalance process without notification"); } } catch (final Exception ex) { - s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process due to:", + logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process due to:", ex); result = false; } if (result) { - s_logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process"); + logger.debug("Successfully loaded directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process"); } else { - s_logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process"); + logger.warn("Failed to load directly connected host " + host.getId() + "(" + host.getName() + ") to the management server " + _nodeId + " as a part of rebalance process"); } } @@ -1114,13 +1112,13 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust protected void finishRebalance(final long hostId, final long futureOwnerId, final Event event) { final boolean success = event == Event.RebalanceCompleted ? true : false; - if (s_logger.isDebugEnabled()) { - s_logger.debug("Finishing rebalancing for the agent " + hostId + " with event " + event); + if (logger.isDebugEnabled()) { + logger.debug("Finishing rebalancing for the agent " + hostId + " with event " + event); } final AgentAttache attache = findAttache(hostId); if (attache == null || !(attache instanceof ClusteredAgentAttache)) { - s_logger.debug("Unable to find forward attache for the host id=" + hostId + ", assuming that the agent disconnected already"); + logger.debug("Unable to find forward attache for the host id=" + hostId + ", assuming that the agent disconnected already"); _hostTransferDao.completeAgentTransfer(hostId); return; } @@ -1135,7 +1133,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust // 2) Get all transfer requests and route them to peer Request requestToTransfer = forwardAttache.getRequestToTransfer(); while (requestToTransfer != null) { - s_logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " + _nodeId + " to " + futureOwnerId); + logger.debug("Forwarding request " + requestToTransfer.getSequence() + " held in transfer attache " + hostId + " from the management server " + _nodeId + " to " + futureOwnerId); final boolean routeResult = routeToPeer(Long.toString(futureOwnerId), requestToTransfer.getBytes()); if (!routeResult) { logD(requestToTransfer.getBytes(), "Failed to route request to peer"); @@ -1144,23 +1142,23 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust requestToTransfer = forwardAttache.getRequestToTransfer(); } - s_logger.debug("Management server " + _nodeId + " completed agent " + hostId + " rebalance to " + futureOwnerId); + logger.debug("Management server " + _nodeId + " completed agent " + hostId + " rebalance to " + futureOwnerId); } else { failRebalance(hostId); } - s_logger.debug("Management server " + _nodeId + " completed agent " + hostId + " rebalance"); + logger.debug("Management server " + _nodeId + " completed agent " + hostId + " rebalance"); _hostTransferDao.completeAgentTransfer(hostId); } protected void failRebalance(final long hostId) { try { - s_logger.debug("Management server " + _nodeId + " failed to rebalance agent " + hostId); + logger.debug("Management server " + _nodeId + " failed to rebalance agent " + hostId); _hostTransferDao.completeAgentTransfer(hostId); handleDisconnectWithoutInvestigation(findAttache(hostId), Event.RebalanceFailed, true, true); } catch (final Exception ex) { - s_logger.warn("Failed to reconnect host id=" + hostId + " as a part of failed rebalance task cleanup"); + logger.warn("Failed to reconnect host id=" + hostId + " as a part of failed rebalance task cleanup"); } } @@ -1168,7 +1166,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust final HostVO host = _hostDao.findById(hostId); if (host == null || host.getRemoved() != null) { - s_logger.warn("Unable to find host record, fail start rebalancing process"); + logger.warn("Unable to find host record, fail start rebalancing process"); return false; } @@ -1178,17 +1176,17 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust handleDisconnectWithoutInvestigation(attache, Event.StartAgentRebalance, true, true); final ClusteredAgentAttache forwardAttache = (ClusteredAgentAttache)createAttache(hostId); if (forwardAttache == null) { - s_logger.warn("Unable to create a forward attache for the host " + hostId + " as a part of rebalance process"); + logger.warn("Unable to create a forward attache for the host " + hostId + " as a part of rebalance process"); return false; } - s_logger.debug("Putting agent id=" + hostId + " to transfer mode"); + logger.debug("Putting agent id=" + hostId + " to transfer mode"); forwardAttache.setTransferMode(true); _agents.put(hostId, forwardAttache); } else { if (attache == null) { - s_logger.warn("Attache for the agent " + hostId + " no longer exists on management server " + _nodeId + ", can't start host rebalancing"); + logger.warn("Attache for the agent " + hostId + " no longer exists on management server " + _nodeId + ", can't start host rebalancing"); } else { - s_logger.warn("Attache for the agent " + hostId + " has request queue size= " + attache.getQueueSize() + " and listener queue size " + attache.getNonRecurringListenersSize() + logger.warn("Attache for the agent " + hostId + " has request queue size= " + attache.getQueueSize() + " and listener queue size " + attache.getNonRecurringListenersSize() + ", can't start host rebalancing"); } return false; @@ -1225,19 +1223,19 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override protected void runInContext() { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Rebalancing host id=" + hostId); + if (logger.isDebugEnabled()) { + logger.debug("Rebalancing host id=" + hostId); } rebalanceHost(hostId, currentOwnerId, futureOwnerId); } catch (final Exception e) { - s_logger.warn("Unable to rebalance host id=" + hostId, e); + logger.warn("Unable to rebalance host id=" + hostId, e); } } } private String handleScheduleHostScanTaskCommand(final ScheduleHostScanTaskCommand cmd) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Intercepting resource manager command: " + _gson.toJson(cmd)); + if (logger.isDebugEnabled()) { + logger.debug("Intercepting resource manager command: " + _gson.toJson(cmd)); } try { @@ -1245,7 +1243,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } catch (final Exception e) { // Scheduling host scan task in peer MS is a best effort operation during host add, regular host scan // happens at fixed intervals anyways. So handling any exceptions that may be thrown - s_logger.warn( + logger.warn( "Exception happened while trying to schedule host scan task on mgmt server " + _clusterMgr.getSelfPeerName() + ", ignoring as regular host scan happens at fixed interval anyways", e); return null; @@ -1273,8 +1271,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override public String dispatch(final ClusterServicePdu pdu) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Dispatch ->" + pdu.getAgentId() + ", json: " + pdu.getJsonPackage()); + if (logger.isDebugEnabled()) { + logger.debug("Dispatch ->" + pdu.getAgentId() + ", json: " + pdu.getJsonPackage()); } Command[] cmds = null; @@ -1282,24 +1280,24 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust cmds = _gson.fromJson(pdu.getJsonPackage(), Command[].class); } catch (final Throwable e) { assert false; - s_logger.error("Exception in gson decoding : ", e); + logger.error("Exception in gson decoding : ", e); } if (cmds.length == 1 && cmds[0] instanceof ChangeAgentCommand) { // intercepted final ChangeAgentCommand cmd = (ChangeAgentCommand)cmds[0]; - if (s_logger.isDebugEnabled()) { - s_logger.debug("Intercepting command for agent change: agent " + cmd.getAgentId() + " event: " + cmd.getEvent()); + if (logger.isDebugEnabled()) { + logger.debug("Intercepting command for agent change: agent " + cmd.getAgentId() + " event: " + cmd.getEvent()); } boolean result = false; try { result = executeAgentUserRequest(cmd.getAgentId(), cmd.getEvent()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Result is " + result); + if (logger.isDebugEnabled()) { + logger.debug("Result is " + result); } } catch (final AgentUnavailableException e) { - s_logger.warn("Agent is unavailable", e); + logger.warn("Agent is unavailable", e); return null; } @@ -1309,21 +1307,21 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } else if (cmds.length == 1 && cmds[0] instanceof TransferAgentCommand) { final TransferAgentCommand cmd = (TransferAgentCommand)cmds[0]; - if (s_logger.isDebugEnabled()) { - s_logger.debug("Intercepting command for agent rebalancing: agent " + cmd.getAgentId() + " event: " + cmd.getEvent()); + if (logger.isDebugEnabled()) { + logger.debug("Intercepting command for agent rebalancing: agent " + cmd.getAgentId() + " event: " + cmd.getEvent()); } boolean result = false; try { result = rebalanceAgent(cmd.getAgentId(), cmd.getEvent(), cmd.getCurrentOwner(), cmd.getFutureOwner()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Result is " + result); + if (logger.isDebugEnabled()) { + logger.debug("Result is " + result); } } catch (final AgentUnavailableException e) { - s_logger.warn("Agent is unavailable", e); + logger.warn("Agent is unavailable", e); return null; } catch (final OperationTimedoutException e) { - s_logger.warn("Operation timed out", e); + logger.warn("Operation timed out", e); return null; } final Answer[] answers = new Answer[1]; @@ -1332,14 +1330,14 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } else if (cmds.length == 1 && cmds[0] instanceof PropagateResourceEventCommand) { final PropagateResourceEventCommand cmd = (PropagateResourceEventCommand)cmds[0]; - s_logger.debug("Intercepting command to propagate event " + cmd.getEvent().name() + " for host " + cmd.getHostId()); + logger.debug("Intercepting command to propagate event " + cmd.getEvent().name() + " for host " + cmd.getHostId()); boolean result = false; try { result = _resourceMgr.executeUserRequest(cmd.getHostId(), cmd.getEvent()); - s_logger.debug("Result is " + result); + logger.debug("Result is " + result); } catch (final AgentUnavailableException ex) { - s_logger.warn("Agent is unavailable", ex); + logger.warn("Agent is unavailable", ex); return null; } @@ -1356,30 +1354,30 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust try { final long startTick = System.currentTimeMillis(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Dispatch -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage()); + if (logger.isDebugEnabled()) { + logger.debug("Dispatch -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage()); } final Answer[] answers = sendToAgent(pdu.getAgentId(), cmds, pdu.isStopOnError()); if (answers != null) { final String jsonReturn = _gson.toJson(answers); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + (System.currentTimeMillis() - startTick) + " ms, return result: " + if (logger.isDebugEnabled()) { + logger.debug("Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + (System.currentTimeMillis() - startTick) + " ms, return result: " + jsonReturn); } return jsonReturn; } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug( + if (logger.isDebugEnabled()) { + logger.debug( "Completed dispatching -> " + pdu.getAgentId() + ", json: " + pdu.getJsonPackage() + " in " + (System.currentTimeMillis() - startTick) + " ms, return null result"); } } } catch (final AgentUnavailableException e) { - s_logger.warn("Agent is unavailable", e); + logger.warn("Agent is unavailable", e); } catch (final OperationTimedoutException e) { - s_logger.warn("Timed Out", e); + logger.warn("Timed Out", e); } return null; @@ -1387,7 +1385,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust private String handleShutdownManagementServerHostCommand(BaseShutdownManagementServerHostCommand cmd) { if (cmd instanceof PrepareForShutdownManagementServerHostCommand) { - s_logger.debug("Received BaseShutdownManagementServerHostCommand - preparing to shut down"); + logger.debug("Received BaseShutdownManagementServerHostCommand - preparing to shut down"); try { shutdownManager.prepareForShutdown(); return "Successfully prepared for shutdown"; @@ -1396,7 +1394,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } } if (cmd instanceof TriggerShutdownManagementServerHostCommand) { - s_logger.debug("Received TriggerShutdownManagementServerHostCommand - triggering a shut down"); + logger.debug("Received TriggerShutdownManagementServerHostCommand - triggering a shut down"); try { shutdownManager.triggerShutdown(); return "Successfully triggered shutdown"; @@ -1405,7 +1403,7 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust } } if (cmd instanceof CancelShutdownManagementServerHostCommand) { - s_logger.debug("Received CancelShutdownManagementServerHostCommand - cancelling shut down"); + logger.debug("Received CancelShutdownManagementServerHostCommand - cancelling shut down"); try { shutdownManager.cancelShutdown(); return "Successfully prepared for shutdown"; @@ -1434,8 +1432,8 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override protected void runInContext() { try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Agent rebalance task check, management server id:" + _nodeId); + if (logger.isTraceEnabled()) { + logger.trace("Agent rebalance task check, management server id:" + _nodeId); } // initiate agent lb task will be scheduled and executed only once, and only when number of agents // loaded exceeds _connectedAgentsThreshold @@ -1453,16 +1451,16 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust if (allHostsCount > 0.0) { final double load = managedHostsCount / allHostsCount; if (load > ConnectedAgentThreshold.value()) { - s_logger.debug("Scheduling agent rebalancing task as the average agent load " + load + " is more than the threshold " + ConnectedAgentThreshold.value()); + logger.debug("Scheduling agent rebalancing task as the average agent load " + load + " is more than the threshold " + ConnectedAgentThreshold.value()); scheduleRebalanceAgents(); _agentLbHappened = true; } else { - s_logger.debug("Not scheduling agent rebalancing task as the average load " + load + " has not crossed the threshold " + ConnectedAgentThreshold.value()); + logger.debug("Not scheduling agent rebalancing task as the average load " + load + " has not crossed the threshold " + ConnectedAgentThreshold.value()); } } } } catch (final Throwable e) { - s_logger.error("Problem with the clustered agent transfer scan check!", e); + logger.error("Problem with the clustered agent transfer scan check!", e); } } }; @@ -1471,13 +1469,13 @@ public class ClusteredAgentManagerImpl extends AgentManagerImpl implements Clust @Override public void rescan() { // schedule a scan task immediately - if (s_logger.isDebugEnabled()) { - s_logger.debug("Scheduling a host scan task"); + if (logger.isDebugEnabled()) { + logger.debug("Scheduling a host scan task"); } // schedule host scan task on current MS scheduleHostScanTask(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notifying all peer MS to schedule host scan task"); + if (logger.isDebugEnabled()) { + logger.debug("Notifying all peer MS to schedule host scan task"); } } diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/ConnectedAgentAttache.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/ConnectedAgentAttache.java index 82423205a65..81c026348c8 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/ConnectedAgentAttache.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/ConnectedAgentAttache.java @@ -18,7 +18,6 @@ package com.cloud.agent.manager; import java.nio.channels.ClosedChannelException; -import org.apache.log4j.Logger; import com.cloud.agent.transport.Request; import com.cloud.exception.AgentUnavailableException; @@ -29,7 +28,6 @@ import com.cloud.utils.nio.Link; * ConnectedAgentAttache implements a direct connection to this management server. */ public class ConnectedAgentAttache extends AgentAttache { - private static final Logger s_logger = Logger.getLogger(ConnectedAgentAttache.class); protected Link _link; @@ -55,7 +53,7 @@ public class ConnectedAgentAttache extends AgentAttache { @Override public void disconnect(final Status state) { synchronized (this) { - s_logger.debug("Processing Disconnect."); + logger.debug("Processing Disconnect."); if (_link != null) { _link.close(); _link.terminated(); @@ -100,7 +98,7 @@ public class ConnectedAgentAttache extends AgentAttache { assert _link == null : "Duh...Says you....Forgot to call disconnect()!"; synchronized (this) { if (_link != null) { - s_logger.warn("Lost attache " + _id + "(" + _name + ")"); + logger.warn("Lost attache " + _id + "(" + _name + ")"); disconnect(Status.Alert); } } diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/DirectAgentAttache.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/DirectAgentAttache.java index 6514685aa46..969af3d1ba6 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/DirectAgentAttache.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/DirectAgentAttache.java @@ -23,10 +23,8 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.MDC; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -38,9 +36,9 @@ import com.cloud.agent.transport.Response; import com.cloud.exception.AgentUnavailableException; import com.cloud.host.Status; import com.cloud.resource.ServerResource; +import org.apache.logging.log4j.ThreadContext; public class DirectAgentAttache extends AgentAttache { - private final static Logger s_logger = Logger.getLogger(DirectAgentAttache.class); protected final ConfigKey _HostPingRetryCount = new ConfigKey("Advanced", Integer.class, "host.ping.retry.count", "0", "Number of times retrying a host ping while waiting for check results", true); @@ -62,8 +60,8 @@ public class DirectAgentAttache extends AgentAttache { @Override public void disconnect(Status state) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Processing disconnect " + _id + "(" + _name + ")"); + if (logger.isDebugEnabled()) { + logger.debug("Processing disconnect " + _id + "(" + _name + ")"); } for (ScheduledFuture future : _futures) { @@ -119,7 +117,7 @@ public class DirectAgentAttache extends AgentAttache { if (answers != null && answers[0] instanceof StartupAnswer) { StartupAnswer startup = (StartupAnswer)answers[0]; int interval = startup.getPingInterval(); - s_logger.info("StartupAnswer received " + startup.getHostId() + " Interval = " + interval); + logger.info("StartupAnswer received " + startup.getHostId() + " Interval = " + interval); _futures.add(_agentMgr.getCronJobPool().scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS)); } } @@ -130,7 +128,7 @@ public class DirectAgentAttache extends AgentAttache { assert _resource == null : "Come on now....If you're going to dabble in agent code, you better know how to close out our resources. Ever considered why there's a method called disconnect()?"; synchronized (this) { if (_resource != null) { - s_logger.warn("Lost attache for " + _id + "(" + _name + ")"); + logger.warn("Lost attache for " + _id + "(" + _name + ")"); disconnect(Status.Alert); } } @@ -144,8 +142,8 @@ public class DirectAgentAttache extends AgentAttache { } private synchronized void scheduleFromQueue() { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Agent attache=" + _id + ", task queue size=" + tasks.size() + ", outstanding tasks=" + _outstandingTaskCount.get()); + if (logger.isTraceEnabled()) { + logger.trace("Agent attache=" + _id + ", task queue size=" + tasks.size() + ", outstanding tasks=" + _outstandingTaskCount.get()); } while (!tasks.isEmpty() && _outstandingTaskCount.get() < _agentMgr.getDirectAgentThreadCap()) { _outstandingTaskCount.incrementAndGet(); @@ -158,7 +156,7 @@ public class DirectAgentAttache extends AgentAttache { protected synchronized void runInContext() { try { if (_outstandingCronTaskCount.incrementAndGet() >= _agentMgr.getDirectAgentThreadCap()) { - s_logger.warn("PingTask execution for direct attache(" + _id + ") has reached maximum outstanding limit(" + _agentMgr.getDirectAgentThreadCap() + "), bailing out"); + logger.warn("PingTask execution for direct attache(" + _id + ") has reached maximum outstanding limit(" + _agentMgr.getDirectAgentThreadCap() + "), bailing out"); return; } @@ -173,28 +171,28 @@ public class DirectAgentAttache extends AgentAttache { } if (cmd == null) { - s_logger.warn("Unable to get current status on " + _id + "(" + _name + ")"); + logger.warn("Unable to get current status on " + _id + "(" + _name + ")"); return; } if (cmd.getContextParam("logid") != null) { - MDC.put("logcontextid", cmd.getContextParam("logid")); + ThreadContext.put("logcontextid", cmd.getContextParam("logid")); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping from " + _id + "(" + _name + ")"); + if (logger.isDebugEnabled()) { + logger.debug("Ping from " + _id + "(" + _name + ")"); } long seq = _seq++; - if (s_logger.isTraceEnabled()) { - s_logger.trace("SeqA " + _id + "-" + seq + ": " + new Request(_id, -1, cmd, false).toString()); + if (logger.isTraceEnabled()) { + logger.trace("SeqA " + _id + "-" + seq + ": " + new Request(_id, -1, cmd, false).toString()); } _agentMgr.handleCommands(DirectAgentAttache.this, seq, new Command[] {cmd}); } else { - s_logger.debug("Unable to send ping because agent is disconnected " + _id + "(" + _name + ")"); + logger.debug("Unable to send ping because agent is disconnected " + _id + "(" + _name + ")"); } } catch (Exception e) { - s_logger.warn("Unable to complete the ping task", e); + logger.warn("Unable to complete the ping task", e); } finally { _outstandingCronTaskCount.decrementAndGet(); } @@ -220,7 +218,7 @@ public class DirectAgentAttache extends AgentAttache { Response resp = new Response(_req, answers.toArray(new Answer[answers.size()])); processAnswers(seq, resp); } catch (Exception e) { - s_logger.warn(log(seq, "Exception caught in bailout "), e); + logger.warn(log(seq, "Exception caught in bailout "), e); } } @@ -229,7 +227,7 @@ public class DirectAgentAttache extends AgentAttache { long seq = _req.getSequence(); try { if (_outstandingCronTaskCount.incrementAndGet() >= _agentMgr.getDirectAgentThreadCap()) { - s_logger.warn("CronTask execution for direct attache(" + _id + ") has reached maximum outstanding limit(" + _agentMgr.getDirectAgentThreadCap() + "), bailing out"); + logger.warn("CronTask execution for direct attache(" + _id + ") has reached maximum outstanding limit(" + _agentMgr.getDirectAgentThreadCap() + "), bailing out"); bailout(); return; } @@ -238,47 +236,47 @@ public class DirectAgentAttache extends AgentAttache { Command[] cmds = _req.getCommands(); boolean stopOnError = _req.stopOnError(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Executing request")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Executing request")); } ArrayList answers = new ArrayList(cmds.length); for (int i = 0; i < cmds.length; i++) { Answer answer = null; Command currentCmd = cmds[i]; if (currentCmd.getContextParam("logid") != null) { - MDC.put("logcontextid", currentCmd.getContextParam("logid")); + ThreadContext.put("logcontextid", currentCmd.getContextParam("logid")); } try { if (resource != null) { answer = resource.executeRequest(cmds[i]); if (answer == null) { - s_logger.warn("Resource returned null answer!"); + logger.warn("Resource returned null answer!"); answer = new Answer(cmds[i], false, "Resource returned null answer"); } } else { answer = new Answer(cmds[i], false, "Agent is disconnected"); } } catch (Exception e) { - s_logger.warn(log(seq, "Exception Caught while executing command"), e); + logger.warn(log(seq, "Exception Caught while executing command"), e); answer = new Answer(cmds[i], false, e.toString()); } answers.add(answer); if (!answer.getResult() && stopOnError) { - if (i < cmds.length - 1 && s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Cancelling because one of the answers is false and it is stop on error.")); + if (i < cmds.length - 1 && logger.isDebugEnabled()) { + logger.debug(log(seq, "Cancelling because one of the answers is false and it is stop on error.")); } break; } } Response resp = new Response(_req, answers.toArray(new Answer[answers.size()])); - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Response Received: ")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Response Received: ")); } processAnswers(seq, resp); } catch (Exception e) { - s_logger.warn(log(seq, "Exception caught "), e); + logger.warn(log(seq, "Exception caught "), e); } finally { _outstandingCronTaskCount.decrementAndGet(); } @@ -300,21 +298,21 @@ public class DirectAgentAttache extends AgentAttache { Command[] cmds = _req.getCommands(); boolean stopOnError = _req.stopOnError(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Executing request")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Executing request")); } ArrayList answers = new ArrayList(cmds.length); for (int i = 0; i < cmds.length; i++) { Answer answer = null; Command currentCmd = cmds[i]; if (currentCmd.getContextParam("logid") != null) { - MDC.put("logcontextid", currentCmd.getContextParam("logid")); + ThreadContext.put("logcontextid", currentCmd.getContextParam("logid")); } try { if (resource != null) { answer = resource.executeRequest(cmds[i]); if (answer == null) { - s_logger.warn("Resource returned null answer!"); + logger.warn("Resource returned null answer!"); answer = new Answer(cmds[i], false, "Resource returned null answer"); } } else { @@ -322,27 +320,27 @@ public class DirectAgentAttache extends AgentAttache { } } catch (Throwable t) { // Catch Throwable as all exceptions will otherwise be eaten by the executor framework - s_logger.warn(log(seq, "Throwable caught while executing command"), t); + logger.warn(log(seq, "Throwable caught while executing command"), t); answer = new Answer(cmds[i], false, t.toString()); } answers.add(answer); if (!answer.getResult() && stopOnError) { - if (i < cmds.length - 1 && s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Cancelling because one of the answers is false and it is stop on error.")); + if (i < cmds.length - 1 && logger.isDebugEnabled()) { + logger.debug(log(seq, "Cancelling because one of the answers is false and it is stop on error.")); } break; } } Response resp = new Response(_req, answers.toArray(new Answer[answers.size()])); - if (s_logger.isDebugEnabled()) { - s_logger.debug(log(seq, "Response Received: ")); + if (logger.isDebugEnabled()) { + logger.debug(log(seq, "Response Received: ")); } processAnswers(seq, resp); } catch (Throwable t) { // This is pretty serious as processAnswers might not be called and the calling process is stuck waiting for the full timeout - s_logger.error(log(seq, "Throwable caught in runInContext, this will cause the management to become unpredictable"), t); + logger.error(log(seq, "Throwable caught in runInContext, this will cause the management to become unpredictable"), t); } finally { _outstandingTaskCount.decrementAndGet(); scheduleFromQueue(); diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/SynchronousListener.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/SynchronousListener.java index 96d40777f8e..b5687e2636a 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/SynchronousListener.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/SynchronousListener.java @@ -16,7 +16,8 @@ // under the License. package com.cloud.agent.manager; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.Listener; import com.cloud.agent.api.AgentControlAnswer; @@ -29,7 +30,7 @@ import com.cloud.host.Status; import com.cloud.utils.Profiler; public class SynchronousListener implements Listener { - private static final Logger s_logger = Logger.getLogger(SynchronousListener.class); + protected Logger logger = LogManager.getLogger(getClass()); protected Answer[] _answers; protected boolean _disconnected; @@ -70,8 +71,8 @@ public class SynchronousListener implements Listener { @Override public synchronized boolean processDisconnect(long agentId, Status state) { - if (s_logger.isTraceEnabled()) - s_logger.trace("Agent disconnected, agent id: " + agentId + ", state: " + state + ". Will notify waiters"); + if (logger.isTraceEnabled()) + logger.trace("Agent disconnected, agent id: " + agentId + ", state: " + state + ". Will notify waiters"); _disconnected = true; notifyAll(); @@ -127,8 +128,8 @@ public class SynchronousListener implements Listener { } profiler.stop(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Synchronized command - sending completed, time: " + profiler.getDurationInMillis() + ", answer: " + + if (logger.isTraceEnabled()) { + logger.trace("Synchronized command - sending completed, time: " + profiler.getDurationInMillis() + ", answer: " + (_answers != null ? _answers[0].toString() : "null")); } return _answers; diff --git a/engine/orchestration/src/main/java/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java b/engine/orchestration/src/main/java/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java index c774470b758..641ae441480 100644 --- a/engine/orchestration/src/main/java/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java +++ b/engine/orchestration/src/main/java/com/cloud/cluster/agentlb/ClusterBasedAgentLoadBalancerPlanner.java @@ -26,7 +26,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.host.Host; @@ -39,7 +38,6 @@ import com.cloud.utils.db.SearchCriteria.Op; @Component public class ClusterBasedAgentLoadBalancerPlanner extends AdapterBase implements AgentLoadBalancerPlanner { - private static final Logger s_logger = Logger.getLogger(AgentLoadBalancerPlanner.class); @Inject HostDao _hostDao = null; @@ -52,7 +50,7 @@ public class ClusterBasedAgentLoadBalancerPlanner extends AdapterBase implements List allHosts = sc.list(); if (allHosts.size() <= avLoad) { - s_logger.debug("Agent load = " + allHosts.size() + " for management server " + msId + " doesn't exceed average system agent load = " + avLoad + + logger.debug("Agent load = " + allHosts.size() + " for management server " + msId + " doesn't exceed average system agent load = " + avLoad + "; so it doesn't participate in agent rebalancing process"); return null; } @@ -64,7 +62,7 @@ public class ClusterBasedAgentLoadBalancerPlanner extends AdapterBase implements List directHosts = sc.list(); if (directHosts.isEmpty()) { - s_logger.debug("No direct agents in status " + Status.Up + " exist for the management server " + msId + + logger.debug("No direct agents in status " + Status.Up + " exist for the management server " + msId + "; so it doesn't participate in agent rebalancing process"); return null; } @@ -90,23 +88,23 @@ public class ClusterBasedAgentLoadBalancerPlanner extends AdapterBase implements int hostsLeft = directHosts.size(); List hostsToReturn = new ArrayList(); - s_logger.debug("Management server " + msId + " can give away " + hostsToGive + " as it currently owns " + allHosts.size() + + logger.debug("Management server " + msId + " can give away " + hostsToGive + " as it currently owns " + allHosts.size() + " and the average agent load in the system is " + avLoad + "; finalyzing list of hosts to give away..."); for (Long cluster : hostToClusterMap.keySet()) { List hostsInCluster = hostToClusterMap.get(cluster); hostsLeft = hostsLeft - hostsInCluster.size(); if (hostsToReturn.size() < hostsToGive) { - s_logger.debug("Trying cluster id=" + cluster); + logger.debug("Trying cluster id=" + cluster); if (hostsInCluster.size() > hostsLeftToGive) { - s_logger.debug("Skipping cluster id=" + cluster + " as it has more hosts than we need: " + hostsInCluster.size() + " vs " + hostsLeftToGive); + logger.debug("Skipping cluster id=" + cluster + " as it has more hosts than we need: " + hostsInCluster.size() + " vs " + hostsLeftToGive); if (hostsLeft >= hostsLeftToGive) { continue; } else { break; } } else { - s_logger.debug("Taking all " + hostsInCluster.size() + " hosts: " + hostsInCluster + " from cluster id=" + cluster); + logger.debug("Taking all " + hostsInCluster.size() + " hosts: " + hostsInCluster + " from cluster id=" + cluster); hostsToReturn.addAll(hostsInCluster); hostsLeftToGive = hostsLeftToGive - hostsInCluster.size(); } @@ -115,7 +113,7 @@ public class ClusterBasedAgentLoadBalancerPlanner extends AdapterBase implements } } - s_logger.debug("Management server " + msId + " is ready to give away " + hostsToReturn.size() + " hosts"); + logger.debug("Management server " + msId + " is ready to give away " + hostsToReturn.size() + " hosts"); return hostsToReturn; } diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java index ccc005c3932..9f743668cd5 100755 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java @@ -1,4 +1,4 @@ -// Licensed to the Apacohe Software Foundation (ASF) under one +// 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 @@ -19,6 +19,7 @@ package com.cloud.vm; import static com.cloud.configuration.ConfigurationManagerImpl.MIGRATE_VM_ACROSS_CLUSTERS; +import java.lang.reflect.Field; import java.net.URI; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -35,6 +36,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.TimeZone; import java.util.UUID; @@ -47,6 +49,12 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import javax.persistence.EntityExistsException; +import com.cloud.configuration.Resource; +import com.cloud.domain.Domain; +import com.cloud.domain.dao.DomainDao; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.user.dao.AccountDao; import com.cloud.event.ActionEventUtils; import com.google.gson.Gson; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; @@ -80,6 +88,7 @@ import org.apache.cloudstack.framework.messagebus.MessageDispatcher; import org.apache.cloudstack.framework.messagebus.MessageHandler; import org.apache.cloudstack.jobs.JobInfo; import org.apache.cloudstack.managed.context.ManagedContextRunnable; +import org.apache.cloudstack.reservation.dao.ReservationDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.to.VolumeObjectTO; @@ -88,7 +97,6 @@ import org.apache.cloudstack.vm.UnmanagedVMsManager; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -149,7 +157,6 @@ import com.cloud.api.query.dao.UserVmJoinDao; import com.cloud.api.query.vo.DomainRouterJoinVO; import com.cloud.api.query.vo.UserVmJoinVO; import com.cloud.capacity.CapacityManager; -import com.cloud.configuration.Resource.ResourceType; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterDetailsVO; import com.cloud.dc.ClusterVO; @@ -166,6 +173,7 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.deploy.DeploymentPlanningManager; +import com.cloud.deploy.DeploymentPlanningManagerImpl; import com.cloud.deployasis.dao.UserVmDeployAsIsDetailsDao; import com.cloud.event.EventTypes; import com.cloud.event.UsageEventUtils; @@ -213,8 +221,8 @@ import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.ScopeType; -import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage; +import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePool; import com.cloud.storage.VMTemplateVO; @@ -238,6 +246,7 @@ import com.cloud.user.User; import com.cloud.uservm.UserVm; import com.cloud.utils.DateUtil; import com.cloud.utils.Journal; +import com.cloud.utils.LogUtils; import com.cloud.utils.Pair; import com.cloud.utils.Predicate; import com.cloud.utils.ReflectionUse; @@ -271,7 +280,6 @@ import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDao; public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMachineManager, VmWorkJobHandler, Listener, Configurable { - private static final Logger s_logger = Logger.getLogger(VirtualMachineManagerImpl.class); public static final String VM_WORK_JOB_HANDLER = VirtualMachineManagerImpl.class.getSimpleName(); @@ -290,6 +298,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Inject private VMInstanceDao _vmDao; @Inject + private ReservationDao _reservationDao; + @Inject private ServiceOfferingDao _offeringDao; @Inject private DiskOfferingDao _diskOfferingDao; @@ -385,6 +395,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac private DomainRouterJoinDao domainRouterJoinDao; @Inject private AnnotationDao annotationDao; + @Inject + private AccountDao accountDao; + @Inject + private VpcDao vpcDao; + @Inject + private DomainDao domainDao; VmWorkJobHandlerProxy _jobHandlerProxy = new VmWorkJobHandlerProxy(this); @@ -459,14 +475,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final LinkedHashMap> auxiliaryNetworks, final DeploymentPlan plan, final HypervisorType hyperType, final Map> extraDhcpOptions, final Map datadiskTemplateToDiskOfferingMap) throws InsufficientCapacityException { - s_logger.info(String.format("allocating virtual machine from template:%s with hostname:%s and %d networks", template.getUuid(), vmInstanceName, auxiliaryNetworks.size())); + logger.info(String.format("allocating virtual machine from template:%s with hostname:%s and %d networks", template.getUuid(), vmInstanceName, auxiliaryNetworks.size())); VMInstanceVO persistedVm = null; try { final VMInstanceVO vm = _vmDao.findVMByInstanceName(vmInstanceName); final Account owner = _entityMgr.findById(Account.class, vm.getAccountId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Allocating entries for VM: " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Allocating entries for VM: " + vm); } vm.setDataCenterId(plan.getDataCenterId()); @@ -484,8 +500,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } final Long rootDiskSizeFinal = rootDiskSize; - if (s_logger.isDebugEnabled()) { - s_logger.debug("Allocating nics for " + persistedVm); + if (logger.isDebugEnabled()) { + logger.debug("Allocating nics for " + persistedVm); } try { @@ -496,8 +512,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throw new CloudRuntimeException("Concurrent operation while trying to allocate resources for the VM", e); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Allocating disks for " + persistedVm); + if (logger.isDebugEnabled()) { + logger.debug("Allocating disks for " + persistedVm); } allocateRootVolume(persistedVm, template, rootDiskOfferingInfo, owner, rootDiskSizeFinal); @@ -527,8 +543,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac CallContext.unregister(); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Allocation completed for VM: " + persistedVm); + if (logger.isDebugEnabled()) { + logger.debug("Allocation completed for VM: " + persistedVm); } } catch (InsufficientCapacityException | CloudRuntimeException e) { // Failed VM will be in Stopped. Transition it to Error, so it can be expunged by ExpungeTask or similar @@ -537,7 +553,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac stateTransitTo(persistedVm, VirtualMachine.Event.OperationFailedToError, null); } } catch (NoTransitionException nte) { - s_logger.error(String.format("Failed to transition %s in %s state to Error state", persistedVm, persistedVm.getState().toString())); + logger.error(String.format("Failed to transition %s in %s state to Error state", persistedVm, persistedVm.getState().toString())); } throw e; } @@ -552,7 +568,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac volumeMgr.allocateRawVolume(Type.ROOT, rootVolumeName, rootDiskOfferingInfo.getDiskOffering(), rootDiskOfferingInfo.getSize(), rootDiskOfferingInfo.getMinIops(), rootDiskOfferingInfo.getMaxIops(), vm, template, owner, null); } else if (template.getFormat() == ImageFormat.BAREMETAL) { - s_logger.debug(String.format("%s has format [%s]. Skipping ROOT volume [%s] allocation.", template.toString(), ImageFormat.BAREMETAL, rootVolumeName)); + logger.debug(String.format("%s has format [%s]. Skipping ROOT volume [%s] allocation.", template.toString(), ImageFormat.BAREMETAL, rootVolumeName)); } else { volumeMgr.allocateTemplatedVolumes(Type.ROOT, rootVolumeName, rootDiskOfferingInfo.getDiskOffering(), rootDiskSizeFinal, rootDiskOfferingInfo.getMinIops(), rootDiskOfferingInfo.getMaxIops(), template, vm, owner); @@ -599,11 +615,18 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac VirtualMachine.Type.ConsoleProxy.equals(vm.getType()); } - protected void advanceExpunge(VMInstanceVO vm) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException { + private boolean isVmDestroyed(VMInstanceVO vm) { if (vm == null || vm.getRemoved() != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find vm or vm is destroyed: " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Unable to find vm or vm is expunged: " + vm); } + return true; + } + return false; + } + + protected void advanceExpunge(VMInstanceVO vm) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException { + if (isVmDestroyed(vm)) { return; } @@ -612,17 +635,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { if (!stateTransitTo(vm, VirtualMachine.Event.ExpungeOperation, vm.getHostId())) { - s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm); - throw new CloudRuntimeException("Unable to destroy " + vm); + logger.debug("Unable to expunge the vm because it is not in the correct state: " + vm); + throw new CloudRuntimeException("Unable to expunge " + vm); } } catch (final NoTransitionException e) { - s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm); - throw new CloudRuntimeException("Unable to destroy " + vm, e); + logger.debug("Unable to expunge the vm because it is not in the correct state: " + vm); + throw new CloudRuntimeException("Unable to expunge " + vm, e); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Destroying vm " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Expunging vm " + vm); } final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); @@ -630,11 +653,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); List vmNics = profile.getNics(); - s_logger.debug(String.format("Cleaning up NICS [%s] of %s.", vmNics.stream().map(nic -> nic.toString()).collect(Collectors.joining(", ")),vm.toString())); + logger.debug(String.format("Cleaning up NICS [%s] of %s.", vmNics.stream().map(nic -> nic.toString()).collect(Collectors.joining(", ")),vm.toString())); final List nicExpungeCommands = hvGuru.finalizeExpungeNics(vm, profile.getNics()); _networkMgr.cleanupNics(profile); - s_logger.debug(String.format("Cleaning up hypervisor data structures (ex. SRs in XenServer) for managed storage. Data from %s.", vm.toString())); + logger.debug(String.format("Cleaning up hypervisor data structures (ex. SRs in XenServer) for managed storage. Data from %s.", vm.toString())); final List volumeExpungeCommands = hvGuru.finalizeExpungeVolumes(vm); @@ -674,26 +697,29 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac // send hypervisor-dependent commands before removing final List finalizeExpungeCommands = hvGuru.finalizeExpunge(vm); - if (CollectionUtils.isNotEmpty(finalizeExpungeCommands) || CollectionUtils.isNotEmpty(nicExpungeCommands)) { - if (hostId != null) { - final Commands cmds = new Commands(Command.OnError.Stop); - addAllExpungeCommandsFromList(finalizeExpungeCommands, cmds, vm); - addAllExpungeCommandsFromList(nicExpungeCommands, cmds, vm); - _agentMgr.send(hostId, cmds); - if (!cmds.isSuccessful()) { - for (final Answer answer : cmds.getAnswers()) { - if (!answer.getResult()) { - s_logger.warn("Failed to expunge vm due to: " + answer.getDetails()); - throw new CloudRuntimeException("Unable to expunge " + vm + " due to " + answer.getDetails()); - } + handleUnsuccessfulExpungeOperation(finalizeExpungeCommands, nicExpungeCommands, vm, hostId); + + if (logger.isDebugEnabled()) { + logger.debug("Expunged " + vm); + } + } + + private void handleUnsuccessfulExpungeOperation(List finalizeExpungeCommands, List nicExpungeCommands, + VMInstanceVO vm, Long hostId) throws OperationTimedoutException, AgentUnavailableException { + if (CollectionUtils.isNotEmpty(finalizeExpungeCommands) || CollectionUtils.isNotEmpty(nicExpungeCommands) && (hostId != null)) { + final Commands cmds = new Commands(Command.OnError.Stop); + addAllExpungeCommandsFromList(finalizeExpungeCommands, cmds, vm); + addAllExpungeCommandsFromList(nicExpungeCommands, cmds, vm); + _agentMgr.send(hostId, cmds); + if (!cmds.isSuccessful()) { + for (final Answer answer : cmds.getAnswers()) { + if (!answer.getResult()) { + logger.warn("Failed to expunge vm due to: " + answer.getDetails()); + throw new CloudRuntimeException(String.format("Unable to expunge %s due to %s", vm, answer.getDetails())); } } } } - - if (s_logger.isDebugEnabled()) { - s_logger.debug("Expunged " + vm); - } } protected void handleUnsuccessfulCommands(Commands cmds, VMInstanceVO vm) throws CloudRuntimeException { @@ -701,15 +727,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac String vmToString = vm.toString(); if (cmds.isSuccessful()) { - s_logger.debug(String.format("The commands [%s] to %s were successful.", cmdsStr, vmToString)); + logger.debug(String.format("The commands [%s] to %s were successful.", cmdsStr, vmToString)); return; } - s_logger.info(String.format("The commands [%s] to %s were unsuccessful. Handling answers.", cmdsStr, vmToString)); + logger.info(String.format("The commands [%s] to %s were unsuccessful. Handling answers.", cmdsStr, vmToString)); Answer[] answers = cmds.getAnswers(); if (answers == null) { - s_logger.debug(String.format("There are no answers to commands [%s] to %s.", cmdsStr, vmToString)); + logger.debug(String.format("There are no answers to commands [%s] to %s.", cmdsStr, vmToString)); return; } @@ -717,11 +743,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac String details = answer.getDetails(); if (!answer.getResult()) { String message = String.format("Unable to expunge %s due to [%s].", vmToString, details); - s_logger.error(message); + logger.error(message); throw new CloudRuntimeException(message); } - s_logger.debug(String.format("Commands [%s] to %s got answer [%s].", cmdsStr, vmToString, details)); + logger.debug(String.format("Commands [%s] to %s got answer [%s].", cmdsStr, vmToString, details)); } } @@ -731,8 +757,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } for (final Command command : cmdList) { command.setBypassHostMaintenance(isValidSystemVMType(vm)); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Adding expunge command [%s] for VM [%s]", command.toString(), vm.toString())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Adding expunge command [%s] for VM [%s]", command.toString(), vm.toString())); } cmds.addCommand(command); } @@ -785,12 +811,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Answer answer = _agentMgr.easySend(hostId, cmd); if (answer == null) { - s_logger.warn(String.format("Unable to get an answer to the modify targets command. Targets [%s].", cmd.getTargets().stream().map(target -> target.toString()).collect(Collectors.joining(", ")))); + logger.warn(String.format("Unable to get an answer to the modify targets command. Targets [%s].", cmd.getTargets().stream().map(target -> target.toString()).collect(Collectors.joining(", ")))); return; } if (!answer.getResult()) { - s_logger.warn(String.format("Unable to modify targets [%s] on the host [%s].", cmd.getTargets().stream().map(target -> target.toString()).collect(Collectors.joining(", ")), hostId)); + logger.warn(String.format("Unable to modify targets [%s] on the host [%s].", cmd.getTargets().stream().map(target -> target.toString()).collect(Collectors.joining(", ")), hostId)); } } @@ -853,46 +879,46 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac while (true) { final ItWorkVO vo = _workDao.findByOutstandingWork(vm.getId(), state); if (vo == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find work for VM: " + vm + " and state: " + state); + if (logger.isDebugEnabled()) { + logger.debug("Unable to find work for VM: " + vm + " and state: " + state); } return true; } if (vo.getStep() == Step.Done) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Work for " + vm + " is " + vo.getStep()); + if (logger.isDebugEnabled()) { + logger.debug("Work for " + vm + " is " + vo.getStep()); } return true; } final VMInstanceVO instance = _vmDao.findById(vm.getId()); if (instance != null && instance.getState() == State.Running) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("VM is already started in DB: " + vm); + if (logger.isDebugEnabled()) { + logger.debug("VM is already started in DB: " + vm); } return true; } if (vo.getSecondsTaskIsInactive() > VmOpCancelInterval.value()) { - s_logger.warn("The task item for vm " + vm + " has been inactive for " + vo.getSecondsTaskIsInactive()); + logger.warn("The task item for vm " + vm + " has been inactive for " + vo.getSecondsTaskIsInactive()); return false; } try { Thread.sleep(VmOpWaitInterval.value()*1000); } catch (final InterruptedException e) { - s_logger.info("Waiting for " + vm + " but is interrupted"); + logger.info("Waiting for " + vm + " but is interrupted"); throw new ConcurrentOperationException("Waiting for " + vm + " but is interrupted"); } - s_logger.debug("Waiting some more to make sure there's no activity on " + vm); + logger.debug("Waiting some more to make sure there's no activity on " + vm); } } @DB protected Ternary changeToStartState(final VirtualMachineGuru vmGuru, final VMInstanceVO vm, final User caller, - final Account account) throws ConcurrentOperationException { + final Account account, Account owner, ServiceOfferingVO offering, VirtualMachineTemplate template) throws ConcurrentOperationException { final long vmId = vm.getId(); ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Starting, vm.getType(), vm.getId()); @@ -904,13 +930,16 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Transaction.execute(new TransactionCallbackWithException, NoTransitionException>() { @Override public Ternary doInTransaction(final TransactionStatus status) throws NoTransitionException { - final Journal journal = new Journal.LogJournal("Creating " + vm, s_logger); + final Journal journal = new Journal.LogJournal("Creating " + vm, logger); final ItWorkVO work = _workDao.persist(workFinal); final ReservationContextImpl context = new ReservationContextImpl(work.getId(), journal, caller, account); if (stateTransitTo(vm, Event.StartRequested, null, work.getId())) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Successfully transitioned to start state for " + vm + " reservation id = " + work.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Successfully transitioned to start state for " + vm + " reservation id = " + work.getId()); + } + if (VirtualMachine.Type.User.equals(vm.type) && ResourceCountRunningVMsonly.value()) { + _resourceLimitMgr.incrementVmResourceCount(owner.getAccountId(), vm.isDisplay(), offering, template); } return new Ternary<>(vm, context, work); } @@ -924,8 +953,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return result; } } catch (final NoTransitionException e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to transition into Starting state due to " + e.getMessage()); + if (logger.isDebugEnabled()) { + logger.debug("Unable to transition into Starting state due to " + e.getMessage()); } } @@ -934,14 +963,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throw new ConcurrentOperationException("Unable to acquire lock on " + vm); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Determining why we're unable to update the state to Starting for " + instance + ". Retry=" + retry); + if (logger.isDebugEnabled()) { + logger.debug("Determining why we're unable to update the state to Starting for " + instance + ". Retry=" + retry); } final State state = instance.getState(); if (state == State.Running) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("VM is already started: " + vm); + if (logger.isDebugEnabled()) { + logger.debug("VM is already started: " + vm); } return null; } @@ -956,7 +985,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (state != State.Stopped) { String msg = String.format("Cannot start %s in %s state", vm, state); - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } } @@ -1000,8 +1029,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext(); if ( jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("start parameter value of %s == %s during dispatching", + if (logger.isDebugEnabled()) { + logger.debug(String.format("start parameter value of %s == %s during dispatching", VirtualMachineProfile.Param.BootIntoSetup.getName(), (params == null?"":params.get(VirtualMachineProfile.Param.BootIntoSetup)))); } @@ -1016,8 +1045,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("start parameter value of %s == %s during processing of queued job", + if (logger.isDebugEnabled()) { + logger.debug(String.format("start parameter value of %s == %s during processing of queued job", VirtualMachineProfile.Param.BootIntoSetup.getName(), (params == null?"":params.get(VirtualMachineProfile.Param.BootIntoSetup)))); } @@ -1039,10 +1068,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac new ArrayList<>(ipAddressDetails.values()), CAManager.CertValidityPeriod.value(), null); final boolean result = caManager.deployCertificate(vmHost, certificate, false, sshAccessDetails); if (!result) { - s_logger.error("Failed to setup certificate for system vm: " + vm.getInstanceName()); + logger.error("Failed to setup certificate for system vm: " + vm.getInstanceName()); } } else { - s_logger.error("Failed to setup keystore and generate CSR for system vm: " + vm.getInstanceName()); + logger.error("Failed to setup keystore and generate CSR for system vm: " + vm.getInstanceName()); } } @@ -1060,13 +1089,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final VMTemplateVO template = _templateDao.findById(vm.getTemplateId()); if (template == null) { String msg = "Template for the VM instance can not be found, VM instance configuration needs to be updated"; - s_logger.error(String.format("%s. Template ID: %d seems to be removed", msg, vm.getTemplateId())); + logger.error(String.format("%s. Template ID: %d seems to be removed", msg, vm.getTemplateId())); throw new CloudRuntimeException(msg); } final VMTemplateZoneVO templateZoneVO = templateZoneDao.findByZoneTemplate(vm.getDataCenterId(), template.getId()); if (templateZoneVO == null) { String msg = "Template for the VM instance can not be found in the zone ID: %s, VM instance configuration needs to be updated"; - s_logger.error(String.format("%s. %s", msg, template)); + logger.error(String.format("%s. %s", msg, template)); throw new CloudRuntimeException(msg); } } @@ -1084,7 +1113,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } Answer[] answer = attemptHypervisorMigration(vm, volumePoolMap, lastHost.getId()); if (answer == null) { - s_logger.warn("Hypervisor inter-cluster migration during VM start failed"); + logger.warn("Hypervisor inter-cluster migration during VM start failed"); return; } // Other network related updates will be done using caller @@ -1095,6 +1124,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public void orchestrateStart(final String vmUuid, final Map params, final DeploymentPlan planToDeploy, final DeploymentPlanner planner) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { + logger.debug(() -> LogUtils.logGsonWithoutException("Trying to start VM [%s] using plan [%s] and planner [%s].", vmUuid, planToDeploy, planner)); final CallContext cctxt = CallContext.current(); final Account account = cctxt.getCallingAccount(); final User caller = cctxt.getCallingUser(); @@ -1103,7 +1133,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final VirtualMachineGuru vmGuru = getVmGuru(vm); - final Ternary start = changeToStartState(vmGuru, vm, caller, account); + final Account owner = _entityMgr.findById(Account.class, vm.getAccountId()); + final ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId()); + final VirtualMachineTemplate template = _entityMgr.findByIdIncludingRemoved(VirtualMachineTemplate.class, vm.getTemplateId()); + final Ternary start = changeToStartState(vmGuru, vm, caller, account, owner, offering, template); if (start == null) { return; } @@ -1113,15 +1146,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac ItWorkVO work = start.third(); VMInstanceVO startedVm = null; - final ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId()); - final VirtualMachineTemplate template = _entityMgr.findByIdIncludingRemoved(VirtualMachineTemplate.class, vm.getTemplateId()); DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null, ctx); if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("advanceStart: DeploymentPlan is provided, using dcId:" + planToDeploy.getDataCenterId() + ", podId: " + planToDeploy.getPodId() + - ", clusterId: " + planToDeploy.getClusterId() + ", hostId: " + planToDeploy.getHostId() + ", poolId: " + planToDeploy.getPoolId()); - } + VMInstanceVO finalVm = vm; + logger.debug(() -> DeploymentPlanningManagerImpl.logDeploymentWithoutException(finalVm, planToDeploy, planToDeploy.getAvoids(), planner)); plan = new DataCenterDeployment(planToDeploy.getDataCenterId(), planToDeploy.getPodId(), planToDeploy.getClusterId(), planToDeploy.getHostId(), planToDeploy.getPoolId(), planToDeploy.getPhysicalNetworkId(), ctx); @@ -1129,12 +1158,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType()); - // check resource count if ResourceCountRunningVMsonly.value() = true - final Account owner = _entityMgr.findById(Account.class, vm.getAccountId()); - if (VirtualMachine.Type.User.equals(vm.type) && ResourceCountRunningVMsonly.value()) { - resourceCountIncrement(owner.getAccountId(),new Long(offering.getCpu()), new Long(offering.getRamSize())); - } - boolean canRetry = true; ExcludeList avoids = null; try { @@ -1142,13 +1165,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (planToDeploy != null) { avoids = planToDeploy.getAvoids(); + ExcludeList finalAvoids = avoids; + logger.debug(() -> LogUtils.logGsonWithoutException("Avoiding components [%s] in deployment of VM [%s].", finalAvoids, vmUuid)); } if (avoids == null) { avoids = new ExcludeList(); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Deploy avoids pods: " + avoids.getPodsToAvoid() + ", clusters: " + avoids.getClustersToAvoid() + ", hosts: " + avoids.getHostsToAvoid()); - } boolean planChangedByVolume = false; boolean reuseVolume = true; @@ -1158,23 +1180,23 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac int retry = StartRetry.value(); while (retry-- != 0) { - s_logger.debug("VM start attempt #" + (StartRetry.value() - retry)); + logger.debug("VM start attempt #" + (StartRetry.value() - retry)); if (reuseVolume) { final List vols = _volsDao.findReadyRootVolumesByInstance(vm.getId()); for (final VolumeVO vol : vols) { final Long volTemplateId = vol.getTemplateId(); if (volTemplateId != null && volTemplateId != template.getId()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(vol + " of " + vm + " is READY, but template ids don't match, let the planner reassign a new pool"); + if (logger.isDebugEnabled()) { + logger.debug(vol + " of " + vm + " is READY, but template ids don't match, let the planner reassign a new pool"); } continue; } final StoragePool pool = (StoragePool)dataStoreMgr.getPrimaryDataStore(vol.getPoolId()); if (!pool.isInMaintenance()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Root volume is ready, need to place VM in volume's cluster"); + if (logger.isDebugEnabled()) { + logger.debug("Root volume is ready, need to place VM in volume's cluster"); } final long rootVolDcId = pool.getDataCenterId(); final Long rootVolPodId = pool.getPodId(); @@ -1183,8 +1205,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final Long clusterIdSpecified = planToDeploy.getClusterId(); if (clusterIdSpecified != null && rootVolClusterId != null) { if (!rootVolClusterId.equals(clusterIdSpecified)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cannot satisfy the deployment plan passed in since the ready Root volume is in different cluster. volume's cluster: " + + if (logger.isDebugEnabled()) { + logger.debug("Cannot satisfy the deployment plan passed in since the ready Root volume is in different cluster. volume's cluster: " + rootVolClusterId + ", cluster specified: " + clusterIdSpecified); } throw new ResourceUnavailableException( @@ -1197,8 +1219,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac planToDeploy.getHostId(), vol.getPoolId(), null, ctx); } else { plan = new DataCenterDeployment(rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, ctx); - if (s_logger.isDebugEnabled()) { - s_logger.debug(vol + " is READY, changing deployment plan to use this pool's dcId: " + rootVolDcId + " , podId: " + rootVolPodId + + if (logger.isDebugEnabled()) { + logger.debug(vol + " is READY, changing deployment plan to use this pool's dcId: " + rootVolDcId + " , podId: " + rootVolPodId + " , and clusterId: " + rootVolClusterId); } planChangedByVolume = true; @@ -1213,7 +1235,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { dest = _dpMgr.planDeployment(vmProfile, plan, avoids, planner); } catch (final AffinityConflictException e2) { - s_logger.warn("Unable to create deployment, affinity rules associated to the VM conflict", e2); + logger.warn("Unable to create deployment, affinity rules associated to the VM conflict", e2); throw new CloudRuntimeException("Unable to create deployment, affinity rules associated to the VM conflict"); } @@ -1279,6 +1301,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac checkAndSetEnterSetupMode(vmTO, params); handlePath(vmTO.getDisks(), vm.getHypervisorType()); + setVmNetworkDetails(vm, vmTO); + Commands cmds = new Commands(Command.OnError.Stop); final Map sshAccessDetails = _networkMgr.getSystemVMAccessDetails(vm); @@ -1320,7 +1344,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac syncDiskChainChange(startAnswer); if (!changeState(vm, Event.OperationSucceeded, destHostId, work, Step.Done)) { - s_logger.error("Unable to transition to a new state. VM uuid: "+vm.getUuid()+ "VM oldstate:"+vm.getState()+"Event:"+Event.OperationSucceeded); + logger.error("Unable to transition to a new state. VM uuid: "+vm.getUuid()+ "VM oldstate:"+vm.getState()+"Event:"+Event.OperationSucceeded); throw new ConcurrentOperationException("Failed to deploy VM"+ vm.getUuid()); } @@ -1334,8 +1358,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } startedVm = vm; - if (s_logger.isDebugEnabled()) { - s_logger.debug("Start completed for VM " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Start completed for VM " + vm); } final Host vmHost = _hostDao.findById(destHostId); if (vmHost != null && (VirtualMachine.Type.ConsoleProxy.equals(vm.getType()) || @@ -1346,19 +1370,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac new ArrayList<>(ipAddressDetails.values()), CAManager.CertValidityPeriod.value(), null); final boolean result = caManager.deployCertificate(vmHost, certificate, false, sshAccessDetails); if (!result) { - s_logger.error("Failed to setup certificate for system vm: " + vm.getInstanceName()); + logger.error("Failed to setup certificate for system vm: " + vm.getInstanceName()); } return; } catch (final Exception e) { - s_logger.error("Retrying after catching exception while trying to secure agent for systemvm id=" + vm.getId(), e); + logger.error("Retrying after catching exception while trying to secure agent for systemvm id=" + vm.getId(), e); } } throw new CloudRuntimeException("Failed to setup and secure agent for systemvm id=" + vm.getId()); } return; } else { - if (s_logger.isDebugEnabled()) { - s_logger.info("The guru did not like the answers so stopping " + vm); + if (logger.isDebugEnabled()) { + logger.info("The guru did not like the answers so stopping " + vm); } StopCommand stopCmd = new StopCommand(vm, getExecuteInSequence(vm.getHypervisorType()), false); stopCmd.setControlIp(getControlNicIpForVM(vm)); @@ -1381,49 +1405,49 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } if (answer == null || !answer.getResult()) { - s_logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers")); + logger.warn("Unable to stop " + vm + " due to " + (answer != null ? answer.getDetails() : "no answers")); _haMgr.scheduleStop(vm, destHostId, WorkType.ForceStop); throw new ExecutionException("Unable to stop this VM, "+vm.getUuid()+" so we are unable to retry the start operation"); } throw new ExecutionException("Unable to start VM:"+vm.getUuid()+" due to error in finalizeStart, not retrying"); } } - s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + (startAnswer == null ? " no start answer" : startAnswer.getDetails())); + logger.info("Unable to start VM on " + dest.getHost() + " due to " + (startAnswer == null ? " no start answer" : startAnswer.getDetails())); if (startAnswer != null && startAnswer.getContextParam("stopRetry") != null) { break; } } catch (OperationTimedoutException e) { - s_logger.debug("Unable to send the start command to host " + dest.getHost()+" failed to start VM: "+vm.getUuid()); + logger.debug("Unable to send the start command to host " + dest.getHost()+" failed to start VM: "+vm.getUuid()); if (e.isActive()) { _haMgr.scheduleStop(vm, destHostId, WorkType.CheckStop); } canRetry = false; throw new AgentUnavailableException("Unable to start " + vm.getHostName(), destHostId, e); } catch (final ResourceUnavailableException e) { - s_logger.warn("Unable to contact resource.", e); + logger.warn("Unable to contact resource.", e); if (!avoids.add(e)) { if (e.getScope() == Volume.class || e.getScope() == Nic.class) { throw e; } else { - s_logger.warn("unexpected ResourceUnavailableException : " + e.getScope().getName(), e); + logger.warn("unexpected ResourceUnavailableException : " + e.getScope().getName(), e); throw e; } } } catch (final InsufficientCapacityException e) { - s_logger.warn("Insufficient capacity ", e); + logger.warn("Insufficient capacity ", e); if (!avoids.add(e)) { if (e.getScope() == Volume.class || e.getScope() == Nic.class) { throw e; } else { - s_logger.warn("unexpected InsufficientCapacityException : " + e.getScope().getName(), e); + logger.warn("unexpected InsufficientCapacityException : " + e.getScope().getName(), e); } } } catch (ExecutionException | NoTransitionException e) { - s_logger.error("Failed to start instance " + vm, e); + logger.error("Failed to start instance " + vm, e); throw new AgentUnavailableException("Unable to start instance due to " + e.getMessage(), destHostId, e); } catch (final StorageAccessException e) { - s_logger.warn("Unable to access storage on host", e); + logger.warn("Unable to access storage on host", e); } finally { if (startedVm == null && canRetry) { final Step prevStep = work.getStep(); @@ -1440,7 +1464,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } finally { if (startedVm == null) { if (VirtualMachine.Type.User.equals(vm.type) && ResourceCountRunningVMsonly.value()) { - resourceCountDecrement(owner.getAccountId(),new Long(offering.getCpu()), new Long(offering.getRamSize())); + _resourceLimitMgr.decrementVmResourceCount(owner.getAccountId(), vm.isDisplay(), offering, template); } if (canRetry) { try { @@ -1462,6 +1486,55 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } + public void setVmNetworkDetails(VMInstanceVO vm, VirtualMachineTO vmTO) { + Map networkToNetworkNameMap = new HashMap<>(); + if (VirtualMachine.Type.User.equals(vm.getType())) { + List userVmJoinVOs = userVmJoinDao.searchByIds(vm.getId()); + if (userVmJoinVOs != null && !userVmJoinVOs.isEmpty()) { + for (UserVmJoinVO userVmJoinVO : userVmJoinVOs) { + addToNetworkNameMap(userVmJoinVO.getNetworkId(), vm.getDataCenterId(), networkToNetworkNameMap); + } + vmTO.setNetworkIdToNetworkNameMap(networkToNetworkNameMap); + } + } else if (VirtualMachine.Type.DomainRouter.equals(vm.getType())) { + List routerJoinVO = domainRouterJoinDao.getRouterByIdAndTrafficType(vm.getId(), Networks.TrafficType.Guest); + for (DomainRouterJoinVO router : routerJoinVO) { + NetworkVO guestNetwork = _networkDao.findById(router.getNetworkId()); + if (guestNetwork.getVpcId() == null && guestNetwork.getBroadcastDomainType() == Networks.BroadcastDomainType.NSX) { + addToNetworkNameMap(router.getNetworkId(), vm.getDataCenterId(), networkToNetworkNameMap); + } + } + vmTO.setNetworkIdToNetworkNameMap(networkToNetworkNameMap); + } + } + + private void addToNetworkNameMap(long networkId, long dataCenterId, Map networkToNetworkNameMap) { + NetworkVO networkVO = _networkDao.findById(networkId); + Account acc = accountDao.findById(networkVO.getAccountId()); + Domain domain = domainDao.findById(networkVO.getDomainId()); + DataCenter zone = _dcDao.findById(dataCenterId); + if (Objects.isNull(zone)) { + throw new CloudRuntimeException(String.format("Failed to find zone with ID: %s", dataCenterId)); + } + if (Objects.isNull(acc)) { + throw new CloudRuntimeException(String.format("Failed to find account with ID: %s", networkVO.getAccountId())); + } + if (Objects.isNull(domain)) { + throw new CloudRuntimeException(String.format("Failed to find domain with ID: %s", networkVO.getDomainId())); + } + String networkName = String.format("D%s-A%s-Z%s", domain.getId(), acc.getId(), zone.getId()); + if (Objects.isNull(networkVO.getVpcId())) { + networkName += "-S" + networkVO.getId(); + } else { + VpcVO vpc = vpcDao.findById(networkVO.getVpcId()); + if (Objects.isNull(vpc)) { + throw new CloudRuntimeException(String.format("Failed to find VPC with ID: %s", networkVO.getVpcId())); + } + networkName = String.format("%s-V%s-S%s", networkName, vpc.getId(), networkVO.getId()); + } + networkToNetworkNameMap.put(networkVO.getId(), networkName); + } + /** * Setting pod id to null can result in migration of Volumes across pods. This is not desirable for VMs which * have a volume in Ready state (happens when a VM is shutdown and started again). @@ -1508,7 +1581,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac log = true; } if (log) { - s_logger.info(msgBuf.toString()); + logger.info(msgBuf.toString()); } } @@ -1662,17 +1735,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return ExecuteInSequence.value(); } - switch (hypervisorType) { - case KVM: - case XenServer: - case Hyperv: - case LXC: - return false; - case VMware: - return StorageManager.shouldExecuteInSequenceOnVmware(); - default: - return ExecuteInSequence.value(); + if (Set.of(HypervisorType.KVM, HypervisorType.XenServer, HypervisorType.Hyperv, HypervisorType.LXC).contains(hypervisorType)) { + return false; + } else if (hypervisorType.equals(HypervisorType.VMware)) { + return StorageManager.shouldExecuteInSequenceOnVmware(); } + return ExecuteInSequence.value(); } @Override @@ -1685,7 +1753,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final List pendingWorkJobs = _workJobDao.listPendingWorkJobs(VirtualMachine.Type.Instance, vm.getId()); if (CollectionUtils.isNotEmpty(pendingWorkJobs) || _haMgr.hasPendingHaWork(vm.getId())) { String msg = "There are pending jobs or HA tasks working on the VM with id: " + vm.getId() + ", can't unmanage the VM."; - s_logger.info(msg); + logger.info(msg); throw new ConcurrentOperationException(msg); } @@ -1693,8 +1761,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @Override public Boolean doInTransaction(TransactionStatus status) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unmanaging vm " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Unmanaging vm " + vm); } final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); @@ -1707,7 +1775,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac guru.finalizeUnmanage(vm); } catch (Exception e) { - s_logger.error("Error while unmanaging VM " + vm, e); + logger.error("Error while unmanaging VM " + vm, e); return false; } @@ -1747,10 +1815,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac * - If 'unmanage.vm.preserve.nics' = false: then the NICs are removed while unmanaging */ private void unmanageVMNics(VirtualMachineProfile profile, VMInstanceVO vm) { - s_logger.debug(String.format("Cleaning up NICs of %s.", vm.toString())); + logger.debug(String.format("Cleaning up NICs of %s.", vm.toString())); Boolean preserveNics = UnmanagedVMsManager.UnmanageVMPreserveNic.valueIn(vm.getDataCenterId()); if (BooleanUtils.isTrue(preserveNics)) { - s_logger.debug("Preserve NICs configuration enabled"); + logger.debug("Preserve NICs configuration enabled"); profile.setParameter(VirtualMachineProfile.Param.PreserveNics, true); } _networkMgr.unmanageNics(profile); @@ -1816,7 +1884,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } if (!answer.getResult()) { final String details = answer.getDetails(); - s_logger.debug("Unable to stop VM due to " + details); + logger.debug("Unable to stop VM due to " + details); return false; } @@ -1830,12 +1898,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } } else { - s_logger.error("Invalid answer received in response to a StopCommand for " + vm.getInstanceName()); + logger.error("Invalid answer received in response to a StopCommand for " + vm.getInstanceName()); return false; } } catch (final AgentUnavailableException | OperationTimedoutException e) { - s_logger.warn(String.format("Unable to stop %s due to [%s].", vm.toString(), e.getMessage()), e); + logger.warn(String.format("Unable to stop %s due to [%s].", vm.toString(), e.getMessage()), e); if (!force) { return false; } @@ -1847,33 +1915,33 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac protected boolean cleanup(final VirtualMachineGuru guru, final VirtualMachineProfile profile, final ItWorkVO work, final Event event, final boolean cleanUpEvenIfUnableToStop) { final VirtualMachine vm = profile.getVirtualMachine(); final State state = vm.getState(); - s_logger.debug("Cleaning up resources for the vm " + vm + " in " + state + " state"); + logger.debug("Cleaning up resources for the vm " + vm + " in " + state + " state"); try { if (state == State.Starting) { if (work != null) { final Step step = work.getStep(); if (step == Step.Starting && !cleanUpEvenIfUnableToStop) { - s_logger.warn("Unable to cleanup vm " + vm + "; work state is incorrect: " + step); + logger.warn("Unable to cleanup vm " + vm + "; work state is incorrect: " + step); return false; } if (step == Step.Started || step == Step.Starting || step == Step.Release) { if (vm.getHostId() != null) { if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop, false)) { - s_logger.warn("Failed to stop vm " + vm + " in " + State.Starting + " state as a part of cleanup process"); + logger.warn("Failed to stop vm " + vm + " in " + State.Starting + " state as a part of cleanup process"); return false; } } } if (step != Step.Release && step != Step.Prepare && step != Step.Started && step != Step.Starting) { - s_logger.debug("Cleanup is not needed for vm " + vm + "; work state is incorrect: " + step); + logger.debug("Cleanup is not needed for vm " + vm + "; work state is incorrect: " + step); return true; } } else { if (vm.getHostId() != null) { if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop, false)) { - s_logger.warn("Failed to stop vm " + vm + " in " + State.Starting + " state as a part of cleanup process"); + logger.warn("Failed to stop vm " + vm + " in " + State.Starting + " state as a part of cleanup process"); return false; } } @@ -1882,26 +1950,26 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } else if (state == State.Stopping) { if (vm.getHostId() != null) { if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop, false)) { - s_logger.warn("Failed to stop vm " + vm + " in " + State.Stopping + " state as a part of cleanup process"); + logger.warn("Failed to stop vm " + vm + " in " + State.Stopping + " state as a part of cleanup process"); return false; } } } else if (state == State.Migrating) { if (vm.getHostId() != null) { if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop, false)) { - s_logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process"); + logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process"); return false; } } if (vm.getLastHostId() != null) { if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop, false)) { - s_logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process"); + logger.warn("Failed to stop vm " + vm + " in " + State.Migrating + " state as a part of cleanup process"); return false; } } } else if (state == State.Running) { if (!sendStop(guru, profile, cleanUpEvenIfUnableToStop, false)) { - s_logger.warn("Failed to stop vm " + vm + " in " + State.Running + " state as a part of cleanup process"); + logger.warn("Failed to stop vm " + vm + " in " + State.Running + " state as a part of cleanup process"); return false; } } @@ -1917,21 +1985,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final State state = vm.getState(); try { _networkMgr.release(profile, forced); - s_logger.debug(String.format("Successfully released network resources for the VM %s in %s state", vm, state)); + logger.debug(String.format("Successfully released network resources for the VM %s in %s state", vm, state)); } catch (final Exception e) { - s_logger.warn(String.format("Unable to release some network resources for the VM %s in %s state", vm, state), e); + logger.warn(String.format("Unable to release some network resources for the VM %s in %s state", vm, state), e); } try { if (vm.getHypervisorType() != HypervisorType.BareMetal) { volumeMgr.release(profile); - s_logger.debug(String.format("Successfully released storage resources for the VM %s in %s state", vm, state)); + logger.debug(String.format("Successfully released storage resources for the VM %s in %s state", vm, state)); } } catch (final Exception e) { - s_logger.warn(String.format("Unable to release storage resources for the VM %s in %s state", vm, state), e); + logger.warn(String.format("Unable to release storage resources for the VM %s in %s state", vm, state), e); } - s_logger.debug(String.format("Successfully cleaned up resources for the VM %s in %s state", vm, state)); + logger.debug(String.format("Successfully cleaned up resources for the VM %s in %s state", vm, state)); } @Override @@ -2033,42 +2101,42 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac ConcurrentOperationException { final State state = vm.getState(); if (state == State.Stopped) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("VM is already stopped: " + vm); + if (logger.isDebugEnabled()) { + logger.debug("VM is already stopped: " + vm); } return; } if (state == State.Destroyed || state == State.Expunging || state == State.Error) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Stopped called on " + vm + " but the state is " + state); + if (logger.isDebugEnabled()) { + logger.debug("Stopped called on " + vm + " but the state is " + state); } return; } final ItWorkVO work = _workDao.findByOutstandingWork(vm.getId(), vm.getState()); if (work != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found an outstanding work item for this vm " + vm + " with state:" + vm.getState() + ", work id:" + work.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Found an outstanding work item for this vm " + vm + " with state:" + vm.getState() + ", work id:" + work.getId()); } } final Long hostId = vm.getHostId(); if (hostId == null) { if (!cleanUpEvenIfUnableToStop) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("HostId is null but this is not a forced stop, cannot stop vm " + vm + " with state:" + vm.getState()); + if (logger.isDebugEnabled()) { + logger.debug("HostId is null but this is not a forced stop, cannot stop vm " + vm + " with state:" + vm.getState()); } throw new CloudRuntimeException("Unable to stop " + vm); } try { stateTransitTo(vm, Event.AgentReportStopped, null, null); } catch (final NoTransitionException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); } if (work != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Updating work item to Done, id:" + work.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Updating work item to Done, id:" + work.getId()); } work.setStep(Step.Done); _workDao.update(work.getId(), work); @@ -2077,7 +2145,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } else { HostVO host = _hostDao.findById(hostId); if (!cleanUpEvenIfUnableToStop && vm.getState() == State.Running && host.getResourceState() == ResourceState.PrepareForMaintenance) { - s_logger.debug("Host is in PrepareForMaintenance state - Stop VM operation on the VM id: " + vm.getId() + " is not allowed"); + logger.debug("Host is in PrepareForMaintenance state - Stop VM operation on the VM id: " + vm.getId() + " is not allowed"); throw new CloudRuntimeException("Stop VM operation on the VM id: " + vm.getId() + " is not allowed as host is preparing for maintenance mode"); } } @@ -2094,27 +2162,27 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throw new CloudRuntimeException("We cannot stop " + vm + " when it is in state " + vm.getState()); } final boolean doCleanup = true; - if (s_logger.isDebugEnabled()) { - s_logger.warn("Unable to transition the state but we're moving on because it's forced stop", e1); + if (logger.isDebugEnabled()) { + logger.warn("Unable to transition the state but we're moving on because it's forced stop", e1); } if (doCleanup) { if (cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.StopRequested, cleanUpEvenIfUnableToStop)) { try { - if (s_logger.isDebugEnabled() && work != null) { - s_logger.debug("Updating work item to Done, id:" + work.getId()); + if (logger.isDebugEnabled() && work != null) { + logger.debug("Updating work item to Done, id:" + work.getId()); } if (!changeState(vm, Event.AgentReportStopped, null, work, Step.Done)) { throw new CloudRuntimeException("Unable to stop " + vm); } } catch (final NoTransitionException e) { - s_logger.warn("Unable to cleanup " + vm); + logger.warn("Unable to cleanup " + vm); throw new CloudRuntimeException("Unable to stop " + vm, e); } } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to cleanup VM: " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Failed to cleanup VM: " + vm); } throw new CloudRuntimeException("Failed to cleanup " + vm + " , current state " + vm.getState()); } @@ -2165,19 +2233,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } catch (AgentUnavailableException | OperationTimedoutException e) { - s_logger.warn(String.format("Unable to stop %s due to [%s].", profile.toString(), e.toString()), e); + logger.warn(String.format("Unable to stop %s due to [%s].", profile.toString(), e.toString()), e); } finally { if (!stopped) { if (!cleanUpEvenIfUnableToStop) { - s_logger.warn("Unable to stop vm " + vm); + logger.warn("Unable to stop vm " + vm); try { stateTransitTo(vm, Event.OperationFailed, vm.getHostId()); } catch (final NoTransitionException e) { - s_logger.warn("Unable to transition the state " + vm, e); + logger.warn("Unable to transition the state " + vm, e); } throw new CloudRuntimeException("Unable to stop " + vm); } else { - s_logger.warn("Unable to actually stop " + vm + " but continue with release because it's a force stop"); + logger.warn("Unable to actually stop " + vm + " but continue with release because it's a force stop"); vmGuru.finalizeStop(profile, answer); } } else { @@ -2191,33 +2259,41 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - if (s_logger.isDebugEnabled()) { - s_logger.debug(vm + " is stopped on the host. Proceeding to release resource held."); + if (logger.isDebugEnabled()) { + logger.debug(vm + " is stopped on the host. Proceeding to release resource held."); } releaseVmResources(profile, cleanUpEvenIfUnableToStop); try { if (work != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Updating the outstanding work item to Done, id:" + work.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Updating the outstanding work item to Done, id:" + work.getId()); } work.setStep(Step.Done); _workDao.update(work.getId(), work); } - boolean result = stateTransitTo(vm, Event.OperationSucceeded, null); - if (result) { - if (VirtualMachine.Type.User.equals(vm.type) && ResourceCountRunningVMsonly.value()) { - ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId()); - resourceCountDecrement(vm.getAccountId(),new Long(offering.getCpu()), new Long(offering.getRamSize())); + boolean result = Transaction.execute(new TransactionCallbackWithException() { + @Override + public Boolean doInTransaction(TransactionStatus status) throws NoTransitionException { + boolean result = stateTransitTo(vm, Event.OperationSucceeded, null); + + if (result && VirtualMachine.Type.User.equals(vm.type) && ResourceCountRunningVMsonly.value()) { + ServiceOfferingVO offering = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId()); + VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId()); + _resourceLimitMgr.decrementVmResourceCount(vm.getAccountId(), vm.isDisplay(), offering, template); + } + return result; } - } else { + }); + + if (!result) { throw new CloudRuntimeException("unable to stop " + vm); } } catch (final NoTransitionException e) { String message = String.format("Unable to stop %s due to [%s].", vm.toString(), e.getMessage()); - s_logger.warn(message, e); + logger.warn(message, e); throw new CloudRuntimeException(message, e); } } @@ -2245,6 +2321,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac vm.setLastHostId(vm.getHostId()); } } + + if (e.equals(VirtualMachine.Event.DestroyRequested) || e.equals(VirtualMachine.Event.ExpungeOperation)) { + _reservationDao.setResourceId(Resource.ResourceType.user_vm, null); + _reservationDao.setResourceId(Resource.ResourceType.cpu, null); + _reservationDao.setResourceId(Resource.ResourceType.memory, null); + } return _stateMachine.transitTo(vm, e, new Pair<>(vm.getHostId(), hostId), _vmDao); } @@ -2252,14 +2334,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public void destroy(final String vmUuid, final boolean expunge) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException { VMInstanceVO vm = _vmDao.findByUuid(vmUuid); if (vm == null || vm.getState() == State.Destroyed || vm.getState() == State.Expunging || vm.getRemoved() != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find vm or vm is destroyed: " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Unable to find vm or vm is destroyed: " + vm); } return; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Destroying vm " + vm + ", expunge flag " + (expunge ? "on" : "off")); + if (logger.isDebugEnabled()) { + logger.debug("Destroying vm " + vm + ", expunge flag " + (expunge ? "on" : "off")); } advanceStop(vmUuid, VmDestroyForcestop.value()); @@ -2272,19 +2354,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac VMInstanceVO vm = _vmDao.findByUuid(vmUuid); try { if (!stateTransitTo(vm, VirtualMachine.Event.DestroyRequested, vm.getHostId())) { - s_logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm); + logger.debug("Unable to destroy the vm because it is not in the correct state: " + vm); throw new CloudRuntimeException("Unable to destroy " + vm); } else { if (expunge) { if (!stateTransitTo(vm, VirtualMachine.Event.ExpungeOperation, vm.getHostId())) { - s_logger.debug("Unable to expunge the vm because it is not in the correct state: " + vm); + logger.debug("Unable to expunge the vm because it is not in the correct state: " + vm); throw new CloudRuntimeException("Unable to expunge " + vm); } } } } catch (final NoTransitionException e) { String message = String.format("Unable to destroy %s due to [%s].", vm.toString(), e.getMessage()); - s_logger.debug(message, e); + logger.debug(message, e); throw new CloudRuntimeException(message, e); } } @@ -2301,7 +2383,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac private void deleteVMSnapshots(VMInstanceVO vm, boolean expunge) { if (! vm.getHypervisorType().equals(HypervisorType.VMware)) { if (!_vmSnapshotMgr.deleteAllVMSnapshots(vm.getId(), null)) { - s_logger.debug("Unable to delete all snapshots for " + vm); + logger.debug("Unable to delete all snapshots for " + vm); throw new CloudRuntimeException("Unable to delete vm snapshots for " + vm); } } @@ -2331,7 +2413,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (command != null) { RestoreVMSnapshotAnswer restoreVMSnapshotAnswer = (RestoreVMSnapshotAnswer) _agentMgr.send(hostId, command); if (restoreVMSnapshotAnswer == null || !restoreVMSnapshotAnswer.getResult()) { - s_logger.warn("Unable to restore the vm snapshot from image file after live migration of vm with vmsnapshots: " + restoreVMSnapshotAnswer == null ? "null answer" : restoreVMSnapshotAnswer.getDetails()); + logger.warn("Unable to restore the vm snapshot from image file after live migration of vm with vmsnapshots: " + restoreVMSnapshotAnswer == null ? "null answer" : restoreVMSnapshotAnswer.getDetails()); } } } @@ -2372,8 +2454,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Map volumeToPoolMap = prepareVmStorageMigration(vm, volumeToPool); try { - if(s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Offline migration of %s vm %s with volumes", + if(logger.isDebugEnabled()) { + logger.debug(String.format("Offline migration of %s vm %s with volumes", vm.getHypervisorType().toString(), vm.getInstanceName())); } @@ -2384,14 +2466,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac | InsufficientCapacityException | StorageUnavailableException e) { String msg = String.format("Failed to migrate VM: %s", vmUuid); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } finally { try { stateTransitTo(vm, Event.AgentReportStopped, null); } catch (final NoTransitionException e) { String anotherMEssage = String.format("failed to change vm state of VM: %s", vmUuid); - s_logger.warn(anotherMEssage, e); + logger.warn(anotherMEssage, e); throw new CloudRuntimeException(anotherMEssage, e); } } @@ -2412,17 +2494,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { return _agentMgr.send(hostId, commandsContainer); } catch (AgentUnavailableException | OperationTimedoutException e) { - s_logger.warn(String.format("Hypervisor migration failed for the VM: %s", vm), e); + logger.warn(String.format("Hypervisor migration failed for the VM: %s", vm), e); } } return null; } private void afterHypervisorMigrationCleanup(VMInstanceVO vm, Map volumeToPool, Long sourceClusterId, Answer[] hypervisorMigrationResults) throws InsufficientCapacityException { - boolean isDebugEnabled = s_logger.isDebugEnabled(); + boolean isDebugEnabled = logger.isDebugEnabled(); if(isDebugEnabled) { String msg = String.format("Cleaning up after hypervisor pool migration volumes for VM %s(%s)", vm.getInstanceName(), vm.getUuid()); - s_logger.debug(msg); + logger.debug(msg); } StoragePool rootVolumePool = null; @@ -2439,7 +2521,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (destClusterId != null && !destClusterId.equals(sourceClusterId)) { if(isDebugEnabled) { String msg = String.format("Resetting lastHost for VM %s(%s)", vm.getInstanceName(), vm.getUuid()); - s_logger.debug(msg); + logger.debug(msg); } vm.setLastHostId(null); vm.setPodIdToDeployIn(rootVolumePool.getPodId()); @@ -2454,8 +2536,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throw new CloudRuntimeException(String.format("VM ID: %s migration failed. %s", vm.getUuid(), hypervisorMigrationResults[0].getDetails())); } for (Answer answer : hypervisorMigrationResults) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Received an %s: %s", answer.getClass().getSimpleName(), answer)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Received an %s: %s", answer.getClass().getSimpleName(), answer)); } if (answer instanceof MigrateVmToPoolAnswer) { relevantAnswer = (MigrateVmToPoolAnswer) answer; @@ -2469,13 +2551,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac results = new ArrayList<>(); } List volumes = _volsDao.findUsableVolumesForInstance(vm.getId()); - if(s_logger.isDebugEnabled()) { + if(logger.isDebugEnabled()) { String msg = String.format("Found %d volumes for VM %s(uuid:%s, id:%d)", results.size(), vm.getInstanceName(), vm.getUuid(), vm.getId()); - s_logger.debug(msg); + logger.debug(msg); } for (VolumeObjectTO result : results ) { - if(s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Updating volume (%d) with path '%s' on pool '%s'", result.getId(), result.getPath(), result.getDataStoreUuid())); + if(logger.isDebugEnabled()) { + logger.debug(String.format("Updating volume (%d) with path '%s' on pool '%s'", result.getId(), result.getPath(), result.getDataStoreUuid())); } VolumeVO volume = _volsDao.findById(result.getId()); StoragePool pool = _storagePoolDao.findPoolByUUID(result.getDataStoreUuid()); @@ -2503,7 +2585,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (migrationResult) { postStorageMigrationCleanup(vm, volumeToPool, _hostDao.findById(sourceHostId), sourceClusterId); } else { - s_logger.debug("Storage migration failed"); + logger.debug("Storage migration failed"); } } else { afterHypervisorMigrationCleanup(vm, volumeToPool, sourceClusterId, hypervisorMigrationResults); @@ -2534,7 +2616,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } if (dataCenterId == null) { String msg = "Unable to migrate vm: failed to create deployment destination with given volume to pool map"; - s_logger.debug(msg); + logger.debug(msg); throw new CloudRuntimeException(msg); } final DataCenterDeployment destination = new DataCenterDeployment(dataCenterId, podId, clusterId, null, null, null); @@ -2545,7 +2627,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac stateTransitTo(vm, Event.StorageMigrationRequested, null); } catch (final NoTransitionException e) { String msg = String.format("Unable to migrate vm: %s", vm.getUuid()); - s_logger.warn(msg, e); + logger.warn(msg, e); throw new CloudRuntimeException(msg, e); } return volumeToPoolMap; @@ -2607,9 +2689,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac private void setDestinationPoolAndReallocateNetwork(StoragePool destPool, VMInstanceVO vm) throws InsufficientCapacityException { if (destPool != null && destPool.getPodId() != null && !destPool.getPodId().equals(vm.getPodIdToDeployIn())) { - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { String msg = String.format("as the pod for vm %s has changed we are reallocating its network", vm.getInstanceName()); - s_logger.debug(msg); + logger.debug(msg); } final DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), destPool.getPodId(), null, null, null, null); final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null); @@ -2629,7 +2711,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } private void removeStaleVmFromSource(VMInstanceVO vm, HostVO srcHost) { - s_logger.debug("Since VM's storage was successfully migrated across VMware Datacenters, unregistering VM: " + vm.getInstanceName() + + logger.debug("Since VM's storage was successfully migrated across VMware Datacenters, unregistering VM: " + vm.getInstanceName() + " from source host: " + srcHost.getId()); final UnregisterVMCommand uvc = new UnregisterVMCommand(vm.getInstanceName()); uvc.setCleanupVmFiles(true); @@ -2672,8 +2754,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac private void orchestrateMigrate(final String vmUuid, final long srcHostId, final DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException { final VMInstanceVO vm = _vmDao.findByUuid(vmUuid); if (vm == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find the vm " + vmUuid); + if (logger.isDebugEnabled()) { + logger.debug("Unable to find the vm " + vmUuid); } throw new CloudRuntimeException("Unable to find a virtual machine with id " + vmUuid); } @@ -2681,11 +2763,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } protected void migrate(final VMInstanceVO vm, final long srcHostId, final DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException { - s_logger.info("Migrating " + vm + " to " + dest); + logger.info("Migrating " + vm + " to " + dest); final long dstHostId = dest.getHost().getId(); final Host fromHost = _hostDao.findById(srcHostId); if (fromHost == null) { - s_logger.info("Unable to find the host to migrate from: " + srcHostId); + logger.info("Unable to find the host to migrate from: " + srcHostId); throw new CloudRuntimeException("Unable to find the host to migrate from: " + srcHostId); } @@ -2693,7 +2775,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final List volumes = _volsDao.findCreatedByInstance(vm.getId()); for (final VolumeVO volume : volumes) { if (!_storagePoolDao.findById(volume.getPoolId()).getScope().equals(ScopeType.ZONE)) { - s_logger.info("Source and destination host are not in same cluster and all volumes are not on zone wide primary store, unable to migrate to host: " + logger.info("Source and destination host are not in same cluster and all volumes are not on zone wide primary store, unable to migrate to host: " + dest.getHost().getId()); throw new CloudRuntimeException( "Source and destination host are not in same cluster and all volumes are not on zone wide primary store, unable to migrate to host: " @@ -2705,8 +2787,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final VirtualMachineGuru vmGuru = getVmGuru(vm); if (vm.getState() != State.Running) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("VM is not Running, unable to migrate the vm " + vm); + if (logger.isDebugEnabled()) { + logger.debug("VM is not Running, unable to migrate the vm " + vm); } throw new CloudRuntimeException("VM is not Running, unable to migrate the vm currently " + vm + " , current state: " + vm.getState().toString()); } @@ -2733,6 +2815,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final VirtualMachineTO to = toVmTO(profile); final PrepareForMigrationCommand pfmc = new PrepareForMigrationCommand(to); + setVmNetworkDetails(vm, to); ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Migrating, vm.getType(), vm.getId()); work.setStep(Step.Prepare); @@ -2761,6 +2844,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } vm.setLastHostId(srcHostId); + _vmDao.resetVmPowerStateTracking(vm.getId()); try { if (vm.getHostId() == null || vm.getHostId() != srcHostId || !changeState(vm, Event.MigrationRequested, dstHostId, work, Step.Migrating)) { _networkMgr.rollbackNicForMigration(vmSrc, profile); @@ -2768,24 +2852,24 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac volumeMgr.release(vm.getId(), dstHostId); } - s_logger.info("Migration cancelled because state has changed: " + vm); + logger.info("Migration cancelled because state has changed: " + vm); throw new ConcurrentOperationException("Migration cancelled because state has changed: " + vm); } } catch (final NoTransitionException e1) { _networkMgr.rollbackNicForMigration(vmSrc, profile); volumeMgr.release(vm.getId(), dstHostId); - s_logger.info("Migration cancelled because " + e1.getMessage()); + logger.info("Migration cancelled because " + e1.getMessage()); throw new ConcurrentOperationException("Migration cancelled because " + e1.getMessage()); } catch (final CloudRuntimeException e2) { _networkMgr.rollbackNicForMigration(vmSrc, profile); volumeMgr.release(vm.getId(), dstHostId); - s_logger.info("Migration cancelled because " + e2.getMessage()); + logger.info("Migration cancelled because " + e2.getMessage()); work.setStep(Step.Done); _workDao.update(work.getId(), work); try { stateTransitTo(vm, Event.OperationFailed, srcHostId); } catch (final NoTransitionException e3) { - s_logger.warn(e3.getMessage()); + logger.warn(e3.getMessage()); } throw new CloudRuntimeException("Migration cancelled because " + e2.getMessage()); } @@ -2803,7 +2887,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } catch (final OperationTimedoutException e) { if (e.isActive()) { - s_logger.warn("Active migration command so scheduling a restart for " + vm, e); + logger.warn("Active migration command so scheduling a restart for " + vm, e); _haMgr.scheduleRestart(vm, true); } throw new AgentUnavailableException("Operation timed out on migrating " + vm, dstHostId); @@ -2819,22 +2903,22 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { if (!checkVmOnHost(vm, dstHostId)) { - s_logger.error("Unable to complete migration for " + vm); + logger.error("Unable to complete migration for " + vm); try { _agentMgr.send(srcHostId, new Commands(cleanup(vm, dpdkInterfaceMapping)), null); } catch (final AgentUnavailableException e) { - s_logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId, e); + logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId, e); } cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true); throw new CloudRuntimeException("Unable to complete migration for " + vm); } } catch (final OperationTimedoutException e) { - s_logger.warn("Error while checking the vm " + vm + " on host " + dstHostId, e); + logger.warn("Error while checking the vm " + vm + " on host " + dstHostId, e); } migrated = true; } finally { if (!migrated) { - s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); + logger.info("Migration was unsuccessful. Cleaning up: " + vm); _networkMgr.rollbackNicForMigration(vmSrc, profile); volumeMgr.release(vm.getId(), dstHostId); @@ -2844,13 +2928,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { _agentMgr.send(dstHostId, new Commands(cleanup(vm, dpdkInterfaceMapping)), null); } catch (final AgentUnavailableException ae) { - s_logger.warn("Looks like the destination Host is unavailable for cleanup", ae); + logger.warn("Looks like the destination Host is unavailable for cleanup", ae); } _networkMgr.setHypervisorHostname(profile, dest, false); try { stateTransitTo(vm, Event.OperationFailed, srcHostId); } catch (final NoTransitionException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); } } else { _networkMgr.commitNicForMigration(vmSrc, profile); @@ -2876,7 +2960,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Map vlanToPersistenceMap = getVlanToPersistenceMapForVM(vmInstance.getId()); if (MapUtils.isNotEmpty(vlanToPersistenceMap)) { - s_logger.debug(String.format("Setting VLAN persistence to [%s] as part of migrate command for VM [%s].", new Gson().toJson(vlanToPersistenceMap), virtualMachineTO)); + logger.debug(String.format("Setting VLAN persistence to [%s] as part of migrate command for VM [%s].", new Gson().toJson(vlanToPersistenceMap), virtualMachineTO)); migrateCommand.setVlanToPersistenceMap(vlanToPersistenceMap); } @@ -2887,7 +2971,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Map answerDpdkInterfaceMapping = prepareForMigrationAnswer.getDpdkInterfaceMapping(); if (MapUtils.isNotEmpty(answerDpdkInterfaceMapping) && dpdkInterfaceMapping != null) { - s_logger.debug(String.format("Setting DPDK interface mapping to [%s] as part of migrate command for VM [%s].", new Gson().toJson(vlanToPersistenceMap), + logger.debug(String.format("Setting DPDK interface mapping to [%s] as part of migrate command for VM [%s].", new Gson().toJson(vlanToPersistenceMap), virtualMachineTO)); dpdkInterfaceMapping.putAll(answerDpdkInterfaceMapping); migrateCommand.setDpdkInterfaceMapping(dpdkInterfaceMapping); @@ -2895,7 +2979,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Integer newVmCpuShares = prepareForMigrationAnswer.getNewVmCpuShares(); if (newVmCpuShares != null) { - s_logger.debug(String.format("Setting CPU shares to [%d] as part of migrate command for VM [%s].", newVmCpuShares, virtualMachineTO)); + logger.debug(String.format("Setting CPU shares to [%d] as part of migrate command for VM [%s].", newVmCpuShares, virtualMachineTO)); migrateCommand.setNewVmCpuShares(newVmCpuShares); } @@ -2969,7 +3053,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac volume.getUuid(), targetPool.getUuid(), profile.getUuid(), targetHost.getUuid())); } if (currentPool.getId() == targetPool.getId()) { - s_logger.info(String.format("The volume [%s] is already allocated in storage pool [%s].", volume.getUuid(), targetPool.getUuid())); + logger.info(String.format("The volume [%s] is already allocated in storage pool [%s].", volume.getUuid(), targetPool.getUuid())); } volumeToPoolObjectMap.put(volume, targetPool); } @@ -3128,11 +3212,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac private void moveVmToMigratingState(final T vm, final Long hostId, final ItWorkVO work) throws ConcurrentOperationException { try { if (!changeState(vm, Event.MigrationRequested, hostId, work, Step.Migrating)) { - s_logger.error("Migration cancelled because state has changed: " + vm); + logger.error("Migration cancelled because state has changed: " + vm); throw new ConcurrentOperationException("Migration cancelled because state has changed: " + vm); } } catch (final NoTransitionException e) { - s_logger.error("Migration cancelled because " + e.getMessage(), e); + logger.error("Migration cancelled because " + e.getMessage(), e); throw new ConcurrentOperationException("Migration cancelled because " + e.getMessage()); } } @@ -3140,11 +3224,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac private void moveVmOutofMigratingStateOnSuccess(final T vm, final Long hostId, final ItWorkVO work) throws ConcurrentOperationException { try { if (!changeState(vm, Event.OperationSucceeded, hostId, work, Step.Started)) { - s_logger.error("Unable to change the state for " + vm); + logger.error("Unable to change the state for " + vm); throw new ConcurrentOperationException("Unable to change the state for " + vm); } } catch (final NoTransitionException e) { - s_logger.error("Unable to change state due to " + e.getMessage(), e); + logger.error("Unable to change state due to " + e.getMessage(), e); throw new ConcurrentOperationException("Unable to change state due to " + e.getMessage()); } } @@ -3256,9 +3340,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac AttachOrDettachConfigDriveCommand dettachCommand = new AttachOrDettachConfigDriveCommand(vm.getInstanceName(), vmData, VmConfigDriveLabel.value(), false); try { _agentMgr.send(srcHost.getId(), dettachCommand); - s_logger.debug("Deleted config drive ISO for vm " + vm.getInstanceName() + " In host " + srcHost); + logger.debug("Deleted config drive ISO for vm " + vm.getInstanceName() + " In host " + srcHost); } catch (OperationTimedoutException e) { - s_logger.error("TIme out occurred while exeuting command AttachOrDettachConfigDrive " + e.getMessage(), e); + logger.error("TIme out occurred while exeuting command AttachOrDettachConfigDrive " + e.getMessage(), e); } } @@ -3270,22 +3354,22 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { if (!checkVmOnHost(vm, destHostId)) { - s_logger.error("Vm not found on destination host. Unable to complete migration for " + vm); + logger.error("Vm not found on destination host. Unable to complete migration for " + vm); try { _agentMgr.send(srcHostId, new Commands(cleanup(vm.getInstanceName())), null); } catch (final AgentUnavailableException e) { - s_logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId, e); + logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId, e); } cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true); throw new CloudRuntimeException("VM not found on destination host. Unable to complete migration for " + vm); } } catch (final OperationTimedoutException e) { - s_logger.error("Error while checking the vm " + vm + " is on host " + destHost, e); + logger.error("Error while checking the vm " + vm + " is on host " + destHost, e); } migrated = true; } finally { if (!migrated) { - s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); + logger.info("Migration was unsuccessful. Cleaning up: " + vm); _networkMgr.rollbackNicForMigration(vmSrc, profile); volumeMgr.release(vm.getId(), destHostId); @@ -3297,9 +3381,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac vm.setPodIdToDeployIn(srcHost.getPodId()); stateTransitTo(vm, Event.OperationFailed, srcHostId); } catch (final AgentUnavailableException e) { - s_logger.warn("Looks like the destination Host is unavailable for cleanup.", e); + logger.warn("Looks like the destination Host is unavailable for cleanup.", e); } catch (final NoTransitionException e) { - s_logger.error("Error while transitioning vm from migrating to running state.", e); + logger.error("Error while transitioning vm from migrating to running state.", e); } _networkMgr.setHypervisorHostname(profile, destination, false); } else { @@ -3328,7 +3412,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { final List works = _workDao.listWorkInProgressFor(nodeId); for (final ItWorkVO work : works) { - s_logger.info("Handling unfinished work item: " + work); + logger.info("Handling unfinished work item: " + work); try { final VMInstanceVO vm = _vmDao.findById(work.getInstanceId()); if (vm != null) { @@ -3349,7 +3433,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } } catch (final Exception e) { - s_logger.error("Error while handling " + work, e); + logger.error("Error while handling " + work, e); } } } finally { @@ -3371,7 +3455,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { orchestrateMigrateAway(vmUuid, srcHostId, null); } catch (final InsufficientServerCapacityException e) { - s_logger.warn("Failed to deploy vm " + vmUuid + " with original planner, sending HAPlanner"); + logger.warn("Failed to deploy vm " + vmUuid + " with original planner, sending HAPlanner"); orchestrateMigrateAway(vmUuid, srcHostId, _haMgr.getHAPlanner()); } } finally { @@ -3394,7 +3478,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final VMInstanceVO vm = _vmDao.findByUuid(vmUuid); if (vm == null) { String message = String.format("Unable to find VM with uuid [%s].", vmUuid); - s_logger.warn(message); + logger.warn(message); throw new CloudRuntimeException(message); } @@ -3404,7 +3488,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final Long hostId = vm.getHostId(); if (hostId == null) { String message = String.format("Unable to migrate %s due to it does not have a host id.", vm.toString()); - s_logger.warn(message); + logger.warn(message); throw new CloudRuntimeException(message); } @@ -3430,15 +3514,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac dest = _dpMgr.planDeployment(profile, plan, excludes, planner); } catch (final AffinityConflictException e2) { String message = String.format("Unable to create deployment, affinity rules associated to the %s conflict.", vm.toString()); - s_logger.warn(message, e2); + logger.warn(message, e2); throw new CloudRuntimeException(message, e2); } if (dest == null) { - s_logger.warn("Unable to find destination for migrating the vm " + profile); + logger.warn("Unable to find destination for migrating the vm " + profile); throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", DataCenter.class, host.getDataCenterId()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found destination " + dest + " for migrating to."); + if (logger.isDebugEnabled()) { + logger.debug("Found destination " + dest + " for migrating to."); } excludes.addHost(dest.getHost().getId()); @@ -3446,14 +3530,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac migrate(vm, srcHostId, dest); return; } catch (ResourceUnavailableException | ConcurrentOperationException e) { - s_logger.warn(String.format("Unable to migrate %s to %s due to [%s]", vm.toString(), dest.getHost().toString(), e.getMessage()), e); + logger.warn(String.format("Unable to migrate %s to %s due to [%s]", vm.toString(), dest.getHost().toString(), e.getMessage()), e); } try { advanceStop(vmUuid, true); throw new CloudRuntimeException("Unable to migrate " + vm); } catch (final ResourceUnavailableException | ConcurrentOperationException | OperationTimedoutException e) { - s_logger.error(String.format("Unable to stop %s due to [%s].", vm.toString(), e.getMessage()), e); + logger.error(String.format("Unable to stop %s due to [%s].", vm.toString(), e.getMessage()), e); throw new CloudRuntimeException("Unable to migrate " + vm); } } @@ -3477,7 +3561,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public DataCenterDeployment getMigrationDeployment(final VirtualMachine vm, final Host host, final Long poolId, final ExcludeList excludes) { if (MIGRATE_VM_ACROSS_CLUSTERS.valueIn(host.getDataCenterId()) && (HypervisorType.VMware.equals(host.getHypervisorType()) || !checkIfVmHasClusterWideVolumes(vm.getId()))) { - s_logger.info("Searching for hosts in the zone for vm migration"); + logger.info("Searching for hosts in the zone for vm migration"); List clustersToExclude = _clusterDao.listAllClusters(host.getDataCenterId()); List clusterList = _clusterDao.listByDcHyType(host.getDataCenterId(), host.getHypervisorType().toString()); for (ClusterVO cluster : clusterList) { @@ -3497,13 +3581,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac protected class CleanupTask extends ManagedContextRunnable { @Override protected void runInContext() { - s_logger.debug("VM Operation Thread Running"); + logger.debug("VM Operation Thread Running"); try { _workDao.cleanup(VmOpCleanupWait.value()); final Date cutDate = new Date(DateUtil.currentGMTTime().getTime() - VmOpCleanupInterval.value() * 1000); _workJobDao.expungeCompletedWorkJobs(cutDate); } catch (final Exception e) { - s_logger.error("VM Operations failed due to ", e); + logger.error("VM Operations failed due to ", e); } } } @@ -3539,8 +3623,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final VirtualMachine vm = _vmDao.findByUuid(vmUuid); VmWorkJobVO placeHolder = createPlaceHolderWork(vm.getId()); try { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("reboot parameter value of %s == %s at orchestration", VirtualMachineProfile.Param.BootIntoSetup.getName(), + if (logger.isDebugEnabled()) { + logger.debug(String.format("reboot parameter value of %s == %s at orchestration", VirtualMachineProfile.Param.BootIntoSetup.getName(), (params == null? "":params.get(VirtualMachineProfile.Param.BootIntoSetup)))); } orchestrateReboot(vmUuid, params); @@ -3550,8 +3634,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("reboot parameter value of %s == %s through job-queue", VirtualMachineProfile.Param.BootIntoSetup.getName(), + if (logger.isDebugEnabled()) { + logger.debug(String.format("reboot parameter value of %s == %s through job-queue", VirtualMachineProfile.Param.BootIntoSetup.getName(), (params == null? "":params.get(VirtualMachineProfile.Param.BootIntoSetup)))); } final Outcome outcome = rebootVmThroughJobQueue(vmUuid, params); @@ -3566,7 +3650,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac ResourceUnavailableException { final VMInstanceVO vm = _vmDao.findByUuid(vmUuid); if (_vmSnapshotMgr.hasActiveVMSnapshotTasks(vm.getId())) { - s_logger.error("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks"); + logger.error("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks"); throw new CloudRuntimeException("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks"); } final DataCenter dc = _entityMgr.findById(DataCenter.class, vm.getDataCenterId()); @@ -3599,10 +3683,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } String errorMsg = "Unable to reboot VM " + vm + " on " + dest.getHost() + " due to " + (rebootAnswer == null ? "no reboot response" : rebootAnswer.getDetails()); - s_logger.info(errorMsg); + logger.info(errorMsg); throw new CloudRuntimeException(errorMsg); } catch (final OperationTimedoutException e) { - s_logger.warn("Unable to send the reboot command to host " + dest.getHost() + " for the vm " + vm + " due to operation timeout", e); + logger.warn("Unable to send the reboot command to host " + dest.getHost() + " for the vm " + vm + " due to operation timeout", e); throw new CloudRuntimeException("Failed to reboot the vm on host " + dest.getHost(), e); } } @@ -3612,8 +3696,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (params != null) { enterSetup = (Boolean) params.get(VirtualMachineProfile.Param.BootIntoSetup); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("orchestrating VM reboot for '%s' %s set to %s", vmTo.getName(), VirtualMachineProfile.Param.BootIntoSetup, enterSetup)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("orchestrating VM reboot for '%s' %s set to %s", vmTo.getName(), VirtualMachineProfile.Param.BootIntoSetup, enterSetup)); } vmTo.setEnterHardwareSetup(enterSetup == null ? false : enterSetup); } @@ -3668,7 +3752,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac case DomainRouter: return vm.getPrivateIpAddress(); default: - s_logger.debug(String.format("%s is a [%s], returning null for control Nic IP.", vm.toString(), vm.getType())); + logger.debug(String.format("%s is a [%s], returning null for control Nic IP.", vm.toString(), vm.getType())); return null; } } @@ -3814,14 +3898,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return; } - if(s_logger.isDebugEnabled()) { - s_logger.debug("Received startup command from hypervisor host. host id: " + agent.getId()); + if(logger.isDebugEnabled()) { + logger.debug("Received startup command from hypervisor host. host id: " + agent.getId()); } _syncMgr.resetHostSyncState(agent.getId()); if (forRebalance) { - s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process"); + logger.debug("Not processing listener " + this + " as connect happens on rebalance process"); return; } final Long clusterId = agent.getClusterId(); @@ -3831,9 +3915,9 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final ClusterVMMetaDataSyncCommand syncVMMetaDataCmd = new ClusterVMMetaDataSyncCommand(ClusterVMMetaDataSyncInterval.value(), clusterId); try { final long seq_no = _agentMgr.send(agentId, new Commands(syncVMMetaDataCmd), this); - s_logger.debug("Cluster VM metadata sync started with jobid " + seq_no); + logger.debug("Cluster VM metadata sync started with jobid " + seq_no); } catch (final AgentUnavailableException e) { - s_logger.fatal("The Cluster VM metadata sync process failed for cluster id " + clusterId + " with ", e); + logger.fatal("The Cluster VM metadata sync process failed for cluster id " + clusterId + " with ", e); } } } @@ -3843,12 +3927,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac protected void runInContext() { final GlobalLock lock = GlobalLock.getInternLock("TransitionChecking"); if (lock == null) { - s_logger.debug("Couldn't get the global lock"); + logger.debug("Couldn't get the global lock"); return; } if (!lock.lock(30)) { - s_logger.debug("Couldn't lock the db"); + logger.debug("Couldn't lock the db"); return; } try { @@ -3864,7 +3948,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } } catch (final Exception e) { - s_logger.warn("Caught the following exception on transition checking", e); + logger.warn("Caught the following exception on transition checking", e); } finally { lock.unlock(); } @@ -3887,14 +3971,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } if (!(vmInstance.getState().equals(State.Stopped) || vmInstance.getState().equals(State.Running))) { - s_logger.warn("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState()); + logger.warn("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState()); throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " " + " in state " + vmInstance.getState() + "; make sure the virtual machine is stopped/running"); } if (!newServiceOffering.isDynamic() && vmInstance.getServiceOfferingId() == newServiceOffering.getId()) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Not upgrading vm " + vmInstance.toString() + " since it already has the requested " + "service offering (" + newServiceOffering.getName() + + if (logger.isInfoEnabled()) { + logger.info("Not upgrading vm " + vmInstance.toString() + " since it already has the requested " + "service offering (" + newServiceOffering.getName() + ")"); } @@ -4030,7 +4114,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final CallContext cctx = CallContext.current(); checkIfNetworkExistsForUserVM(vm, network); - s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested); + logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested); final VMInstanceVO vmVO = _vmDao.findById(vm.getId()); final ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount()); @@ -4049,14 +4133,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType()); //4) plug the nic to the vm - s_logger.debug("Plugging nic for vm " + vm + " in network " + network); + logger.debug("Plugging nic for vm " + vm + " in network " + network); boolean result = false; try { result = plugNic(network, nicTO, vmTO, context, dest); if (result) { _userVmMgr.setupVmForPvlan(true, vm.getHostId(), nic); - s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now"); + logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now"); final long isDefault = nic.isDefaultNic() ? 1 : 0; if(VirtualMachine.Type.User.equals(vmVO.getType())) { @@ -4065,19 +4149,19 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } return nic; } else { - s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network); + logger.warn("Failed to plug nic to the vm " + vm + " in network " + network); return null; } } finally { if (!result) { - s_logger.debug("Removing nic " + nic + " from vm " + vmProfile.getVirtualMachine() + " as nic plug failed on the backend"); + logger.debug("Removing nic " + nic + " from vm " + vmProfile.getVirtualMachine() + " as nic plug failed on the backend"); _networkMgr.removeNic(vmProfile, _nicsDao.findById(nic.getId())); } } } else if (vm.getState() == State.Stopped) { return _networkMgr.createNicForVm(network, requested, context, vmProfile, false); } else { - s_logger.warn("Unable to add vm " + vm + " to network " + network); + logger.warn("Unable to add vm " + vm + " to network " + network); throw new ResourceUnavailableException("Unable to add vm " + vm + " to network, is not in the right state", DataCenter.class, vm.getDataCenterId()); } } @@ -4141,25 +4225,25 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (vm.getState() == State.Running) { final NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType()); - s_logger.debug("Un-plugging nic " + nic + " for vm " + vm + " from network " + network); + logger.debug("Un-plugging nic " + nic + " for vm " + vm + " from network " + network); final boolean result = unplugNic(network, nicTO, vmTO, context, dest); if (result) { _userVmMgr.setupVmForPvlan(false, vm.getHostId(), nicProfile); - s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network); + logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network); final long isDefault = nic.isDefaultNic() ? 1 : 0; UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay()); } else { - s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network); + logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network); return false; } } else if (vm.getState() != State.Stopped) { - s_logger.warn("Unable to remove vm " + vm + " from network " + network); + logger.warn("Unable to remove vm " + vm + " from network " + network); throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", DataCenter.class, vm.getDataCenterId()); } _networkMgr.releaseNic(vmProfile, nic); - s_logger.debug("Successfully released nic " + nic + "for vm " + vm); + logger.debug("Successfully released nic " + nic + "for vm " + vm); _networkMgr.removeNic(vmProfile, nic); _nicsDao.remove(nic.getId()); @@ -4194,28 +4278,28 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } if (nic == null) { - s_logger.warn("Could not get a nic with " + network); + logger.warn("Could not get a nic with " + network); return false; } if (nic.isDefaultNic() && vm.getType() == VirtualMachine.Type.User) { - s_logger.warn("Failed to remove nic from " + vm + " in " + network + ", nic is default."); + logger.warn("Failed to remove nic from " + vm + " in " + network + ", nic is default."); throw new CloudRuntimeException("Failed to remove nic from " + vm + " in " + network + ", nic is default."); } final Nic lock = _nicsDao.acquireInLockTable(nic.getId()); if (lock == null) { if (_nicsDao.findById(nic.getId()) == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Not need to remove the vm " + vm + " from network " + network + " as the vm doesn't have nic in this network"); + if (logger.isDebugEnabled()) { + logger.debug("Not need to remove the vm " + vm + " from network " + network + " as the vm doesn't have nic in this network"); } return true; } throw new ConcurrentOperationException("Unable to lock nic " + nic.getId()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Lock is acquired for nic id " + lock.getId() + " as a part of remove vm " + vm + " from network " + network); + if (logger.isDebugEnabled()) { + logger.debug("Lock is acquired for nic id " + lock.getId() + " as a part of remove vm " + vm + " from network " + network); } try { @@ -4225,28 +4309,28 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (vm.getState() == State.Running) { final NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType()); - s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network); + logger.debug("Un-plugging nic for vm " + vm + " from network " + network); final boolean result = unplugNic(network, nicTO, vmTO, context, dest); if (result) { - s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network); + logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network); } else { - s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network); + logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network); return false; } } else if (vm.getState() != State.Stopped) { - s_logger.warn("Unable to remove vm " + vm + " from network " + network); + logger.warn("Unable to remove vm " + vm + " from network " + network); throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", DataCenter.class, vm.getDataCenterId()); } _networkMgr.releaseNic(vmProfile, nic); - s_logger.debug("Successfully released nic " + nic + "for vm " + vm); + logger.debug("Successfully released nic " + nic + "for vm " + vm); _networkMgr.removeNic(vmProfile, nic); return true; } finally { _nicsDao.releaseFromLockTable(lock.getId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Lock is released for nic id " + lock.getId() + " as a part of remove vm " + vm + " from network " + network); + if (logger.isDebugEnabled()) { + logger.debug("Lock is released for nic id " + lock.getId() + " as a part of remove vm " + vm + " from network " + network); } } } @@ -4282,13 +4366,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac dest = _dpMgr.planDeployment(profile, plan, excludes, null); } catch (final AffinityConflictException e2) { String message = String.format("Unable to create deployment, affinity rules associated to the %s conflict.", vm.toString()); - s_logger.warn(message, e2); + logger.warn(message, e2); throw new CloudRuntimeException(message); } if (dest != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(" Found " + dest + " for scaling the vm to."); + if (logger.isDebugEnabled()) { + logger.debug(" Found " + dest + " for scaling the vm to."); } } @@ -4300,7 +4384,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { migrateForScale(vm.getUuid(), srcHostId, dest, oldSvcOfferingId); } catch (ResourceUnavailableException | ConcurrentOperationException e) { - s_logger.warn(String.format("Unable to migrate %s to %s due to [%s]", vm.toString(), dest.getHost().toString(), e.getMessage()), e); + logger.warn(String.format("Unable to migrate %s to %s due to [%s]", vm.toString(), dest.getHost().toString(), e.getMessage()), e); throw e; } } @@ -4336,7 +4420,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throws ResourceUnavailableException, ConcurrentOperationException { VMInstanceVO vm = _vmDao.findByUuid(vmUuid); - s_logger.info(String.format("Migrating %s to %s", vm, dest)); + logger.info(String.format("Migrating %s to %s", vm, dest)); vm.getServiceOfferingId(); final long dstHostId = dest.getHost().getId(); @@ -4344,7 +4428,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Host srcHost = _hostDao.findById(srcHostId); if (fromHost == null) { String logMessageUnableToFindHost = String.format("Unable to find host to migrate from %s.", srcHost); - s_logger.info(logMessageUnableToFindHost); + logger.info(logMessageUnableToFindHost); throw new CloudRuntimeException(logMessageUnableToFindHost); } @@ -4353,7 +4437,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac long fromHostClusterId = fromHost.getClusterId(); if (fromHostClusterId != destHostClusterId) { String logMessageHostsOnDifferentCluster = String.format("Source and destination host are not in same cluster, unable to migrate to %s", srcHost); - s_logger.info(logMessageHostsOnDifferentCluster); + logger.info(logMessageHostsOnDifferentCluster); throw new CloudRuntimeException(logMessageHostsOnDifferentCluster); } @@ -4362,13 +4446,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac vm = _vmDao.findByUuid(vmUuid); if (vm == null) { String message = String.format("Unable to find VM {\"uuid\": \"%s\"}.", vmUuid); - s_logger.warn(message); + logger.warn(message); throw new CloudRuntimeException(message); } if (vm.getState() != State.Running) { String message = String.format("%s is not in \"Running\" state, unable to migrate it. Current state [%s].", vm.toString(), vm.getState()); - s_logger.warn(message); + logger.warn(message); throw new CloudRuntimeException(message); } @@ -4414,12 +4498,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { if (vm.getHostId() == null || vm.getHostId() != srcHostId || !changeState(vm, Event.MigrationRequested, dstHostId, work, Step.Migrating)) { String message = String.format("Migration of %s cancelled because state has changed.", vm.toString()); - s_logger.warn(message); + logger.warn(message); throw new ConcurrentOperationException(message); } } catch (final NoTransitionException e1) { String message = String.format("Migration of %s cancelled due to [%s].", vm.toString(), e1.getMessage()); - s_logger.error(message, e1); + logger.error(message, e1); throw new ConcurrentOperationException(message); } @@ -4431,12 +4515,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final Answer ma = _agentMgr.send(vm.getLastHostId(), mc); if (ma == null || !ma.getResult()) { String msg = String.format("Unable to migrate %s due to [%s].", vm.toString(), ma != null ? ma.getDetails() : "null answer returned"); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } catch (final OperationTimedoutException e) { if (e.isActive()) { - s_logger.warn("Active migration command so scheduling a restart for " + vm, e); + logger.warn("Active migration command so scheduling a restart for " + vm, e); _haMgr.scheduleRestart(vm, true); } throw new AgentUnavailableException("Operation timed out on migrating " + vm, dstHostId, e); @@ -4455,23 +4539,23 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { if (!checkVmOnHost(vm, dstHostId)) { - s_logger.error("Unable to complete migration for " + vm); + logger.error("Unable to complete migration for " + vm); try { _agentMgr.send(srcHostId, new Commands(cleanup(vm.getInstanceName())), null); } catch (final AgentUnavailableException e) { - s_logger.error(String.format("Unable to cleanup source host [%s] due to [%s].", srcHostId, e.getMessage()), e); + logger.error(String.format("Unable to cleanup source host [%s] due to [%s].", srcHostId, e.getMessage()), e); } cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true); throw new CloudRuntimeException("Unable to complete migration for " + vm); } } catch (final OperationTimedoutException e) { - s_logger.debug(String.format("Error while checking the %s on %s", vm, dstHost), e); + logger.debug(String.format("Error while checking the %s on %s", vm, dstHost), e); } migrated = true; } finally { if (!migrated) { - s_logger.info("Migration was unsuccessful. Cleaning up: " + vm); + logger.info("Migration was unsuccessful. Cleaning up: " + vm); String alertSubject = String.format("Unable to migrate %s from %s in Zone [%s] and Pod [%s].", vm.getInstanceName(), fromHost, dest.getDataCenter().getName(), dest.getPod().getName()); @@ -4480,13 +4564,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { _agentMgr.send(dstHostId, new Commands(cleanup(vm.getInstanceName())), null); } catch (final AgentUnavailableException ae) { - s_logger.info("Looks like the destination Host is unavailable for cleanup"); + logger.info("Looks like the destination Host is unavailable for cleanup"); } _networkMgr.setHypervisorHostname(profile, dest, false); try { stateTransitTo(vm, Event.OperationFailed, srcHostId); } catch (final NoTransitionException e) { - s_logger.warn(e.getMessage(), e); + logger.warn(e.getMessage(), e); } } else { _networkMgr.setHypervisorHostname(profile, dest, true); @@ -4513,7 +4597,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac _agentMgr.send(host.getId(), cmds); final ReplugNicAnswer replugNicAnswer = cmds.getAnswer(ReplugNicAnswer.class); if (replugNicAnswer == null || !replugNicAnswer.getResult()) { - s_logger.warn("Unable to replug nic for vm " + vm.getName()); + logger.warn("Unable to replug nic for vm " + vm.getName()); result = false; } } catch (final OperationTimedoutException e) { @@ -4521,7 +4605,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } else { String message = String.format("Unable to apply ReplugNic, VM [%s] is not in the right state (\"Running\"). VM state [%s].", router.toString(), router.getState()); - s_logger.warn(message); + logger.warn(message); throw new ResourceUnavailableException(message, DataCenter.class, router.getDataCenterId()); } @@ -4539,7 +4623,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac NetworkDetailVO pvlanTypeDetail = networkDetailsDao.findDetail(network.getId(), ApiConstants.ISOLATED_PVLAN_TYPE); if (pvlanTypeDetail != null) { Map nicDetails = nic.getDetails() == null ? new HashMap<>() : nic.getDetails(); - s_logger.debug("Found PVLAN type: " + pvlanTypeDetail.getValue() + " on network details, adding it as part of the PlugNicCommand"); + logger.debug("Found PVLAN type: " + pvlanTypeDetail.getValue() + " on network details, adding it as part of the PlugNicCommand"); nicDetails.putIfAbsent(NetworkOffering.Detail.pvlanType, pvlanTypeDetail.getValue()); nic.setDetails(nicDetails); } @@ -4549,7 +4633,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac _agentMgr.send(dest.getHost().getId(), cmds); final PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class); if (plugNicAnswer == null || !plugNicAnswer.getResult()) { - s_logger.warn("Unable to plug nic for vm " + vm.getName()); + logger.warn("Unable to plug nic for vm " + vm.getName()); result = false; } } catch (final OperationTimedoutException e) { @@ -4557,7 +4641,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } else { String message = String.format("Unable to apply PlugNic, VM [%s] is not in the right state (\"Running\"). VM state [%s].", router.toString(), router.getState()); - s_logger.warn(message); + logger.warn(message); throw new ResourceUnavailableException(message, DataCenter.class, router.getDataCenterId()); @@ -4589,17 +4673,17 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class); if (unplugNicAnswer == null || !unplugNicAnswer.getResult()) { - s_logger.warn("Unable to unplug nic from router " + router); + logger.warn("Unable to unplug nic from router " + router); result = false; } } catch (final OperationTimedoutException e) { throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network, dest.getHost().getId(), e); } } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) { - s_logger.debug("Vm " + router.getInstanceName() + " is in " + router.getState() + ", so not sending unplug nic command to the backend"); + logger.debug("Vm " + router.getInstanceName() + " is in " + router.getState() + ", so not sending unplug nic command to the backend"); } else { String message = String.format("Unable to apply unplug nic, VM [%s] is not in the right state (\"Running\"). VM state [%s].", router.toString(), router.getState()); - s_logger.warn(message); + logger.warn(message); throw new ResourceUnavailableException(message, DataCenter.class, router.getDataCenterId()); } @@ -4685,7 +4769,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Answer reconfigureAnswer = _agentMgr.send(vm.getHostId(), scaleVmCommand); if (reconfigureAnswer == null || !reconfigureAnswer.getResult()) { - s_logger.error("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails())); + logger.error("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails())); throw new CloudRuntimeException("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails())); } @@ -4791,10 +4875,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac break; } } else { - s_logger.warn("VM " + vmId + " no longer exists when processing VM state report"); + logger.warn("VM " + vmId + " no longer exists when processing VM state report"); } } else { - s_logger.info("There is pending job or HA tasks working on the VM. vm id: " + vmId + ", postpone power-change report by resetting power-change counters"); + logger.info("There is pending job or HA tasks working on the VM. vm id: " + vmId + ", postpone power-change report by resetting power-change counters"); _vmDao.resetVmPowerStateTracking(vmId); } } @@ -4805,15 +4889,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac switch (vm.getState()) { case Starting: - s_logger.info("VM " + vm.getInstanceName() + " is at " + vm.getState() + " and we received a power-on report while there is no pending jobs on it"); + logger.info("VM " + vm.getInstanceName() + " is at " + vm.getState() + " and we received a power-on report while there is no pending jobs on it"); try { stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId()); } catch (final NoTransitionException e) { - s_logger.warn("Unexpected VM state transition exception, race-condition?", e); + logger.warn("Unexpected VM state transition exception, race-condition?", e); } - s_logger.info("VM " + vm.getInstanceName() + " is sync-ed to at Running state according to power-on report from hypervisor"); + logger.info("VM " + vm.getInstanceName() + " is sync-ed to at Running state according to power-on report from hypervisor"); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SYNC, vm.getDataCenterId(), vm.getPodIdToDeployIn(), VM_SYNC_ALERT_SUBJECT, "VM " + vm.getHostName() + "(" + vm.getInstanceName() @@ -4823,23 +4907,23 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac case Running: try { if (vm.getHostId() != null && !vm.getHostId().equals(vm.getPowerHostId())) { - s_logger.info("Detected out of band VM migration from host " + vm.getHostId() + " to host " + vm.getPowerHostId()); + logger.info("Detected out of band VM migration from host " + vm.getHostId() + " to host " + vm.getPowerHostId()); } stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId()); } catch (final NoTransitionException e) { - s_logger.warn("Unexpected VM state transition exception, race-condition?", e); + logger.warn("Unexpected VM state transition exception, race-condition?", e); } break; case Stopping: case Stopped: - s_logger.info("VM " + vm.getInstanceName() + " is at " + vm.getState() + " and we received a power-on report while there is no pending jobs on it"); + logger.info("VM " + vm.getInstanceName() + " is at " + vm.getState() + " and we received a power-on report while there is no pending jobs on it"); try { stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId()); } catch (final NoTransitionException e) { - s_logger.warn("Unexpected VM state transition exception, race-condition?", e); + logger.warn("Unexpected VM state transition exception, race-condition?", e); } _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SYNC, vm.getDataCenterId(), vm.getPodIdToDeployIn(), VM_SYNC_ALERT_SUBJECT, "VM " + vm.getHostName() + "(" + vm.getInstanceName() + ") state is sync-ed (" + vm.getState() @@ -4847,28 +4931,28 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, vm.getDomainId(), EventTypes.EVENT_VM_START, "Out of band VM power on", vm.getId(), ApiCommandResourceType.VirtualMachine.toString()); - s_logger.info("VM " + vm.getInstanceName() + " is sync-ed to at Running state according to power-on report from hypervisor"); + logger.info("VM " + vm.getInstanceName() + " is sync-ed to at Running state according to power-on report from hypervisor"); break; case Destroyed: case Expunging: - s_logger.info("Receive power on report when VM is in destroyed or expunging state. vm: " + logger.info("Receive power on report when VM is in destroyed or expunging state. vm: " + vm.getId() + ", state: " + vm.getState()); break; case Migrating: - s_logger.info("VM " + vm.getInstanceName() + " is at " + vm.getState() + " and we received a power-on report while there is no pending jobs on it"); + logger.info("VM " + vm.getInstanceName() + " is at " + vm.getState() + " and we received a power-on report while there is no pending jobs on it"); try { stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId()); } catch (final NoTransitionException e) { - s_logger.warn("Unexpected VM state transition exception, race-condition?", e); + logger.warn("Unexpected VM state transition exception, race-condition?", e); } - s_logger.info("VM " + vm.getInstanceName() + " is sync-ed to at Running state according to power-on report from hypervisor"); + logger.info("VM " + vm.getInstanceName() + " is sync-ed to at Running state according to power-on report from hypervisor"); break; case Error: default: - s_logger.info("Receive power on report when VM is in error or unexpected state. vm: " + logger.info("Receive power on report when VM is in error or unexpected state. vm: " + vm.getId() + ", state: " + vm.getState()); break; } @@ -4883,8 +4967,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM,vm.getDomainId(), EventTypes.EVENT_VM_STOP, "Out of band VM power off", vm.getId(), ApiCommandResourceType.VirtualMachine.toString()); case Migrating: - if (s_logger.isInfoEnabled()) { - s_logger.info( + if (logger.isInfoEnabled()) { + logger.info( String.format("VM %s is at %s and we received a %s report while there is no pending jobs on it" , vm.getInstanceName(), vm.getState(), vm.getPowerState())); } @@ -4892,11 +4976,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac && HaVmRestartHostUp.value() && vm.getHypervisorType() != HypervisorType.VMware && vm.getHypervisorType() != HypervisorType.Hyperv) { - s_logger.info("Detected out-of-band stop of a HA enabled VM " + vm.getInstanceName() + ", will schedule restart"); + logger.info("Detected out-of-band stop of a HA enabled VM " + vm.getInstanceName() + ", will schedule restart"); if (!_haMgr.hasPendingHaWork(vm.getId())) { _haMgr.scheduleRestart(vm, true); } else { - s_logger.info("VM " + vm.getInstanceName() + " already has an pending HA task working on it"); + logger.info("VM " + vm.getInstanceName() + " already has an pending HA task working on it"); } return; } @@ -4919,14 +5003,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOffReport, null); } catch (final NoTransitionException e) { - s_logger.warn("Unexpected VM state transition exception, race-condition?", e); + logger.warn("Unexpected VM state transition exception, race-condition?", e); } _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SYNC, vm.getDataCenterId(), vm.getPodIdToDeployIn(), VM_SYNC_ALERT_SUBJECT, "VM " + vm.getHostName() + "(" + vm.getInstanceName() + ") state is sync-ed (" + vm.getState() + " -> Stopped) from out-of-context transition."); - s_logger.info("VM " + vm.getInstanceName() + " is sync-ed to at Stopped state according to power-off report from hypervisor"); + logger.info("VM " + vm.getInstanceName() + " is sync-ed to at Stopped state according to power-off report from hypervisor"); break; @@ -4996,7 +5080,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac l.add(rs.getLong(1)); } } catch (SQLException e) { - s_logger.error(String.format("Unable to execute SQL [%s] with params {\"h.id\": %s, \"i.power_state_update_time\": \"%s\"} due to [%s].", sql, hostId, cutTimeStr, e.getMessage()), e); + logger.error(String.format("Unable to execute SQL [%s] with params {\"h.id\": %s, \"i.power_state_update_time\": \"%s\"} due to [%s].", sql, hostId, cutTimeStr, e.getMessage()), e); } } return l; @@ -5025,7 +5109,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac l.add(rs.getLong(1)); } } catch (final SQLException e) { - s_logger.error(String.format("Unable to execute SQL [%s] with params {\"h.id\": %s, \"i.power_state_update_time\": \"%s\", \"j.job_status\": %s} due to [%s].", sql, hostId, cutTimeStr, jobStatusInProgress, e.getMessage()), e); + logger.error(String.format("Unable to execute SQL [%s] with params {\"h.id\": %s, \"i.power_state_update_time\": \"%s\", \"j.job_status\": %s} due to [%s].", sql, hostId, cutTimeStr, jobStatusInProgress, e.getMessage()), e); } return l; } @@ -5053,7 +5137,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac l.add(rs.getLong(1)); } } catch (final SQLException e) { - s_logger.error(String.format("Unable to execute SQL [%s] with params {\"i.power_state_update_time\": \"%s\", \"j.job_status\": %s} due to [%s].", sql, cutTimeStr, jobStatusInProgress, e.getMessage()), e); + logger.error(String.format("Unable to execute SQL [%s] with params {\"i.power_state_update_time\": \"%s\", \"j.job_status\": %s} due to [%s].", sql, cutTimeStr, jobStatusInProgress, e.getMessage()), e); } return l; } @@ -5331,8 +5415,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } workJob = pendingWorkJobs.get(0); } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("no jobs to add network %s for vm %s yet", network, vm)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("no jobs to add network %s for vm %s yet", network, vm)); } workJob = createVmWorkJobToAddNetwork(vm, network, requested, context, user, account); @@ -5372,7 +5456,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } catch (CloudRuntimeException e) { if (e.getCause() instanceof EntityExistsException) { String msg = String.format("A job to add a nic for network %s to vm %s already exists", network.getUuid(), vm.getUuid()); - s_logger.warn(msg, e); + logger.warn(msg, e); } throw e; } @@ -5449,15 +5533,15 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac VMInstanceVO vm = findVmById(work.getVmId()); Boolean enterSetup = (Boolean)work.getParams().get(VirtualMachineProfile.Param.BootIntoSetup); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("orchestrating VM start for '%s' %s set to %s", vm.getInstanceName(), VirtualMachineProfile.Param.BootIntoSetup, enterSetup)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("orchestrating VM start for '%s' %s set to %s", vm.getInstanceName(), VirtualMachineProfile.Param.BootIntoSetup, enterSetup)); } try { orchestrateStart(vm.getUuid(), work.getParams(), work.getPlan(), _dpMgr.getDeploymentPlannerByName(work.getDeploymentPlanner())); } catch (CloudRuntimeException e){ String message = String.format("Unable to orchestrate start %s due to [%s].", vm.toString(), e.getMessage()); - s_logger.warn(message, e); + logger.warn(message, e); CloudRuntimeException ex = new CloudRuntimeException(message); return new Pair<>(JobInfo.Status.FAILED, JobSerializerHelper.toObjectSerializedString(ex)); } @@ -5469,7 +5553,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac final VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, work.getVmId()); if (vm == null) { String message = String.format("Unable to find VM [%s].", work.getVmId()); - s_logger.warn(message); + logger.warn(message); throw new CloudRuntimeException(message); } @@ -5492,7 +5576,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac try { orchestrateMigrateAway(vm.getUuid(), work.getSrcHostId(), null); } catch (final InsufficientServerCapacityException e) { - s_logger.warn("Failed to deploy vm " + vm.getId() + " with original planner, sending HAPlanner", e); + logger.warn("Failed to deploy vm " + vm.getId() + " with original planner, sending HAPlanner", e); orchestrateMigrateAway(vm.getUuid(), work.getSrcHostId(), _haMgr.getHAPlanner()); } @@ -5607,33 +5691,21 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return workJob; } - protected void resourceCountIncrement (long accountId, Long cpu, Long memory) { - _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.user_vm); - _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.cpu, cpu); - _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.memory, memory); - } - - protected void resourceCountDecrement (long accountId, Long cpu, Long memory) { - _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.user_vm); - _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.cpu, cpu); - _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.memory, memory); - } - @Override - public UserVm restoreVirtualMachine(final long vmId, final Long newTemplateId) throws ResourceUnavailableException, InsufficientCapacityException { + public UserVm restoreVirtualMachine(final long vmId, final Long newTemplateId, final Long rootDiskOfferingId, final boolean expunge, final Map details) throws ResourceUnavailableException, InsufficientCapacityException { final AsyncJobExecutionContext jobContext = AsyncJobExecutionContext.getCurrentExecutionContext(); if (jobContext.isJobDispatchedBy(VmWorkConstants.VM_WORK_JOB_DISPATCHER)) { VmWorkJobVO placeHolder = null; placeHolder = createPlaceHolderWork(vmId); try { - return orchestrateRestoreVirtualMachine(vmId, newTemplateId); + return orchestrateRestoreVirtualMachine(vmId, newTemplateId, rootDiskOfferingId, expunge, details); } finally { if (placeHolder != null) { _workJobDao.expunge(placeHolder.getId()); } } } else { - final Outcome outcome = restoreVirtualMachineThroughJobQueue(vmId, newTemplateId); + final Outcome outcome = restoreVirtualMachineThroughJobQueue(vmId, newTemplateId, rootDiskOfferingId, expunge, details); retrieveVmFromJobOutcome(outcome, String.valueOf(vmId), "restoreVirtualMachine"); @@ -5650,14 +5722,14 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } - private UserVm orchestrateRestoreVirtualMachine(final long vmId, final Long newTemplateId) throws ResourceUnavailableException, InsufficientCapacityException { - s_logger.debug("Restoring vm " + vmId + " with new templateId " + newTemplateId); + private UserVm orchestrateRestoreVirtualMachine(final long vmId, final Long newTemplateId, final Long rootDiskOfferingId, final boolean expunge, final Map details) throws ResourceUnavailableException, InsufficientCapacityException { + logger.debug("Restoring vm " + vmId + " with templateId : " + newTemplateId + " diskOfferingId : " + rootDiskOfferingId + " details : " + details); final CallContext context = CallContext.current(); final Account account = context.getCallingAccount(); - return _userVmService.restoreVirtualMachine(account, vmId, newTemplateId); + return _userVmService.restoreVirtualMachine(account, vmId, newTemplateId, rootDiskOfferingId, expunge, details); } - public Outcome restoreVirtualMachineThroughJobQueue(final long vmId, final Long newTemplateId) { + public Outcome restoreVirtualMachineThroughJobQueue(final long vmId, final Long newTemplateId, final Long rootDiskOfferingId, final boolean expunge, Map details) { String commandName = VmWorkRestore.class.getName(); Pair pendingWorkJob = retrievePendingWorkJob(vmId, commandName); @@ -5667,7 +5739,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Pair newVmWorkJobAndInfo = createWorkJobAndWorkInfo(commandName, vmId); workJob = newVmWorkJobAndInfo.first(); - VmWorkRestore workInfo = new VmWorkRestore(newVmWorkJobAndInfo.second(), newTemplateId); + VmWorkRestore workInfo = new VmWorkRestore(newVmWorkJobAndInfo.second(), newTemplateId, rootDiskOfferingId, expunge, details); setCmdInfoAndSubmitAsyncJob(workJob, workInfo, vmId); } @@ -5679,7 +5751,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac @ReflectionUse private Pair orchestrateRestoreVirtualMachine(final VmWorkRestore work) throws Exception { VMInstanceVO vm = findVmById(work.getVmId()); - UserVm uservm = orchestrateRestoreVirtualMachine(vm.getId(), work.getTemplateId()); + UserVm uservm = orchestrateRestoreVirtualMachine(vm.getId(), work.getTemplateId(), work.getRootDiskOfferingId(), work.getExpunge(), work.getDetails()); HashMap passwordMap = new HashMap<>(); passwordMap.put(uservm.getId(), uservm.getPassword()); return new Pair<>(JobInfo.Status.SUCCEEDED, _jobMgr.marshallResultObject(passwordMap)); @@ -5719,7 +5791,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac private Boolean orchestrateUpdateDefaultNicForVM(final VirtualMachine vm, final Nic nic, final Nic defaultNic) { - s_logger.debug("Updating default nic of vm " + vm + " from nic " + defaultNic.getUuid() + " to nic " + nic.getUuid()); + logger.debug("Updating default nic of vm " + vm + " from nic " + defaultNic.getUuid() + " to nic " + nic.getUuid()); Integer chosenID = nic.getDeviceId(); Integer existingID = defaultNic.getDeviceId(); NicVO nicVO = _nicsDao.findById(nic.getId()); @@ -5802,8 +5874,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac Long clusterId = null; if(hostId == null) { hostId = vm.getLastHostId(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("host id is null, using last host id %d", hostId) ); + if (logger.isDebugEnabled()) { + logger.debug(String.format("host id is null, using last host id %d", hostId) ); } } if (hostId == null) { @@ -5889,7 +5961,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (vm == null) { String message = String.format("Could not find a VM with the uuid [%s]. Unable to continue validations with command [%s] through job queue.", vmUuid, commandName); - s_logger.error(message); + logger.error(message); throw new RuntimeException(message); } @@ -5946,7 +6018,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, vmId); if (vm == null) { - s_logger.warn(String.format("Could not find VM [%s].", vmId)); + logger.warn(String.format("Could not find VM [%s].", vmId)); } assert vm != null; @@ -5978,12 +6050,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } Answer answer = _agentMgr.easySend(hostId, new GetVmStatsCommand(new ArrayList<>(vmNames.keySet()), _hostDao.findById(hostId).getGuid(), hostName)); if (answer == null || !answer.getResult()) { - s_logger.warn("Unable to obtain VM statistics."); + logger.warn("Unable to obtain VM statistics."); return vmStatsById; } else { HashMap vmStatsByName = ((GetVmStatsAnswer)answer).getVmStatsMap(); if (vmStatsByName == null) { - s_logger.warn("Unable to obtain VM statistics."); + logger.warn("Unable to obtain VM statistics."); return vmStatsById; } for (Map.Entry entry : vmStatsByName.entrySet()) { @@ -6005,12 +6077,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } Answer answer = _agentMgr.easySend(hostId, new GetVmDiskStatsCommand(new ArrayList<>(vmNames.keySet()), _hostDao.findById(hostId).getGuid(), hostName)); if (answer == null || !answer.getResult()) { - s_logger.warn("Unable to obtain VM disk statistics."); + logger.warn("Unable to obtain VM disk statistics."); return vmDiskStatsById; } else { HashMap> vmDiskStatsByName = ((GetVmDiskStatsAnswer)answer).getVmDiskStatsMap(); if (vmDiskStatsByName == null) { - s_logger.warn("Unable to obtain VM disk statistics."); + logger.warn("Unable to obtain VM disk statistics."); return vmDiskStatsById; } for (Map.Entry> entry: vmDiskStatsByName.entrySet()) { @@ -6032,12 +6104,12 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } Answer answer = _agentMgr.easySend(hostId, new GetVmNetworkStatsCommand(new ArrayList<>(vmNames.keySet()), _hostDao.findById(hostId).getGuid(), hostName)); if (answer == null || !answer.getResult()) { - s_logger.warn("Unable to obtain VM network statistics."); + logger.warn("Unable to obtain VM network statistics."); return vmNetworkStatsById; } else { HashMap> vmNetworkStatsByName = ((GetVmNetworkStatsAnswer)answer).getVmNetworkStatsMap(); if (vmNetworkStatsByName == null) { - s_logger.warn("Unable to obtain VM network statistics."); + logger.warn("Unable to obtain VM network statistics."); return vmNetworkStatsById; } for (Map.Entry> entry: vmNetworkStatsByName.entrySet()) { @@ -6046,4 +6118,48 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } return vmNetworkStatsById; } + + protected boolean isDiskOfferingSuitableForVm(VMInstanceVO vm, VirtualMachineProfile profile, long podId, long clusterId, long hostId, long diskOfferingId) { + + DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId); + VolumeVO dummyVolume = new VolumeVO("Data", vm.getDataCenterId(), podId, vm.getAccountId(), + vm.getDomainId(), vm.getId(), null, null, diskOffering.getProvisioningType(), diskOffering.getDiskSize(), Type.DATADISK); + try { + Field idField = dummyVolume.getClass().getDeclaredField("id"); + idField.setAccessible(true); + idField.set(dummyVolume, Volume.DISK_OFFERING_SUITABILITY_CHECK_VOLUME_ID); + } catch (NoSuchFieldException | IllegalAccessException ignored) { + return false; + } + dummyVolume.setDiskOfferingId(diskOfferingId); + DiskProfile diskProfile = new DiskProfile(dummyVolume, diskOffering, profile.getHypervisorType()); + diskProfile.setMinIops(diskOffering.getMinIops()); + diskProfile.setMaxIops(diskOffering.getMaxIops()); + ExcludeList avoid = new ExcludeList(); + DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), podId, clusterId, hostId, null, null); + for (StoragePoolAllocator allocator : _storagePoolAllocators) { + List poolListFromAllocator = allocator.allocateToPool(diskProfile, profile, plan, avoid, 1); + if (CollectionUtils.isNotEmpty(poolListFromAllocator)) { + if (logger.isDebugEnabled()) { + logger.debug(String.format("Found a suitable pool: %s for disk offering: %s", poolListFromAllocator.get(0).getName(), diskOffering.getName())); + } + return true; + } + } + return false; + } + + @Override + public Map getDiskOfferingSuitabilityForVm(long vmId, List diskOfferingIds) { + VMInstanceVO vm = _vmDao.findById(vmId); + VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm); + Pair clusterAndHost = findClusterAndHostIdForVm(vm, false); + Long clusterId = clusterAndHost.first(); + Cluster cluster = _clusterDao.findById(clusterId); + Map result = new HashMap<>(); + for (Long diskOfferingId : diskOfferingIds) { + result.put(diskOfferingId, isDiskOfferingSuitableForVm(vm, profile, cluster.getPodId(), clusterId, clusterAndHost.second(), diskOfferingId)); + } + return result; + } } diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java index 3eb3569cab0..bbd4510f6f5 100644 --- a/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java @@ -26,7 +26,8 @@ import javax.inject.Inject; import org.apache.cloudstack.framework.messagebus.MessageBus; import org.apache.cloudstack.framework.messagebus.PublishScope; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.HostVmStateReportEntry; import com.cloud.configuration.ManagementServiceConfiguration; @@ -35,7 +36,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.dao.VMInstanceDao; public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStateSync { - private static final Logger s_logger = Logger.getLogger(VirtualMachinePowerStateSyncImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject MessageBus _messageBus; @Inject VMInstanceDao _instanceDao; @@ -46,13 +47,13 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat @Override public void resetHostSyncState(long hostId) { - s_logger.info("Reset VM power state sync for host: " + hostId); + logger.info("Reset VM power state sync for host: " + hostId); _instanceDao.resetHostPowerStateTracking(hostId); } @Override public void processHostVmStateReport(long hostId, Map report) { - s_logger.debug("Process host VM state report. host: " + hostId); + logger.debug("Process host VM state report. host: " + hostId); Map translatedInfo = convertVmStateReport(report); processReport(hostId, translatedInfo, false); @@ -60,8 +61,8 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat @Override public void processHostVmStatePingReport(long hostId, Map report, boolean force) { - if (s_logger.isDebugEnabled()) - s_logger.debug("Process host VM state report from ping process. host: " + hostId); + if (logger.isDebugEnabled()) + logger.debug("Process host VM state report from ping process. host: " + hostId); Map translatedInfo = convertVmStateReport(report); processReport(hostId, translatedInfo, force); @@ -69,24 +70,24 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat private void processReport(long hostId, Map translatedInfo, boolean force) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Process VM state report. host: " + hostId + ", number of records in report: " + translatedInfo.size()); + if (logger.isDebugEnabled()) { + logger.debug("Process VM state report. host: " + hostId + ", number of records in report: " + translatedInfo.size()); } for (Map.Entry entry : translatedInfo.entrySet()) { - if (s_logger.isDebugEnabled()) - s_logger.debug("VM state report. host: " + hostId + ", vm id: " + entry.getKey() + ", power state: " + entry.getValue()); + if (logger.isDebugEnabled()) + logger.debug("VM state report. host: " + hostId + ", vm id: " + entry.getKey() + ", power state: " + entry.getValue()); if (_instanceDao.updatePowerState(entry.getKey(), hostId, entry.getValue(), DateUtil.currentGMTTime())) { - if (s_logger.isInfoEnabled()) { - s_logger.debug("VM state report is updated. host: " + hostId + ", vm id: " + entry.getKey() + ", power state: " + entry.getValue()); + if (logger.isInfoEnabled()) { + logger.debug("VM state report is updated. host: " + hostId + ", vm id: " + entry.getKey() + ", power state: " + entry.getValue()); } _messageBus.publish(null, VirtualMachineManager.Topics.VM_POWER_STATE, PublishScope.GLOBAL, entry.getKey()); } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("VM power state does not change, skip DB writing. vm id: " + entry.getKey()); + if (logger.isTraceEnabled()) { + logger.trace("VM power state does not change, skip DB writing. vm id: " + entry.getKey()); } } } @@ -106,8 +107,8 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat // here we need to be wary of out of band migration as opposed to other, more unexpected state changes if (vmsThatAreMissingReport.size() > 0) { Date currentTime = DateUtil.currentGMTTime(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run missing VM report. current time: " + currentTime.getTime()); + if (logger.isDebugEnabled()) { + logger.debug("Run missing VM report. current time: " + currentTime.getTime()); } // 2 times of sync-update interval for graceful period @@ -118,28 +119,28 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat // Make sure powerState is up to date for missing VMs try { if (!force && !_instanceDao.isPowerStateUpToDate(instance.getId())) { - s_logger.warn("Detected missing VM but power state is outdated, wait for another process report run for VM id: " + instance.getId()); + logger.warn("Detected missing VM but power state is outdated, wait for another process report run for VM id: " + instance.getId()); _instanceDao.resetVmPowerStateTracking(instance.getId()); continue; } } catch (CloudRuntimeException e) { - s_logger.warn("Checked for missing powerstate of a none existing vm", e); + logger.warn("Checked for missing powerstate of a none existing vm", e); continue; } Date vmStateUpdateTime = instance.getPowerStateUpdateTime(); if (vmStateUpdateTime == null) { - s_logger.warn("VM power state update time is null, falling back to update time for vm id: " + instance.getId()); + logger.warn("VM power state update time is null, falling back to update time for vm id: " + instance.getId()); vmStateUpdateTime = instance.getUpdateTime(); if (vmStateUpdateTime == null) { - s_logger.warn("VM update time is null, falling back to creation time for vm id: " + instance.getId()); + logger.warn("VM update time is null, falling back to creation time for vm id: " + instance.getId()); vmStateUpdateTime = instance.getCreated(); } } - if (s_logger.isInfoEnabled()) { + if (logger.isInfoEnabled()) { String lastTime = new SimpleDateFormat("yyyy/MM/dd'T'HH:mm:ss.SSS'Z'").format(vmStateUpdateTime); - s_logger.debug( + logger.debug( String.format("Detected missing VM. host: %d, vm id: %d(%s), power state: %s, last state update: %s" , hostId , instance.getId() @@ -151,30 +152,30 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat long milliSecondsSinceLastStateUpdate = currentTime.getTime() - vmStateUpdateTime.getTime(); if (force || milliSecondsSinceLastStateUpdate > milliSecondsGracefullPeriod) { - s_logger.debug("vm id: " + instance.getId() + " - time since last state update(" + milliSecondsSinceLastStateUpdate + "ms) has passed graceful period"); + logger.debug("vm id: " + instance.getId() + " - time since last state update(" + milliSecondsSinceLastStateUpdate + "ms) has passed graceful period"); // this is were a race condition might have happened if we don't re-fetch the instance; // between the startime of this job and the currentTime of this missing-branch // an update might have occurred that we should not override in case of out of band migration if (_instanceDao.updatePowerState(instance.getId(), hostId, VirtualMachine.PowerState.PowerReportMissing, startTime)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("VM state report is updated. host: " + hostId + ", vm id: " + instance.getId() + ", power state: PowerReportMissing "); + if (logger.isDebugEnabled()) { + logger.debug("VM state report is updated. host: " + hostId + ", vm id: " + instance.getId() + ", power state: PowerReportMissing "); } _messageBus.publish(null, VirtualMachineManager.Topics.VM_POWER_STATE, PublishScope.GLOBAL, instance.getId()); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("VM power state does not change, skip DB writing. vm id: " + instance.getId()); + if (logger.isDebugEnabled()) { + logger.debug("VM power state does not change, skip DB writing. vm id: " + instance.getId()); } } } else { - s_logger.debug("vm id: " + instance.getId() + " - time since last state update(" + milliSecondsSinceLastStateUpdate + "ms) has not passed graceful period yet"); + logger.debug("vm id: " + instance.getId() + " - time since last state update(" + milliSecondsSinceLastStateUpdate + "ms) has not passed graceful period yet"); } } } - if (s_logger.isDebugEnabled()) - s_logger.debug("Done with process of VM state report. host: " + hostId); + if (logger.isDebugEnabled()) + logger.debug("Done with process of VM state report. host: " + hostId); } @Override @@ -189,7 +190,7 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat if (vm != null) { map.put(vm.getId(), entry.getValue().getState()); } else { - s_logger.debug("Unable to find matched VM in CloudStack DB. name: " + entry.getKey()); + logger.debug("Unable to find matched VM in CloudStack DB. name: " + entry.getKey()); } } diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkJobDispatcher.java b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkJobDispatcher.java index 9f1eca67022..c7e30e366a9 100644 --- a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkJobDispatcher.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkJobDispatcher.java @@ -20,7 +20,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.framework.jobs.AsyncJob; @@ -34,7 +33,6 @@ import com.cloud.utils.component.AdapterBase; import com.cloud.vm.dao.VMInstanceDao; public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatcher { - private static final Logger s_logger = Logger.getLogger(VmWorkJobDispatcher.class); @Inject private VirtualMachineManagerImpl _vmMgr; @Inject @@ -65,23 +63,23 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch try { workClz = Class.forName(job.getCmd()); } catch (ClassNotFoundException e) { - s_logger.error("VM work class " + cmd + " is not found" + ", job origin: " + job.getRelated(), e); + logger.error("VM work class " + cmd + " is not found" + ", job origin: " + job.getRelated(), e); _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, e.getMessage()); return; } work = VmWorkSerializer.deserialize(workClz, job.getCmdInfo()); if(work == null) { - s_logger.error("Unable to deserialize VM work " + job.getCmd() + ", job info: " + job.getCmdInfo() + ", job origin: " + job.getRelated()); + logger.error("Unable to deserialize VM work " + job.getCmd() + ", job info: " + job.getCmdInfo() + ", job origin: " + job.getRelated()); _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, "Unable to deserialize VM work"); return; } - if (s_logger.isDebugEnabled()) - s_logger.debug("Run VM work job: " + cmd + " for VM " + work.getVmId() + ", job origin: " + job.getRelated()); + if (logger.isDebugEnabled()) + logger.debug("Run VM work job: " + cmd + " for VM " + work.getVmId() + ", job origin: " + job.getRelated()); try { if (_handlers == null || _handlers.isEmpty()) { - s_logger.error("Invalid startup configuration, no work job handler is found. cmd: " + job.getCmd() + ", job info: " + job.getCmdInfo() + logger.error("Invalid startup configuration, no work job handler is found. cmd: " + job.getCmd() + ", job info: " + job.getCmdInfo() + ", job origin: " + job.getRelated()); _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, "Invalid startup configuration. no job handler is found"); return; @@ -90,7 +88,7 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch VmWorkJobHandler handler = _handlers.get(work.getHandlerName()); if (handler == null) { - s_logger.error("Unable to find work job handler. handler name: " + work.getHandlerName() + ", job cmd: " + job.getCmd() + logger.error("Unable to find work job handler. handler name: " + work.getHandlerName() + ", job cmd: " + job.getCmd() + ", job info: " + job.getCmdInfo() + ", job origin: " + job.getRelated()); _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, "Unable to find work job handler"); return; @@ -105,14 +103,14 @@ public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatch CallContext.unregister(); } } finally { - if (s_logger.isDebugEnabled()) - s_logger.debug("Done with run of VM work job: " + cmd + " for VM " + work.getVmId() + ", job origin: " + job.getRelated()); + if (logger.isDebugEnabled()) + logger.debug("Done with run of VM work job: " + cmd + " for VM " + work.getVmId() + ", job origin: " + job.getRelated()); } } catch(InvalidParameterValueException e) { - s_logger.error("Unable to complete " + job + ", job origin:" + job.getRelated()); + logger.error("Unable to complete " + job + ", job origin:" + job.getRelated()); _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, _asyncJobMgr.marshallResultObject(e)); } catch(Throwable e) { - s_logger.error("Unable to complete " + job + ", job origin:" + job.getRelated(), e); + logger.error("Unable to complete " + job + ", job origin:" + job.getRelated(), e); //RuntimeException ex = new RuntimeException("Job failed due to exception " + e.getMessage()); _asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, _asyncJobMgr.marshallResultObject(e)); diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkJobWakeupDispatcher.java b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkJobWakeupDispatcher.java index 0afe21f7262..b7c82ce5c21 100644 --- a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkJobWakeupDispatcher.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkJobWakeupDispatcher.java @@ -24,7 +24,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.framework.jobs.AsyncJob; @@ -47,7 +46,6 @@ import com.cloud.vm.dao.VMInstanceDao; * Current code base uses blocking calls to wait for job completion */ public class VmWorkJobWakeupDispatcher extends AdapterBase implements AsyncJobDispatcher { - private static final Logger s_logger = Logger.getLogger(VmWorkJobWakeupDispatcher.class); @Inject private VmWorkJobDao _workjobDao; @@ -69,7 +67,7 @@ public class VmWorkJobWakeupDispatcher extends AdapterBase implements AsyncJobDi try { List joinRecords = _joinMapDao.listJoinRecords(job.getId()); if (joinRecords.size() != 1) { - s_logger.warn("AsyncJob-" + job.getId() + logger.warn("AsyncJob-" + job.getId() + " received wakeup call with un-supported joining job number: " + joinRecords.size()); // if we fail wakeup-execution for any reason, avoid release sync-source if there is any @@ -84,7 +82,7 @@ public class VmWorkJobWakeupDispatcher extends AdapterBase implements AsyncJobDi try { workClz = Class.forName(job.getCmd()); } catch (ClassNotFoundException e) { - s_logger.error("VM work class " + job.getCmd() + " is not found", e); + logger.error("VM work class " + job.getCmd() + " is not found", e); return; } @@ -105,14 +103,14 @@ public class VmWorkJobWakeupDispatcher extends AdapterBase implements AsyncJobDi handler.invoke(_vmMgr); } else { assert (false); - s_logger.error("Unable to find wakeup handler " + joinRecord.getWakeupHandler() + + logger.error("Unable to find wakeup handler " + joinRecord.getWakeupHandler() + " when waking up job-" + job.getId()); } } finally { CallContext.unregister(); } } catch (Throwable e) { - s_logger.warn("Unexpected exception in waking up job-" + job.getId()); + logger.warn("Unexpected exception in waking up job-" + job.getId()); // if we fail wakeup-execution for any reason, avoid release sync-source if there is any job.setSyncSource(null); @@ -132,11 +130,11 @@ public class VmWorkJobWakeupDispatcher extends AdapterBase implements AsyncJobDi method.setAccessible(true); } catch (SecurityException e) { assert (false); - s_logger.error("Unexpected exception", e); + logger.error("Unexpected exception", e); return null; } catch (NoSuchMethodException e) { assert (false); - s_logger.error("Unexpected exception", e); + logger.error("Unexpected exception", e); return null; } diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkReboot.java b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkReboot.java index 6a903b3d781..3813a8dc207 100644 --- a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkReboot.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkReboot.java @@ -17,7 +17,9 @@ package com.cloud.vm; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper; @@ -62,4 +64,11 @@ public class VmWorkReboot extends VmWork { } } } + + @Override + public String toString() { + List params = new ArrayList<>(); + params.add(VirtualMachineProfile.Param.VmPassword.getName()); + return super.toStringAfterRemoveParams("rawParams", params); + } } diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkRestore.java b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkRestore.java index cb3adae27aa..ab5425a2500 100644 --- a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkRestore.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkRestore.java @@ -16,23 +16,38 @@ // under the License. package com.cloud.vm; +import java.util.Map; + public class VmWorkRestore extends VmWork { private static final long serialVersionUID = 195901782359759635L; private Long templateId; + private Long rootDiskOfferingId; + private Map details; - public VmWorkRestore(long userId, long accountId, long vmId, String handlerName, Long templateId) { - super(userId, accountId, vmId, handlerName); + private boolean expunge; - this.templateId = templateId; - } - - public VmWorkRestore(VmWork vmWork, Long templateId) { + public VmWorkRestore(VmWork vmWork, Long templateId, Long rootDiskOfferingId, boolean expunge, Map details) { super(vmWork); this.templateId = templateId; + this.rootDiskOfferingId = rootDiskOfferingId; + this.expunge = expunge; + this.details = details; } public Long getTemplateId() { return templateId; } + + public Long getRootDiskOfferingId() { + return rootDiskOfferingId; + } + + public boolean getExpunge() { + return expunge; + } + + public Map getDetails() { + return details; + } } diff --git a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkStart.java b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkStart.java index 1b2a7194d17..132bc9e19be 100644 --- a/engine/orchestration/src/main/java/com/cloud/vm/VmWorkStart.java +++ b/engine/orchestration/src/main/java/com/cloud/vm/VmWorkStart.java @@ -18,12 +18,13 @@ package com.cloud.vm; import java.io.Serializable; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper; -import org.apache.log4j.Logger; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeploymentPlan; @@ -33,7 +34,6 @@ import com.cloud.utils.Journal; public class VmWorkStart extends VmWork { private static final long serialVersionUID = 9038937399817468894L; - private static final Logger s_logger = Logger.getLogger(VmWorkStart.class); long dcId; Long podId; @@ -65,7 +65,7 @@ public class VmWorkStart extends VmWork { // this has to be refactored together with migrating legacy code into the new way ReservationContext context = null; if (reservationId != null) { - Journal journal = new Journal.LogJournal("VmWorkStart", s_logger); + Journal journal = new Journal.LogJournal("VmWorkStart", logger); context = new ReservationContextImpl(reservationId, journal, CallContext.current().getCallingUser(), CallContext.current().getCallingAccount()); @@ -135,4 +135,11 @@ public class VmWorkStart extends VmWork { } } } + + @Override + public String toString() { + List params = new ArrayList<>(); + params.add(VirtualMachineProfile.Param.VmPassword.getName()); + return super.toStringAfterRemoveParams("rawParams", params); + } } diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java index 896b55734d7..8d4fa21754c 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java @@ -30,7 +30,8 @@ import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenter; @@ -68,7 +69,7 @@ import com.cloud.vm.dao.VMInstanceDao; @Component public class VMEntityManagerImpl implements VMEntityManager { - private static final Logger s_logger = Logger.getLogger(VMEntityManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject protected VMInstanceDao _vmDao; @@ -213,8 +214,8 @@ public class VMEntityManagerImpl implements VMEntityManager { if (reservationId != null) { return reservationId; } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cannot finalize the VM reservation for this destination found, retrying"); + if (logger.isDebugEnabled()) { + logger.debug("Cannot finalize the VM reservation for this destination found, retrying"); } exclude.addHost(dest.getHost().getId()); continue; diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineClusterVO.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineClusterVO.java index 75965fe4bd1..be35cea3c07 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineClusterVO.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineClusterVO.java @@ -26,8 +26,10 @@ import com.cloud.utils.db.StateMachine; import org.apache.cloudstack.api.Identity; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State.Event; +import org.apache.cloudstack.util.HypervisorTypeConverter; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -62,6 +64,7 @@ public class EngineClusterVO implements EngineCluster, Identity { long podId; @Column(name = "hypervisor_type") + @Convert(converter = HypervisorTypeConverter.class) String hypervisorType; @Column(name = "cluster_type") diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineHostVO.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineHostVO.java index 846b4157786..f8535b6b6cc 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineHostVO.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/EngineHostVO.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; @@ -45,9 +46,11 @@ import com.cloud.host.Status; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.resource.ResourceState; import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.util.StoragePoolTypeConverter; import com.cloud.utils.NumbersUtil; import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.StateMachine; +import org.apache.cloudstack.util.HypervisorTypeConverter; @Entity @Table(name = "host") @@ -116,7 +119,7 @@ public class EngineHostVO implements EngineHost, Identity { private String storageMacAddressDeux; @Column(name = "hypervisor_type", updatable = true, nullable = false) - @Enumerated(value = EnumType.STRING) + @Convert(converter = HypervisorTypeConverter.class) private HypervisorType hypervisorType; @Column(name = "proxy_port") @@ -126,6 +129,7 @@ public class EngineHostVO implements EngineHost, Identity { private String resource; @Column(name = "fs_type") + @Convert(converter = StoragePoolTypeConverter.class) private StoragePoolType fsType; @Column(name = "available") diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineClusterDaoImpl.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineClusterDaoImpl.java index 10c75d56db0..cc33f9eb335 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineClusterDaoImpl.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineClusterDaoImpl.java @@ -27,7 +27,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity; @@ -51,7 +50,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component(value = "EngineClusterDao") public class EngineClusterDaoImpl extends GenericDaoBase implements EngineClusterDao { - private static final Logger s_logger = Logger.getLogger(EngineClusterDaoImpl.class); protected final SearchBuilder PodSearch; protected final SearchBuilder HyTypeWithoutGuidSearch; @@ -272,7 +270,7 @@ public class EngineClusterDaoImpl extends GenericDaoBase int rows = update(vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { EngineClusterVO dbCluster = findByIdIncludingRemoved(vo.getId()); if (dbCluster != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -299,7 +297,7 @@ public class EngineClusterDaoImpl extends GenericDaoBase .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore"); + logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore"); } } return rows > 0; diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineDataCenterDaoImpl.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineDataCenterDaoImpl.java index f4b2362d055..03b4bd9eaaf 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineDataCenterDaoImpl.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineDataCenterDaoImpl.java @@ -24,7 +24,6 @@ import java.util.Random; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity; @@ -50,7 +49,6 @@ import com.cloud.utils.db.UpdateBuilder; **/ @Component(value = "EngineDataCenterDao") public class EngineDataCenterDaoImpl extends GenericDaoBase implements EngineDataCenterDao { - private static final Logger s_logger = Logger.getLogger(EngineDataCenterDaoImpl.class); protected SearchBuilder NameSearch; protected SearchBuilder ListZonesByDomainIdSearch; @@ -242,7 +240,7 @@ public class EngineDataCenterDaoImpl extends GenericDaoBase 0; diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java index 819bd32146e..2099ebadb9f 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostDaoImpl.java @@ -25,7 +25,6 @@ import java.util.Map; import javax.inject.Inject; import javax.persistence.TableGenerator; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity; @@ -54,7 +53,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @DB @TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1) public class EngineHostDaoImpl extends GenericDaoBase implements EngineHostDao { - private static final Logger s_logger = Logger.getLogger(EngineHostDaoImpl.class); private final SearchBuilder TypePodDcStatusSearch; @@ -431,7 +429,7 @@ public class EngineHostDaoImpl extends GenericDaoBase implem int rows = update(vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { EngineHostVO dbHost = findByIdIncludingRemoved(vo.getId()); if (dbHost != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -453,7 +451,7 @@ public class EngineHostDaoImpl extends GenericDaoBase implem .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore"); + logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore"); } } return rows > 0; diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostPodDaoImpl.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostPodDaoImpl.java index 1eb0857a61d..535e396a376 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostPodDaoImpl.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/datacenter/entity/api/db/dao/EngineHostPodDaoImpl.java @@ -25,7 +25,6 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity; @@ -44,7 +43,6 @@ import com.cloud.utils.db.UpdateBuilder; @Component(value = "EngineHostPodDao") public class EngineHostPodDaoImpl extends GenericDaoBase implements EngineHostPodDao { - private static final Logger s_logger = Logger.getLogger(EngineHostPodDaoImpl.class); protected SearchBuilder DataCenterAndNameSearch; protected SearchBuilder DataCenterIdSearch; @@ -111,7 +109,7 @@ public class EngineHostPodDaoImpl extends GenericDaoBase currentPodCidrSubnets.put(podId, cidrPair); } } catch (SQLException ex) { - s_logger.warn("DB exception " + ex.getMessage(), ex); + logger.warn("DB exception " + ex.getMessage(), ex); return null; } @@ -163,7 +161,7 @@ public class EngineHostPodDaoImpl extends GenericDaoBase int rows = update(vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { EngineHostPodVO dbDC = findByIdIncludingRemoved(vo.getId()); if (dbDC != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -185,7 +183,7 @@ public class EngineHostPodDaoImpl extends GenericDaoBase .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore"); + logger.debug("Unable to update dataCenter: id=" + vo.getId() + ", as there is no such dataCenter exists in the database anymore"); } } return rows > 0; diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java index d639b4513e4..6763a13aed6 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/CloudOrchestrator.java @@ -61,6 +61,9 @@ import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.UserVmDetailsDao; import com.cloud.vm.dao.VMInstanceDao; +import static org.apache.cloudstack.api.ApiConstants.MAX_IOPS; +import static org.apache.cloudstack.api.ApiConstants.MIN_IOPS; + @Component public class CloudOrchestrator implements OrchestrationService { @@ -196,8 +199,8 @@ public class CloudOrchestrator implements OrchestrationService { Map userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId()); if (userVmDetails != null) { - String minIops = userVmDetails.get("minIops"); - String maxIops = userVmDetails.get("maxIops"); + String minIops = userVmDetails.get(MIN_IOPS); + String maxIops = userVmDetails.get(MAX_IOPS); rootDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null); rootDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null); diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java index 0a761cb7fbb..31230442f17 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java @@ -46,7 +46,6 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; -import org.apache.log4j.Logger; import com.cloud.host.HostVO; import com.cloud.host.Status; @@ -62,9 +61,11 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.SecondaryStorageVmVO; import com.cloud.vm.VirtualMachine; import com.cloud.vm.dao.SecondaryStorageVmDao; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class DataMigrationUtility { - private static Logger LOGGER = Logger.getLogger(DataMigrationUtility.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject SecondaryStorageVmDao secStorageVmDao; @@ -96,15 +97,15 @@ public class DataMigrationUtility { boolean isReady = true; for (TemplateDataStoreVO template : templates) { isReady &= (Arrays.asList(validStates).contains(template.getState())); - LOGGER.trace(String.format("template state: %s", template.getState())); + logger.trace(String.format("template state: %s", template.getState())); } for (SnapshotDataStoreVO snapshot : snapshots) { isReady &= (Arrays.asList(validStates).contains(snapshot.getState())); - LOGGER.trace(String.format("snapshot state: %s", snapshot.getState())); + logger.trace(String.format("snapshot state: %s", snapshot.getState())); } for (VolumeDataStoreVO volume : volumes) { isReady &= (Arrays.asList(validStates).contains(volume.getState())); - LOGGER.trace(String.format("volume state: %s", volume.getState())); + logger.trace(String.format("volume state: %s", volume.getState())); } return isReady; } diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java index 30fd35e5f37..5e3c8cfaa57 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -38,6 +38,9 @@ import java.util.stream.Collectors; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.dc.VlanDetailsVO; +import com.cloud.dc.dao.VlanDetailsDao; +import com.cloud.network.dao.NsxProviderDao; import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.annotation.AnnotationService; import org.apache.cloudstack.annotation.dao.AnnotationDao; @@ -56,8 +59,8 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.network.dao.NetworkPermissionDao; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -254,12 +257,12 @@ import com.cloud.vm.dao.NicSecondaryIpVO; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; import com.googlecode.ipv6.IPv6Address; +import org.jetbrains.annotations.NotNull; /** * NetworkManagerImpl implements NetworkManager. */ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestrationService, Listener, Configurable { - static final Logger s_logger = Logger.getLogger(NetworkOrchestrator.class); @Inject EntityManager _entityMgr; @@ -339,8 +342,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra Ipv6Service ipv6Service; @Inject RouterNetworkDao routerNetworkDao; + @Inject + private VlanDetailsDao vlanDetailsDao; List networkGurus; + @Inject + private NsxProviderDao nsxProviderDao; @Override public List getNetworkGurus() { @@ -502,6 +509,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra defaultTungstenSharedSGEnabledNetworkOfferingProviders.put(Service.UserData, tungstenProvider); defaultTungstenSharedSGEnabledNetworkOfferingProviders.put(Service.SecurityGroup, tungstenProvider); + final Map> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = new HashMap>(); defaultProviders.clear(); defaultProviders.add(Network.Provider.VirtualRouter); @@ -538,27 +546,27 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (_networkOfferingDao.findByUniqueName(NetworkOffering.QuickCloudNoServices) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.QuickCloudNoServices, "Offering for QuickCloud with no services", TrafficType.Guest, null, true, Availability.Optional, null, new HashMap>(), true, Network.GuestType.Shared, false, null, true, null, true, - false, null, false, null, true, false, false, null, null, true, null); + false, null, false, null, true, false, false, false, null, null, null, true, null); } //#2 - SG enabled network offering if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, - null, true, false, null, false, null, true, false, false, null, null, true, null); + null, true, false, null, false, null, true, false, false, false, null, null, null, true, null); } //#3 - shared network offering with no SG service if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false, null, false, - null, true, false, false, null, null, true, null); + null, true, false, false, false, null,null, null, true, null); } if (_networkOfferingDao.findByUniqueName(NetworkOffering.DEFAULT_TUNGSTEN_SHARED_NETWORK_OFFERING_WITH_SGSERVICE) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DEFAULT_TUNGSTEN_SHARED_NETWORK_OFFERING_WITH_SGSERVICE, "Offering for Tungsten Shared Security group enabled networks", TrafficType.Guest, null, true, Availability.Optional, null, defaultTungstenSharedSGEnabledNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, - null, true, false, null, false, null, true, false, true,null, null, true, null); + null, true, false, null, false, null, true, false, true, false, null, null,null, true, null); offering.setState(NetworkOffering.State.Enabled); _networkOfferingDao.update(offering.getId(), offering); } @@ -568,14 +576,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false, false, null, false, null, - true, false, false, null, null, true, null); + true, false, false, false, null, null,null, true, null); } //#5 - default vpc offering with LB service if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Optional, null, - defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, null, null, true, null); + defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, false, null, null, null,true, null); } //#6 - default vpc offering with no LB service @@ -584,14 +592,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra defaultVPCOffProviders.remove(Service.Lb); offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB, "Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled", TrafficType.Guest, null, false, Availability.Optional, - null, defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, null, null, true, null); + null, defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, false, null, null, null,true, null); } //#7 - isolated offering with source nat disabled if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, - true, null, true, false, null, false, null, true, false, false, null, null, true, null); + true, null, true, false, null, false, null, true, false, false, false, null, null, null, true, null); } //#8 - network offering with internal lb service @@ -613,7 +621,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB, "Offering for Isolated VPC networks with Internal Lb support", TrafficType.Guest, null, false, Availability.Optional, null, internalLbOffProviders, - true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, null, null, true, null); + true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, false, false, null, null, null, true, null); offering.setInternalLb(true); offering.setPublicLb(false); _networkOfferingDao.update(offering.getId(), offering); @@ -644,7 +652,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) { offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, Availability.Optional, null, - netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null, false, null, true, false, false, null, null, true, null); + netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null, false, null, true, false, false, false, null, null, null, true, null); offering.setDedicatedLB(false); _networkOfferingDao.update(offering.getId(), offering); } @@ -685,7 +693,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra Network.State.getStateMachine().registerListener(new NetworkStateListener(_configDao)); - s_logger.info("Network Manager is configured."); + logger.info("Network Manager is configured."); return true; } @@ -693,7 +701,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @Override public boolean start() { final int netGcInterval = NumbersUtil.parseInt(_configDao.getValue(NetworkGcInterval.key()), 60); - s_logger.info("Network Manager will run the NetworkGarbageCollector every '" + netGcInterval + "' seconds."); + logger.info("Network Manager will run the NetworkGarbageCollector every '" + netGcInterval + "' seconds."); _executor.scheduleWithFixedDelay(new NetworkGarbageCollector(), netGcInterval, netGcInterval, TimeUnit.SECONDS); return true; @@ -740,20 +748,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra .getBroadcastDomainType() == BroadcastDomainType.Vlan || predefined.getBroadcastDomainType() == BroadcastDomainType.Lswitch || predefined .getBroadcastDomainType() == BroadcastDomainType.Vxlan)) { final List configs = _networksDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId()); - if (configs.size() > 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found existing network configuration for offering " + offering + ": " + configs.get(0)); - } - - if (errorIfAlreadySetup) { - final InvalidParameterValueException ex = new InvalidParameterValueException( - "Found existing network configuration (with specified id) for offering (with specified id)"); - ex.addProxyObject(offering.getUuid(), "offeringId"); - ex.addProxyObject(configs.get(0).getUuid(), "networkConfigId"); - throw ex; - } else { - return configs; - } + if (!configs.isEmpty()) { + return existingConfiguration(offering, configs, errorIfAlreadySetup); } } @@ -762,7 +758,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra long related = -1; for (final NetworkGuru guru : networkGurus) { - final Network network = guru.design(offering, plan, predefined, owner); + final Network network = guru.design(offering, plan, predefined, name, vpcId, owner); if (network == null) { continue; } @@ -785,11 +781,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra Transaction.execute(new TransactionCallbackNoReturn() { @Override public void doInTransactionWithoutResult(final TransactionStatus status) { - final NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), relatedFile, name, displayText, predefined - .getNetworkDomain(), offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.isSpecifyIpRanges(), - vpcId, offering.isRedundantRouter(), predefined.getExternalId()); - vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled); - vo.setStrechedL2Network(offering.isSupportingStrechedL2()); + final NetworkVO vo = getNetworkVO(id, offering, plan, predefined, + network, guru, owner, name, displayText,relatedFile, aclType,vpcId, isDisplayNetworkEnabled); final NetworkVO networkPersisted = _networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())); networks.add(networkPersisted); @@ -806,13 +799,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } if (domainId != null && aclType == ACLType.Domain) { - _networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null ? true : subdomainAccess); + _networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null || subdomainAccess); } } }); + guru.setup(network, relatedFile); } - if (networks.size() < 1) { + if (networks.isEmpty()) { // see networkOfferingVO.java final CloudRuntimeException ex = new CloudRuntimeException("Unable to convert network offering with specified id to network profile"); ex.addProxyObject(offering.getUuid(), "offeringId"); @@ -821,18 +815,49 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return networks; } finally { - s_logger.debug("Releasing lock for " + locked); + logger.debug("Releasing lock for " + locked); _accountDao.releaseFromLockTable(locked.getId()); } } + @NotNull + private static NetworkVO getNetworkVO(long id, final NetworkOffering offering, final DeploymentPlan plan, final Network predefined, + Network network, final NetworkGuru guru, final Account owner, + final String name, final String displayText, long relatedFile, final ACLType aclType, + final Long vpcId, final Boolean isDisplayNetworkEnabled) { + final NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), + relatedFile, name, displayText, predefined.getNetworkDomain(), offering.getGuestType(), + plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.isSpecifyIpRanges(), + vpcId, offering.isRedundantRouter(), predefined.getExternalId()); + vo.setDisplayNetwork(isDisplayNetworkEnabled == null || isDisplayNetworkEnabled); + vo.setStrechedL2Network(offering.isSupportingStrechedL2()); + return vo; + } + + private List existingConfiguration(final NetworkOffering offering, List configs, + final boolean errorIfAlreadySetup) { + if (logger.isDebugEnabled()) { + logger.debug("Found existing network configuration for offering " + offering + ": " + configs.get(0)); + } + + if (errorIfAlreadySetup) { + final InvalidParameterValueException ex = new InvalidParameterValueException( + "Found existing network configuration (with specified id) for offering (with specified id)"); + ex.addProxyObject(offering.getUuid(), "offeringId"); + ex.addProxyObject(configs.get(0).getUuid(), "networkConfigId"); + throw ex; + } else { + return configs; + } + } + @Override @DB public void allocate(final VirtualMachineProfile vm, final LinkedHashMap> networks, final Map> extraDhcpOptions) throws InsufficientCapacityException, ConcurrentOperationException { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("allocating networks for %s(template %s); %d networks", vm.getInstanceName(), vm.getTemplate().getUuid(), networks.size())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("allocating networks for %s(template %s); %d networks", vm.getInstanceName(), vm.getTemplate().getUuid(), networks.size())); } int deviceId = 0; int size; @@ -977,7 +1002,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra */ private void createExtraNics(final VirtualMachineProfile vm, int size, List nics, Network finalNetwork) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { if (nics.size() != size) { - s_logger.warn("Number of nics " + nics.size() + " doesn't match number of requested nics " + size); + logger.warn("Number of nics " + nics.size() + " doesn't match number of requested nics " + size); if (nics.size() > size) { throw new CloudRuntimeException("Number of nics " + nics.size() + " doesn't match number of requested networks " + size); } else { @@ -1016,7 +1041,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException { final NetworkVO ntwkVO = _networksDao.findById(network.getId()); - s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested); + logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested); final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, ntwkVO.getGuruName()); if (requested != null && requested.getMode() == null) { @@ -1027,6 +1052,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return null; } + if (isNicAllocatedForNsxPublicNetworkOnVR(network, profile, vm)) { + String guruName = "NsxPublicNetworkGuru"; + NetworkGuru nsxGuru = AdapterBase.getAdapterByName(networkGurus, guruName); + nsxGuru.allocate(network, profile, vm); + } + if (isDefaultNic != null) { profile.setDefaultNic(isDefaultNic); } @@ -1059,6 +1090,36 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return new Pair(vmNic, Integer.valueOf(deviceId)); } + private boolean isNicAllocatedForNsxPublicNetworkOnVR(Network network, NicProfile requested, VirtualMachineProfile vm) { + if (ObjectUtils.anyNull(network, requested, vm)) { + return false; + } + boolean isVirtualRouter = vm.getType() == Type.DomainRouter; + boolean isPublicTraffic = network.getTrafficType() == TrafficType.Public; + if (!isVirtualRouter || !isPublicTraffic || requested.getIPv4Address() == null) { + return false; + } + long dataCenterId = vm.getVirtualMachine().getDataCenterId(); + if (nsxProviderDao.findByZoneId(dataCenterId) == null) { + return false; + } + + Long vpcId = _ipAddressDao.findByIp(requested.getIPv4Address()).getVpcId(); + List ips = _ipAddressDao.listByAssociatedVpc(vpcId, true); + + if (CollectionUtils.isEmpty(ips)) { + return false; + } + ips = ips.stream().filter(x -> !x.getAddress().addr().equals(requested.getIPv4Address())).collect(Collectors.toList()); + IPAddressVO ip = ips.get(0); + VlanDetailsVO vlanDetail = vlanDetailsDao.findDetail(ip.getVlanId(), ApiConstants.NSX_DETAIL_KEY); + if (vlanDetail == null) { + return false; + } + boolean isForNsx = vlanDetail.getValue().equalsIgnoreCase("true"); + return isForNsx && !ip.isForSystemVms(); + } + private void setMtuDetailsInVRNic(final Pair networks, Network network, NicVO vo) { if (TrafficType.Public == network.getTrafficType()) { if (networks == null) { @@ -1370,21 +1431,21 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final SetupPersistentNetworkAnswer answer = (SetupPersistentNetworkAnswer) _agentMgr.send(host.getId(), cmd); if (answer == null) { - s_logger.warn("Unable to get an answer to the SetupPersistentNetworkCommand from agent:" + host.getId()); + logger.warn("Unable to get an answer to the SetupPersistentNetworkCommand from agent:" + host.getId()); clusterToHostsMap.get(host.getClusterId()).remove(host.getId()); continue; } if (!answer.getResult()) { - s_logger.warn("Unable to setup agent " + host.getId() + " due to " + answer.getDetails()); + logger.warn("Unable to setup agent " + host.getId() + " due to " + answer.getDetails()); clusterToHostsMap.get(host.getClusterId()).remove(host.getId()); } } catch (Exception e) { - s_logger.warn("Failed to connect to host: " + host.getName()); + logger.warn("Failed to connect to host: " + host.getName()); } } if (clusterToHostsMap.keySet().size() != clusterVOs.size()) { - s_logger.warn("Hosts on all clusters may not have been configured with network devices."); + logger.warn("Hosts on all clusters may not have been configured with network devices."); } } @@ -1407,7 +1468,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra NetworkVO network = _networksDao.findById(networkId); final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); if (isNetworkImplemented(network)) { - s_logger.debug("Network id=" + networkId + " is already implemented"); + logger.debug("Network id=" + networkId + " is already implemented"); implemented.set(guru, network); return implemented; } @@ -1421,19 +1482,19 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra throw ex; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Lock is acquired for network id " + networkId + " as a part of network implement"); + if (logger.isDebugEnabled()) { + logger.debug("Lock is acquired for network id " + networkId + " as a part of network implement"); } try { if (isNetworkImplemented(network)) { - s_logger.debug("Network id=" + networkId + " is already implemented"); + logger.debug("Network id=" + networkId + " is already implemented"); implemented.set(guru, network); return implemented; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + guru.getName() + " to implement " + network); + if (logger.isDebugEnabled()) { + logger.debug("Asking " + guru.getName() + " to implement " + network); } final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId()); @@ -1471,14 +1532,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra implemented.set(guru, network); return implemented; } catch (final NoTransitionException e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); return new Pair(null, null); } catch (final CloudRuntimeException | OperationTimedoutException e) { - s_logger.error("Caught exception: " + e.getMessage()); + logger.error("Caught exception: " + e.getMessage()); return new Pair(null, null); } finally { if (implemented.first() == null) { - s_logger.debug("Cleaning up because we're unable to implement the network " + network); + logger.debug("Cleaning up because we're unable to implement the network " + network); try { if (isSharedNetworkWithServices(network)) { network.setState(Network.State.Shutdown); @@ -1487,20 +1548,20 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra stateTransitTo(network, Event.OperationFailed); } } catch (final NoTransitionException e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); } try { shutdownNetwork(networkId, context, false); } catch (final Exception e) { // Don't throw this exception as it would hide the original thrown exception, just log - s_logger.error("Exception caught while shutting down a network as part of a failed implementation", e); + logger.error("Exception caught while shutting down a network as part of a failed implementation", e); } } _networksDao.releaseFromLockTable(networkId); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Lock is released for network id " + networkId + " as a part of network implement"); + if (logger.isDebugEnabled()) { + logger.debug("Lock is released for network id " + networkId + " as a part of network implement"); } } } @@ -1526,13 +1587,13 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true); if (ips.isEmpty()) { final Vpc vpc = _vpcMgr.getActiveVpc(network.getVpcId()); - s_logger.debug("Creating a source nat ip for vpc " + vpc); + logger.debug("Creating a source nat ip for vpc " + vpc); _vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc); } } else { ips = _ipAddressDao.listByAssociatedNetwork(network.getId(), true); if (ips.isEmpty()) { - s_logger.debug("Creating a source nat ip for network " + network); + logger.debug("Creating a source nat ip for network " + network); _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network); } } @@ -1557,9 +1618,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { // reapply all the firewall/staticNat/lb rules - s_logger.debug("Reprogramming network " + network + " as a part of network implement"); + logger.debug("Reprogramming network " + network + " as a part of network implement"); if (!reprogramNetworkRules(network.getId(), CallContext.current().getCallingAccount(), network)) { - s_logger.warn("Failed to re-program the network as a part of network " + network + " implement"); + logger.warn("Failed to re-program the network as a part of network " + network + " implement"); // see DataCenterVO.java final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId()); @@ -1569,7 +1630,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra for (final NetworkElement element : networkElements) { if (element instanceof AggregatedCommandExecutor && providersToImplement.contains(element.getProvider())) { if (!((AggregatedCommandExecutor) element).completeAggregatedExecution(network, dest)) { - s_logger.warn("Failed to re-program the network as a part of network " + network + " implement due to aggregated commands execution failure!"); + logger.warn("Failed to re-program the network as a part of network " + network + " implement due to aggregated commands execution failure!"); // see DataCenterVO.java final ResourceUnavailableException ex = new ResourceUnavailableException("Unable to apply network rules as a part of network " + network + " implement", DataCenter.class, network.getDataCenterId()); @@ -1600,8 +1661,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra + network.getPhysicalNetworkId()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + element.getName() + " to implement " + network); + if (logger.isDebugEnabled()) { + logger.debug("Asking " + element.getName() + " to implement " + network); } if (!element.implement(network, offering, dest, context)) { @@ -1627,50 +1688,50 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra _firewallMgr.applyDefaultEgressFirewallRule(network.getId(), offering.isEgressDefaultPolicy(), true); } if (!_firewallMgr.applyFirewallRules(firewallEgressRulesToApply, false, caller)) { - s_logger.warn("Failed to reapply firewall Egress rule(s) as a part of network id=" + networkId + " restart"); + logger.warn("Failed to reapply firewall Egress rule(s) as a part of network id=" + networkId + " restart"); success = false; } // associate all ip addresses if (!_ipAddrMgr.applyIpAssociations(network, false)) { - s_logger.warn("Failed to apply ip addresses as a part of network id" + networkId + " restart"); + logger.warn("Failed to apply ip addresses as a part of network id" + networkId + " restart"); success = false; } // apply static nat if (!_rulesMgr.applyStaticNatsForNetwork(networkId, false, caller)) { - s_logger.warn("Failed to apply static nats a part of network id" + networkId + " restart"); + logger.warn("Failed to apply static nats a part of network id" + networkId + " restart"); success = false; } // apply firewall rules final List firewallIngressRulesToApply = _firewallDao.listByNetworkPurposeTrafficType(networkId, Purpose.Firewall, FirewallRule.TrafficType.Ingress); if (!_firewallMgr.applyFirewallRules(firewallIngressRulesToApply, false, caller)) { - s_logger.warn("Failed to reapply Ingress firewall rule(s) as a part of network id=" + networkId + " restart"); + logger.warn("Failed to reapply Ingress firewall rule(s) as a part of network id=" + networkId + " restart"); success = false; } // apply port forwarding rules if (!_rulesMgr.applyPortForwardingRulesForNetwork(networkId, false, caller)) { - s_logger.warn("Failed to reapply port forwarding rule(s) as a part of network id=" + networkId + " restart"); + logger.warn("Failed to reapply port forwarding rule(s) as a part of network id=" + networkId + " restart"); success = false; } // apply static nat rules if (!_rulesMgr.applyStaticNatRulesForNetwork(networkId, false, caller)) { - s_logger.warn("Failed to reapply static nat rule(s) as a part of network id=" + networkId + " restart"); + logger.warn("Failed to reapply static nat rule(s) as a part of network id=" + networkId + " restart"); success = false; } // apply public load balancer rules if (!_lbMgr.applyLoadBalancersForNetwork(networkId, Scheme.Public)) { - s_logger.warn("Failed to reapply Public load balancer rules as a part of network id=" + networkId + " restart"); + logger.warn("Failed to reapply Public load balancer rules as a part of network id=" + networkId + " restart"); success = false; } // apply internal load balancer rules if (!_lbMgr.applyLoadBalancersForNetwork(networkId, Scheme.Internal)) { - s_logger.warn("Failed to reapply internal load balancer rules as a part of network id=" + networkId + " restart"); + logger.warn("Failed to reapply internal load balancer rules as a part of network id=" + networkId + " restart"); success = false; } @@ -1680,7 +1741,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra for (final RemoteAccessVpn vpn : vpnsToReapply) { // Start remote access vpn per ip if (_vpnMgr.startRemoteAccessVpn(vpn.getServerAddressId(), false) == null) { - s_logger.warn("Failed to reapply vpn rules as a part of network id=" + networkId + " restart"); + logger.warn("Failed to reapply vpn rules as a part of network id=" + networkId + " restart"); success = false; } } @@ -1688,7 +1749,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //apply network ACLs if (!_networkACLMgr.applyACLToNetwork(networkId)) { - s_logger.warn("Failed to reapply network ACLs as a part of of network id=" + networkId + " restart"); + logger.warn("Failed to reapply network ACLs as a part of of network id=" + networkId + " restart"); success = false; } @@ -1785,14 +1846,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra Account caller = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM); long userId = User.UID_SYSTEM; //remove all PF/Static Nat rules for the network - s_logger.info("Services:" + services + " are no longer supported in network:" + network.getUuid() + + logger.info("Services:" + services + " are no longer supported in network:" + network.getUuid() + " after applying new network offering:" + network.getNetworkOfferingId() + " removing the related configuration"); if (services.contains(Service.StaticNat.getName()) || services.contains(Service.PortForwarding.getName())) { try { if (_rulesMgr.revokeAllPFStaticNatRulesForNetwork(networkId, userId, caller)) { - s_logger.debug("Successfully cleaned up portForwarding/staticNat rules for network id=" + networkId); + logger.debug("Successfully cleaned up portForwarding/staticNat rules for network id=" + networkId); } else { - s_logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup"); + logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup"); } if (services.contains(Service.StaticNat.getName())) { //removing static nat configured on ips. @@ -1811,7 +1872,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra }); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); + logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); } } if (services.contains(Service.SourceNat.getName())) { @@ -1830,9 +1891,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (services.contains(Service.Lb.getName())) { //remove all LB rules for the network if (_lbMgr.removeAllLoadBalanacersForNetwork(networkId, caller, userId)) { - s_logger.debug("Successfully cleaned up load balancing rules for network id=" + networkId); + logger.debug("Successfully cleaned up load balancing rules for network id=" + networkId); } else { - s_logger.warn("Failed to cleanup LB rules as a part of network id=" + networkId + " cleanup"); + logger.warn("Failed to cleanup LB rules as a part of network id=" + networkId + " cleanup"); } } @@ -1840,12 +1901,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //revoke all firewall rules for the network try { if (_firewallMgr.revokeAllFirewallRulesForNetwork(networkId, userId, caller)) { - s_logger.debug("Successfully cleaned up firewallRules rules for network id=" + networkId); + logger.debug("Successfully cleaned up firewallRules rules for network id=" + networkId); } else { - s_logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup"); + logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup"); } } catch (ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); + logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); } } @@ -1855,7 +1916,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { _vpnMgr.destroyRemoteAccessVpnForIp(vpn.getServerAddressId(), caller, true); } catch (ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup remote access vpn resources of network:" + network.getUuid() + " due to Exception: ", ex); + logger.warn("Failed to cleanup remote access vpn resources of network:" + network.getUuid() + " due to Exception: ", ex); } } } @@ -1942,10 +2003,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { final UserDataServiceProvider sp = (UserDataServiceProvider) element; if (!sp.saveHypervisorHostname(profile, network, vm, dest)) { - s_logger.error(errorMsg); + logger.error(errorMsg); } } catch (ResourceUnavailableException e) { - s_logger.error(String.format("%s, error states %s", errorMsg, e)); + logger.error(String.format("%s, error states %s", errorMsg, e)); } } } @@ -1959,7 +2020,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra _nicDao.update(nic.getId(), nic); if (nic.getVmType() == VirtualMachine.Type.User) { - s_logger.debug("Changing active number of nics for network id=" + networkId + " on " + count); + logger.debug("Changing active number of nics for network id=" + networkId + " on " + count); _networksDao.changeActiveNicsBy(networkId, count); } @@ -1992,7 +2053,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra for (final NicVO nic : nics) { final Pair implemented = implementNetwork(nic.getNetworkId(), dest, context, vmProfile.getVirtualMachine().getType() == Type.DomainRouter); if (implemented == null || implemented.first() == null) { - s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId()); + logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId()); throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId()); } @@ -2067,8 +2128,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + element.getName() + " to prepare for " + nic); + if (logger.isDebugEnabled()) { + logger.debug("Asking " + element.getName() + " to prepare for " + nic); } if (!prepareElement(element, network, profile, vmProfile, dest, context)) { throw new InsufficientAddressCapacityException("unable to configure the dhcp service, due to insufficiant address capacity", Network.class, network.getId()); @@ -2109,7 +2170,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra _networkModel.getNetworkTag(vm.getHypervisorType(), network)); if (guru instanceof NetworkMigrationResponder) { if (!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)) { - s_logger.error("NetworkGuru " + guru + " prepareForMigration failed."); // XXX: Transaction error + logger.error("NetworkGuru " + guru + " prepareForMigration failed."); // XXX: Transaction error } } @@ -2126,7 +2187,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } if (element instanceof NetworkMigrationResponder) { if (!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)) { - s_logger.error("NetworkElement " + element + " prepareForMigration failed."); // XXX: Transaction error + logger.error("NetworkElement " + element + " prepareForMigration failed."); // XXX: Transaction error } } } @@ -2158,7 +2219,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network)); if (guru instanceof NetworkMigrationResponder) { if (!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)) { - s_logger.error("NetworkGuru " + guru + " prepareForMigration failed."); // XXX: Transaction error + logger.error("NetworkGuru " + guru + " prepareForMigration failed."); // XXX: Transaction error } } final List providersToImplement = getNetworkProviders(network.getId()); @@ -2169,7 +2230,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } if (element instanceof NetworkMigrationResponder) { if (!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)) { - s_logger.error("NetworkElement " + element + " prepareForMigration failed."); // XXX: Transaction error + logger.error("NetworkElement " + element + " prepareForMigration failed."); // XXX: Transaction error } } } @@ -2190,7 +2251,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (nic == null && !addedURIs.contains(broadcastUri.toString())) { //Nic details are not available in DB //Create nic profile for migration - s_logger.debug("Creating nic profile for migration. BroadcastUri: " + broadcastUri.toString() + " NetworkId: " + ntwkId + " Vm: " + vm.getId()); + logger.debug("Creating nic profile for migration. BroadcastUri: " + broadcastUri.toString() + " NetworkId: " + ntwkId + " Vm: " + vm.getId()); final NetworkVO network = _networksDao.findById(ntwkId); final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); final NicProfile profile = new NicProfile(); @@ -2310,12 +2371,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @DB protected void releaseNic(final VirtualMachineProfile vmProfile, final long nicId) throws ConcurrentOperationException, ResourceUnavailableException { - final Pair networkToRelease = Transaction.execute(new TransactionCallback>() { + final Pair networkToRelease = Transaction.execute(new TransactionCallback<>() { @Override public Pair doInTransaction(final TransactionStatus status) { final NicVO nic = _nicDao.lockRow(nicId, true); if (nic == null) { - throw new ConcurrentOperationException("Unable to acquire lock on nic " + nic); + throw new ConcurrentOperationException(String.format("Unable to acquire lock on nic id=%d", nicId)); } final Nic.State originalState = nic.getState(); @@ -2329,6 +2390,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, _networkModel .isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network)); if (guru.release(profile, vmProfile, nic.getReservationId())) { + if (logger.isDebugEnabled()) { + logger.debug(String.format("The nic %s on %s was released according to %s by guru %s, now updating record.", nic, profile, vmProfile, guru)); + } applyProfileToNicForRelease(nic, profile); nic.setState(Nic.State.Allocated); if (originalState == Nic.State.Reserved) { @@ -2338,7 +2402,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } // Perform release on network elements - return new Pair(network, profile); + return new Pair<>(network, profile); } else { nic.setState(Nic.State.Allocated); updateNic(nic, network.getId(), -1); @@ -2367,8 +2431,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final List providersToImplement = getNetworkProviders(network.getId()); for (final NetworkElement element : networkElements) { if (providersToImplement.contains(element.getProvider())) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + element.getName() + " to release " + profile); + if (logger.isDebugEnabled()) { + logger.debug("Asking " + element.getName() + " to release " + profile); } //NOTE: Context appear to never be used in release method //implementations. Consider removing it from interface Element @@ -2380,8 +2444,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @Override public void cleanupNics(final VirtualMachineProfile vm) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cleaning network for vm: " + vm.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Cleaning network for vm: " + vm.getId()); } final List nics = _nicDao.listByVmId(vm.getId()); @@ -2403,7 +2467,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { releaseNic(vm, nic.getId()); } catch (final Exception ex) { - s_logger.warn("Failed to release nic: " + nic.toString() + " as part of remove operation due to", ex); + logger.warn("Failed to release nic: " + nic.toString() + " as part of remove operation due to", ex); } } @@ -2434,15 +2498,15 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final List providersToImplement = getNetworkProviders(network.getId()); for (final NetworkElement element : networkElements) { if (providersToImplement.contains(element.getProvider())) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Asking " + element.getName() + " to release " + nic); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Asking %s to release %s, according to the reservation strategy %s", element.getName(), nic, nic.getReservationStrategy())); } try { element.release(network, profile, vm, null); } catch (final ConcurrentOperationException ex) { - s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex); + logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex); } catch (final ResourceUnavailableException ex) { - s_logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex); + logger.warn("release failed during the nic " + nic.toString() + " removeNic due to ", ex); } } } @@ -2465,11 +2529,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (dnsServiceProvider != null) { try { if (!dnsServiceProvider.removeDnsSupportForSubnet(network)) { - s_logger.warn("Failed to remove the ip alias on the dns server"); + logger.warn("Failed to remove the ip alias on the dns server"); } } catch (final ResourceUnavailableException e) { //failed to remove the dnsconfig. - s_logger.info("Unable to delete the ip alias due to unable to contact the dns server."); + logger.info("Unable to delete the ip alias due to unable to contact the dns server."); } } } @@ -2481,7 +2545,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra _nicDao.remove(nic.getId()); } - s_logger.debug("Removed nic id=" + nic.getId()); + logger.debug("Removed nic id=" + nic.getId()); // release assigned IPv6 for Isolated Network VR NIC if (Type.User.equals(vm.getType()) && GuestType.Isolated.equals(network.getGuestType()) @@ -2494,7 +2558,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //remove the secondary ip addresses corresponding to this nic if (!removeVmSecondaryIpsOfNic(nic.getId())) { - s_logger.debug("Removing nic " + nic.getId() + " secondary ip addresses failed"); + logger.debug("Removing nic " + nic.getId() + " secondary ip addresses failed"); } } @@ -2533,12 +2597,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } }); if (!dhcpServiceProvider.removeDhcpSupportForSubnet(network)) { - s_logger.warn("Failed to remove the ip alias on the router, marking it as removed in db and freed the allocated ip " + ipAlias.getIp4Address()); + logger.warn("Failed to remove the ip alias on the router, marking it as removed in db and freed the allocated ip " + ipAlias.getIp4Address()); } } } catch (final ResourceUnavailableException e) { //failed to remove the dhcpconfig on the router. - s_logger.info("Unable to delete the ip alias due to unable to contact the virtualrouter."); + logger.info("Unable to delete the ip alias due to unable to contact the virtualrouter."); } } @@ -2586,7 +2650,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final DataCenterVO zone = _dcDao.findById(zoneId); // this method supports only guest network creation if (ntwkOff.getTrafficType() != TrafficType.Guest) { - s_logger.warn("Only guest networks can be created using this method"); + logger.warn("Only guest networks can be created using this method"); return null; } @@ -2813,10 +2877,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } // Check if cidr is RFC1918 compliant if the network is Guest Isolated for IPv4 - if (cidr != null && ntwkOff.getGuestType() == Network.GuestType.Isolated && ntwkOff.getTrafficType() == TrafficType.Guest) { - if (!NetUtils.validateGuestCidr(cidr)) { + if (cidr != null && (ntwkOff.getGuestType() == Network.GuestType.Isolated && ntwkOff.getTrafficType() == TrafficType.Guest) && + !NetUtils.validateGuestCidr(cidr, !ConfigurationManager.AllowNonRFC1918CompliantIPs.value())) { throw new InvalidParameterValueException("Virtual Guest Cidr " + cidr + " is not RFC 1918 or 6598 compliant"); - } } final String networkDomainFinal = networkDomain; @@ -3019,12 +3082,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra public boolean shutdownNetwork(final long networkId, final ReservationContext context, final boolean cleanupElements) { NetworkVO network = _networksDao.findById(networkId); if (network.getState() == Network.State.Allocated) { - s_logger.debug("Network is already shutdown: " + network); + logger.debug("Network is already shutdown: " + network); return true; } if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) { - s_logger.debug("Network is not implemented: " + network); + logger.debug("Network is not implemented: " + network); return false; } @@ -3032,20 +3095,20 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //do global lock for the network network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value()); if (network == null) { - s_logger.warn("Unable to acquire lock for the network " + network + " as a part of network shutdown"); + logger.warn("Unable to acquire lock for the network " + network + " as a part of network shutdown"); return false; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Lock is acquired for network " + network + " as a part of network shutdown"); + if (logger.isDebugEnabled()) { + logger.debug("Lock is acquired for network " + network + " as a part of network shutdown"); } if (network.getState() == Network.State.Allocated) { - s_logger.debug("Network is already shutdown: " + network); + logger.debug("Network is already shutdown: " + network); return true; } if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) { - s_logger.debug("Network is not implemented: " + network); + logger.debug("Network is not implemented: " + network); return false; } @@ -3070,8 +3133,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra boolean result = false; if (success) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now."); + if (logger.isDebugEnabled()) { + logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now."); } final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, networkFinal.getGuruName()); final NetworkProfile profile = convertNetworkToNetworkProfile(networkFinal.getId()); @@ -3110,8 +3173,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } finally { if (network != null) { _networksDao.releaseFromLockTable(network.getId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Lock is released for network " + network + " as a part of network shutdown"); + if (logger.isDebugEnabled()) { + logger.debug("Lock is released for network " + network + " as a part of network shutdown"); } } } @@ -3138,11 +3201,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra cleanupResult = shutdownNetworkResources(network.getId(), context.getAccount(), context.getCaller().getId()); } } catch (final Exception ex) { - s_logger.warn("shutdownNetworkRules failed during the network " + network + " shutdown due to ", ex); + logger.warn("shutdownNetworkRules failed during the network " + network + " shutdown due to ", ex); } finally { // just warn the administrator that the network elements failed to shutdown if (!cleanupResult) { - s_logger.warn("Failed to cleanup network id=" + network.getId() + " resources as a part of shutdownNetwork"); + logger.warn("Failed to cleanup network id=" + network.getId() + " resources as a part of shutdownNetwork"); } } @@ -3151,21 +3214,21 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra for (final NetworkElement element : networkElements) { if (providersToShutdown.contains(element.getProvider())) { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending network shutdown to " + element.getName()); + if (logger.isDebugEnabled()) { + logger.debug("Sending network shutdown to " + element.getName()); } if (!element.shutdown(network, context, cleanupElements)) { - s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName()); + logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName()); success = false; } } catch (final ResourceUnavailableException e) { - s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e); + logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e); success = false; } catch (final ConcurrentOperationException e) { - s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e); + logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e); success = false; } catch (final Exception e) { - s_logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e); + logger.warn("Unable to complete shutdown of the network elements due to element: " + element.getName(), e); success = false; } } @@ -3186,15 +3249,15 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra CleanupPersistentNetworkResourceCommand cmd = new CleanupPersistentNetworkResourceCommand(to); CleanupPersistentNetworkResourceAnswer answer = (CleanupPersistentNetworkResourceAnswer) _agentMgr.send(host.getId(), cmd); if (answer == null) { - s_logger.warn("Unable to get an answer to the CleanupPersistentNetworkResourceCommand from agent:" + host.getId()); + logger.warn("Unable to get an answer to the CleanupPersistentNetworkResourceCommand from agent:" + host.getId()); continue; } if (!answer.getResult()) { - s_logger.warn("Unable to setup agent " + host.getId() + " due to " + answer.getDetails()); + logger.warn("Unable to setup agent " + host.getId() + " due to " + answer.getDetails()); } } catch (Exception e) { - s_logger.warn("Failed to cleanup network resources on host: " + host.getName()); + logger.warn("Failed to cleanup network resources on host: " + host.getName()); } } } @@ -3208,7 +3271,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra NetworkVO network = _networksDao.findById(networkId); if (network == null) { - s_logger.debug("Unable to find network with id: " + networkId); + logger.debug("Unable to find network with id: " + networkId); return false; } // Make sure that there are no user vms in the network that are not Expunged/Error @@ -3216,7 +3279,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra for (final UserVmVO vm : userVms) { if (!(vm.getState() == VirtualMachine.State.Expunging && vm.getRemoved() != null)) { - s_logger.warn("Can't delete the network, not all user vms are expunged. Vm " + vm + " is in " + vm.getState() + " state"); + logger.warn("Can't delete the network, not all user vms are expunged. Vm " + vm + " is in " + vm.getState() + " state"); return false; } } @@ -3224,7 +3287,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // Don't allow to delete network via api call when it has vms assigned to it final int nicCount = getActiveNicsInNetwork(networkId); if (nicCount > 0) { - s_logger.debug("The network id=" + networkId + " has active Nics, but shouldn't."); + logger.debug("The network id=" + networkId + " has active Nics, but shouldn't."); // at this point we have already determined that there are no active user vms in network // if the op_networks table shows active nics, it's a bug in releasing nics updating op_networks _networksDao.changeActiveNicsBy(networkId, -1 * nicCount); @@ -3235,7 +3298,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (zone.getNetworkType() == NetworkType.Basic) { final List systemVms = _vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), Type.ConsoleProxy, Type.SecondaryStorageVm); if (systemVms != null && !systemVms.isEmpty()) { - s_logger.warn("Can't delete the network, not all consoleProxy/secondaryStorage vms are expunged"); + logger.warn("Can't delete the network, not all consoleProxy/secondaryStorage vms are expunged"); return false; } } @@ -3248,13 +3311,13 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // get updated state for the network network = _networksDao.findById(networkId); if (network.getState() != Network.State.Allocated && network.getState() != Network.State.Setup && !forced) { - s_logger.debug("Network is not not in the correct state to be destroyed: " + network.getState()); + logger.debug("Network is not in the correct state to be destroyed: " + network.getState()); return false; } boolean success = true; if (!cleanupNetworkResources(networkId, callerAccount, context.getCaller().getId())) { - s_logger.warn("Unable to delete network id=" + networkId + ": failed to cleanup network resources"); + logger.warn("Unable to delete network id=" + networkId + ": failed to cleanup network resources"); return false; } @@ -3263,30 +3326,30 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra for (final NetworkElement element : networkElements) { if (providersToDestroy.contains(element.getProvider())) { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending destroy to " + element); + if (logger.isDebugEnabled()) { + logger.debug("Sending destroy to " + element); } if (!element.destroy(network, context)) { success = false; - s_logger.warn("Unable to complete destroy of the network: failed to destroy network element " + element.getName()); + logger.warn("Unable to complete destroy of the network: failed to destroy network element " + element.getName()); } } catch (final ResourceUnavailableException e) { - s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e); + logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e); success = false; } catch (final ConcurrentOperationException e) { - s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e); + logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e); success = false; } catch (final Exception e) { - s_logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e); + logger.warn("Unable to complete destroy of the network due to element: " + element.getName(), e); success = false; } } } if (success) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Network id=" + networkId + " is destroyed successfully, cleaning up corresponding resources now."); + if (logger.isDebugEnabled()) { + logger.debug("Network id=" + networkId + " is destroyed successfully, cleaning up corresponding resources now."); } final NetworkVO networkFinal = network; @@ -3301,7 +3364,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } if (!deleteVlansInNetwork(networkFinal, context.getCaller().getId(), callerAccount)) { - s_logger.warn("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges"); + logger.warn("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges"); throw new CloudRuntimeException("Failed to delete network " + networkFinal + "; was unable to cleanup corresponding ip ranges"); } else { // commit transaction only when ips and vlans for the network are released successfully @@ -3311,7 +3374,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { stateTransitTo(networkFinal, Event.DestroyNetwork); } catch (final NoTransitionException e) { - s_logger.debug(e.getMessage()); + logger.debug(e.getMessage()); } if (_networksDao.remove(networkFinal.getId())) { final NetworkDomainVO networkDomain = _networkDomainDao.getDomainNetworkMapByNetworkId(networkFinal.getId()); @@ -3343,7 +3406,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } return true; } catch (final CloudRuntimeException e) { - s_logger.error("Failed to delete network", e); + logger.error("Failed to delete network", e); return false; } } @@ -3365,7 +3428,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra boolean result = true; for (final VlanVO vlan : publicVlans) { if (!_configMgr.deleteVlanAndPublicIpRange(userId, vlan.getId(), callerAccount)) { - s_logger.warn("Failed to delete vlan " + vlan.getId() + ");"); + logger.warn("Failed to delete vlan " + vlan.getId() + ");"); result = false; } } @@ -3373,16 +3436,16 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //cleanup private vlans final int privateIpAllocCount = _privateIpDao.countAllocatedByNetworkId(networkId); if (privateIpAllocCount > 0) { - s_logger.warn("Can't delete Private ip range for network " + networkId + " as it has allocated ip addresses"); + logger.warn("Can't delete Private ip range for network " + networkId + " as it has allocated ip addresses"); result = false; } else { _privateIpDao.deleteByNetworkId(networkId); - s_logger.debug("Deleted ip range for private network id=" + networkId); + logger.debug("Deleted ip range for private network id=" + networkId); } // release vlans of user-shared networks without specifyvlan if (isSharedNetworkWithoutSpecifyVlan(_networkOfferingDao.findById(network.getNetworkOfferingId()))) { - s_logger.debug("Releasing vnet for the network id=" + network.getId()); + logger.debug("Releasing vnet for the network id=" + network.getId()); _dcDao.releaseVnet(BroadcastDomainType.getValue(network.getBroadcastUri()), network.getDataCenterId(), network.getPhysicalNetworkId(), network.getAccountId(), network.getReservationId()); } @@ -3414,7 +3477,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final List networkIds = _networksDao.findNetworksToGarbageCollect(); final int netGcWait = NumbersUtil.parseInt(_configDao.getValue(NetworkGcWait.key()), 60); - s_logger.info("NetworkGarbageCollector uses '" + netGcWait + "' seconds for GC interval."); + logger.info("NetworkGarbageCollector uses '" + netGcWait + "' seconds for GC interval."); for (final Long networkId : networkIds) { if (!_networkModel.isNetworkReadyForGc(networkId)) { @@ -3422,19 +3485,19 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } if (!networkDetailsDao.findDetails(Network.AssociatedNetworkId, String.valueOf(networkId), null).isEmpty()) { - s_logger.debug(String.format("Network %s is associated to a shared network, skipping", networkId)); + logger.debug(String.format("Network %s is associated to a shared network, skipping", networkId)); continue; } final Long time = _lastNetworkIdsToFree.remove(networkId); if (time == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("We found network " + networkId + " to be free for the first time. Adding it to the list: " + currentTime); + if (logger.isDebugEnabled()) { + logger.debug("We found network " + networkId + " to be free for the first time. Adding it to the list: " + currentTime); } stillFree.put(networkId, currentTime); } else if (time > currentTime - netGcWait) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Network " + networkId + " is still free but it's not time to shutdown yet: " + time); + if (logger.isDebugEnabled()) { + logger.debug("Network " + networkId + " is still free but it's not time to shutdown yet: " + time); } stillFree.put(networkId, time); } else { @@ -3450,7 +3513,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // If network is removed, unset gc flag for it if (_networksDao.findById(networkId) == null) { - s_logger.debug("Network id=" + networkId + " is removed, so clearing up corresponding gc check"); + logger.debug("Network id=" + networkId + " is removed, so clearing up corresponding gc check"); _networksDao.clearCheckForGc(networkId); } else { try { @@ -3462,12 +3525,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra shutdownNetwork(networkId, context, false); } catch (final Exception e) { - s_logger.warn("Unable to shutdown network: " + networkId); + logger.warn("Unable to shutdown network: " + networkId); } } } } catch (final Exception e) { - s_logger.warn("Caught exception while running network gc: ", e); + logger.warn("Caught exception while running network gc: ", e); } } } @@ -3485,10 +3548,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } // implement the network - s_logger.debug("Starting network " + network + "..."); + logger.debug("Starting network " + network + "..."); final Pair implementedNetwork = implementNetwork(networkId, dest, context); if (implementedNetwork == null || implementedNetwork.first() == null) { - s_logger.warn("Failed to start the network " + network); + logger.warn("Failed to start the network " + network); return false; } else { return true; @@ -3502,7 +3565,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra boolean restartRequired = false; final NetworkVO network = _networksDao.findById(networkId); - s_logger.debug("Restarting network " + networkId + "..."); + logger.debug("Restarting network " + networkId + "..."); final ReservationContext context = new ReservationContextImpl(null, null, callerUser, callerAccount); final NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId()); @@ -3526,12 +3589,12 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { VMInstanceVO instanceVO = _vmDao.findById(router.getId()); if (instanceVO == null) { - s_logger.info("Did not find a virtual router instance for the network"); + logger.info("Did not find a virtual router instance for the network"); continue; } Pair patched = mgr.updateSystemVM(instanceVO, true); if (patched.first()) { - s_logger.info(String.format("Successfully patched router %s", router)); + logger.info(String.format("Successfully patched router %s", router)); } } catch (CloudRuntimeException e) { throw new CloudRuntimeException(String.format("Failed to live patch router: %s", router), e); @@ -3540,13 +3603,13 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } - s_logger.debug("Implementing the network " + network + " elements and resources as a part of network restart without cleanup"); + logger.debug("Implementing the network " + network + " elements and resources as a part of network restart without cleanup"); try { implementNetworkElementsAndResources(dest, context, network, offering); setRestartRequired(network, false); return true; } catch (final Exception ex) { - s_logger.warn("Failed to implement network " + network + " elements and resources as a part of network restart due to ", ex); + logger.warn("Failed to implement network " + network + " elements and resources as a part of network restart due to ", ex); return false; } } @@ -3559,7 +3622,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra router.getState() == VirtualMachine.State.Error || router.getState() == VirtualMachine.State.Shutdown || router.getState() == VirtualMachine.State.Unknown) { - s_logger.debug("Destroying old router " + router); + logger.debug("Destroying old router " + router); _routerService.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()); } else { remainingRouters.add(router); @@ -3588,7 +3651,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra public boolean areRoutersRunning(final List routers) { for (final VirtualRouter router : routers) { if (router.getState() != VirtualMachine.State.Running) { - s_logger.debug("Found new router " + router.getInstanceName() + " to be in non-Running state: " + router.getState() + ". Please try restarting network again."); + logger.debug("Found new router " + router.getInstanceName() + " to be in non-Running state: " + router.getState() + ". Please try restarting network again."); return false; } } @@ -3615,7 +3678,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { sp.removeDhcpEntry(network, nicProfile, vmProfile); } catch (ResourceUnavailableException e) { - s_logger.error("Failed to remove dhcp-dns entry due to: ", e); + logger.error("Failed to remove dhcp-dns entry due to: ", e); } } } @@ -3643,10 +3706,10 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra implementNetworkElementsAndResources(dest, context, network, offering); return true; } - s_logger.debug("Failed to shutdown the network elements and resources as a part of network restart: " + network.getState()); + logger.debug("Failed to shutdown the network elements and resources as a part of network restart: " + network.getState()); return false; } - s_logger.debug("Performing rolling restart of routers of network " + network); + logger.debug("Performing rolling restart of routers of network " + network); destroyExpendableRouters(routerDao.findByNetwork(network.getId()), context); final List providersToImplement = getNetworkProviders(network.getId()); @@ -3687,7 +3750,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } private void setRestartRequired(final NetworkVO network, final boolean restartRequired) { - s_logger.debug("Marking network " + network + " with restartRequired=" + restartRequired); + logger.debug("Marking network " + network + " with restartRequired=" + restartRequired); network.setRestartRequired(restartRequired); _networksDao.update(network.getId(), network); } @@ -3711,7 +3774,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final String passwordProvider = _ntwkSrvcDao.getProviderForServiceInNetwork(network.getId(), Service.UserData); if (passwordProvider == null) { - s_logger.debug("Network " + network + " doesn't support service " + Service.UserData.getName()); + logger.debug("Network " + network + " doesn't support service " + Service.UserData.getName()); return null; } @@ -3723,7 +3786,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final String SSHKeyProvider = _ntwkSrvcDao.getProviderForServiceInNetwork(network.getId(), Service.UserData); if (SSHKeyProvider == null) { - s_logger.debug("Network " + network + " doesn't support service " + Service.UserData.getName()); + logger.debug("Network " + network + " doesn't support service " + Service.UserData.getName()); return null; } @@ -3735,7 +3798,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final String DhcpProvider = _ntwkSrvcDao.getProviderForServiceInNetwork(network.getId(), Service.Dhcp); if (DhcpProvider == null) { - s_logger.debug("Network " + network + " doesn't support service " + Service.Dhcp.getName()); + logger.debug("Network " + network + " doesn't support service " + Service.Dhcp.getName()); return null; } @@ -3752,7 +3815,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final String dnsProvider = _ntwkSrvcDao.getProviderForServiceInNetwork(network.getId(), Service.Dns); if (dnsProvider == null) { - s_logger.debug("Network " + network + " doesn't support service " + Service.Dhcp.getName()); + logger.debug("Network " + network + " doesn't support service " + Service.Dhcp.getName()); return null; } @@ -3799,7 +3862,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra for (final NicVO nic : result) { if (_networkModel.isProviderForNetwork(Provider.NiciraNvp, nic.getNetworkId())) { //For NSX Based networks, add nsxlogicalswitch, nsxlogicalswitchport to each result - s_logger.info("Listing NSX logical switch and logical switch por for each nic"); + logger.info("Listing NSX logical switch and logical switch por for each nic"); final NetworkVO network = _networksDao.findById(nic.getNetworkId()); final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName()); final NetworkGuruAdditionalFunctions guruFunctions = (NetworkGuruAdditionalFunctions) guru; @@ -3843,56 +3906,57 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra private boolean cleanupNetworkResources(final long networkId, final Account caller, final long callerUserId) { boolean success = true; - final Network network = _networksDao.findById(networkId); + final NetworkVO network = _networksDao.findById(networkId); + final NetworkOfferingVO networkOffering= _networkOfferingDao.findById(network.getNetworkOfferingId()); //remove all PF/Static Nat rules for the network try { if (_rulesMgr.revokeAllPFStaticNatRulesForNetwork(networkId, callerUserId, caller)) { - s_logger.debug("Successfully cleaned up portForwarding/staticNat rules for network id=" + networkId); + logger.debug("Successfully cleaned up portForwarding/staticNat rules for network id=" + networkId); } else { success = false; - s_logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup"); + logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup"); } } catch (final ResourceUnavailableException ex) { success = false; // shouldn't even come here as network is being cleaned up after all network elements are shutdown - s_logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); + logger.warn("Failed to release portForwarding/StaticNat rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); } //remove all LB rules for the network if (_lbMgr.removeAllLoadBalanacersForNetwork(networkId, caller, callerUserId)) { - s_logger.debug("Successfully cleaned up load balancing rules for network id=" + networkId); + logger.debug("Successfully cleaned up load balancing rules for network id=" + networkId); } else { // shouldn't even come here as network is being cleaned up after all network elements are shutdown success = false; - s_logger.warn("Failed to cleanup LB rules as a part of network id=" + networkId + " cleanup"); + logger.warn("Failed to cleanup LB rules as a part of network id=" + networkId + " cleanup"); } //revoke all firewall rules for the network try { if (_firewallMgr.revokeAllFirewallRulesForNetwork(networkId, callerUserId, caller)) { - s_logger.debug("Successfully cleaned up firewallRules rules for network id=" + networkId); + logger.debug("Successfully cleaned up firewallRules rules for network id=" + networkId); } else { success = false; - s_logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup"); + logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup"); } } catch (final ResourceUnavailableException ex) { success = false; // shouldn't even come here as network is being cleaned up after all network elements are shutdown - s_logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); + logger.warn("Failed to cleanup Firewall rules as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); } //revoke all network ACLs for network try { if (_networkACLMgr.revokeACLItemsForNetwork(networkId)) { - s_logger.debug("Successfully cleaned up NetworkACLs for network id=" + networkId); + logger.debug("Successfully cleaned up NetworkACLs for network id=" + networkId); } else { success = false; - s_logger.warn("Failed to cleanup NetworkACLs as a part of network id=" + networkId + " cleanup"); + logger.warn("Failed to cleanup NetworkACLs as a part of network id=" + networkId + " cleanup"); } } catch (final ResourceUnavailableException ex) { success = false; - s_logger.warn("Failed to cleanup Network ACLs as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); + logger.warn("Failed to cleanup Network ACLs as a part of network id=" + networkId + " cleanup due to resourceUnavailable ", ex); } //release all ip addresses @@ -3907,7 +3971,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // so as part of network clean up just break IP association with guest network ipToRelease.setAssociatedWithNetworkId(null); _ipAddressDao.update(ipToRelease.getId(), ipToRelease); - s_logger.debug("Portable IP address " + ipToRelease + " is no longer associated with any network"); + logger.debug("Portable IP address " + ipToRelease + " is no longer associated with any network"); } } else { _vpcMgr.unassignIPFromVpcNetwork(ipToRelease.getId(), network.getId()); @@ -3916,7 +3980,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { if (!_ipAddrMgr.applyIpAssociations(network, true)) { - s_logger.warn("Unable to apply ip address associations for " + network); + logger.warn("Unable to apply ip address associations for " + network); success = false; } } catch (final ResourceUnavailableException e) { @@ -3935,34 +3999,34 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra // Mark all PF rules as revoked and apply them on the backend (not in the DB) final List pfRules = _portForwardingRulesDao.listByNetwork(networkId); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing " + pfRules.size() + " port forwarding rules for network id=" + networkId + " as a part of shutdownNetworkRules"); + if (logger.isDebugEnabled()) { + logger.debug("Releasing " + pfRules.size() + " port forwarding rules for network id=" + networkId + " as a part of shutdownNetworkRules"); } for (final PortForwardingRuleVO pfRule : pfRules) { - s_logger.trace("Marking pf rule " + pfRule + " with Revoke state"); + logger.trace("Marking pf rule " + pfRule + " with Revoke state"); pfRule.setState(FirewallRule.State.Revoke); } try { if (!_firewallMgr.applyRules(pfRules, true, false)) { - s_logger.warn("Failed to cleanup pf rules as a part of shutdownNetworkRules"); + logger.warn("Failed to cleanup pf rules as a part of shutdownNetworkRules"); success = false; } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup pf rules as a part of shutdownNetworkRules due to ", ex); + logger.warn("Failed to cleanup pf rules as a part of shutdownNetworkRules due to ", ex); success = false; } // Mark all static rules as revoked and apply them on the backend (not in the DB) final List firewallStaticNatRules = _firewallDao.listByNetworkAndPurpose(networkId, Purpose.StaticNat); final List staticNatRules = new ArrayList(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing " + firewallStaticNatRules.size() + " static nat rules for network id=" + networkId + " as a part of shutdownNetworkRules"); + if (logger.isDebugEnabled()) { + logger.debug("Releasing " + firewallStaticNatRules.size() + " static nat rules for network id=" + networkId + " as a part of shutdownNetworkRules"); } for (final FirewallRuleVO firewallStaticNatRule : firewallStaticNatRules) { - s_logger.trace("Marking static nat rule " + firewallStaticNatRule + " with Revoke state"); + logger.trace("Marking static nat rule " + firewallStaticNatRule + " with Revoke state"); final IpAddress ip = _ipAddressDao.findById(firewallStaticNatRule.getSourceIpAddressId()); final FirewallRuleVO ruleVO = _firewallDao.findById(firewallStaticNatRule.getId()); @@ -3977,58 +4041,58 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { if (!_firewallMgr.applyRules(staticNatRules, true, false)) { - s_logger.warn("Failed to cleanup static nat rules as a part of shutdownNetworkRules"); + logger.warn("Failed to cleanup static nat rules as a part of shutdownNetworkRules"); success = false; } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup static nat rules as a part of shutdownNetworkRules due to ", ex); + logger.warn("Failed to cleanup static nat rules as a part of shutdownNetworkRules due to ", ex); success = false; } try { if (!_lbMgr.revokeLoadBalancersForNetwork(networkId, Scheme.Public)) { - s_logger.warn("Failed to cleanup public lb rules as a part of shutdownNetworkRules"); + logger.warn("Failed to cleanup public lb rules as a part of shutdownNetworkRules"); success = false; } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup public lb rules as a part of shutdownNetworkRules due to ", ex); + logger.warn("Failed to cleanup public lb rules as a part of shutdownNetworkRules due to ", ex); success = false; } try { if (!_lbMgr.revokeLoadBalancersForNetwork(networkId, Scheme.Internal)) { - s_logger.warn("Failed to cleanup internal lb rules as a part of shutdownNetworkRules"); + logger.warn("Failed to cleanup internal lb rules as a part of shutdownNetworkRules"); success = false; } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup public lb rules as a part of shutdownNetworkRules due to ", ex); + logger.warn("Failed to cleanup public lb rules as a part of shutdownNetworkRules due to ", ex); success = false; } // revoke all firewall rules for the network w/o applying them on the DB final List firewallRules = _firewallDao.listByNetworkPurposeTrafficType(networkId, Purpose.Firewall, FirewallRule.TrafficType.Ingress); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing " + firewallRules.size() + " firewall ingress rules for network id=" + networkId + " as a part of shutdownNetworkRules"); + if (logger.isDebugEnabled()) { + logger.debug("Releasing " + firewallRules.size() + " firewall ingress rules for network id=" + networkId + " as a part of shutdownNetworkRules"); } for (final FirewallRuleVO firewallRule : firewallRules) { - s_logger.trace("Marking firewall ingress rule " + firewallRule + " with Revoke state"); + logger.trace("Marking firewall ingress rule " + firewallRule + " with Revoke state"); firewallRule.setState(FirewallRule.State.Revoke); } try { if (!_firewallMgr.applyRules(firewallRules, true, false)) { - s_logger.warn("Failed to cleanup firewall ingress rules as a part of shutdownNetworkRules"); + logger.warn("Failed to cleanup firewall ingress rules as a part of shutdownNetworkRules"); success = false; } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup firewall ingress rules as a part of shutdownNetworkRules due to ", ex); + logger.warn("Failed to cleanup firewall ingress rules as a part of shutdownNetworkRules due to ", ex); success = false; } final List firewallEgressRules = _firewallDao.listByNetworkPurposeTrafficType(networkId, Purpose.Firewall, FirewallRule.TrafficType.Egress); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing " + firewallEgressRules.size() + " firewall egress rules for network id=" + networkId + " as a part of shutdownNetworkRules"); + if (logger.isDebugEnabled()) { + logger.debug("Releasing " + firewallEgressRules.size() + " firewall egress rules for network id=" + networkId + " as a part of shutdownNetworkRules"); } try { @@ -4041,38 +4105,38 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup firewall default egress rule as a part of shutdownNetworkRules due to ", ex); + logger.warn("Failed to cleanup firewall default egress rule as a part of shutdownNetworkRules due to ", ex); success = false; } for (final FirewallRuleVO firewallRule : firewallEgressRules) { - s_logger.trace("Marking firewall egress rule " + firewallRule + " with Revoke state"); + logger.trace("Marking firewall egress rule " + firewallRule + " with Revoke state"); firewallRule.setState(FirewallRule.State.Revoke); } try { if (!_firewallMgr.applyRules(firewallEgressRules, true, false)) { - s_logger.warn("Failed to cleanup firewall egress rules as a part of shutdownNetworkRules"); + logger.warn("Failed to cleanup firewall egress rules as a part of shutdownNetworkRules"); success = false; } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup firewall egress rules as a part of shutdownNetworkRules due to ", ex); + logger.warn("Failed to cleanup firewall egress rules as a part of shutdownNetworkRules due to ", ex); success = false; } if (network.getVpcId() != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing Network ACL Items for network id=" + networkId + " as a part of shutdownNetworkRules"); + if (logger.isDebugEnabled()) { + logger.debug("Releasing Network ACL Items for network id=" + networkId + " as a part of shutdownNetworkRules"); } try { //revoke all Network ACLs for the network w/o applying them in the DB if (!_networkACLMgr.revokeACLItemsForNetwork(networkId)) { - s_logger.warn("Failed to cleanup network ACLs as a part of shutdownNetworkRules"); + logger.warn("Failed to cleanup network ACLs as a part of shutdownNetworkRules"); success = false; } } catch (final ResourceUnavailableException ex) { - s_logger.warn("Failed to cleanup network ACLs as a part of shutdownNetworkRules due to ", ex); + logger.warn("Failed to cleanup network ACLs as a part of shutdownNetworkRules due to ", ex); success = false; } @@ -4080,7 +4144,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra //release all static nats for the network if (!_rulesMgr.applyStaticNatForNetwork(networkId, false, caller, true)) { - s_logger.warn("Failed to disable static nats as part of shutdownNetworkRules for network id " + networkId); + logger.warn("Failed to disable static nats as part of shutdownNetworkRules for network id " + networkId); success = false; } @@ -4097,7 +4161,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra try { if (!_ipAddrMgr.applyIpAssociations(network, true, true, publicIpsToRelease)) { - s_logger.warn("Unable to apply ip address associations for " + network + " as a part of shutdownNetworkRules"); + logger.warn("Unable to apply ip address associations for " + network + " as a part of shutdownNetworkRules"); success = false; } } catch (final ResourceUnavailableException e) { @@ -4150,8 +4214,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra dcId = dc.getId(); final HypervisorType hypervisorType = startup.getHypervisorType(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Host's hypervisorType is: " + hypervisorType); + if (logger.isDebugEnabled()) { + logger.debug("Host's hypervisorType is: " + hypervisorType); } final List networkInfoList = new ArrayList(); @@ -4179,20 +4243,20 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra } // send the names to the agent - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending CheckNetworkCommand to check the Network is setup correctly on Agent"); + if (logger.isDebugEnabled()) { + logger.debug("Sending CheckNetworkCommand to check the Network is setup correctly on Agent"); } final CheckNetworkCommand nwCmd = new CheckNetworkCommand(networkInfoList); final CheckNetworkAnswer answer = (CheckNetworkAnswer) _agentMgr.easySend(hostId, nwCmd); if (answer == null) { - s_logger.warn("Unable to get an answer to the CheckNetworkCommand from agent:" + host.getId()); + logger.warn("Unable to get an answer to the CheckNetworkCommand from agent:" + host.getId()); throw new ConnectionException(true, "Unable to get an answer to the CheckNetworkCommand from agent: " + host.getId()); } if (!answer.getResult()) { - s_logger.warn("Unable to setup agent " + hostId + " due to " + answer.getDetails()); + logger.warn("Unable to setup agent " + hostId + " due to " + answer.getDetails()); final String msg = "Incorrect Network setup on agent, Reinitialize agent after network names are setup, details : " + answer.getDetails(); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, host.getPodId(), msg, msg); throw new ConnectionException(true, msg); @@ -4200,8 +4264,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra if (answer.needReconnect()) { throw new ConnectionException(false, "Reinitialize agent after network setup."); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Network setup is correct on Agent"); + if (logger.isDebugEnabled()) { + logger.debug("Network setup is correct on Agent"); } return; } @@ -4343,18 +4407,18 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final VMNetworkMapVO vno = new VMNetworkMapVO(vm.getId(), network.getId()); _vmNetworkMapDao.persist(vno); } - s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); + logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network); } //2) prepare nic if (prepare) { final Pair implemented = implementNetwork(nic.getNetworkId(), dest, context, vmProfile.getVirtualMachine().getType() == Type.DomainRouter); if (implemented == null || implemented.first() == null) { - s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId()); + logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId()); throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId()); } nic = prepareNic(vmProfile, dest, context, nic.getId(), implemented.second()); - s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); + logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network); } return nic; @@ -4362,11 +4426,11 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra private boolean getNicProfileDefaultNic(NicProfile nicProfile) { if (nicProfile != null) { - s_logger.debug(String.format("Using requested nic profile isDefaultNic value [%s].", nicProfile.isDefaultNic())); + logger.debug(String.format("Using requested nic profile isDefaultNic value [%s].", nicProfile.isDefaultNic())); return nicProfile.isDefaultNic(); } - s_logger.debug("Using isDefaultNic default value [false] as requested nic profile is null."); + logger.debug("Using isDefaultNic default value [false] as requested nic profile is null."); return false; } @@ -4424,7 +4488,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return accessDetails; } - protected boolean stateTransitTo(final NetworkVO network, final Network.Event e) throws NoTransitionException { + @Override + public boolean stateTransitTo(final Network network, final Network.Event e) throws NoTransitionException { return _stateMachine.transitTo(network, e, null, _networksDao); } @@ -4461,18 +4526,18 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra final List providers = getProvidersForServiceInNetwork(network, service); //Only support one provider now if (providers == null) { - s_logger.error("Cannot find " + service.getName() + " provider for network " + network.getId()); + logger.error("Cannot find " + service.getName() + " provider for network " + network.getId()); return null; } if (providers.size() != 1 && service != Service.Lb) { //support more than one LB providers only - s_logger.error("Found " + providers.size() + " " + service.getName() + " providers for network!" + network.getId()); + logger.error("Found " + providers.size() + " " + service.getName() + " providers for network!" + network.getId()); return null; } for (final Provider provider : providers) { final NetworkElement element = _networkModel.getElementImplementingProvider(provider.getName()); - s_logger.info("Let " + element.getName() + " handle " + service.getName() + " in network " + network.getId()); + logger.info("Let " + element.getName() + " handle " + service.getName() + " in network " + network.getId()); elements.add(element); } return elements; @@ -4533,7 +4598,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra for (final NicSecondaryIpVO ip : ipList) { _nicSecondaryIpDao.remove(ip.getId()); } - s_logger.debug("Revoving nic secondary ip entry ..."); + logger.debug("Revoving nic secondary ip entry ..."); } } }); @@ -4564,25 +4629,21 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra @DB @Override - public Pair importNic(final String macAddress, int deviceId, final Network network, final Boolean isDefaultNic, final VirtualMachine vm, final Network.IpAddresses ipAddresses, final boolean forced) + public Pair importNic(final String macAddress, int deviceId, final Network network, final Boolean isDefaultNic, final VirtualMachine vm, final Network.IpAddresses ipAddresses, final DataCenter dataCenter, final boolean forced) throws ConcurrentOperationException, InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { - s_logger.debug("Allocating nic for vm " + vm.getUuid() + " in network " + network + " during import"); - String guestIp = null; + logger.debug("Allocating nic for vm " + vm.getUuid() + " in network " + network + " during import"); + String selectedIp = null; if (ipAddresses != null && StringUtils.isNotEmpty(ipAddresses.getIp4Address())) { if (ipAddresses.getIp4Address().equals("auto")) { ipAddresses.setIp4Address(null); } - if (network.getGuestType() != GuestType.L2) { - guestIp = _ipAddrMgr.acquireGuestIpAddress(network, ipAddresses.getIp4Address()); - } else { - guestIp = null; - } - if (guestIp == null && network.getGuestType() != GuestType.L2 && !_networkModel.listNetworkOfferingServices(network.getNetworkOfferingId()).isEmpty()) { + selectedIp = getSelectedIpForNicImport(network, dataCenter, ipAddresses); + if (selectedIp == null && network.getGuestType() != GuestType.L2 && !_networkModel.listNetworkOfferingServices(network.getNetworkOfferingId()).isEmpty()) { throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Guest IP address for network " + network, DataCenter.class, network.getDataCenterId()); } } - final String finalGuestIp = guestIp; + final String finalSelectedIp = selectedIp; final NicVO vo = Transaction.execute(new TransactionCallback() { @Override public NicVO doInTransaction(TransactionStatus status) { @@ -4594,12 +4655,13 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra NicVO vo = new NicVO(network.getGuruName(), vm.getId(), network.getId(), vm.getType()); vo.setMacAddress(macAddressToPersist); vo.setAddressFormat(Networks.AddressFormat.Ip4); - if (NetUtils.isValidIp4(finalGuestIp) && StringUtils.isNotEmpty(network.getGateway())) { - vo.setIPv4Address(finalGuestIp); - vo.setIPv4Gateway(network.getGateway()); - if (StringUtils.isNotEmpty(network.getCidr())) { - vo.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr())); - } + Pair pair = getNetworkGatewayAndNetmaskForNicImport(network, dataCenter, finalSelectedIp); + String gateway = pair.first(); + String netmask = pair.second(); + if (NetUtils.isValidIp4(finalSelectedIp) && StringUtils.isNotEmpty(gateway)) { + vo.setIPv4Address(finalSelectedIp); + vo.setIPv4Gateway(gateway); + vo.setIPv4Netmask(netmask); } vo.setBroadcastUri(network.getBroadcastUri()); vo.setMode(network.getMode()); @@ -4613,7 +4675,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra int count = 1; if (vo.getVmType() == VirtualMachine.Type.User) { - s_logger.debug("Changing active number of nics for network id=" + network.getUuid() + " on " + count); + logger.debug("Changing active number of nics for network id=" + network.getUuid() + " on " + count); _networksDao.changeActiveNicsBy(network.getId(), count); } if (vo.getVmType() == VirtualMachine.Type.User @@ -4636,27 +4698,66 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return new Pair(vmNic, Integer.valueOf(deviceId)); } + protected String getSelectedIpForNicImport(Network network, DataCenter dataCenter, Network.IpAddresses ipAddresses) { + if (network.getGuestType() == GuestType.L2) { + return null; + } + return dataCenter.getNetworkType() == NetworkType.Basic ? + getSelectedIpForNicImportOnBasicZone(ipAddresses.getIp4Address(), network, dataCenter): + _ipAddrMgr.acquireGuestIpAddress(network, ipAddresses.getIp4Address()); + } + + protected String getSelectedIpForNicImportOnBasicZone(String requestedIp, Network network, DataCenter dataCenter) { + IPAddressVO ipAddressVO = StringUtils.isBlank(requestedIp) ? + _ipAddressDao.findBySourceNetworkIdAndDatacenterIdAndState(network.getId(), dataCenter.getId(), IpAddress.State.Free): + _ipAddressDao.findByIp(requestedIp); + if (ipAddressVO == null || ipAddressVO.getState() != IpAddress.State.Free) { + String msg = String.format("Cannot find a free IP to assign to VM NIC on network %s", network.getName()); + logger.error(msg); + throw new CloudRuntimeException(msg); + } + return ipAddressVO.getAddress() != null ? ipAddressVO.getAddress().addr() : null; + } + + /** + * Obtain the gateway and netmask for a VM NIC to import + * If the VM to import is on a Basic Zone, then obtain the information from the vlan table instead of the network + */ + protected Pair getNetworkGatewayAndNetmaskForNicImport(Network network, DataCenter dataCenter, String selectedIp) { + String gateway = network.getGateway(); + String netmask = StringUtils.isNotEmpty(network.getCidr()) ? NetUtils.cidr2Netmask(network.getCidr()) : null; + if (dataCenter.getNetworkType() == NetworkType.Basic) { + IPAddressVO freeIp = _ipAddressDao.findByIp(selectedIp); + if (freeIp != null) { + VlanVO vlan = _vlanDao.findById(freeIp.getVlanId()); + gateway = vlan != null ? vlan.getVlanGateway() : null; + netmask = vlan != null ? vlan.getVlanNetmask() : null; + } + } + return new Pair<>(gateway, netmask); + } + private String generateNewMacAddressIfForced(Network network, String macAddress, boolean forced) { if (!forced) { throw new CloudRuntimeException("NIC with MAC address = " + macAddress + " exists on network with ID = " + network.getId() + " and forced flag is disabled"); } try { - s_logger.debug(String.format("Generating a new mac address on network %s as the mac address %s already exists", network.getName(), macAddress)); + logger.debug(String.format("Generating a new mac address on network %s as the mac address %s already exists", network.getName(), macAddress)); String newMacAddress = _networkModel.getNextAvailableMacAddressInNetwork(network.getId()); - s_logger.debug(String.format("Successfully generated the mac address %s, using it instead of the conflicting address %s", newMacAddress, macAddress)); + logger.debug(String.format("Successfully generated the mac address %s, using it instead of the conflicting address %s", newMacAddress, macAddress)); return newMacAddress; } catch (InsufficientAddressCapacityException e) { String msg = String.format("Could not generate a new mac address on network %s", network.getName()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } @Override public void unmanageNics(VirtualMachineProfile vm) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unmanaging NICs for VM: " + vm.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Unmanaging NICs for VM: " + vm.getId()); } VirtualMachine virtualMachine = vm.getVirtualMachine(); @@ -4686,6 +4787,6 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra return new ConfigKey[]{NetworkGcWait, NetworkGcInterval, NetworkLockTimeout, GuestDomainSuffix, NetworkThrottlingRate, MinVRVersion, PromiscuousMode, MacAddressChanges, ForgedTransmits, MacLearning, RollingRestartEnabled, - TUNGSTEN_ENABLED }; + TUNGSTEN_ENABLED, NSX_ENABLED }; } } diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/StorageOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/StorageOrchestrator.java index 873ddb5d80b..1faf46361c6 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/StorageOrchestrator.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/StorageOrchestrator.java @@ -59,7 +59,6 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.math3.stat.descriptive.moment.Mean; import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; -import org.apache.log4j.Logger; import com.cloud.capacity.CapacityManager; import com.cloud.server.StatsCollector; @@ -75,7 +74,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class StorageOrchestrator extends ManagerBase implements StorageOrchestrationService, Configurable { - private static final Logger s_logger = Logger.getLogger(StorageOrchestrator.class); @Inject SnapshotDataStoreDao snapshotDataStoreDao; @Inject @@ -161,7 +159,7 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra } storageCapacities.put(srcDataStoreId, new Pair<>(null, null)); if (migrationPolicy == MigrationPolicy.COMPLETE) { - s_logger.debug(String.format("Setting source image store: %s to read-only", srcDatastore.getId())); + logger.debug(String.format("Setting source image store: %s to read-only", srcDatastore.getId())); storageService.updateImageStoreStatus(srcDataStoreId, true); } @@ -173,7 +171,7 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra TimeUnit.MINUTES, new MigrateBlockingQueue<>(numConcurrentCopyTasksPerSSVM)); Date start = new Date(); if (meanstddev < threshold && migrationPolicy == MigrationPolicy.BALANCE) { - s_logger.debug("mean std deviation of the image stores is below threshold, no migration required"); + logger.debug("mean std deviation of the image stores is below threshold, no migration required"); response = new MigrationResponse("Migration not required as system seems balanced", migrationPolicy.toString(), true); return response; } @@ -202,7 +200,7 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra } if (chosenFileForMigration.getPhysicalSize() > storageCapacities.get(destDatastoreId).first()) { - s_logger.debug(String.format("%s: %s too large to be migrated to %s", chosenFileForMigration.getType().name() , chosenFileForMigration.getUuid(), destDatastoreId)); + logger.debug(String.format("%s: %s too large to be migrated to %s", chosenFileForMigration.getType().name() , chosenFileForMigration.getUuid(), destDatastoreId)); skipped += 1; continue; } @@ -269,7 +267,7 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra } if (chosenFileForMigration.getPhysicalSize() > storageCapacities.get(destImgStoreId).first()) { - s_logger.debug(String.format("%s: %s too large to be migrated to %s", chosenFileForMigration.getType().name(), chosenFileForMigration.getUuid(), destImgStoreId)); + logger.debug(String.format("%s: %s too large to be migrated to %s", chosenFileForMigration.getType().name(), chosenFileForMigration.getUuid(), destImgStoreId)); continue; } @@ -304,7 +302,7 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra boolean success = true; if (destDatastoreId == srcDatastore.getId() && !files.isEmpty()) { if (migrationPolicy == MigrationPolicy.BALANCE) { - s_logger.debug("Migration completed : data stores have been balanced "); + logger.debug("Migration completed : data stores have been balanced "); if (destDatastoreId == srcDatastore.getId()) { message = "Seems like source datastore has more free capacity than the destination(s)"; } @@ -355,7 +353,7 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra task.setTemplateChain(templateChains); } futures.add((executor.submit(task))); - s_logger.debug(String.format("Migration of %s: %s is initiated. ", chosenFileForMigration.getType().name(), chosenFileForMigration.getUuid())); + logger.debug(String.format("Migration of %s: %s is initiated. ", chosenFileForMigration.getType().name(), chosenFileForMigration.getUuid())); return storageCapacities; } @@ -370,7 +368,7 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra successCount++; } } catch ( InterruptedException | ExecutionException e) { - s_logger.warn("Failed to get result"); + logger.warn("Failed to get result"); continue; } } @@ -492,7 +490,7 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra double meanStdDevAfter = getStandardDeviation(proposedCapacities); if (meanStdDevAfter > meanStdDevCurrent) { - s_logger.debug("migrating the file doesn't prove to be beneficial, skipping migration"); + logger.debug("migrating the file doesn't prove to be beneficial, skipping migration"); return false; } @@ -512,10 +510,10 @@ public class StorageOrchestrator extends ManagerBase implements StorageOrchestra Pair imageStoreCapacity = storageCapacities.get(destStoreId); long usedCapacity = imageStoreCapacity.second() - imageStoreCapacity.first(); if (imageStoreCapacity != null && (usedCapacity / (imageStoreCapacity.second() * 1.0)) <= CapacityManager.SecondaryStorageCapacityThreshold.value()) { - s_logger.debug("image store: " + destStoreId + " has sufficient capacity to proceed with migration of file"); + logger.debug("image store: " + destStoreId + " has sufficient capacity to proceed with migration of file"); return true; } - s_logger.debug("Image store capacity threshold exceeded, migration not possible"); + logger.debug("Image store capacity threshold exceeded, migration not possible"); return false; } diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index b8f3e5a10e5..e90258311de 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -86,7 +86,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; import com.cloud.agent.api.to.DataTO; @@ -131,6 +130,7 @@ import com.cloud.storage.Volume.Type; import com.cloud.storage.VolumeApiService; import com.cloud.storage.VolumeDetailVO; import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.storage.dao.VMTemplateDetailsDao; @@ -179,7 +179,6 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati full, linked } - private static final Logger s_logger = Logger.getLogger(VolumeOrchestrator.class); @Inject EntityManager _entityMgr; @@ -247,6 +246,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati PassphraseDao passphraseDao; @Inject StoragePoolHostDao storagePoolHostDao; + @Inject + DiskOfferingDao diskOfferingDao; @Inject protected SnapshotHelper snapshotHelper; @@ -348,12 +349,12 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (storagePool.isPresent()) { String storagePoolToString = getReflectOnlySelectedFields(storagePool.get()); - s_logger.debug(String.format("The storage pool [%s] was specified for this account [%s] and will be used for allocation.", storagePoolToString, vm.getAccountId())); + logger.debug(String.format("The storage pool [%s] was specified for this account [%s] and will be used for allocation.", storagePoolToString, vm.getAccountId())); } else { String globalStoragePoolUuid = StorageManager.PreferredStoragePool.value(); storagePool = getMatchingStoragePool(globalStoragePoolUuid, poolList); - storagePool.ifPresent(pool -> s_logger.debug(String.format("The storage pool [%s] was specified in the Global Settings and will be used for allocation.", + storagePool.ifPresent(pool -> logger.debug(String.format("The storage pool [%s] was specified in the Global Settings and will be used for allocation.", getReflectOnlySelectedFields(pool)))); } return storagePool; @@ -374,28 +375,28 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati final List poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, StoragePoolAllocator.RETURN_UPTO_ALL); if (poolList != null && !poolList.isEmpty()) { - StorageUtil.traceLogStoragePools(poolList, s_logger, "pools to choose from: "); + StorageUtil.traceLogStoragePools(poolList, logger, "pools to choose from: "); // Check if the preferred storage pool can be used. If yes, use it. Optional storagePool = getPreferredStoragePool(poolList, vm); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("we have a preferred pool: %b", storagePool.isPresent())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("we have a preferred pool: %b", storagePool.isPresent())); } StoragePool storage; if (storagePool.isPresent()) { storage = (StoragePool)this.dataStoreMgr.getDataStore(storagePool.get().getId(), DataStoreRole.Primary); - s_logger.debug(String.format("VM [%s] has a preferred storage pool [%s]. Volume Orchestrator found this storage using Storage Pool Allocator [%s] and will" + logger.debug(String.format("VM [%s] has a preferred storage pool [%s]. Volume Orchestrator found this storage using Storage Pool Allocator [%s] and will" + " use it.", vm, storage, allocator.getClass().getSimpleName())); } else { storage = (StoragePool)dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary); - s_logger.debug(String.format("VM [%s] does not have a preferred storage pool or it cannot be used. Volume Orchestrator will use the available Storage Pool" + logger.debug(String.format("VM [%s] does not have a preferred storage pool or it cannot be used. Volume Orchestrator will use the available Storage Pool" + " [%s], which was discovered using Storage Pool Allocator [%s].", vm, storage, allocator.getClass().getSimpleName())); } return storage; } - s_logger.debug(String.format("Could not find any available Storage Pool using Storage Pool Allocator [%s].", allocator.getClass().getSimpleName())); + logger.debug(String.format("Could not find any available Storage Pool using Storage Pool Allocator [%s].", allocator.getClass().getSimpleName())); } - s_logger.info("Volume Orchestrator could not find any available Storage Pool."); + logger.info("Volume Orchestrator could not find any available Storage Pool."); return null; } @@ -524,7 +525,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati String logMsg = String.format("Could not find a storage pool in the pod/cluster of the provided VM [%s] to create the volume [%s] in.", vm, volumeToString); //pool could not be found in the VM's pod/cluster. - s_logger.error(logMsg); + logger.error(logMsg); StringBuilder addDetails = new StringBuilder(msg); addDetails.append(logMsg); @@ -542,8 +543,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (pool != null) { String poolToString = getReflectOnlySelectedFields(pool); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Found a suitable pool [%s] to create the volume [%s] in.", poolToString, volumeToString)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Found a suitable pool [%s] to create the volume [%s] in.", poolToString, volumeToString)); } break; } @@ -551,7 +552,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } if (pool == null) { - s_logger.info(msg); + logger.info(msg); throw new StorageUnavailableException(msg, -1); } @@ -579,7 +580,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati _snapshotSrv.syncVolumeSnapshotsToRegionStore(snapVolId, snapStore); } catch (Exception ex) { // log but ignore the sync error to avoid any potential S3 down issue, it should be sync next time - s_logger.warn(ex.getMessage(), ex); + logger.warn(ex.getMessage(), ex); } } @@ -591,14 +592,14 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati VolumeApiResult result = future.get(); if (result.isFailed()) { String logMsg = String.format("Failed to create volume from snapshot [%s] due to [%s].", snapshotToString, result.getResult()); - s_logger.error(logMsg); + logger.error(logMsg); throw new CloudRuntimeException(logMsg); } return result.getVolume(); } catch (InterruptedException | ExecutionException e) { String message = String.format("Failed to create volume from snapshot [%s] due to [%s].", snapshotToString, e.getMessage()); - s_logger.error(message); - s_logger.debug("Exception: ", e); + logger.error(message); + logger.debug("Exception: ", e); throw new CloudRuntimeException(message, e); } finally { snapshotHelper.expungeTemporarySnapshot(kvmSnapshotOnlyInPrimaryStorage, snapInfo); @@ -647,14 +648,14 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati VolumeApiResult result = future.get(); if (result.isFailed()) { String msg = String.format("Copy of the volume [%s] failed due to [%s].", volumeToString, result.getResult()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } return result.getVolume(); } catch (InterruptedException | ExecutionException e) { String msg = String.format("Failed to copy the volume [%s] due to [%s].", volumeToString, e.getMessage()); - s_logger.error(msg); - s_logger.debug("Exception: ", e); + logger.error(msg); + logger.debug("Exception: ", e); throw new CloudRuntimeException(msg, e); } } @@ -699,14 +700,14 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati pool = findStoragePool(dskCh, dc, pod, clusterId, hostId, vm, avoidPools); if (pool == null) { String msg = String.format("Unable to find suitable primary storage when creating volume [%s].", volumeToString); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } String poolToString = getReflectOnlySelectedFields(pool); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Trying to create volume [%s] on storage pool [%s].", + if (logger.isDebugEnabled()) { + logger.debug(String.format("Trying to create volume [%s] on storage pool [%s].", volumeToString, poolToString)); } DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); @@ -724,19 +725,19 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati VolumeApiResult result = future.get(); if (result.isFailed()) { if (result.getResult().contains(REQUEST_TEMPLATE_RELOAD) && (i == 0)) { - s_logger.debug(String.format("Retrying to deploy template [%s] for VMware, attempt 2/2. ", templateToString)); + logger.debug(String.format("Retrying to deploy template [%s] for VMware, attempt 2/2. ", templateToString)); continue; } else { String msg = String.format("Failed to create volume [%s] due to [%s].", volumeToString, result.getResult()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } return result.getVolume(); } catch (InterruptedException | ExecutionException e) { String msg = String.format("Failed to create volume [%s] due to [%s].", volumeToString, e.getMessage()); - s_logger.error(msg); - s_logger.debug("Exception: ", e); + logger.error(msg); + logger.debug("Exception: ", e); throw new CloudRuntimeException(msg, e); } } @@ -863,26 +864,13 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati vol.setFormat(getSupportedImageFormatForCluster(vm.getHypervisorType())); vol = _volsDao.persist(vol); - List volumeDetailsVO = new ArrayList(); - DiskOfferingDetailVO bandwidthLimitDetail = _diskOfferingDetailDao.findDetail(offering.getId(), Volume.BANDWIDTH_LIMIT_IN_MBPS); - if (bandwidthLimitDetail != null) { - volumeDetailsVO.add(new VolumeDetailVO(vol.getId(), Volume.BANDWIDTH_LIMIT_IN_MBPS, bandwidthLimitDetail.getValue(), false)); - } - DiskOfferingDetailVO iopsLimitDetail = _diskOfferingDetailDao.findDetail(offering.getId(), Volume.IOPS_LIMIT); - if (iopsLimitDetail != null) { - volumeDetailsVO.add(new VolumeDetailVO(vol.getId(), Volume.IOPS_LIMIT, iopsLimitDetail.getValue(), false)); - } - if (!volumeDetailsVO.isEmpty()) { - _volDetailDao.saveDetails(volumeDetailsVO); - } + saveVolumeDetails(offering.getId(), vol.getId()); // Save usage event and update resource count for user vm volumes if (vm.getType() == VirtualMachine.Type.User) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), null, size, Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume()); - - _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume, vol.isDisplayVolume()); - _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.primary_storage, vol.isDisplayVolume(), new Long(vol.getSize())); + _resourceLimitMgr.incrementVolumeResourceCount(vm.getAccountId(), vol.isDisplayVolume(), vol.getSize(), offering); } DiskProfile diskProfile = toDiskProfile(vol, offering); @@ -903,10 +891,10 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } else { rootDisksize = rootDisksize * 1024 * 1024 * 1024; if (rootDisksize > size) { - s_logger.debug(String.format("Using root disk size of [%s] bytes for the volume [%s].", toHumanReadableSize(rootDisksize), name)); + logger.debug(String.format("Using root disk size of [%s] bytes for the volume [%s].", toHumanReadableSize(rootDisksize), name)); size = rootDisksize; } else { - s_logger.debug(String.format("The specified root disk size of [%s] bytes is smaller than the template. Using root disk size of [%s] bytes for the volume [%s].", + logger.debug(String.format("The specified root disk size of [%s] bytes is smaller than the template. Using root disk size of [%s] bytes for the volume [%s].", toHumanReadableSize(rootDisksize), size, name)); } } @@ -934,18 +922,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati vol = _volsDao.persist(vol); - List volumeDetailsVO = new ArrayList(); - DiskOfferingDetailVO bandwidthLimitDetail = _diskOfferingDetailDao.findDetail(offering.getId(), Volume.BANDWIDTH_LIMIT_IN_MBPS); - if (bandwidthLimitDetail != null) { - volumeDetailsVO.add(new VolumeDetailVO(vol.getId(), Volume.BANDWIDTH_LIMIT_IN_MBPS, bandwidthLimitDetail.getValue(), false)); - } - DiskOfferingDetailVO iopsLimitDetail = _diskOfferingDetailDao.findDetail(offering.getId(), Volume.IOPS_LIMIT); - if (iopsLimitDetail != null) { - volumeDetailsVO.add(new VolumeDetailVO(vol.getId(), Volume.IOPS_LIMIT, iopsLimitDetail.getValue(), false)); - } - if (!volumeDetailsVO.isEmpty()) { - _volDetailDao.saveDetails(volumeDetailsVO); - } + saveVolumeDetails(offering.getId(), vol.getId()); if (StringUtils.isNotBlank(configurationId)) { VolumeDetailVO deployConfigurationDetail = new VolumeDetailVO(vol.getId(), VmDetailConstants.DEPLOY_AS_IS_CONFIGURATION, configurationId, false); @@ -964,12 +941,37 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offeringId, vol.getTemplateId(), size, Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume()); - _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume, vol.isDisplayVolume()); - _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.primary_storage, vol.isDisplayVolume(), new Long(vol.getSize())); + _resourceLimitMgr.incrementVolumeResourceCount(vm.getAccountId(), vol.isDisplayVolume(), vol.getSize(), offering); } return toDiskProfile(vol, offering); } + @Override + public void saveVolumeDetails(Long diskOfferingId, Long volumeId) { + List volumeDetailsVO = new ArrayList<>(); + DiskOfferingDetailVO bandwidthLimitDetail = _diskOfferingDetailDao.findDetail(diskOfferingId, Volume.BANDWIDTH_LIMIT_IN_MBPS); + if (bandwidthLimitDetail != null) { + volumeDetailsVO.add(new VolumeDetailVO(volumeId, Volume.BANDWIDTH_LIMIT_IN_MBPS, bandwidthLimitDetail.getValue(), false)); + } else { + VolumeDetailVO bandwidthLimit = _volDetailDao.findDetail(volumeId, Volume.BANDWIDTH_LIMIT_IN_MBPS); + if (bandwidthLimit != null) { + _volDetailDao.remove(bandwidthLimit.getId()); + } + } + DiskOfferingDetailVO iopsLimitDetail = _diskOfferingDetailDao.findDetail(diskOfferingId, Volume.IOPS_LIMIT); + if (iopsLimitDetail != null) { + volumeDetailsVO.add(new VolumeDetailVO(volumeId, Volume.IOPS_LIMIT, iopsLimitDetail.getValue(), false)); + } else { + VolumeDetailVO iopsLimit = _volDetailDao.findDetail(volumeId, Volume.IOPS_LIMIT); + if (iopsLimit != null) { + _volDetailDao.remove(iopsLimit.getId()); + } + } + if (!volumeDetailsVO.isEmpty()) { + _volDetailDao.saveDetails(volumeDetailsVO); + } + } + @ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating ROOT volume", create = true) @Override public List allocateTemplatedVolumes(Type type, String name, DiskOffering offering, Long rootDisksize, Long minIops, Long maxIops, VirtualMachineTemplate template, VirtualMachine vm, @@ -983,7 +985,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (template.isDeployAsIs() && vm.getType() != VirtualMachine.Type.SecondaryStorageVm) { List runningSSVMs = secondaryStorageVmDao.getSecStorageVmListInStates(null, vm.getDataCenterId(), State.Running); if (CollectionUtils.isEmpty(runningSSVMs)) { - s_logger.info(String.format("Could not find a running SSVM in datacenter [%s] for deploying VM as is. Not deploying VM [%s] as is.", + logger.info(String.format("Could not find a running SSVM in datacenter [%s] for deploying VM as is. Not deploying VM [%s] as is.", vm.getDataCenterId(), vm)); } else { UserVmDetailVO configurationDetail = userVmDetailsDao.findDetail(vm.getId(), VmDetailConstants.DEPLOY_AS_IS_CONFIGURATION); @@ -1018,7 +1020,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati volumeSize = templateAsIsDisks.get(number).getVirtualSize(); deviceId = templateAsIsDisks.get(number).getDiskNumber(); } - s_logger.info(String.format("Adding disk object [%s] to VM [%s]", volumeName, vm)); + logger.info(String.format("Adding disk object [%s] to VM [%s]", volumeName, vm)); DiskProfile diskProfile = allocateTemplatedVolume(type, volumeName, offering, volumeSize, minIops, maxIops, template, vm, owner, deviceId, configurationId); profiles.add(diskProfile); @@ -1115,8 +1117,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati VirtualMachineTemplate rootDiskTmplt = _entityMgr.findById(VirtualMachineTemplate.class, vm.getTemplateId()); DataCenter dcVO = _entityMgr.findById(DataCenter.class, vm.getDataCenterId()); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("storage-pool %s/%s is associated with pod %d",storagePool.getName(), storagePool.getUuid(), storagePool.getPodId())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("storage-pool %s/%s is associated with pod %d",storagePool.getName(), storagePool.getUuid(), storagePool.getPodId())); } Long podId = storagePool.getPodId() != null ? storagePool.getPodId() : vm.getPodIdToDeployIn(); Pod pod = _entityMgr.findById(Pod.class, podId); @@ -1124,8 +1126,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati ServiceOffering svo = _entityMgr.findById(ServiceOffering.class, vm.getServiceOfferingId()); DiskOffering diskVO = _entityMgr.findById(DiskOffering.class, volumeInfo.getDiskOfferingId()); Long clusterId = storagePool.getClusterId(); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("storage-pool %s/%s is associated with cluster %d",storagePool.getName(), storagePool.getUuid(), clusterId)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("storage-pool %s/%s is associated with cluster %d",storagePool.getName(), storagePool.getUuid(), clusterId)); } Long hostId = vm.getHostId(); if (hostId == null && storagePool.isLocal()) { @@ -1144,6 +1146,10 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati // Moving of Volume is successful, decrement the volume resource count from secondary for an account and increment it into primary storage under same account. _resourceLimitMgr.decrementResourceCount(volumeInfo.getAccountId(), ResourceType.secondary_storage, volumeInfo.getSize()); _resourceLimitMgr.incrementResourceCount(volumeInfo.getAccountId(), ResourceType.primary_storage, volumeInfo.getSize()); + List tags = _resourceLimitMgr.getResourceLimitStorageTags(diskVO); + for (String tag : tags) { + _resourceLimitMgr.incrementResourceCountWithTag(volumeInfo.getAccountId(), ResourceType.primary_storage, tag, volumeInfo.getSize()); + } } } @@ -1166,8 +1172,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati Long volTemplateId = existingVolume.getTemplateId(); long vmTemplateId = vm.getTemplateId(); if (volTemplateId != null && volTemplateId.longValue() != vmTemplateId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("switchVolume: Old volume's templateId [%s] does not match the VM's templateId [%s]. Updating templateId in the new volume.", volTemplateId, vmTemplateId)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("switchVolume: Old volume's templateId [%s] does not match the VM's templateId [%s]. Updating templateId in the new volume.", volTemplateId, vmTemplateId)); } templateIdToUse = vmTemplateId; } @@ -1180,17 +1186,17 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati try { stateTransitTo(existingVolume, Volume.Event.DestroyRequested); } catch (NoTransitionException e) { - s_logger.error(String.format("Unable to destroy existing volume [%s] due to [%s].", volumeToString, e.getMessage())); + logger.error(String.format("Unable to destroy existing volume [%s] due to [%s].", volumeToString, e.getMessage())); } // In case of VMware VM will continue to use the old root disk until expunged, so force expunge old root disk if (vm.getHypervisorType() == HypervisorType.VMware) { - s_logger.info(String.format("Trying to expunge volume [%s] from primary data storage.", volumeToString)); + logger.info(String.format("Trying to expunge volume [%s] from primary data storage.", volumeToString)); AsyncCallFuture future = volService.expungeVolumeAsync(volFactory.getVolume(existingVolume.getId())); try { future.get(); } catch (Exception e) { - s_logger.error(String.format("Failed to expunge volume [%s] from primary data storage due to [%s].", volumeToString, e.getMessage())); - s_logger.debug("Exception: ", e); + logger.error(String.format("Failed to expunge volume [%s] from primary data storage due to [%s].", volumeToString, e.getMessage())); + logger.debug("Exception: ", e); } } @@ -1216,8 +1222,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati HostVO host = _hostDao.findById(hostId); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Releasing [%s] volumes for VM [%s] from host [%s].", volumesForVm.size(), _userVmDao.findById(vmId), host)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Releasing [%s] volumes for VM [%s] from host [%s].", volumesForVm.size(), _userVmDao.findById(vmId), host)); } for (VolumeVO volumeForVm : volumesForVm) { @@ -1228,8 +1234,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati DataStore dataStore = dataStoreMgr.getDataStore(volumeForVm.getPoolId(), DataStoreRole.Primary); PrimaryDataStore primaryDataStore = (PrimaryDataStore)dataStore; - // This might impact other managed storages, grant access for PowerFlex storage pool only - if (primaryDataStore.isManaged() && primaryDataStore.getPoolType() == Storage.StoragePoolType.PowerFlex) { + // This might impact other managed storages, enable requires access for migration in relevant datastore driver (currently enabled for PowerFlex storage pool only) + if (primaryDataStore.isManaged() && volService.requiresAccessForMigration(volumeInfo, dataStore)) { volService.revokeAccess(volumeInfo, host, dataStore); } } @@ -1241,8 +1247,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati public void cleanupVolumes(long vmId) throws ConcurrentOperationException { VMInstanceVO vm = _userVmDao.findById(vmId); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Cleaning storage for VM [%s].", vm)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Cleaning storage for VM [%s].", vm)); } final List volumesForVm = _volsDao.findByInstance(vmId); final List toBeExpunged = new ArrayList(); @@ -1259,12 +1265,12 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (!volumeAlreadyDestroyed) { destroyVolumeInContext(vol); } else { - s_logger.debug(String.format("Skipping destroy for the volume [%s] as it is in [%s] state.", volumeToString, vol.getState().toString())); + logger.debug(String.format("Skipping destroy for the volume [%s] as it is in [%s] state.", volumeToString, vol.getState().toString())); } toBeExpunged.add(vol); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Detaching volume [%s].", volumeToString)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Detaching volume [%s].", volumeToString)); } if (vm.getHypervisorType().equals(HypervisorType.VMware)) { _volumeApiService.detachVolumeViaDestroyVM(vmId, vol.getId()); @@ -1283,8 +1289,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati try { future.get(); } catch (InterruptedException | ExecutionException e) { - s_logger.error(String.format("Failed to expunge volume [%s] due to [%s].", expungeToString, e.getMessage())); - s_logger.debug("Exception: ", e); + logger.error(String.format("Failed to expunge volume [%s] due to [%s].", expungeToString, e.getMessage())); + logger.debug("Exception: ", e); } } } @@ -1367,7 +1373,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati String volToString = getReflectOnlySelectedFields(vol.getVolume()); String msg = String.format("Volume [%s] migration failed due to [%s].", volToString, result.getResult()); - s_logger.error(msg); + logger.error(msg); if (result.getResult() != null && result.getResult().contains("[UNSUPPORTED]")) { throw new CloudRuntimeException(msg); @@ -1383,8 +1389,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati return result.getVolume(); } catch (InterruptedException | ExecutionException e) { String msg = String.format("Volume [%s] migration failed due to [%s].", volumeToString, e.getMessage()); - s_logger.error(msg); - s_logger.debug("Exception: ", e); + logger.error(msg); + logger.debug("Exception: ", e); throw new CloudRuntimeException(msg, e); } } @@ -1401,13 +1407,13 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati try { VolumeApiResult result = future.get(); if (result.isFailed()) { - s_logger.error(String.format("Volume [%s] migration failed due to [%s].", volToString, result.getResult())); + logger.error(String.format("Volume [%s] migration failed due to [%s].", volToString, result.getResult())); return null; } return result.getVolume(); } catch (InterruptedException | ExecutionException e) { - s_logger.error(String.format("Volume [%s] migration failed due to [%s].", volToString, e.getMessage())); - s_logger.debug("Exception: ", e); + logger.error(String.format("Volume [%s] migration failed due to [%s].", volToString, e.getMessage())); + logger.debug("Exception: ", e); return null; } } @@ -1443,12 +1449,12 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati CommandResult result = future.get(); if (result.isFailed()) { String msg = String.format("Failed to migrate VM [%s] along with its volumes due to [%s].", vm, result.getResult()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } catch (InterruptedException | ExecutionException e) { - s_logger.error(String.format("Failed to migrate VM [%s] along with its volumes due to [%s].", vm, e.getMessage())); - s_logger.debug("Exception: ", e); + logger.error(String.format("Failed to migrate VM [%s] along with its volumes due to [%s].", vm, e.getMessage())); + logger.debug("Exception: ", e); } } @@ -1464,23 +1470,23 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (volume.getState() != Volume.State.Ready) { String msg = String.format("Volume [%s] is in [%s] state.", volumeToString, volume.getState()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } if (volume.getPoolId() == pool.getId()) { - s_logger.debug(String.format("Volume [%s] already is on the elected storage pool [%s].", volumeToString, poolToString)); + logger.debug(String.format("Volume [%s] already is on the elected storage pool [%s].", volumeToString, poolToString)); continue; } volumeStoragePoolMap.put(volume, volumeToPool.get(volume)); } if (MapUtils.isEmpty(volumeStoragePoolMap)) { - s_logger.debug("No volume needs to be migrated."); + logger.debug("No volume needs to be migrated."); return true; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Offline VM migration was not done up the stack in VirtualMachineManager. Trying to migrate the VM here."); + if (logger.isDebugEnabled()) { + logger.debug("Offline VM migration was not done up the stack in VirtualMachineManager. Trying to migrate the VM here."); } for (Map.Entry entry : volumeStoragePoolMap.entrySet()) { Volume result = migrateVolume(entry.getKey(), entry.getValue()); @@ -1494,8 +1500,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati @Override public void prepareForMigration(VirtualMachineProfile vm, DeployDestination dest) { List vols = _volsDao.findUsableVolumesForInstance(vm.getId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Preparing to migrate [%s] volumes for VM [%s].", vols.size(), vm.getVirtualMachine())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Preparing to migrate [%s] volumes for VM [%s].", vols.size(), vm.getVirtualMachine())); } for (VolumeVO vol : vols) { @@ -1507,8 +1513,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati disk.setDetails(getDetails(volumeInfo, dataStore)); PrimaryDataStore primaryDataStore = (PrimaryDataStore)dataStore; - // This might impact other managed storages, grant access for PowerFlex storage pool only - if (primaryDataStore.isManaged() && primaryDataStore.getPoolType() == Storage.StoragePoolType.PowerFlex) { + // This might impact other managed storages, enable requires access for migration in relevant datastore driver (currently enabled for PowerFlex storage pool only) + if (primaryDataStore.isManaged() && volService.requiresAccessForMigration(volumeInfo, dataStore)) { volService.grantAccess(volFactory.getVolume(vol.getId()), dest.getHost(), dataStore); } @@ -1618,15 +1624,15 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati tasks.add(task); } else { if (vol.isRecreatable()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Volume [%s] will be recreated on storage pool [%s], assigned by deploymentPlanner.", volToString, assignedPoolToString)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Volume [%s] will be recreated on storage pool [%s], assigned by deploymentPlanner.", volToString, assignedPoolToString)); } VolumeTask task = new VolumeTask(VolumeTaskType.RECREATE, vol, null); tasks.add(task); } else { if (assignedPool.getId() != vol.getPoolId()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Mismatch with the storage pool [%s] assigned by deploymentPlanner and the one associated with the volume [%s].", + if (logger.isDebugEnabled()) { + logger.debug(String.format("Mismatch with the storage pool [%s] assigned by deploymentPlanner and the one associated with the volume [%s].", assignedPoolToString, volToString)); } DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, vol.getDiskOfferingId()); @@ -1634,7 +1640,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati // Currently migration of local volume is not supported so bail out String msg = String.format("Local volume [%s] cannot be recreated on storage pool [%s], assigned by deploymentPlanner.", volToString, assignedPoolToString); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } else { @@ -1647,8 +1653,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati storageMigrationEnabled = StorageMigrationEnabled.value(); } if (storageMigrationEnabled) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Shared volume [%s] will be migrated to the storage pool [%s], assigned by deploymentPlanner.", + if (logger.isDebugEnabled()) { + logger.debug(String.format("Shared volume [%s] will be migrated to the storage pool [%s], assigned by deploymentPlanner.", volToString, assignedPoolToString)); } VolumeTask task = new VolumeTask(VolumeTaskType.MIGRATE, vol, assignedPool); @@ -1673,8 +1679,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("No need to recreate the volume [%s] since it already has an assigned pool: [%s]. Adding disk to the VM.", + if (logger.isDebugEnabled()) { + logger.debug(String.format("No need to recreate the volume [%s] since it already has an assigned pool: [%s]. Adding disk to the VM.", volToString, pool.getUuid())); } VolumeTask task = new VolumeTask(VolumeTaskType.NOP, vol, pool); @@ -1689,7 +1695,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (Objects.equals(originalEntry.getSize(), updateEntry.getSize())) { return; } - s_logger.debug(String.format("Size mismatch found for %s after creation, old size: %d, new size: %d. Updating resource count", updateEntry, originalEntry.getSize(), updateEntry.getSize())); + logger.debug(String.format("Size mismatch found for %s after creation, old size: %d, new size: %d. Updating resource count", updateEntry, originalEntry.getSize(), updateEntry.getSize())); if (ObjectUtils.anyNull(originalEntry.getSize(), updateEntry.getSize())) { _resourceLimitMgr.recalculateResourceCount(updateEntry.getAccountId(), updateEntry.getDomainId(), ResourceType.primary_storage.getOrdinal()); @@ -1711,7 +1717,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (recreate && (dest.getStorageForDisks() == null || dest.getStorageForDisks().get(vol) == null)) { destPool = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary); String destPoolToString = getReflectOnlySelectedFields(destPool); - s_logger.debug(String.format("Existing pool: [%s].", destPoolToString)); + logger.debug(String.format("Existing pool: [%s].", destPoolToString)); } else { StoragePool pool = dest.getStorageForDisks().get(vol); destPool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); @@ -1733,8 +1739,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati dest.getStorageForDisks().put(newVol, poolWithOldVol); dest.getStorageForDisks().remove(vol); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Created new volume [%s] from old volume [%s].", newVolToString, volToString)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Created new volume [%s] from old volume [%s].", newVolToString, volToString)); } } VolumeInfo volume = volFactory.getVolume(newVol.getId(), destPool); @@ -1756,7 +1762,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } else { final VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId); if (template == null) { - s_logger.error(String.format("Failed to find template: %d for %s", templateId, volume)); + logger.error(String.format("Failed to find template: %d for %s", templateId, volume)); throw new CloudRuntimeException(String.format("Failed to find template for volume ID: %s", volume.getUuid())); } TemplateInfo templ = tmplFactory.getReadyTemplateOnImageStore(templateId, dest.getDataCenter().getId()); @@ -1768,19 +1774,19 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (!primaryDataStore.isManaged()) { templ = tmplFactory.getReadyBypassedTemplateOnPrimaryStore(templateId, destPool.getId(), dest.getHost().getId()); } else { - s_logger.debug(String.format("Directly downloading template [%s] on host [%s] and copying it to the managed storage pool [%s].", + logger.debug(String.format("Directly downloading template [%s] on host [%s] and copying it to the managed storage pool [%s].", templateId, dest.getHost().getUuid(), destPool.getUuid())); templ = volService.createManagedStorageTemplate(templateId, destPool.getId(), dest.getHost().getId()); } if (templ == null) { String msg = String.format("Failed to spool direct download template [%s] to the data center [%s].", templateId, dest.getDataCenter().getUuid()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } else { String msg = String.format("Could not find template [%s] ready for the data center [%s].", templateId, dest.getDataCenter().getUuid()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } @@ -1806,11 +1812,11 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati result = future.get(); if (result.isFailed()) { if (result.getResult().contains(REQUEST_TEMPLATE_RELOAD) && (i == 0)) { - s_logger.debug("Retrying template deploy for VMware."); + logger.debug("Retrying template deploy for VMware."); continue; } else { String msg = String.format("Unable to create volume [%s] due to [%s].", newVolToString, result.getResult()); - s_logger.error(msg); + logger.error(msg); throw new StorageUnavailableException(msg, destPool.getId()); } } @@ -1834,8 +1840,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati throw e; } catch (InterruptedException | ExecutionException e) { String msg = String.format("Unable to create volume [%s] due to [%s].", newVolToString, e.toString()); - s_logger.error(msg); - s_logger.debug("Exception: ", e); + logger.error(msg); + logger.debug("Exception: ", e); throw new StorageUnavailableException(msg, destPool.getId()); } } @@ -1847,20 +1853,32 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (volume.getPassphraseId() != null) { return volume; } - s_logger.debug("Creating passphrase for the volume: " + volume.getName()); + logger.debug("Creating passphrase for the volume: " + volume.getName()); long startTime = System.currentTimeMillis(); PassphraseVO passphrase = passphraseDao.persist(new PassphraseVO(true)); volume.setPassphraseId(passphrase.getId()); long finishTime = System.currentTimeMillis(); - s_logger.debug("Creating and persisting passphrase took: " + (finishTime - startTime) + " ms for the volume: " + volume.toString()); + logger.debug("Creating and persisting passphrase took: " + (finishTime - startTime) + " ms for the volume: " + volume.toString()); return _volsDao.persist(volume); } + protected void grantVolumeAccessToHostIfNeeded(PrimaryDataStore volumeStore, long volumeId, Host host, String volToString) { + PrimaryDataStoreDriver driver = (PrimaryDataStoreDriver)volumeStore.getDriver(); + if (!driver.volumesRequireGrantAccessWhenUsed()) { + return; + } + try { + volService.grantAccess(volFactory.getVolume(volumeId), host, volumeStore); + } catch (Exception e) { + throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host)); + } + } + @Override public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException, StorageAccessException { if (dest == null) { String msg = String.format("Unable to prepare volumes for the VM [%s] because DeployDestination is null.", vm.getVirtualMachine()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -1873,18 +1891,18 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati List tasks = getTasks(vols, dest.getStorageForDisks(), vm); Volume vol = null; - StoragePool pool; + PrimaryDataStore store; for (VolumeTask task : tasks) { if (task.type == VolumeTaskType.NOP) { vol = task.volume; String volToString = getReflectOnlySelectedFields(vol); - pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary); + store = (PrimaryDataStore)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary); // For zone-wide managed storage, it is possible that the VM can be started in another // cluster. In that case, make sure that the volume is in the right access group. - if (pool.isManaged()) { + if (store.isManaged()) { Host lastHost = _hostDao.findById(vm.getVirtualMachine().getLastHostId()); Host host = _hostDao.findById(vm.getVirtualMachine().getHostId()); @@ -1893,35 +1911,27 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (lastClusterId != clusterId) { if (lastHost != null) { - storageMgr.removeStoragePoolFromCluster(lastHost.getId(), vol.get_iScsiName(), pool); - - DataStore storagePool = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); - - volService.revokeAccess(volFactory.getVolume(vol.getId()), lastHost, storagePool); + storageMgr.removeStoragePoolFromCluster(lastHost.getId(), vol.get_iScsiName(), store); + volService.revokeAccess(volFactory.getVolume(vol.getId()), lastHost, store); } try { - volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore)pool); + volService.grantAccess(volFactory.getVolume(vol.getId()), host, store); } catch (Exception e) { throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host)); } } else { - // This might impact other managed storages, grant access for PowerFlex and Iscsi/Solidfire storage pool only - if (pool.getPoolType() == Storage.StoragePoolType.PowerFlex || pool.getPoolType() == Storage.StoragePoolType.Iscsi) { - try { - volService.grantAccess(volFactory.getVolume(vol.getId()), host, (DataStore)pool); - } catch (Exception e) { - throw new StorageAccessException(String.format("Unable to grant access to volume [%s] on host [%s].", volToString, host)); - } - } + grantVolumeAccessToHostIfNeeded(store, vol.getId(), host, volToString); } + } else { + handleCheckAndRepairVolume(vol, vm.getVirtualMachine().getHostId()); } } else if (task.type == VolumeTaskType.MIGRATE) { - pool = (StoragePool)dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary); - vol = migrateVolume(task.volume, pool); + store = (PrimaryDataStore) dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary); + vol = migrateVolume(task.volume, store); } else if (task.type == VolumeTaskType.RECREATE) { Pair result = recreateVolume(task.volume, vm, dest); - pool = (StoragePool)dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary); + store = (PrimaryDataStore) dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary); vol = result.first(); } @@ -1957,6 +1967,16 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } } + private void handleCheckAndRepairVolume(Volume vol, Long hostId) { + Host host = _hostDao.findById(hostId); + try { + volService.checkAndRepairVolumeBasedOnConfig(volFactory.getVolume(vol.getId()), host); + } catch (Exception e) { + String volumeToString = getReflectOnlySelectedFields(vol); + logger.debug(String.format("Unable to check and repair volume [%s] on host [%s], due to %s.", volumeToString, host, e.getMessage())); + } + } + private boolean stateTransitTo(Volume vol, Volume.Event event) throws NoTransitionException { return _volStateMachine.transitTo(vol, event, null, _volsDao); } @@ -2009,12 +2029,12 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati String volumeToString = getReflectOnlySelectedFields(volume); if (volume.getState().equals(Volume.State.Creating)) { - s_logger.debug(String.format("Removing volume [%s], as it was leftover from the last management server stop.", volumeToString)); + logger.debug(String.format("Removing volume [%s], as it was leftover from the last management server stop.", volumeToString)); _volsDao.remove(volume.getId()); } if (volume.getState().equals(Volume.State.Attaching)) { - s_logger.warn(String.format("Volume [%s] failed to attach to the VM [%s] on the last management server stop, changing state back to Ready.", volumeToString, _userVmDao.findById(vmId))); + logger.warn(String.format("Volume [%s] failed to attach to the VM [%s] on the last management server stop, changing state back to Ready.", volumeToString, _userVmDao.findById(vmId))); volume.setState(Volume.State.Ready); _volsDao.update(volumeId, volume); } @@ -2037,11 +2057,11 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (duplicateVol != null) { String duplicateVolToString = getReflectOnlySelectedFields(duplicateVol); - s_logger.debug(String.format("Removing volume [%s] from storage pool [%s] because it's duplicated.", duplicateVolToString, destPoolToString)); + logger.debug(String.format("Removing volume [%s] from storage pool [%s] because it's duplicated.", duplicateVolToString, destPoolToString)); _volsDao.remove(duplicateVol.getId()); } - s_logger.debug(String.format("Changing volume [%s] state from Migrating to Ready in case of migration failure.", volumeToString)); + logger.debug(String.format("Changing volume [%s] state from Migrating to Ready in case of migration failure.", volumeToString)); volume.setState(Volume.State.Ready); _volsDao.update(volumeId, volume); } @@ -2055,7 +2075,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati String volumeToString = getReflectOnlySelectedFields(volume); if (volume.getState() == Volume.State.Snapshotting) { - s_logger.debug(String.format("Changing volume [%s] state back to Ready.", volumeToString)); + logger.debug(String.format("Changing volume [%s] state back to Ready.", volumeToString)); volume.setState(Volume.State.Ready); _volsDao.update(volume.getId(), volume); } @@ -2079,8 +2099,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati cleanupVolumeDuringSnapshotFailure(work.getVolumeId(), work.getSnapshotId()); } } catch (Exception e) { - s_logger.error(String.format("Clean up job failed due to [%s]. Will continue with other clean up jobs.", e.getMessage())); - s_logger.debug("Exception: ", e); + logger.error(String.format("Clean up job failed due to [%s]. Will continue with other clean up jobs.", e.getMessage())); + logger.debug("Exception: ", e); } } } @@ -2104,8 +2124,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati if (volume.getState() == Volume.State.Allocated) { _volsDao.remove(volume.getId()); stateTransitTo(volume, Volume.Event.DestroyRequested); - _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplay()); - _resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplay(), new Long(volume.getSize())); + _resourceLimitMgr.decrementVolumeResourceCount(volume.getAccountId(), volume.isDisplay(), volume.getSize(), diskOfferingDao.findByIdIncludingRemoved(volume.getDiskOfferingId())); } else { destroyVolumeInContext(volume); } @@ -2115,8 +2134,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati volume.getUuid(), volume.isDisplayVolume()); } catch (Exception e) { String msg = String.format("Failed to destroy volume [%s] due to [%s].", volumeToString, e.getMessage()); - s_logger.error(msg); - s_logger.debug("Exception: ", e); + logger.error(msg); + logger.debug("Exception: ", e); throw new CloudRuntimeException(msg, e); } } @@ -2157,7 +2176,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } if (needUpdate) { - s_logger.info(String.format("Updating volume's disk chain info. Volume: [%s]. Path: [%s] -> [%s], Disk Chain Info: [%s] -> [%s].", + logger.info(String.format("Updating volume's disk chain info. Volume: [%s]. Path: [%s] -> [%s], Disk Chain Info: [%s] -> [%s].", volToString, vol.getPath(), path, vol.getChainInfo(), chainInfo)); vol.setPath(path); vol.setChainInfo(chainInfo); @@ -2172,19 +2191,17 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati } @Override - public DiskProfile importVolume(Type type, String name, DiskOffering offering, Long size, Long minIops, Long maxIops, + public DiskProfile importVolume(Type type, String name, DiskOffering offering, Long sizeInBytes, Long minIops, Long maxIops, VirtualMachine vm, VirtualMachineTemplate template, Account owner, Long deviceId, Long poolId, String path, String chainInfo) { - if (size == null) { - size = offering.getDiskSize(); - } else { - size = (size * 1024 * 1024 * 1024); + if (sizeInBytes == null) { + sizeInBytes = offering.getDiskSize(); } minIops = minIops != null ? minIops : offering.getMinIops(); maxIops = maxIops != null ? maxIops : offering.getMaxIops(); - VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), offering.getProvisioningType(), size, minIops, maxIops, null); + VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), offering.getProvisioningType(), sizeInBytes, minIops, maxIops, null); if (vm != null) { vol.setInstanceId(vm.getId()); } @@ -2271,8 +2288,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati @Override public void unmanageVolumes(long vmId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Unmanaging storage for VM [%s].", _userVmDao.findById(vmId))); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Unmanaging storage for VM [%s].", _userVmDao.findById(vmId))); } final List volumesForVm = _volsDao.findByInstance(vmId); @@ -2285,7 +2302,7 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati boolean volumeAlreadyDestroyed = (vol.getState() == Volume.State.Destroy || vol.getState() == Volume.State.Expunged || vol.getState() == Volume.State.Expunging); if (volumeAlreadyDestroyed) { - s_logger.debug(String.format("Skipping Destroy for the volume [%s] as it is in [%s] state.", volToString, vol.getState().toString())); + logger.debug(String.format("Skipping Destroy for the volume [%s] as it is in [%s] state.", volToString, vol.getState().toString())); } else { volService.unmanageVolume(vol.getId()); } diff --git a/engine/orchestration/src/test/java/com/cloud/agent/manager/DirectAgentAttacheTest.java b/engine/orchestration/src/test/java/com/cloud/agent/manager/DirectAgentAttacheTest.java index 2ee2b46b4c9..fe9b7fafa81 100644 --- a/engine/orchestration/src/test/java/com/cloud/agent/manager/DirectAgentAttacheTest.java +++ b/engine/orchestration/src/test/java/com/cloud/agent/manager/DirectAgentAttacheTest.java @@ -22,7 +22,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.resource.ServerResource; diff --git a/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java b/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java index cf194462719..9b32980087c 100644 --- a/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java +++ b/engine/orchestration/src/test/java/com/cloud/vm/VirtualMachineManagerImplTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -38,27 +39,24 @@ import java.util.Map; import java.util.Random; import java.util.stream.Collectors; -import com.cloud.dc.ClusterDetailsDao; -import com.cloud.dc.ClusterDetailsVO; -import com.cloud.dc.Pod; -import com.cloud.deploy.DeployDestination; -import com.cloud.deploy.DeploymentPlanningManager; -import com.cloud.hypervisor.HypervisorGuruManager; -import com.cloud.org.Cluster; -import com.cloud.template.VirtualMachineTemplate; -import com.cloud.user.Account; -import com.cloud.user.User; -import com.cloud.utils.Journal; -import com.cloud.utils.Pair; -import com.cloud.utils.Ternary; -import com.cloud.utils.db.EntityManager; -import com.cloud.utils.fsm.StateMachine2; -import com.cloud.vm.dao.UserVmDetailsDao; +import com.cloud.agent.api.to.VirtualMachineTO; +import com.cloud.api.query.vo.UserVmJoinVO; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkVO; +import com.cloud.network.vpc.VpcVO; +import com.cloud.network.vpc.dao.VpcDao; +import com.cloud.user.AccountVO; +import com.cloud.user.dao.AccountDao; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import org.apache.commons.collections.MapUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -71,6 +69,7 @@ import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; +import org.springframework.test.util.ReflectionTestUtils; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Command; @@ -78,16 +77,25 @@ import com.cloud.agent.api.StopAnswer; import com.cloud.agent.api.StopCommand; import com.cloud.agent.api.routing.NetworkElementCommand; import com.cloud.api.query.dao.UserVmJoinDao; +import com.cloud.dc.ClusterDetailsDao; +import com.cloud.dc.ClusterDetailsVO; +import com.cloud.dc.ClusterVO; +import com.cloud.dc.Pod; +import com.cloud.dc.dao.ClusterDao; import com.cloud.deploy.DataCenterDeployment; +import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner; import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.deploy.DeploymentPlanningManager; import com.cloud.exception.InvalidParameterValueException; import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.hypervisor.HypervisorGuruManager; import com.cloud.offering.ServiceOffering; +import com.cloud.org.Cluster; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; @@ -105,11 +113,19 @@ import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplateZoneDao; import com.cloud.storage.dao.VolumeDao; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.user.Account; +import com.cloud.user.User; +import com.cloud.utils.Journal; +import com.cloud.utils.Pair; +import com.cloud.utils.Ternary; +import com.cloud.utils.db.EntityManager; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.fsm.StateMachine2; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.UserVmDao; +import com.cloud.vm.dao.UserVmDetailsDao; import com.cloud.vm.dao.VMInstanceDao; -import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) public class VirtualMachineManagerImplTest { @@ -178,12 +194,24 @@ public class VirtualMachineManagerImplTest { @Mock private UserVmVO userVmMock; @Mock + private NetworkDao networkDao; + @Mock + private AccountDao accountDao; + @Mock + private DomainDao domainDao; + @Mock + private DataCenterDao dcDao; + @Mock + private VpcDao vpcDao; + @Mock private EntityManager _entityMgr; @Mock private DeploymentPlanningManager _dpMgr; @Mock private HypervisorGuruManager _hvGuruMgr; @Mock + private ClusterDao clusterDao; + @Mock private ClusterDetailsDao _clusterDetailsDao; @Mock private UserVmDetailsDao userVmDetailsDao; @@ -742,7 +770,7 @@ public class VirtualMachineManagerImplTest { List volumesNotMapped = new ArrayList<>(); Mockito.doReturn(volumeToPoolObjectMap).when(virtualMachineManagerImpl).buildMapUsingUserInformation(Mockito.eq(virtualMachineProfileMock), Mockito.eq(hostMock), - Mockito.anyMapOf(Long.class, Long.class)); + Mockito.anyMap()); Mockito.doReturn(volumesNotMapped).when(virtualMachineManagerImpl).findVolumesThatWereNotMappedByTheUser(virtualMachineProfileMock, volumeToPoolObjectMap); Mockito.doNothing().when(virtualMachineManagerImpl).createStoragePoolMappingsForVolumes(Mockito.eq(virtualMachineProfileMock), @@ -753,7 +781,7 @@ public class VirtualMachineManagerImplTest { assertEquals(mappingVolumeAndStoragePool, volumeToPoolObjectMap); InOrder inOrder = Mockito.inOrder(virtualMachineManagerImpl); - inOrder.verify(virtualMachineManagerImpl).buildMapUsingUserInformation(Mockito.eq(virtualMachineProfileMock), Mockito.eq(hostMock), Mockito.anyMapOf(Long.class, Long.class)); + inOrder.verify(virtualMachineManagerImpl).buildMapUsingUserInformation(Mockito.eq(virtualMachineProfileMock), Mockito.eq(hostMock), Mockito.anyMap()); inOrder.verify(virtualMachineManagerImpl).findVolumesThatWereNotMappedByTheUser(virtualMachineProfileMock, volumeToPoolObjectMap); inOrder.verify(virtualMachineManagerImpl).createStoragePoolMappingsForVolumes(Mockito.eq(virtualMachineProfileMock), any(DataCenterDeployment.class), Mockito.eq(volumeToPoolObjectMap), Mockito.eq(volumesNotMapped)); @@ -932,10 +960,53 @@ public class VirtualMachineManagerImplTest { virtualMachineManagerImpl.checkAndAttemptMigrateVmAcrossCluster(vm, destinationClusterId, map); } + @Test + public void checkIfVmNetworkDetailsReturnedIsCorrect() { + VMInstanceVO vm = new VMInstanceVO(1L, 1L, "VM1", "i-2-2-VM", + VirtualMachine.Type.User, 1L, HypervisorType.KVM, 1L, 1L, 1L, + 1L, false, false); + + VirtualMachineTO vmTO = new VirtualMachineTO() { + }; + UserVmJoinVO userVm = new UserVmJoinVO(); + NetworkVO networkVO = mock(NetworkVO.class); + AccountVO accountVO = mock(AccountVO.class); + DomainVO domainVO = mock(DomainVO.class); + domainVO.setName("testDomain"); + DataCenterVO dataCenterVO = mock(DataCenterVO.class); + VpcVO vpcVO = mock(VpcVO.class); + + networkVO.setAccountId(1L); + networkVO.setName("testNet"); + networkVO.setVpcId(1L); + + accountVO.setAccountName("testAcc"); + + vpcVO.setName("VPC1"); + + + List userVms = List.of(userVm); + Mockito.when(userVmJoinDaoMock.searchByIds(anyLong())).thenReturn(userVms); + Mockito.when(networkDao.findById(anyLong())).thenReturn(networkVO); + Mockito.when(accountDao.findById(anyLong())).thenReturn(accountVO); + Mockito.when(domainDao.findById(anyLong())).thenReturn(domainVO); + Mockito.when(dcDao.findById(anyLong())).thenReturn(dataCenterVO); + Mockito.when(vpcDao.findById(anyLong())).thenReturn(vpcVO); + Mockito.when(dataCenterVO.getId()).thenReturn(1L); + when(accountVO.getId()).thenReturn(2L); + Mockito.when(domainVO.getId()).thenReturn(3L); + Mockito.when(vpcVO.getId()).thenReturn(4L); + Mockito.when(networkVO.getId()).thenReturn(5L); + virtualMachineManagerImpl.setVmNetworkDetails(vm, vmTO); + assertEquals(1, vmTO.getNetworkIdToNetworkNameMap().size()); + assertEquals("D3-A2-Z1-V4-S5", vmTO.getNetworkIdToNetworkNameMap().get(5L)); + } + @Test public void testOrchestrateStartNonNullPodId() throws Exception { VMInstanceVO vmInstance = new VMInstanceVO(); ReflectionTestUtils.setField(vmInstance, "id", 1L); + ReflectionTestUtils.setField(vmInstance, "accountId", 1L); ReflectionTestUtils.setField(vmInstance, "uuid", "vm-uuid"); ReflectionTestUtils.setField(vmInstance, "serviceOfferingId", 2L); ReflectionTestUtils.setField(vmInstance, "instanceName", "myVm"); @@ -949,6 +1020,7 @@ public class VirtualMachineManagerImplTest { User user = mock(User.class); Account account = mock(Account.class); + Account owner = mock(Account.class); ReservationContext ctx = mock(ReservationContext.class); @@ -972,12 +1044,13 @@ public class VirtualMachineManagerImplTest { doReturn(vmGuru).when(virtualMachineManagerImpl).getVmGuru(vmInstance); Ternary start = new Ternary<>(vmInstance, ctx, work); - Mockito.doReturn(start).when(virtualMachineManagerImpl).changeToStartState(vmGuru, vmInstance, user, account); + Mockito.doReturn(start).when(virtualMachineManagerImpl).changeToStartState(vmGuru, vmInstance, user, account, owner, serviceOffering, template); when(ctx.getJournal()).thenReturn(Mockito.mock(Journal.class)); when(serviceOfferingDaoMock.findById(vmInstance.getId(), vmInstance.getServiceOfferingId())).thenReturn(serviceOffering); + when(_entityMgr.findById(Account.class, vmInstance.getAccountId())).thenReturn(owner); when(_entityMgr.findByIdIncludingRemoved(VirtualMachineTemplate.class, vmInstance.getTemplateId())).thenReturn(template); Host destHost = mock(Host.class); @@ -1029,6 +1102,7 @@ public class VirtualMachineManagerImplTest { public void testOrchestrateStartNullPodId() throws Exception { VMInstanceVO vmInstance = new VMInstanceVO(); ReflectionTestUtils.setField(vmInstance, "id", 1L); + ReflectionTestUtils.setField(vmInstance, "accountId", 1L); ReflectionTestUtils.setField(vmInstance, "uuid", "vm-uuid"); ReflectionTestUtils.setField(vmInstance, "serviceOfferingId", 2L); ReflectionTestUtils.setField(vmInstance, "instanceName", "myVm"); @@ -1042,6 +1116,7 @@ public class VirtualMachineManagerImplTest { User user = mock(User.class); Account account = mock(Account.class); + Account owner = mock(Account.class); ReservationContext ctx = mock(ReservationContext.class); @@ -1065,12 +1140,13 @@ public class VirtualMachineManagerImplTest { doReturn(vmGuru).when(virtualMachineManagerImpl).getVmGuru(vmInstance); Ternary start = new Ternary<>(vmInstance, ctx, work); - Mockito.doReturn(start).when(virtualMachineManagerImpl).changeToStartState(vmGuru, vmInstance, user, account); + Mockito.doReturn(start).when(virtualMachineManagerImpl).changeToStartState(vmGuru, vmInstance, user, account, owner, serviceOffering, template); when(ctx.getJournal()).thenReturn(Mockito.mock(Journal.class)); when(serviceOfferingDaoMock.findById(vmInstance.getId(), vmInstance.getServiceOfferingId())).thenReturn(serviceOffering); + when(_entityMgr.findById(Account.class, vmInstance.getAccountId())).thenReturn(owner); when(_entityMgr.findByIdIncludingRemoved(VirtualMachineTemplate.class, vmInstance.getTemplateId())).thenReturn(template); Host destHost = mock(Host.class); @@ -1117,4 +1193,47 @@ public class VirtualMachineManagerImplTest { assertNull(vmInstance.getPodIdToDeployIn()); } + + @Test + public void testIsDiskOfferingSuitableForVmSuccess() { + Mockito.doReturn(Mockito.mock(DiskOfferingVO.class)).when(diskOfferingDaoMock).findById(anyLong()); + List poolListMock = new ArrayList<>(); + poolListMock.add(storagePoolVoMock); + Mockito.doReturn(poolListMock).when(storagePoolAllocatorMock).allocateToPool(any(DiskProfile.class), any(VirtualMachineProfile.class), any(DeploymentPlan.class), + any(ExcludeList.class), Mockito.eq(1)); + boolean result = virtualMachineManagerImpl.isDiskOfferingSuitableForVm(vmInstanceMock, virtualMachineProfileMock, 1L, 1L, 1L, 1L); + assertTrue(result); + } + + @Test + public void testIsDiskOfferingSuitableForVmNegative() { + Mockito.doReturn(Mockito.mock(DiskOfferingVO.class)).when(diskOfferingDaoMock).findById(anyLong()); + Mockito.doReturn(new ArrayList<>()).when(storagePoolAllocatorMock).allocateToPool(any(DiskProfile.class), any(VirtualMachineProfile.class), any(DeploymentPlan.class), + any(ExcludeList.class), Mockito.eq(1)); + boolean result = virtualMachineManagerImpl.isDiskOfferingSuitableForVm(vmInstanceMock, virtualMachineProfileMock, 1L, 1L, 1L, 1L); + assertFalse(result); + } + + @Test + public void testGetDiskOfferingSuitabilityForVm() { + Mockito.doReturn(vmInstanceMock).when(vmInstanceDaoMock).findById(1L); + Mockito.when(vmInstanceMock.getHostId()).thenReturn(1L); + Mockito.doReturn(hostMock).when(hostDaoMock).findById(1L); + Mockito.when(hostMock.getClusterId()).thenReturn(1L); + ClusterVO cluster = Mockito.mock(ClusterVO.class); + Mockito.when(cluster.getPodId()).thenReturn(1L); + Mockito.doReturn(cluster).when(clusterDao).findById(1L); + List diskOfferingIds = List.of(1L, 2L); + Mockito.doReturn(false).when(virtualMachineManagerImpl) + .isDiskOfferingSuitableForVm(eq(vmInstanceMock), any(VirtualMachineProfile.class), + eq(1L), eq(1L), eq(1L), eq(1L)); + Mockito.doReturn(true).when(virtualMachineManagerImpl) + .isDiskOfferingSuitableForVm(eq(vmInstanceMock), any(VirtualMachineProfile.class), + eq(1L), eq(1L), eq(1L), eq(2L)); + Map result = virtualMachineManagerImpl.getDiskOfferingSuitabilityForVm(1L, diskOfferingIds); + assertTrue(MapUtils.isNotEmpty(result)); + assertEquals(2, result.keySet().size()); + assertFalse(result.get(1L)); + assertTrue(result.get(2L)); + } } diff --git a/engine/orchestration/src/test/java/com/cloud/vm/VmWorkRebootTest.java b/engine/orchestration/src/test/java/com/cloud/vm/VmWorkRebootTest.java new file mode 100644 index 00000000000..75ffd94600a --- /dev/null +++ b/engine/orchestration/src/test/java/com/cloud/vm/VmWorkRebootTest.java @@ -0,0 +1,42 @@ +// 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.vm; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper; +import org.junit.Assert; +import org.junit.Test; + +public class VmWorkRebootTest { + + @Test + public void testToString() { + VmWork vmWork = new VmWork(1l, 1l, 1l, "testhandler"); + Map params = new HashMap<>(); + String lastHost = "rO0ABXQABHRydWU"; + String lastHostSerialized = JobSerializerHelper.toObjectSerializedString(lastHost); + params.put(VirtualMachineProfile.Param.ConsiderLastHost, lastHost); + params.put(VirtualMachineProfile.Param.VmPassword, "rO0ABXQADnNhdmVkX3Bhc3N3b3Jk"); + VmWorkReboot workInfo = new VmWorkReboot(vmWork, params); + String expectedVmWorkRebootStr = "{\"accountId\":1,\"vmId\":1,\"handlerName\":\"testhandler\",\"userId\":1,\"rawParams\":{\"ConsiderLastHost\":\"" + lastHostSerialized + "\"}}"; + + String vmWorkRebootStr = workInfo.toString(); + Assert.assertEquals(expectedVmWorkRebootStr, vmWorkRebootStr); + } +} diff --git a/engine/orchestration/src/test/java/com/cloud/vm/VmWorkStartTest.java b/engine/orchestration/src/test/java/com/cloud/vm/VmWorkStartTest.java new file mode 100644 index 00000000000..a0644b1976f --- /dev/null +++ b/engine/orchestration/src/test/java/com/cloud/vm/VmWorkStartTest.java @@ -0,0 +1,57 @@ +// 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.vm; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.cloudstack.framework.jobs.impl.JobSerializerHelper; +import org.junit.Assert; +import org.junit.Test; + +public class VmWorkStartTest { + + @Test + public void testToStringWithParams() { + VmWork vmWork = new VmWork(1l, 1l, 1l, "testhandler"); + VmWorkStart workInfo = new VmWorkStart(vmWork); + Map params = new HashMap<>(); + String lastHost = "rO0ABXQABHRydWU"; + String lastHostSerialized = JobSerializerHelper.toObjectSerializedString(lastHost); + params.put(VirtualMachineProfile.Param.ConsiderLastHost, lastHost); + params.put(VirtualMachineProfile.Param.VmPassword, "rO0ABXQADnNhdmVkX3Bhc3N3b3Jk"); + workInfo.setParams(params); + String expectedVmWorkStartStr = "{\"accountId\":1,\"dcId\":0,\"vmId\":1,\"handlerName\":\"testhandler\",\"userId\":1,\"rawParams\":{\"ConsiderLastHost\":\"" + lastHostSerialized + "\"}}"; + + String vmWorkStartStr = workInfo.toString(); + Assert.assertEquals(expectedVmWorkStartStr, vmWorkStartStr); + } + + @Test + public void testToStringWithRawParams() { + VmWork vmWork = new VmWork(1l, 1l, 1l, "testhandler"); + VmWorkStart workInfo = new VmWorkStart(vmWork); + Map rawParams = new HashMap<>(); + rawParams.put(VirtualMachineProfile.Param.ConsiderLastHost.getName(), "rO0ABXQABHRydWU"); + rawParams.put(VirtualMachineProfile.Param.VmPassword.getName(), "rO0ABXQADnNhdmVkX3Bhc3N3b3Jk"); + workInfo.setRawParams(rawParams); + String expectedVmWorkStartStr = "{\"accountId\":1,\"dcId\":0,\"vmId\":1,\"handlerName\":\"testhandler\",\"userId\":1,\"rawParams\":{\"ConsiderLastHost\":\"rO0ABXQABHRydWU\"}}"; + + String vmWorkStartStr = workInfo.toString(); + Assert.assertEquals(expectedVmWorkStartStr, vmWorkStartStr); + } +} diff --git a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java index 0aed5a2c259..d1532cdbef1 100644 --- a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java +++ b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java @@ -29,13 +29,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import com.cloud.dc.DataCenter; +import com.cloud.network.IpAddressManager; +import com.cloud.utils.Pair; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import com.cloud.api.query.dao.DomainRouterJoinDao; @@ -90,7 +92,6 @@ import junit.framework.TestCase; */ @RunWith(JUnit4.class) public class NetworkOrchestratorTest extends TestCase { - static final Logger s_logger = Logger.getLogger(NetworkOrchestratorTest.class); NetworkOrchestrator testOrchastrator = Mockito.spy(new NetworkOrchestrator()); @@ -125,6 +126,7 @@ public class NetworkOrchestratorTest extends TestCase { testOrchastrator.routerNetworkDao = mock(RouterNetworkDao.class); testOrchastrator._vpcMgr = mock(VpcManager.class); testOrchastrator.routerJoinDao = mock(DomainRouterJoinDao.class); + testOrchastrator._ipAddrMgr = mock(IpAddressManager.class); DhcpServiceProvider provider = mock(DhcpServiceProvider.class); Map capabilities = new HashMap(); @@ -133,7 +135,7 @@ public class NetworkOrchestratorTest extends TestCase { when(provider.getCapabilities()).thenReturn(services); capabilities.put(Network.Capability.DhcpAccrossMultipleSubnets, "true"); - when(testOrchastrator._ntwkSrvcDao.getProviderForServiceInNetwork(Matchers.anyLong(), Matchers.eq(Service.Dhcp))).thenReturn(dhcpProvider); + when(testOrchastrator._ntwkSrvcDao.getProviderForServiceInNetwork(ArgumentMatchers.anyLong(), ArgumentMatchers.eq(Service.Dhcp))).thenReturn(dhcpProvider); when(testOrchastrator._networkModel.getElementImplementingProvider(dhcpProvider)).thenReturn(provider); when(guru.getName()).thenReturn(guruName); @@ -708,4 +710,134 @@ public class NetworkOrchestratorTest extends TestCase { Assert.assertEquals(ip6Dns[0], profile.getIPv6Dns1()); Assert.assertEquals(ip6Dns[1], profile.getIPv6Dns2()); } + + @Test + public void testGetNetworkGatewayAndNetmaskForNicImportAdvancedZone() { + Network network = Mockito.mock(Network.class); + DataCenter dataCenter = Mockito.mock(DataCenter.class); + String ipAddress = "10.1.1.10"; + + String networkGateway = "10.1.1.1"; + String networkNetmask = "255.255.255.0"; + String networkCidr = "10.1.1.0/24"; + Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Advanced); + Mockito.when(network.getGateway()).thenReturn(networkGateway); + Mockito.when(network.getCidr()).thenReturn(networkCidr); + Pair pair = testOrchastrator.getNetworkGatewayAndNetmaskForNicImport(network, dataCenter, ipAddress); + Assert.assertNotNull(pair); + Assert.assertEquals(networkGateway, pair.first()); + Assert.assertEquals(networkNetmask, pair.second()); + } + + @Test + public void testGetNetworkGatewayAndNetmaskForNicImportBasicZone() { + Network network = Mockito.mock(Network.class); + DataCenter dataCenter = Mockito.mock(DataCenter.class); + IPAddressVO ipAddressVO = Mockito.mock(IPAddressVO.class); + String ipAddress = "172.1.1.10"; + + String defaultNetworkGateway = "172.1.1.1"; + String defaultNetworkNetmask = "255.255.255.0"; + VlanVO vlan = Mockito.mock(VlanVO.class); + Mockito.when(vlan.getVlanGateway()).thenReturn(defaultNetworkGateway); + Mockito.when(vlan.getVlanNetmask()).thenReturn(defaultNetworkNetmask); + Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic); + Mockito.when(ipAddressVO.getVlanId()).thenReturn(1L); + Mockito.when(testOrchastrator._vlanDao.findById(1L)).thenReturn(vlan); + Mockito.when(testOrchastrator._ipAddressDao.findByIp(ipAddress)).thenReturn(ipAddressVO); + Pair pair = testOrchastrator.getNetworkGatewayAndNetmaskForNicImport(network, dataCenter, ipAddress); + Assert.assertNotNull(pair); + Assert.assertEquals(defaultNetworkGateway, pair.first()); + Assert.assertEquals(defaultNetworkNetmask, pair.second()); + } + + @Test + public void testGetGuestIpForNicImportL2Network() { + Network network = Mockito.mock(Network.class); + DataCenter dataCenter = Mockito.mock(DataCenter.class); + Network.IpAddresses ipAddresses = Mockito.mock(Network.IpAddresses.class); + Mockito.when(network.getGuestType()).thenReturn(GuestType.L2); + Assert.assertNull(testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses)); + } + + @Test + public void testGetGuestIpForNicImportAdvancedZone() { + Network network = Mockito.mock(Network.class); + DataCenter dataCenter = Mockito.mock(DataCenter.class); + Network.IpAddresses ipAddresses = Mockito.mock(Network.IpAddresses.class); + Mockito.when(network.getGuestType()).thenReturn(GuestType.Isolated); + Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Advanced); + String ipAddress = "10.1.10.10"; + Mockito.when(ipAddresses.getIp4Address()).thenReturn(ipAddress); + Mockito.when(testOrchastrator._ipAddrMgr.acquireGuestIpAddress(network, ipAddress)).thenReturn(ipAddress); + String guestIp = testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses); + Assert.assertEquals(ipAddress, guestIp); + } + + @Test + public void testGetGuestIpForNicImportBasicZoneAutomaticIP() { + Network network = Mockito.mock(Network.class); + DataCenter dataCenter = Mockito.mock(DataCenter.class); + Network.IpAddresses ipAddresses = Mockito.mock(Network.IpAddresses.class); + Mockito.when(network.getGuestType()).thenReturn(GuestType.Shared); + Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic); + long networkId = 1L; + long dataCenterId = 1L; + String freeIp = "172.10.10.10"; + IPAddressVO ipAddressVO = Mockito.mock(IPAddressVO.class); + Ip ip = mock(Ip.class); + Mockito.when(ip.addr()).thenReturn(freeIp); + Mockito.when(ipAddressVO.getAddress()).thenReturn(ip); + Mockito.when(ipAddressVO.getState()).thenReturn(State.Free); + Mockito.when(network.getId()).thenReturn(networkId); + Mockito.when(dataCenter.getId()).thenReturn(dataCenterId); + Mockito.when(testOrchastrator._ipAddressDao.findBySourceNetworkIdAndDatacenterIdAndState(networkId, dataCenterId, State.Free)).thenReturn(ipAddressVO); + String ipAddress = testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses); + Assert.assertEquals(freeIp, ipAddress); + } + + @Test + public void testGetGuestIpForNicImportBasicZoneManualIP() { + Network network = Mockito.mock(Network.class); + DataCenter dataCenter = Mockito.mock(DataCenter.class); + Network.IpAddresses ipAddresses = Mockito.mock(Network.IpAddresses.class); + Mockito.when(network.getGuestType()).thenReturn(GuestType.Shared); + Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic); + long networkId = 1L; + long dataCenterId = 1L; + String requestedIp = "172.10.10.10"; + IPAddressVO ipAddressVO = Mockito.mock(IPAddressVO.class); + Ip ip = mock(Ip.class); + Mockito.when(ip.addr()).thenReturn(requestedIp); + Mockito.when(ipAddressVO.getAddress()).thenReturn(ip); + Mockito.when(ipAddressVO.getState()).thenReturn(State.Free); + Mockito.when(network.getId()).thenReturn(networkId); + Mockito.when(dataCenter.getId()).thenReturn(dataCenterId); + Mockito.when(ipAddresses.getIp4Address()).thenReturn(requestedIp); + Mockito.when(testOrchastrator._ipAddressDao.findByIp(requestedIp)).thenReturn(ipAddressVO); + String ipAddress = testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses); + Assert.assertEquals(requestedIp, ipAddress); + } + + @Test(expected = CloudRuntimeException.class) + public void testGetGuestIpForNicImportBasicUsedIP() { + Network network = Mockito.mock(Network.class); + DataCenter dataCenter = Mockito.mock(DataCenter.class); + Network.IpAddresses ipAddresses = Mockito.mock(Network.IpAddresses.class); + Mockito.when(network.getGuestType()).thenReturn(GuestType.Shared); + Mockito.when(dataCenter.getNetworkType()).thenReturn(DataCenter.NetworkType.Basic); + long networkId = 1L; + long dataCenterId = 1L; + String requestedIp = "172.10.10.10"; + IPAddressVO ipAddressVO = Mockito.mock(IPAddressVO.class); + Ip ip = mock(Ip.class); + Mockito.when(ip.addr()).thenReturn(requestedIp); + Mockito.when(ipAddressVO.getAddress()).thenReturn(ip); + Mockito.when(ipAddressVO.getState()).thenReturn(State.Allocated); + Mockito.when(network.getId()).thenReturn(networkId); + Mockito.when(dataCenter.getId()).thenReturn(dataCenterId); + Mockito.when(ipAddresses.getIp4Address()).thenReturn(requestedIp); + Mockito.when(testOrchastrator._ipAddressDao.findByIp(requestedIp)).thenReturn(ipAddressVO); + testOrchastrator.getSelectedIpForNicImport(network, dataCenter, ipAddresses); + } } diff --git a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestratorTest.java b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestratorTest.java index b2f4c436ca3..e817f61a098 100644 --- a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestratorTest.java +++ b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestratorTest.java @@ -18,6 +18,13 @@ package org.apache.cloudstack.engine.orchestration; import java.util.ArrayList; +import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; +import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore; +import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; import org.apache.commons.lang3.ObjectUtils; import org.junit.Assert; import org.junit.Before; @@ -31,14 +38,22 @@ import org.mockito.junit.MockitoJUnitRunner; import org.mockito.stubbing.Answer; import com.cloud.configuration.Resource; +import com.cloud.exception.StorageAccessException; +import com.cloud.host.Host; +import com.cloud.host.HostVO; import com.cloud.storage.VolumeVO; import com.cloud.user.ResourceLimitService; +import com.cloud.utils.exception.CloudRuntimeException; @RunWith(MockitoJUnitRunner.class) public class VolumeOrchestratorTest { @Mock protected ResourceLimitService resourceLimitMgr; + @Mock + protected VolumeService volumeService; + @Mock + protected VolumeDataFactory volumeDataFactory; @Spy @InjectMocks @@ -100,4 +115,44 @@ public class VolumeOrchestratorTest { public void testCheckAndUpdateVolumeAccountResourceCountLessSize() { runCheckAndUpdateVolumeAccountResourceCountTest(20L, 10L); } + + @Test + public void testGrantVolumeAccessToHostIfNeededDriverNoNeed() { + PrimaryDataStore store = Mockito.mock(PrimaryDataStore.class); + PrimaryDataStoreDriver driver = Mockito.mock(PrimaryDataStoreDriver.class); + Mockito.when(driver.volumesRequireGrantAccessWhenUsed()).thenReturn(false); + Mockito.when(store.getDriver()).thenReturn(driver); + volumeOrchestrator.grantVolumeAccessToHostIfNeeded(store, 1L, + Mockito.mock(HostVO.class), ""); + Mockito.verify(volumeService, Mockito.never()) + .grantAccess(Mockito.any(DataObject.class), Mockito.any(Host.class), Mockito.any(DataStore.class)); + } + + @Test + public void testGrantVolumeAccessToHostIfNeededDriverNeeds() { + PrimaryDataStore store = Mockito.mock(PrimaryDataStore.class); + PrimaryDataStoreDriver driver = Mockito.mock(PrimaryDataStoreDriver.class); + Mockito.when(driver.volumesRequireGrantAccessWhenUsed()).thenReturn(true); + Mockito.when(store.getDriver()).thenReturn(driver); + Mockito.when(volumeDataFactory.getVolume(Mockito.anyLong())).thenReturn(Mockito.mock(VolumeInfo.class)); + Mockito.doReturn(true).when(volumeService) + .grantAccess(Mockito.any(DataObject.class), Mockito.any(Host.class), Mockito.any(DataStore.class)); + volumeOrchestrator.grantVolumeAccessToHostIfNeeded(store, 1L, + Mockito.mock(HostVO.class), ""); + Mockito.verify(volumeService, Mockito.times(1)) + .grantAccess(Mockito.any(DataObject.class), Mockito.any(Host.class), Mockito.any(DataStore.class)); + } + + @Test(expected = StorageAccessException.class) + public void testGrantVolumeAccessToHostIfNeededDriverNeedsButException() { + PrimaryDataStore store = Mockito.mock(PrimaryDataStore.class); + PrimaryDataStoreDriver driver = Mockito.mock(PrimaryDataStoreDriver.class); + Mockito.when(driver.volumesRequireGrantAccessWhenUsed()).thenReturn(true); + Mockito.when(store.getDriver()).thenReturn(driver); + Mockito.when(volumeDataFactory.getVolume(Mockito.anyLong())).thenReturn(Mockito.mock(VolumeInfo.class)); + Mockito.doThrow(CloudRuntimeException.class).when(volumeService) + .grantAccess(Mockito.any(DataObject.class), Mockito.any(Host.class), Mockito.any(DataStore.class)); + volumeOrchestrator.grantVolumeAccessToHostIfNeeded(store, 1L, + Mockito.mock(HostVO.class), ""); + } } diff --git a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java index c9e6424a345..c566ad87f38 100644 --- a/engine/orchestration/src/test/java/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java +++ b/engine/orchestration/src/test/java/org/apache/cloudstack/engine/provisioning/test/ProvisioningTest.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.engine.provisioning.test; import java.util.HashMap; -import java.util.UUID; import junit.framework.TestCase; @@ -30,11 +29,10 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.apache.cloudstack.engine.datacenter.entity.api.ClusterEntity; import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity.State; @@ -51,7 +49,6 @@ import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.EngineHostDao; import org.apache.cloudstack.engine.datacenter.entity.api.db.dao.EngineHostPodDao; import org.apache.cloudstack.engine.service.api.ProvisioningService; -import com.cloud.dc.DataCenter.NetworkType; import static org.mockito.ArgumentMatchers.any; diff --git a/engine/orchestration/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/orchestration/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/orchestration/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/pom.xml b/engine/pom.xml index 6ecfb4bebf4..5e52544aeca 100644 --- a/engine/pom.xml +++ b/engine/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/engine/schema/pom.xml b/engine/schema/pom.xml index 4ffef5c532e..b1868f27837 100644 --- a/engine/schema/pom.xml +++ b/engine/schema/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml @@ -49,8 +49,8 @@ ${project.version} - mysql - mysql-connector-java + com.mysql + mysql-connector-j org.ini4j @@ -101,8 +101,10 @@ for (template in templateList) { def data = lines.findAll { it.contains(template) } if (data != null) { - def hypervisor = template.tokenize('-')[-1] - pom.properties["$hypervisor" + ".checksum"] = data[0].tokenize(' ')[0] + if (data.size() > 0) { + def hypervisor = template.tokenize('-')[-1] + pom.properties["$hypervisor" + ".checksum"] = data[0].tokenize(' ')[0] + } } } diff --git a/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java b/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java index 50c40134a91..132fd3fe5a2 100644 --- a/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java +++ b/engine/schema/src/main/java/com/cloud/capacity/CapacityVO.java @@ -80,6 +80,9 @@ public class CapacityVO implements Capacity { @Transient private Long allocatedCapacity; + @Transient + private String tag; + public CapacityVO() { } @@ -221,6 +224,15 @@ public class CapacityVO implements Capacity { this.allocatedCapacity = allocatedCapacity; } + @Override + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + @Override public String getUuid() { return null; //To change body of implemented methods use File | Settings | File Templates. diff --git a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java index 459a63a7ba1..9616f31d0c5 100644 --- a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java +++ b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDao.java @@ -44,6 +44,8 @@ public interface CapacityDao extends GenericDao { List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId); + List findFilteredCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, List hostIds, List poolIds); + List listPodsByHostCapacities(long zoneId, int requiredCpu, long requiredRam, short capacityType); Pair, Map> orderPodsByAggregateCapacity(long zoneId, short capacityType); @@ -51,7 +53,8 @@ public interface CapacityDao extends GenericDao { List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, String resourceState); - List listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, Long clusterId, int level, Long limit); + List listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, + Long clusterId, int level, List hostIds, List poolIds, Long limit); void updateCapacityState(Long dcId, Long podId, Long clusterId, Long hostId, String capacityState, short[] capacityType); diff --git a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java index 302ffd8e760..3acae985af4 100644 --- a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java @@ -26,12 +26,11 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; -import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Component; - import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; import com.cloud.capacity.Capacity; import com.cloud.capacity.CapacityVO; @@ -51,7 +50,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class CapacityDaoImpl extends GenericDaoBase implements CapacityDao { - private static final Logger s_logger = Logger.getLogger(CapacityDaoImpl.class); private static final String ADD_ALLOCATED_SQL = "UPDATE `cloud`.`op_host_capacity` SET used_capacity = used_capacity + ? WHERE host_id = ? AND capacity_type = ?"; private static final String SUBTRACT_ALLOCATED_SQL = @@ -341,7 +339,8 @@ public class CapacityDaoImpl extends GenericDaoBase implements } @Override - public List listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, Long clusterId, int level, Long limit) { + public List listCapacitiesGroupedByLevelAndType(Integer capacityType, Long zoneId, Long podId, + Long clusterId, int level, List hostIds, List poolIds, Long limit) { StringBuilder finalQuery = new StringBuilder(); TransactionLegacy txn = TransactionLegacy.currentTxn(); @@ -380,6 +379,18 @@ public class CapacityDaoImpl extends GenericDaoBase implements finalQuery.append(" AND capacity_type = ?"); resourceIdList.add(capacityType.longValue()); } + if (CollectionUtils.isNotEmpty(hostIds)) { + finalQuery.append(String.format(" AND capacity.host_id IN (%s)", StringUtils.join(hostIds, ","))); + if (capacityType == null) { + finalQuery.append(String.format(" AND capacity_type NOT IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ","))); + } + } + if (CollectionUtils.isNotEmpty(poolIds)) { + finalQuery.append(String.format(" AND capacity.host_id IN (%s)", StringUtils.join(poolIds, ","))); + if (capacityType == null) { + finalQuery.append(String.format(" AND capacity_type IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ","))); + } + } switch (level) { case 1: // List all the capacities grouped by zone, capacity Type @@ -463,8 +474,37 @@ public class CapacityDaoImpl extends GenericDaoBase implements } } + protected String getHostAndPoolConditionForFilteredCapacity(Integer capacityType, List hostIds, List poolIds) { + StringBuilder sql = new StringBuilder(); + if (CollectionUtils.isEmpty(hostIds) && CollectionUtils.isEmpty(poolIds)) { + return ""; + } + sql.append(" AND ("); + boolean hostConditionAdded = false; + if (CollectionUtils.isNotEmpty(hostIds) && (capacityType == null || !Capacity.STORAGE_CAPACITY_TYPES.contains(capacityType.shortValue()))) { + sql.append(String.format("(capacity.host_id IN (%s)", StringUtils.join(hostIds, ","))); + if (capacityType == null) { + sql.append(String.format(" AND capacity_type NOT IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ","))); + } + sql.append(")"); + hostConditionAdded = true; + } + if (CollectionUtils.isNotEmpty(poolIds) && (capacityType == null || Capacity.STORAGE_CAPACITY_TYPES.contains(capacityType.shortValue()))) { + if (hostConditionAdded) { + sql.append(" OR "); + } + sql.append(String.format("(capacity.host_id IN (%s)", StringUtils.join(poolIds, ","))); + if (capacityType == null || Capacity.STORAGE_CAPACITY_TYPES.contains(capacityType.shortValue())) { + sql.append(String.format(" AND capacity_type IN (%s)", StringUtils.join(Capacity.STORAGE_CAPACITY_TYPES, ","))); + } + sql.append(")"); + } + sql.append(")"); + return sql.toString(); + } + @Override - public List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId) { + public List findFilteredCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId, List hostIds, List poolIds) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; @@ -518,6 +558,8 @@ public class CapacityDaoImpl extends GenericDaoBase implements resourceIdList.add(capacityType.longValue()); } + sql.append(getHostAndPoolConditionForFilteredCapacity(capacityType, hostIds, poolIds)); + if (podId == null && clusterId == null) { sql.append(" GROUP BY capacity_type, data_center_id"); } else { @@ -593,6 +635,11 @@ public class CapacityDaoImpl extends GenericDaoBase implements } } + @Override + public List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId) { + return findFilteredCapacityBy(capacityType, zoneId, podId, clusterId, null, null); + } + public void updateAllocated(Long hostId, long allocatedAmount, short capacityType, boolean add) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; @@ -612,7 +659,7 @@ public class CapacityDaoImpl extends GenericDaoBase implements txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Exception updating capacity for host: " + hostId, e); + logger.warn("Exception updating capacity for host: " + hostId, e); } } @@ -704,6 +751,7 @@ public class CapacityDaoImpl extends GenericDaoBase implements public Long clusterId; public Long podId; public Long dcId; + public String tag; public SummedCapacity() { } @@ -792,6 +840,14 @@ public class CapacityDaoImpl extends GenericDaoBase implements public void setAllocatedCapacity(Long sumAllocated) { this.sumAllocated = sumAllocated; } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } } @Override @@ -1126,7 +1182,7 @@ public class CapacityDaoImpl extends GenericDaoBase implements pstmt.executeUpdate(); } catch (Exception e) { - s_logger.warn("Error updating CapacityVO", e); + logger.warn("Error updating CapacityVO", e); } } @@ -1146,7 +1202,7 @@ public class CapacityDaoImpl extends GenericDaoBase implements return rs.getFloat(1); } } catch (Exception e) { - s_logger.warn("Error checking cluster threshold", e); + logger.warn("Error checking cluster threshold", e); } return 0; } diff --git a/engine/schema/src/main/java/com/cloud/certificate/dao/CertificateDaoImpl.java b/engine/schema/src/main/java/com/cloud/certificate/dao/CertificateDaoImpl.java index 9544804284e..99ba36f22b9 100644 --- a/engine/schema/src/main/java/com/cloud/certificate/dao/CertificateDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/certificate/dao/CertificateDaoImpl.java @@ -17,7 +17,6 @@ package com.cloud.certificate.dao; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.certificate.CertificateVO; @@ -28,7 +27,6 @@ import com.cloud.utils.db.GenericDaoBase; @DB public class CertificateDaoImpl extends GenericDaoBase implements CertificateDao { - private static final Logger s_logger = Logger.getLogger(CertificateDaoImpl.class); public CertificateDaoImpl() { @@ -42,7 +40,7 @@ public class CertificateDaoImpl extends GenericDaoBase impl update(cert.getId(), cert); return cert.getId(); } catch (Exception e) { - s_logger.warn("Unable to read the certificate: " + e); + logger.warn("Unable to read the certificate: " + e); return new Long(0); } } diff --git a/engine/schema/src/main/java/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java b/engine/schema/src/main/java/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java index e1c0dbd9e47..861dbeb1df4 100644 --- a/engine/schema/src/main/java/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java @@ -21,7 +21,6 @@ import java.util.List; import javax.annotation.PostConstruct; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.cluster.agentlb.HostTransferMapVO; @@ -34,7 +33,6 @@ import com.cloud.utils.db.SearchCriteria; @Component @DB public class HostTransferMapDaoImpl extends GenericDaoBase implements HostTransferMapDao { - private static final Logger s_logger = Logger.getLogger(HostTransferMapDaoImpl.class); protected SearchBuilder AllFieldsSearch; protected SearchBuilder IntermediateStateSearch; diff --git a/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java b/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java index ae8f3822704..9e39a608f9e 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java +++ b/engine/schema/src/main/java/com/cloud/configuration/ResourceCountVO.java @@ -47,10 +47,13 @@ public class ResourceCountVO implements ResourceCount { @Column(name = "count") private long count; + @Column(name = "tag") + private String tag; + public ResourceCountVO() { } - public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwnerType ownerType) { + public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwnerType ownerType, String tag) { this.type = type; this.count = count; @@ -59,6 +62,11 @@ public class ResourceCountVO implements ResourceCount { } else if (ownerType == ResourceOwnerType.Domain) { this.domainId = ownerId; } + this.tag = tag; + } + + public ResourceCountVO(ResourceType type, long count, long ownerId, ResourceOwnerType ownerType) { + this(type, count, ownerId, ownerType, null); } @Override @@ -99,7 +107,7 @@ public class ResourceCountVO implements ResourceCount { @Override public String toString() { - return new StringBuilder("REsourceCount[").append("-") + return new StringBuilder("ResourceCount[").append("-") .append(id) .append("-") .append(type) @@ -107,6 +115,8 @@ public class ResourceCountVO implements ResourceCount { .append(accountId) .append("-") .append(domainId) + .append("-") + .append(tag) .append("]") .toString(); } @@ -136,4 +146,13 @@ public class ResourceCountVO implements ResourceCount { public void setAccountId(Long accountId) { this.accountId = accountId; } + + @Override + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java b/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java index 39217091975..1619537ae74 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java +++ b/engine/schema/src/main/java/com/cloud/configuration/ResourceLimitVO.java @@ -47,10 +47,13 @@ public class ResourceLimitVO implements ResourceLimit { @Column(name = "max") private Long max; + @Column(name = "tag") + private String tag; + public ResourceLimitVO() { } - public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType) { + public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType, String tag) { this.type = type; this.max = max; @@ -59,6 +62,11 @@ public class ResourceLimitVO implements ResourceLimit { } else if (ownerType == ResourceOwnerType.Domain) { this.domainId = ownerId; } + this.tag = tag; + } + + public ResourceLimitVO(ResourceCount.ResourceType type, Long max, long ownerId, ResourceOwnerType ownerType) { + this(type, max, ownerId, ownerType, null); } @Override @@ -123,4 +131,12 @@ public class ResourceLimitVO implements ResourceLimit { this.accountId = accountId; } + @Override + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } } diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java index 28f2a536071..b978cc04bfa 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java +++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDao.java @@ -26,18 +26,20 @@ import com.cloud.utils.db.GenericDao; public interface ResourceCountDao extends GenericDao { /** - * @param domainId the id of the domain to get the resource count + * @param ownerId the id of the owner to get the resource count * @param type the type of resource (e.g. user_vm, public_ip, volume) + * @param tag for the type of resource * @return the count of resources in use for the given type and domain */ - long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type); + long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag); /** - * @param domainId the id of the domain to set the resource count + * @param ownerId the id of the owner to set the resource count * @param type the type of resource (e.g. user_vm, public_ip, volume) - * @param the count of resources in use for the given type and domain + * @param tag the tag for the type of resource + * @param count the count of resources in use for the given type and domain */ - void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, long count); + void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag, long count); boolean updateById(long id, boolean increment, long delta); @@ -45,13 +47,18 @@ public interface ResourceCountDao extends GenericDao { List listByOwnerId(long ownerId, ResourceOwnerType ownerType); - ResourceCountVO findByOwnerAndType(long ownerId, ResourceOwnerType ownerType, ResourceType type); + ResourceCountVO findByOwnerAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag); + + List findByOwnersAndTypeAndTag(List ownerIdList, ResourceOwnerType ownerType, + ResourceType type, String tag); List listResourceCountByOwnerType(ResourceOwnerType ownerType); - Set listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type); + Set listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag); - Set listRowsToUpdateForDomain(long domainId, ResourceType type); + boolean updateCountByDeltaForIds(List ids, boolean increment, long delta); + + Set listRowsToUpdateForDomain(long domainId, ResourceType type, String tag); long removeEntriesByOwner(long ownerId, ResourceOwnerType ownerType); @@ -68,4 +75,8 @@ public interface ResourceCountDao extends GenericDao { * Side note: This method is not using the "resource_count" table. It is executing the actual count instead. */ long countMemoryAllocatedToAccount(long accountId); + + void removeResourceCountsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List types, List tags); + + List lockRows(Set ids); } diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java index ca6f13d2d64..65d7fed2d1a 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceCountDaoImpl.java @@ -20,13 +20,18 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.inject.Inject; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import com.cloud.configuration.Resource; @@ -37,6 +42,7 @@ import com.cloud.configuration.ResourceLimit; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import com.cloud.user.AccountVO; +import com.cloud.user.ResourceLimitService; import com.cloud.user.dao.AccountDao; import com.cloud.utils.db.DB; import com.cloud.utils.db.GenericDaoBase; @@ -49,24 +55,49 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class ResourceCountDaoImpl extends GenericDaoBase implements ResourceCountDao { private final SearchBuilder TypeSearch; - + private final SearchBuilder TypeNullTagSearch; + private final SearchBuilder NonMatchingTagsSearch; private final SearchBuilder AccountSearch; private final SearchBuilder DomainSearch; + private final SearchBuilder IdsSearch; @Inject private DomainDao _domainDao; @Inject private AccountDao _accountDao; + protected static final String INCREMENT_COUNT_BY_IDS_SQL = "UPDATE `cloud`.`resource_count` SET `count` = `count` + ? WHERE `id` IN (?)"; + protected static final String DECREMENT_COUNT_BY_IDS_SQL = "UPDATE `cloud`.`resource_count` SET `count` = `count` - ? WHERE `id` IN (?)"; + public ResourceCountDaoImpl() { TypeSearch = createSearchBuilder(); TypeSearch.and("type", TypeSearch.entity().getType(), SearchCriteria.Op.EQ); - TypeSearch.and("accountId", TypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ); - TypeSearch.and("domainId", TypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + TypeSearch.and("accountId", TypeSearch.entity().getAccountId(), SearchCriteria.Op.IN); + TypeSearch.and("domainId", TypeSearch.entity().getDomainId(), SearchCriteria.Op.IN); + TypeSearch.and("tag", TypeSearch.entity().getTag(), SearchCriteria.Op.EQ); TypeSearch.done(); + TypeNullTagSearch = createSearchBuilder(); + TypeNullTagSearch.and("type", TypeNullTagSearch.entity().getType(), SearchCriteria.Op.EQ); + TypeNullTagSearch.and("accountId", TypeNullTagSearch.entity().getAccountId(), SearchCriteria.Op.IN); + TypeNullTagSearch.and("domainId", TypeNullTagSearch.entity().getDomainId(), SearchCriteria.Op.IN); + TypeNullTagSearch.and("tag", TypeNullTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + TypeNullTagSearch.done(); + + NonMatchingTagsSearch = createSearchBuilder(); + NonMatchingTagsSearch.and("accountId", NonMatchingTagsSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + NonMatchingTagsSearch.and("domainId", NonMatchingTagsSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + NonMatchingTagsSearch.and("types", NonMatchingTagsSearch.entity().getType(), SearchCriteria.Op.IN); + NonMatchingTagsSearch.and("tagNotNull", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NNULL); + NonMatchingTagsSearch.and("tags", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NIN); + NonMatchingTagsSearch.done(); + AccountSearch = createSearchBuilder(); DomainSearch = createSearchBuilder(); + + IdsSearch = createSearchBuilder(); + IdsSearch.and("id", IdsSearch.entity().getId(), SearchCriteria.Op.IN); + IdsSearch.done(); } @PostConstruct @@ -85,24 +116,40 @@ public class ResourceCountDaoImpl extends GenericDaoBase } @Override - public ResourceCountVO findByOwnerAndType(long ownerId, ResourceOwnerType ownerType, ResourceType type) { - SearchCriteria sc = TypeSearch.create(); - sc.setParameters("type", type); - - if (ownerType == ResourceOwnerType.Account) { - sc.setParameters("accountId", ownerId); - return findOneIncludingRemovedBy(sc); - } else if (ownerType == ResourceOwnerType.Domain) { - sc.setParameters("domainId", ownerId); - return findOneIncludingRemovedBy(sc); + public ResourceCountVO findByOwnerAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag) { + List resourceCounts = findByOwnersAndTypeAndTag(List.of(ownerId), ownerType, type, tag); + if (CollectionUtils.isNotEmpty(resourceCounts)) { + return resourceCounts.get(0); } else { return null; } } @Override - public long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type) { - ResourceCountVO vo = findByOwnerAndType(ownerId, ownerType, type); + public List findByOwnersAndTypeAndTag(List ownerIdList, ResourceOwnerType ownerType, ResourceType type, String tag) { + if (CollectionUtils.isEmpty(ownerIdList)) { + return new ArrayList<>(); + } + SearchCriteria sc = tag != null ? TypeSearch.create() : TypeNullTagSearch.create(); + sc.setParameters("type", type); + if (tag != null) { + sc.setParameters("tag", tag); + } + + if (ownerType == ResourceOwnerType.Account) { + sc.setParameters("accountId", ownerIdList.toArray()); + return listIncludingRemovedBy(sc); + } else if (ownerType == ResourceOwnerType.Domain) { + sc.setParameters("domainId", ownerIdList.toArray()); + return listIncludingRemovedBy(sc); + } else { + return new ArrayList<>(); + } + } + + @Override + public long getResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag) { + ResourceCountVO vo = findByOwnerAndTypeAndTag(ownerId, ownerType, type, tag); if (vo != null) { return vo.getCount(); } else { @@ -111,8 +158,8 @@ public class ResourceCountDaoImpl extends GenericDaoBase } @Override - public void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, long count) { - ResourceCountVO resourceCountVO = findByOwnerAndType(ownerId, ownerType, type); + public void setResourceCount(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag, long count) { + ResourceCountVO resourceCountVO = findByOwnerAndTypeAndTag(ownerId, ownerType, type, tag); if (resourceCountVO != null && count != resourceCountVO.getCount()) { resourceCountVO.setCount(count); update(resourceCountVO.getId(), resourceCountVO); @@ -129,38 +176,79 @@ public class ResourceCountDaoImpl extends GenericDaoBase } @Override - public Set listRowsToUpdateForDomain(long domainId, ResourceType type) { + public boolean updateCountByDeltaForIds(List ids, boolean increment, long delta) { + if (CollectionUtils.isEmpty(ids)) { + return false; + } + String updateSql = increment ? INCREMENT_COUNT_BY_IDS_SQL : DECREMENT_COUNT_BY_IDS_SQL; + + String poolIdsInStr = ids.stream().map(String::valueOf).collect(Collectors.joining(",", "(", ")")); + String sql = updateSql.replace("(?)", poolIdsInStr); + + final TransactionLegacy txn = TransactionLegacy.currentTxn(); + try(PreparedStatement pstmt = txn.prepareStatement(sql);) { + pstmt.setLong(1, delta); + pstmt.executeUpdate(); + return true; + } catch (SQLException e) { + throw new CloudRuntimeException(e); + } + } + + @Override + public Set listRowsToUpdateForDomain(long domainId, ResourceType type, String tag) { Set rowIds = new HashSet(); Set domainIdsToUpdate = _domainDao.getDomainParentIds(domainId); for (Long domainIdToUpdate : domainIdsToUpdate) { - ResourceCountVO domainCountRecord = findByOwnerAndType(domainIdToUpdate, ResourceOwnerType.Domain, type); + ResourceCountVO domainCountRecord = findByOwnerAndTypeAndTag(domainIdToUpdate, ResourceOwnerType.Domain, type, tag); if (domainCountRecord != null) { rowIds.add(domainCountRecord.getId()); + } else { + if (StringUtils.isNotEmpty(tag)) { + ResourceCountVO resourceCountVO = createTaggedResourceCount(domainIdToUpdate, ResourceOwnerType.Domain, type, tag); + rowIds.add(resourceCountVO.getId()); + } } } return rowIds; } @Override - public Set listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type) { + public Set listAllRowsToUpdate(long ownerId, ResourceOwnerType ownerType, ResourceType type, String tag) { Set rowIds = new HashSet(); if (ownerType == ResourceOwnerType.Account) { //get records for account - ResourceCountVO accountCountRecord = findByOwnerAndType(ownerId, ResourceOwnerType.Account, type); + ResourceCountVO accountCountRecord = findByOwnerAndTypeAndTag(ownerId, ResourceOwnerType.Account, type, tag); if (accountCountRecord != null) { rowIds.add(accountCountRecord.getId()); + } else { + if (StringUtils.isNotEmpty(tag)) { + ResourceCountVO resourceCountVO = createTaggedResourceCount(ownerId, ownerType, type, tag); + rowIds.add(resourceCountVO.getId()); + } } //get records for account's domain and all its parent domains - rowIds.addAll(listRowsToUpdateForDomain(_accountDao.findByIdIncludingRemoved(ownerId).getDomainId(), type)); + rowIds.addAll(listRowsToUpdateForDomain(_accountDao.findByIdIncludingRemoved(ownerId).getDomainId(), type, tag)); } else if (ownerType == ResourceOwnerType.Domain) { - return listRowsToUpdateForDomain(ownerId, type); + rowIds = listRowsToUpdateForDomain(ownerId, type, tag); } return rowIds; } + protected ResourceCountVO createTaggedResourceCount(long ownerId, ResourceLimit.ResourceOwnerType ownerType, ResourceType resourceType, String tag) { + ResourceCountVO taggedResourceCountVO = new ResourceCountVO(resourceType, 0, ownerId, ownerType, tag); + return persist(taggedResourceCountVO); + } + + protected void createTaggedResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType ownerType, ResourceType resourceType, List tags) { + for (String tag : tags) { + createTaggedResourceCount(ownerId, ownerType, resourceType, tag); + } + } + @Override @DB public void createResourceCounts(long ownerId, ResourceLimit.ResourceOwnerType ownerType) { @@ -169,9 +257,23 @@ public class ResourceCountDaoImpl extends GenericDaoBase txn.start(); ResourceType[] resourceTypes = Resource.ResourceType.values(); + List hostTags = new ArrayList<>(); + if (StringUtils.isNotEmpty(ResourceLimitService.ResourceLimitHostTags.value())) { + hostTags = Arrays.asList(ResourceLimitService.ResourceLimitHostTags.value().split(",")); + } + List storageTags = new ArrayList<>(); + if (StringUtils.isNotEmpty(ResourceLimitService.ResourceLimitStorageTags.value())) { + storageTags = Arrays.asList(ResourceLimitService.ResourceLimitStorageTags.value().split(",")); + } for (ResourceType resourceType : resourceTypes) { ResourceCountVO resourceCountVO = new ResourceCountVO(resourceType, 0, ownerId, ownerType); persist(resourceCountVO); + if (ResourceLimitService.HostTagsSupportingTypes.contains(resourceType)) { + createTaggedResourceCounts(ownerId, ownerType, resourceType, hostTags); + } + if (ResourceLimitService.StorageTagsSupportingTypes.contains(resourceType)) { + createTaggedResourceCounts(ownerId, ownerType, resourceType, storageTags); + } } txn.commit(); @@ -266,4 +368,32 @@ public class ResourceCountDaoImpl extends GenericDaoBase } } + @Override + public void removeResourceCountsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List types, List tags) { + SearchCriteria sc = NonMatchingTagsSearch.create(); + if (ObjectUtils.allNotNull(ownerId, ownerType)) { + if (ResourceOwnerType.Account.equals(ownerType)) { + sc.setParameters("accountId", ownerId); + } else { + sc.setParameters("domainId", ownerId); + } + } + if (CollectionUtils.isNotEmpty(types)) { + sc.setParameters("types", types.stream().map(ResourceType::getName).toArray()); + } + if (CollectionUtils.isNotEmpty(tags)) { + sc.setParameters("tags", tags.toArray()); + } + remove(sc); + } + + @Override + public List lockRows(Set ids) { + if (CollectionUtils.isEmpty(ids)) { + return new ArrayList<>(); + } + SearchCriteria sc = IdsSearch.create(); + sc.setParameters("id", ids.toArray()); + return lockRows(sc, null, true); + } } diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java index e47b38340c2..7cdc2aacc3b 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java +++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDao.java @@ -18,6 +18,7 @@ package com.cloud.configuration.dao; import java.util.List; +import com.cloud.configuration.Resource; import com.cloud.configuration.Resource.ResourceOwnerType; import com.cloud.configuration.ResourceCount; import com.cloud.configuration.ResourceLimitVO; @@ -31,7 +32,8 @@ public interface ResourceLimitDao extends GenericDao { ResourceCount.ResourceType getLimitType(String type); - ResourceLimitVO findByOwnerIdAndType(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type); + ResourceLimitVO findByOwnerIdAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type, String tag); long removeEntriesByOwner(Long ownerId, ResourceOwnerType ownerType); + void removeResourceLimitsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List types, List tags); } diff --git a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java index 03c2d2a4624..96523ba9bea 100644 --- a/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/configuration/dao/ResourceLimitDaoImpl.java @@ -20,6 +20,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Component; import com.cloud.configuration.Resource; @@ -33,19 +35,36 @@ import com.cloud.utils.db.SearchCriteria; @Component public class ResourceLimitDaoImpl extends GenericDaoBase implements ResourceLimitDao { - private SearchBuilder IdTypeSearch; + private SearchBuilder IdTypeTagSearch; + private SearchBuilder IdTypeNullTagSearch; + private SearchBuilder NonMatchingTagsSearch; public ResourceLimitDaoImpl() { - IdTypeSearch = createSearchBuilder(); - IdTypeSearch.and("type", IdTypeSearch.entity().getType(), SearchCriteria.Op.EQ); - IdTypeSearch.and("domainId", IdTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ); - IdTypeSearch.and("accountId", IdTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ); - IdTypeSearch.done(); + IdTypeTagSearch = createSearchBuilder(); + IdTypeTagSearch.and("type", IdTypeTagSearch.entity().getType(), SearchCriteria.Op.EQ); + IdTypeTagSearch.and("domainId", IdTypeTagSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + IdTypeTagSearch.and("accountId", IdTypeTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + IdTypeTagSearch.and("tag", IdTypeTagSearch.entity().getTag(), SearchCriteria.Op.EQ); + + IdTypeNullTagSearch = createSearchBuilder(); + IdTypeNullTagSearch.and("type", IdTypeNullTagSearch.entity().getType(), SearchCriteria.Op.EQ); + IdTypeNullTagSearch.and("domainId", IdTypeNullTagSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + IdTypeNullTagSearch.and("accountId", IdTypeNullTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + IdTypeNullTagSearch.and("tag", IdTypeNullTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + IdTypeNullTagSearch.done(); + + NonMatchingTagsSearch = createSearchBuilder(); + NonMatchingTagsSearch.and("accountId", NonMatchingTagsSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + NonMatchingTagsSearch.and("domainId", NonMatchingTagsSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + NonMatchingTagsSearch.and("types", NonMatchingTagsSearch.entity().getType(), SearchCriteria.Op.IN); + NonMatchingTagsSearch.and("tagNotNull", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NNULL); + NonMatchingTagsSearch.and("tags", NonMatchingTagsSearch.entity().getTag(), SearchCriteria.Op.NIN); + NonMatchingTagsSearch.done(); } @Override public List listByOwner(Long ownerId, ResourceOwnerType ownerType) { - SearchCriteria sc = IdTypeSearch.create(); + SearchCriteria sc = IdTypeTagSearch.create(); if (ownerType == ResourceOwnerType.Account) { sc.setParameters("accountId", ownerId); @@ -81,9 +100,12 @@ public class ResourceLimitDaoImpl extends GenericDaoBase } @Override - public ResourceLimitVO findByOwnerIdAndType(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type) { - SearchCriteria sc = IdTypeSearch.create(); + public ResourceLimitVO findByOwnerIdAndTypeAndTag(long ownerId, ResourceOwnerType ownerType, ResourceCount.ResourceType type, String tag) { + SearchCriteria sc = tag != null ? IdTypeTagSearch.create() : IdTypeNullTagSearch.create(); sc.setParameters("type", type); + if (tag != null) { + sc.setParameters("tag", tag); + } if (ownerType == ResourceOwnerType.Account) { sc.setParameters("accountId", ownerId); @@ -98,7 +120,7 @@ public class ResourceLimitDaoImpl extends GenericDaoBase @Override public long removeEntriesByOwner(Long ownerId, ResourceOwnerType ownerType) { - SearchCriteria sc = IdTypeSearch.create(); + SearchCriteria sc = IdTypeTagSearch.create(); if (ownerType == ResourceOwnerType.Account) { sc.setParameters("accountId", ownerId); @@ -109,4 +131,23 @@ public class ResourceLimitDaoImpl extends GenericDaoBase } return 0; } + + @Override + public void removeResourceLimitsForNonMatchingTags(Long ownerId, ResourceOwnerType ownerType, List types, List tags) { + SearchCriteria sc = NonMatchingTagsSearch.create(); + if (ObjectUtils.allNotNull(ownerId, ownerType)) { + if (ResourceOwnerType.Account.equals(ownerType)) { + sc.setParameters("accountId", ownerId); + } else { + sc.setParameters("domainId", ownerId); + } + } + if (CollectionUtils.isNotEmpty(types)) { + sc.setParameters("types", types.stream().map(ResourceType::getName).toArray()); + } + if (CollectionUtils.isNotEmpty(tags)) { + sc.setParameters("tags", tags.toArray()); + } + remove(sc); + } } diff --git a/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java b/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java index f60765e2856..90591690eb0 100644 --- a/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java +++ b/engine/schema/src/main/java/com/cloud/dc/ClusterVO.java @@ -22,8 +22,10 @@ import com.cloud.org.Grouping; import com.cloud.org.Managed.ManagedState; import com.cloud.utils.NumbersUtil; import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.util.HypervisorTypeConverter; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -56,6 +58,7 @@ public class ClusterVO implements Cluster { long podId; @Column(name = "hypervisor_type") + @Convert(converter = HypervisorTypeConverter.class) String hypervisorType; @Column(name = "cluster_type") diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java index 491919bbca7..2776b09c2a1 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterDaoImpl.java @@ -26,7 +26,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenter; @@ -55,7 +54,6 @@ import com.cloud.utils.db.TransactionLegacy; **/ @Component public class DataCenterDaoImpl extends GenericDaoBase implements DataCenterDao { - private static final Logger s_logger = Logger.getLogger(DataCenterDaoImpl.class); protected SearchBuilder NameSearch; protected SearchBuilder ListZonesByDomainIdSearch; @@ -405,7 +403,7 @@ public class DataCenterDaoImpl extends GenericDaoBase implem Long dcId = Long.parseLong(tokenOrIdOrName); return findById(dcId); } catch (NumberFormatException nfe) { - s_logger.debug("Cannot parse " + tokenOrIdOrName + " into long. " + nfe); + logger.debug("Cannot parse " + tokenOrIdOrName + " into long. " + nfe); } } } diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java index e58b08da4c1..c23137095e6 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java @@ -23,7 +23,6 @@ import java.util.List; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenterIpAddressVO; @@ -40,7 +39,6 @@ import com.cloud.utils.net.NetUtils; @Component @DB public class DataCenterIpAddressDaoImpl extends GenericDaoBase implements DataCenterIpAddressDao, Configurable { - private static final Logger s_logger = Logger.getLogger(DataCenterIpAddressDaoImpl.class); private final SearchBuilder AllFieldsSearch; private final GenericSearchBuilder AllIpCount; @@ -169,8 +167,8 @@ public class DataCenterIpAddressDaoImpl extends GenericDaoBase sc = AllFieldsSearch.create(); sc.setParameters("ip", ipAddress); @@ -187,8 +185,8 @@ public class DataCenterIpAddressDaoImpl extends GenericDaoBase implements DataCenterLinkLocalIpAddressDao { - private static final Logger s_logger = Logger.getLogger(DataCenterLinkLocalIpAddressDaoImpl.class); private final SearchBuilder AllFieldsSearch; private final GenericSearchBuilder AllIpCount; @@ -105,8 +103,8 @@ public class DataCenterLinkLocalIpAddressDaoImpl extends GenericDaoBase sc = AllFieldsSearch.create(); sc.setParameters("ip", ipAddress); diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/HostPodDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/HostPodDaoImpl.java index 3fbeb58c56f..f1835067380 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/HostPodDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/HostPodDaoImpl.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.HostPodVO; @@ -38,7 +37,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class HostPodDaoImpl extends GenericDaoBase implements HostPodDao { - private static final Logger s_logger = Logger.getLogger(HostPodDaoImpl.class); protected SearchBuilder DataCenterAndNameSearch; protected SearchBuilder DataCenterIdSearch; @@ -100,7 +98,7 @@ public class HostPodDaoImpl extends GenericDaoBase implements H currentPodCidrSubnets.put(podId, cidrPair); } } catch (SQLException ex) { - s_logger.warn("DB exception " + ex.getMessage(), ex); + logger.warn("DB exception " + ex.getMessage(), ex); return null; } diff --git a/engine/schema/src/main/java/com/cloud/dc/dao/VsphereStoragePolicyDaoImpl.java b/engine/schema/src/main/java/com/cloud/dc/dao/VsphereStoragePolicyDaoImpl.java index 0cdb6ad7422..c99fec5a17a 100644 --- a/engine/schema/src/main/java/com/cloud/dc/dao/VsphereStoragePolicyDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/dc/dao/VsphereStoragePolicyDaoImpl.java @@ -20,7 +20,6 @@ import com.cloud.dc.VsphereStoragePolicyVO; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.util.List; @@ -28,7 +27,6 @@ import java.util.List; @Component public class VsphereStoragePolicyDaoImpl extends GenericDaoBase implements VsphereStoragePolicyDao { - protected static final Logger LOGGER = Logger.getLogger(VsphereStoragePolicyDaoImpl.class); private final SearchBuilder zoneSearch; private final SearchBuilder policySearch; diff --git a/engine/schema/src/main/java/com/cloud/domain/DomainVO.java b/engine/schema/src/main/java/com/cloud/domain/DomainVO.java index 05cd4cc492e..4c36a3401ca 100644 --- a/engine/schema/src/main/java/com/cloud/domain/DomainVO.java +++ b/engine/schema/src/main/java/com/cloud/domain/DomainVO.java @@ -26,14 +26,15 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.db.GenericDao; @Entity @Table(name = "domain") public class DomainVO implements Domain { - public static final Logger s_logger = Logger.getLogger(DomainVO.class.getName()); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/engine/schema/src/main/java/com/cloud/domain/dao/DomainDaoImpl.java b/engine/schema/src/main/java/com/cloud/domain/dao/DomainDaoImpl.java index c020493d8f9..74f2932ca43 100644 --- a/engine/schema/src/main/java/com/cloud/domain/dao/DomainDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/domain/dao/DomainDaoImpl.java @@ -25,7 +25,6 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.domain.Domain; @@ -40,7 +39,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class DomainDaoImpl extends GenericDaoBase implements DomainDao { - private static final Logger s_logger = Logger.getLogger(DomainDaoImpl.class); protected SearchBuilder DomainNameLikeSearch; protected SearchBuilder ParentDomainNameLikeSearch; @@ -112,7 +110,7 @@ public class DomainDaoImpl extends GenericDaoBase implements Dom DomainVO parentDomain = findById(parent); if (parentDomain == null) { - s_logger.error("Unable to load parent domain: " + parent); + logger.error("Unable to load parent domain: " + parent); return null; } @@ -122,7 +120,7 @@ public class DomainDaoImpl extends GenericDaoBase implements Dom parentDomain = this.lockRow(parent, true); if (parentDomain == null) { - s_logger.error("Unable to lock parent domain: " + parent); + logger.error("Unable to lock parent domain: " + parent); return null; } @@ -137,7 +135,7 @@ public class DomainDaoImpl extends GenericDaoBase implements Dom txn.commit(); return domain; } catch (Exception e) { - s_logger.error("Unable to create domain due to " + e.getMessage(), e); + logger.error("Unable to create domain due to " + e.getMessage(), e); txn.rollback(); return null; } @@ -148,23 +146,23 @@ public class DomainDaoImpl extends GenericDaoBase implements Dom public boolean remove(Long id) { // check for any active users / domains assigned to the given domain id and don't remove the domain if there are any if (id != null && id.longValue() == Domain.ROOT_DOMAIN) { - s_logger.error("Can not remove domain " + id + " as it is ROOT domain"); + logger.error("Can not remove domain " + id + " as it is ROOT domain"); return false; } else { if(id == null) { - s_logger.error("Can not remove domain without id."); + logger.error("Can not remove domain without id."); return false; } } DomainVO domain = findById(id); if (domain == null) { - s_logger.info("Unable to remove domain as domain " + id + " no longer exists"); + logger.info("Unable to remove domain as domain " + id + " no longer exists"); return true; } if (domain.getParent() == null) { - s_logger.error("Invalid domain " + id + ", orphan?"); + logger.error("Invalid domain " + id + ", orphan?"); return false; } @@ -177,7 +175,7 @@ public class DomainDaoImpl extends GenericDaoBase implements Dom txn.start(); DomainVO parentDomain = super.lockRow(domain.getParent(), true); if (parentDomain == null) { - s_logger.error("Unable to load parent domain: " + domain.getParent()); + logger.error("Unable to load parent domain: " + domain.getParent()); return false; } @@ -198,7 +196,7 @@ public class DomainDaoImpl extends GenericDaoBase implements Dom txn.commit(); } catch (SQLException ex) { success = false; - s_logger.error("error removing domain: " + id, ex); + logger.error("error removing domain: " + id, ex); txn.rollback(); } return success; @@ -310,7 +308,7 @@ public class DomainDaoImpl extends GenericDaoBase implements Dom return true; } } catch (NumberFormatException nfe) { - s_logger.debug(String.format("Unable to parse %s as domain ID from the list of domain IDs: %s", domainIdList.trim(), domainIdList), nfe); + logger.debug(String.format("Unable to parse %s as domain ID from the list of domain IDs: %s", domainIdList.trim(), domainIdList), nfe); } } return false; diff --git a/engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java b/engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java index d4627904f0b..e748e98900e 100644 --- a/engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java @@ -20,7 +20,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.event.Event.State; @@ -34,7 +33,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class EventDaoImpl extends GenericDaoBase implements EventDao { - public static final Logger s_logger = Logger.getLogger(EventDaoImpl.class.getName()); protected final SearchBuilder CompletedEventSearch; protected final SearchBuilder ToArchiveOrDeleteEventSearch; diff --git a/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDaoImpl.java b/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDaoImpl.java index 519b2ecfe73..fdef509da5b 100644 --- a/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDaoImpl.java @@ -25,7 +25,6 @@ import java.util.TimeZone; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.Vlan; @@ -42,7 +41,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class UsageEventDaoImpl extends GenericDaoBase implements UsageEventDao { - public static final Logger s_logger = Logger.getLogger(UsageEventDaoImpl.class.getName()); private final SearchBuilder latestEventsSearch; private final SearchBuilder IpeventsSearch; @@ -101,8 +99,8 @@ public class UsageEventDaoImpl extends GenericDaoBase implem // Copy events from cloud db to usage db String sql = COPY_EVENTS; if (recentEventId == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("no recent event date, copying all events"); + if (logger.isDebugEnabled()) { + logger.debug("no recent event date, copying all events"); } sql = COPY_ALL_EVENTS; } @@ -120,7 +118,7 @@ public class UsageEventDaoImpl extends GenericDaoBase implem txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error copying events from cloud db to usage db", ex); + logger.error("error copying events from cloud db to usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); @@ -129,8 +127,8 @@ public class UsageEventDaoImpl extends GenericDaoBase implem // Copy event details from cloud db to usage db sql = COPY_EVENT_DETAILS; if (recentEventId == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("no recent event date, copying all event detailss"); + if (logger.isDebugEnabled()) { + logger.debug("no recent event date, copying all event detailss"); } sql = COPY_ALL_EVENT_DETAILS; } @@ -148,7 +146,7 @@ public class UsageEventDaoImpl extends GenericDaoBase implem txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error copying event details from cloud db to usage db", ex); + logger.error("error copying event details from cloud db to usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); @@ -171,7 +169,7 @@ public class UsageEventDaoImpl extends GenericDaoBase implem } return 0; } catch (Exception ex) { - s_logger.error("error getting most recent event id", ex); + logger.error("error getting most recent event id", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); @@ -183,7 +181,7 @@ public class UsageEventDaoImpl extends GenericDaoBase implem try { return listLatestEvents(endDate); } catch (Exception ex) { - s_logger.error("error getting most recent event date", ex); + logger.error("error getting most recent event date", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); @@ -203,7 +201,7 @@ public class UsageEventDaoImpl extends GenericDaoBase implem } return 0; } catch (Exception ex) { - s_logger.error("error getting max event id", ex); + logger.error("error getting max event id", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); diff --git a/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDetailsDaoImpl.java b/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDetailsDaoImpl.java index 43e00efc1ad..37b203b2e88 100644 --- a/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDetailsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/event/dao/UsageEventDetailsDaoImpl.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.event.UsageEventDetailsVO; @@ -31,7 +30,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class UsageEventDetailsDaoImpl extends GenericDaoBase implements UsageEventDetailsDao { - public static final Logger s_logger = Logger.getLogger(UsageEventDetailsDaoImpl.class.getName()); protected final SearchBuilder EventDetailsSearch; protected final SearchBuilder DetailSearch; diff --git a/engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDaoImpl.java b/engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDaoImpl.java index 25f8d245a3b..30535c7e27d 100644 --- a/engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/gpu/dao/HostGpuGroupsDaoImpl.java @@ -19,7 +19,6 @@ package com.cloud.gpu.dao; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.gpu.HostGpuGroupsVO; @@ -30,7 +29,6 @@ import com.cloud.utils.db.SearchCriteria; @Component public class HostGpuGroupsDaoImpl extends GenericDaoBase implements HostGpuGroupsDao { - private static final Logger s_logger = Logger.getLogger(HostGpuGroupsDaoImpl.class); private final SearchBuilder _hostIdGroupNameSearch; private final SearchBuilder _searchByHostId; diff --git a/engine/schema/src/main/java/com/cloud/gpu/dao/VGPUTypesDaoImpl.java b/engine/schema/src/main/java/com/cloud/gpu/dao/VGPUTypesDaoImpl.java index d4e31d365d9..edc5e1f67c8 100644 --- a/engine/schema/src/main/java/com/cloud/gpu/dao/VGPUTypesDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/gpu/dao/VGPUTypesDaoImpl.java @@ -27,7 +27,6 @@ import java.util.Map.Entry; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.api.VgpuTypesInfo; @@ -41,7 +40,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class VGPUTypesDaoImpl extends GenericDaoBase implements VGPUTypesDao { - private static final Logger s_logger = Logger.getLogger(VGPUTypesDaoImpl.class); private final SearchBuilder _searchByGroupId; private final SearchBuilder _searchByGroupIdVGPUType; diff --git a/engine/schema/src/main/java/com/cloud/host/HostVO.java b/engine/schema/src/main/java/com/cloud/host/HostVO.java index 697401ad069..3e64d20d0e2 100644 --- a/engine/schema/src/main/java/com/cloud/host/HostVO.java +++ b/engine/schema/src/main/java/com/cloud/host/HostVO.java @@ -16,13 +16,17 @@ // under the License. package com.cloud.host; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; @@ -38,20 +42,22 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.cloudstack.util.HypervisorTypeConverter; +import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper; +import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang3.StringUtils; + import com.cloud.agent.api.VgpuTypesInfo; import com.cloud.host.dao.HostTagsDao; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.offering.ServiceOffering; import com.cloud.resource.ResourceState; import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.util.StoragePoolTypeConverter; import com.cloud.utils.NumbersUtil; import com.cloud.utils.db.GenericDao; -import java.util.Arrays; - -import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper; -import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.commons.lang.BooleanUtils; -import org.apache.commons.lang3.StringUtils; @Entity @Table(name = "host") @@ -120,7 +126,7 @@ public class HostVO implements Host { private String storageMacAddressDeux; @Column(name = "hypervisor_type", updatable = true, nullable = false) - @Enumerated(value = EnumType.STRING) + @Convert(converter = HypervisorTypeConverter.class) private HypervisorType hypervisorType; @Column(name = "proxy_port") @@ -130,6 +136,7 @@ public class HostVO implements Host { private String resource; @Column(name = "fs_type") + @Convert(converter = StoragePoolTypeConverter.class) private StoragePoolType fsType; @Column(name = "available") @@ -761,7 +768,28 @@ public class HostVO implements Host { this.uuid = uuid; } - public boolean checkHostServiceOfferingTags(ServiceOffering serviceOffering){ + public boolean checkHostServiceOfferingAndTemplateTags(ServiceOffering serviceOffering, VirtualMachineTemplate template) { + if (serviceOffering == null || template == null) { + return false; + } + if (StringUtils.isEmpty(serviceOffering.getHostTag()) && StringUtils.isEmpty(template.getTemplateTag())) { + return true; + } + if (getHostTags() == null) { + return false; + } + HashSet hostTagsSet = new HashSet<>(getHostTags()); + List tags = new ArrayList<>(); + if (StringUtils.isNotEmpty(serviceOffering.getHostTag())) { + tags.addAll(Arrays.asList(serviceOffering.getHostTag().split(","))); + } + if (StringUtils.isNotEmpty(template.getTemplateTag()) && !tags.contains(template.getTemplateTag())) { + tags.add(template.getTemplateTag()); + } + return hostTagsSet.containsAll(tags); + } + + public boolean checkHostServiceOfferingTags(ServiceOffering serviceOffering) { if (serviceOffering == null) { return false; } @@ -773,7 +801,6 @@ public class HostVO implements Host { if (StringUtils.isEmpty(serviceOffering.getHostTag())) { return true; } - List serviceOfferingTags = Arrays.asList(serviceOffering.getHostTag().split(",")); return this.getHostTags() != null && this.getHostTags().containsAll(serviceOfferingTags); } diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java b/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java index fe30722feb1..ca180e2323f 100644 --- a/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java +++ b/engine/schema/src/main/java/com/cloud/host/dao/HostDao.java @@ -63,7 +63,7 @@ public interface HostDao extends GenericDao, StateDao listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag); + List listByHostTag(Host.Type type, Long clusterId, Long podId, Long dcId, String hostTag); List findAndUpdateApplianceToLoad(long lastPingSecondsAfter, long managementServerId); diff --git a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java index 136351527f6..5faa877b458 100644 --- a/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java @@ -36,7 +36,6 @@ import javax.persistence.TableGenerator; import org.apache.cloudstack.utils.jsinterpreter.TagAsRuleHelper; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.VgpuTypesInfo; import com.cloud.cluster.agentlb.HostTransferMapVO; @@ -74,14 +73,12 @@ import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.db.UpdateBuilder; import com.cloud.utils.exception.CloudRuntimeException; + import java.util.Arrays; @DB @TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1) public class HostDaoImpl extends GenericDaoBase implements HostDao { //FIXME: , ExternalIdDao { - private static final Logger s_logger = Logger.getLogger(HostDaoImpl.class); - private static final Logger status_logger = Logger.getLogger(Status.class); - private static final Logger state_logger = Logger.getLogger(ResourceState.class); private static final String LIST_HOST_IDS_BY_COMPUTETAGS = "SELECT filtered.host_id, COUNT(filtered.tag) AS tag_count " + "FROM (SELECT host_id, tag, is_tag_a_rule FROM host_tags GROUP BY host_id,tag) AS filtered " @@ -355,7 +352,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao try { HostTransferSearch = _hostTransferDao.createSearchBuilder(); } catch (Throwable e) { - s_logger.debug("error", e); + logger.debug("error", e); } HostTransferSearch.and("id", HostTransferSearch.entity().getId(), SearchCriteria.Op.NULL); UnmanagedDirectConnectSearch.join("hostTransferSearch", HostTransferSearch, HostTransferSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getId(), @@ -593,8 +590,8 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao sb.append(" "); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Following hosts got reset: " + sb.toString()); + if (logger.isTraceEnabled()) { + logger.trace("Following hosts got reset: " + sb.toString()); } } @@ -642,19 +639,19 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao public List findAndUpdateDirectAgentToLoad(long lastPingSecondsAfter, Long limit, long managementServerId) { TransactionLegacy txn = TransactionLegacy.currentTxn(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Resetting hosts suitable for reconnect"); + if (logger.isDebugEnabled()) { + logger.debug("Resetting hosts suitable for reconnect"); } // reset hosts that are suitable candidates for reconnect resetHosts(managementServerId, lastPingSecondsAfter); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Completed resetting hosts suitable for reconnect"); + if (logger.isDebugEnabled()) { + logger.debug("Completed resetting hosts suitable for reconnect"); } List assignedHosts = new ArrayList(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Acquiring hosts for clusters already owned by this management server"); + if (logger.isDebugEnabled()) { + logger.debug("Acquiring hosts for clusters already owned by this management server"); } List clusters = findClustersOwnedByManagementServer(managementServerId); txn.start(); @@ -673,17 +670,17 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao sb.append(host.getId()); sb.append(" "); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Following hosts got acquired for clusters already owned: " + sb.toString()); + if (logger.isTraceEnabled()) { + logger.trace("Following hosts got acquired for clusters already owned: " + sb.toString()); } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Completed acquiring hosts for clusters already owned by this management server"); + if (logger.isDebugEnabled()) { + logger.debug("Completed acquiring hosts for clusters already owned by this management server"); } if (assignedHosts.size() < limit) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Acquiring hosts for clusters not owned by any management server"); + if (logger.isDebugEnabled()) { + logger.debug("Acquiring hosts for clusters not owned by any management server"); } // for remaining hosts not owned by any MS check if they can be owned (by owning full cluster) clusters = findClustersForHostsNotOwnedByAnyManagementServer(); @@ -723,12 +720,12 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao break; } } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Following hosts got acquired from newly owned clusters: " + sb.toString()); + if (logger.isTraceEnabled()) { + logger.trace("Following hosts got acquired from newly owned clusters: " + sb.toString()); } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Completed acquiring hosts for clusters not owned by any management server"); + if (logger.isDebugEnabled()) { + logger.debug("Completed acquiring hosts for clusters not owned by any management server"); } } txn.commit(); @@ -783,7 +780,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao } @Override - public List listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) { + public List listByHostTag(Host.Type type, Long clusterId, Long podId, Long dcId, String hostTag) { SearchBuilder hostSearch = createSearchBuilder(); HostVO entity = hostSearch.entity(); hostSearch.and("type", entity.getType(), SearchCriteria.Op.EQ); @@ -801,7 +798,9 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao if (clusterId != null) { sc.setParameters("cluster", clusterId); } - sc.setParameters("dc", dcId); + if (dcId != null) { + sc.setParameters("dc", dcId); + } sc.setParameters("status", Status.Up.toString()); sc.setParameters("resourceState", ResourceState.Enabled.toString()); @@ -899,7 +898,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao } } } catch (SQLException e) { - s_logger.warn("Exception: ", e); + logger.warn("Exception: ", e); } return result; } @@ -1009,15 +1008,15 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao l.add(info); } } catch (SQLException e) { - s_logger.debug("SQLException caught", e); + logger.debug("SQLException caught", e); } return l; } @Override public long getNextSequence(long hostId) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("getNextSequence(), hostId: " + hostId); + if (logger.isTraceEnabled()) { + logger.trace("getNextSequence(), hostId: " + hostId); } TableGenerator tg = _tgs.get("host_req_sq"); @@ -1087,7 +1086,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao HostVO ho = findById(host.getId()); assert ho != null : "How how how? : " + host.getId(); - if (status_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString()); str.append(". Name=").append(host.getName()); @@ -1097,7 +1096,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao .append("]"); str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=").append(vo.getLastPinged()) .append(":old update count=").append(oldUpdateCount).append("]"); - status_logger.debug(str.toString()); + logger.debug(str.toString()); } else { StringBuilder msg = new StringBuilder("Agent status update: ["); msg.append("id = " + host.getId()); @@ -1107,11 +1106,11 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao msg.append("; new status = " + newStatus); msg.append("; old update count = " + oldUpdateCount); msg.append("; new update count = " + newUpdateCount + "]"); - status_logger.debug(msg.toString()); + logger.debug(msg.toString()); } if (ho.getState() == newStatus) { - status_logger.debug("Host " + ho.getName() + " state has already been updated to " + newStatus); + logger.debug("Host " + ho.getName() + " state has already been updated to " + newStatus); return true; } } @@ -1137,7 +1136,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao int result = update(ub, sc, null); assert result <= 1 : "How can this update " + result + " rows? "; - if (state_logger.isDebugEnabled() && result == 0) { + if (logger.isDebugEnabled() && result == 0) { HostVO ho = findById(host.getId()); assert ho != null : "How how how? : " + host.getId(); @@ -1147,7 +1146,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao str.append("; old state = " + oldState); str.append("; event = " + event); str.append("; new state = " + newState + "]"); - state_logger.debug(str.toString()); + logger.debug(str.toString()); } else { StringBuilder msg = new StringBuilder("Resource state update: ["); msg.append("id = " + host.getId()); @@ -1155,7 +1154,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao msg.append("; old state = " + oldState); msg.append("; event = " + event); msg.append("; new state = " + newState + "]"); - state_logger.debug(msg.toString()); + logger.debug(msg.toString()); } return result > 0; @@ -1419,7 +1418,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao result.add(resultSet.getString(1)); } } catch (SQLException e) { - s_logger.error("Error trying to obtain hypervisor version on datacenter", e); + logger.error("Error trying to obtain hypervisor version on datacenter", e); } return result; } diff --git a/engine/schema/src/main/java/com/cloud/hypervisor/HypervisorCapabilitiesVO.java b/engine/schema/src/main/java/com/cloud/hypervisor/HypervisorCapabilitiesVO.java index 5ab684c1100..4455c7491dd 100644 --- a/engine/schema/src/main/java/com/cloud/hypervisor/HypervisorCapabilitiesVO.java +++ b/engine/schema/src/main/java/com/cloud/hypervisor/HypervisorCapabilitiesVO.java @@ -19,9 +19,8 @@ package com.cloud.hypervisor; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -29,6 +28,7 @@ import javax.persistence.Table; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.utils.NumbersUtil; +import org.apache.cloudstack.util.HypervisorTypeConverter; @Entity @Table(name = "hypervisor_capabilities") @@ -39,7 +39,7 @@ public class HypervisorCapabilitiesVO implements HypervisorCapabilities { private long id; @Column(name = "hypervisor_type") - @Enumerated(value = EnumType.STRING) + @Convert(converter = HypervisorTypeConverter.class) private HypervisorType hypervisorType; @Column(name = "hypervisor_version") diff --git a/engine/schema/src/main/java/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java b/engine/schema/src/main/java/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java index e8272825213..f636c2eb762 100644 --- a/engine/schema/src/main/java/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/hypervisor/dao/HypervisorCapabilitiesDaoImpl.java @@ -21,7 +21,6 @@ import java.util.List; import org.apache.cloudstack.utils.CloudStackVersion; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -33,7 +32,6 @@ import com.cloud.utils.db.SearchCriteria; @Component public class HypervisorCapabilitiesDaoImpl extends GenericDaoBase implements HypervisorCapabilitiesDao { - private static final Logger s_logger = Logger.getLogger(HypervisorCapabilitiesDaoImpl.class); protected final SearchBuilder HypervisorTypeSearch; protected final SearchBuilder HypervisorTypeAndVersionSearch; @@ -75,11 +73,17 @@ public class HypervisorCapabilitiesDaoImpl extends GenericDaoBase implements VmwareDatacenterDao { - protected static final Logger s_logger = Logger.getLogger(VmwareDatacenterDaoImpl.class); final SearchBuilder nameSearch; final SearchBuilder guidSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java index f6185309972..fdd1e0ec43a 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/FirewallRulesCidrsDaoImpl.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.DB; @@ -31,7 +30,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class FirewallRulesCidrsDaoImpl extends GenericDaoBase implements FirewallRulesCidrsDao { - private static final Logger s_logger = Logger.getLogger(FirewallRulesCidrsDaoImpl.class); protected final SearchBuilder CidrsSearch; protected FirewallRulesCidrsDaoImpl() { diff --git a/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDao.java b/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDao.java index f75dc8a6661..b1b1e1cf757 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDao.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDao.java @@ -103,4 +103,6 @@ public interface IPAddressDao extends GenericDao { List listByNetworkId(long networkId); void buildQuarantineSearchCriteria(SearchCriteria sc); + + IPAddressVO findBySourceNetworkIdAndDatacenterIdAndState(long sourceNetworkId, long dataCenterId, State state); } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDaoImpl.java index 9ffc4c9159c..ca779f7e9ce 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/IPAddressDaoImpl.java @@ -26,7 +26,6 @@ import javax.inject.Inject; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.resourcedetail.dao.UserIpAddressDetailsDao; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.Vlan.VlanType; @@ -50,7 +49,6 @@ import com.cloud.utils.net.Ip; @Component @DB public class IPAddressDaoImpl extends GenericDaoBase implements IPAddressDao { - private static final Logger s_logger = Logger.getLogger(IPAddressDaoImpl.class); protected SearchBuilder AllFieldsSearch; protected SearchBuilder VlanDbIdSearchUnallocated; @@ -374,7 +372,7 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen ipCount = rs.getInt(1); } } catch (Exception e) { - s_logger.warn("Exception counting IP addresses", e); + logger.warn("Exception counting IP addresses", e); } return ipCount; @@ -554,4 +552,13 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen sc.setParametersIfNotNull("quarantinedPublicIpsIdsNIN", quarantinedIpsIdsAllowedToUser); } + + @Override + public IPAddressVO findBySourceNetworkIdAndDatacenterIdAndState(long sourceNetworkId, long dataCenterId, State state) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("sourcenetwork", sourceNetworkId); + sc.setParameters("dataCenterId", dataCenterId); + sc.setParameters("state", State.Free); + return findOneBy(sc); + } } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/NetworkDomainDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/NetworkDomainDaoImpl.java index ce86a8636a1..e8c55131ecd 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/NetworkDomainDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/NetworkDomainDaoImpl.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import com.cloud.utils.db.TransactionLegacy; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.DB; @@ -38,7 +37,6 @@ import com.cloud.utils.db.SearchCriteria.Op; @Component @DB() public class NetworkDomainDaoImpl extends GenericDaoBase implements NetworkDomainDao { - public static Logger logger = Logger.getLogger(NetworkDomainDaoImpl.class.getName()); final SearchBuilder AllFieldsSearch; final SearchBuilder DomainsSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java b/engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java index f24eec4931e..581f7899069 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/NetworkVO.java @@ -39,7 +39,6 @@ import com.cloud.network.Networks.TrafficType; import com.cloud.utils.NumbersUtil; import com.cloud.utils.db.GenericDao; import com.cloud.utils.net.NetUtils; -import org.apache.log4j.Logger; /** * NetworkConfigurationVO contains information about a specific network. @@ -48,7 +47,6 @@ import org.apache.log4j.Logger; @Entity @Table(name = "networks") public class NetworkVO implements Network { - static final Logger s_logger = Logger.getLogger(NetworkVO.class); @Id @TableGenerator(name = "networks_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "networks_seq", allocationSize = 1) @Column(name = "id") @@ -369,6 +367,10 @@ public class NetworkVO implements Network { return mode; } + public void setAccountId(long accountId) { + this.accountId = accountId; + } + @Override public long getAccountId() { return accountId; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDao.java b/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDao.java new file mode 100644 index 00000000000..0fc77537711 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDao.java @@ -0,0 +1,30 @@ +// 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.network.dao; + +import com.cloud.network.element.NsxProviderVO; +import com.cloud.utils.db.GenericDao; + +import java.util.List; + +public interface NsxProviderDao extends GenericDao { + NsxProviderVO findByZoneId(long zoneId); + + NsxProviderVO findByUuid(String uuid); + + List findAll(); +} diff --git a/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDaoImpl.java new file mode 100644 index 00000000000..cf7b5d405c0 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/network/dao/NsxProviderDaoImpl.java @@ -0,0 +1,65 @@ +// 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.network.dao; + +import com.cloud.network.element.NsxProviderVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@DB() +public class NsxProviderDaoImpl extends GenericDaoBase + implements NsxProviderDao { + + final SearchBuilder allFieldsSearch; + + public NsxProviderDaoImpl() { + super(); + allFieldsSearch = createSearchBuilder(); + allFieldsSearch.and("id", allFieldsSearch.entity().getId(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("uuid", allFieldsSearch.entity().getUuid(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("hostname", allFieldsSearch.entity().getHostname(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("provider_name", allFieldsSearch.entity().getProviderName(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("tier0_gateway", allFieldsSearch.entity().getTier0Gateway(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("zone_id", allFieldsSearch.entity().getZoneId(), + SearchCriteria.Op.EQ); + allFieldsSearch.and("edge_cluster", allFieldsSearch.entity().getEdgeCluster(), + SearchCriteria.Op.EQ); + allFieldsSearch.done(); + } + @Override + public NsxProviderVO findByZoneId(long zoneId) { + SearchCriteria sc = allFieldsSearch.create(); + sc.setParameters("zone_id", zoneId); + return findOneBy(sc); + } + + @Override + public List findAll() { + return listAll(); + } +} diff --git a/engine/schema/src/main/java/com/cloud/network/dao/PortProfileDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/PortProfileDaoImpl.java index a90ce059c31..eb2a1968158 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/PortProfileDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/PortProfileDaoImpl.java @@ -22,7 +22,6 @@ import java.sql.SQLException; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.DB; @@ -36,7 +35,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component @DB() public class PortProfileDaoImpl extends GenericDaoBase implements PortProfileDao { - protected static final Logger s_logger = Logger.getLogger(PortProfileDaoImpl.class); final SearchBuilder nameSearch; final SearchBuilder accessVlanSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/RemoteAccessVpnDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/RemoteAccessVpnDaoImpl.java index 3aa2e749712..484aa6f6631 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/RemoteAccessVpnDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/RemoteAccessVpnDaoImpl.java @@ -19,7 +19,6 @@ package com.cloud.network.dao; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.RemoteAccessVpn; @@ -29,7 +28,6 @@ import com.cloud.utils.db.SearchCriteria; @Component public class RemoteAccessVpnDaoImpl extends GenericDaoBase implements RemoteAccessVpnDao { - private static final Logger s_logger = Logger.getLogger(RemoteAccessVpnDaoImpl.class); private final SearchBuilder AllFieldsSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/RouterHealthCheckResultDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/RouterHealthCheckResultDaoImpl.java index 991365b5f54..b1292aebfd1 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/RouterHealthCheckResultDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/RouterHealthCheckResultDaoImpl.java @@ -19,7 +19,6 @@ package com.cloud.network.dao; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -28,7 +27,6 @@ import com.cloud.utils.db.SearchCriteria; @Component public class RouterHealthCheckResultDaoImpl extends GenericDaoBase implements RouterHealthCheckResultDao { - private final static Logger s_logger = Logger.getLogger(RouterHealthCheckResultDaoImpl.class); private SearchBuilder RouterChecksSearchBuilder; private SearchBuilder IsRouterFailingSearchBuilder; @@ -69,7 +67,7 @@ public class RouterHealthCheckResultDaoImpl extends GenericDaoBase checks = listBy(sc); if (checks.size() > 1) { - s_logger.error("Found multiple entries for router Id: " + routerId + ", check name: " + checkName); + logger.error("Found multiple entries for router Id: " + routerId + ", check name: " + checkName); } return checks.isEmpty() ? null : checks.get(0); } diff --git a/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java index b55f39ab31b..f9c5ce08964 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnConnectionDaoImpl.java @@ -21,7 +21,6 @@ import java.util.List; import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -31,7 +30,6 @@ import com.cloud.utils.db.SearchCriteria; @Component public class Site2SiteVpnConnectionDaoImpl extends GenericDaoBase implements Site2SiteVpnConnectionDao { - private static final Logger s_logger = Logger.getLogger(Site2SiteVpnConnectionDaoImpl.class); @Inject protected IPAddressDao _addrDao; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnGatewayDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnGatewayDaoImpl.java index 80465f9ee1e..d1fde963217 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnGatewayDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/Site2SiteVpnGatewayDaoImpl.java @@ -18,7 +18,6 @@ package com.cloud.network.dao; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -30,7 +29,6 @@ public class Site2SiteVpnGatewayDaoImpl extends GenericDaoBase AllFieldsSearch; diff --git a/engine/schema/src/main/java/com/cloud/network/dao/UserIpv6AddressDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/dao/UserIpv6AddressDaoImpl.java index 08f0829f4ac..407d34fa365 100644 --- a/engine/schema/src/main/java/com/cloud/network/dao/UserIpv6AddressDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/dao/UserIpv6AddressDaoImpl.java @@ -20,7 +20,6 @@ import java.util.List; import com.cloud.network.IpAddress; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.UserIpv6AddressVO; @@ -33,7 +32,6 @@ import com.cloud.utils.db.SearchCriteria.Op; @Component public class UserIpv6AddressDaoImpl extends GenericDaoBase implements UserIpv6AddressDao { - private static final Logger s_logger = Logger.getLogger(IPAddressDaoImpl.class); protected final SearchBuilder AllFieldsSearch; protected GenericSearchBuilder CountFreePublicIps; diff --git a/engine/schema/src/main/java/com/cloud/network/element/NsxProviderVO.java b/engine/schema/src/main/java/com/cloud/network/element/NsxProviderVO.java new file mode 100644 index 00000000000..f08e08b1ca0 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/network/element/NsxProviderVO.java @@ -0,0 +1,285 @@ +// 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.network.element; + +import com.cloud.network.nsx.NsxProvider; +import com.cloud.utils.db.Encrypt; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Date; +import java.util.UUID; + +@Entity +@Table(name = "nsx_providers") +public class NsxProviderVO implements NsxProvider { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + long id; + + @Column(name = "zone_id") + private long zoneId; + + @Column(name = "host_id") + private long hostId; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "provider_name") + private String providerName; + + @Column(name = "hostname") + private String hostname; + + @Column(name = "port") + private String port = "443"; + + @Column(name = "username") + private String username; + + @Encrypt + @Column(name = "password") + private String password; + + @Column(name = "tier0_gateway") + private String tier0Gateway; + + @Column(name = "edge_cluster") + private String edgeCluster; + + @Column(name = "transport_zone") + private String transportZone; + + @Column(name = "created") + private Date created; + + @Column(name = "removed") + private Date removed; + public NsxProviderVO() { + this.uuid = UUID.randomUUID().toString(); + } + + @Override + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + @Override + public long getZoneId() { + return zoneId; + } + + public void setZoneId(long zoneId) { + this.zoneId = zoneId; + } + + public long getHostId() { + return hostId; + } + + public void setHostId(long hostId) { + this.hostId = hostId; + } + + @Override + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + @Override + public String getProviderName() { + return providerName; + } + + public void setProviderName(String providerName) { + this.providerName = providerName; + } + + @Override + public String getHostname() { + return hostname; + } + + public void setPort(String port) { + this.port = port; + } + + @Override + public String getPort() { + return port; + } + + public void setHostname(String hostname) { + this.hostname = hostname; + } + + @Override + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getTier0Gateway() { + return tier0Gateway; + } + + public void setTier0Gateway(String tier0Gateway) { + this.tier0Gateway = tier0Gateway; + } + + public String getEdgeCluster() { + return edgeCluster; + } + + public void setEdgeCluster(String edgeCluster) { + this.edgeCluster = edgeCluster; + } + + public String getTransportZone() { + return transportZone; + } + + public void setTransportZone(String transportZone) { + this.transportZone = transportZone; + } + + public Date getCreated() { + return created; + } + + public void setCreated(Date created) { + this.created = created; + } + + public Date getRemoved() { + return removed; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + public static final class Builder { + private long zoneId; + private long hostId; + private String providerName; + private String hostname; + private String port; + private String username; + private String password; + private String tier0Gateway; + private String edgeCluster; + private String transportZone; + + + public Builder() { + // Default constructor + } + + public Builder setZoneId(long zoneId) { + this.zoneId = zoneId; + return this; + } + + public Builder setHostId(long hostId) { + this.hostId = hostId; + return this; + } + + public Builder setProviderName(String providerName) { + this.providerName = providerName; + return this; + } + + public Builder setHostname(String hostname) { + this.hostname = hostname; + return this; + } + + public Builder setPort(String port) { + this.port = port; + return this; + } + + public Builder setUsername(String username) { + this.username = username; + return this; + } + + public Builder setPassword(String password) { + this.password = password; + return this; + } + + public Builder setTier0Gateway(String tier0Gateway) { + this.tier0Gateway = tier0Gateway; + return this; + } + + public Builder setEdgeCluster(String edgeCluster) { + this.edgeCluster = edgeCluster; + return this; + } + + public Builder setTransportZone(String transportZone) { + this.transportZone = transportZone; + return this; + } + public NsxProviderVO build() { + NsxProviderVO provider = new NsxProviderVO(); + provider.setZoneId(this.zoneId); + provider.setHostId(this.hostId); + provider.setUuid(UUID.randomUUID().toString()); + provider.setProviderName(this.providerName); + provider.setHostname(this.hostname); + provider.setPort(this.port); + provider.setUsername(this.username); + provider.setPassword(this.password); + provider.setTier0Gateway(this.tier0Gateway); + provider.setEdgeCluster(this.edgeCluster); + provider.setTransportZone(this.transportZone); + provider.setCreated(new Date()); + return provider; + } + } +} diff --git a/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupVMMapDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupVMMapDaoImpl.java index a2ec95ccb67..803955a562c 100644 --- a/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupVMMapDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupVMMapDaoImpl.java @@ -131,7 +131,7 @@ public class SecurityGroupVMMapDaoImpl extends GenericDaoBase sc = ListBySecurityGroupAndStates.create(); sc.setParameters("securityGroupId", securityGroupId); sc.setParameters("states", (Object[])vmStates); - return listBy(sc, null, true); + return listBy(sc, null); } @Override diff --git a/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupWorkDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupWorkDaoImpl.java index 9b0bf088a14..327d12c759a 100644 --- a/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupWorkDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/security/dao/SecurityGroupWorkDaoImpl.java @@ -20,7 +20,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.security.SecurityGroupWork; @@ -37,7 +36,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class SecurityGroupWorkDaoImpl extends GenericDaoBase implements SecurityGroupWorkDao { - private static final Logger s_logger = Logger.getLogger(SecurityGroupWorkDaoImpl.class); private final SearchBuilder VmIdTakenSearch; private final SearchBuilder VmIdSeqNumSearch; @@ -107,8 +105,8 @@ public class SecurityGroupWorkDaoImpl extends GenericDaoBase vos = lockRows(sc, filter, true); if (vos.size() == 0) { txn.commit(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Security Group take: no work found"); + if (logger.isTraceEnabled()) { + logger.trace("Security Group take: no work found"); } return null; } @@ -117,8 +115,8 @@ public class SecurityGroupWorkDaoImpl extends GenericDaoBase im } catch (SQLTransactionRollbackException e1) { if (i < maxTries - 1) { int delayMs = (i + 1) * 1000; - s_logger.debug("Caught a deadlock exception while inserting security group rule log, retrying in " + delayMs); + logger.debug("Caught a deadlock exception while inserting security group rule log, retrying in " + delayMs); try { Thread.sleep(delayMs); } catch (InterruptedException ie) { - s_logger.debug("[ignored] interrupted while inserting security group rule log."); + logger.debug("[ignored] interrupted while inserting security group rule log."); } } else - s_logger.warn("Caught another deadlock exception while retrying inserting security group rule log, giving up"); + logger.warn("Caught another deadlock exception while retrying inserting security group rule log, giving up"); } } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Inserted or updated " + numUpdated + " rows"); + if (logger.isTraceEnabled()) { + logger.trace("Inserted or updated " + numUpdated + " rows"); } return numUpdated; } @@ -134,8 +132,8 @@ public class VmRulesetLogDaoImpl extends GenericDaoBase im vmIds.add(vmId); } int numUpdated = executeWithRetryOnDeadlock(txn, pstmt, vmIds); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Inserted or updated " + numUpdated + " rows"); + if (logger.isTraceEnabled()) { + logger.trace("Inserted or updated " + numUpdated + " rows"); } if (numUpdated > 0) count += stmtSize; @@ -145,7 +143,7 @@ public class VmRulesetLogDaoImpl extends GenericDaoBase im } } catch (SQLException sqe) { - s_logger.warn("Failed to execute multi insert ", sqe); + logger.warn("Failed to execute multi insert ", sqe); } return count; @@ -173,10 +171,10 @@ public class VmRulesetLogDaoImpl extends GenericDaoBase im queryResult = stmtInsert.executeBatch(); txn.commit(); - if (s_logger.isTraceEnabled()) - s_logger.trace("Updated or inserted " + workItems.size() + " log items"); + if (logger.isTraceEnabled()) + logger.trace("Updated or inserted " + workItems.size() + " log items"); } catch (SQLException e) { - s_logger.warn("Failed to execute batch update statement for ruleset log: ", e); + logger.warn("Failed to execute batch update statement for ruleset log: ", e); txn.rollback(); success = false; } @@ -185,7 +183,7 @@ public class VmRulesetLogDaoImpl extends GenericDaoBase im workItems.toArray(arrayItems); for (int i = 0; i < queryResult.length; i++) { if (queryResult[i] < 0) { - s_logger.debug("Batch query update failed for vm " + arrayItems[i]); + logger.debug("Batch query update failed for vm " + arrayItems[i]); } } } diff --git a/engine/schema/src/main/java/com/cloud/network/vo/PublicIpQuarantineVO.java b/engine/schema/src/main/java/com/cloud/network/vo/PublicIpQuarantineVO.java index 56d167a0060..89e02610bd2 100644 --- a/engine/schema/src/main/java/com/cloud/network/vo/PublicIpQuarantineVO.java +++ b/engine/schema/src/main/java/com/cloud/network/vo/PublicIpQuarantineVO.java @@ -63,6 +63,9 @@ public class PublicIpQuarantineVO implements PublicIpQuarantine { @Column(name = "removal_reason") private String removalReason = null; + @Column(name = "remover_account_id") + private Long removerAccountId = null; + public PublicIpQuarantineVO() { } @@ -98,6 +101,11 @@ public class PublicIpQuarantineVO implements PublicIpQuarantine { return removalReason; } + @Override + public Long getRemoverAccountId() { + return this.removerAccountId; + } + @Override public String getUuid() { return uuid; @@ -111,6 +119,10 @@ public class PublicIpQuarantineVO implements PublicIpQuarantine { this.removalReason = removalReason; } + public void setRemoverAccountId(Long removerAccountId) { + this.removerAccountId = removerAccountId; + } + @Override public Date getRemoved() { return removed; diff --git a/engine/schema/src/main/java/com/cloud/network/vpc/VpcOfferingVO.java b/engine/schema/src/main/java/com/cloud/network/vpc/VpcOfferingVO.java index aa26f16568a..350dda3f3b8 100644 --- a/engine/schema/src/main/java/com/cloud/network/vpc/VpcOfferingVO.java +++ b/engine/schema/src/main/java/com/cloud/network/vpc/VpcOfferingVO.java @@ -58,6 +58,12 @@ public class VpcOfferingVO implements VpcOffering { @Column(name = "default") boolean isDefault = false; + @Column(name = "for_nsx") + boolean forNsx = false; + + @Column(name = "nsx_mode") + String nsxMode; + @Column(name = GenericDao.REMOVED_COLUMN) Date removed; @@ -144,6 +150,22 @@ public class VpcOfferingVO implements VpcOffering { return isDefault; } + public boolean isForNsx() { + return forNsx; + } + + public void setForNsx(boolean forNsx) { + this.forNsx = forNsx; + } + + public String getNsxMode() { + return nsxMode; + } + + public void setNsxMode(String nsxMode) { + this.nsxMode = nsxMode; + } + public void setUniqueName(String uniqueName) { this.uniqueName = uniqueName; } diff --git a/engine/schema/src/main/java/com/cloud/network/vpc/dao/NetworkACLItemCidrsDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/vpc/dao/NetworkACLItemCidrsDaoImpl.java index 4501f1493b5..1eb6482dd3a 100644 --- a/engine/schema/src/main/java/com/cloud/network/vpc/dao/NetworkACLItemCidrsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/vpc/dao/NetworkACLItemCidrsDaoImpl.java @@ -21,7 +21,6 @@ package com.cloud.network.vpc.dao; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.vpc.NetworkACLItemCidrsDao; @@ -37,7 +36,6 @@ import com.cloud.utils.db.TransactionLegacy; */ @Component public class NetworkACLItemCidrsDaoImpl extends GenericDaoBase implements NetworkACLItemCidrsDao { - private static final Logger s_logger = Logger.getLogger(NetworkACLItemCidrsDaoImpl.class); protected final SearchBuilder cidrsSearch; protected NetworkACLItemCidrsDaoImpl() { diff --git a/engine/schema/src/main/java/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java b/engine/schema/src/main/java/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java index 8b090fdfbc8..47b91b24c27 100644 --- a/engine/schema/src/main/java/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/network/vpc/dao/PrivateIpDaoImpl.java @@ -20,7 +20,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.network.vpc.PrivateIpVO; @@ -36,7 +35,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component @DB() public class PrivateIpDaoImpl extends GenericDaoBase implements PrivateIpDao { - private static final Logger s_logger = Logger.getLogger(PrivateIpDaoImpl.class); private final SearchBuilder AllFieldsSearch; private final GenericSearchBuilder CountAllocatedByNetworkId; @@ -90,8 +88,8 @@ public class PrivateIpDaoImpl extends GenericDaoBase implemen @Override public void releaseIpAddress(String ipAddress, long networkId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing private ip address: " + ipAddress + " network id " + networkId); + if (logger.isDebugEnabled()) { + logger.debug("Releasing private ip address: " + ipAddress + " network id " + networkId); } SearchCriteria sc = AllFieldsSearch.create(); sc.setParameters("ip", ipAddress); diff --git a/engine/schema/src/main/java/com/cloud/offerings/NetworkOfferingVO.java b/engine/schema/src/main/java/com/cloud/offerings/NetworkOfferingVO.java index ae5e6fb95ea..b2fabf2e3cd 100644 --- a/engine/schema/src/main/java/com/cloud/offerings/NetworkOfferingVO.java +++ b/engine/schema/src/main/java/com/cloud/offerings/NetworkOfferingVO.java @@ -136,6 +136,12 @@ public class NetworkOfferingVO implements NetworkOffering { @Column(name = "for_tungsten") boolean forTungsten = false; + @Column(name = "for_nsx") + boolean forNsx = false; + + @Column(name = "nsx_mode") + String nsxMode; + @Column(name = "egress_default_policy") boolean egressdefaultpolicy; @@ -195,6 +201,24 @@ public class NetworkOfferingVO implements NetworkOffering { this.forTungsten = forTungsten; } + @Override + public boolean isForNsx() { + return forNsx; + } + + public void setForNsx(boolean forNsx) { + this.forNsx = forNsx; + } + + @Override + public String getNsxMode() { + return nsxMode; + } + + public void setNsxMode(String nsxMode) { + this.nsxMode = nsxMode; + } + @Override public long getId() { return id; diff --git a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java index d2ba49e9408..8947cc600b3 100644 --- a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java @@ -18,7 +18,6 @@ package com.cloud.projects.dao; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.projects.ProjectAccount; @@ -39,7 +38,6 @@ public class ProjectAccountDaoImpl extends GenericDaoBase ProjectAccountsSearch; final GenericSearchBuilder CountByRoleSearch; - public static final Logger s_logger = Logger.getLogger(ProjectAccountDaoImpl.class.getName()); protected ProjectAccountDaoImpl() { AllFieldsSearch = createSearchBuilder(); @@ -190,7 +188,7 @@ public class ProjectAccountDaoImpl extends GenericDaoBase 0) { - s_logger.debug("Removed account id=" + accountId + " from " + rowsRemoved + " projects"); + logger.debug("Removed account id=" + accountId + " from " + rowsRemoved + " projects"); } } diff --git a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectDaoImpl.java b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectDaoImpl.java index 5deb8586120..46bf36ae397 100644 --- a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectDaoImpl.java @@ -20,7 +20,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.projects.Project; @@ -36,7 +35,6 @@ import com.cloud.utils.db.SearchCriteria.Func; @Component public class ProjectDaoImpl extends GenericDaoBase implements ProjectDao { - private static final Logger s_logger = Logger.getLogger(ProjectDaoImpl.class); protected final SearchBuilder AllFieldsSearch; protected GenericSearchBuilder CountByDomain; protected GenericSearchBuilder ProjectAccountSearch; diff --git a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectInvitationDaoImpl.java b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectInvitationDaoImpl.java index f8d153740ab..d30b1c9f1f1 100644 --- a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectInvitationDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectInvitationDaoImpl.java @@ -19,7 +19,6 @@ package com.cloud.projects.dao; import java.sql.Date; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.projects.ProjectInvitation.State; @@ -31,7 +30,6 @@ import com.cloud.utils.db.SearchCriteria; @Component public class ProjectInvitationDaoImpl extends GenericDaoBase implements ProjectInvitationDao { - private static final Logger s_logger = Logger.getLogger(ProjectInvitationDaoImpl.class); protected final SearchBuilder AllFieldsSearch; protected final SearchBuilder InactiveSearch; protected final SearchBuilder ProjectAccountInviteSearch; @@ -111,7 +109,7 @@ public class ProjectInvitationDaoImpl extends GenericDaoBase listByHostTag(String tag) { + SearchBuilder sb = createSearchBuilder(); + sb.and("tagNotNull", sb.entity().getHostTag(), SearchCriteria.Op.NNULL); + sb.and().op("tagEq", sb.entity().getHostTag(), SearchCriteria.Op.EQ); + sb.or("tagStartLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE); + sb.or("tagMidLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE); + sb.or("tagEndLike", sb.entity().getHostTag(), SearchCriteria.Op.LIKE); + sb.cp(); + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("tagEq", tag); + sc.setParameters("tagStartLike", tag + ",%"); + sc.setParameters("tagMidLike", "%," + tag + ",%"); + sc.setParameters("tagEndLike", "%," + tag); + return listBy(sc); + } } diff --git a/engine/schema/src/main/java/com/cloud/storage/GuestOSHypervisorVO.java b/engine/schema/src/main/java/com/cloud/storage/GuestOSHypervisorVO.java index e900d28a864..cae1e1b7eee 100644 --- a/engine/schema/src/main/java/com/cloud/storage/GuestOSHypervisorVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/GuestOSHypervisorVO.java @@ -20,6 +20,7 @@ import java.util.Date; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -28,6 +29,7 @@ import javax.persistence.Table; import com.cloud.hypervisor.Hypervisor; import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.util.HypervisorTypeConverter; @Entity @Table(name = "guest_os_hypervisor") @@ -44,6 +46,7 @@ public class GuestOSHypervisorVO implements GuestOSHypervisor { String guestOsName; @Column(name = "hypervisor_type") + @Convert(converter = HypervisorTypeConverter.class) String hypervisorType; @Column(name = "hypervisor_version") diff --git a/engine/schema/src/main/java/com/cloud/storage/SnapshotVO.java b/engine/schema/src/main/java/com/cloud/storage/SnapshotVO.java index e9d6df85c2f..39d2cdd0b77 100644 --- a/engine/schema/src/main/java/com/cloud/storage/SnapshotVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/SnapshotVO.java @@ -20,6 +20,7 @@ import java.util.Date; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -28,6 +29,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import org.apache.cloudstack.util.HypervisorTypeConverter; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -89,7 +91,7 @@ public class SnapshotVO implements Snapshot { Date removed; @Column(name = "hypervisor_type") - @Enumerated(value = EnumType.STRING) + @Convert(converter = HypervisorTypeConverter.class) HypervisorType hypervisorType; @Expose diff --git a/engine/schema/src/main/java/com/cloud/storage/VMTemplateVO.java b/engine/schema/src/main/java/com/cloud/storage/VMTemplateVO.java index 44e4dc920ab..25b02db6479 100644 --- a/engine/schema/src/main/java/com/cloud/storage/VMTemplateVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/VMTemplateVO.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -32,6 +33,7 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import com.cloud.user.UserData; +import org.apache.cloudstack.util.HypervisorTypeConverter; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -108,7 +110,7 @@ public class VMTemplateVO implements VirtualMachineTemplate { private boolean crossZones = false; @Column(name = "hypervisor_type") - @Enumerated(value = EnumType.STRING) + @Convert(converter = HypervisorTypeConverter.class) private HypervisorType hypervisorType; @Column(name = "extractable") diff --git a/engine/schema/src/main/java/com/cloud/storage/VolumeDetailVO.java b/engine/schema/src/main/java/com/cloud/storage/VolumeDetailVO.java index 6723f0b8bc1..42980e07b2b 100644 --- a/engine/schema/src/main/java/com/cloud/storage/VolumeDetailVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/VolumeDetailVO.java @@ -80,4 +80,7 @@ public class VolumeDetailVO implements ResourceDetail { return display; } + public void setValue(String value) { + this.value = value; + } } diff --git a/engine/schema/src/main/java/com/cloud/storage/VolumeVO.java b/engine/schema/src/main/java/com/cloud/storage/VolumeVO.java index 0bd71ea6d86..e12859ea8d6 100644 --- a/engine/schema/src/main/java/com/cloud/storage/VolumeVO.java +++ b/engine/schema/src/main/java/com/cloud/storage/VolumeVO.java @@ -20,6 +20,7 @@ import java.util.Date; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; @@ -32,6 +33,7 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import com.cloud.util.StoragePoolTypeConverter; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import com.cloud.storage.Storage.ProvisioningType; @@ -114,7 +116,7 @@ public class VolumeVO implements Volume { Type volumeType = Volume.Type.UNKNOWN; @Column(name = "pool_type") - @Enumerated(EnumType.STRING) + @Convert(converter = StoragePoolTypeConverter.class) StoragePoolType poolType; @Column(name = GenericDao.REMOVED_COLUMN) @@ -180,6 +182,7 @@ public class VolumeVO implements Volume { @Column(name = "encrypt_format") private String encryptFormat; + // Real Constructor public VolumeVO(Type type, String name, long dcId, long domainId, long accountId, long diskOfferingId, Storage.ProvisioningType provisioningType, long size, @@ -331,9 +334,7 @@ public class VolumeVO implements Volume { this.poolType = poolType; } - public StoragePoolType getPoolType() { - return poolType; - } + public StoragePoolType getPoolType() { return poolType; } @Override public long getDomainId() { diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/BucketDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/BucketDaoImpl.java index 83b5f6bdb74..98bef6201a1 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/BucketDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/BucketDaoImpl.java @@ -20,7 +20,6 @@ import com.cloud.storage.BucketVO; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import javax.naming.ConfigurationException; @@ -29,7 +28,6 @@ import java.util.Map; @Component public class BucketDaoImpl extends GenericDaoBase implements BucketDao { - public static final Logger s_logger = Logger.getLogger(BucketDaoImpl.class.getName()); private SearchBuilder searchFilteringStoreId; private SearchBuilder bucketSearch; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java index 5a49d0b5192..f726bca3c5d 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDao.java @@ -31,5 +31,6 @@ public interface DiskOfferingDao extends GenericDao { List listAllBySizeAndProvisioningType(long size, Storage.ProvisioningType provisioningType); List findCustomDiskOfferings(); + List listByStorageTag(String tag); } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java index 78b2a542837..853a9998226 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/DiskOfferingDaoImpl.java @@ -157,4 +157,22 @@ public class DiskOfferingDaoImpl extends GenericDaoBase im return update(id, diskOffering); } + + @Override + public List listByStorageTag(String tag) { + SearchBuilder sb = createSearchBuilder(); + sb.and("tagNotNull", sb.entity().getTags(), SearchCriteria.Op.NNULL); + sb.and().op("tagEq", sb.entity().getTags(), SearchCriteria.Op.EQ); + sb.or("tagStartLike", sb.entity().getTags(), SearchCriteria.Op.LIKE); + sb.or("tagMidLike", sb.entity().getTags(), SearchCriteria.Op.LIKE); + sb.or("tagEndLike", sb.entity().getTags(), SearchCriteria.Op.LIKE); + sb.cp(); + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("tagEq", tag); + sc.setParameters("tagStartLike", tag + ",%"); + sc.setParameters("tagMidLike", "%," + tag + ",%"); + sc.setParameters("tagEndLike", "%," + tag); + return listBy(sc); + } } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java index e03e3f7ce64..1aaa277a358 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/GuestOSHypervisorDaoImpl.java @@ -20,9 +20,11 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.apache.cloudstack.utils.CloudStackVersion; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; +import com.cloud.hypervisor.Hypervisor; import com.cloud.storage.GuestOSHypervisorVO; import com.cloud.utils.db.Filter; import com.cloud.utils.db.QueryBuilder; @@ -80,6 +82,29 @@ public class GuestOSHypervisorDaoImpl extends GenericDaoBase listByGuestOsId(long guestOsId) { SearchCriteria sc = guestOsSearch.create(); @@ -87,8 +112,7 @@ public class GuestOSHypervisorDaoImpl extends GenericDaoBase sc = mappingSearch.create(); String version = "default"; if (!(hypervisorVersion == null || hypervisorVersion.isEmpty())) { @@ -100,6 +124,12 @@ public class GuestOSHypervisorDaoImpl extends GenericDaoBase sc = userDefinedMappingSearch.create(); @@ -123,8 +153,7 @@ public class GuestOSHypervisorDaoImpl extends GenericDaoBase sc = guestOsNameSearch.create(); String version = "default"; if (!(hypervisorVersion == null || hypervisorVersion.isEmpty())) { @@ -138,6 +167,12 @@ public class GuestOSHypervisorDaoImpl extends GenericDaoBase sc = guestOsNameSearch.create(); diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/LaunchPermissionDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/LaunchPermissionDaoImpl.java index ec1a3a267c6..b4fdb4b6394 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/LaunchPermissionDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/LaunchPermissionDaoImpl.java @@ -23,7 +23,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.storage.LaunchPermissionVO; @@ -39,7 +38,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class LaunchPermissionDaoImpl extends GenericDaoBase implements LaunchPermissionDao { - private static final Logger s_logger = Logger.getLogger(LaunchPermissionDaoImpl.class); private static final String REMOVE_LAUNCH_PERMISSION = "DELETE FROM `cloud`.`launch_permission`" + " WHERE template_id = ? AND account_id = ?"; private static final String LIST_PERMITTED_TEMPLATES = @@ -80,7 +78,7 @@ public class LaunchPermissionDaoImpl extends GenericDaoBase implements SnapshotDao { - public static final Logger s_logger = Logger.getLogger(SnapshotDaoImpl.class.getName()); // TODO: we should remove these direct sqls private static final String GET_LAST_SNAPSHOT = "SELECT snapshots.id FROM snapshot_store_ref, snapshots where snapshots.id = snapshot_store_ref.snapshot_id AND snapshosts.volume_id = ? AND snapshot_store_ref.role = ? ORDER BY created DESC"; @@ -197,7 +195,7 @@ public class SnapshotDaoImpl extends GenericDaoBase implements return rs.getLong(1); } } catch (Exception ex) { - s_logger.error("error getting last snapshot", ex); + logger.error("error getting last snapshot", ex); } return 0; } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotZoneDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotZoneDaoImpl.java index 1ed8a547a10..5f8ded6665b 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotZoneDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/SnapshotZoneDaoImpl.java @@ -20,7 +20,6 @@ package com.cloud.storage.dao; import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.storage.SnapshotZoneVO; import com.cloud.utils.db.GenericDaoBase; @@ -28,7 +27,6 @@ import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; public class SnapshotZoneDaoImpl extends GenericDaoBase implements SnapshotZoneDao { - public static final Logger s_logger = Logger.getLogger(SnapshotZoneDaoImpl.class.getName()); protected final SearchBuilder ZoneSnapshotSearch; public SnapshotZoneDaoImpl() { diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolHostDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolHostDaoImpl.java index c27aeb0f652..9e7bdca1181 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolHostDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolHostDaoImpl.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.host.Status; @@ -36,7 +35,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class StoragePoolHostDaoImpl extends GenericDaoBase implements StoragePoolHostDao { - public static final Logger s_logger = Logger.getLogger(StoragePoolHostDaoImpl.class.getName()); protected final SearchBuilder PoolSearch; protected final SearchBuilder HostSearch; @@ -115,10 +113,10 @@ public class StoragePoolHostDaoImpl extends GenericDaoBase(rs.getLong(1), rs.getInt(2))); } } catch (SQLException e) { - s_logger.debug("SQLException: ", e); + logger.debug("SQLException: ", e); } return l; } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java index 9352ee21858..a4b87ef025f 100755 --- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDao.java @@ -34,5 +34,6 @@ public interface StoragePoolTagsDao extends GenericDao { StorageTagResponse newStorageTagResponse(StoragePoolTagVO tag); List findStoragePoolTags(long poolId); + List listPoolIdsByTag(String tag); } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java index c01c66763af..c4d7ed88607 100755 --- a/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/StoragePoolTagsDaoImpl.java @@ -18,12 +18,10 @@ package com.cloud.storage.dao; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import javax.inject.Inject; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.db.TransactionCallbackNoReturn; -import com.cloud.utils.db.TransactionStatus; import org.apache.cloudstack.api.response.StorageTagResponse; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; @@ -31,7 +29,10 @@ import com.cloud.storage.StoragePoolTagVO; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallbackNoReturn; import com.cloud.utils.db.TransactionLegacy; +import com.cloud.utils.db.TransactionStatus; public class StoragePoolTagsDaoImpl extends GenericDaoBase implements StoragePoolTagsDao { @@ -178,4 +179,15 @@ public class StoragePoolTagsDaoImpl extends GenericDaoBase listPoolIdsByTag(String tag) { + SearchBuilder sb = createSearchBuilder(); + sb.and("tag", sb.entity().getTag(), SearchCriteria.Op.EQ); + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("tag", tag); + List poolRefs = search(sc, null); + return poolRefs.stream().map(StoragePoolTagVO::getPoolId).collect(Collectors.toList()); + } + } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/UploadDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/UploadDaoImpl.java index fb296be4d35..8ee4a21a3c0 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/UploadDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/UploadDaoImpl.java @@ -19,7 +19,6 @@ package com.cloud.storage.dao; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.storage.Upload.Mode; @@ -31,7 +30,6 @@ import com.cloud.utils.db.SearchCriteria; @Component public class UploadDaoImpl extends GenericDaoBase implements UploadDao { - public static final Logger s_logger = Logger.getLogger(UploadDaoImpl.class.getName()); protected final SearchBuilder typeUploadStatusSearch; protected final SearchBuilder typeHostAndUploadStatusSearch; protected final SearchBuilder typeModeAndStatusSearch; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java index 708a77a8f9e..1c5a2cb4256 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java @@ -90,4 +90,7 @@ public interface VMTemplateDao extends GenericDao, StateDao< List findTemplatesLinkedToUserdata(long userdataId); List listByIds(List ids); + + List listByTemplateTag(String tag); + } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java index 031bcb3af7b..4665f660251 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java @@ -28,7 +28,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.dc.dao.DataCenterDao; @@ -62,7 +61,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class VMTemplateDaoImpl extends GenericDaoBase implements VMTemplateDao { - private static final Logger s_logger = Logger.getLogger(VMTemplateDaoImpl.class); @Inject VMTemplateZoneDao _templateZoneDao; @@ -293,7 +291,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem routerTmpltName = (String)params.get("routing.uniquename"); - s_logger.debug("Found parameter routing unique name " + routerTmpltName); + logger.debug("Found parameter routing unique name " + routerTmpltName); if (routerTmpltName == null) { routerTmpltName = "routing"; } @@ -302,8 +300,8 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem if (consoleProxyTmpltName == null) { consoleProxyTmpltName = "routing"; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Use console proxy template : " + consoleProxyTmpltName); + if (logger.isDebugEnabled()) { + logger.debug("Use console proxy template : " + consoleProxyTmpltName); } UniqueNameSearch = createSearchBuilder(); @@ -688,6 +686,16 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem return result; } + @Override + public List listByTemplateTag(String tag) { + SearchBuilder sb = createSearchBuilder(); + sb.and("tag", sb.entity().getTemplateTag(), SearchCriteria.Op.EQ); + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("tag", tag); + return listIncludingRemovedBy(sc); + } + @Override public boolean updateState( com.cloud.template.VirtualMachineTemplate.State currentState, @@ -710,7 +718,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem builder.set(vo, "updated", new Date()); int rows = update((VMTemplateVO)vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { VMTemplateVO dbTemplate = findByIdIncludingRemoved(vo.getId()); if (dbTemplate != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -743,7 +751,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase implem .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update template: id=" + vo.getId() + ", as no such template exists in the database anymore"); + logger.debug("Unable to update template: id=" + vo.getId() + ", as no such template exists in the database anymore"); } } return rows > 0; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java index d938bebb18e..5a2ec1163fb 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplatePoolDaoImpl.java @@ -31,7 +31,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; @@ -49,7 +48,6 @@ import com.cloud.utils.db.UpdateBuilder; @Component public class VMTemplatePoolDaoImpl extends GenericDaoBase implements VMTemplatePoolDao { - public static final Logger s_logger = Logger.getLogger(VMTemplatePoolDaoImpl.class.getName()); @Inject DataStoreManager dataStoreManager; @@ -193,7 +191,7 @@ public class VMTemplatePoolDaoImpl extends GenericDaoBase 0; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java index 489ac130eaf..12835d184ea 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateZoneDaoImpl.java @@ -19,7 +19,6 @@ package com.cloud.storage.dao; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.storage.VMTemplateZoneVO; @@ -30,7 +29,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class VMTemplateZoneDaoImpl extends GenericDaoBase implements VMTemplateZoneDao { - public static final Logger s_logger = Logger.getLogger(VMTemplateZoneDaoImpl.class.getName()); protected final SearchBuilder ZoneSearch; protected final SearchBuilder TemplateSearch; diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java index be6588e3189..4e9c63699ca 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDao.java @@ -155,4 +155,7 @@ public interface VolumeDao extends GenericDao, StateDao listByIds(List ids); + + List listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(long accountId, List diskOfferingIds, List vmIds); + } diff --git a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java index bf556622463..31d64daf147 100644 --- a/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/storage/dao/VolumeDaoImpl.java @@ -23,11 +23,16 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.stream.Collectors; import javax.inject.Inject; +import com.cloud.configuration.Resource; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; +import org.apache.cloudstack.reservation.ReservationVO; +import org.apache.cloudstack.reservation.dao.ReservationDao; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.exception.InvalidParameterValueException; @@ -55,7 +60,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class VolumeDaoImpl extends GenericDaoBase implements VolumeDao { - private static final Logger s_logger = Logger.getLogger(VolumeDaoImpl.class); protected final SearchBuilder DetachedAccountIdSearch; protected final SearchBuilder TemplateZoneSearch; protected final GenericSearchBuilder TotalSizeByPoolSearch; @@ -73,6 +77,8 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol protected GenericSearchBuilder secondaryStorageSearch; private final SearchBuilder poolAndPathSearch; @Inject + ReservationDao reservationDao; + @Inject ResourceTagDao _tagsDao; protected static final String SELECT_VM_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ? and v.mirror_state = ?"; @@ -83,8 +89,9 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol protected static final String SELECT_HYPERTYPE_FROM_ZONE_VOLUME = "SELECT s.hypervisor from volumes v, storage_pool s where v.pool_id = s.id and v.id = ?"; protected static final String SELECT_POOLSCOPE = "SELECT s.scope from storage_pool s, volumes v where s.id = v.pool_id and v.id = ?"; - private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? " - + " AND pool.pod_id = ? AND pool.cluster_id = ? " + " GROUP BY pool.id ORDER BY 2 ASC "; + private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_PART1 = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? "; + private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_PART2 = " GROUP BY pool.id ORDER BY 2 ASC "; + private static final String ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? " + " AND pool.scope = 'ZONE' AND pool.status='Up' " + " GROUP BY pool.id ORDER BY 2 ASC "; @@ -336,7 +343,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol } else if (scope == ScopeType.ZONE) { sql = SELECT_HYPERTYPE_FROM_ZONE_VOLUME; } else { - s_logger.error("Unhandled scope type '" + scope + "' when running getHypervisorType on volume id " + volumeId); + logger.error("Unhandled scope type '" + scope + "' when running getHypervisorType on volume id " + volumeId); } pstmt = txn.prepareAutoCloseStatement(sql); @@ -366,7 +373,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol } else if (type.equals(HypervisorType.VMware)) { return ImageFormat.OVA; } else { - s_logger.warn("Do not support hypervisor " + type.toString()); + logger.warn("Do not support hypervisor " + type.toString()); return null; } } @@ -444,6 +451,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol CountByAccount.and("account", CountByAccount.entity().getAccountId(), SearchCriteria.Op.EQ); CountByAccount.and("state", CountByAccount.entity().getState(), SearchCriteria.Op.NIN); CountByAccount.and("displayVolume", CountByAccount.entity().isDisplayVolume(), Op.EQ); + CountByAccount.and("idNIN", CountByAccount.entity().getId(), Op.NIN); CountByAccount.done(); primaryStorageSearch = createSearchBuilder(SumCount.class); @@ -455,6 +463,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol primaryStorageSearch.and("displayVolume", primaryStorageSearch.entity().isDisplayVolume(), Op.EQ); primaryStorageSearch.and("isRemoved", primaryStorageSearch.entity().getRemoved(), Op.NULL); primaryStorageSearch.and("NotCountStates", primaryStorageSearch.entity().getState(), Op.NIN); + primaryStorageSearch.and("idNIN", primaryStorageSearch.entity().getId(), Op.NIN); primaryStorageSearch.done(); primaryStorageSearch2 = createSearchBuilder(SumCount.class); @@ -469,6 +478,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol primaryStorageSearch2.and("displayVolume", primaryStorageSearch2.entity().isDisplayVolume(), Op.EQ); primaryStorageSearch2.and("isRemoved", primaryStorageSearch2.entity().getRemoved(), Op.NULL); primaryStorageSearch2.and("NotCountStates", primaryStorageSearch2.entity().getState(), Op.NIN); + primaryStorageSearch2.and("idNIN", primaryStorageSearch2.entity().getId(), Op.NIN); primaryStorageSearch2.done(); secondaryStorageSearch = createSearchBuilder(SumCount.class); @@ -507,15 +517,24 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol @Override public Long countAllocatedVolumesForAccount(long accountId) { + List reservations = reservationDao.getReservationsForAccount(accountId, Resource.ResourceType.volume, null); + List reservedResourceIds = reservations.stream().filter(reservation -> reservation.getReservedAmount() > 0).map(ReservationVO::getResourceId).collect(Collectors.toList()); + SearchCriteria sc = CountByAccount.create(); sc.setParameters("account", accountId); - sc.setParameters("state", Volume.State.Destroy, Volume.State.Expunged); + sc.setParameters("state", State.Destroy, State.Expunged); sc.setParameters("displayVolume", 1); + if (CollectionUtils.isNotEmpty(reservedResourceIds)) { + sc.setParameters("idNIN", reservedResourceIds.toArray()); + } return customSearch(sc, null).get(0); } @Override public long primaryStorageUsedForAccount(long accountId, List virtualRouters) { + List reservations = reservationDao.getReservationsForAccount(accountId, Resource.ResourceType.volume, null); + List reservedResourceIds = reservations.stream().filter(reservation -> reservation.getReservedAmount() > 0).map(ReservationVO::getResourceId).collect(Collectors.toList()); + SearchCriteria sc; if (!virtualRouters.isEmpty()) { sc = primaryStorageSearch2.create(); @@ -527,6 +546,9 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol sc.setParameters("states", State.Allocated); sc.setParameters("NotCountStates", State.Destroy, State.Expunged); sc.setParameters("displayVolume", 1); + if (CollectionUtils.isNotEmpty(reservedResourceIds)) { + sc.setParameters("idNIN", reservedResourceIds.toArray()); + } List storageSpace = customSearch(sc, null); if (storageSpace != null) { return storageSpace.get(0).sum; @@ -591,7 +613,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol builder.set(vo, "updated", new Date()); int rows = update((VolumeVO)vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { VolumeVO dbVol = findByIdIncludingRemoved(vo.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -602,7 +624,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated) .append("; updatedTime=").append(oldUpdatedTime); } else { - s_logger.debug("Unable to update volume: id=" + vo.getId() + ", as there is no such volume exists in the database anymore"); + logger.debug("Unable to update volume: id=" + vo.getId() + ", as there is no such volume exists in the database anymore"); } } return rows > 0; @@ -612,14 +634,27 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol public List listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; - List result = new ArrayList(); + List result = new ArrayList<>(); + StringBuilder sql = new StringBuilder(ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_PART1); try { - String sql = ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT; - pstmt = txn.prepareAutoCloseStatement(sql); - pstmt.setLong(1, accountId); - pstmt.setLong(2, dcId); - pstmt.setLong(3, podId); - pstmt.setLong(4, clusterId); + List resourceIdList = new ArrayList<>(); + resourceIdList.add(accountId); + resourceIdList.add(dcId); + + if (podId != null) { + sql.append(" AND pool.pod_id = ?"); + resourceIdList.add(podId); + } + if (clusterId != null) { + sql.append(" AND pool.cluster_id = ?"); + resourceIdList.add(clusterId); + } + sql.append(ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_PART2); + + pstmt = txn.prepareAutoCloseStatement(sql.toString()); + for (int i = 0; i < resourceIdList.size(); i++) { + pstmt.setLong(i + 1, resourceIdList.get(i)); + } ResultSet rs = pstmt.executeQuery(); while (rs.next()) { @@ -627,9 +662,11 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol } return result; } catch (SQLException e) { - throw new CloudRuntimeException("DB Exception on: " + ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e); + logger.debug("DB Exception on: " + sql.toString(), e); + throw new CloudRuntimeException(e); } catch (Throwable e) { - throw new CloudRuntimeException("Caught: " + ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e); + logger.debug("Caught: " + sql.toString(), e); + throw new CloudRuntimeException(e); } } @@ -700,7 +737,7 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol public boolean remove(Long id) { TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); - s_logger.debug(String.format("Removing volume %s from DB", id)); + logger.debug(String.format("Removing volume %s from DB", id)); VolumeVO entry = findById(id); if (entry != null) { _tagsDao.removeByIdAndType(id, ResourceObjectType.Volume); @@ -825,4 +862,38 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol sc.setParameters("idIN", ids.toArray()); return listBy(sc, null); } + + @Override + public List listAllocatedVolumesForAccountDiskOfferingIdsAndNotForVms(long accountId, List diskOfferingIds, List vmIds) { + SearchBuilder sb = createSearchBuilder(); + sb.and("account", sb.entity().getAccountId(), SearchCriteria.Op.EQ); + sb.and("state", sb.entity().getState(), SearchCriteria.Op.NIN); + sb.and("diskOfferingIds", sb.entity().getDiskOfferingId(), SearchCriteria.Op.IN); + sb.and("displayVolume", sb.entity().isDisplayVolume(), Op.EQ); + if (CollectionUtils.isNotEmpty(vmIds)) { + sb.and().op("instanceId", sb.entity().getInstanceId(), Op.NULL); + sb.or("notVmIds", sb.entity().getInstanceId(), Op.NIN); + sb.cp(); + } + sb.done(); + SearchCriteria sc = sb.create(); + sc.setParameters("account", accountId); + sc.setParameters("state", Volume.State.Destroy, Volume.State.Expunged); + sc.setParameters("diskOfferingIds", diskOfferingIds.toArray()); + sc.setParameters("displayVolume", 1); + if (CollectionUtils.isNotEmpty(vmIds)) { + sc.setParameters("notVmIds", vmIds.toArray()); + } + return listBy(sc); + } + + @Override + public VolumeVO persist(VolumeVO entity) { + return Transaction.execute((TransactionCallback) status -> { + VolumeVO volume = super.persist(entity); + reservationDao.setResourceId(Resource.ResourceType.volume, volume.getId()); + reservationDao.setResourceId(Resource.ResourceType.primary_storage, volume.getId()); + return volume; + }); + } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/ConfigurationGroupsAggregator.java b/engine/schema/src/main/java/com/cloud/upgrade/ConfigurationGroupsAggregator.java index 34de1bccb82..03857137ded 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/ConfigurationGroupsAggregator.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/ConfigurationGroupsAggregator.java @@ -30,13 +30,14 @@ import org.apache.cloudstack.framework.config.impl.ConfigurationSubGroupVO; import org.apache.cloudstack.framework.config.impl.ConfigurationVO; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ConfigurationGroupsAggregator { - static final Logger LOG = Logger.getLogger(ConfigurationGroupsAggregator.class); + protected Logger LOG = LogManager.getLogger(getClass()); @Inject ConfigurationDao configDao; diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java index 7bf5cf62790..154a8d11887 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseCreator.java @@ -74,7 +74,7 @@ public class DatabaseCreator { private static void runQuery(String host, String port, String rootPassword, String query, boolean dryRun) { System.out.println("============> Running query: " + query); - try (Connection conn = DriverManager.getConnection(String.format("jdbc:mysql://%s:%s/", host, port), "root", rootPassword); + try (Connection conn = DriverManager.getConnection(String.format("jdbc:mysql://%s:%s/?" + TransactionLegacy.CONNECTION_PARAMS, host, port), "root", rootPassword); Statement stmt = conn.createStatement();){ if (!dryRun) stmt.executeUpdate(query); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseIntegrityChecker.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseIntegrityChecker.java index 1fc8b7e3d84..e7ea6025ad7 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseIntegrityChecker.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseIntegrityChecker.java @@ -23,7 +23,6 @@ import java.sql.SQLException; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.utils.CloudStackVersion; @@ -38,7 +37,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class DatabaseIntegrityChecker extends AdapterBase implements SystemIntegrityChecker { - private static final Logger s_logger = Logger.getLogger(DatabaseIntegrityChecker.class); @Inject VersionDao _dao; @@ -102,32 +100,32 @@ public class DatabaseIntegrityChecker extends AdapterBase implements SystemInteg } catch (Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage(),e); } } catch (Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage(),e); } } if (noDuplicate) { - s_logger.debug("No duplicate hosts with the same local storage found in database"); + logger.debug("No duplicate hosts with the same local storage found in database"); } else { - s_logger.error(helpInfo.toString()); + logger.error(helpInfo.toString()); } txn.commit(); return noDuplicate; }catch (Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage(),e); } } catch (Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage()); throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage: Exception :" + e.getMessage(),e); } finally @@ -138,7 +136,7 @@ public class DatabaseIntegrityChecker extends AdapterBase implements SystemInteg } }catch(Exception e) { - s_logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception:"+ e.getMessage()); + logger.error("checkDuplicateHostWithTheSameLocalStorage: Exception:"+ e.getMessage()); } } } @@ -151,7 +149,7 @@ public class DatabaseIntegrityChecker extends AdapterBase implements SystemInteg String tableName = rs.getString(1); if (tableName.equalsIgnoreCase("usage_event") || tableName.equalsIgnoreCase("usage_port_forwarding") || tableName.equalsIgnoreCase("usage_network_offering")) { num++; - s_logger.debug("Checking 21to22PremiumUprage table " + tableName + " found"); + logger.debug("Checking 21to22PremiumUprage table " + tableName + " found"); } if (num == 3) { return true; @@ -167,7 +165,7 @@ public class DatabaseIntegrityChecker extends AdapterBase implements SystemInteg boolean found = false; while (rs.next()) { if (column.equalsIgnoreCase(rs.getString(1))) { - s_logger.debug(String.format("Column %1$s.%2$s.%3$s found", dbName, tableName, column)); + logger.debug(String.format("Column %1$s.%2$s.%3$s found", dbName, tableName, column)); found = true; break; } @@ -224,33 +222,33 @@ public class DatabaseIntegrityChecker extends AdapterBase implements SystemInteg } } if (!hasUsage) { - s_logger.debug("No cloud_usage found in database, no need to check missed premium upgrade"); + logger.debug("No cloud_usage found in database, no need to check missed premium upgrade"); txn.commit(); return true; } if (!check21to22PremiumUprage(conn)) { - s_logger.error("21to22 premium upgrade missed"); + logger.error("21to22 premium upgrade missed"); txn.commit(); return false; } if (!check221to222PremiumUprage(conn)) { - s_logger.error("221to222 premium upgrade missed"); + logger.error("221to222 premium upgrade missed"); txn.commit(); return false; } if (!check222to224PremiumUpgrade(conn)) { - s_logger.error("222to224 premium upgrade missed"); + logger.error("222to224 premium upgrade missed"); txn.commit(); return false; } txn.commit(); return true; } catch (Exception e) { - s_logger.error("checkMissedPremiumUpgradeFor228: Exception:" + e.getMessage()); + logger.error("checkMissedPremiumUpgradeFor228: Exception:" + e.getMessage()); throw new CloudRuntimeException("checkMissedPremiumUpgradeFor228: Exception:" + e.getMessage(), e); } }catch (Exception e) { - s_logger.error("checkMissedPremiumUpgradeFor228: Exception:"+ e.getMessage()); + logger.error("checkMissedPremiumUpgradeFor228: Exception:"+ e.getMessage()); throw new CloudRuntimeException("checkMissedPremiumUpgradeFor228: Exception:" + e.getMessage(),e); } finally @@ -261,7 +259,7 @@ public class DatabaseIntegrityChecker extends AdapterBase implements SystemInteg } }catch(Exception e) { - s_logger.error("checkMissedPremiumUpgradeFor228: Exception:"+ e.getMessage()); + logger.error("checkMissedPremiumUpgradeFor228: Exception:"+ e.getMessage()); } } } @@ -270,19 +268,19 @@ public class DatabaseIntegrityChecker extends AdapterBase implements SystemInteg public void check() { GlobalLock lock = GlobalLock.getInternLock("DatabaseIntegrity"); try { - s_logger.info("Grabbing lock to check for database integrity."); + logger.info("Grabbing lock to check for database integrity."); if (!lock.lock(20 * 60)) { throw new CloudRuntimeException("Unable to acquire lock to check for database integrity."); } try { - s_logger.info("Performing database integrity check"); + logger.info("Performing database integrity check"); if (!checkDuplicateHostWithTheSameLocalStorage()) { throw new CloudRuntimeException("checkDuplicateHostWithTheSameLocalStorage detected error"); } if (!checkMissedPremiumUpgradeFor228()) { - s_logger.error("Your current database version is 2.2.8, management server detected some missed premium upgrade, please contact CloudStack support and attach log file. Thank you!"); + logger.error("Your current database version is 2.2.8, management server detected some missed premium upgrade, please contact CloudStack support and attach log file. Thank you!"); throw new CloudRuntimeException("Detected missed premium upgrade"); } } finally { @@ -298,7 +296,7 @@ public class DatabaseIntegrityChecker extends AdapterBase implements SystemInteg try { check(); } catch (Exception e) { - s_logger.error("System integrity check exception", e); + logger.error("System integrity check exception", e); System.exit(1); } return true; diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java index 697782dc1db..ea8ce47611a 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java @@ -33,10 +33,12 @@ import java.util.List; import javax.inject.Inject; +import com.cloud.upgrade.dao.Upgrade41900to42000; import com.cloud.utils.FileUtil; import org.apache.cloudstack.utils.CloudStackVersion; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.upgrade.dao.DbUpgrade; import com.cloud.upgrade.dao.DbUpgradeSystemVmTemplate; @@ -124,7 +126,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.google.common.annotations.VisibleForTesting; public class DatabaseUpgradeChecker implements SystemIntegrityChecker { - private static final Logger s_logger = Logger.getLogger(DatabaseUpgradeChecker.class); + protected static Logger LOGGER = LogManager.getLogger(DatabaseUpgradeChecker.class); private final DatabaseVersionHierarchy hierarchy; private static final String VIEWS_DIRECTORY = Paths.get("META-INF", "db", "views").toString(); @@ -224,6 +226,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { .next("4.17.2.0", new Upgrade41720to41800()) .next("4.18.0.0", new Upgrade41800to41810()) .next("4.18.1.0", new Upgrade41810to41900()) + .next("4.19.0.0", new Upgrade41900to42000()) .build(); } @@ -233,10 +236,10 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { ScriptRunner runner = new ScriptRunner(conn, false, true); runner.runScript(reader); } catch (IOException e) { - s_logger.error("Unable to read upgrade script", e); + LOGGER.error("Unable to read upgrade script", e); throw new CloudRuntimeException("Unable to read upgrade script", e); } catch (SQLException e) { - s_logger.error("Unable to execute upgrade script", e); + LOGGER.error("Unable to execute upgrade script", e); throw new CloudRuntimeException("Unable to execute upgrade script", e); } @@ -275,7 +278,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { conn = txn.getConnection(); } catch (SQLException e) { String errorMessage = "Unable to upgrade the database"; - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } ((DbUpgradeSystemVmTemplate)upgrade).updateSystemVmTemplates(conn); @@ -283,7 +286,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { break; } catch (CloudRuntimeException e) { String errorMessage = "Unable to upgrade the database"; - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } finally { txn.close(); @@ -293,13 +296,13 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { } protected void upgrade(CloudStackVersion dbVersion, CloudStackVersion currentVersion) { - s_logger.info("Database upgrade must be performed from " + dbVersion + " to " + currentVersion); + LOGGER.info("Database upgrade must be performed from " + dbVersion + " to " + currentVersion); final DbUpgrade[] upgrades = calculateUpgradePath(dbVersion, currentVersion); for (DbUpgrade upgrade : upgrades) { VersionVO version; - s_logger.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade + LOGGER.debug("Running upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade .getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion()); TransactionLegacy txn = TransactionLegacy.open("Upgrade"); txn.start(); @@ -309,7 +312,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { conn = txn.getConnection(); } catch (SQLException e) { String errorMessage = "Unable to upgrade the database"; - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } InputStream[] scripts = upgrade.getPrepareScripts(); @@ -327,7 +330,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { txn.commit(); } catch (CloudRuntimeException e) { String errorMessage = "Unable to upgrade the database"; - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } finally { txn.close(); @@ -336,7 +339,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { // Run the corresponding '-cleanup.sql' script txn = TransactionLegacy.open("Cleanup"); try { - s_logger.info("Cleanup upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade + LOGGER.info("Cleanup upgrade " + upgrade.getClass().getSimpleName() + " to upgrade from " + upgrade.getUpgradableVersionRange()[0] + "-" + upgrade .getUpgradableVersionRange()[1] + " to " + upgrade.getUpgradedVersion()); txn.start(); @@ -344,7 +347,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { try { conn = txn.getConnection(); } catch (SQLException e) { - s_logger.error("Unable to cleanup the database", e); + LOGGER.error("Unable to cleanup the database", e); throw new CloudRuntimeException("Unable to cleanup the database", e); } @@ -352,7 +355,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { if (scripts != null) { for (InputStream script : scripts) { runScript(conn, script); - s_logger.debug("Cleanup script " + upgrade.getClass().getSimpleName() + " is executed successfully"); + LOGGER.debug("Cleanup script " + upgrade.getClass().getSimpleName() + " is executed successfully"); } } txn.commit(); @@ -362,7 +365,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { version.setUpdated(new Date()); _dao.update(version.getId(), version); txn.commit(); - s_logger.debug("Upgrade completed for version " + version.getVersion()); + LOGGER.debug("Upgrade completed for version " + version.getVersion()); } finally { txn.close(); } @@ -373,23 +376,23 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { } protected void executeViewScripts() { - s_logger.info(String.format("Executing VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY)); + LOGGER.info(String.format("Executing VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY)); List filesPathUnderViewsDirectory = FileUtil.getFilesPathsUnderResourceDirectory(VIEWS_DIRECTORY); try (TransactionLegacy txn = TransactionLegacy.open("execute-view-scripts")) { Connection conn = txn.getConnection(); for (String filePath : filesPathUnderViewsDirectory) { - s_logger.debug(String.format("Executing VIEW script [%s].", filePath)); + LOGGER.debug(String.format("Executing VIEW script [%s].", filePath)); InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath); runScript(conn, viewScript); } - s_logger.info(String.format("Finished execution of VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY)); + LOGGER.info(String.format("Finished execution of VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY)); } catch (SQLException e) { String message = String.format("Unable to execute VIEW scripts due to [%s].", e.getMessage()); - s_logger.error(message, e); + LOGGER.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -398,7 +401,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { public void check() { GlobalLock lock = GlobalLock.getInternLock("DatabaseUpgrade"); try { - s_logger.info("Grabbing lock to check for database upgrade."); + LOGGER.info("Grabbing lock to check for database upgrade."); if (!lock.lock(20 * 60)) { throw new CloudRuntimeException("Unable to acquire lock to check for database integrity."); } @@ -419,14 +422,14 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { SystemVmTemplateRegistration.CS_MAJOR_VERSION = String.valueOf(sysVmVersion.getMajorRelease()) + "." + String.valueOf(sysVmVersion.getMinorRelease()); SystemVmTemplateRegistration.CS_TINY_VERSION = String.valueOf(sysVmVersion.getPatchRelease()); - s_logger.info("DB version = " + dbVersion + " Code Version = " + currentVersion); + LOGGER.info("DB version = " + dbVersion + " Code Version = " + currentVersion); if (dbVersion.compareTo(currentVersion) > 0) { throw new CloudRuntimeException("Database version " + dbVersion + " is higher than management software version " + currentVersionValue); } if (dbVersion.compareTo(currentVersion) == 0) { - s_logger.info("DB version and code version matches so no upgrade needed."); + LOGGER.info("DB version and code version matches so no upgrade needed."); return; } @@ -449,13 +452,13 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { decryptInit(conn); txn.commit(); } catch (CloudRuntimeException e) { - s_logger.error(e.getMessage()); + LOGGER.error(e.getMessage()); errorMessage = String.format("Unable to initialize the database encryptors due to %s. " + "Please check if database encryption key and database encryptor version are correct.", errorMessage); - s_logger.error(errorMessage); + LOGGER.error(errorMessage); throw new CloudRuntimeException(errorMessage, e); } catch (SQLException e) { - s_logger.error(errorMessage, e); + LOGGER.error(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } finally { txn.close(); @@ -468,7 +471,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { ResultSet result = pstmt.executeQuery()) { if (result.next()) { String init = result.getString(1); - s_logger.info("init = " + DBEncryptionUtil.decrypt(init)); + LOGGER.info("init = " + DBEncryptionUtil.decrypt(init)); } } } @@ -525,7 +528,7 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker { @Override public void updateSystemVmTemplates(Connection conn) { - s_logger.debug("Updating System Vm template IDs"); + LOGGER.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/GuestOsMapper.java b/engine/schema/src/main/java/com/cloud/upgrade/GuestOsMapper.java index 4aabaa3e182..abb0d7f7669 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/GuestOsMapper.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/GuestOsMapper.java @@ -18,7 +18,8 @@ package com.cloud.upgrade; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.sql.Connection; import java.sql.PreparedStatement; @@ -40,7 +41,7 @@ import com.cloud.storage.dao.GuestOSHypervisorDaoImpl; public class GuestOsMapper { - final static Logger LOG = Logger.getLogger(GuestOsMapper.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject GuestOSHypervisorDao guestOSHypervisorDao; @@ -56,15 +57,15 @@ public class GuestOsMapper { } public void mergeDuplicates() { - LOG.info("merging duplicate guest osses"); + logger.info("merging duplicate guest osses"); Set> duplicates = findDuplicates(); - LOG.debug(String.format("merging %d sets of duplicates", duplicates.size())); + logger.debug(String.format("merging %d sets of duplicates", duplicates.size())); for (Set setOfGuestOSes : duplicates) { // decide which to (mark as) remove(d) // # highest/lowest id // # or is user_defined == false GuestOSVO guestOSVO = highestIdFrom(setOfGuestOSes); - LOG.info(String.format("merging %d duplicates for %s ", setOfGuestOSes.size(), guestOSVO.getDisplayName())); + logger.info(String.format("merging %d duplicates for %s ", setOfGuestOSes.size(), guestOSVO.getDisplayName())); makeNormative(guestOSVO, setOfGuestOSes); } @@ -144,7 +145,7 @@ public class GuestOsMapper { if (guestOS != null) { id = guestOS.getId(); } else { - LOG.warn(String.format("Unable to find the guest OS details with category id: %d and display name: %s", + categoryId, displayName)); + logger.warn(String.format("Unable to find the guest OS details with category id: %d and display name: %s", + categoryId, displayName)); } return id; } @@ -155,7 +156,7 @@ public class GuestOsMapper { if (guestOSHypervisorVO != null) { id = guestOSHypervisorVO.getGuestOsId(); } else { - LOG.warn(String.format("Unable to find the guest OS hypervisor mapping details for %s", mapping.toString())); + logger.warn(String.format("Unable to find the guest OS hypervisor mapping details for %s", mapping.toString())); } return id; } @@ -163,9 +164,9 @@ public class GuestOsMapper { public void addGuestOsAndHypervisorMappings(long categoryId, String displayName, List mappings) { long guestOsId = getGuestOsId(categoryId, displayName); if (guestOsId == 0) { - LOG.debug("No guest OS found with category id: " + categoryId + " and display name: " + displayName); + logger.debug("No guest OS found with category id: " + categoryId + " and display name: " + displayName); if (!addGuestOs(categoryId, displayName)) { - LOG.warn("Couldn't add the guest OS with category id: " + categoryId + " and display name: " + displayName); + logger.warn("Couldn't add the guest OS with category id: " + categoryId + " and display name: " + displayName); return; } guestOsId = getGuestOsId(categoryId, displayName); @@ -189,7 +190,7 @@ public class GuestOsMapper { } public boolean addGuestOs(long categoryId, String displayName) { - LOG.debug("Adding guest OS with category id: " + categoryId + " and display name: " + displayName); + logger.debug("Adding guest OS with category id: " + categoryId + " and display name: " + displayName); GuestOSVO guestOS = new GuestOSVO(); guestOS.setCategoryId(categoryId); guestOS.setDisplayName(displayName); @@ -199,7 +200,7 @@ public class GuestOsMapper { public void addGuestOsHypervisorMapping(GuestOSHypervisorMapping mapping, long category, String displayName) { long guestOsId = getGuestOsId(category, displayName); if (guestOsId == 0) { - LOG.error(String.format("no guest os found for category %d and name %s, skipping mapping it to %s/%s", guestOsId, displayName, mapping.getHypervisorType(), mapping.getHypervisorVersion())); + logger.error(String.format("no guest os found for category %d and name %s, skipping mapping it to %s/%s", guestOsId, displayName, mapping.getHypervisorType(), mapping.getHypervisorVersion())); } else { addGuestOsHypervisorMapping(mapping, guestOsId); } @@ -210,7 +211,7 @@ public class GuestOsMapper { return; } - LOG.debug("Adding guest OS hypervisor mapping - " + mapping.toString() + ", for guest OS with id - " + guestOsId); + logger.debug("Adding guest OS hypervisor mapping - " + mapping.toString() + ", for guest OS with id - " + guestOsId); GuestOSHypervisorVO guestOsMapping = new GuestOSHypervisorVO(); guestOsMapping.setHypervisorType(mapping.getHypervisorType()); guestOsMapping.setHypervisorVersion(mapping.getHypervisorVersion()); @@ -222,7 +223,7 @@ public class GuestOsMapper { public void updateGuestOsName(long categoryId, String oldDisplayName, String newDisplayName) { GuestOSVO guestOS = guestOSDao.findByCategoryIdAndDisplayNameOrderByCreatedDesc(categoryId, oldDisplayName); if (guestOS == null) { - LOG.debug("Unable to update guest OS name, as there is no guest OS with category id: " + categoryId + " and display name: " + oldDisplayName); + logger.debug("Unable to update guest OS name, as there is no guest OS with category id: " + categoryId + " and display name: " + oldDisplayName); return; } @@ -237,7 +238,7 @@ public class GuestOsMapper { GuestOSHypervisorVO guestOSHypervisorVO = guestOSHypervisorDao.findByOsNameAndHypervisorOrderByCreatedDesc(mapping.getGuestOsName(), mapping.getHypervisorType(), mapping.getHypervisorVersion()); if (guestOSHypervisorVO == null) { - LOG.debug("Unable to update guest OS name, as there is no guest os hypervisor mapping"); + logger.debug("Unable to update guest OS name, as there is no guest os hypervisor mapping"); return; } @@ -256,13 +257,13 @@ public class GuestOsMapper { long oldGuestOsId = getGuestOsIdFromHypervisorMapping(mapping); if (oldGuestOsId == 0) { - LOG.debug("Unable to update guest OS in hypervisor mapping, as there is no guest os hypervisor mapping - " + mapping.toString()); + logger.debug("Unable to update guest OS in hypervisor mapping, as there is no guest os hypervisor mapping - " + mapping.toString()); return; } long newGuestOsId = getGuestOsId(categoryId, displayName); if (newGuestOsId == 0) { - LOG.debug("Unable to update guest OS id in hypervisor mapping, as there is no guest OS with category id: " + categoryId + " and display name: " + displayName); + logger.debug("Unable to update guest OS id in hypervisor mapping, as there is no guest OS with category id: " + categoryId + " and display name: " + displayName); return; } @@ -270,7 +271,7 @@ public class GuestOsMapper { } private void updateGuestOsIdInMapping(Connection conn, long oldGuestOsId, long newGuestOsId, GuestOSHypervisorMapping mapping) { - LOG.debug("Updating guest os id: " + oldGuestOsId + " to id: " + newGuestOsId + " in hypervisor mapping - " + mapping.toString()); + logger.debug("Updating guest os id: " + oldGuestOsId + " to id: " + newGuestOsId + " in hypervisor mapping - " + mapping.toString()); try { PreparedStatement pstmt = conn.prepareStatement(updateGuestOsHypervisorSql); pstmt.setLong(1, newGuestOsId); @@ -280,7 +281,7 @@ public class GuestOsMapper { pstmt.setString(5, mapping.getGuestOsName()); pstmt.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to update guest OS id in hypervisor mapping due to: " + e.getMessage(), e); + logger.error("Failed to update guest OS id in hypervisor mapping due to: " + e.getMessage(), e); } } @@ -289,7 +290,7 @@ public class GuestOsMapper { return true; } - LOG.warn("Invalid Guest OS hypervisor mapping"); + logger.warn("Invalid Guest OS hypervisor mapping"); return false; } @@ -299,22 +300,22 @@ public class GuestOsMapper { */ public boolean copyGuestOSHypervisorMappings(HypervisorType hypervisorType, String srcVersion, String destVersion) { if (hypervisorType == HypervisorType.None || hypervisorType == HypervisorType.Any) { - LOG.warn("Unable to copy, invalid hypervisor"); + logger.warn("Unable to copy, invalid hypervisor"); return false; } if (StringUtils.isAnyBlank(srcVersion, destVersion)) { - LOG.warn("Unable to copy, invalid hypervisor version details"); + logger.warn("Unable to copy, invalid hypervisor version details"); return false; } List guestOSHypervisorMappingsForSrcVersion = guestOSHypervisorDao.listByHypervisorTypeAndVersion(hypervisorType.toString(), srcVersion); if (CollectionUtils.isEmpty(guestOSHypervisorMappingsForSrcVersion)) { - LOG.warn(String.format("Unable to copy, couldn't find guest OS mappings for hypervisor: %s and src version: %s", hypervisorType.toString(), srcVersion)); + logger.warn(String.format("Unable to copy, couldn't find guest OS mappings for hypervisor: %s and src version: %s", hypervisorType.toString(), srcVersion)); return false; } - LOG.debug(String.format("Adding guest OS mappings for hypervisor: %s and version: %s, from version: %s ", hypervisorType.toString(), destVersion, srcVersion)); + logger.debug(String.format("Adding guest OS mappings for hypervisor: %s and version: %s, from version: %s ", hypervisorType.toString(), destVersion, srcVersion)); for (GuestOSHypervisorVO guestOSHypervisorMapping : guestOSHypervisorMappingsForSrcVersion) { GuestOSHypervisorMapping mapping = new GuestOSHypervisorMapping(hypervisorType.toString(), destVersion, guestOSHypervisorMapping.getGuestOsName()); addGuestOsHypervisorMapping(mapping, guestOSHypervisorMapping.getGuestOsId()); @@ -329,7 +330,7 @@ public class GuestOsMapper { long guestOsId = getGuestOsId(categoryId, displayName); if (guestOsId == 0) { - LOG.error(String.format("no guest os found for category %d and name %s, skipping mapping it to %s/%s", guestOsId, displayName, mapping.getHypervisorType(), mapping.getHypervisorVersion())); + logger.error(String.format("no guest os found for category %d and name %s, skipping mapping it to %s/%s", guestOsId, displayName, mapping.getHypervisorType(), mapping.getHypervisorVersion())); return; } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/RolePermissionChecker.java b/engine/schema/src/main/java/com/cloud/upgrade/RolePermissionChecker.java index 6d434cda755..370b85e37be 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/RolePermissionChecker.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/RolePermissionChecker.java @@ -16,7 +16,8 @@ // under the License. package com.cloud.upgrade; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.sql.Connection; import java.sql.PreparedStatement; @@ -25,7 +26,7 @@ import java.sql.SQLException; public class RolePermissionChecker { - final static Logger LOG = Logger.getLogger(RolePermissionChecker.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String checkAnnotationRulesPermissionPreparedStatement = "SELECT permission FROM `cloud`.`role_permissions` WHERE role_id = ? AND rule = ?"; @@ -43,7 +44,7 @@ public class RolePermissionChecker { ResultSet rs = pstmt.executeQuery(); return rs != null && rs.next(); } catch (SQLException e) { - LOG.error("Error on existsRolePermissionByRoleIdAndRule: " + e.getMessage(), e); + logger.error("Error on existsRolePermissionByRoleIdAndRule: " + e.getMessage(), e); return false; } } @@ -55,7 +56,7 @@ public class RolePermissionChecker { pstmt.setString(2, rule); pstmt.executeUpdate(); } catch (SQLException e) { - LOG.error("Error on insertAnnotationRulePermission: " + e.getMessage(), e); + logger.error("Error on insertAnnotationRulePermission: " + e.getMessage(), e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java b/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java index dc94dd708b1..33371fc436e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java @@ -56,7 +56,8 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.utils.security.DigestHelper; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.ini4j.Ini; import javax.inject.Inject; @@ -82,7 +83,7 @@ import java.util.UUID; import java.util.stream.Collectors; public class SystemVmTemplateRegistration { - private static final Logger LOGGER = Logger.getLogger(SystemVmTemplateRegistration.class); + protected static Logger LOGGER = LogManager.getLogger(SystemVmTemplateRegistration.class); private static final String MOUNT_COMMAND = "sudo mount -t nfs %s %s"; private static final String UMOUNT_COMMAND = "sudo umount %s"; private static final String RELATIVE_TEMPLATE_PATH = "./engine/schema/dist/systemvm-templates/"; @@ -445,7 +446,7 @@ public class SystemVmTemplateRegistration { private List fetchAllHypervisors(Long zoneId) { List hypervisorList = new ArrayList<>(); List hypervisorTypes = clusterDao.getAvailableHypervisorInZone(zoneId); - hypervisorList = hypervisorTypes.stream().distinct().map(Enum::name).collect(Collectors.toList()); + hypervisorList = hypervisorTypes.stream().distinct().map(Hypervisor.HypervisorType::name).collect(Collectors.toList()); return hypervisorList; } @@ -718,8 +719,8 @@ public class SystemVmTemplateRegistration { } private void validateTemplates(Set hypervisorsInUse) { - Set hypervisors = hypervisorsInUse.stream().map(Enum::name). - map(name -> name.toLowerCase(Locale.ROOT)).map(this::getHypervisorName).collect(Collectors.toSet()); + Set hypervisors = hypervisorsInUse.stream(). + map(Hypervisor.HypervisorType::name).map(name -> name.toLowerCase(Locale.ROOT)).map(this::getHypervisorName).collect(Collectors.toSet()); List templates = new ArrayList<>(); for (Hypervisor.HypervisorType hypervisorType : hypervisorsInUse) { templates.add(FileNames.get(hypervisorType)); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java index de161afea07..1c2c4b3c7ce 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/DatabaseAccessObject.java @@ -22,20 +22,21 @@ import java.sql.ResultSet; import java.sql.SQLException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class DatabaseAccessObject { - private static Logger s_logger = Logger.getLogger(DatabaseAccessObject.class); + protected Logger logger = LogManager.getLogger(DatabaseAccessObject.class); public void addForeignKey(Connection conn, String tableName, String tableColumn, String foreignTableName, String foreignColumnName) { String addForeignKeyStmt = String.format("ALTER TABLE `cloud`.`%s` ADD CONSTRAINT `fk_%s__%s` FOREIGN KEY `fk_%s__%s`(`%s`) REFERENCES `%s`(`%s`)", tableName, tableName, tableColumn, tableName, tableColumn, tableColumn, foreignTableName, foreignColumnName); try(PreparedStatement pstmt = conn.prepareStatement(addForeignKeyStmt);) { pstmt.executeUpdate(); - s_logger.debug(String.format("Foreign key is added successfully from the table %s", tableName)); + logger.debug(String.format("Foreign key is added successfully from the table %s", tableName)); } catch (SQLException e) { - s_logger.error("Ignored SQL Exception when trying to add foreign key on table " + tableName + " exception: " + e.getMessage()); + logger.error("Ignored SQL Exception when trying to add foreign key on table " + tableName + " exception: " + e.getMessage()); } } @@ -50,9 +51,9 @@ public class DatabaseAccessObject { try(PreparedStatement pstmt = conn.prepareStatement(alter_sql_str);) { pstmt.executeUpdate(); - s_logger.debug("Key " + key + " is dropped successfully from the table " + tableName); + logger.debug("Key " + key + " is dropped successfully from the table " + tableName); } catch (SQLException e) { - s_logger.debug("Ignored SQL Exception when trying to drop " + (isForeignKey ? "foreign " : "") + "key " + key + " on table " + tableName + " exception: " + e.getMessage()); + logger.debug("Ignored SQL Exception when trying to drop " + (isForeignKey ? "foreign " : "") + "key " + key + " on table " + tableName + " exception: " + e.getMessage()); } } @@ -60,18 +61,18 @@ public class DatabaseAccessObject { public void dropPrimaryKey(Connection conn, String tableName) { try(PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE " + tableName + " DROP PRIMARY KEY ");) { pstmt.executeUpdate(); - s_logger.debug("Primary key is dropped successfully from the table " + tableName); + logger.debug("Primary key is dropped successfully from the table " + tableName); } catch (SQLException e) { - s_logger.debug("Ignored SQL Exception when trying to drop primary key on table " + tableName + " exception: " + e.getMessage()); + logger.debug("Ignored SQL Exception when trying to drop primary key on table " + tableName + " exception: " + e.getMessage()); } } public void dropColumn(Connection conn, String tableName, String columnName) { try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE " + tableName + " DROP COLUMN " + columnName);){ pstmt.executeUpdate(); - s_logger.debug("Column " + columnName + " is dropped successfully from the table " + tableName); + logger.debug("Column " + columnName + " is dropped successfully from the table " + tableName); } catch (SQLException e) { - s_logger.warn("Unable to drop column " + columnName + " due to exception", e); + logger.warn("Unable to drop column " + columnName + " due to exception", e); } } @@ -81,7 +82,7 @@ public class DatabaseAccessObject { pstmt.executeQuery(); columnExists = true; } catch (SQLException e) { - s_logger.debug("Field " + columnName + " doesn't exist in " + tableName + " ignoring exception: " + e.getMessage()); + logger.debug("Field " + columnName + " doesn't exist in " + tableName + " ignoring exception: " + e.getMessage()); } return columnExists; } @@ -97,29 +98,29 @@ public class DatabaseAccessObject { return true; } } catch (SQLException e) { - s_logger.debug(String.format("Index %s doesn't exist, ignoring exception:", indexName, e.getMessage())); + logger.debug(String.format("Index %s doesn't exist, ignoring exception:", indexName, e.getMessage())); } return false; } public void createIndex(Connection conn, String tableName, String indexName, String... columnNames) { String stmt = String.format("CREATE INDEX %s ON %s (%s)", indexName, tableName, StringUtils.join(columnNames, ", ")); - s_logger.debug("Statement: " + stmt); + logger.debug("Statement: " + stmt); try (PreparedStatement pstmt = conn.prepareStatement(stmt)) { pstmt.execute(); - s_logger.debug(String.format("Created index %s", indexName)); + logger.debug(String.format("Created index %s", indexName)); } catch (SQLException e) { - s_logger.warn(String.format("Unable to create index %s", indexName), e); + logger.warn(String.format("Unable to create index %s", indexName), e); } } - protected static void closePreparedStatement(PreparedStatement pstmt, String errorMessage) { + protected void closePreparedStatement(PreparedStatement pstmt, String errorMessage) { try { if (pstmt != null) { pstmt.close(); } } catch (SQLException e) { - s_logger.warn(errorMessage, e); + logger.warn(errorMessage, e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeAbstractImpl.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeAbstractImpl.java new file mode 100644 index 00000000000..c96365dd6f5 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgradeAbstractImpl.java @@ -0,0 +1,24 @@ +// 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.upgrade.dao; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; + +public abstract class DbUpgradeAbstractImpl implements DbUpgrade { + protected Logger logger = LogManager.getLogger(getClass()); +} diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/LegacyDbUpgrade.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/LegacyDbUpgrade.java index d058943f439..2a64ff496a2 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/LegacyDbUpgrade.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/LegacyDbUpgrade.java @@ -16,11 +16,9 @@ // under the License. package com.cloud.upgrade.dao; -import org.apache.log4j.Logger; -public abstract class LegacyDbUpgrade implements DbUpgrade{ +public abstract class LegacyDbUpgrade extends DbUpgradeAbstractImpl{ - final static Logger s_logger = Logger.getLogger(LegacyDbUpgrade.class); public LegacyDbUpgrade() { super(); @@ -34,7 +32,7 @@ public abstract class LegacyDbUpgrade implements DbUpgrade{ try { closable.close(); } catch (Exception e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade217to218.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade217to218.java index 2ca4e794fb8..5441f8fb02f 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade217to218.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade217to218.java @@ -21,7 +21,7 @@ import java.sql.Connection; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade217to218 implements DbUpgrade { +public class Upgrade217to218 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22.java index bc58794e8bd..171357578ee 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22.java @@ -34,7 +34,6 @@ import java.util.Properties; import java.util.TimeZone; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.configuration.Resource.ResourceType; import com.cloud.event.EventTypes; @@ -45,8 +44,7 @@ import com.cloud.utils.NumbersUtil; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; -public class Upgrade218to22 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade218to22.class); +public class Upgrade218to22 extends DbUpgradeAbstractImpl { boolean _basicZone; @Override @@ -212,7 +210,7 @@ public class Upgrade218to22 implements DbUpgrade { protected void upgradeDomR(Connection conn, long dcId, long domrId, Long publicNetworkId, long guestNetworkId, long controlNetworkId, String zoneType, String vnet) throws SQLException { - s_logger.debug("Upgrading domR" + domrId); + logger.debug("Upgrading domR" + domrId); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT vm_instance.id, vm_instance.state, vm_instance.private_mac_address, vm_instance.private_ip_address, vm_instance.private_netmask, domain_router.public_mac_address, domain_router.public_ip_address, domain_router.public_netmask, domain_router.guest_mac_address, domain_router.guest_ip_address, domain_router.guest_netmask, domain_router.vnet, domain_router.gateway FROM vm_instance INNER JOIN domain_router ON vm_instance.id=domain_router.id WHERE vm_instance.removed is NULL AND vm_instance.id=?"); @@ -274,7 +272,7 @@ public class Upgrade218to22 implements DbUpgrade { protected void upgradeSsvm(Connection conn, long dataCenterId, long publicNetworkId, long managementNetworkId, long controlNetworkId, String zoneType) throws SQLException { - s_logger.debug("Upgrading ssvm in " + dataCenterId); + logger.debug("Upgrading ssvm in " + dataCenterId); //select instance try ( PreparedStatement selectInstance = @@ -284,7 +282,7 @@ public class Upgrade218to22 implements DbUpgrade { try (ResultSet instanceResult = selectInstance.executeQuery();) { if (!instanceResult.next()) { - s_logger.debug("Unable to find ssvm in data center " + dataCenterId); + logger.debug("Unable to find ssvm in data center " + dataCenterId); return; } @@ -309,7 +307,7 @@ public class Upgrade218to22 implements DbUpgrade { try (ResultSet hostResult = selectHost.executeQuery();) { if (!hostResult.next()) { - s_logger.debug("Unable to find ssvm in data center " + dataCenterId); + logger.debug("Unable to find ssvm in data center " + dataCenterId); return; } @@ -365,7 +363,7 @@ public class Upgrade218to22 implements DbUpgrade { protected void upgradeConsoleProxy(Connection conn, long dcId, long cpId, long publicNetworkId, long managementNetworkId, long controlNetworkId, String zoneType) throws SQLException { - s_logger.debug("Upgrading cp" + cpId); + logger.debug("Upgrading cp" + cpId); try (PreparedStatement pstmt = conn.prepareStatement("SELECT vm_instance.id, vm_instance.state, vm_instance.private_mac_address, vm_instance.private_ip_address, vm_instance.private_netmask, console_proxy.public_mac_address, console_proxy.public_ip_address, console_proxy.public_netmask, console_proxy.guest_mac_address, console_proxy.guest_ip_address, console_proxy.guest_netmask, console_proxy.gateway, vm_instance.type FROM vm_instance INNER JOIN console_proxy ON vm_instance.id=console_proxy.id WHERE vm_instance.removed is NULL AND vm_instance.id=?");) { pstmt.setLong(1, cpId); @@ -466,7 +464,7 @@ public class Upgrade218to22 implements DbUpgrade { vm[4] = rs.getString(5); // vm state vms.add(vm); } - s_logger.debug("Upgrading " + vms.size() + " vms for router " + domainRouterId); + logger.debug("Upgrading " + vms.size() + " vms for router " + domainRouterId); for (Object[] vm : vms) { String state = (String)vm[4]; @@ -617,7 +615,7 @@ public class Upgrade218to22 implements DbUpgrade { } protected void upgradeDirectUserIpAddress(Connection conn, long dcId, long networkId, String vlanType) throws SQLException { - s_logger.debug("Upgrading user ip address for data center " + dcId + " network " + networkId + " vlan type " + vlanType); + logger.debug("Upgrading user ip address for data center " + dcId + " network " + networkId + " vlan type " + vlanType); try (PreparedStatement pstmt = conn.prepareStatement("UPDATE user_ip_address INNER JOIN vlan ON user_ip_address.vlan_db_id=vlan.id SET user_ip_address.source_network_id=vlan.network_id WHERE user_ip_address.data_center_id=? AND vlan.vlan_type=?");) { pstmt.setLong(1, dcId); @@ -638,8 +636,8 @@ public class Upgrade218to22 implements DbUpgrade { ip[3] = rs.getDate(4); // allocated allocatedIps.add(ip); } - s_logger.debug("Marking " + allocatedIps.size() + " ip addresses to belong to network " + networkId); - s_logger.debug("Updating mac addresses for data center id=" + dcId + ". Found " + allocatedIps.size() + " ip addresses to update"); + logger.debug("Marking " + allocatedIps.size() + " ip addresses to belong to network " + networkId); + logger.debug("Updating mac addresses for data center id=" + dcId + ". Found " + allocatedIps.size() + " ip addresses to update"); for (Object[] allocatedIp : allocatedIps) { try (PreparedStatement selectMacAddresses = conn.prepareStatement("SELECT mac_address FROM data_center WHERE id = ?");) { selectMacAddresses.setLong(1, dcId); @@ -665,7 +663,7 @@ public class Upgrade218to22 implements DbUpgrade { } protected void upgradePublicUserIpAddress(Connection conn, long dcId, long networkId, String vlanType) throws SQLException { - s_logger.debug("Upgrading user ip address for data center " + dcId + " network " + networkId + " vlan type " + vlanType); + logger.debug("Upgrading user ip address for data center " + dcId + " network " + networkId + " vlan type " + vlanType); try (PreparedStatement pstmt = conn.prepareStatement("UPDATE user_ip_address INNER JOIN vlan ON user_ip_address.vlan_db_id=vlan.id SET source_network_id=? WHERE user_ip_address.data_center_id=? AND vlan.vlan_type=?");) { pstmt.setLong(1, networkId); @@ -763,7 +761,7 @@ public class Upgrade218to22 implements DbUpgrade { } } catch (SQLException e) { - s_logger.error("Can't update data center ", e); + logger.error("Can't update data center ", e); throw new CloudRuntimeException("Can't update data center ", e); } } @@ -832,7 +830,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.setString(1, type); try (ResultSet rs = pstmt.executeQuery();) { if (!rs.next()) { - s_logger.error("Unable to find the network offering for networktype '" + type + "'"); + logger.error("Unable to find the network offering for networktype '" + type + "'"); throw new CloudRuntimeException("Unable to find the storage network offering."); } networkOfferingId = rs.getLong(1); @@ -970,7 +968,7 @@ public class Upgrade218to22 implements DbUpgrade { private void updateRouters(Connection conn, Long dcId, long controlNetworkId, long basicDefaultDirectNetworkId, ArrayList routers) throws SQLException { for (Object[] router : routers) { - s_logger.debug("Updating domR with network id in basic zone id=" + dcId); + logger.debug("Updating domR with network id in basic zone id=" + dcId); updateNetworkForRouter(conn, router, basicDefaultDirectNetworkId); upgradeUserVms(conn, (Long)router[0], basicDefaultDirectNetworkId, (String)router[1], "untagged", "DirectPodBasedNetworkGuru", "Create"); upgradeDomR(conn, dcId, (Long)router[0], null, basicDefaultDirectNetworkId, controlNetworkId, "Basic", "untagged"); @@ -1007,7 +1005,7 @@ public class Upgrade218to22 implements DbUpgrade { updateDomainRouter.setLong(2, (Long)router[0]); updateDomainRouter.executeUpdate(); } - s_logger.debug("Network inserted for " + router[0] + " id = " + virtualNetworkId); + logger.debug("Network inserted for " + router[0] + " id = " + virtualNetworkId); } private void createDirectNetworks(Connection conn, Object[] dc, Long dcId) throws SQLException { @@ -1029,7 +1027,7 @@ public class Upgrade218to22 implements DbUpgrade { updateNetworkInVlanTableforTag(conn, vlanNetworkMap, vlanId, tag); upgradeDirectUserIpAddress(conn, dcId, vlanNetworkMap.get(tag), "DirectAttached"); - s_logger.debug("Created Direct networks and upgraded Direct ip addresses"); + logger.debug("Created Direct networks and upgraded Direct ip addresses"); } } } @@ -1118,11 +1116,11 @@ public class Upgrade218to22 implements DbUpgrade { String gateway = retrieveGateway(conn, directNetworkId); updateDomainRouter(conn, routerId, directNetworkId); - s_logger.debug("NetworkId updated for router id=" + routerId + "with network id = " + directNetworkId); + logger.debug("NetworkId updated for router id=" + routerId + "with network id = " + directNetworkId); upgradeUserVms(conn, routerId, directNetworkId, gateway, vnet, "DirectNetworkGuru", "Create"); - s_logger.debug("Upgraded Direct vms in Advance zone id=" + dcId); + logger.debug("Upgraded Direct vms in Advance zone id=" + dcId); upgradeDomR(conn, dcId, routerId, null, directNetworkId, controlNetworkId, "Advanced", vnet); - s_logger.debug("Upgraded Direct domRs in Advance zone id=" + dcId); + logger.debug("Upgraded Direct domRs in Advance zone id=" + dcId); } } } @@ -1166,7 +1164,7 @@ public class Upgrade218to22 implements DbUpgrade { PreparedStatement pstmt = conn.prepareStatement("UPDATE user_statistics SET device_type='DomainRouter'"); ){ pstmt.executeUpdate(); - s_logger.debug("Upgraded userStatistcis with device_type=DomainRouter"); + logger.debug("Upgraded userStatistcis with device_type=DomainRouter"); // update device_id information try ( @@ -1182,7 +1180,7 @@ public class Upgrade218to22 implements DbUpgrade { selectNetworkType.setLong(1, dataCenterId); try (ResultSet dcSet = selectNetworkType.executeQuery();) { if (!dcSet.next()) { - s_logger.error("Unable to get data_center information as a part of user_statistics update"); + logger.error("Unable to get data_center information as a part of user_statistics update"); throw new CloudRuntimeException("Unable to get data_center information as a part of user_statistics update"); } String dataCenterType = dcSet.getString(1); @@ -1204,7 +1202,7 @@ public class Upgrade218to22 implements DbUpgrade { selectnonRemovedVms.setLong(2, dataCenterId); try (ResultSet nonRemovedVms = selectnonRemovedVms.executeQuery();) { if (nonRemovedVms.next()) { - s_logger.warn("Failed to find domR for account id=" + accountId + " in zone id=" + dataCenterId + + logger.warn("Failed to find domR for account id=" + accountId + " in zone id=" + dataCenterId + "; will try to locate domR based on user_vm info"); //try to get domR information from the user_vm belonging to the account try (PreparedStatement selectNetworkType = @@ -1213,14 +1211,14 @@ public class Upgrade218to22 implements DbUpgrade { selectNetworkType.setLong(2, dataCenterId); try (ResultSet userVmSet = selectNetworkType.executeQuery();) { if (!userVmSet.next()) { - s_logger.warn("Skipping user_statistics upgrade for account id=" + accountId + " in datacenter id=" + dataCenterId); + logger.warn("Skipping user_statistics upgrade for account id=" + accountId + " in datacenter id=" + dataCenterId); continue; } deviceId = userVmSet.getLong(1); } } } else { - s_logger.debug("Account id=" + accountId + " doesn't own any user vms and domRs, so skipping user_statistics update"); + logger.debug("Account id=" + accountId + " doesn't own any user vms and domRs, so skipping user_statistics update"); continue; } } @@ -1237,7 +1235,7 @@ public class Upgrade218to22 implements DbUpgrade { } } } - s_logger.debug("Upgraded userStatistcis with deviceId(s)"); + logger.debug("Upgraded userStatistcis with deviceId(s)"); } catch (Exception e) { throw new CloudRuntimeException("Failed to migrate usage events: ", e); @@ -1263,7 +1261,7 @@ public class Upgrade218to22 implements DbUpgrade { } if (!rules.isEmpty()) { - s_logger.debug("Found " + rules.size() + " port forwarding rules to upgrade"); + logger.debug("Found " + rules.size() + " port forwarding rules to upgrade"); for (Object[] rule : rules) { long id = (Long)rule[0]; String sourcePort = (String)rule[2]; @@ -1275,7 +1273,7 @@ public class Upgrade218to22 implements DbUpgrade { try (ResultSet userIpAddressData = selectUserIpAddressData.executeQuery();) { if (!userIpAddressData.next()) { - s_logger.error("Unable to find public IP address " + publicIp); + logger.error("Unable to find public IP address " + publicIp); throw new CloudRuntimeException("Unable to find public IP address " + publicIp); } int ipAddressId = userIpAddressData.getInt(1); @@ -1285,7 +1283,7 @@ public class Upgrade218to22 implements DbUpgrade { String privateIp = (String)rule[3]; // update port_forwarding_rules table - s_logger.trace("Updating port_forwarding_rules table..."); + logger.trace("Updating port_forwarding_rules table..."); try (PreparedStatement selectInstanceId = conn.prepareStatement("SELECT instance_id FROM nics where network_id=? AND ip4_address=?");) { selectInstanceId.setLong(1, networkId); selectInstanceId.setString(2, privateIp); @@ -1293,14 +1291,14 @@ public class Upgrade218to22 implements DbUpgrade { if (!selectedInstanceId.next()) { // the vm might be expunged already...so just give the warning - s_logger.warn("Unable to find vmId for private ip address " + privateIp + " for account id=" + accountId + "; assume that the vm is expunged"); + logger.warn("Unable to find vmId for private ip address " + privateIp + " for account id=" + accountId + "; assume that the vm is expunged"); // throw new CloudRuntimeException("Unable to find vmId for private ip address " + privateIp + // " for account id=" + accountId); } else { long instanceId = selectedInstanceId.getLong(1); - s_logger.debug("Instance id is " + instanceId); + logger.debug("Instance id is " + instanceId); // update firewall_rules table - s_logger.trace("Updating firewall_rules table as a part of PF rules upgrade..."); + logger.trace("Updating firewall_rules table as a part of PF rules upgrade..."); try ( PreparedStatement insertFirewallRules = conn.prepareStatement("INSERT INTO firewall_rules (id, ip_address_id, start_port, end_port, state, protocol, purpose, account_id, domain_id, network_id, xid, is_static_nat, created) VALUES (?, ?, ?, ?, 'Active', ?, 'PortForwarding', ?, ?, ?, ?, 0, now())"); @@ -1315,7 +1313,7 @@ public class Upgrade218to22 implements DbUpgrade { insertFirewallRules.setLong(8, networkId); insertFirewallRules.setString(9, UUID.randomUUID().toString()); insertFirewallRules.executeUpdate(); - s_logger.trace("firewall_rules table is updated as a part of PF rules upgrade"); + logger.trace("firewall_rules table is updated as a part of PF rules upgrade"); } String privatePort = (String)rule[4]; try (PreparedStatement insertPortForwardingRules = conn.prepareStatement("INSERT INTO port_forwarding_rules VALUES (?, ?, ?, ?, ?)");) { @@ -1326,7 +1324,7 @@ public class Upgrade218to22 implements DbUpgrade { insertPortForwardingRules.setInt(5, Integer.parseInt(privatePort.trim())); insertPortForwardingRules.executeUpdate(); } - s_logger.trace("port_forwarding_rules table is updated"); + logger.trace("port_forwarding_rules table is updated"); } } } @@ -1334,7 +1332,7 @@ public class Upgrade218to22 implements DbUpgrade { } } } - s_logger.debug("Port forwarding rules are updated"); + logger.debug("Port forwarding rules are updated"); } catch (SQLException e) { throw new CloudRuntimeException("Can't update port forwarding rules ", e); } @@ -1358,7 +1356,7 @@ public class Upgrade218to22 implements DbUpgrade { } if (!lbs.isEmpty()) { - s_logger.debug("Found " + lbs.size() + " lb rules to upgrade"); + logger.debug("Found " + lbs.size() + " lb rules to upgrade"); long newLbId = 0; try ( PreparedStatement selectFWRules = conn.prepareStatement("SELECT max(id) FROM firewall_rules order by id"); @@ -1382,7 +1380,7 @@ public class Upgrade218to22 implements DbUpgrade { try (ResultSet ipData = selectIpData.executeQuery();) { if (!ipData.next()) { - s_logger.warn("Unable to find public IP address " + publicIp + "; skipping lb rule id=" + originalLbId + + logger.warn("Unable to find public IP address " + publicIp + "; skipping lb rule id=" + originalLbId + " from update. Cleaning it up from load_balancer_vm_map and load_balancer table"); try (PreparedStatement deleteLbVmMap = conn.prepareStatement("DELETE from load_balancer_vm_map where load_balancer_id=?");) { deleteLbVmMap.setLong(1, originalLbId); @@ -1399,7 +1397,7 @@ public class Upgrade218to22 implements DbUpgrade { long domainId = ipData.getLong(3); long networkId = ipData.getLong(4); // update firewall_rules table - s_logger.trace("Updating firewall_rules table as a part of LB rules upgrade..."); + logger.trace("Updating firewall_rules table as a part of LB rules upgrade..."); try (PreparedStatement insertFirewallRules = conn.prepareStatement("INSERT INTO firewall_rules (id, ip_address_id, start_port, end_port, state, protocol, purpose, account_id, domain_id, network_id, xid, is_static_nat, created) VALUES (?, ?, ?, ?, 'Active', ?, 'LoadBalancing', ?, ?, ?, ?, 0, now())");) { insertFirewallRules.setLong(1, newLbId); @@ -1413,13 +1411,13 @@ public class Upgrade218to22 implements DbUpgrade { insertFirewallRules.setString(9, UUID.randomUUID().toString()); insertFirewallRules.executeUpdate(); } - s_logger.trace("firewall_rules table is updated as a part of LB rules upgrade"); + logger.trace("firewall_rules table is updated as a part of LB rules upgrade"); } } // update load_balancing_rules - s_logger.trace("Updating load_balancing_rules table as a part of LB rules upgrade..."); + logger.trace("Updating load_balancing_rules table as a part of LB rules upgrade..."); try (PreparedStatement insertLoadBalancer = conn.prepareStatement("INSERT INTO load_balancing_rules VALUES (?, ?, NULL, ?, ?, ?)");) { insertLoadBalancer.setLong(1, newLbId); insertLoadBalancer.setString(2, name); @@ -1428,10 +1426,10 @@ public class Upgrade218to22 implements DbUpgrade { insertLoadBalancer.setString(5, algorithm); insertLoadBalancer.executeUpdate(); } - s_logger.trace("load_balancing_rules table is updated as a part of LB rules upgrade"); + logger.trace("load_balancing_rules table is updated as a part of LB rules upgrade"); // update load_balancer_vm_map table - s_logger.trace("Updating load_balancer_vm_map table as a part of LB rules upgrade..."); + logger.trace("Updating load_balancer_vm_map table as a part of LB rules upgrade..."); try ( PreparedStatement selectInstance = conn.prepareStatement("SELECT instance_id FROM load_balancer_vm_map WHERE load_balancer_id=?"); ) { @@ -1451,10 +1449,10 @@ public class Upgrade218to22 implements DbUpgrade { updateLoadBalancer.setLong(2, originalLbId); updateLoadBalancer.executeUpdate(); } - s_logger.trace("load_balancer_vm_map table is updated as a part of LB rules upgrade"); + logger.trace("load_balancer_vm_map table is updated as a part of LB rules upgrade"); } } - s_logger.debug("LB rules are upgraded"); + logger.debug("LB rules are upgraded"); } catch (SQLException e) { throw new CloudRuntimeException("Can't update LB rules ", e); } @@ -1724,7 +1722,7 @@ public class Upgrade218to22 implements DbUpgrade { ResultSet rs1 = pstmt1.executeQuery(); ) { if (!rs1.next()) { - s_logger.debug("cloud_usage db doesn't exist. Skipping events migration"); + logger.debug("cloud_usage db doesn't exist. Skipping events migration"); return; } @@ -1734,7 +1732,7 @@ public class Upgrade218to22 implements DbUpgrade { String sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.id > ? and vmevt.state = 'Completed' "; if (lastProcessedEvent == null) { - s_logger.trace("no events are processed earlier, copying all events"); + logger.trace("no events are processed earlier, copying all events"); sql = "SELECT type, description, user_id, account_id, created, level, parameters FROM cloud.event vmevt WHERE vmevt.state = 'Completed' "; } @@ -1744,7 +1742,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.setLong(i++, lastProcessedEvent); } try (ResultSet rs = pstmt.executeQuery();) { - s_logger.debug("Begin Migrating events"); + logger.debug("Begin Migrating events"); while (rs.next()) { EventVO event = new EventVO(); event.setType(rs.getString(1)); @@ -1758,7 +1756,7 @@ public class Upgrade218to22 implements DbUpgrade { } } } - s_logger.debug("Migrating events completed"); + logger.debug("Migrating events completed"); } catch (Exception e) { throw new CloudRuntimeException("Failed to migrate usage events: ", e); } @@ -2142,7 +2140,7 @@ public class Upgrade218to22 implements DbUpgrade { cleanupLbVmMaps(conn); } catch (SQLException e) { - s_logger.error("Can't perform data migration ", e); + logger.error("Can't perform data migration ", e); throw new CloudRuntimeException("Can't perform data migration ", e); } @@ -2180,7 +2178,7 @@ public class Upgrade218to22 implements DbUpgrade { ResultSet rs = selectStoragePoolRef.executeQuery(); ) { if (!rs.next()) { - s_logger.debug("No records in template_spool_ref, skipping this upgrade part"); + logger.debug("No records in template_spool_ref, skipping this upgrade part"); return; } while (rs.next()) { @@ -2192,7 +2190,7 @@ public class Upgrade218to22 implements DbUpgrade { try (ResultSet selectedStoragePool = selectStoragePool.executeQuery();) { if (!selectedStoragePool.next()) { - s_logger.debug("Orphaned template_spool_ref record is found (storage pool doesn't exist any more0) id=" + id + "; so removing the record"); + logger.debug("Orphaned template_spool_ref record is found (storage pool doesn't exist any more0) id=" + id + "; so removing the record"); try (PreparedStatement delete = conn.prepareStatement("DELETE FROM template_spool_ref where id=?");) { delete.setLong(1, id); delete.executeUpdate(); @@ -2201,9 +2199,9 @@ public class Upgrade218to22 implements DbUpgrade { } } } - s_logger.debug("Finished deleting orphaned template_spool_ref(s)"); + logger.debug("Finished deleting orphaned template_spool_ref(s)"); } catch (Exception e) { - s_logger.error("Failed to delete orphaned template_spool_ref(s): ", e); + logger.error("Failed to delete orphaned template_spool_ref(s): ", e); throw new CloudRuntimeException("Failed to delete orphaned template_spool_ref(s): ", e); } } @@ -2215,7 +2213,7 @@ public class Upgrade218to22 implements DbUpgrade { ){ while (selectedVolumes.next()) { Long id = selectedVolumes.getLong(1); - s_logger.debug("Volume id is " + id); + logger.debug("Volume id is " + id); Long instanceId = selectedVolumes.getLong(2); Long accountId = selectedVolumes.getLong(3); @@ -2245,15 +2243,15 @@ public class Upgrade218to22 implements DbUpgrade { try(PreparedStatement pstmt = conn.prepareStatement("UPDATE volumes SET state='Destroy' WHERE id=?");) { pstmt.setLong(1, id); pstmt.executeUpdate(); - s_logger.debug("Volume with id=" + id + " is marked with Destroy state as a part of volume cleanup (it's Destroyed had 127 value)"); + logger.debug("Volume with id=" + id + " is marked with Destroy state as a part of volume cleanup (it's Destroyed had 127 value)"); } } } } } - s_logger.debug("Finished cleaning up volumes with incorrect Destroyed field (127)"); + logger.debug("Finished cleaning up volumes with incorrect Destroyed field (127)"); } catch (Exception e) { - s_logger.error("Failed to cleanup volumes with incorrect Destroyed field (127):", e); + logger.error("Failed to cleanup volumes with incorrect Destroyed field (127):", e); throw new CloudRuntimeException("Failed to cleanup volumes with incorrect Destroyed field (127):", e); } } @@ -2267,7 +2265,7 @@ public class Upgrade218to22 implements DbUpgrade { if (result__index.next()) { try (PreparedStatement alterTable = conn.prepareStatement("ALTER TABLE `cloud`.`security_group` DROP INDEX `fk_network_group__account_id`");) { alterTable.executeUpdate(); - s_logger.debug("Unique key 'fk_network_group__account_id' is removed successfully"); + logger.debug("Unique key 'fk_network_group__account_id' is removed successfully"); } } @@ -2278,7 +2276,7 @@ public class Upgrade218to22 implements DbUpgrade { if (result___index.next()) { try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`security_group` DROP INDEX `fk_network_group___account_id`");) { pstmt.executeUpdate(); - s_logger.debug("Unique key 'fk_network_group___account_id' is removed successfully"); + logger.debug("Unique key 'fk_network_group___account_id' is removed successfully"); } } } @@ -2310,7 +2308,7 @@ public class Upgrade218to22 implements DbUpgrade { ResultSet rs2 = pstmt2.executeQuery(); ) { if (!rs1.next() && rs2.next()) { - s_logger.debug("Removing load balancer vm mappings for lb id=" + lbId + " as a part of cleanup"); + logger.debug("Removing load balancer vm mappings for lb id=" + lbId + " as a part of cleanup"); try (PreparedStatement delete = conn.prepareStatement("DELETE FROM load_balancer_vm_map where load_balancer_id=?");) { delete.setLong(1, lbId); delete.executeUpdate(); @@ -2329,7 +2327,7 @@ public class Upgrade218to22 implements DbUpgrade { * Create usage events for existing port forwarding rules */ private void createPortForwardingEvents(Connection conn) { - s_logger.debug("Creating Port Forwarding usage events"); + logger.debug("Creating Port Forwarding usage events"); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT fw.account_id, ip.data_center_id, fw.id FROM firewall_rules fw, user_ip_address ip where purpose = 'PortForwarding' and " @@ -2354,7 +2352,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt1.executeUpdate(); } } - s_logger.debug("Completed creating Port Forwarding usage events"); + logger.debug("Completed creating Port Forwarding usage events"); } catch (SQLException e) { throw new CloudRuntimeException("Failed to add port forwarding usage events due to:", e); } @@ -2364,7 +2362,7 @@ public class Upgrade218to22 implements DbUpgrade { * Create usage events for existing load balancer rules */ private void createLoadBalancerEvents(Connection conn) { - s_logger.debug("Creating load balancer usage events"); + logger.debug("Creating load balancer usage events"); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT fw.account_id, ip.data_center_id, fw.id FROM firewall_rules fw, user_ip_address ip where purpose = 'LoadBalancing' and " @@ -2389,7 +2387,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt1.executeUpdate(); } } - s_logger.debug("Completed creating load balancer usage events"); + logger.debug("Completed creating load balancer usage events"); } catch (SQLException e) { throw new CloudRuntimeException("Failed to add Load Balancer usage events due to:", e); } @@ -2399,7 +2397,7 @@ public class Upgrade218to22 implements DbUpgrade { * Create usage events for network offerings */ private void createNetworkOfferingEvents(Connection conn) { - s_logger.debug("Creating network offering usage events"); + logger.debug("Creating network offering usage events"); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT vm.account_id, vm.data_center_id, ni.instance_id, vm.name, nw.network_offering_id, nw.is_default FROM nics ni, " @@ -2429,7 +2427,7 @@ public class Upgrade218to22 implements DbUpgrade { pstmt1.executeUpdate(); } } - s_logger.debug("Completed creating network offering usage events"); + logger.debug("Completed creating network offering usage events"); } catch (SQLException e) { throw new CloudRuntimeException("Failed to add network offering usage events due to:", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java index 5f66728e6d9..65a71993e91 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to224DomainVlans.java @@ -23,12 +23,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade218to224DomainVlans implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade218to224DomainVlans.class); +public class Upgrade218to224DomainVlans extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { @@ -42,7 +40,7 @@ public class Upgrade218to224DomainVlans implements DbUpgrade { try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM networks WHERE shared=1 AND traffic_type='Guest' AND guest_type='Direct'"); ResultSet rs = pstmt.executeQuery(); - s_logger.debug("query is " + pstmt); + logger.debug("query is " + pstmt); while (rs.next()) { Long networkId = rs.getLong(1); Long vlanId = null; @@ -50,7 +48,7 @@ public class Upgrade218to224DomainVlans implements DbUpgrade { pstmt = conn.prepareStatement("SELECT id FROM vlan WHERE network_id=? LIMIT 0,1"); pstmt.setLong(1, networkId); - s_logger.debug("query is " + pstmt); + logger.debug("query is " + pstmt); rs = pstmt.executeQuery(); while (rs.next()) { @@ -60,7 +58,7 @@ public class Upgrade218to224DomainVlans implements DbUpgrade { if (vlanId != null) { pstmt = conn.prepareStatement("SELECT domain_id FROM account_vlan_map WHERE domain_id IS NOT NULL AND vlan_db_id=? LIMIT 0,1"); pstmt.setLong(1, vlanId); - s_logger.debug("query is " + pstmt); + logger.debug("query is " + pstmt); rs = pstmt.executeQuery(); while (rs.next()) { @@ -118,7 +116,7 @@ public class Upgrade218to224DomainVlans implements DbUpgrade { try { pstmt.executeQuery(); } catch (SQLException e) { - s_logger.debug("Assuming that domain_id field doesn't exist in account_vlan_map table, no need to upgrade"); + logger.debug("Assuming that domain_id field doesn't exist in account_vlan_map table, no need to upgrade"); return; } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22Premium.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22Premium.java index d21d1ce4e66..d5106925e99 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22Premium.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade218to22Premium.java @@ -52,7 +52,7 @@ public class Upgrade218to22Premium extends Upgrade218to22 { ) { pstmt.executeUpdate(); - s_logger.debug("Upgraded cloud_usage user_statistics with deviceId"); + logger.debug("Upgraded cloud_usage user_statistics with deviceId"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade user stats: ", e); } @@ -64,7 +64,7 @@ public class Upgrade218to22Premium extends Upgrade218to22 { ) { pstmt1.executeUpdate(); - s_logger.debug("Upgraded cloud_usage usage_network with hostId"); + logger.debug("Upgraded cloud_usage usage_network with hostId"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade network usage stats: ", e); } @@ -78,7 +78,7 @@ public class Upgrade218to22Premium extends Upgrade218to22 { ) { pstmt.executeUpdate(); - s_logger.debug("Upgraded cloud_usage usage_ip_address with Id"); + logger.debug("Upgraded cloud_usage usage_ip_address with Id"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade usage_ip_address: ", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2210to2211.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2210to2211.java index db145227080..ba456a62953 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2210to2211.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2210to2211.java @@ -21,7 +21,7 @@ import java.sql.Connection; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2210to2211 implements DbUpgrade { +public class Upgrade2210to2211 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212.java index f8175386df5..1c4868d61b0 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212.java @@ -24,12 +24,10 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2211to2212 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade2211to2212.class); +public class Upgrade2211to2212 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -68,7 +66,7 @@ public class Upgrade2211to2212 implements DbUpgrade { } private void createResourceCount(Connection conn) { - s_logger.debug("Creating missing resource_count records as a part of 2.2.11-2.2.12 upgrade"); + logger.debug("Creating missing resource_count records as a part of 2.2.11-2.2.12 upgrade"); try { //Get all non removed accounts @@ -99,7 +97,7 @@ public class Upgrade2211to2212 implements DbUpgrade { pstmt.setLong(2, accountId); rs = pstmt.executeQuery(); if (!rs.next()) { - s_logger.debug("Inserting resource_count record of type " + resourceType + " for account id=" + accountId); + logger.debug("Inserting resource_count record of type " + resourceType + " for account id=" + accountId); pstmt = conn.prepareStatement("INSERT INTO resource_count (account_id, domain_id, type, count) VALUES (?, null, ?, 0)"); pstmt.setLong(1, accountId); pstmt.setString(2, resourceType); @@ -117,7 +115,7 @@ public class Upgrade2211to2212 implements DbUpgrade { pstmt.setLong(2, domainId); rs = pstmt.executeQuery(); if (!rs.next()) { - s_logger.debug("Inserting resource_count record of type " + resourceType + " for domain id=" + domainId); + logger.debug("Inserting resource_count record of type " + resourceType + " for domain id=" + domainId); pstmt = conn.prepareStatement("INSERT INTO resource_count (account_id, domain_id, type, count) VALUES (null, ?, ?, 0)"); pstmt.setLong(1, domainId); pstmt.setString(2, resourceType); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212Premium.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212Premium.java index 37448381136..d2f0f00ee0a 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212Premium.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2211to2212Premium.java @@ -18,12 +18,10 @@ package com.cloud.upgrade.dao; import java.io.InputStream; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade2211to2212Premium extends Upgrade2211to2212 { - final static Logger s_logger = Logger.getLogger(Upgrade2211to2212Premium.class); @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2212to2213.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2212to2213.java index 7debe2ec378..809e23c1b5a 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2212to2213.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2212to2213.java @@ -24,12 +24,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2212to2213 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade2212to2213.class); +public class Upgrade2212to2213 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -74,7 +72,7 @@ public class Upgrade2212to2213 implements DbUpgrade { foreignKeys.put("networks", keys); // drop all foreign keys - s_logger.debug("Dropping old key fk_networks__data_center_id..."); + logger.debug("Dropping old key fk_networks__data_center_id..."); for (String tableName : foreignKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, foreignKeys.get(tableName), true); } @@ -95,7 +93,7 @@ public class Upgrade2212to2213 implements DbUpgrade { try { PreparedStatement pstmt = conn.prepareStatement("drop index network_offering_id on cloud_usage.usage_network_offering"); pstmt.executeUpdate(); - s_logger.debug("Dropped usage_network_offering unique key"); + logger.debug("Dropped usage_network_offering unique key"); } catch (Exception e) { // Ignore error if the usage_network_offering table or the unique key doesn't exist } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2213to2214.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2213to2214.java index 9dc3f5be2d8..6299abf1030 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2213to2214.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2213to2214.java @@ -23,12 +23,10 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2213to2214 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade2213to2214.class); +public class Upgrade2213to2214 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2214to30.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2214to30.java index d806490d87d..524b6a34893 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2214to30.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade2214to30.java @@ -29,7 +29,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.offering.NetworkOffering; import com.cloud.utils.crypt.DBEncryptionUtil; @@ -37,8 +36,7 @@ import com.cloud.utils.crypt.EncryptionSecretKeyChecker; import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade2214to30.class); +public class Upgrade2214to30 extends Upgrade30xBase { @Override public String[] getUpgradableVersionRange() { @@ -183,7 +181,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt2.setLong(1, zoneId); ResultSet rsTags = pstmt2.executeQuery(); if (rsTags.next()) { - s_logger.debug("Network tags are not empty, might have to create more than one physical network..."); + logger.debug("Network tags are not empty, might have to create more than one physical network..."); //make sure setup does not use guest vnets if (vnet != null) { @@ -214,7 +212,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { + "6. Reconfigure the vnet ranges for each physical network as desired by using updatePhysicalNetwork API \n" + "7. Start all your VMs"; - s_logger.error(message); + logger.error(message); throw new CloudRuntimeException( "Cannot upgrade this setup since it uses guest vnet and will have multiple physical networks. Please check the logs for details on how to proceed"); @@ -263,7 +261,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { if (crtPbNtwk) { addTrafficType(conn, physicalNetworkId, "Public", xenPublicLabel, kvmPublicLabel, vmwarePublicLabel); } else { - s_logger.debug("Skip adding public traffic type to zone id=" + zoneId); + logger.debug("Skip adding public traffic type to zone id=" + zoneId); } addTrafficType(conn, physicalNetworkId, "Management", xenPrivateLabel, kvmPrivateLabel, vmwarePrivateLabel); addTrafficType(conn, physicalNetworkId, "Storage", xenStorageLabel, null, null); @@ -276,9 +274,9 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { PreparedStatement pstmt3 = conn.prepareStatement("SELECT network_id FROM `cloud`.`network_tags` where tag= ?"); pstmt3.setString(1,guestNetworkTag); ResultSet rsNet = pstmt3.executeQuery(); - s_logger.debug("Adding PhysicalNetwork to VLAN"); - s_logger.debug("Adding PhysicalNetwork to user_ip_address"); - s_logger.debug("Adding PhysicalNetwork to networks"); + logger.debug("Adding PhysicalNetwork to VLAN"); + logger.debug("Adding PhysicalNetwork to user_ip_address"); + logger.debug("Adding PhysicalNetwork to networks"); while (rsNet.next()) { Long networkId = rsNet.getLong(1); addPhysicalNtwk_To_Ntwk_IP_Vlan(conn, physicalNetworkId, networkId); @@ -288,7 +286,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { // add the reference to this physical network for the default public network entries in vlan / user_ip_address tables // add first physicalNetworkId to op_dc_vnet_alloc for this zone - just a placeholder since direct networking don't need this if (isFirstPhysicalNtwk) { - s_logger.debug("Adding PhysicalNetwork to default Public network entries in vlan and user_ip_address"); + logger.debug("Adding PhysicalNetwork to default Public network entries in vlan and user_ip_address"); pstmt3 = conn.prepareStatement("SELECT id FROM `cloud`.`networks` where traffic_type = 'Public' and data_center_id = " + zoneId); ResultSet rsPubNet = pstmt3.executeQuery(); if (rsPubNet.next()) { @@ -297,7 +295,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { } pstmt3.close(); - s_logger.debug("Adding PhysicalNetwork to op_dc_vnet_alloc"); + logger.debug("Adding PhysicalNetwork to op_dc_vnet_alloc"); String updateVnet = "UPDATE `cloud`.`op_dc_vnet_alloc` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId; pstmtUpdate = conn.prepareStatement(updateVnet); pstmtUpdate.executeUpdate(); @@ -314,7 +312,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { if (crtPbNtwk) { addTrafficType(conn, physicalNetworkId, "Public", xenPublicLabel, kvmPublicLabel, vmwarePublicLabel); } else { - s_logger.debug("Skip adding public traffic type to zone id=" + zoneId); + logger.debug("Skip adding public traffic type to zone id=" + zoneId); } addTrafficType(conn, physicalNetworkId, "Management", xenPrivateLabel, kvmPrivateLabel, vmwarePrivateLabel); addTrafficType(conn, physicalNetworkId, "Storage", xenStorageLabel, null, null); @@ -323,28 +321,28 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { addDefaultSGProvider(conn, physicalNetworkId, zoneId, networkType, false); // add physicalNetworkId to op_dc_vnet_alloc for this zone - s_logger.debug("Adding PhysicalNetwork to op_dc_vnet_alloc"); + logger.debug("Adding PhysicalNetwork to op_dc_vnet_alloc"); String updateVnet = "UPDATE `cloud`.`op_dc_vnet_alloc` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId; pstmtUpdate = conn.prepareStatement(updateVnet); pstmtUpdate.executeUpdate(); pstmtUpdate.close(); // add physicalNetworkId to vlan for this zone - s_logger.debug("Adding PhysicalNetwork to VLAN"); + logger.debug("Adding PhysicalNetwork to VLAN"); String updateVLAN = "UPDATE `cloud`.`vlan` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId; pstmtUpdate = conn.prepareStatement(updateVLAN); pstmtUpdate.executeUpdate(); pstmtUpdate.close(); // add physicalNetworkId to user_ip_address for this zone - s_logger.debug("Adding PhysicalNetwork to user_ip_address"); + logger.debug("Adding PhysicalNetwork to user_ip_address"); String updateUsrIp = "UPDATE `cloud`.`user_ip_address` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId; pstmtUpdate = conn.prepareStatement(updateUsrIp); pstmtUpdate.executeUpdate(); pstmtUpdate.close(); // add physicalNetworkId to guest networks for this zone - s_logger.debug("Adding PhysicalNetwork to networks"); + logger.debug("Adding PhysicalNetwork to networks"); String updateNet = "UPDATE `cloud`.`networks` SET physical_network_id = " + physicalNetworkId + " WHERE data_center_id = " + zoneId + " AND traffic_type = 'Guest'"; pstmtUpdate = conn.prepareStatement(updateNet); @@ -370,17 +368,17 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { } private void encryptData(Connection conn) { - s_logger.debug("Encrypting the data..."); + logger.debug("Encrypting the data..."); encryptConfigValues(conn); encryptHostDetails(conn); encryptVNCPassword(conn); encryptUserCredentials(conn); encryptVPNPassword(conn); - s_logger.debug("Done encrypting the data"); + logger.debug("Done encrypting the data"); } private void encryptConfigValues(Connection conn) { - s_logger.debug("Encrypting Config values"); + logger.debug("Encrypting Config values"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -412,14 +410,14 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt.close(); } } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } - s_logger.debug("Done encrypting Config values"); + logger.debug("Done encrypting Config values"); } private void encryptHostDetails(Connection conn) { - s_logger.debug("Encrypting host details"); + logger.debug("Encrypting host details"); List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; ResultSet rs = null; @@ -447,11 +445,11 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { } finally { TransactionLegacy.closePstmts(pstmt2Close); } - s_logger.debug("Done encrypting host details"); + logger.debug("Done encrypting host details"); } private void encryptVNCPassword(Connection conn) { - s_logger.debug("Encrypting vm_instance vnc_password"); + logger.debug("Encrypting vm_instance vnc_password"); List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; ResultSet rs = null; @@ -493,11 +491,11 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { } finally { TransactionLegacy.closePstmts(pstmt2Close); } - s_logger.debug("Done encrypting vm_instance vnc_password"); + logger.debug("Done encrypting vm_instance vnc_password"); } private void encryptUserCredentials(Connection conn) { - s_logger.debug("Encrypting user keys"); + logger.debug("Encrypting user keys"); List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; ResultSet rs = null; @@ -526,11 +524,11 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { } finally { TransactionLegacy.closePstmts(pstmt2Close); } - s_logger.debug("Done encrypting user keys"); + logger.debug("Done encrypting user keys"); } private void encryptVPNPassword(Connection conn) { - s_logger.debug("Encrypting vpn_users password"); + logger.debug("Encrypting vpn_users password"); List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; ResultSet rs = null; @@ -559,7 +557,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { } finally { TransactionLegacy.closePstmts(pstmt2Close); } - s_logger.debug("Done encrypting vpn_users password"); + logger.debug("Done encrypting vpn_users password"); } private void dropKeysIfExist(Connection conn) { @@ -570,7 +568,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { uniqueKeys.put("secondary_storage_vm", keys); // drop keys - s_logger.debug("Dropping public_ip_address keys from `cloud`.`secondary_storage_vm` and console_proxy tables..."); + logger.debug("Dropping public_ip_address keys from `cloud`.`secondary_storage_vm` and console_proxy tables..."); for (String tableName : uniqueKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, uniqueKeys.get(tableName), false); } @@ -697,7 +695,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt2Close.add(pstmt); pstmt.setBoolean(1, subdomainAccess); pstmt.executeUpdate(); - s_logger.debug("Successfully updated subdomain_access field in network_domain table with value " + subdomainAccess); + logger.debug("Successfully updated subdomain_access field in network_domain table with value " + subdomainAccess); } // convert zone level 2.2.x networks to ROOT domain 3.0 access networks @@ -710,7 +708,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt2Close.add(pstmt); pstmt.setLong(1, networkId); pstmt.executeUpdate(); - s_logger.debug("Successfully converted zone specific network id=" + networkId + " to the ROOT domain level network with subdomain access set to true"); + logger.debug("Successfully converted zone specific network id=" + networkId + " to the ROOT domain level network with subdomain access set to true"); } } catch (SQLException e) { @@ -745,7 +743,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt.setString(3, provider); pstmt.executeUpdate(); } - s_logger.debug("Created service/provider map for network id=" + networkId); + logger.debug("Created service/provider map for network id=" + networkId); } } catch (SQLException e) { throw new CloudRuntimeException("Unable to create service/provider map for networks", e); @@ -757,7 +755,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { protected void updateRouters(Connection conn) { PreparedStatement pstmt = null; try { - s_logger.debug("Updating domain_router table"); + logger.debug("Updating domain_router table"); pstmt = conn.prepareStatement("UPDATE domain_router, virtual_router_providers vrp LEFT JOIN (physical_network_service_providers pnsp INNER JOIN physical_network pntwk INNER JOIN vm_instance vm INNER JOIN domain_router vr) ON (vrp.nsp_id = pnsp.id AND pnsp.physical_network_id = pntwk.id AND pntwk.data_center_id = vm.data_center_id AND vm.id=vr.id) SET vr.element_id=vrp.id;"); pstmt.executeUpdate(); @@ -793,7 +791,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { ntwkOffCount = rs1.getLong(1); } - s_logger.debug("Have " + ntwkOffCount + " networkOfferings"); + logger.debug("Have " + ntwkOffCount + " networkOfferings"); pstmt = conn.prepareStatement("CREATE TEMPORARY TABLE `cloud`.`network_offerings2` ENGINE=MEMORY SELECT * FROM `cloud`.`network_offerings` WHERE id=1"); pstmt2Close.add(pstmt); pstmt.executeUpdate(); @@ -803,7 +801,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { while (rs.next()) { long networkId = rs.getLong(1); long networkOfferingId = rs.getLong(2); - s_logger.debug("Updating network offering for the network id=" + networkId + " as it has redundant routers"); + logger.debug("Updating network offering for the network id=" + networkId + " as it has redundant routers"); Long newNetworkOfferingId = null; if (!newNetworkOfferingMap.containsKey(networkOfferingId)) { @@ -852,7 +850,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt.executeUpdate(); } - s_logger.debug("Successfully updated network offering id=" + networkId + " with new network offering id " + newNetworkOfferingId); + logger.debug("Successfully updated network offering id=" + networkId + " with new network offering id " + newNetworkOfferingId); } } catch (SQLException e) { @@ -863,7 +861,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt.executeUpdate(); pstmt.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } TransactionLegacy.closePstmts(pstmt2Close); } @@ -873,7 +871,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { List pstmt2Close = new ArrayList(); PreparedStatement pstmt = null; try { - s_logger.debug("Updating op_host_capacity table, column capacity_state"); + logger.debug("Updating op_host_capacity table, column capacity_state"); pstmt = conn.prepareStatement("UPDATE op_host_capacity, host SET op_host_capacity.capacity_state='Disabled' where host.id=op_host_capacity.host_id and op_host_capacity.capacity_type in (0,1) and host.resource_state='Disabled';"); pstmt2Close.add(pstmt); @@ -912,7 +910,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt2Close.add(pstmt); rs = pstmt.executeQuery(); } catch (Exception ex) { - s_logger.debug("switch_to_isolated field is not present in networks table"); + logger.debug("switch_to_isolated field is not present in networks table"); if (pstmt != null) { pstmt.close(); } @@ -932,7 +930,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { ntwkOffCount = rs1.getLong(1); } - s_logger.debug("Have " + ntwkOffCount + " networkOfferings"); + logger.debug("Have " + ntwkOffCount + " networkOfferings"); pstmt = conn.prepareStatement("CREATE TEMPORARY TABLE `cloud`.`network_offerings2` ENGINE=MEMORY SELECT * FROM `cloud`.`network_offerings` WHERE id=1"); pstmt2Close.add(pstmt); pstmt.executeUpdate(); @@ -942,7 +940,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { while (rs.next()) { long networkId = rs.getLong(1); long networkOfferingId = rs.getLong(2); - s_logger.debug("Updating network offering for the network id=" + networkId + " as it has switch_to_isolated=1"); + logger.debug("Updating network offering for the network id=" + networkId + " as it has switch_to_isolated=1"); Long newNetworkOfferingId = null; if (!newNetworkOfferingMap.containsKey(networkOfferingId)) { @@ -983,7 +981,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt.executeUpdate(); } - s_logger.debug("Successfully updated network offering id=" + networkId + " with new network offering id " + newNetworkOfferingId); + logger.debug("Successfully updated network offering id=" + networkId + " with new network offering id " + newNetworkOfferingId); } try { @@ -992,7 +990,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt.executeUpdate(); } catch (SQLException ex) { // do nothing here - s_logger.debug("Caught SQLException when trying to drop switch_to_isolated column ", ex); + logger.debug("Caught SQLException when trying to drop switch_to_isolated column ", ex); } } catch (SQLException e) { @@ -1003,7 +1001,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt.executeUpdate(); pstmt.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } TransactionLegacy.closePstmts(pstmt2Close); } @@ -1057,7 +1055,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt.close(); } } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } } @@ -1107,7 +1105,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { while (rs.next()) { long networkId = rs.getLong(1); long networkOfferingId = rs.getLong(2); - s_logger.debug("Updating network offering for the network id=" + networkId + " as it has switch_to_isolated=1"); + logger.debug("Updating network offering for the network id=" + networkId + " as it has switch_to_isolated=1"); Long newNetworkOfferingId = null; if (!newNetworkOfferingMap.containsKey(networkOfferingId)) { uniqueName = "Isolated with external providers"; @@ -1150,7 +1148,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { pstmt.executeUpdate(); } - s_logger.debug("Successfully updated network id=" + networkId + " with new network offering id " + newNetworkOfferingId); + logger.debug("Successfully updated network id=" + networkId + " with new network offering id " + newNetworkOfferingId); } } catch (SQLException e) { @@ -1159,7 +1157,7 @@ public class Upgrade2214to30 extends Upgrade30xBase implements DbUpgrade { try (PreparedStatement dropStatement = conn.prepareStatement("DROP TABLE `cloud`.`network_offerings2`");){ dropStatement.executeUpdate(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } TransactionLegacy.closePstmts(pstmt2Close); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade221to222.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade221to222.java index 41198adb14b..307b72c61ea 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade221to222.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade221to222.java @@ -21,7 +21,7 @@ import java.sql.Connection; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade221to222 implements DbUpgrade { +public class Upgrade221to222 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224.java index 51a929d0377..b891b02ea57 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224.java @@ -25,13 +25,11 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.capacity.Capacity; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade222to224 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade222to224.class); +public class Upgrade222to224 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -64,7 +62,7 @@ public class Upgrade222to224 implements DbUpgrade { try { pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.debug("Ignore if the key is not there."); + logger.debug("Ignore if the key is not there."); } pstmt.close(); @@ -130,11 +128,11 @@ public class Upgrade222to224 implements DbUpgrade { } if (zonesWithDuplicateNetworks.size() > 0) { - s_logger.warn(errorMsg + zonesWithDuplicateNetworks); + logger.warn(errorMsg + zonesWithDuplicateNetworks); } } catch (SQLException e) { - s_logger.warn(e); + logger.warn(e); throw new CloudRuntimeException("Unable to check for duplicate public networks as part of 222 to 224 upgrade."); } } @@ -208,21 +206,21 @@ public class Upgrade222to224 implements DbUpgrade { try { pstmtUpdate.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } if (rs != null) { try { rs.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } @@ -275,7 +273,7 @@ public class Upgrade222to224 implements DbUpgrade { ResultSet rs1 = pstmt.executeQuery(); if (rs1.next()) { - s_logger.debug("Not updating user_statistics table for domR id=" + instanceId + " as domR is already expunged"); + logger.debug("Not updating user_statistics table for domR id=" + instanceId + " as domR is already expunged"); continue; } @@ -301,7 +299,7 @@ public class Upgrade222to224 implements DbUpgrade { rs.close(); pstmt.close(); - s_logger.debug("Upgraded user_statistics with networkId for DomainRouter device type"); + logger.debug("Upgraded user_statistics with networkId for DomainRouter device type"); // update network_id information for ExternalFirewall and ExternalLoadBalancer device types PreparedStatement pstmt1 = @@ -310,9 +308,9 @@ public class Upgrade222to224 implements DbUpgrade { pstmt1.executeUpdate(); pstmt1.close(); - s_logger.debug("Upgraded user_statistics with networkId for ExternalFirewall and ExternalLoadBalancer device types"); + logger.debug("Upgraded user_statistics with networkId for ExternalFirewall and ExternalLoadBalancer device types"); - s_logger.debug("Successfully update user_statistics table with network_ids as a part of 222 to 224 upgrade"); + logger.debug("Successfully update user_statistics table with network_ids as a part of 222 to 224 upgrade"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to update user_statistics table with network_ids as a part of 222 to 224 upgrade", e); @@ -327,7 +325,7 @@ public class Upgrade222to224 implements DbUpgrade { if (rs.next()) { pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`domain` DROP INDEX `path`"); pstmt.executeUpdate(); - s_logger.debug("Unique key 'path' is removed successfully"); + logger.debug("Unique key 'path' is removed successfully"); } rs.close(); @@ -346,7 +344,7 @@ public class Upgrade222to224 implements DbUpgrade { Long zoneId = rs.getLong(1); Long networkId = null; Long vmCount = 0L; - s_logger.debug("Updating basic zone id=" + zoneId + " with correct nic count"); + logger.debug("Updating basic zone id=" + zoneId + " with correct nic count"); pstmt = conn.prepareStatement("SELECT id from networks where data_center_id=? AND guest_type='Direct'"); pstmt.setLong(1, zoneId); @@ -372,7 +370,7 @@ public class Upgrade222to224 implements DbUpgrade { } - s_logger.debug("Basic zones are updated with correct nic counts successfully"); + logger.debug("Basic zones are updated with correct nic counts successfully"); rs.close(); pstmt.close(); } catch (SQLException e) { @@ -386,7 +384,7 @@ public class Upgrade222to224 implements DbUpgrade { PreparedStatement pstmtUpdate = null; try { // Load all Routing hosts - s_logger.debug("Updating total CPU capacity entries in op_host_capacity"); + logger.debug("Updating total CPU capacity entries in op_host_capacity"); pstmt = conn.prepareStatement("SELECT id, cpus, speed FROM host WHERE type = 'Routing'"); rs = pstmt.executeQuery(); while (rs.next()) { @@ -410,21 +408,21 @@ public class Upgrade222to224 implements DbUpgrade { try { pstmtUpdate.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } if (rs != null) { try { rs.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } @@ -439,7 +437,7 @@ public class Upgrade222to224 implements DbUpgrade { if (!rs.next()) { pstmt = conn.prepareStatement("INSERT INTO `cloud`.`guest_os` (id, category_id, display_name) VALUES (138, 7, 'None')"); pstmt.executeUpdate(); - s_logger.debug("Inserted NONE category to guest_os table"); + logger.debug("Inserted NONE category to guest_os table"); } rs.close(); @@ -488,7 +486,7 @@ public class Upgrade222to224 implements DbUpgrade { try { pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.debug("Ignore if the key is not there."); + logger.debug("Ignore if the key is not there."); } pstmt.close(); } @@ -499,7 +497,7 @@ public class Upgrade222to224 implements DbUpgrade { try { pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.debug("Ignore if the index is not there."); + logger.debug("Ignore if the index is not there."); } pstmt.close(); } @@ -613,7 +611,7 @@ public class Upgrade222to224 implements DbUpgrade { pstmt.close(); - s_logger.debug("Resource limit is cleaned up successfully as a part of db upgrade"); + logger.debug("Resource limit is cleaned up successfully as a part of db upgrade"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224Premium.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224Premium.java index ac7bd120c3d..cc5d3399fa6 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224Premium.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade222to224Premium.java @@ -20,12 +20,10 @@ import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade222to224Premium extends Upgrade222to224 { - final static Logger s_logger = Logger.getLogger(Upgrade222to224Premium.class); @Override public InputStream[] getPrepareScripts() { @@ -55,7 +53,7 @@ public class Upgrade222to224Premium extends Upgrade222to224 { ) { pstmt.executeUpdate(); - s_logger.debug("Upgraded cloud_usage user_statistics with networkId"); + logger.debug("Upgraded cloud_usage user_statistics with networkId"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade user stats: ", e); } @@ -66,7 +64,7 @@ public class Upgrade222to224Premium extends Upgrade222to224 { + "us.network_id where us.account_id = un.account_id and us.data_center_id = un.zone_id and us.device_id = un.host_id"); ) { pstmt1.executeUpdate(); - s_logger.debug("Upgraded cloud_usage usage_network with networkId"); + logger.debug("Upgraded cloud_usage usage_network with networkId"); } catch (Exception e) { throw new CloudRuntimeException("Failed to upgrade user stats: ", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade224to225.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade224to225.java index 48908f5c7d5..4d88e1a6f40 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade224to225.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade224to225.java @@ -25,12 +25,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade224to225 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade224to225.class); +public class Upgrade224to225 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { @@ -80,7 +78,7 @@ public class Upgrade224to225 implements DbUpgrade { } private void createSecurityGroups(Connection conn) { - s_logger.debug("Creating missing default security group as a part of 224-225 upgrade"); + logger.debug("Creating missing default security group as a part of 224-225 upgrade"); try { List accounts = new ArrayList(); PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM account WHERE removed IS NULL and id != 1"); @@ -95,7 +93,7 @@ public class Upgrade224to225 implements DbUpgrade { pstmt.setLong(1, accountId); rs = pstmt.executeQuery(); if (!rs.next()) { - s_logger.debug("Default security group is missing for account id=" + accountId + " so adding it"); + logger.debug("Default security group is missing for account id=" + accountId + " so adding it"); // get accountName/domainId information @@ -208,7 +206,7 @@ public class Upgrade224to225 implements DbUpgrade { columns.add("guest_ip_type"); tablesToModify.put("service_offering", columns); - s_logger.debug("Dropping columns that don't exist in 2.2.5 version of the DB..."); + logger.debug("Dropping columns that don't exist in 2.2.5 version of the DB..."); for (String tableName : tablesToModify.keySet()) { DbUpgradeUtils.dropTableColumnsIfExist(conn, tableName, tablesToModify.get(tableName)); } @@ -277,7 +275,7 @@ public class Upgrade224to225 implements DbUpgrade { indexes.put("remote_access_vpn", keys); // drop all foreign keys first - s_logger.debug("Dropping keys that don't exist in 2.2.5 version of the DB..."); + logger.debug("Dropping keys that don't exist in 2.2.5 version of the DB..."); for (String tableName : foreignKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, foreignKeys.get(tableName), true); } @@ -291,7 +289,7 @@ public class Upgrade224to225 implements DbUpgrade { private void addMissingKeys(Connection conn) { PreparedStatement pstmt = null; try { - s_logger.debug("Adding missing foreign keys"); + logger.debug("Adding missing foreign keys"); HashMap keyToTableMap = new HashMap(); keyToTableMap.put("fk_console_proxy__id", "console_proxy"); @@ -325,13 +323,13 @@ public class Upgrade224to225 implements DbUpgrade { pstmt = conn.prepareStatement("ALTER TABLE " + tableName + " ADD CONSTRAINT " + key + " FOREIGN KEY " + keyToStatementMap.get(key)); pstmt.executeUpdate(); - s_logger.debug("Added missing key " + key + " to table " + tableName); + logger.debug("Added missing key " + key + " to table " + tableName); rs.close(); } - s_logger.debug("Missing keys were added successfully as a part of 224 to 225 upgrade"); + logger.debug("Missing keys were added successfully as a part of 224 to 225 upgrade"); pstmt.close(); } catch (SQLException e) { - s_logger.error("Unable to add missing foreign key; following statement was executed:" + pstmt); + logger.error("Unable to add missing foreign key; following statement was executed:" + pstmt); throw new CloudRuntimeException("Unable to add missing keys due to exception", e); } } @@ -341,13 +339,13 @@ public class Upgrade224to225 implements DbUpgrade { PreparedStatement pstmt = conn.prepareStatement("SELECT * from ovs_tunnel_account"); ResultSet rs = pstmt.executeQuery(); if (!rs.next()) { - s_logger.debug("Adding missing ovs tunnel account"); + logger.debug("Adding missing ovs tunnel account"); pstmt = conn.prepareStatement("INSERT INTO `cloud`.`ovs_tunnel_account` (`from`, `to`, `account`, `key`, `port_name`, `state`) VALUES (0, 0, 0, 0, 'lock', 'SUCCESS')"); pstmt.executeUpdate(); } } catch (SQLException e) { - s_logger.error("Unable to add missing ovs tunnel account due to ", e); + logger.error("Unable to add missing ovs tunnel account due to ", e); throw new CloudRuntimeException("Unable to add missing ovs tunnel account due to ", e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade225to226.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade225to226.java index f606d6e756f..99bf1f981da 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade225to226.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade225to226.java @@ -22,12 +22,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade225to226 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade225to226.class); +public class Upgrade225to226 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { @@ -75,7 +73,7 @@ public class Upgrade225to226 implements DbUpgrade { columns.add("domain_id"); tablesToModify.put("domain_router", columns); - s_logger.debug("Dropping columns that don't exist in 2.2.6 version of the DB..."); + logger.debug("Dropping columns that don't exist in 2.2.6 version of the DB..."); for (String tableName : tablesToModify.keySet()) { DbUpgradeUtils.dropTableColumnsIfExist(conn, tableName, tablesToModify.get(tableName)); } @@ -95,7 +93,7 @@ public class Upgrade225to226 implements DbUpgrade { indexes.put("domain_router", keys); // drop all foreign keys first - s_logger.debug("Dropping keys that don't exist in 2.2.6 version of the DB..."); + logger.debug("Dropping keys that don't exist in 2.2.6 version of the DB..."); for (String tableName : foreignKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, foreignKeys.get(tableName), true); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228.java index 7d665718db4..3c85ee21d1b 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228.java @@ -23,12 +23,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade227to228 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade227to228.class); +public class Upgrade227to228 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -79,7 +77,7 @@ public class Upgrade227to228 implements DbUpgrade { pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.error("Failed to DB migration for multiple secondary storages", e); + logger.error("Failed to DB migration for multiple secondary storages", e); throw new CloudRuntimeException("Failed to DB migration for multiple secondary storages", e); } @@ -93,7 +91,7 @@ public class Upgrade227to228 implements DbUpgrade { } private void updateDomainLevelNetworks(Connection conn) { - s_logger.debug("Updating domain level specific networks..."); + logger.debug("Updating domain level specific networks..."); try { PreparedStatement pstmt = conn.prepareStatement("SELECT n.id FROM networks n, network_offerings o WHERE n.shared=1 AND o.system_only=0 AND o.id=n.network_offering_id"); @@ -113,7 +111,7 @@ public class Upgrade227to228 implements DbUpgrade { pstmt.setLong(1, networkId); rs = pstmt.executeQuery(); if (rs.next()) { - s_logger.debug("Setting network id=" + networkId + " as domain specific shared network"); + logger.debug("Setting network id=" + networkId + " as domain specific shared network"); pstmt = conn.prepareStatement("UPDATE networks set is_domain_specific=1 where id=?"); pstmt.setLong(1, networkId); pstmt.executeUpdate(); @@ -122,9 +120,9 @@ public class Upgrade227to228 implements DbUpgrade { pstmt.close(); } - s_logger.debug("Successfully updated domain level specific networks"); + logger.debug("Successfully updated domain level specific networks"); } catch (SQLException e) { - s_logger.error("Failed to set domain specific shared networks due to ", e); + logger.error("Failed to set domain specific shared networks due to ", e); throw new CloudRuntimeException("Failed to set domain specific shared networks due to ", e); } } @@ -132,7 +130,7 @@ public class Upgrade227to228 implements DbUpgrade { //this method inserts missing volume.delete events (events were missing when vm failed to create) private void updateVolumeUsageRecords(Connection conn) { try { - s_logger.debug("Inserting missing usage_event records for destroyed volumes..."); + logger.debug("Inserting missing usage_event records for destroyed volumes..."); PreparedStatement pstmt = conn.prepareStatement("select id, account_id, data_center_id, name from volumes where state='Destroy' and id in (select resource_id from usage_event where type='volume.create') and id not in (select resource_id from usage_event where type='volume.delete')"); ResultSet rs = pstmt.executeQuery(); @@ -151,9 +149,9 @@ public class Upgrade227to228 implements DbUpgrade { pstmt.executeUpdate(); } - s_logger.debug("Successfully inserted missing usage_event records for destroyed volumes"); + logger.debug("Successfully inserted missing usage_event records for destroyed volumes"); } catch (SQLException e) { - s_logger.error("Failed to insert missing delete usage records ", e); + logger.error("Failed to insert missing delete usage records ", e); throw new CloudRuntimeException("Failed to insert missing delete usage records ", e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228Premium.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228Premium.java index 032fb58da86..4787017ce4b 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228Premium.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade227to228Premium.java @@ -22,12 +22,10 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade227to228Premium extends Upgrade227to228 { - final static Logger s_logger = Logger.getLogger(Upgrade227to228Premium.class); @Override public InputStream[] getPrepareScripts() { @@ -59,7 +57,7 @@ public class Upgrade227to228Premium extends Upgrade227to228 { ResultSet rs = pstmt.executeQuery(); if (rs.next()) { - s_logger.info("The source id field already exist, not adding it"); + logger.info("The source id field already exist, not adding it"); } } catch (Exception e) { @@ -68,21 +66,21 @@ public class Upgrade227to228Premium extends Upgrade227to228 { } if (insertField) { - s_logger.debug("Adding source_id to usage_storage..."); + logger.debug("Adding source_id to usage_storage..."); pstmt = conn.prepareStatement("ALTER TABLE `cloud_usage`.`usage_storage` ADD COLUMN `source_id` bigint unsigned"); pstmt.executeUpdate(); - s_logger.debug("Column source_id was added successfully to usage_storage table"); + logger.debug("Column source_id was added successfully to usage_storage table"); pstmt.close(); } } catch (SQLException e) { - s_logger.error("Failed to add source_id to usage_storage due to ", e); + logger.error("Failed to add source_id to usage_storage due to ", e); throw new CloudRuntimeException("Failed to add source_id to usage_storage due to ", e); } } private void addNetworkIdsToUserStats(Connection conn) { - s_logger.debug("Adding network IDs to user stats..."); + logger.debug("Adding network IDs to user stats..."); try { String stmt = "SELECT DISTINCT public_ip_address FROM `cloud`.`user_statistics` WHERE public_ip_address IS NOT null"; PreparedStatement pstmt = conn.prepareStatement(stmt); @@ -112,10 +110,10 @@ public class Upgrade227to228Premium extends Upgrade227to228 { rs.close(); pstmt.close(); - s_logger.debug("Successfully added network IDs to user stats."); + logger.debug("Successfully added network IDs to user stats."); } catch (SQLException e) { String errorMsg = "Failed to add network IDs to user stats."; - s_logger.error(errorMsg, e); + logger.error(errorMsg, e); throw new CloudRuntimeException(errorMsg, e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade228to229.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade228to229.java index c556cd90089..bd95a067129 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade228to229.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade228to229.java @@ -24,12 +24,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade228to229 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade228to229.class); +public class Upgrade228to229 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -126,7 +124,7 @@ public class Upgrade228to229 implements DbUpgrade { foreignKeys.put("network_tags", keys); // drop all foreign keys first - s_logger.debug("Dropping keys that don't exist in 2.2.6 version of the DB..."); + logger.debug("Dropping keys that don't exist in 2.2.6 version of the DB..."); for (String tableName : foreignKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, foreignKeys.get(tableName), true); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade229to2210.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade229to2210.java index 1ad7e6d2b4c..3d4725c108f 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade229to2210.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade229to2210.java @@ -23,12 +23,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade229to2210 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade229to2210.class); +public class Upgrade229to2210 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -128,7 +126,7 @@ public class Upgrade229to2210 implements DbUpgrade { pstmt.setString(8, UUID.randomUUID().toString()); pstmt.setLong(9, id); - s_logger.debug("Updating firewall rule with the statement " + pstmt); + logger.debug("Updating firewall rule with the statement " + pstmt); pstmt.executeUpdate(); //get new FirewallRule update @@ -159,12 +157,12 @@ public class Upgrade229to2210 implements DbUpgrade { pstmt = conn.prepareStatement("update firewall_rules_cidrs set firewall_rule_id=? where firewall_rule_id=?"); pstmt.setLong(1, firewallRuleId); pstmt.setLong(2, id); - s_logger.debug("Updating existing cidrs for the rule id=" + id + " with the new Firewall rule id=" + firewallRuleId + " with statement" + pstmt); + logger.debug("Updating existing cidrs for the rule id=" + id + " with the new Firewall rule id=" + firewallRuleId + " with statement" + pstmt); pstmt.executeUpdate(); } else { pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')"); pstmt.setLong(1, firewallRuleId); - s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt); + logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt); pstmt.executeUpdate(); } } @@ -180,7 +178,7 @@ public class Upgrade229to2210 implements DbUpgrade { pstmt.close(); } } catch (SQLException e) { - s_logger.info("[ignored]",e); + logger.info("[ignored]",e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade301to302.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade301to302.java index ba479b52f89..28e8d89dff0 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade301to302.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade301to302.java @@ -26,12 +26,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade301to302 extends LegacyDbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade301to302.class); @Override public String[] getUpgradableVersionRange() { @@ -66,7 +64,7 @@ public class Upgrade301to302 extends LegacyDbUpgrade { keys.add("i_host__allocation_state"); uniqueKeys.put("host", keys); - s_logger.debug("Dropping i_host__allocation_state key in host table"); + logger.debug("Dropping i_host__allocation_state key in host table"); for (String tableName : uniqueKeys.keySet()) { DbUpgradeUtils.dropKeysIfExist(conn, tableName, uniqueKeys.get(tableName), false); } @@ -129,7 +127,7 @@ public class Upgrade301to302 extends LegacyDbUpgrade { pstmt = conn.prepareStatement("DELETE FROM `cloud`.`ntwk_offering_service_map` WHERE id=?"); pstmt.setLong(1, mapId); pstmt.executeUpdate(); - s_logger.debug("Deleted lb service for network offering id=" + ntwkOffId + " as it doesn't have source nat service enabled"); + logger.debug("Deleted lb service for network offering id=" + ntwkOffId + " as it doesn't have source nat service enabled"); //delete lb service for the network pstmt = @@ -144,7 +142,7 @@ public class Upgrade301to302 extends LegacyDbUpgrade { pstmt = conn.prepareStatement("DELETE FROM `cloud`.`ntwk_service_map` WHERE id=?"); pstmt.setLong(1, mapId); pstmt.executeUpdate(); - s_logger.debug("Deleted lb service for network id=" + ntwkId + " as it doesn't have source nat service enabled"); + logger.debug("Deleted lb service for network id=" + ntwkId + " as it doesn't have source nat service enabled"); } } @@ -180,14 +178,14 @@ public class Upgrade301to302 extends LegacyDbUpgrade { } private void changeEngine(Connection conn) { - s_logger.debug("Fixing engine and row_format for op_lock and op_nwgrp_work tables"); + logger.debug("Fixing engine and row_format for op_lock and op_nwgrp_work tables"); String sqlOpLock = "ALTER TABLE `cloud`.`op_lock` ENGINE=MEMORY, ROW_FORMAT = FIXED"; try ( PreparedStatement pstmt = conn.prepareStatement(sqlOpLock); ) { pstmt.executeUpdate(); } catch (Exception e) { - s_logger.debug("Failed do execute the statement " + sqlOpLock + ", moving on as it's not critical fix"); + logger.debug("Failed do execute the statement " + sqlOpLock + ", moving on as it's not critical fix"); } String sqlOpNwgrpWork = "ALTER TABLE `cloud`.`op_nwgrp_work` ENGINE=MEMORY, ROW_FORMAT = FIXED"; @@ -196,7 +194,7 @@ public class Upgrade301to302 extends LegacyDbUpgrade { ) { pstmt.executeUpdate(); } catch (Exception e) { - s_logger.debug("Failed do execute the statement " + sqlOpNwgrpWork + ", moving on as it's not critical fix"); + logger.debug("Failed do execute the statement " + sqlOpNwgrpWork + ", moving on as it's not critical fix"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to303.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to303.java index e07c98dd448..91b9b3849a8 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to303.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to303.java @@ -28,14 +28,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade302to303 extends LegacyDbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade302to303.class); @Override public String[] getUpgradableVersionRange() { @@ -142,7 +140,7 @@ public class Upgrade302to303 extends LegacyDbUpgrade { private void addF5LoadBalancer(Connection conn, long hostId, long physicalNetworkId) { PreparedStatement pstmtUpdate = null; try { - s_logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); String insertF5 = "INSERT INTO `cloud`.`external_load_balancer_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, is_inline, is_managed, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -169,7 +167,7 @@ public class Upgrade302to303 extends LegacyDbUpgrade { private void addSrxFirewall(Connection conn, long hostId, long physicalNetworkId) { PreparedStatement pstmtUpdate = null; try { - s_logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); String insertSrx = "INSERT INTO `cloud`.`external_firewall_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -195,7 +193,7 @@ public class Upgrade302to303 extends LegacyDbUpgrade { PreparedStatement pstmtUpdate = null; try { // add physical network service provider - F5BigIp - s_logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); + logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -219,7 +217,7 @@ public class Upgrade302to303 extends LegacyDbUpgrade { PreparedStatement pstmtUpdate = null; try { // add physical network service provider - JuniperSRX - s_logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); + logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -241,7 +239,7 @@ public class Upgrade302to303 extends LegacyDbUpgrade { private void encryptConfig(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Encrypting Config values"); + logger.debug("Encrypting Config values"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -268,7 +266,7 @@ public class Upgrade302to303 extends LegacyDbUpgrade { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done encrypting Config values"); + logger.debug("Done encrypting Config values"); } @Override diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to40.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to40.java index eb0492cd288..aa427252585 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to40.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade302to40.java @@ -27,14 +27,12 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter.NetworkType; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade302to40 extends Upgrade30xBase { - final static Logger s_logger = Logger.getLogger(Upgrade302to40.class); @Override public String[] getUpgradableVersionRange() { @@ -211,9 +209,9 @@ public class Upgrade302to40 extends Upgrade30xBase { if (rsSameLabel.next()) { Long sameLabelcount = rsSameLabel.getLong(1); if (sameLabelcount > 0) { - s_logger.error("There are untagged networks for which we need to add a physical network with Xen traffic label = 'xen.guest.network.device' config value, which is: " + + logger.error("There are untagged networks for which we need to add a physical network with Xen traffic label = 'xen.guest.network.device' config value, which is: " + xenGuestLabel); - s_logger.error("However already there are " + sameLabelcount + " physical networks setup with same traffic label, cannot upgrade"); + logger.error("However already there are " + sameLabelcount + " physical networks setup with same traffic label, cannot upgrade"); throw new CloudRuntimeException("Cannot upgrade this setup since a physical network with same traffic label: " + xenGuestLabel + " already exists, Please check logs and contact Support."); } @@ -230,9 +228,9 @@ public class Upgrade302to40 extends Upgrade30xBase { conn.prepareStatement("SELECT n.id FROM networks n WHERE n.physical_network_id IS NULL AND n.traffic_type = 'Guest' and n.data_center_id = ? and n.removed is null"); pstmt3.setLong(1, zoneId); ResultSet rsNet = pstmt3.executeQuery(); - s_logger.debug("Adding PhysicalNetwork to VLAN"); - s_logger.debug("Adding PhysicalNetwork to user_ip_address"); - s_logger.debug("Adding PhysicalNetwork to networks"); + logger.debug("Adding PhysicalNetwork to VLAN"); + logger.debug("Adding PhysicalNetwork to user_ip_address"); + logger.debug("Adding PhysicalNetwork to networks"); while (rsNet.next()) { Long networkId = rsNet.getLong(1); addPhysicalNtwk_To_Ntwk_IP_Vlan(conn, physicalNetworkId, networkId); @@ -253,7 +251,7 @@ public class Upgrade302to40 extends Upgrade30xBase { if (rs.next()) { Long count = rs.getLong(1); if (count > 1) { - s_logger.debug("There are " + count + " physical networks setup"); + logger.debug("There are " + count + " physical networks setup"); multiplePhysicalNetworks = true; } } @@ -272,7 +270,7 @@ public class Upgrade302to40 extends Upgrade30xBase { String networkId = rsVNet.getString(5); String vpid = rsVNet.getString(4); String npid = rsVNet.getString(6); - s_logger.error("Guest Vnet assignment is set wrongly . Cannot upgrade until that is corrected. Example- Vnet: " + vnet + + logger.error("Guest Vnet assignment is set wrongly . Cannot upgrade until that is corrected. Example- Vnet: " + vnet + " has physical network id: " + vpid + " ,but the guest network: " + networkId + " that uses it has physical network id: " + npid); String message = "Cannot upgrade. Your setup has multiple Physical Networks and is using guest Vnet that is assigned wrongly. " @@ -291,7 +289,7 @@ public class Upgrade302to40 extends Upgrade30xBase { + "5. Run upgrade. This will allocate all your guest vnet range to first physical network. \n" + "6. Reconfigure the vnet ranges for each physical network as desired by using updatePhysicalNetwork API \n" + "7. Start all your VMs"; - s_logger.error(message); + logger.error(message); throw new CloudRuntimeException("Cannot upgrade this setup since Guest Vnet assignment to the multiple physical " + "networks is incorrect. Please check the logs for details on how to proceed"); @@ -470,26 +468,26 @@ public class Upgrade302to40 extends Upgrade30xBase { pstmt = conn.prepareStatement("DROP TEMPORARY TABLE `cloud`.`network_offerings2`"); pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.info("[ignored] ",e); + logger.info("[ignored] ",e); } closeAutoCloseable(pstmt); } } private void addHostDetailsUniqueKey(Connection conn) { - s_logger.debug("Checking if host_details unique key exists, if not we will add it"); + logger.debug("Checking if host_details unique key exists, if not we will add it"); try ( PreparedStatement pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` WHERE KEY_NAME = 'uk_host_id_name'"); ResultSet rs = pstmt.executeQuery(); ) { if (rs.next()) { - s_logger.debug("Unique key already exists on host_details - not adding new one"); + logger.debug("Unique key already exists on host_details - not adding new one"); } else { //add the key PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER IGNORE TABLE `cloud`.`host_details` ADD CONSTRAINT UNIQUE KEY `uk_host_id_name` (`host_id`, `name`)"); pstmtUpdate.executeUpdate(); - s_logger.debug("Unique key did not exist on host_details - added new one"); + logger.debug("Unique key did not exist on host_details - added new one"); pstmtUpdate.close(); } } catch (SQLException e) { @@ -499,7 +497,7 @@ public class Upgrade302to40 extends Upgrade30xBase { private void addVpcProvider(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Adding vpc provider to all physical networks in the system"); + logger.debug("Adding vpc provider to all physical networks in the system"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -534,7 +532,7 @@ public class Upgrade302to40 extends Upgrade30xBase { pstmt.setLong(1, providerId); pstmt.executeUpdate(); - s_logger.debug("Added VPC Virtual router provider for physical network id=" + pNtwkId); + logger.debug("Added VPC Virtual router provider for physical network id=" + pNtwkId); } } catch (SQLException e) { @@ -543,12 +541,12 @@ public class Upgrade302to40 extends Upgrade30xBase { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done adding VPC physical network service providers to all physical networks"); + logger.debug("Done adding VPC physical network service providers to all physical networks"); } private void updateRouterNetworkRef(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Updating router network ref"); + logger.debug("Updating router network ref"); try ( PreparedStatement pstmt = conn.prepareStatement("SELECT d.id, d.network_id FROM `cloud`.`domain_router` d, `cloud`.`vm_instance` v " + "WHERE d.id=v.id AND v.removed is NULL"); PreparedStatement pstmt1 = conn.prepareStatement("SELECT guest_type from `cloud`.`networks` where id=?"); @@ -571,13 +569,13 @@ public class Upgrade302to40 extends Upgrade30xBase { pstmt2.setString(3, networkType); pstmt2.executeUpdate(); } - s_logger.debug("Added reference for router id=" + routerId + " and network id=" + networkId); + logger.debug("Added reference for router id=" + routerId + " and network id=" + networkId); } } catch (SQLException e) { throw new CloudRuntimeException("Failed to update the router/network reference ", e); } - s_logger.debug("Done updating router/network references"); + logger.debug("Done updating router/network references"); } private void fixForeignKeys(Connection conn) { @@ -693,7 +691,7 @@ public class Upgrade302to40 extends Upgrade30xBase { } private void addF5LoadBalancer(Connection conn, long hostId, long physicalNetworkId) { - s_logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); String insertF5 = "INSERT INTO `cloud`.`external_load_balancer_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, is_inline, is_managed, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -716,7 +714,7 @@ public class Upgrade302to40 extends Upgrade30xBase { } private void addSrxFirewall(Connection conn, long hostId, long physicalNetworkId) { - s_logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); String insertSrx = "INSERT INTO `cloud`.`external_firewall_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)"; @@ -738,7 +736,7 @@ public class Upgrade302to40 extends Upgrade30xBase { private void addF5ServiceProvider(Connection conn, long physicalNetworkId, long zoneId) { // add physical network service provider - F5BigIp - s_logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); + logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -757,7 +755,7 @@ public class Upgrade302to40 extends Upgrade30xBase { private void addSrxServiceProvider(Connection conn, long physicalNetworkId, long zoneId) { // add physical network service provider - JuniperSRX - s_logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); + logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -875,7 +873,7 @@ public class Upgrade302to40 extends Upgrade30xBase { pstmtUpdate.setLong(2, networkId); pstmtUpdate.setLong(3, f5DeviceId); pstmtUpdate.executeUpdate(); - s_logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); + logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); // add mapping for the network in network_external_firewall_device_map String insertFwMapping = @@ -885,11 +883,11 @@ public class Upgrade302to40 extends Upgrade30xBase { pstmtUpdate.setLong(2, networkId); pstmtUpdate.setLong(3, srxDevivceId); pstmtUpdate.executeUpdate(); - s_logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); + logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); } // update host details for F5 and SRX devices - s_logger.debug("Updating the host details for F5 and SRX devices"); + logger.debug("Updating the host details for F5 and SRX devices"); pstmt = conn.prepareStatement("SELECT host_id, name FROM `cloud`.`host_details` WHERE host_id=? OR host_id=?"); pstmt.setLong(1, f5HostId); pstmt.setLong(2, srxHostId); @@ -908,20 +906,20 @@ public class Upgrade302to40 extends Upgrade30xBase { pstmt.setString(3, camlCaseName); pstmt.executeUpdate(); } - s_logger.debug("Successfully updated host details for F5 and SRX devices"); + logger.debug("Successfully updated host details for F5 and SRX devices"); } catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } finally { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.info("Successfully upgraded networks using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); + logger.info("Successfully upgraded networks using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); } } private void encryptConfig(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Encrypting Config values"); + logger.debug("Encrypting Config values"); try ( PreparedStatement pstmt = conn.prepareStatement("select name, value from `cloud`.`configuration` where name in ('router.ram.size', 'secondary.storage.vm', 'security.hash.key') and category <> 'Hidden'"); PreparedStatement pstmt1 = conn.prepareStatement("update `cloud`.`configuration` set value=?, category = 'Hidden' where name=?"); @@ -943,11 +941,11 @@ public class Upgrade302to40 extends Upgrade30xBase { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt configuration values ", e); } - s_logger.debug("Done encrypting Config values"); + logger.debug("Done encrypting Config values"); } private void encryptClusterDetails(Connection conn) { - s_logger.debug("Encrypting cluster details"); + logger.debug("Encrypting cluster details"); try ( PreparedStatement pstmt = conn.prepareStatement("select id, value from `cloud`.`cluster_details` where name = 'password'"); PreparedStatement pstmt1 = conn.prepareStatement("update `cloud`.`cluster_details` set value=? where id=?"); @@ -969,6 +967,6 @@ public class Upgrade302to40 extends Upgrade30xBase { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt cluster_details values ", e); } - s_logger.debug("Done encrypting cluster_details"); + logger.debug("Done encrypting cluster_details"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade303to304.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade303to304.java index 03f69ddefc9..d713a1c8592 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade303to304.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade303to304.java @@ -24,13 +24,11 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade303to304 extends Upgrade30xBase implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade303to304.class); +public class Upgrade303to304 extends Upgrade30xBase { @Override public String[] getUpgradableVersionRange() { @@ -171,9 +169,9 @@ public class Upgrade303to304 extends Upgrade30xBase implements DbUpgrade { if (rsSameLabel.next()) { Long sameLabelcount = rsSameLabel.getLong(1); if (sameLabelcount > 0) { - s_logger.error("There are untagged networks for which we need to add a physical network with Xen traffic label = 'xen.guest.network.device' config value, which is: " + + logger.error("There are untagged networks for which we need to add a physical network with Xen traffic label = 'xen.guest.network.device' config value, which is: " + xenGuestLabel); - s_logger.error("However already there are " + sameLabelcount + " physical networks setup with same traffic label, cannot upgrade"); + logger.error("However already there are " + sameLabelcount + " physical networks setup with same traffic label, cannot upgrade"); throw new CloudRuntimeException("Cannot upgrade this setup since a physical network with same traffic label: " + xenGuestLabel + " already exists, Please check logs and contact Support."); } @@ -188,9 +186,9 @@ public class Upgrade303to304 extends Upgrade30xBase implements DbUpgrade { pstmt_network_id.setLong(1, zoneId); try (ResultSet rsNet = pstmt_network_id.executeQuery();) { - s_logger.debug("Adding PhysicalNetwork to VLAN"); - s_logger.debug("Adding PhysicalNetwork to user_ip_address"); - s_logger.debug("Adding PhysicalNetwork to networks"); + logger.debug("Adding PhysicalNetwork to VLAN"); + logger.debug("Adding PhysicalNetwork to user_ip_address"); + logger.debug("Adding PhysicalNetwork to networks"); while (rsNet.next()) { Long networkId = rsNet.getLong(1); addPhysicalNtwk_To_Ntwk_IP_Vlan(conn, physicalNetworkId, networkId); @@ -207,7 +205,7 @@ public class Upgrade303to304 extends Upgrade30xBase implements DbUpgrade { if (rs.next()) { Long count = rs.getLong(1); if (count > 1) { - s_logger.debug("There are " + count + " physical networks setup"); + logger.debug("There are " + count + " physical networks setup"); multiplePhysicalNetworks = true; } } @@ -223,7 +221,7 @@ public class Upgrade303to304 extends Upgrade30xBase implements DbUpgrade { String networkId = rsVNet.getString(5); String vpid = rsVNet.getString(4); String npid = rsVNet.getString(6); - s_logger.error("Guest Vnet assignment is set wrongly . Cannot upgrade until that is corrected. Example- Vnet: " + vnet + + logger.error("Guest Vnet assignment is set wrongly . Cannot upgrade until that is corrected. Example- Vnet: " + vnet + " has physical network id: " + vpid + " ,but the guest network: " + networkId + " that uses it has physical network id: " + npid); String message = "Cannot upgrade. Your setup has multiple Physical Networks and is using guest Vnet that is assigned wrongly. " @@ -242,7 +240,7 @@ public class Upgrade303to304 extends Upgrade30xBase implements DbUpgrade { + "5. Run upgrade. This will allocate all your guest vnet range to first physical network. \n" + "6. Reconfigure the vnet ranges for each physical network as desired by using updatePhysicalNetwork API \n" + "7. Start all your VMs"; - s_logger.error(message); + logger.error(message); throw new CloudRuntimeException("Cannot upgrade this setup since Guest Vnet assignment to the multiple physical networks " + "is incorrect. Please check the logs for details on how to proceed"); @@ -383,7 +381,7 @@ public class Upgrade303to304 extends Upgrade30xBase implements DbUpgrade { try (PreparedStatement pstmt_drop_table = conn.prepareStatement("DROP TEMPORARY TABLE `cloud`.`network_offerings2`");) { pstmt_drop_table.executeUpdate(); } catch (SQLException e) { - s_logger.debug("drop of temp table 'network_offerings2' failed", e); + logger.debug("drop of temp table 'network_offerings2' failed", e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade304to305.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade304to305.java index a8009630976..bb4c73f67b6 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade304to305.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade304to305.java @@ -27,13 +27,11 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade304to305 extends Upgrade30xBase { - final static Logger s_logger = Logger.getLogger(Upgrade304to305.class); @Override public String[] getUpgradableVersionRange() { @@ -99,7 +97,7 @@ public class Upgrade304to305 extends Upgrade30xBase { throw new CloudRuntimeException("Error while iterating through list of hypervisors in use", e); } // Just update the VMware system template. Other hypervisor templates are unchanged from previous 3.0.x versions. - s_logger.debug("Updating VMware System Vms"); + logger.debug("Updating VMware System Vms"); try { //Get 3.0.5 VMware system Vm template Id pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = 'systemvm-vmware-3.0.5' and removed is null"); @@ -122,18 +120,18 @@ public class Upgrade304to305 extends Upgrade30xBase { if (VMware) { throw new CloudRuntimeException("3.0.5 VMware SystemVm template not found. Cannot upgrade system Vms"); } else { - s_logger.warn("3.0.5 VMware SystemVm template not found. VMware hypervisor is not used, so not failing upgrade"); + logger.warn("3.0.5 VMware SystemVm template not found. VMware hypervisor is not used, so not failing upgrade"); } } } catch (SQLException e) { throw new CloudRuntimeException("Error while updating VMware systemVm template", e); } - s_logger.debug("Updating System Vm Template IDs Complete"); + logger.debug("Updating System Vm Template IDs Complete"); } private void addVpcProvider(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Adding vpc provider to all physical networks in the system"); + logger.debug("Adding vpc provider to all physical networks in the system"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -168,7 +166,7 @@ public class Upgrade304to305 extends Upgrade30xBase { pstmt.setLong(1, providerId); pstmt.executeUpdate(); - s_logger.debug("Added VPC Virtual router provider for physical network id=" + pNtwkId); + logger.debug("Added VPC Virtual router provider for physical network id=" + pNtwkId); } } catch (SQLException e) { @@ -177,12 +175,12 @@ public class Upgrade304to305 extends Upgrade30xBase { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done adding VPC physical network service providers to all physical networks"); + logger.debug("Done adding VPC physical network service providers to all physical networks"); } private void updateRouterNetworkRef(Connection conn) { //Encrypt config params and change category to Hidden - s_logger.debug("Updating router network ref"); + logger.debug("Updating router network ref"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -207,7 +205,7 @@ public class Upgrade304to305 extends Upgrade30xBase { pstmt.setString(3, networkType); pstmt.executeUpdate(); - s_logger.debug("Added reference for router id=" + routerId + " and network id=" + networkId); + logger.debug("Added reference for router id=" + routerId + " and network id=" + networkId); } } catch (SQLException e) { @@ -216,24 +214,24 @@ public class Upgrade304to305 extends Upgrade30xBase { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done updating router/network references"); + logger.debug("Done updating router/network references"); } private void addHostDetailsUniqueKey(Connection conn) { - s_logger.debug("Checking if host_details unique key exists, if not we will add it"); + logger.debug("Checking if host_details unique key exists, if not we will add it"); PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` WHERE KEY_NAME = 'uk_host_id_name'"); rs = pstmt.executeQuery(); if (rs.next()) { - s_logger.debug("Unique key already exists on host_details - not adding new one"); + logger.debug("Unique key already exists on host_details - not adding new one"); } else { //add the key PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER IGNORE TABLE `cloud`.`host_details` ADD CONSTRAINT UNIQUE KEY `uk_host_id_name` (`host_id`, `name`)"); pstmtUpdate.executeUpdate(); - s_logger.debug("Unique key did not exist on host_details - added new one"); + logger.debug("Unique key did not exist on host_details - added new one"); pstmtUpdate.close(); } } catch (SQLException e) { @@ -347,7 +345,7 @@ public class Upgrade304to305 extends Upgrade30xBase { pstmtUpdate.setLong(2, networkId); pstmtUpdate.setLong(3, f5DeviceId); pstmtUpdate.executeUpdate(); - s_logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); + logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); // add mapping for the network in network_external_firewall_device_map String insertFwMapping = @@ -357,11 +355,11 @@ public class Upgrade304to305 extends Upgrade30xBase { pstmtUpdate.setLong(2, networkId); pstmtUpdate.setLong(3, srxDevivceId); pstmtUpdate.executeUpdate(); - s_logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); + logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); } // update host details for F5 and SRX devices - s_logger.debug("Updating the host details for F5 and SRX devices"); + logger.debug("Updating the host details for F5 and SRX devices"); pstmt = conn.prepareStatement("SELECT host_id, name FROM `cloud`.`host_details` WHERE host_id=? OR host_id=?"); pstmt.setLong(1, f5HostId); pstmt.setLong(2, srxHostId); @@ -380,19 +378,19 @@ public class Upgrade304to305 extends Upgrade30xBase { pstmt.setString(3, camlCaseName); pstmt.executeUpdate(); } - s_logger.debug("Successfully updated host details for F5 and SRX devices"); + logger.debug("Successfully updated host details for F5 and SRX devices"); } catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } finally { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.info("Successfully upgraded network using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); + logger.info("Successfully upgraded network using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); } } private void fixForeignKeys(Connection conn) { - s_logger.debug("Fixing foreign keys' names in ssh_keypairs table"); + logger.debug("Fixing foreign keys' names in ssh_keypairs table"); //Drop the keys (if exist) List keys = new ArrayList(); keys.add("fk_ssh_keypair__account_id"); @@ -434,7 +432,7 @@ public class Upgrade304to305 extends Upgrade30xBase { } private void encryptClusterDetails(Connection conn) { - s_logger.debug("Encrypting cluster details"); + logger.debug("Encrypting cluster details"); PreparedStatement pstmt = null; ResultSet rs = null; try { @@ -460,6 +458,6 @@ public class Upgrade304to305 extends Upgrade30xBase { closeAutoCloseable(rs); closeAutoCloseable(pstmt); } - s_logger.debug("Done encrypting cluster_details"); + logger.debug("Done encrypting cluster_details"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade305to306.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade305to306.java index 796287697a9..52aab2a13e9 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade305to306.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade305to306.java @@ -27,12 +27,10 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade305to306 extends Upgrade30xBase { - final static Logger s_logger = Logger.getLogger(Upgrade305to306.class); @Override public String[] getUpgradableVersionRange() { @@ -78,14 +76,14 @@ public class Upgrade305to306 extends Upgrade30xBase { //First drop if it exists. (Due to patches shipped to customers some will have the index and some won't.) List indexList = new ArrayList(); - s_logger.debug("Dropping index i_alert__last_sent if it exists"); + logger.debug("Dropping index i_alert__last_sent if it exists"); indexList.add("i_alert__last_sent"); DbUpgradeUtils.dropKeysIfExist(conn, "alert", indexList, false); //Now add index. try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`alert` ADD INDEX `i_alert__last_sent`(`last_sent`)");) { pstmt.executeUpdate(); - s_logger.debug("Added index i_alert__last_sent for table alert"); + logger.debug("Added index i_alert__last_sent for table alert"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add index i_alert__last_sent to alert table for the column last_sent", e); } @@ -117,14 +115,14 @@ public class Upgrade305to306 extends Upgrade30xBase { //First drop if it exists. (Due to patches shipped to customers some will have the index and some won't.) List indexList = new ArrayList(); - s_logger.debug("Dropping index fk_host_details__host_id if it exists"); + logger.debug("Dropping index fk_host_details__host_id if it exists"); indexList.add("fk_host_details__host_id"); DbUpgradeUtils.dropKeysIfExist(conn, "host_details", indexList, false); //Now add index. try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`host_details` ADD INDEX `fk_host_details__host_id`(`host_id`)");) { pstmt.executeUpdate(); - s_logger.debug("Added index fk_host_details__host_id for table host_details"); + logger.debug("Added index fk_host_details__host_id for table host_details"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add index fk_host_details__host_id to host_details table for the column host_id", e); } @@ -140,7 +138,7 @@ public class Upgrade305to306 extends Upgrade30xBase { // update the existing ingress rules traffic type pstmt = conn.prepareStatement("update `cloud`.`firewall_rules`" + " set traffic_type='Ingress' where purpose='Firewall' and ip_address_id is not null and traffic_type is null"); - s_logger.debug("Updating firewall Ingress rule traffic type: " + pstmt); + logger.debug("Updating firewall Ingress rule traffic type: " + pstmt); pstmt.executeUpdate(); pstmt = conn.prepareStatement("select network_id FROM `cloud`.`ntwk_service_map` where service='Firewall' and provider='VirtualRouter' "); @@ -152,7 +150,7 @@ public class Upgrade305to306 extends Upgrade30xBase { pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='" + "Virtual') and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR state='Shutdown') and id=? "); pstmt.setLong(1, netId); - s_logger.debug("Getting account_id, domain_id from networks table: " + pstmt); + logger.debug("Getting account_id, domain_id from networks table: " + pstmt); rsNw = pstmt.executeQuery(); if (rsNw.next()) { @@ -160,7 +158,7 @@ public class Upgrade305to306 extends Upgrade30xBase { long domainId = rsNw.getLong(2); //Add new rule for the existing networks - s_logger.debug("Adding default egress firewall rule for network " + netId); + logger.debug("Adding default egress firewall rule for network " + netId); pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created, traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')"); pstmt.setString(1, UUID.randomUUID().toString()); @@ -168,7 +166,7 @@ public class Upgrade305to306 extends Upgrade30xBase { pstmt.setLong(3, domainId); pstmt.setLong(4, netId); pstmt.setString(5, UUID.randomUUID().toString()); - s_logger.debug("Inserting default egress firewall rule " + pstmt); + logger.debug("Inserting default egress firewall rule " + pstmt); pstmt.executeUpdate(); pstmt = conn.prepareStatement("select id from firewall_rules where protocol='all' and network_id=?"); @@ -180,7 +178,7 @@ public class Upgrade305to306 extends Upgrade30xBase { firewallRuleId = rsId.getLong(1); pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')"); pstmt.setLong(1, firewallRuleId); - s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt); + logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + pstmt); pstmt.executeUpdate(); } } @@ -218,7 +216,7 @@ public class Upgrade305to306 extends Upgrade30xBase { private void fix22xKVMSnapshots(Connection conn) { PreparedStatement pstmt = null; ResultSet rs = null; - s_logger.debug("Updating KVM snapshots"); + logger.debug("Updating KVM snapshots"); try { pstmt = conn.prepareStatement("select id, backup_snap_id from `cloud`.`snapshots` where hypervisor_type='KVM' and removed is null and backup_snap_id is not null"); @@ -232,14 +230,14 @@ public class Upgrade305to306 extends Upgrade30xBase { int index = backUpPath.indexOf("snapshots" + File.separator); if (index > 1) { String correctedPath = File.separator + backUpPath.substring(index); - s_logger.debug("Updating Snapshot with id: " + id + " original backup path: " + backUpPath + " updated backup path: " + correctedPath); + logger.debug("Updating Snapshot with id: " + id + " original backup path: " + backUpPath + " updated backup path: " + correctedPath); pstmt = conn.prepareStatement("UPDATE `cloud`.`snapshots` set backup_snap_id=? where id = ?"); pstmt.setString(1, correctedPath); pstmt.setLong(2, id); pstmt.executeUpdate(); } } - s_logger.debug("Done updating KVM snapshots"); + logger.debug("Done updating KVM snapshots"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to update backup id for KVM snapshots", e); } finally { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade306to307.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade306to307.java index 4eb39af51d7..3d28d73031a 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade306to307.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade306to307.java @@ -23,12 +23,10 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade306to307 extends Upgrade30xBase { - final static Logger s_logger = Logger.getLogger(Upgrade306to307.class); @Override public String[] getUpgradableVersionRange() { @@ -96,7 +94,7 @@ public class Upgrade306to307 extends Upgrade30xBase { pstmt = conn.prepareStatement("drop table `cloud`.`network_details`"); pstmt.executeUpdate(); } catch (SQLException e) { - s_logger.info("[ignored] error during network offering update:" + e.getLocalizedMessage(), e); + logger.info("[ignored] error during network offering update:" + e.getLocalizedMessage(), e); } finally { closeAutoCloseable(rs); closeAutoCloseable(rs1); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade307to410.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade307to410.java index 1554ff04f70..1d47717a2de 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade307to410.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade307to410.java @@ -23,13 +23,11 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Properties; -import org.apache.log4j.Logger; import com.cloud.utils.db.DbProperties; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade307to410 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade307to410.class); +public class Upgrade307to410 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -71,7 +69,7 @@ public class Upgrade307to410 implements DbUpgrade { } try (PreparedStatement pstmt = conn.prepareStatement("update `cloud`.`region` set id = ?");){ //Update regionId in region table - s_logger.debug("Updating region table with Id: " + region_id); + logger.debug("Updating region table with Id: " + region_id); pstmt.setInt(1, region_id); pstmt.executeUpdate(); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30to301.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30to301.java index 806cabb12eb..ba17082bab5 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30to301.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30to301.java @@ -22,13 +22,11 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.configuration.Resource.ResourceType; import com.cloud.utils.exception.CloudRuntimeException; public class Upgrade30to301 extends LegacyDbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade30to301.class); @Override public String[] getUpgradableVersionRange() { @@ -95,7 +93,7 @@ public class Upgrade30to301 extends LegacyDbUpgrade { pstmt.setLong(1, accountId); pstmt.setLong(2, count); pstmt.executeUpdate(); - s_logger.debug("Updated network resource count for account id=" + accountId + " to be " + count); + logger.debug("Updated network resource count for account id=" + accountId + " to be " + count); } } catch (SQLException e) { throw new CloudRuntimeException("Unable to update network resource count for account id=" + accountId, e); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30xBase.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30xBase.java index 47b877d5aa5..d2dd7736533 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30xBase.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade30xBase.java @@ -23,13 +23,11 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; public abstract class Upgrade30xBase extends LegacyDbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade30xBase.class); protected String getNetworkLabelFromConfig(Connection conn, String name) { String sql = "SELECT value FROM `cloud`.`configuration` where name = ?"; @@ -72,7 +70,7 @@ public abstract class Upgrade30xBase extends LegacyDbUpgrade { broadcastDomainRange = "ZONE"; } - s_logger.debug("Adding PhysicalNetwork " + physicalNetworkId + " for Zone id " + zoneId); + logger.debug("Adding PhysicalNetwork " + physicalNetworkId + " for Zone id " + zoneId); String sql = "INSERT INTO `cloud`.`physical_network` (id, uuid, data_center_id, vnet, broadcast_domain_range, state, name) VALUES (?,?,?,?,?,?,?)"; pstmtUpdate = conn.prepareStatement(sql); @@ -84,12 +82,12 @@ public abstract class Upgrade30xBase extends LegacyDbUpgrade { pstmtUpdate.setString(6, "Enabled"); zoneName = zoneName + "-pNtwk" + physicalNetworkId; pstmtUpdate.setString(7, zoneName); - s_logger.warn("Statement is " + pstmtUpdate.toString()); + logger.warn("Statement is " + pstmtUpdate.toString()); pstmtUpdate.executeUpdate(); pstmtUpdate.close(); if (domainId != null && domainId.longValue() != 0) { - s_logger.debug("Updating domain_id for physical network id=" + physicalNetworkId); + logger.debug("Updating domain_id for physical network id=" + physicalNetworkId); sql = "UPDATE `cloud`.`physical_network` set domain_id=? where id=?"; pstmtUpdate = conn.prepareStatement(sql); pstmtUpdate.setLong(1, domainId); @@ -111,7 +109,7 @@ public abstract class Upgrade30xBase extends LegacyDbUpgrade { // add traffic types PreparedStatement pstmtUpdate = null; try { - s_logger.debug("Adding PhysicalNetwork traffic types"); + logger.debug("Adding PhysicalNetwork traffic types"); String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` (physical_network_id, traffic_type, xen_network_label, kvm_network_label, vmware_network_label, uuid) VALUES ( ?, ?, ?, ?, ?, ?)"; pstmtUpdate = conn.prepareStatement(insertTraficType); @@ -154,7 +152,7 @@ public abstract class Upgrade30xBase extends LegacyDbUpgrade { pstmt2.close(); if (isSGServiceEnabled) { - s_logger.debug("Adding PhysicalNetworkServiceProvider SecurityGroupProvider to the physical network id=" + physicalNetworkId); + logger.debug("Adding PhysicalNetworkServiceProvider SecurityGroupProvider to the physical network id=" + physicalNetworkId); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," @@ -182,7 +180,7 @@ public abstract class Upgrade30xBase extends LegacyDbUpgrade { PreparedStatement pstmtUpdate = null, pstmt2 = null; try { // add physical network service provider - VirtualRouter - s_logger.debug("Adding PhysicalNetworkServiceProvider VirtualRouter"); + logger.debug("Adding PhysicalNetworkServiceProvider VirtualRouter"); String insertPNSP = "INSERT INTO `cloud`.`physical_network_service_providers` (`uuid`, `physical_network_id` , `provider_name`, `state` ," + "`destination_physical_network_id`, `vpn_service_provided`, `dhcp_service_provided`, `dns_service_provided`, `gateway_service_provided`," diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade40to41.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade40to41.java index 3e15ff6782b..6dc58fdda79 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade40to41.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade40to41.java @@ -25,13 +25,11 @@ import java.sql.SQLException; import java.util.Properties; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.utils.db.DbProperties; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade40to41 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade40to41.class); +public class Upgrade40to41 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -85,7 +83,7 @@ public class Upgrade40to41 implements DbUpgrade { } try (PreparedStatement pstmt = conn.prepareStatement("update `cloud`.`region` set id = ?");) { //Update regionId in region table - s_logger.debug("Updating region table with Id: " + region_id); + logger.debug("Updating region table with Id: " + region_id); pstmt.setInt(1, region_id); pstmt.executeUpdate(); @@ -101,7 +99,7 @@ public class Upgrade40to41 implements DbUpgrade { "not null and traffic_type is null");) { updateNwpstmt.executeUpdate(); - s_logger.debug("Updating firewall Ingress rule traffic type: " + updateNwpstmt); + logger.debug("Updating firewall Ingress rule traffic type: " + updateNwpstmt); } catch (SQLException e) { throw new CloudRuntimeException("Unable to update ingress firewall rules ", e); } @@ -120,13 +118,13 @@ public class Upgrade40to41 implements DbUpgrade { NwAcctDomIdpstmt.setLong(1, netId); try (ResultSet NwAcctDomIdps = NwAcctDomIdpstmt.executeQuery();) { - s_logger.debug("Getting account_id, domain_id from networks table: " + NwAcctDomIdpstmt); + logger.debug("Getting account_id, domain_id from networks table: " + NwAcctDomIdpstmt); if (NwAcctDomIdps.next()) { long accountId = NwAcctDomIdps.getLong(1); long domainId = NwAcctDomIdps.getLong(2); //Add new rule for the existing networks - s_logger.debug("Adding default egress firewall rule for network " + netId); + logger.debug("Adding default egress firewall rule for network " + netId); try (PreparedStatement fwRulespstmt = conn.prepareStatement("INSERT INTO firewall_rules "+ " (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created," + " traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), " @@ -137,7 +135,7 @@ public class Upgrade40to41 implements DbUpgrade { fwRulespstmt.setLong(3, domainId); fwRulespstmt.setLong(4, netId); fwRulespstmt.setString(5, UUID.randomUUID().toString()); - s_logger.debug("Inserting default egress firewall rule " + fwRulespstmt); + logger.debug("Inserting default egress firewall rule " + fwRulespstmt); fwRulespstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("failed to insert default egress firewall rule ", e); @@ -154,7 +152,7 @@ public class Upgrade40to41 implements DbUpgrade { try (PreparedStatement fwCidrsPstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");) { fwCidrsPstmt.setLong(1, firewallRuleId); - s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + fwCidrsPstmt); + logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + fwCidrsPstmt); fwCidrsPstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Unable to set egress firewall rules ", e); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41000to41100.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41000to41100.java index 3900cf0bf82..9b2a7fcc0bb 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41000to41100.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41000to41100.java @@ -25,14 +25,12 @@ import java.sql.SQLException; import java.util.Map; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; import com.cloud.utils.PropertiesUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41000to41100 implements DbUpgrade { +public class Upgrade41000to41100 extends DbUpgradeAbstractImpl { - final static Logger LOG = Logger.getLogger(Upgrade41000to41100.class); @Override public String[] getUpgradableVersionRange() { @@ -69,16 +67,16 @@ public class Upgrade41000to41100 implements DbUpgrade { private void checkAndEnableDynamicRoles(final Connection conn) { final Map apiMap = PropertiesUtil.processConfigFile(new String[] { "commands.properties" }); if (apiMap == null || apiMap.isEmpty()) { - if (LOG.isDebugEnabled()) { - LOG.debug("No commands.properties file was found, enabling dynamic roles by setting dynamic.apichecker.enabled to true if not already enabled."); + if (logger.isDebugEnabled()) { + logger.debug("No commands.properties file was found, enabling dynamic roles by setting dynamic.apichecker.enabled to true if not already enabled."); } try (final PreparedStatement updateStatement = conn.prepareStatement("INSERT INTO cloud.configuration (category, instance, name, default_value, value) VALUES ('Advanced', 'DEFAULT', 'dynamic.apichecker.enabled', 'false', 'true') ON DUPLICATE KEY UPDATE value='true'")) { updateStatement.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to set dynamic.apichecker.enabled to true, please run migrate-dynamicroles.py script to manually migrate to dynamic roles.", e); + logger.error("Failed to set dynamic.apichecker.enabled to true, please run migrate-dynamicroles.py script to manually migrate to dynamic roles.", e); } } else { - LOG.warn("Old commands.properties static checker is deprecated, please use migrate-dynamicroles.py to migrate to dynamic roles. Refer http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/latest/accounts.html#using-dynamic-roles"); + logger.warn("Old commands.properties static checker is deprecated, please use migrate-dynamicroles.py to migrate to dynamic roles. Refer http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/latest/accounts.html#using-dynamic-roles"); } } @@ -96,19 +94,19 @@ public class Upgrade41000to41100 implements DbUpgrade { updateStatement.setLong(2, userVmId); updateStatement.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " with exception: " + e.getMessage()); + logger.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " with exception: " + e.getMessage()); throw new CloudRuntimeException("Exception while updating cloud.user_vm for id " + userVmId, e); } } } else { // Update to NULL since it's invalid - LOG.warn("Removing user_data for vm id " + userVmId + " because it's invalid"); - LOG.warn("Removed data was: " + userData); + logger.warn("Removing user_data for vm id " + userVmId + " because it's invalid"); + logger.warn("Removed data was: " + userData); try (final PreparedStatement updateStatement = conn.prepareStatement("UPDATE `cloud`.`user_vm` SET `user_data` = NULL WHERE `id` = ? ;")) { updateStatement.setLong(1, userVmId); updateStatement.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " to NULL with exception: " + e.getMessage()); + logger.error("Failed to update cloud.user_vm user_data for id:" + userVmId + " to NULL with exception: " + e.getMessage()); throw new CloudRuntimeException("Exception while updating cloud.user_vm for id " + userVmId + " to NULL", e); } } @@ -116,8 +114,8 @@ public class Upgrade41000to41100 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Exception while validating existing user_vm table's user_data column to be base64 valid with padding", e); } - if (LOG.isDebugEnabled()) { - LOG.debug("Done validating base64 content of user data"); + if (logger.isDebugEnabled()) { + logger.debug("Done validating base64 content of user data"); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade410to420.java index 2e7eee13a5a..b78aed3119a 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade410to420.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade410to420.java @@ -33,7 +33,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; @@ -44,8 +43,7 @@ import com.cloud.utils.Pair; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade410to420 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade410to420.class); +public class Upgrade410to420 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -194,15 +192,15 @@ public class Upgrade410to420 implements DbUpgrade { detailsMap.put(clusterId, detailsList); updateClusterDetails(conn, detailsMap); - s_logger.debug("Persist vSwitch Configuration: Successfully persisted vswitch configuration for cluster " + clusterId); + logger.debug("Persist vSwitch Configuration: Successfully persisted vswitch configuration for cluster " + clusterId); } else { - s_logger.debug("Persist vSwitch Configuration: Ignoring cluster " + clusterId + " with hypervisor type " + clusterHypervisorType); + logger.debug("Persist vSwitch Configuration: Ignoring cluster " + clusterId + " with hypervisor type " + clusterHypervisorType); continue; } } // End cluster iteration }catch (SQLException e) { String msg = "Unable to persist vswitch configuration of VMware clusters." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } @@ -212,7 +210,7 @@ public class Upgrade410to420 implements DbUpgrade { } } catch (SQLException e) { String msg = "Unable to persist vswitch configuration of VMware clusters." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } } @@ -238,7 +236,7 @@ public class Upgrade410to420 implements DbUpgrade { clusterDetailsInsert.setString(3, val); clusterDetailsInsert.executeUpdate(); } - s_logger.debug("Inserted vswitch configuration details into cloud.cluster_details for cluster with id " + clusterId + "."); + logger.debug("Inserted vswitch configuration details into cloud.cluster_details for cluster with id " + clusterId + "."); }catch (SQLException e) { throw new CloudRuntimeException("Unable insert cluster details into cloud.cluster_details table.", e); } @@ -272,7 +270,7 @@ public class Upgrade410to420 implements DbUpgrade { { pstmt.setString(1, paramVal); pstmt.setString(2, paramName); - s_logger.debug("Updating global configuration parameter " + paramName + " with value " + paramVal + ". Update SQL statement is " + pstmt); + logger.debug("Updating global configuration parameter " + paramName + " with value " + paramVal + ". Update SQL statement is " + pstmt); pstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Unable to set global configuration parameter " + paramName + " to " + paramVal + ". ", e); @@ -311,7 +309,7 @@ public class Upgrade410to420 implements DbUpgrade { String type = "ExplicitDedication"; String uuid = UUID.randomUUID().toString(); String groupName = "DedicatedGrp-domain-" + domainName; - s_logger.debug("Adding AffinityGroup of type " + type + " for domain id " + domainId); + logger.debug("Adding AffinityGroup of type " + type + " for domain id " + domainId); String sql = "INSERT INTO `cloud`.`affinity_group` (`name`, `type`, `uuid`, `description`, `domain_id`, `account_id`, `acl_type`) VALUES (?, ?, ?, ?, 1, 1, 'Domain')"; try (PreparedStatement insert_pstmt = conn.prepareStatement(sql);) { @@ -416,7 +414,7 @@ public class Upgrade410to420 implements DbUpgrade { }catch (SQLException e) { throw new CloudRuntimeException("Unable to add foreign keys to baremetal_dhcp_devices table", e); } - s_logger.debug("Added foreign keys for table baremetal_dhcp_devices"); + logger.debug("Added foreign keys for table baremetal_dhcp_devices"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add foreign keys to baremetal_dhcp_devices table", e); } @@ -436,7 +434,7 @@ public class Upgrade410to420 implements DbUpgrade { }catch (SQLException e) { throw new CloudRuntimeException("Unable to add foreign keys to baremetal_pxe_devices table", e); } - s_logger.debug("Added foreign keys for table baremetal_pxe_devices"); + logger.debug("Added foreign keys for table baremetal_pxe_devices"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add foreign keys to baremetal_pxe_devices table", e); } @@ -445,7 +443,7 @@ public class Upgrade410to420 implements DbUpgrade { private void addIndexForAlert(Connection conn) { //First drop if it exists. (Due to patches shipped to customers some will have the index and some won't.) List indexList = new ArrayList(); - s_logger.debug("Dropping index i_alert__last_sent if it exists"); + logger.debug("Dropping index i_alert__last_sent if it exists"); indexList.add("last_sent"); // in 4.1, we created this index that is not in convention. indexList.add("i_alert__last_sent"); DbUpgradeUtils.dropKeysIfExist(conn, "alert", indexList, false); @@ -453,7 +451,7 @@ public class Upgrade410to420 implements DbUpgrade { try(PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`alert` ADD INDEX `i_alert__last_sent`(`last_sent`)");) { pstmt.executeUpdate(); - s_logger.debug("Added index i_alert__last_sent for table alert"); + logger.debug("Added index i_alert__last_sent for table alert"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add index i_alert__last_sent to alert table for the column last_sent", e); } @@ -462,7 +460,7 @@ public class Upgrade410to420 implements DbUpgrade { private void dropUploadTable(Connection conn) { try(PreparedStatement pstmt0 = conn.prepareStatement("SELECT url, created, type_id, host_id from upload where type=?");) { // Read upload table - Templates - s_logger.debug("Populating template_store_ref table"); + logger.debug("Populating template_store_ref table"); pstmt0.setString(1, "TEMPLATE"); try(ResultSet rs0 = pstmt0.executeQuery();) { @@ -476,7 +474,7 @@ public class Upgrade410to420 implements DbUpgrade { pstmt1.executeUpdate(); } // Read upload table - Volumes - s_logger.debug("Populating volume store ref table"); + logger.debug("Populating volume store ref table"); try(PreparedStatement pstmt2 = conn.prepareStatement("SELECT url, created, type_id, host_id, install_path from upload where type=?");) { pstmt2.setString(1, "VOLUME"); try(ResultSet rs2 = pstmt2.executeQuery();) { @@ -518,7 +516,7 @@ public class Upgrade410to420 implements DbUpgrade { //KVM snapshot flag: only turn on if Customers is using snapshot; private void setKVMSnapshotFlag(Connection conn) { - s_logger.debug("Verify and set the KVM snapshot flag if snapshot was used. "); + logger.debug("Verify and set the KVM snapshot flag if snapshot was used. "); try(PreparedStatement pstmt = conn.prepareStatement("select count(*) from `cloud`.`snapshots` where hypervisor_type = 'KVM'");) { int numRows = 0; @@ -541,7 +539,7 @@ public class Upgrade410to420 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Failed to read the snapshot table for KVM upgrade. ", e); } - s_logger.debug("Done set KVM snapshot flag. "); + logger.debug("Done set KVM snapshot flag. "); } private void updatePrimaryStore(Connection conn) { @@ -633,7 +631,7 @@ public class Upgrade410to420 implements DbUpgrade { } } } catch (SQLException e) { - s_logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e)); + logger.error(new CloudRuntimeException("Failed to read vmware_network_label : " + e)); } return newGuestLabel; } @@ -667,7 +665,7 @@ public class Upgrade410to420 implements DbUpgrade { newLabel = getNewLabel(rsLabel, trafficTypeVswitchParamValue); try(PreparedStatement update_pstmt = conn.prepareStatement("update physical_network_traffic_types set vmware_network_label = ? where traffic_type = ? and vmware_network_label is not NULL;");) { - s_logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt); + logger.debug("Updating vmware label for " + trafficType + " traffic. Update SQL statement is " + pstmt); pstmt.setString(1, newLabel); pstmt.setString(2, trafficType); update_pstmt.executeUpdate(); @@ -748,7 +746,7 @@ public class Upgrade410to420 implements DbUpgrade { if (count > 0) { if (!dcOfPreviousCluster.equalsIgnoreCase(dcOfCurrentCluster)) { legacyZone = true; - s_logger.debug("Marking the zone " + zoneId + " as legacy zone."); + logger.debug("Marking the zone " + zoneId + " as legacy zone."); } } } catch (SQLException e) { @@ -758,7 +756,7 @@ public class Upgrade410to420 implements DbUpgrade { throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e); } } else { - s_logger.debug("Ignoring zone " + zoneId + " with hypervisor type " + clusterHypervisorType); + logger.debug("Ignoring zone " + zoneId + " with hypervisor type " + clusterHypervisorType); break; } count++; @@ -798,11 +796,11 @@ public class Upgrade410to420 implements DbUpgrade { updateLegacyZones(conn, listOfLegacyZones); updateNonLegacyZones(conn, listOfNonLegacyZones); } catch (SQLException e) { - s_logger.error("Unable to discover legacy zones." + e.getMessage(),e); + logger.error("Unable to discover legacy zones." + e.getMessage(),e); throw new CloudRuntimeException("Unable to discover legacy zones." + e.getMessage(), e); } }catch (SQLException e) { - s_logger.error("Unable to discover legacy zones." + e.getMessage(),e); + logger.error("Unable to discover legacy zones." + e.getMessage(),e); throw new CloudRuntimeException("Unable to discover legacy zones." + e.getMessage(), e); } } @@ -813,7 +811,7 @@ public class Upgrade410to420 implements DbUpgrade { for (Long zoneId : zones) { legacyZonesQuery.setLong(1, zoneId); legacyZonesQuery.executeUpdate(); - s_logger.debug("Inserted zone " + zoneId + " into cloud.legacyzones table"); + logger.debug("Inserted zone " + zoneId + " into cloud.legacyzones table"); } } catch (SQLException e) { throw new CloudRuntimeException("Unable add zones to cloud.legacyzones table.", e); @@ -823,7 +821,7 @@ public class Upgrade410to420 implements DbUpgrade { private void updateNonLegacyZones(Connection conn, List zones) { try { for (Long zoneId : zones) { - s_logger.debug("Discovered non-legacy zone " + zoneId + ". Processing the zone to associate with VMware datacenter."); + logger.debug("Discovered non-legacy zone " + zoneId + ". Processing the zone to associate with VMware datacenter."); // All clusters in a non legacy zone will belong to the same VMware DC, hence pick the first cluster try (PreparedStatement clustersQuery = conn.prepareStatement("select id from `cloud`.`cluster` where removed is NULL AND data_center_id=?");) { @@ -888,7 +886,7 @@ public class Upgrade410to420 implements DbUpgrade { } } catch (SQLException e) { String msg = "Unable to update non legacy zones." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } } @@ -914,7 +912,7 @@ public class Upgrade410to420 implements DbUpgrade { }catch (SQLException e) { throw new CloudRuntimeException("Unable to create placeholder nics", e); } - s_logger.debug("Created placeholder nic for the ipAddress " + ip + " and network " + networkId); + logger.debug("Created placeholder nic for the ipAddress " + ip + " and network " + networkId); } }catch (SQLException e) { throw new CloudRuntimeException("Unable to create placeholder nics", e); @@ -959,7 +957,7 @@ public class Upgrade410to420 implements DbUpgrade { try(PreparedStatement sel_net_pstmt = conn.prepareStatement("select account_id, domain_id FROM `cloud`.`networks` where (guest_type='Isolated' OR guest_type='Virtual') and traffic_type='Guest' and vpc_id is NULL and (state='implemented' OR state='Shutdown') and id=? ");) { sel_net_pstmt.setLong(1, netId); - s_logger.debug("Getting account_id, domain_id from networks table: "); + logger.debug("Getting account_id, domain_id from networks table: "); try(ResultSet rsNw = pstmt.executeQuery();) { if (rsNw.next()) { @@ -967,7 +965,7 @@ public class Upgrade410to420 implements DbUpgrade { long domainId = rsNw.getLong(2); //Add new rule for the existing networks - s_logger.debug("Adding default egress firewall rule for network " + netId); + logger.debug("Adding default egress firewall rule for network " + netId); try (PreparedStatement insert_pstmt = conn.prepareStatement("INSERT INTO firewall_rules (uuid, state, protocol, purpose, account_id, domain_id, network_id, xid, created, traffic_type) VALUES (?, 'Active', 'all', 'Firewall', ?, ?, ?, ?, now(), 'Egress')");) { insert_pstmt.setString(1, UUID.randomUUID().toString()); @@ -975,7 +973,7 @@ public class Upgrade410to420 implements DbUpgrade { insert_pstmt.setLong(3, domainId); insert_pstmt.setLong(4, netId); insert_pstmt.setString(5, UUID.randomUUID().toString()); - s_logger.debug("Inserting default egress firewall rule " + insert_pstmt); + logger.debug("Inserting default egress firewall rule " + insert_pstmt); insert_pstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Unable to set egress firewall rules ", e); @@ -988,7 +986,7 @@ public class Upgrade410to420 implements DbUpgrade { firewallRuleId = rsId.getLong(1); try (PreparedStatement insert_pstmt = conn.prepareStatement("insert into firewall_rules_cidrs (firewall_rule_id,source_cidr) values (?, '0.0.0.0/0')");) { insert_pstmt.setLong(1, firewallRuleId); - s_logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + insert_pstmt); + logger.debug("Inserting rule for cidr 0.0.0.0/0 for the new Firewall rule id=" + firewallRuleId + " with statement " + insert_pstmt); insert_pstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Unable to set egress firewall rules ", e); @@ -1040,7 +1038,7 @@ public class Upgrade410to420 implements DbUpgrade { //For each tier create a network ACL and move all the acl_items to network_acl_item table // If there are no acl_items for a tier, associate it with default ACL - s_logger.debug("Updating network ACLs"); + logger.debug("Updating network ACLs"); //1,2 are default acl Ids, start acl Ids from 3 long nextAclId = 3; @@ -1066,7 +1064,7 @@ public class Upgrade410to420 implements DbUpgrade { //Get all VPC tiers while (rsNetworkIds.next()) { Long networkId = rsNetworkIds.getLong(1); - s_logger.debug("Updating network ACLs for network: " + networkId); + logger.debug("Updating network ACLs for network: " + networkId); Long vpcId = rsNetworkIds.getLong(2); String tierUuid = rsNetworkIds.getString(3); pstmtSelectFirewallRules.setLong(1, networkId); @@ -1079,7 +1077,7 @@ public class Upgrade410to420 implements DbUpgrade { hasAcls = true; aclId = nextAclId++; //create ACL for the tier - s_logger.debug("Creating network ACL for tier: " + tierUuid); + logger.debug("Creating network ACL for tier: " + tierUuid); pstmtInsertNetworkAcl.setLong(1, aclId); pstmtInsertNetworkAcl.setLong(2, vpcId); pstmtInsertNetworkAcl.setString(3, "ACL for tier " + tierUuid); @@ -1107,7 +1105,7 @@ public class Upgrade410to420 implements DbUpgrade { } String aclItemUuid = rsAcls.getString(2); //Move acl to network_acl_item table - s_logger.debug("Moving firewall rule: " + aclItemUuid); + logger.debug("Moving firewall rule: " + aclItemUuid); //uuid pstmtInsertNetworkAclItem.setString(1, aclItemUuid); //aclId @@ -1178,7 +1176,7 @@ public class Upgrade410to420 implements DbUpgrade { pstmtUpdate.setLong(2, networkId); pstmtUpdate.executeUpdate(); } - s_logger.debug("Done updating network ACLs "); + logger.debug("Done updating network ACLs "); } catch (SQLException e) { throw new CloudRuntimeException("Unable to move network acls from firewall rules table to network_acl_item table", e); } @@ -1292,17 +1290,17 @@ public class Upgrade410to420 implements DbUpgrade { } private void addHostDetailsIndex(Connection conn) { - s_logger.debug("Checking if host_details index exists, if not we will add it"); + logger.debug("Checking if host_details index exists, if not we will add it"); try(PreparedStatement pstmt = conn.prepareStatement("SHOW INDEX FROM `cloud`.`host_details` where KEY_NAME = 'fk_host_details__host_id'");) { try(ResultSet rs = pstmt.executeQuery();) { if (rs.next()) { - s_logger.debug("Index already exists on host_details - not adding new one"); + logger.debug("Index already exists on host_details - not adding new one"); } else { // add the index try(PreparedStatement pstmtUpdate = conn.prepareStatement("ALTER TABLE `cloud`.`host_details` ADD INDEX `fk_host_details__host_id` (`host_id`)");) { pstmtUpdate.executeUpdate(); - s_logger.debug("Index did not exist on host_details - added new one"); + logger.debug("Index did not exist on host_details - added new one"); }catch (SQLException e) { throw new CloudRuntimeException("Failed to check/update the host_details index ", e); } @@ -1363,7 +1361,7 @@ public class Upgrade410to420 implements DbUpgrade { } private void fix22xKVMSnapshots(Connection conn) { - s_logger.debug("Updating KVM snapshots"); + logger.debug("Updating KVM snapshots"); try (PreparedStatement pstmt = conn.prepareStatement("select id, backup_snap_id from `cloud`.`snapshots` where hypervisor_type='KVM' and removed is null and backup_snap_id is not null");) { try(ResultSet rs = pstmt.executeQuery();) { @@ -1376,7 +1374,7 @@ public class Upgrade410to420 implements DbUpgrade { int index = backUpPath.indexOf("snapshots" + File.separator); if (index > 1) { String correctedPath = backUpPath.substring(index); - s_logger.debug("Updating Snapshot with id: " + id + " original backup path: " + backUpPath + " updated backup path: " + correctedPath); + logger.debug("Updating Snapshot with id: " + id + " original backup path: " + backUpPath + " updated backup path: " + correctedPath); try(PreparedStatement update_pstmt = conn.prepareStatement("UPDATE `cloud`.`snapshots` set backup_snap_id=? where id = ?");) { update_pstmt.setString(1, correctedPath); update_pstmt.setLong(2, id); @@ -1386,7 +1384,7 @@ public class Upgrade410to420 implements DbUpgrade { } } } - s_logger.debug("Done updating KVM snapshots"); + logger.debug("Done updating KVM snapshots"); }catch (SQLException e) { throw new CloudRuntimeException("Unable to update backup id for KVM snapshots", e); } @@ -1480,7 +1478,7 @@ public class Upgrade410to420 implements DbUpgrade { "INSERT INTO `cloud`.`external_load_balancer_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, is_managed, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; try(PreparedStatement pstmtUpdate = conn.prepareStatement(insertF5);) { - s_logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding F5 Big IP load balancer with host id " + hostId + " in to physical network" + physicalNetworkId); pstmtUpdate.setLong(1, physicalNetworkId); pstmtUpdate.setLong(2, hostId); pstmtUpdate.setString(3, "F5BigIp"); @@ -1502,7 +1500,7 @@ public class Upgrade410to420 implements DbUpgrade { "INSERT INTO `cloud`.`external_firewall_devices` (physical_network_id, host_id, provider_name, " + "device_name, capacity, is_dedicated, device_state, allocation_state, uuid) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)"; try(PreparedStatement pstmtUpdate = conn.prepareStatement(insertSrx);) { - s_logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); + logger.debug("Adding SRX firewall device with host id " + hostId + " in to physical network" + physicalNetworkId); pstmtUpdate.setLong(1, physicalNetworkId); pstmtUpdate.setLong(2, hostId); pstmtUpdate.setString(3, "JuniperSRX"); @@ -1526,7 +1524,7 @@ public class Upgrade410to420 implements DbUpgrade { + "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,0,0,0,0,0,0,0,1,0,0,0,0)"; try(PreparedStatement pstmtUpdate = conn.prepareStatement(insertPNSP);) { // add physical network service provider - F5BigIp - s_logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); + logger.debug("Adding PhysicalNetworkServiceProvider F5BigIp" + " in to physical network" + physicalNetworkId); pstmtUpdate.setString(1, UUID.randomUUID().toString()); pstmtUpdate.setLong(2, physicalNetworkId); pstmtUpdate.setString(3, "F5BigIp"); @@ -1545,7 +1543,7 @@ public class Upgrade410to420 implements DbUpgrade { + "`port_forwarding_service_provided`, `user_data_service_provided`, `security_group_service_provided`) VALUES (?,?,?,?,0,0,0,0,1,1,1,0,1,1,0,0)"; try( PreparedStatement pstmtUpdate = conn.prepareStatement(insertPNSP);) { // add physical network service provider - JuniperSRX - s_logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); + logger.debug("Adding PhysicalNetworkServiceProvider JuniperSRX"); pstmtUpdate.setString(1, UUID.randomUUID().toString()); pstmtUpdate.setLong(2, physicalNetworkId); pstmtUpdate.setString(3, "JuniperSRX"); @@ -1690,7 +1688,7 @@ public class Upgrade410to420 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } - s_logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); + logger.debug("Successfully added entry in network_external_lb_device_map for network " + networkId + " and F5 device ID " + f5DeviceId); // add mapping for the network in network_external_firewall_device_map String insertFwMapping = @@ -1703,7 +1701,7 @@ public class Upgrade410to420 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } - s_logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); + logger.debug("Successfully added entry in network_external_firewall_device_map for network " + networkId + " and SRX device ID " + srxDevivceId); } }catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); @@ -1712,7 +1710,7 @@ public class Upgrade410to420 implements DbUpgrade { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } // update host details for F5 and SRX devices - s_logger.debug("Updating the host details for F5 and SRX devices"); + logger.debug("Updating the host details for F5 and SRX devices"); try(PreparedStatement sel_pstmt = conn.prepareStatement("SELECT host_id, name FROM `cloud`.`host_details` WHERE host_id=? OR host_id=?");) { sel_pstmt.setLong(1, f5HostId); sel_pstmt.setLong(2, srxHostId); @@ -1740,11 +1738,11 @@ public class Upgrade410to420 implements DbUpgrade { }catch (SQLException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } - s_logger.debug("Successfully updated host details for F5 and SRX devices"); + logger.debug("Successfully updated host details for F5 and SRX devices"); } catch (RuntimeException e) { throw new CloudRuntimeException("Unable create a mapping for the networks in network_external_lb_device_map and network_external_firewall_device_map", e); } - s_logger.info("Successfully upgraded network using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); + logger.info("Successfully upgraded network using F5 and SRX devices to have a entry in the network_external_lb_device_map and network_external_firewall_device_map"); } } @@ -1755,7 +1753,7 @@ public class Upgrade410to420 implements DbUpgrade { String sqlInsertStoreDetail = "INSERT INTO `cloud`.`image_store_details` (store_id, name, value) values(?, ?, ?)"; String sqlUpdateHostAsRemoved = "UPDATE `cloud`.`host` SET removed = now() WHERE type = 'SecondaryStorage' and removed is null"; - s_logger.debug("Migrating secondary storage to image store"); + logger.debug("Migrating secondary storage to image store"); boolean hasS3orSwift = false; try ( PreparedStatement pstmtSelectS3Count = conn.prepareStatement(sqlSelectS3Count); @@ -1770,7 +1768,7 @@ public class Upgrade410to420 implements DbUpgrade { ResultSet rsSelectSwiftCount = pstmtSelectSwiftCount.executeQuery(); ResultSet rsNfs = nfsQuery.executeQuery(); ) { - s_logger.debug("Checking if we need to migrate NFS secondary storage to image store or staging store"); + logger.debug("Checking if we need to migrate NFS secondary storage to image store or staging store"); int numRows = 0; if (rsSelectS3Count.next()) { numRows = rsSelectS3Count.getInt(1); @@ -1788,7 +1786,7 @@ public class Upgrade410to420 implements DbUpgrade { store_role = "ImageCache"; } - s_logger.debug("Migrating NFS secondary storage to " + store_role + " store"); + logger.debug("Migrating NFS secondary storage to " + store_role + " store"); // migrate NFS secondary storage, for nfs, keep previous host_id as the store_id while (rsNfs.next()) { @@ -1820,84 +1818,84 @@ public class Upgrade410to420 implements DbUpgrade { storeInsert.executeUpdate(); } - s_logger.debug("Marking NFS secondary storage in host table as removed"); + logger.debug("Marking NFS secondary storage in host table as removed"); pstmtUpdateHostAsRemoved.executeUpdate(); } catch (SQLException e) { String msg = "Unable to migrate secondary storages." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } - s_logger.debug("Completed migrating secondary storage to image store"); + logger.debug("Completed migrating secondary storage to image store"); } // migrate volume_host_ref to volume_store_ref private void migrateVolumeHostRef(Connection conn) { - s_logger.debug("Updating volume_store_ref table from volume_host_ref table"); + logger.debug("Updating volume_store_ref table from volume_host_ref table"); try(PreparedStatement volStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`volume_store_ref` (store_id, volume_id, zone_id, created, last_updated, job_id, download_pct, size, physical_size, download_state, checksum, error_str, local_path, install_path, url, destroyed, update_count, ref_cnt, state) select host_id, volume_id, zone_id, created, last_updated, job_id, download_pct, size, physical_size, download_state, checksum, error_str, local_path, install_path, url, destroyed, 0, 0, 'Allocated' from `cloud`.`volume_host_ref`");) { int rowCount = volStoreInsert.executeUpdate(); - s_logger.debug("Insert modified " + rowCount + " rows"); + logger.debug("Insert modified " + rowCount + " rows"); try(PreparedStatement volStoreUpdate = conn.prepareStatement("update `cloud`.`volume_store_ref` set state = 'Ready' where download_state = 'DOWNLOADED'");) { rowCount = volStoreUpdate.executeUpdate(); - s_logger.debug("Update modified " + rowCount + " rows"); + logger.debug("Update modified " + rowCount + " rows"); }catch (SQLException e) { - s_logger.error("Unable to migrate volume_host_ref." + e.getMessage(),e); + logger.error("Unable to migrate volume_host_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate volume_host_ref." + e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("Unable to migrate volume_host_ref." + e.getMessage(),e); + logger.error("Unable to migrate volume_host_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate volume_host_ref." + e.getMessage(),e); } - s_logger.debug("Completed updating volume_store_ref table from volume_host_ref table"); + logger.debug("Completed updating volume_store_ref table from volume_host_ref table"); } // migrate template_host_ref to template_store_ref private void migrateTemplateHostRef(Connection conn) { - s_logger.debug("Updating template_store_ref table from template_host_ref table"); + logger.debug("Updating template_store_ref table from template_host_ref table"); try (PreparedStatement tmplStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`template_store_ref` (store_id, template_id, created, last_updated, job_id, download_pct, size, physical_size, download_state, error_str, local_path, install_path, url, destroyed, is_copy, update_count, ref_cnt, store_role, state) select host_id, template_id, created, last_updated, job_id, download_pct, size, physical_size, download_state, error_str, local_path, install_path, url, destroyed, is_copy, 0, 0, 'Image', 'Allocated' from `cloud`.`template_host_ref`");) { int rowCount = tmplStoreInsert.executeUpdate(); - s_logger.debug("Insert modified " + rowCount + " rows"); + logger.debug("Insert modified " + rowCount + " rows"); try(PreparedStatement tmplStoreUpdate = conn.prepareStatement("update `cloud`.`template_store_ref` set state = 'Ready' where download_state = 'DOWNLOADED'");) { rowCount = tmplStoreUpdate.executeUpdate(); }catch (SQLException e) { - s_logger.error("Unable to migrate template_host_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_host_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_host_ref." + e.getMessage(), e); } - s_logger.debug("Update modified " + rowCount + " rows"); + logger.debug("Update modified " + rowCount + " rows"); } catch (SQLException e) { - s_logger.error("Unable to migrate template_host_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_host_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_host_ref." + e.getMessage(), e); } - s_logger.debug("Completed updating template_store_ref table from template_host_ref table"); + logger.debug("Completed updating template_store_ref table from template_host_ref table"); } // migrate some entry contents of snapshots to snapshot_store_ref private void migrateSnapshotStoreRef(Connection conn) { - s_logger.debug("Updating snapshot_store_ref table from snapshots table"); + logger.debug("Updating snapshot_store_ref table from snapshots table"); try(PreparedStatement snapshotStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) select sechost_id, id, created, size, prev_snap_id, CONCAT('snapshots', '/', account_id, '/', volume_id, '/', backup_snap_id), volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` where status = 'BackedUp' and hypervisor_type <> 'KVM' and sechost_id is not null and removed is null"); ) { //Update all snapshots except KVM snapshots int rowCount = snapshotStoreInsert.executeUpdate(); - s_logger.debug("Inserted " + rowCount + " snapshots into snapshot_store_ref"); + logger.debug("Inserted " + rowCount + " snapshots into snapshot_store_ref"); //backsnap_id for KVM snapshots is complete path. CONCAT is not required try(PreparedStatement snapshotStoreInsert_2 = conn.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) select sechost_id, id, created, size, prev_snap_id, backup_snap_id, volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` where status = 'BackedUp' and hypervisor_type = 'KVM' and sechost_id is not null and removed is null");) { rowCount = snapshotStoreInsert_2.executeUpdate(); - s_logger.debug("Inserted " + rowCount + " KVM snapshots into snapshot_store_ref"); + logger.debug("Inserted " + rowCount + " KVM snapshots into snapshot_store_ref"); }catch (SQLException e) { - s_logger.error("Unable to migrate snapshot_store_ref." + e.getMessage(),e); + logger.error("Unable to migrate snapshot_store_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate snapshot_store_ref." + e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("Unable to migrate snapshot_store_ref." + e.getMessage(),e); + logger.error("Unable to migrate snapshot_store_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate snapshot_store_ref." + e.getMessage(),e); } - s_logger.debug("Completed updating snapshot_store_ref table from snapshots table"); + logger.debug("Completed updating snapshot_store_ref table from snapshots table"); } // migrate secondary storages S3 from s3 tables to image_store table @@ -1905,7 +1903,7 @@ public class Upgrade410to420 implements DbUpgrade { Long storeId = null; Map s3_store_id_map = new HashMap(); - s_logger.debug("Migrating S3 to image store"); + logger.debug("Migrating S3 to image store"); try ( PreparedStatement storeQuery = conn.prepareStatement("select id from `cloud`.`image_store` where uuid = ?"); PreparedStatement storeDetailInsert = conn.prepareStatement("INSERT INTO `cloud`.`image_store_details` (store_id, name, value) values(?, ?, ?)"); @@ -1976,22 +1974,22 @@ public class Upgrade410to420 implements DbUpgrade { } } catch (SQLException e) { String msg = "Unable to migrate S3 secondary storages." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } - s_logger.debug("Migrating template_s3_ref to template_store_ref"); + logger.debug("Migrating template_s3_ref to template_store_ref"); migrateTemplateS3Ref(conn, s3_store_id_map); - s_logger.debug("Migrating s3 backedup snapshots to snapshot_store_ref"); + logger.debug("Migrating s3 backedup snapshots to snapshot_store_ref"); migrateSnapshotS3Ref(conn, s3_store_id_map); - s_logger.debug("Completed migrating S3 secondary storage to image store"); + logger.debug("Completed migrating S3 secondary storage to image store"); } // migrate template_s3_ref to template_store_ref private void migrateTemplateS3Ref(Connection conn, Map s3StoreMap) { - s_logger.debug("Updating template_store_ref table from template_s3_ref table"); + logger.debug("Updating template_store_ref table from template_s3_ref table"); try(PreparedStatement tmplStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`template_store_ref` (store_id, template_id, created, download_pct, size, physical_size, download_state, local_path, install_path, update_count, ref_cnt, store_role, state) values(?, ?, ?, 100, ?, ?, 'DOWNLOADED', '?', '?', 0, 0, 'Image', 'Ready')"); ) { @@ -2024,23 +2022,23 @@ public class Upgrade410to420 implements DbUpgrade { tmplStoreInsert.executeUpdate(); } }catch (SQLException e) { - s_logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_s3_ref." + e.getMessage(),e); } }catch (SQLException e) { - s_logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_s3_ref." + e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); + logger.error("Unable to migrate template_s3_ref." + e.getMessage(),e); throw new CloudRuntimeException("Unable to migrate template_s3_ref." + e.getMessage(),e); } - s_logger.debug("Completed migrating template_s3_ref table."); + logger.debug("Completed migrating template_s3_ref table."); } // migrate some entry contents of snapshots to snapshot_store_ref private void migrateSnapshotS3Ref(Connection conn, Map s3StoreMap) { - s_logger.debug("Updating snapshot_store_ref table from snapshots table for s3"); + logger.debug("Updating snapshot_store_ref table from snapshots table for s3"); try(PreparedStatement snapshotStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) values(?, ?, ?, ?, ?, ?, ?, 0, 0, 'Image', 'Ready')"); ) { @@ -2074,18 +2072,18 @@ public class Upgrade410to420 implements DbUpgrade { snapshotStoreInsert.executeUpdate(); } }catch (SQLException e) { - s_logger.error("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); } }catch (SQLException e) { - s_logger.error("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotS3Ref:Exception:"+e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("Unable to migrate s3 backedup snapshots to snapshot_store_ref." + e.getMessage()); + logger.error("Unable to migrate s3 backedup snapshots to snapshot_store_ref." + e.getMessage()); throw new CloudRuntimeException("Unable to migrate s3 backedup snapshots to snapshot_store_ref." + e.getMessage(), e); } - s_logger.debug("Completed updating snapshot_store_ref table from s3 snapshots entries"); + logger.debug("Completed updating snapshot_store_ref table from s3 snapshots entries"); } // migrate secondary storages Swift from swift tables to image_store table @@ -2093,7 +2091,7 @@ public class Upgrade410to420 implements DbUpgrade { Long storeId = null; Map swift_store_id_map = new HashMap(); - s_logger.debug("Migrating Swift to image store"); + logger.debug("Migrating Swift to image store"); try ( PreparedStatement storeQuery = conn.prepareStatement("select id from `cloud`.`image_store` where uuid = ?"); PreparedStatement storeDetailInsert = conn.prepareStatement("INSERT INTO `cloud`.`image_store_details` (store_id, name, value) values(?, ?, ?)"); @@ -2146,22 +2144,22 @@ public class Upgrade410to420 implements DbUpgrade { } } catch (SQLException e) { String msg = "Unable to migrate swift secondary storages." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } - s_logger.debug("Migrating template_swift_ref to template_store_ref"); + logger.debug("Migrating template_swift_ref to template_store_ref"); migrateTemplateSwiftRef(conn, swift_store_id_map); - s_logger.debug("Migrating swift backedup snapshots to snapshot_store_ref"); + logger.debug("Migrating swift backedup snapshots to snapshot_store_ref"); migrateSnapshotSwiftRef(conn, swift_store_id_map); - s_logger.debug("Completed migrating Swift secondary storage to image store"); + logger.debug("Completed migrating Swift secondary storage to image store"); } // migrate template_s3_ref to template_store_ref private void migrateTemplateSwiftRef(Connection conn, Map swiftStoreMap) { - s_logger.debug("Updating template_store_ref table from template_swift_ref table"); + logger.debug("Updating template_store_ref table from template_swift_ref table"); try ( PreparedStatement tmplStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`template_store_ref` (store_id, template_id, created, download_pct, size, physical_size, download_state, local_path, install_path, update_count, ref_cnt, store_role, state) values(?, ?, ?, 100, ?, ?, 'DOWNLOADED', '?', '?', 0, 0, 'Image', 'Ready')"); @@ -2195,15 +2193,15 @@ public class Upgrade410to420 implements DbUpgrade { } } catch (SQLException e) { String msg = "Unable to migrate template_swift_ref." + e.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg, e); } - s_logger.debug("Completed migrating template_swift_ref table."); + logger.debug("Completed migrating template_swift_ref table."); } // migrate some entry contents of snapshots to snapshot_store_ref private void migrateSnapshotSwiftRef(Connection conn, Map swiftStoreMap) { - s_logger.debug("Updating snapshot_store_ref table from snapshots table for swift"); + logger.debug("Updating snapshot_store_ref table from snapshots table for swift"); try (PreparedStatement snapshotStoreInsert = conn.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) values(?, ?, ?, ?, ?, ?, ?, 0, 0, 'Image', 'Ready')"); ){ @@ -2229,31 +2227,31 @@ public class Upgrade410to420 implements DbUpgrade { snapshotStoreInsert.executeUpdate(); } }catch (SQLException e) { - s_logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); } }catch (SQLException e) { - s_logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); } } catch (SQLException e) { - s_logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); + logger.error("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); throw new CloudRuntimeException("migrateSnapshotSwiftRef:Exception:"+e.getMessage(),e); } - s_logger.debug("Completed updating snapshot_store_ref table from swift snapshots entries"); + logger.debug("Completed updating snapshot_store_ref table from swift snapshots entries"); } private void fixNiciraKeys(Connection conn) { //First drop the key if it exists. List keys = new ArrayList(); - s_logger.debug("Dropping foreign key fk_nicira_nvp_nic_map__nic from the table nicira_nvp_nic_map if it exists"); + logger.debug("Dropping foreign key fk_nicira_nvp_nic_map__nic from the table nicira_nvp_nic_map if it exists"); keys.add("fk_nicira_nvp_nic_map__nic"); DbUpgradeUtils.dropKeysIfExist(conn, "nicira_nvp_nic_map", keys, true); //Now add foreign key. try(PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`nicira_nvp_nic_map` ADD CONSTRAINT `fk_nicira_nvp_nic_map__nic` FOREIGN KEY (`nic`) REFERENCES `nics` (`uuid`) ON DELETE CASCADE");) { pstmt.executeUpdate(); - s_logger.debug("Added foreign key fk_nicira_nvp_nic_map__nic to the table nicira_nvp_nic_map"); + logger.debug("Added foreign key fk_nicira_nvp_nic_map__nic to the table nicira_nvp_nic_map"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add foreign key fk_nicira_nvp_nic_map__nic to the table nicira_nvp_nic_map", e); } @@ -2262,7 +2260,7 @@ public class Upgrade410to420 implements DbUpgrade { private void fixRouterKeys(Connection conn) { //First drop the key if it exists. List keys = new ArrayList(); - s_logger.debug("Dropping foreign key fk_router_network_ref__router_id from the table router_network_ref if it exists"); + logger.debug("Dropping foreign key fk_router_network_ref__router_id from the table router_network_ref if it exists"); keys.add("fk_router_network_ref__router_id"); DbUpgradeUtils.dropKeysIfExist(conn, "router_network_ref", keys, true); //Now add foreign key. @@ -2270,14 +2268,14 @@ public class Upgrade410to420 implements DbUpgrade { conn.prepareStatement("ALTER TABLE `cloud`.`router_network_ref` ADD CONSTRAINT `fk_router_network_ref__router_id` FOREIGN KEY (`router_id`) REFERENCES `domain_router` (`id`) ON DELETE CASCADE");) { pstmt.executeUpdate(); - s_logger.debug("Added foreign key fk_router_network_ref__router_id to the table router_network_ref"); + logger.debug("Added foreign key fk_router_network_ref__router_id to the table router_network_ref"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to add foreign key fk_router_network_ref__router_id to the table router_network_ref", e); } } private void encryptSite2SitePSK(Connection conn) { - s_logger.debug("Encrypting Site2Site Customer Gateway pre-shared key"); + logger.debug("Encrypting Site2Site Customer Gateway pre-shared key"); try (PreparedStatement select_pstmt = conn.prepareStatement("select id, ipsec_psk from `cloud`.`s2s_customer_gateway`");){ try(ResultSet rs = select_pstmt.executeQuery();) { @@ -2304,7 +2302,7 @@ public class Upgrade410to420 implements DbUpgrade { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable to encrypt Site2Site Customer Gateway pre-shared key ", e); } - s_logger.debug("Done encrypting Site2Site Customer Gateway pre-shared key"); + logger.debug("Done encrypting Site2Site Customer Gateway pre-shared key"); } protected void updateConcurrentConnectionsInNetworkOfferings(Connection conn) { @@ -2388,31 +2386,31 @@ public class Upgrade410to420 implements DbUpgrade { conn.prepareStatement("ALTER TABLE `cloud`.`volumes` CHANGE COLUMN `iso_id1` `iso_id` bigint(20) unsigned COMMENT 'The id of the iso from which the volume was created'");) { alter_iso_pstmt.executeUpdate(); }catch (SQLException e) { - s_logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); - if (s_logger.isTraceEnabled()) { - s_logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); + logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); + if (logger.isTraceEnabled()) { + logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); } //implies iso_id1 is not present, so do nothing. } }catch (SQLException e) { - s_logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); - if (s_logger.isTraceEnabled()) { - s_logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); + logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); + if (logger.isTraceEnabled()) { + logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); } //implies iso_id1 is not present, so do nothing. } } }catch (SQLException e) { - s_logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); - if (s_logger.isTraceEnabled()) { - s_logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); + logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); + if (logger.isTraceEnabled()) { + logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); } //implies iso_id1 is not present, so do nothing. } } catch (SQLException e) { - s_logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); - if (s_logger.isTraceEnabled()) { - s_logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); + logger.info("migrateDatafromIsoIdInVolumesTable: ignoring Exception: " + e.getMessage()); + if (logger.isTraceEnabled()) { + logger.trace("migrateDatafromIsoIdInVolumesTable: ignored Exception",e); } //implies iso_id1 is not present, so do nothing. } @@ -2421,7 +2419,7 @@ public class Upgrade410to420 implements DbUpgrade { protected void setRAWformatForRBDVolumes(Connection conn) { try(PreparedStatement pstmt = conn.prepareStatement("UPDATE volumes SET format = 'RAW' WHERE pool_id IN(SELECT id FROM storage_pool WHERE pool_type = 'RBD')");) { - s_logger.debug("Setting format to RAW for all volumes on RBD primary storage pools"); + logger.debug("Setting format to RAW for all volumes on RBD primary storage pools"); pstmt.executeUpdate(); } catch (SQLException e) { throw new CloudRuntimeException("Failed to update volume format to RAW for volumes on RBD pools due to exception ", e); @@ -2429,7 +2427,7 @@ public class Upgrade410to420 implements DbUpgrade { } private void upgradeVpcServiceMap(Connection conn) { - s_logger.debug("Upgrading VPC service Map"); + logger.debug("Upgrading VPC service Map"); try(PreparedStatement listVpc = conn.prepareStatement("SELECT id, vpc_offering_id FROM `cloud`.`vpc` where removed is NULL");) { //Get all vpc Ids along with vpc offering Id @@ -2461,7 +2459,7 @@ public class Upgrade410to420 implements DbUpgrade { }catch (SQLException e) { throw new CloudRuntimeException("Error during VPC service map upgrade", e); } - s_logger.debug("Upgraded service map for VPC: " + vpc_id); + logger.debug("Upgraded service map for VPC: " + vpc_id); } } } catch (SQLException e) { @@ -2470,7 +2468,7 @@ public class Upgrade410to420 implements DbUpgrade { } private void upgradeResourceCount(Connection conn) { - s_logger.debug("upgradeResourceCount start"); + logger.debug("upgradeResourceCount start"); try( PreparedStatement sel_dom_pstmt = conn.prepareStatement("select id, domain_id FROM `cloud`.`account` where removed is NULL "); ResultSet rsAccount = sel_dom_pstmt.executeQuery(); @@ -2599,7 +2597,7 @@ public class Upgrade410to420 implements DbUpgrade { throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage) ", e); } } - s_logger.debug("upgradeResourceCount finish"); + logger.debug("upgradeResourceCount finish"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage) ", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41100to41110.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41100to41110.java index 3703040771b..1df197b4fcf 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41100to41110.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41100to41110.java @@ -25,13 +25,11 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41100to41110 implements DbUpgrade { - final static Logger LOG = Logger.getLogger(Upgrade41000to41100.class); +public class Upgrade41100to41110 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -105,8 +103,8 @@ public class Upgrade41100to41110 implements DbUpgrade { try ( ResultSet resultSet = prepSelStmt.executeQuery(); ) { - if (LOG.isInfoEnabled()) { - LOG.info("updating setting '" + name + "'"); + if (logger.isInfoEnabled()) { + logger.info("updating setting '" + name + "'"); } if (resultSet.next()) { if ("Secure".equals(resultSet.getString(1))) { @@ -118,10 +116,10 @@ public class Upgrade41100to41110 implements DbUpgrade { prepUpdStmt.setString(2, name); prepUpdStmt.execute(); } catch (SQLException e) { - if (LOG.isInfoEnabled()) { - LOG.info("failed to update configuration item '" + name + "' with value '" + value + "'"); - if (LOG.isDebugEnabled()) { - LOG.debug("no update because ", e); + if (logger.isInfoEnabled()) { + logger.info("failed to update configuration item '" + name + "' with value '" + value + "'"); + if (logger.isDebugEnabled()) { + logger.debug("no update because ", e); } } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41110to41120.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41110to41120.java index f7782cebf46..85be41fc6f2 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41110to41120.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41110to41120.java @@ -20,12 +20,10 @@ package com.cloud.upgrade.dao; import java.io.InputStream; import java.sql.Connection; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41110to41120 implements DbUpgrade { - final static Logger LOG = Logger.getLogger(Upgrade41110to41120.class); +public class Upgrade41110to41120 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41130.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41130.java index d9eec476628..d011f4fb0fc 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41130.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41130.java @@ -20,7 +20,7 @@ package com.cloud.upgrade.dao; import java.io.InputStream; import java.sql.Connection; -public class Upgrade41120to41130 implements DbUpgrade { +public class Upgrade41120to41130 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41200.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41200.java index f68f04a53aa..ce0e1e39c2e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41200.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41120to41200.java @@ -23,11 +23,9 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; -public class Upgrade41120to41200 implements DbUpgrade { +public class Upgrade41120to41200 extends DbUpgradeAbstractImpl { - final static Logger LOG = Logger.getLogger(Upgrade41120to41200.class); @Override public String[] getUpgradableVersionRange() { @@ -64,7 +62,7 @@ public class Upgrade41120to41200 implements DbUpgrade { try (final PreparedStatement updateStatement = conn.prepareStatement("UPDATE cloud.mshost SET uuid=UUID()")) { updateStatement.executeUpdate(); } catch (SQLException e) { - LOG.error("Failed to add an UUID to each management server.", e); + logger.error("Failed to add an UUID to each management server.", e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41200to41300.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41200to41300.java index 2de8dc98358..dd6f2cf3036 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41200to41300.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41200to41300.java @@ -22,7 +22,7 @@ import java.sql.Connection; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41200to41300 implements DbUpgrade { +public class Upgrade41200to41300 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41300to41310.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41300to41310.java index ac6149f7844..4cae3d445c7 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41300to41310.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41300to41310.java @@ -19,7 +19,7 @@ package com.cloud.upgrade.dao; import java.io.InputStream; import java.sql.Connection; -public class Upgrade41300to41310 implements DbUpgrade { +public class Upgrade41300to41310 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { return new String[] {"4.13.0.0", "4.13.1.0"}; diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41310to41400.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41310to41400.java index f1a333e7d48..91fd5b6d57f 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41310to41400.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41310to41400.java @@ -20,13 +20,11 @@ package com.cloud.upgrade.dao; import java.io.InputStream; import java.sql.Connection; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41310to41400 implements DbUpgrade { +public class Upgrade41310to41400 extends DbUpgradeAbstractImpl { - final static Logger LOG = Logger.getLogger(Upgrade41310to41400.class); @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java index ba969ae879e..4750915baa6 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41400to41500.java @@ -27,13 +27,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41400to41500 implements DbUpgrade { - - final static Logger LOG = Logger.getLogger(Upgrade41400to41500.class); +public class Upgrade41400to41500 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -74,7 +71,7 @@ public class Upgrade41400to41500 implements DbUpgrade { } private void addRolePermissionsForReadOnlyAdmin(final Connection conn) { - LOG.debug("Adding role permissions for new read-only admin role"); + logger.debug("Adding role permissions for new read-only admin role"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only Admin - Default' AND is_default = 1"); ResultSet rs = pstmt.executeQuery(); @@ -108,15 +105,15 @@ public class Upgrade41400to41500 implements DbUpgrade { if (pstmt != null && !pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully added role permissions for new read-only admin role"); + logger.debug("Successfully added role permissions for new read-only admin role"); } catch (final SQLException e) { - LOG.error("Exception while adding role permissions for read-only admin role: " + e.getMessage()); + logger.error("Exception while adding role permissions for read-only admin role: " + e.getMessage()); throw new CloudRuntimeException("Exception while adding role permissions for read-only admin role: " + e.getMessage(), e); } } private void addRolePermissionsForReadOnlyUser(final Connection conn) { - LOG.debug("Adding role permissions for new read-only user role"); + logger.debug("Adding role permissions for new read-only user role"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Read-Only User - Default' AND is_default = 1"); ResultSet rs = pstmt.executeQuery(); @@ -179,15 +176,15 @@ public class Upgrade41400to41500 implements DbUpgrade { if (pstmt != null && !pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully added role permissions for new read-only user role"); + logger.debug("Successfully added role permissions for new read-only user role"); } catch (final SQLException e) { - LOG.error("Exception while adding role permissions for read-only user role: " + e.getMessage()); + logger.error("Exception while adding role permissions for read-only user role: " + e.getMessage()); throw new CloudRuntimeException("Exception while adding role permissions for read-only user role: " + e.getMessage(), e); } } private void addRolePermissionsForSupportAdmin(final Connection conn) { - LOG.debug("Adding role permissions for new support admin role"); + logger.debug("Adding role permissions for new support admin role"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Support Admin - Default' AND is_default = 1"); ResultSet rs = pstmt.executeQuery(); @@ -264,15 +261,15 @@ public class Upgrade41400to41500 implements DbUpgrade { if (pstmt != null && !pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully added role permissions for new support admin role"); + logger.debug("Successfully added role permissions for new support admin role"); } catch (final SQLException e) { - LOG.error("Exception while adding role permissions for support admin role: " + e.getMessage()); + logger.error("Exception while adding role permissions for support admin role: " + e.getMessage()); throw new CloudRuntimeException("Exception while adding role permissions for support admin role: " + e.getMessage(), e); } } private void addRolePermissionsForSupportUser(final Connection conn) { - LOG.debug("Adding role permissions for new support user role"); + logger.debug("Adding role permissions for new support user role"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`roles` WHERE name = 'Support User - Default' AND is_default = 1"); ResultSet rs = pstmt.executeQuery(); @@ -341,9 +338,9 @@ public class Upgrade41400to41500 implements DbUpgrade { if (pstmt != null && !pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully added role permissions for new support user role"); + logger.debug("Successfully added role permissions for new support user role"); } catch (final SQLException e) { - LOG.error("Exception while adding role permissions for support user role: " + e.getMessage()); + logger.error("Exception while adding role permissions for support user role: " + e.getMessage()); throw new CloudRuntimeException("Exception while adding role permissions for support user role: " + e.getMessage(), e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41500to41510.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41500to41510.java index 344bbccc95b..a6b77813fa1 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41500to41510.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41500to41510.java @@ -27,14 +27,18 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.apache.log4j.Logger; import com.cloud.hypervisor.Hypervisor; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate { +import static com.cloud.hypervisor.Hypervisor.HypervisorType.Hyperv; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.KVM; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.LXC; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.Ovm3; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.VMware; +import static com.cloud.hypervisor.Hypervisor.HypervisorType.XenServer; - final static Logger LOG = Logger.getLogger(Upgrade41500to41510.class); +public class Upgrade41500to41510 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { @Override public String[] getUpgradableVersionRange() { @@ -70,84 +74,76 @@ public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate @Override @SuppressWarnings("serial") public void updateSystemVmTemplates(final Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); final Set hypervisorsListInUse = new HashSet(); try (PreparedStatement pstmt = conn.prepareStatement("select distinct(hypervisor_type) from `cloud`.`cluster` where removed is null"); ResultSet rs = pstmt.executeQuery()) { while (rs.next()) { - switch (Hypervisor.HypervisorType.getType(rs.getString(1))) { - case XenServer: - hypervisorsListInUse.add(Hypervisor.HypervisorType.XenServer); - break; - case KVM: - hypervisorsListInUse.add(Hypervisor.HypervisorType.KVM); - break; - case VMware: - hypervisorsListInUse.add(Hypervisor.HypervisorType.VMware); - break; - case Hyperv: - hypervisorsListInUse.add(Hypervisor.HypervisorType.Hyperv); - break; - case LXC: - hypervisorsListInUse.add(Hypervisor.HypervisorType.LXC); - break; - case Ovm3: - hypervisorsListInUse.add(Hypervisor.HypervisorType.Ovm3); - break; - default: - break; + Hypervisor.HypervisorType type = Hypervisor.HypervisorType.getType(rs.getString(1)); + if (type.equals(XenServer)) { + hypervisorsListInUse.add(XenServer); + } else if (type.equals(KVM)) { + hypervisorsListInUse.add(KVM); + } else if (type.equals(VMware)) { + hypervisorsListInUse.add(VMware); + } else if (type.equals(Hyperv)) { + hypervisorsListInUse.add(Hyperv); + } else if (type.equals(LXC)) { + hypervisorsListInUse.add(LXC); + } else if (type.equals(Ovm3)) { + hypervisorsListInUse.add(Ovm3); } } } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates: Exception caught while getting hypervisor types from clusters: " + e.getMessage()); + logger.error("updateSystemVmTemplates: Exception caught while getting hypervisor types from clusters: " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting hypervisor types from clusters", e); } final Map NewTemplateNameList = new HashMap() { { - put(Hypervisor.HypervisorType.KVM, "systemvm-kvm-4.15.1"); - put(Hypervisor.HypervisorType.VMware, "systemvm-vmware-4.15.1"); - put(Hypervisor.HypervisorType.XenServer, "systemvm-xenserver-4.15.1"); - put(Hypervisor.HypervisorType.Hyperv, "systemvm-hyperv-4.15.1"); - put(Hypervisor.HypervisorType.LXC, "systemvm-lxc-4.15.1"); - put(Hypervisor.HypervisorType.Ovm3, "systemvm-ovm3-4.15.1"); + put(KVM, "systemvm-kvm-4.15.1"); + put(VMware, "systemvm-vmware-4.15.1"); + put(XenServer, "systemvm-xenserver-4.15.1"); + put(Hyperv, "systemvm-hyperv-4.15.1"); + put(LXC, "systemvm-lxc-4.15.1"); + put(Ovm3, "systemvm-ovm3-4.15.1"); } }; final Map routerTemplateConfigurationNames = new HashMap() { { - put(Hypervisor.HypervisorType.KVM, "router.template.kvm"); - put(Hypervisor.HypervisorType.VMware, "router.template.vmware"); - put(Hypervisor.HypervisorType.XenServer, "router.template.xenserver"); - put(Hypervisor.HypervisorType.Hyperv, "router.template.hyperv"); - put(Hypervisor.HypervisorType.LXC, "router.template.lxc"); - put(Hypervisor.HypervisorType.Ovm3, "router.template.ovm3"); + put(KVM, "router.template.kvm"); + put(VMware, "router.template.vmware"); + put(XenServer, "router.template.xenserver"); + put(Hyperv, "router.template.hyperv"); + put(LXC, "router.template.lxc"); + put(Ovm3, "router.template.ovm3"); } }; final Map newTemplateUrl = new HashMap() { { - put(Hypervisor.HypervisorType.KVM, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); - put(Hypervisor.HypervisorType.VMware, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-vmware.ova"); - put(Hypervisor.HypervisorType.XenServer, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-xen.vhd.bz2"); - put(Hypervisor.HypervisorType.Hyperv, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-hyperv.vhd.zip"); - put(Hypervisor.HypervisorType.LXC, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); - put(Hypervisor.HypervisorType.Ovm3, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-ovm.raw.bz2"); + put(KVM, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); + put(VMware, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-vmware.ova"); + put(XenServer, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-xen.vhd.bz2"); + put(Hyperv, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-hyperv.vhd.zip"); + put(LXC, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-kvm.qcow2.bz2"); + put(Ovm3, "https://download.cloudstack.org/systemvm/4.15/systemvmtemplate-4.15.1-ovm.raw.bz2"); } }; final Map newTemplateChecksum = new HashMap() { { - put(Hypervisor.HypervisorType.KVM, "0e9f9a7d0957c3e0a2088e41b2da2cec"); - put(Hypervisor.HypervisorType.XenServer, "86373992740b1eca8aff8b08ebf3aea5"); - put(Hypervisor.HypervisorType.VMware, "4006982765846d373eb3719b2fe4d720"); - put(Hypervisor.HypervisorType.Hyperv, "0b9514e4b6cba1f636fea2125f0f7a5f"); - put(Hypervisor.HypervisorType.LXC, "0e9f9a7d0957c3e0a2088e41b2da2cec"); - put(Hypervisor.HypervisorType.Ovm3, "ae3977e696b3e6c81bdcbb792d514d29"); + put(KVM, "0e9f9a7d0957c3e0a2088e41b2da2cec"); + put(XenServer, "86373992740b1eca8aff8b08ebf3aea5"); + put(VMware, "4006982765846d373eb3719b2fe4d720"); + put(Hyperv, "0b9514e4b6cba1f636fea2125f0f7a5f"); + put(LXC, "0e9f9a7d0957c3e0a2088e41b2da2cec"); + put(Ovm3, "ae3977e696b3e6c81bdcbb792d514d29"); } }; for (final Map.Entry hypervisorAndTemplateName : NewTemplateNameList.entrySet()) { - LOG.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); + logger.debug("Updating " + hypervisorAndTemplateName.getKey() + " System Vms"); try (PreparedStatement pstmt = conn.prepareStatement("select id from `cloud`.`vm_template` where name = ? and removed is null and account_id in (select id from account where type = 1 and removed is NULL) order by id desc limit 1")) { // Get systemvm template id for corresponding hypervisor long templateId = -1; @@ -157,7 +153,7 @@ public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate templateId = rs.getLong(1); } } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates: Exception caught while getting ids of templates: " + e.getMessage()); + logger.error("updateSystemVmTemplates: Exception caught while getting ids of templates: " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates: Exception caught while getting ids of templates", e); } @@ -167,7 +163,7 @@ public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate templ_type_pstmt.setLong(1, templateId); templ_type_pstmt.executeUpdate(); } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage()); + logger.error("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system': " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating template with id " + templateId + " to be marked as 'system'", e); } // update template ID of system Vms @@ -177,7 +173,7 @@ public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate update_templ_id_pstmt.setString(2, hypervisorAndTemplateName.getKey().toString()); update_templ_id_pstmt.executeUpdate(); } catch (final Exception e) { - LOG.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId + logger.error("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId + ": " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting template for " + hypervisorAndTemplateName.getKey().toString() + " to " + templateId, e); @@ -190,7 +186,7 @@ public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate update_pstmt.setString(2, routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey())); update_pstmt.executeUpdate(); } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + logger.error("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue() + ": " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting " + routerTemplateConfigurationNames.get(hypervisorAndTemplateName.getKey()) + " to " + hypervisorAndTemplateName.getValue(), e); @@ -203,14 +199,14 @@ public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate update_pstmt.setString(2, "minreq.sysvmtemplate.version"); update_pstmt.executeUpdate(); } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.1: " + e.getMessage()); + logger.error("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.1: " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while setting 'minreq.sysvmtemplate.version' to 4.15.1", e); } } else { if (hypervisorsListInUse.contains(hypervisorAndTemplateName.getKey())) { throw new CloudRuntimeException(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. Cannot upgrade system Vms"); } else { - LOG.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + logger.warn(getUpgradedVersion() + hypervisorAndTemplateName.getKey() + " SystemVm template not found. " + hypervisorAndTemplateName.getKey() + " hypervisor is not used, so not failing upgrade"); // Update the latest template URLs for corresponding // hypervisor @@ -221,7 +217,7 @@ public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate update_templ_url_pstmt.setString(3, hypervisorAndTemplateName.getKey().toString()); update_templ_url_pstmt.executeUpdate(); } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + logger.error("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + hypervisorAndTemplateName.getKey().toString() + ": " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type " + hypervisorAndTemplateName.getKey().toString(), e); @@ -229,11 +225,11 @@ public class Upgrade41500to41510 implements DbUpgrade, DbUpgradeSystemVmTemplate } } } catch (final SQLException e) { - LOG.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage()); + logger.error("updateSystemVmTemplates:Exception while getting ids of templates: " + e.getMessage()); throw new CloudRuntimeException("updateSystemVmTemplates:Exception while getting ids of templates", e); } } - LOG.debug("Updating System Vm Template IDs Complete"); + logger.debug("Updating System Vm Template IDs Complete"); } @Override diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41520.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41520.java index bf91c8f7ace..41b362c4bf7 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41520.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41510to41520.java @@ -21,11 +21,8 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -import org.apache.log4j.Logger; -public class Upgrade41510to41520 implements DbUpgrade { - - final static Logger LOG = Logger.getLogger(Upgrade41510to41520.class); +public class Upgrade41510to41520 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java index 107742076fd..76227d43417 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41520to41600.java @@ -28,14 +28,12 @@ import java.util.List; import com.cloud.upgrade.RolePermissionChecker; import com.cloud.upgrade.SystemVmTemplateRegistration; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41520to41600 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41520to41600 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41520to41600.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; private RolePermissionChecker rolePermissionChecker = new RolePermissionChecker(); @@ -82,21 +80,21 @@ public class Upgrade41520to41600 implements DbUpgrade, DbUpgradeSystemVmTemplate } private void checkAndPersistAnnotationPermissions(Connection conn, RoleType roleType, List rules) { - LOG.debug("Checking the annotation permissions for the role: " + roleType.getId()); + logger.debug("Checking the annotation permissions for the role: " + roleType.getId()); for (String rule : rules) { - LOG.debug("Checking the annotation permissions for the role: " + roleType.getId() + " and rule: " + rule); + logger.debug("Checking the annotation permissions for the role: " + roleType.getId() + " and rule: " + rule); if (!rolePermissionChecker.existsRolePermissionByRoleIdAndRule(conn, roleType.getId(), rule)) { - LOG.debug("Inserting role permission for role: " + roleType.getId() + " and rule: " + rule); + logger.debug("Inserting role permission for role: " + roleType.getId() + " and rule: " + rule); rolePermissionChecker.insertAnnotationRulePermission(conn, roleType.getId(), rule); } else { - LOG.debug("Found existing role permission for role: " + roleType.getId() + " and rule: " + rule + + logger.debug("Found existing role permission for role: " + roleType.getId() + " and rule: " + rule + ", not updating it"); } } } private void generateUuidForExistingSshKeyPairs(Connection conn) { - LOG.debug("Generating uuid for existing ssh key-pairs"); + logger.debug("Generating uuid for existing ssh key-pairs"); try { PreparedStatement pstmt = conn.prepareStatement("SELECT id FROM `cloud`.`ssh_keypairs` WHERE uuid is null"); ResultSet rs = pstmt.executeQuery(); @@ -112,10 +110,10 @@ public class Upgrade41520to41600 implements DbUpgrade, DbUpgradeSystemVmTemplate if (!pstmt.isClosed()) { pstmt.close(); } - LOG.debug("Successfully generated uuid for existing ssh key-pairs"); + logger.debug("Successfully generated uuid for existing ssh key-pairs"); } catch (SQLException e) { String errMsg = "Exception while generating uuid for existing ssh key-pairs: " + e.getMessage(); - LOG.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg, e); } } @@ -127,7 +125,7 @@ public class Upgrade41520to41600 implements DbUpgrade, DbUpgradeSystemVmTemplate @Override @SuppressWarnings("serial") public void updateSystemVmTemplates(final Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41600to41610.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41600to41610.java index 8094a2e9a3c..3208b4ad8f9 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41600to41610.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41600to41610.java @@ -19,14 +19,12 @@ package com.cloud.upgrade.dao; import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; -public class Upgrade41600to41610 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41600to41610 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41600to41610.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; @Override @@ -77,7 +75,7 @@ public class Upgrade41600to41610 implements DbUpgrade, DbUpgradeSystemVmTemplate @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java index bb4e70567c6..0a0ab0b9f5a 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41610to41700.java @@ -24,14 +24,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; -import org.apache.log4j.Logger; import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41610to41700 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41610to41700 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41700to41710.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; @Override @@ -82,7 +80,7 @@ public class Upgrade41610to41700 implements DbUpgrade, DbUpgradeSystemVmTemplate @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); @@ -92,7 +90,7 @@ public class Upgrade41610to41700 implements DbUpgrade, DbUpgradeSystemVmTemplate } public void fixWrongDatastoreClusterPoolUuid(Connection conn) { - LOG.debug("Replacement of faulty pool uuids on datastorecluster"); + logger.debug("Replacement of faulty pool uuids on datastorecluster"); try (PreparedStatement pstmt = conn.prepareStatement("SELECT id,uuid FROM storage_pool " + "WHERE uuid NOT LIKE \"%-%-%-%\" AND removed IS NULL " + "AND pool_type = 'DatastoreCluster';"); ResultSet rs = pstmt.executeQuery()) { @@ -109,7 +107,7 @@ public class Upgrade41610to41700 implements DbUpgrade, DbUpgradeSystemVmTemplate updateStmt.executeBatch(); } catch (SQLException ex) { String errorMsg = "fixWrongPoolUuid:Exception while updating faulty pool uuids"; - LOG.error(errorMsg,ex); + logger.error(errorMsg,ex); throw new CloudRuntimeException(errorMsg, ex); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41700to41710.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41700to41710.java index a228a01b9e8..e3eb2bf514d 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41700to41710.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41700to41710.java @@ -23,7 +23,6 @@ import java.util.List; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.VolumeVO; @@ -32,9 +31,8 @@ import com.cloud.storage.dao.VolumeDaoImpl; import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade41700to41710 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41700to41710 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41700to41710.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; private PrimaryDataStoreDao storageDao; @@ -88,7 +86,7 @@ public class Upgrade41700to41710 implements DbUpgrade, DbUpgradeSystemVmTemplate @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41710to41720.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41710to41720.java index 91b7cfe978d..9854268c1ff 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41710to41720.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41710to41720.java @@ -18,14 +18,12 @@ package com.cloud.upgrade.dao; import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; -public class Upgrade41710to41720 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41710to41720 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41710to41720.class); private SystemVmTemplateRegistration systemVmTemplateRegistration; @@ -64,7 +62,7 @@ public class Upgrade41710to41720 implements DbUpgrade, DbUpgradeSystemVmTemplate @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41720to41800.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41720to41800.java index 77fffb17ddd..6a90396deb0 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41720to41800.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41720to41800.java @@ -25,7 +25,6 @@ import org.apache.cloudstack.api.response.UsageTypeResponse; import org.apache.cloudstack.usage.UsageTypes; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.lang3.time.DateUtils; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; @@ -39,9 +38,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate { +public class Upgrade41720to41800 extends DbUpgradeAbstractImpl implements DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41720to41800.class); private GuestOsMapper guestOsMapper = new GuestOsMapper(); @@ -101,7 +99,7 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); @@ -111,7 +109,7 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate } protected void convertQuotaTariffsToNewParadigm(Connection conn) { - LOG.info("Converting quota tariffs to new paradigm."); + logger.info("Converting quota tariffs to new paradigm."); List usageTypeResponses = UsageTypes.listUsageTypes(); @@ -120,14 +118,14 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate String tariffTypeDescription = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(usageTypeResponse, "description", "usageType"); - LOG.info(String.format("Converting quota tariffs of type %s to new paradigm.", tariffTypeDescription)); + logger.info(String.format("Converting quota tariffs of type %s to new paradigm.", tariffTypeDescription)); for (boolean previousTariff : Arrays.asList(true, false)) { Map tariffs = selectTariffs(conn, usageType, previousTariff, tariffTypeDescription); int tariffsSize = tariffs.size(); if (tariffsSize < 2) { - LOG.info(String.format("Quota tariff of type %s has [%s] %s register(s). Tariffs with less than 2 register do not need to be converted to new paradigm.", + logger.info(String.format("Quota tariff of type %s has [%s] %s register(s). Tariffs with less than 2 register do not need to be converted to new paradigm.", tariffTypeDescription, tariffsSize, previousTariff ? "previous of current" : "next to current")); continue; } @@ -143,7 +141,7 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate String selectQuotaTariffs = String.format("SELECT id, effective_on FROM cloud_usage.quota_tariff WHERE %s AND usage_type = ? ORDER BY effective_on, updated_on;", previousTariff ? "usage_name = name" : "removed is null"); - LOG.info(String.format("Selecting %s quota tariffs of type [%s] according to SQL [%s].", previousTariff ? "previous of current" : "next to current", + logger.info(String.format("Selecting %s quota tariffs of type [%s] according to SQL [%s].", previousTariff ? "previous of current" : "next to current", tariffTypeDescription, selectQuotaTariffs)); try (PreparedStatement pstmt = conn.prepareStatement(selectQuotaTariffs)) { @@ -158,7 +156,7 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate } catch (SQLException e) { String message = String.format("Unable to retrieve %s quota tariffs of type [%s] due to [%s].", previousTariff ? "previous" : "next", tariffTypeDescription, e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -168,7 +166,7 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate Object[] ids = tariffs.keySet().toArray(); - LOG.info(String.format("Updating %s registers of %s quota tariffs of type [%s] with SQL [%s].", tariffs.size() - 1, setRemoved ? "previous of current" : + logger.info(String.format("Updating %s registers of %s quota tariffs of type [%s] with SQL [%s].", tariffs.size() - 1, setRemoved ? "previous of current" : "next to current", tariffTypeDescription, updateQuotaTariff)); for (int i = 0; i < tariffs.size() - 1; i++) { @@ -195,19 +193,19 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate pstmt.setLong(2, id); } - LOG.info(String.format("Updating \"end_date\" to [%s] %sof quota tariff with ID [%s].", sqlEndDate, updateRemoved, id)); + logger.info(String.format("Updating \"end_date\" to [%s] %sof quota tariff with ID [%s].", sqlEndDate, updateRemoved, id)); pstmt.executeUpdate(); } catch (SQLException e) { String message = String.format("Unable to update \"end_date\" %s of quota tariffs of usage type [%s] due to [%s].", setRemoved ? "and \"removed\"" : "", usageType, e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } } protected void convertVmResourcesQuotaTypesToRunningVmQuotaType(Connection conn) { - LOG.info("Converting quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\" to \"RUNNING_VM\"."); + logger.info("Converting quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\" to \"RUNNING_VM\"."); String insertSql = "INSERT INTO cloud_usage.quota_tariff (usage_type, usage_name, usage_unit, usage_discriminator, currency_value, effective_on, updated_on," + " updated_by, uuid, name, description, removed, end_date, activation_rule)\n" @@ -225,11 +223,11 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate pstmt.executeUpdate(); } catch (SQLException e) { String message = String.format("Failed to convert quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\" to \"RUNNING_VM\" due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } - LOG.info("Disabling unused quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\"."); + logger.info("Disabling unused quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\"."); String updateSql = "UPDATE cloud_usage.quota_tariff SET removed = now() WHERE usage_type in (15, 16, 17) and removed is null;"; @@ -237,7 +235,7 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate pstmt.executeUpdate(); } catch (SQLException e) { String message = String.format("Failed disable quota tariffs of type \"vCPU\", \"CPU_SPEED\" and \"MEMORY\" due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -251,7 +249,7 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate } private void updateGuestOsMappings() { - LOG.debug("Updating guest OS mappings"); + logger.debug("Updating guest OS mappings"); // Add support for SUSE Linux Enterprise Desktop 12 SP3 (64-bit) for Xenserver 8.1.0 List mappings = new ArrayList(); @@ -708,7 +706,7 @@ public class Upgrade41720to41800 implements DbUpgrade, DbUpgradeSystemVmTemplate } private void correctGuestOsIdsInHypervisorMapping(final Connection conn) { - LOG.debug("Correcting guest OS ids in hypervisor mappings"); + logger.debug("Correcting guest OS ids in hypervisor mappings"); guestOsMapper.updateGuestOsIdInHypervisorMapping(conn, 10, "Ubuntu 20.04 LTS", new GuestOSHypervisorMapping("Xenserver", "8.2.0", "Ubuntu Focal Fossa 20.04")); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41800to41810.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41800to41810.java index a58d9965259..b8d2e618068 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41800to41810.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41800to41810.java @@ -22,7 +22,6 @@ import com.cloud.upgrade.GuestOsMapper; import com.cloud.storage.GuestOSVO; import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; @@ -30,8 +29,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; -public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41800to41810.class); +public class Upgrade41800to41810 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { private GuestOsMapper guestOsMapper = new GuestOsMapper(); private SystemVmTemplateRegistration systemVmTemplateRegistration; @@ -96,7 +94,7 @@ public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); @@ -106,12 +104,12 @@ public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate } private void updateGuestOsMappings(Connection conn) { - LOG.debug("Updating guest OS mappings"); + logger.debug("Updating guest OS mappings"); GuestOsMapper guestOsMapper = new GuestOsMapper(); List mappings = new ArrayList<>(); - LOG.debug("Adding Ubuntu 20.04 support for VMware 6.5+"); + logger.debug("Adding Ubuntu 20.04 support for VMware 6.5+"); guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "6.5", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "6.7", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "6.7.1", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); @@ -123,7 +121,7 @@ public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "7.0.3.0", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); guestOsMapper.addGuestOsHypervisorMapping(new GuestOSHypervisorMapping("VMware", "8.0", "ubuntu64Guest"), 10, "Ubuntu 20.04 LTS"); - LOG.debug("Adding Ubuntu 22.04 support for KVM and VMware 6.5+"); + logger.debug("Adding Ubuntu 22.04 support for KVM and VMware 6.5+"); mappings.add(new GuestOSHypervisorMapping("KVM", "default", "Ubuntu 22.04 LTS")); mappings.add(new GuestOSHypervisorMapping("VMware", "6.5", "ubuntu64Guest")); mappings.add(new GuestOSHypervisorMapping("VMware", "6.7", "ubuntu64Guest")); @@ -138,7 +136,7 @@ public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate guestOsMapper.addGuestOsAndHypervisorMappings(10, "Ubuntu 22.04 LTS", mappings); mappings.clear(); - LOG.debug("Correcting guest OS names in hypervisor mappings for VMware 8.0 ad 8.0.0.1"); + logger.debug("Correcting guest OS names in hypervisor mappings for VMware 8.0 ad 8.0.0.1"); final String hypervisorVMware = Hypervisor.HypervisorType.VMware.name(); final String hypervisorVersionVmware8 = "8.0"; guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "AlmaLinux 9", new GuestOSHypervisorMapping(hypervisorVMware, hypervisorVersionVmware8, "almalinux_64Guest")); @@ -148,7 +146,7 @@ public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Oracle Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "8.0.0.1", "oracleLinux9_64Guest")); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Rocky Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "8.0.0.1", "rockylinux_64Guest")); - LOG.debug("Correcting guest OS names in hypervisor mappings for Red Hat Enterprise Linux 9"); + logger.debug("Correcting guest OS names in hypervisor mappings for Red Hat Enterprise Linux 9"); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "7.0", "rhel9_64Guest")); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "7.0.1.0", "rhel9_64Guest")); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "7.0.2.0", "rhel9_64Guest")); @@ -156,7 +154,7 @@ public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, hypervisorVersionVmware8, "rhel9_64Guest")); guestOsMapper.updateGuestOsNameInHypervisorMapping(1, "Red Hat Enterprise Linux 9", new GuestOSHypervisorMapping(hypervisorVMware, "8.0.0.1", "rhel9_64Guest")); - LOG.debug("Adding new guest OS ids in hypervisor mappings for VMware 8.0"); + logger.debug("Adding new guest OS ids in hypervisor mappings for VMware 8.0"); // Add support for darwin22_64Guest from VMware 8.0 mappings.add(new GuestOSHypervisorMapping(hypervisorVMware, hypervisorVersionVmware8, "darwin22_64Guest")); guestOsMapper.addGuestOsAndHypervisorMappings(7, "macOS 13 (64-bit)", mappings); @@ -209,7 +207,7 @@ public class Upgrade41800to41810 implements DbUpgrade, DbUpgradeSystemVmTemplate } private void copyGuestOsMappingsToVMware80u1() { - LOG.debug("Copying guest OS mappings from VMware 8.0 to VMware 8.0.1"); + logger.debug("Copying guest OS mappings from VMware 8.0 to VMware 8.0.1"); GuestOsMapper guestOsMapper = new GuestOsMapper(); guestOsMapper.copyGuestOSHypervisorMappings(Hypervisor.HypervisorType.VMware, "8.0", "8.0.1"); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41810to41900.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41810to41900.java index bdfe58cbf89..e2b1ae1399b 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41810to41900.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41810to41900.java @@ -20,7 +20,6 @@ import com.cloud.upgrade.SystemVmTemplateRegistration; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.DateUtil; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import org.jasypt.exceptions.EncryptionOperationNotPossibleException; import java.io.InputStream; @@ -34,8 +33,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate { - final static Logger LOG = Logger.getLogger(Upgrade41810to41900.class); +public class Upgrade41810to41900 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { private SystemVmTemplateRegistration systemVmTemplateRegistration; private static final String ACCOUNT_DETAILS = "account_details"; @@ -77,6 +75,7 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate decryptConfigurationValuesFromAccountAndDomainScopesNotInSecureHiddenCategories(conn); migrateBackupDates(conn); addIndexes(conn); + addRemoverAccountIdForeignKeyToQuarantinedIps(conn); } @Override @@ -96,7 +95,7 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate @Override public void updateSystemVmTemplates(Connection conn) { - LOG.debug("Updating System Vm template IDs"); + logger.debug("Updating System Vm template IDs"); initSystemVmTemplateRegistration(); try { systemVmTemplateRegistration.updateSystemVmTemplates(conn); @@ -106,15 +105,15 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate } protected void decryptConfigurationValuesFromAccountAndDomainScopesNotInSecureHiddenCategories(Connection conn) { - LOG.info("Decrypting global configuration values from the following tables: account_details and domain_details."); + logger.info("Decrypting global configuration values from the following tables: account_details and domain_details."); Map accountsMap = getConfigsWithScope(conn, ACCOUNT_DETAILS); updateConfigValuesWithScope(conn, accountsMap, ACCOUNT_DETAILS); - LOG.info("Successfully decrypted configurations from account_details table."); + logger.info("Successfully decrypted configurations from account_details table."); Map domainsMap = getConfigsWithScope(conn, DOMAIN_DETAILS); updateConfigValuesWithScope(conn, domainsMap, DOMAIN_DETAILS); - LOG.info("Successfully decrypted configurations from domain_details table."); + logger.info("Successfully decrypted configurations from domain_details table."); } protected Map getConfigsWithScope(Connection conn, String table) { @@ -131,19 +130,19 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate return configsToBeUpdated; } catch (SQLException e) { String message = String.format("Unable to retrieve data from table [%s] due to [%s].", table, e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } public void migrateBackupDates(Connection conn) { - LOG.info("Trying to convert backups' date column from varchar(255) to datetime type."); + logger.info("Trying to convert backups' date column from varchar(255) to datetime type."); modifyDateColumnNameAndCreateNewOne(conn); fetchDatesAndMigrateToNewColumn(conn); dropOldColumn(conn); - LOG.info("Finished converting backups' date column from varchar(255) to datetime."); + logger.info("Finished converting backups' date column from varchar(255) to datetime."); } private void modifyDateColumnNameAndCreateNewOne(Connection conn) { @@ -152,7 +151,7 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate pstmt.execute(); } catch (SQLException e) { String message = String.format("Unable to alter backups' date column name due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } @@ -161,7 +160,7 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate pstmt.execute(); } catch (SQLException e) { String message = String.format("Unable to crate new backups' column date due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -176,12 +175,12 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate pstmt.setString(1, decryptedValue); pstmt.setLong(2, config.getKey()); - LOG.info(String.format("Updating config with ID [%s] to value [%s].", config.getKey(), decryptedValue)); + logger.info(String.format("Updating config with ID [%s] to value [%s].", config.getKey(), decryptedValue)); pstmt.executeUpdate(); } catch (SQLException | EncryptionOperationNotPossibleException e) { String message = String.format("Unable to update config value with ID [%s] on table [%s] due to [%s]. The config value may already be decrypted.", config.getKey(), table, e); - LOG.error(message); + logger.error(message); throw new CloudRuntimeException(message, e); } } @@ -202,7 +201,7 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate } } catch (SQLException e) { String message = String.format("Unable to retrieve backup dates due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -223,7 +222,7 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate } if (parsedDate == null) { String msg = String.format("Unable to parse date [%s]. Will change backup date to null.", date); - LOG.error(msg); + logger.error(msg); return null; } @@ -239,7 +238,7 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate pstmt.executeUpdate(); } catch (SQLException e) { String message = String.format("Unable to update backup date with id [%s] to date [%s] due to [%s].", id, date, e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -250,7 +249,7 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate pstmt.execute(); } catch (SQLException e) { String message = String.format("Unable to drop old_date column due to [%s].", e.getMessage()); - LOG.error(message, e); + logger.error(message, e); throw new CloudRuntimeException(message, e); } } @@ -262,4 +261,7 @@ public class Upgrade41810to41900 implements DbUpgrade, DbUpgradeSystemVmTemplate DbUpgradeUtils.addIndexIfNeeded(conn, "event", "resource_type", "resource_id"); } + private void addRemoverAccountIdForeignKeyToQuarantinedIps(Connection conn) { + DbUpgradeUtils.addForeignKey(conn, "quarantined_ips", "remover_account_id", "account", "id"); + } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to41910.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to41910.java new file mode 100644 index 00000000000..f55580a7e19 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to41910.java @@ -0,0 +1,88 @@ +// 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.upgrade.dao; + +import com.cloud.upgrade.SystemVmTemplateRegistration; +import com.cloud.utils.exception.CloudRuntimeException; + +import java.io.InputStream; +import java.sql.Connection; + +public class Upgrade41900to41910 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { + private SystemVmTemplateRegistration systemVmTemplateRegistration; + + @Override + public String[] getUpgradableVersionRange() { + return new String[]{"4.19.0.0", "4.19.1.0"}; + } + + @Override + public String getUpgradedVersion() { + return "4.19.1.0"; + } + + @Override + public boolean supportsRollingUpgrade() { + return false; + } + + @Override + public InputStream[] getPrepareScripts() { + final String scriptFile = "META-INF/db/schema-41900to41910.sql"; + final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile); + if (script == null) { + throw new CloudRuntimeException("Unable to find " + scriptFile); + } + + return new InputStream[]{script}; + } + + @Override + public void performDataMigration(Connection conn) { + addIndexes(conn); + } + + @Override + public InputStream[] getCleanupScripts() { + final String scriptFile = "META-INF/db/schema-41900to41910-cleanup.sql"; + final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile); + if (script == null) { + throw new CloudRuntimeException("Unable to find " + scriptFile); + } + + return new InputStream[]{script}; + } + + private void addIndexes(Connection conn) { + DbUpgradeUtils.addIndexIfNeeded(conn, "vm_stats", "vm_id"); + } + + @Override + public void updateSystemVmTemplates(Connection conn) { + logger.debug("Updating System Vm template IDs"); + initSystemVmTemplateRegistration(); + try { + systemVmTemplateRegistration.updateSystemVmTemplates(conn); + } catch (Exception e) { + throw new CloudRuntimeException("Failed to find / register SystemVM template(s)"); + } + } + + private void initSystemVmTemplateRegistration() { + systemVmTemplateRegistration = new SystemVmTemplateRegistration(""); + } +} diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to42000.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to42000.java new file mode 100644 index 00000000000..200c5fda232 --- /dev/null +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41900to42000.java @@ -0,0 +1,83 @@ +// 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.upgrade.dao; + +import java.io.InputStream; +import java.sql.Connection; + +import com.cloud.upgrade.SystemVmTemplateRegistration; +import com.cloud.utils.exception.CloudRuntimeException; + +public class Upgrade41900to42000 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { + private SystemVmTemplateRegistration systemVmTemplateRegistration; + + @Override + public String[] getUpgradableVersionRange() { + return new String[] {"4.19.0.0", "4.20.0.0"}; + } + + @Override + public String getUpgradedVersion() { + return "4.20.0.0"; + } + + @Override + public boolean supportsRollingUpgrade() { + return false; + } + + @Override + public InputStream[] getPrepareScripts() { + final String scriptFile = "META-INF/db/schema-41900to42000.sql"; + final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile); + if (script == null) { + throw new CloudRuntimeException("Unable to find " + scriptFile); + } + + return new InputStream[] {script}; + } + + @Override + public void performDataMigration(Connection conn) { + } + + @Override + public InputStream[] getCleanupScripts() { + final String scriptFile = "META-INF/db/schema-41900to42000-cleanup.sql"; + final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile); + if (script == null) { + throw new CloudRuntimeException("Unable to find " + scriptFile); + } + + return new InputStream[] {script}; + } + + private void initSystemVmTemplateRegistration() { + systemVmTemplateRegistration = new SystemVmTemplateRegistration(""); + } + + @Override + public void updateSystemVmTemplates(Connection conn) { + logger.debug("Updating System Vm template IDs"); + initSystemVmTemplateRegistration(); + try { + systemVmTemplateRegistration.updateSystemVmTemplates(conn); + } catch (Exception e) { + throw new CloudRuntimeException("Failed to find / register SystemVM template(s)"); + } + } +} diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade420to421.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade420to421.java index d7ba2ed20da..9ca342d7f4a 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade420to421.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade420to421.java @@ -23,13 +23,11 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.hypervisor.Hypervisor; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade420to421 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade420to421.class); +public class Upgrade420to421 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -89,7 +87,7 @@ public class Upgrade420to421 implements DbUpgrade { } } // Need to populate only when overprovisioning factor doesn't pre exist. - s_logger.debug("Starting updating user_vm_details with cpu/memory overprovisioning factors"); + logger.debug("Starting updating user_vm_details with cpu/memory overprovisioning factors"); try ( PreparedStatement pstmt2 = conn .prepareStatement("select id, hypervisor_type from `cloud`.`vm_instance` where removed is null and id not in (select vm_id from `cloud`.`user_vm_details` where name='cpuOvercommitRatio')"); @@ -123,14 +121,14 @@ public class Upgrade420to421 implements DbUpgrade { } } } - s_logger.debug("Done updating user_vm_details with cpu/memory overprovisioning factors"); + logger.debug("Done updating user_vm_details with cpu/memory overprovisioning factors"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to update cpu/memory overprovisioning factors", e); } } private void upgradeResourceCount(Connection conn) { - s_logger.debug("upgradeResourceCount start"); + logger.debug("upgradeResourceCount start"); String sqlSelectAccountIds = "select id, domain_id FROM `cloud`.`account` where removed is NULL "; String sqlSelectOfferingTotals = "SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)" + " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" @@ -236,7 +234,7 @@ public class Upgrade420to421 implements DbUpgrade { } } } - s_logger.debug("upgradeResourceCount finish"); + logger.debug("upgradeResourceCount finish"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage) ", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade421to430.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade421to430.java index 55e7d3bdac2..88428f455f3 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade421to430.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade421to430.java @@ -24,13 +24,11 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade421to430 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade421to430.class); +public class Upgrade421to430 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -88,11 +86,11 @@ public class Upgrade421to430 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade ram_size of service offering for secondary storage vm. ", e); } - s_logger.debug("Done upgrading RAM for service offering of Secondary Storage VM to " + newRamSize); + logger.debug("Done upgrading RAM for service offering of Secondary Storage VM to " + newRamSize); } private void encryptImageStoreDetails(Connection conn) { - s_logger.debug("Encrypting image store details"); + logger.debug("Encrypting image store details"); try ( PreparedStatement selectPstmt = conn.prepareStatement("select id, value from `cloud`.`image_store_details` where name = 'key' or name = 'secretkey'"); ResultSet rs = selectPstmt.executeQuery(); @@ -115,7 +113,7 @@ public class Upgrade421to430 implements DbUpgrade { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt image_store_details values ", e); } - s_logger.debug("Done encrypting image_store_details"); + logger.debug("Done encrypting image_store_details"); } @Override diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade430to440.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade430to440.java index 43d4d877361..9a2077471e6 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade430to440.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade430to440.java @@ -23,14 +23,12 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; import com.cloud.network.Network; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade430to440 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade430to440.class); +public class Upgrade430to440 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -163,12 +161,12 @@ public class Upgrade430to440 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Exception while Moving private zone information to dedicated resources", e); } - s_logger.debug("Done updating vm nic secondary ip account and domain ids"); + logger.debug("Done updating vm nic secondary ip account and domain ids"); } private void moveCidrsToTheirOwnTable(Connection conn) { - s_logger.debug("Moving network acl item cidrs to a row per cidr"); + logger.debug("Moving network acl item cidrs to a row per cidr"); String networkAclItemSql = "SELECT id, cidr FROM `cloud`.`network_acl_item`"; String networkAclItemCidrSql = "INSERT INTO `cloud`.`network_acl_item_cidrs` (network_acl_item_id, cidr) VALUES (?,?)"; @@ -184,7 +182,7 @@ public class Upgrade430to440 implements DbUpgrade { long itemId = rsItems.getLong(1); // get the source cidr list String cidrList = rsItems.getString(2); - s_logger.debug("Moving '" + cidrList + "' to a row per cidr"); + logger.debug("Moving '" + cidrList + "' to a row per cidr"); // split it String[] cidrArray = cidrList.split(","); // insert a record per cidr @@ -197,11 +195,11 @@ public class Upgrade430to440 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Exception while Moving network acl item cidrs to a row per cidr", e); } - s_logger.debug("Done moving network acl item cidrs to a row per cidr"); + logger.debug("Done moving network acl item cidrs to a row per cidr"); } private void updateVlanUris(Connection conn) { - s_logger.debug("updating vlan URIs"); + logger.debug("updating vlan URIs"); try(PreparedStatement selectstatement = conn.prepareStatement("SELECT id, vlan_id FROM `cloud`.`vlan` where vlan_id not like '%:%'"); ResultSet results = selectstatement.executeQuery()) { @@ -224,7 +222,7 @@ public class Upgrade430to440 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Unable to update vlan URIs ", e); } - s_logger.debug("Done updating vlan URIs"); + logger.debug("Done updating vlan URIs"); } @Override diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade431to440.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade431to440.java index 98b52ac0aa9..54aa3b76d6f 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade431to440.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade431to440.java @@ -17,10 +17,8 @@ package com.cloud.upgrade.dao; -import org.apache.log4j.Logger; -public class Upgrade431to440 extends Upgrade430to440 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade431to440.class); +public class Upgrade431to440 extends Upgrade430to440 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade432to440.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade432to440.java index ded0db474d5..3b934c1f344 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade432to440.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade432to440.java @@ -17,10 +17,8 @@ package com.cloud.upgrade.dao; -import org.apache.log4j.Logger; -public class Upgrade432to440 extends Upgrade431to440 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade432to440.class); +public class Upgrade432to440 extends Upgrade431to440 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade440to441.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade440to441.java index a51f464a797..4309a1a53c5 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade440to441.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade440to441.java @@ -22,7 +22,7 @@ import java.sql.Connection; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade440to441 implements DbUpgrade { +public class Upgrade440to441 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade441to442.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade441to442.java index 4234428f72b..1993b15b640 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade441to442.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade441to442.java @@ -23,7 +23,7 @@ import java.sql.Connection; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade441to442 implements DbUpgrade { +public class Upgrade441to442 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade442to450.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade442to450.java index 54e8da5f6e9..803d521ac24 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade442to450.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade442to450.java @@ -28,13 +28,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade442to450 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade442to450.class); +public class Upgrade442to450 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -82,7 +80,7 @@ public class Upgrade442to450 implements DbUpgrade { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt configuration values ", e); } - s_logger.debug("Done updating router.ram.size config to 256"); + logger.debug("Done updating router.ram.size config to 256"); } private void upgradeMemoryOfVirtualRoutervmOffering(Connection conn) { @@ -109,7 +107,7 @@ public class Upgrade442to450 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade ram_size of service offering for domain router. ", e); } - s_logger.debug("Done upgrading RAM for service offering of domain router to " + newRamSize); + logger.debug("Done upgrading RAM for service offering of domain router to " + newRamSize); } private void upgradeMemoryOfInternalLoadBalancervmOffering(Connection conn) { @@ -134,7 +132,7 @@ public class Upgrade442to450 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade ram_size of service offering for internal loadbalancer vm. ", e); } - s_logger.debug("Done upgrading RAM for service offering of internal loadbalancer vm to " + newRamSize); + logger.debug("Done upgrading RAM for service offering of internal loadbalancer vm to " + newRamSize); } @Override @@ -155,7 +153,7 @@ public class Upgrade442to450 implements DbUpgrade { keys.add("id_2"); uniqueKeys.put("storage_pool", keys); - s_logger.debug("Dropping id_2 key from storage_pool table"); + logger.debug("Dropping id_2 key from storage_pool table"); for (Map.Entry> entry: uniqueKeys.entrySet()) { DbUpgradeUtils.dropKeysIfExist(conn,entry.getKey(), entry.getValue(), false); } @@ -168,7 +166,7 @@ public class Upgrade442to450 implements DbUpgrade { keys.add("fk_async_job_join_map__join_job_id"); foreignKeys.put("async_job_join_map", keys); - s_logger.debug("Dropping fk_async_job_join_map__join_job_id key from async_job_join_map table"); + logger.debug("Dropping fk_async_job_join_map__join_job_id key from async_job_join_map table"); for (Map.Entry> entry: foreignKeys.entrySet()) { DbUpgradeUtils.dropKeysIfExist(conn,entry.getKey(), entry.getValue(), true); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to444.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to444.java index b8110546a13..61674d9870f 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to444.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to444.java @@ -22,7 +22,7 @@ import java.sql.Connection; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade443to444 implements DbUpgrade { +public class Upgrade443to444 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to450.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to450.java index 80b2c14e00c..9f571fedc2c 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to450.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade443to450.java @@ -17,7 +17,7 @@ package com.cloud.upgrade.dao; -public class Upgrade443to450 extends Upgrade442to450 implements DbUpgrade { +public class Upgrade443to450 extends Upgrade442to450 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade444to450.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade444to450.java index 52fc7299810..d393e73f59a 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade444to450.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade444to450.java @@ -17,7 +17,7 @@ package com.cloud.upgrade.dao; -public class Upgrade444to450 extends Upgrade442to450 implements DbUpgrade { +public class Upgrade444to450 extends Upgrade442to450 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade450to451.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade450to451.java index 015d463347a..ffdf2cc1273 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade450to451.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade450to451.java @@ -26,13 +26,11 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.crypt.DBEncryptionUtil; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade450to451 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade450to451.class); +public class Upgrade450to451 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -97,7 +95,7 @@ public class Upgrade450to451 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Exception while encrypting key column in keystore table", e); } - s_logger.debug("Done encrypting keystore's key column"); + logger.debug("Done encrypting keystore's key column"); } private void encryptIpSecPresharedKeysOfRemoteAccessVpn(Connection conn) { @@ -111,7 +109,7 @@ public class Upgrade450to451 implements DbUpgrade { try { preSharedKey = DBEncryptionUtil.decrypt(preSharedKey); } catch (CloudRuntimeException ignored) { - s_logger.debug("The ipsec_psk preshared key id=" + rowId + "in remote_access_vpn is not encrypted, encrypting it."); + logger.debug("The ipsec_psk preshared key id=" + rowId + "in remote_access_vpn is not encrypted, encrypting it."); } try (PreparedStatement updateStatement = conn.prepareStatement("UPDATE `cloud`.`remote_access_vpn` SET ipsec_psk=? WHERE id=?");) { updateStatement.setString(1, DBEncryptionUtil.encrypt(preSharedKey)); @@ -122,7 +120,7 @@ public class Upgrade450to451 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Unable to update the remote_access_vpn's preshared key ipsec_psk column", e); } - s_logger.debug("Done encrypting remote_access_vpn's ipsec_psk column"); + logger.debug("Done encrypting remote_access_vpn's ipsec_psk column"); } private void encryptStoragePoolUserInfo(Connection conn) { @@ -151,7 +149,7 @@ public class Upgrade450to451 implements DbUpgrade { } catch (UnsupportedEncodingException e) { throw new CloudRuntimeException("Unable encrypt storage pool user info ", e); } - s_logger.debug("Done encrypting storage_pool's user_info column"); + logger.debug("Done encrypting storage_pool's user_info column"); } private void updateUserVmDetailsWithNicAdapterType(Connection conn) { @@ -160,13 +158,13 @@ public class Upgrade450to451 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Failed to update user_vm_details table with nicAdapter entries by copying from vm_template_detail table", e); } - s_logger.debug("Done. Updated user_vm_details table with nicAdapter entries by copying from vm_template_detail table. This affects only VM/templates with hypervisor_type as VMware."); + logger.debug("Done. Updated user_vm_details table with nicAdapter entries by copying from vm_template_detail table. This affects only VM/templates with hypervisor_type as VMware."); } private void upgradeVMWareLocalStorage(Connection conn) { try (PreparedStatement updatePstmt = conn.prepareStatement("UPDATE storage_pool SET pool_type='VMFS',host_address=@newaddress WHERE (@newaddress:=concat('VMFS datastore: ', path)) IS NOT NULL AND scope = 'HOST' AND pool_type = 'LVM' AND id IN (SELECT * FROM (SELECT storage_pool.id FROM storage_pool,cluster WHERE storage_pool.cluster_id = cluster.id AND cluster.hypervisor_type='VMware') AS t);");) { updatePstmt.executeUpdate(); - s_logger.debug("Done, upgraded VMWare local storage pool type to VMFS and host_address to the VMFS format"); + logger.debug("Done, upgraded VMWare local storage pool type to VMFS and host_address to the VMFS format"); } catch (SQLException e) { throw new CloudRuntimeException("Unable to upgrade VMWare local storage pool type", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade451to452.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade451to452.java index 788b6f28ef1..d019558a33c 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade451to452.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade451to452.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade451to452 implements DbUpgrade { +public class Upgrade451to452 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to453.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to453.java index 3bc39ebc68f..17ec3414896 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to453.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to453.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade452to453 implements DbUpgrade { +public class Upgrade452to453 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to460.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to460.java index 91fe345f4a1..d14d6c9e543 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to460.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade452to460.java @@ -25,12 +25,10 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade452to460 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade452to460.class); +public class Upgrade452to460 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -67,7 +65,7 @@ public class Upgrade452to460 implements DbUpgrade { public void updateVMInstanceUserId(final Connection conn) { // For schemas before this, copy first user from an account_id which // deployed already running VMs - s_logger.debug("Updating vm_instance column user_id using first user in vm_instance's account_id"); + logger.debug("Updating vm_instance column user_id using first user in vm_instance's account_id"); final String vmInstanceSql = "SELECT id, account_id FROM `cloud`.`vm_instance`"; final String userSql = "SELECT id FROM `cloud`.`user` where account_id=?"; final String userIdUpdateSql = "update `cloud`.`vm_instance` set user_id=? where id=?"; @@ -97,7 +95,7 @@ public class Upgrade452to460 implements DbUpgrade { } catch (final SQLException e) { throw new CloudRuntimeException("Unable to update user Ids for previously deployed VMs", e); } - s_logger.debug("Done updating user Ids for previously deployed VMs"); + logger.debug("Done updating user Ids for previously deployed VMs"); addRedundancyForNwAndVpc(conn); removeBumPriorityColumn(conn); } @@ -142,14 +140,14 @@ public class Upgrade452to460 implements DbUpgrade { private void addIndexForVMInstance(final Connection conn) { // Drop index if it exists final List indexList = new ArrayList(); - s_logger.debug("Dropping index i_vm_instance__instance_name from vm_instance table if it exists"); + logger.debug("Dropping index i_vm_instance__instance_name from vm_instance table if it exists"); indexList.add("i_vm_instance__instance_name"); DbUpgradeUtils.dropKeysIfExist(conn, "vm_instance", indexList, false); // Now add index try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`vm_instance` ADD INDEX `i_vm_instance__instance_name`(`instance_name`)");) { pstmt.executeUpdate(); - s_logger.debug("Added index i_vm_instance__instance_name to vm_instance table"); + logger.debug("Added index i_vm_instance__instance_name to vm_instance table"); } catch (final SQLException e) { throw new CloudRuntimeException("Unable to add index i_vm_instance__instance_name to vm_instance table for the column instance_name", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade453to460.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade453to460.java index 2dd4b0aad27..321d0304f9d 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade453to460.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade453to460.java @@ -17,7 +17,7 @@ package com.cloud.upgrade.dao; -public class Upgrade453to460 extends Upgrade452to460 implements DbUpgrade { +public class Upgrade453to460 extends Upgrade452to460 { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade460to461.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade460to461.java index 88bda4616c8..3642a59e516 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade460to461.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade460to461.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade460to461 implements DbUpgrade { +public class Upgrade460to461 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade461to470.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade461to470.java index e7922cebf0a..d2241e0498c 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade461to470.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade461to470.java @@ -18,15 +18,13 @@ package com.cloud.upgrade.dao; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; -public class Upgrade461to470 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade461to470.class); +public class Upgrade461to470 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -58,10 +56,10 @@ public class Upgrade461to470 implements DbUpgrade { final String alterTableSql = "ALTER TABLE `cloud_usage`.`cloud_usage` ADD COLUMN `quota_calculated` tinyint(1) DEFAULT 0 NOT NULL COMMENT 'quota calculation status'"; try (PreparedStatement pstmt = conn.prepareStatement(alterTableSql)) { pstmt.executeUpdate(); - s_logger.info("Altered cloud_usage.cloud_usage table and added column quota_calculated"); + logger.info("Altered cloud_usage.cloud_usage table and added column quota_calculated"); } catch (SQLException e) { if (e.getMessage().contains("quota_calculated")) { - s_logger.warn("cloud_usage.cloud_usage table already has a column called quota_calculated"); + logger.warn("cloud_usage.cloud_usage table already has a column called quota_calculated"); } else { throw new CloudRuntimeException("Unable to create column quota_calculated in table cloud_usage.cloud_usage", e); } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade470to471.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade470to471.java index 08cdfdd53f5..0464381dd60 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade470to471.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade470to471.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade470to471 implements DbUpgrade { +public class Upgrade470to471 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade471to480.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade471to480.java index 3b3a0bba03e..614e1d8779e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade471to480.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade471to480.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade471to480 implements DbUpgrade { +public class Upgrade471to480 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade480to481.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade480to481.java index be33709dd92..d1aa4214837 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade480to481.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade480to481.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade480to481 implements DbUpgrade { +public class Upgrade480to481 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade481to490.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade481to490.java index 2165d809f85..5c950a86b0e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade481to490.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade481to490.java @@ -27,13 +27,11 @@ import java.sql.SQLException; import com.cloud.user.Account; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import com.cloud.utils.db.ScriptRunner; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade481to490 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade481to490.class); +public class Upgrade481to490 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { @@ -74,7 +72,7 @@ public class Upgrade481to490 implements DbUpgrade { final Integer accountType = selectResultSet.getInt(2); final Long roleId = RoleType.getByAccountType(Account.Type.getFromValue(accountType)).getId(); if (roleId < 1L || roleId > 4L) { - s_logger.warn("Skipping role ID migration due to invalid role_id resolved for account id=" + accountId); + logger.warn("Skipping role ID migration due to invalid role_id resolved for account id=" + accountId); continue; } try (final PreparedStatement updateStatement = conn.prepareStatement("UPDATE `cloud`.`account` SET account.role_id = ? WHERE account.id = ? ;")) { @@ -82,14 +80,14 @@ public class Upgrade481to490 implements DbUpgrade { updateStatement.setLong(2, accountId); updateStatement.executeUpdate(); } catch (SQLException e) { - s_logger.error("Failed to update cloud.account role_id for account id:" + accountId + " with exception: " + e.getMessage()); + logger.error("Failed to update cloud.account role_id for account id:" + accountId + " with exception: " + e.getMessage()); throw new CloudRuntimeException("Exception while updating cloud.account role_id", e); } } } catch (SQLException e) { throw new CloudRuntimeException("Exception while migrating existing account table's role_id column to a role based on account type", e); } - s_logger.debug("Done migrating existing accounts to use one of default roles based on account type"); + logger.debug("Done migrating existing accounts to use one of default roles based on account type"); } private void setupRolesAndPermissionsForDynamicChecker(final Connection conn) { @@ -101,7 +99,7 @@ public class Upgrade481to490 implements DbUpgrade { pstmt.executeUpdate(); } catch (SQLException e) { if (e.getMessage().contains("role_id")) { - s_logger.warn("cloud.account table already has the role_id column, skipping altering table and migration of accounts"); + logger.warn("cloud.account table already has the role_id column, skipping altering table and migration of accounts"); return; } else { throw new CloudRuntimeException("Unable to create column role_id in table cloud.account", e); @@ -116,20 +114,20 @@ public class Upgrade481to490 implements DbUpgrade { migrateAccountsToDefaultRoles(conn); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Configuring default role-api mappings, use migrate-dynamicroles.py instead if you want to migrate rules from an existing commands.properties file"); + if (logger.isDebugEnabled()) { + logger.debug("Configuring default role-api mappings, use migrate-dynamicroles.py instead if you want to migrate rules from an existing commands.properties file"); } final String scriptFile = "META-INF/db/create-default-role-api-mappings.sql"; final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile); if (script == null) { - s_logger.error("Unable to find default role-api mapping sql file, please configure api per role manually"); + logger.error("Unable to find default role-api mapping sql file, please configure api per role manually"); return; } try(final InputStreamReader reader = new InputStreamReader(script)) { ScriptRunner runner = new ScriptRunner(conn, false, true); runner.runScript(reader); } catch (SQLException | IOException e) { - s_logger.error("Unable to insert default api-role mappings from file: " + script + ". Please configure api per role manually, giving up!", e); + logger.error("Unable to insert default api-role mappings from file: " + script + ". Please configure api per role manually, giving up!", e); } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade490to4910.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade490to4910.java index 8757d7fa539..fdb5fd261b9 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade490to4910.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade490to4910.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade490to4910 implements DbUpgrade { +public class Upgrade490to4910 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4910to4920.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4910to4920.java index 1950c8f28b8..69cd5b796a8 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4910to4920.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4910to4920.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade4910to4920 implements DbUpgrade { +public class Upgrade4910to4920 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4920to4930.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4920to4930.java index bc02c95064c..9f5437e8d87 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4920to4930.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4920to4930.java @@ -22,7 +22,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import java.io.InputStream; import java.sql.Connection; -public class Upgrade4920to4930 implements DbUpgrade { +public class Upgrade4920to4930 extends DbUpgradeAbstractImpl { @Override public String[] getUpgradableVersionRange() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4930to41000.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4930to41000.java index 46abd44aa6a..631308a975e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4930to41000.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade4930to41000.java @@ -23,12 +23,10 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.HashMap; -import org.apache.log4j.Logger; import com.cloud.utils.exception.CloudRuntimeException; -public class Upgrade4930to41000 implements DbUpgrade { - final static Logger s_logger = Logger.getLogger(Upgrade4930to41000.class); +public class Upgrade4930to41000 extends DbUpgradeAbstractImpl { public static class MemoryValues { long max; diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java index 3e39f81f761..4c856ab154e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot217to224.java @@ -21,7 +21,7 @@ import java.sql.Connection; import com.cloud.utils.exception.CloudRuntimeException; -public class UpgradeSnapshot217to224 implements DbUpgrade { +public class UpgradeSnapshot217to224 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java index 8e546e7dd4d..7a5b7de17b5 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/UpgradeSnapshot223to224.java @@ -21,7 +21,7 @@ import java.sql.Connection; import com.cloud.utils.exception.CloudRuntimeException; -public class UpgradeSnapshot223to224 implements DbUpgrade { +public class UpgradeSnapshot223to224 extends DbUpgradeAbstractImpl { @Override public InputStream[] getPrepareScripts() { diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/VersionDaoImpl.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/VersionDaoImpl.java index 67fe70fdb29..90e1912408c 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/VersionDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/VersionDaoImpl.java @@ -23,7 +23,6 @@ import java.sql.SQLException; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.upgrade.dao.VersionVO.Step; @@ -40,7 +39,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component @DB() public class VersionDaoImpl extends GenericDaoBase implements VersionDao { - private static final Logger s_logger = Logger.getLogger(VersionDaoImpl.class); final GenericSearchBuilder CurrentVersionSearch; final SearchBuilder AllFieldsSearch; @@ -74,7 +72,7 @@ public class VersionDaoImpl extends GenericDaoBase implements V @DB public String getCurrentVersion() { try (Connection conn = TransactionLegacy.getStandaloneConnection();) { - s_logger.debug("Checking to see if the database is at a version before it was the version table is created"); + logger.debug("Checking to see if the database is at a version before it was the version table is created"); try ( PreparedStatement pstmt = conn.prepareStatement("SHOW TABLES LIKE 'version'"); @@ -89,8 +87,8 @@ public class VersionDaoImpl extends GenericDaoBase implements V pstmt_domain.executeQuery(); return "2.1.8"; } catch (final SQLException e) { - s_logger.debug("Assuming the exception means domain_id is not there."); - s_logger.debug("No version table and no nics table, returning 2.1.7"); + logger.debug("Assuming the exception means domain_id is not there."); + logger.debug("No version table and no nics table, returning 2.1.7"); return "2.1.7"; } } else { @@ -98,7 +96,7 @@ public class VersionDaoImpl extends GenericDaoBase implements V ResultSet rs_static_nat = pstmt_static_nat.executeQuery();){ return "2.2.1"; } catch (final SQLException e) { - s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); + logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); return "2.2.2"; } } @@ -125,7 +123,7 @@ public class VersionDaoImpl extends GenericDaoBase implements V } // Use nics table information and is_static_nat field from firewall_rules table to determine version information - s_logger.debug("Version table exists, but it's empty; have to confirm that version is 2.2.2"); + logger.debug("Version table exists, but it's empty; have to confirm that version is 2.2.2"); try (PreparedStatement pstmt = conn.prepareStatement("SHOW TABLES LIKE 'nics'"); ResultSet rs = pstmt.executeQuery();){ if (!rs.next()) { @@ -136,7 +134,7 @@ public class VersionDaoImpl extends GenericDaoBase implements V throw new CloudRuntimeException("Unable to determine the current version, version table exists and empty, " + "nics table doesn't exist, is_static_nat field exists in firewall_rules table"); } catch (final SQLException e) { - s_logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); + logger.debug("Assuming the exception means static_nat field doesn't exist in firewall_rules table, returning version 2.2.2"); return "2.2.2"; } } diff --git a/engine/schema/src/main/java/com/cloud/usage/UsageVO.java b/engine/schema/src/main/java/com/cloud/usage/UsageVO.java index 10b295f593c..50884e3c012 100644 --- a/engine/schema/src/main/java/com/cloud/usage/UsageVO.java +++ b/engine/schema/src/main/java/com/cloud/usage/UsageVO.java @@ -17,6 +17,7 @@ package com.cloud.usage; import java.util.Date; +import java.util.TimeZone; import javax.persistence.Column; import javax.persistence.Entity; @@ -27,9 +28,11 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import com.cloud.utils.DateUtil; import org.apache.cloudstack.api.InternalIdentity; import org.apache.cloudstack.usage.Usage; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; +import org.apache.commons.lang3.StringUtils; @Entity @Table(name = "cloud_usage") @@ -400,6 +403,12 @@ public class UsageVO implements Usage, InternalIdentity { @Override public String toString() { - return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "usageId", "usageType", "startDate", "endDate"); + return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "usageId", "usageType"); + } + + public String toString(TimeZone timeZone) { + String startDateString = DateUtil.displayDateInTimezone(timeZone, getStartDate()); + String endDateString = DateUtil.displayDateInTimezone(timeZone, getEndDate()); + return String.format("%s,\"startDate\":\"%s\",\"endDate\":\"%s\"}", StringUtils.chop(this.toString()), startDateString, endDateString); } } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/BucketStatisticsDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/BucketStatisticsDaoImpl.java index 2261389eab6..1df24079cee 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/BucketStatisticsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/BucketStatisticsDaoImpl.java @@ -20,14 +20,12 @@ import com.cloud.usage.BucketStatisticsVO; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.util.List; @Component public class BucketStatisticsDaoImpl extends GenericDaoBase implements BucketStatisticsDao { - private static final Logger s_logger = Logger.getLogger(BucketStatisticsDaoImpl.class); private final SearchBuilder AllFieldsSearch; private final SearchBuilder AccountSearch; diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageBackupDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageBackupDaoImpl.java index 712f81807c7..3403a8dfe5b 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageBackupDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageBackupDaoImpl.java @@ -25,7 +25,6 @@ import java.util.Date; import java.util.List; import java.util.TimeZone; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.exception.CloudException; @@ -37,7 +36,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class UsageBackupDaoImpl extends GenericDaoBase implements UsageBackupDao { - public static final Logger LOGGER = Logger.getLogger(UsageBackupDaoImpl.class); protected static final String UPDATE_DELETED = "UPDATE usage_backup SET removed = ? WHERE account_id = ? AND vm_id = ? and removed IS NULL"; protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT id, zone_id, account_id, domain_id, vm_id, backup_offering_id, size, protected_size, created, removed FROM usage_backup WHERE " + " account_id = ? AND ((removed IS NULL AND created <= ?) OR (created BETWEEN ? AND ?) OR (removed BETWEEN ? AND ?) " + @@ -55,7 +53,7 @@ public class UsageBackupDaoImpl extends GenericDaoBase impl update(vo.getId(), vo); } } catch (final Exception e) { - LOGGER.error("Error updating backup metrics: " + e.getMessage(), e); + logger.error("Error updating backup metrics: " + e.getMessage(), e); } } @@ -72,13 +70,13 @@ public class UsageBackupDaoImpl extends GenericDaoBase impl pstmt.executeUpdate(); } } catch (SQLException e) { - LOGGER.error("Error removing UsageBackupVO: " + e.getMessage(), e); + logger.error("Error removing UsageBackupVO: " + e.getMessage(), e); throw new CloudException("Remove backup usage exception: " + e.getMessage(), e); } txn.commit(); } catch (Exception e) { txn.rollback(); - LOGGER.error("Exception caught while removing UsageBackupVO: " + e.getMessage(), e); + logger.error("Exception caught while removing UsageBackupVO: " + e.getMessage(), e); } finally { txn.close(); } @@ -128,7 +126,7 @@ public class UsageBackupDaoImpl extends GenericDaoBase impl } } catch (Exception e) { txn.rollback(); - LOGGER.warn("Error getting VM backup usage records", e); + logger.warn("Error getting VM backup usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java index 0d9e727abe2..2335043b7c5 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageDaoImpl.java @@ -34,7 +34,6 @@ import com.cloud.utils.db.TransactionStatus; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.sql.PreparedStatement; @@ -49,7 +48,6 @@ import java.util.TimeZone; @Component public class UsageDaoImpl extends GenericDaoBase implements UsageDao { - public static final Logger s_logger = Logger.getLogger(UsageDaoImpl.class.getName()); private static final String DELETE_ALL = "DELETE FROM cloud_usage"; private static final String DELETE_ALL_BY_ACCOUNTID = "DELETE FROM cloud_usage WHERE account_id = ?"; private static final String DELETE_ALL_BY_INTERVAL = "DELETE FROM cloud_usage WHERE end_date < DATE_SUB(CURRENT_DATE(), INTERVAL ? DAY)"; @@ -108,7 +106,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error retrieving usage vm instances for account id: " + accountId, ex); + logger.error("error retrieving usage vm instances for account id: " + accountId, ex); } finally { txn.close(); } @@ -156,7 +154,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving account to cloud_usage db", ex); + logger.error("error saving account to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -186,7 +184,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating account to cloud_usage db", ex); + logger.error("error updating account to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -227,7 +225,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving user stats to cloud_usage db", ex); + logger.error("error saving user stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -254,7 +252,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating user stats to cloud_usage db", ex); + logger.error("error updating user stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -271,7 +269,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage return Long.valueOf(rs.getLong(1)); } } catch (Exception ex) { - s_logger.error("error getting last account id", ex); + logger.error("error getting last account id", ex); } return null; } @@ -288,7 +286,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage return Long.valueOf(rs.getLong(1)); } } catch (Exception ex) { - s_logger.error("error getting last user stats id", ex); + logger.error("error getting last user stats id", ex); } return null; } @@ -305,7 +303,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage return Long.valueOf(rs.getLong(1)); } } catch (Exception ex) { - s_logger.error("error getting last bucket stats id", ex); + logger.error("error getting last bucket stats id", ex); } return null; } @@ -329,7 +327,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving bucket stats to cloud_usage db", ex); + logger.error("error saving bucket stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -351,7 +349,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating bucket stats to cloud_usage db", ex); + logger.error("error updating bucket stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -370,7 +368,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage templateList.add(Long.valueOf(rs.getLong(1))); } } catch (Exception ex) { - s_logger.error("error listing public templates", ex); + logger.error("error listing public templates", ex); } return templateList; } @@ -387,7 +385,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage return Long.valueOf(rs.getLong(1)); } } catch (Exception ex) { - s_logger.error("error getting last vm disk stats id", ex); + logger.error("error getting last vm disk stats id", ex); } return null; } @@ -420,7 +418,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating vm disk stats to cloud_usage db", ex); + logger.error("error updating vm disk stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } @@ -466,7 +464,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving vm disk stats to cloud_usage db", ex); + logger.error("error saving vm disk stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } @@ -533,7 +531,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving usage records to cloud_usage db", ex); + logger.error("error saving usage records to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } @@ -551,7 +549,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error removing old cloud_usage records for interval: " + days); + logger.error("error removing old cloud_usage records for interval: " + days); } finally { txn.close(); } @@ -568,7 +566,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage @Override public Pair, Integer> listUsageRecordsPendingForQuotaAggregation(long accountId, long domainId) { - s_logger.debug(String.format("Retrieving pending usage records for accountId [%s] and domainId [%s].", accountId, domainId)); + logger.debug(String.format("Retrieving pending usage records for accountId [%s] and domainId [%s].", accountId, domainId)); return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback, Integer>>) status -> { Filter usageFilter = new Filter(UsageVO.class, "startDate", true, null, null); @@ -594,7 +592,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage String startDateString = DateUtil.getOutputString(startDate); String endDateString = DateUtil.getOutputString(endDate); - s_logger.debug(String.format("Retrieving account resources between [%s] and [%s] for accountId [%s] and usageType [%s].", startDateString, endDateString, accountId, + logger.debug(String.format("Retrieving account resources between [%s] and [%s] for accountId [%s] and usageType [%s].", startDateString, endDateString, accountId, usageType)); TransactionLegacy txn = TransactionLegacy.currentTxn(); @@ -617,7 +615,7 @@ public class UsageDaoImpl extends GenericDaoBase implements Usage return accountResourcesOfTheLastDay; } catch (SQLException e) { - s_logger.error(String.format("Failed to retrieve account resources between [%s] and [%s] for accountId [%s] and usageType [%s] due to [%s]. Returning an empty list of" + logger.error(String.format("Failed to retrieve account resources between [%s] and [%s] for accountId [%s] and usageType [%s] due to [%s]. Returning an empty list of" + " resources.", startDateString, endDateString, accountId, usageType, e.getMessage()), e); return new ArrayList<>(); diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageIPAddressDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageIPAddressDaoImpl.java index 2dcb181c6c7..9c0b8f87ab0 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageIPAddressDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageIPAddressDaoImpl.java @@ -26,7 +26,6 @@ import java.util.TimeZone; import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageIPAddressVO; @@ -36,7 +35,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class UsageIPAddressDaoImpl extends GenericDaoBase implements UsageIPAddressDao { - public static final Logger s_logger = Logger.getLogger(UsageIPAddressDaoImpl.class.getName()); protected static final String UPDATE_RELEASED = "UPDATE usage_ip_address SET released = ? WHERE account_id = ? AND public_ip_address = ? and released IS NULL"; protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = @@ -79,7 +77,7 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase implements UsageJobDao { - private static final Logger s_logger = Logger.getLogger(UsageJobDaoImpl.class.getName()); private static final String GET_LAST_JOB_SUCCESS_DATE_MILLIS = "SELECT end_millis FROM cloud_usage.usage_job WHERE end_millis > 0 and success = 1 ORDER BY end_millis DESC LIMIT 1"; @@ -51,7 +49,7 @@ public class UsageJobDaoImpl extends GenericDaoBase implements return rs.getLong(1); } } catch (Exception ex) { - s_logger.error("error getting last usage job success date", ex); + logger.error("error getting last usage job success date", ex); } finally { txn.close(); } @@ -77,7 +75,7 @@ public class UsageJobDaoImpl extends GenericDaoBase implements txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error updating job success date", ex); + logger.error("error updating job success date", ex); throw new CloudRuntimeException(ex.getMessage()); } finally { txn.close(); diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageLoadBalancerPolicyDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageLoadBalancerPolicyDaoImpl.java index 7260caecd1a..ba5c70fbc32 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageLoadBalancerPolicyDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageLoadBalancerPolicyDaoImpl.java @@ -26,7 +26,6 @@ import java.util.TimeZone; import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageLoadBalancerPolicyVO; @@ -36,7 +35,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class UsageLoadBalancerPolicyDaoImpl extends GenericDaoBase implements UsageLoadBalancerPolicyDao { - public static final Logger s_logger = Logger.getLogger(UsageLoadBalancerPolicyDaoImpl.class.getName()); protected static final String REMOVE_BY_USERID_LBID = "DELETE FROM usage_load_balancer_policy WHERE account_id = ? AND lb_id = ?"; protected static final String UPDATE_DELETED = "UPDATE usage_load_balancer_policy SET deleted = ? WHERE account_id = ? AND lb_id = ? and deleted IS NULL"; @@ -64,7 +62,7 @@ public class UsageLoadBalancerPolicyDaoImpl extends GenericDaoBase implements UsageNetworkDao { - private static final Logger s_logger = Logger.getLogger(UsageNetworkDaoImpl.class.getName()); private static final String SELECT_LATEST_STATS = "SELECT u.account_id, u.zone_id, u.host_id, u.host_type, u.network_id, u.bytes_sent, u.bytes_received, u.agg_bytes_received, u.agg_bytes_sent, u.event_time_millis " + "FROM cloud_usage.usage_network u INNER JOIN (SELECT netusage.account_id as acct_id, netusage.zone_id as z_id, max(netusage.event_time_millis) as max_date " @@ -77,7 +75,7 @@ public class UsageNetworkDaoImpl extends GenericDaoBase im } return returnMap; } catch (Exception ex) { - s_logger.error("error getting recent usage network stats", ex); + logger.error("error getting recent usage network stats", ex); } finally { txn.close(); } @@ -97,7 +95,7 @@ public class UsageNetworkDaoImpl extends GenericDaoBase im txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error deleting old usage network stats", ex); + logger.error("error deleting old usage network stats", ex); } } @@ -126,7 +124,7 @@ public class UsageNetworkDaoImpl extends GenericDaoBase im txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving usage_network to cloud_usage db", ex); + logger.error("error saving usage_network to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java index 23931f0a84e..b3bc06e8af4 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageNetworkOfferingDaoImpl.java @@ -26,7 +26,6 @@ import java.util.TimeZone; import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageNetworkOfferingVO; @@ -36,7 +35,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class UsageNetworkOfferingDaoImpl extends GenericDaoBase implements UsageNetworkOfferingDao { - public static final Logger s_logger = Logger.getLogger(UsageNetworkOfferingDaoImpl.class.getName()); protected static final String UPDATE_DELETED = "UPDATE usage_network_offering SET deleted = ? WHERE account_id = ? AND vm_instance_id = ? AND network_offering_id = ? and deleted IS NULL"; @@ -74,7 +72,7 @@ public class UsageNetworkOfferingDaoImpl extends GenericDaoBase implements UsagePortForwardingRuleDao { - public static final Logger s_logger = Logger.getLogger(UsagePortForwardingRuleDaoImpl.class.getName()); protected static final String REMOVE_BY_USERID_PFID = "DELETE FROM usage_port_forwarding WHERE account_id = ? AND pf_id = ?"; protected static final String UPDATE_DELETED = "UPDATE usage_port_forwarding SET deleted = ? WHERE account_id = ? AND pf_id = ? and deleted IS NULL"; @@ -64,7 +62,7 @@ public class UsagePortForwardingRuleDaoImpl extends GenericDaoBase implements UsageSecurityGroupDao { - public static final Logger s_logger = Logger.getLogger(UsageSecurityGroupDaoImpl.class.getName()); protected static final String UPDATE_DELETED = "UPDATE usage_security_group SET deleted = ? WHERE account_id = ? AND vm_instance_id = ? AND security_group_id = ? and deleted IS NULL"; @@ -74,7 +72,7 @@ public class UsageSecurityGroupDaoImpl extends GenericDaoBase implements UsageStorageDao { - public static final Logger s_logger = Logger.getLogger(UsageStorageDaoImpl.class.getName()); protected static final String REMOVE_BY_USERID_STORAGEID = "DELETE FROM usage_storage WHERE account_id = ? AND entity_id = ? AND storage_type = ?"; protected static final String UPDATE_DELETED = "UPDATE usage_storage SET deleted = ? WHERE account_id = ? AND entity_id = ? AND storage_type = ? AND zone_id = ? and deleted IS NULL"; @@ -108,7 +106,7 @@ public class UsageStorageDaoImpl extends GenericDaoBase im txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.error("Error removing usageStorageVO", e); + logger.error("Error removing usageStorageVO", e); } finally { txn.close(); } @@ -137,7 +135,7 @@ public class UsageStorageDaoImpl extends GenericDaoBase im txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.error("Error updating UsageStorageVO:"+e.getMessage(), e); + logger.error("Error updating UsageStorageVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -211,7 +209,7 @@ public class UsageStorageDaoImpl extends GenericDaoBase im } }catch (Exception e) { txn.rollback(); - s_logger.error("getUsageRecords:Exception:"+e.getMessage(), e); + logger.error("getUsageRecords:Exception:"+e.getMessage(), e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMInstanceDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMInstanceDaoImpl.java index d330267d0b4..2fd453013bd 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMInstanceDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVMInstanceDaoImpl.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.TimeZone; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVMInstanceVO; @@ -34,7 +33,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class UsageVMInstanceDaoImpl extends GenericDaoBase implements UsageVMInstanceDao { - public static final Logger s_logger = Logger.getLogger(UsageVMInstanceDaoImpl.class.getName()); protected static final String UPDATE_USAGE_INSTANCE_SQL = "UPDATE usage_vm_instance SET end_date = ? " + "WHERE account_id = ? and vm_instance_id = ? and usage_type = ? and end_date IS NULL"; @@ -62,7 +60,7 @@ public class UsageVMInstanceDaoImpl extends GenericDaoBase implements UsageVMSnapshotDao { - public static final Logger s_logger = Logger.getLogger(UsageVMSnapshotDaoImpl.class.getName()); protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT volume_id, zone_id, account_id, domain_id, vm_id, disk_offering_id, size, created, processed, vm_snapshot_id " + " FROM usage_vmsnapshot" + " WHERE account_id = ? " + " AND ( (created BETWEEN ? AND ?) OR " + " (created < ? AND processed is NULL) ) ORDER BY created asc"; @@ -61,7 +59,7 @@ public class UsageVMSnapshotDaoImpl extends GenericDaoBase implements UsageVMSnapshotOnPrimaryDao { - public static final Logger s_logger = Logger.getLogger(UsageVMSnapshotOnPrimaryDaoImpl.class.getName()); protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT volume_id, zone_id, account_id, domain_id, vm_id, name, type, physicalsize, virtualsize, created, deleted, vm_snapshot_id " + " FROM usage_snapshot_on_primary" + " WHERE account_id = ? " + " AND ( (created < ? AND deleted is NULL)" + " OR ( deleted BETWEEN ? AND ?)) ORDER BY created asc"; @@ -58,7 +56,7 @@ public class UsageVMSnapshotOnPrimaryDaoImpl extends GenericDaoBase implements UsageVPNUserDao { - public static final Logger s_logger = Logger.getLogger(UsageVPNUserDaoImpl.class.getName()); protected static final String UPDATE_DELETED = "UPDATE usage_vpn_user SET deleted = ? WHERE account_id = ? AND user_id = ? and deleted IS NULL"; protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT zone_id, account_id, domain_id, user_id, user_name, created, deleted " + "FROM usage_vpn_user " @@ -69,7 +67,7 @@ public class UsageVPNUserDaoImpl extends GenericDaoBase im txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.error("Error updating UsageVPNUserVO:"+e.getMessage(), e); + logger.error("Error updating UsageVPNUserVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -139,7 +137,7 @@ public class UsageVPNUserDaoImpl extends GenericDaoBase im } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVmDiskDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVmDiskDaoImpl.java index 2b934770b7d..bc1cb06cfec 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVmDiskDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVmDiskDaoImpl.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVmDiskVO; @@ -33,7 +32,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class UsageVmDiskDaoImpl extends GenericDaoBase implements UsageVmDiskDao { - private static final Logger s_logger = Logger.getLogger(UsageVmDiskDaoImpl.class.getName()); private static final String SELECT_LATEST_STATS = "SELECT uvd.account_id, uvd.zone_id, uvd.vm_id, uvd.volume_id, uvd.io_read, uvd.io_write, uvd.agg_io_read, uvd.agg_io_write, " + "uvd.bytes_read, uvd.bytes_write, uvd.agg_bytes_read, uvd.agg_bytes_write, uvd.event_time_millis " @@ -81,7 +79,7 @@ public class UsageVmDiskDaoImpl extends GenericDaoBase impl } return returnMap; } catch (Exception ex) { - s_logger.error("error getting recent usage disk stats", ex); + logger.error("error getting recent usage disk stats", ex); } finally { txn.close(); } @@ -101,7 +99,7 @@ public class UsageVmDiskDaoImpl extends GenericDaoBase impl txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error deleting old usage disk stats", ex); + logger.error("error deleting old usage disk stats", ex); } } @@ -133,7 +131,7 @@ public class UsageVmDiskDaoImpl extends GenericDaoBase impl txn.commit(); } catch (Exception ex) { txn.rollback(); - s_logger.error("error saving usage_vm_disk to cloud_usage db", ex); + logger.error("error saving usage_vm_disk to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } } diff --git a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java index 0c35c118006..4662a6f26ce 100644 --- a/engine/schema/src/main/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/usage/dao/UsageVolumeDaoImpl.java @@ -26,7 +26,6 @@ import java.util.TimeZone; import com.cloud.exception.CloudException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVolumeVO; @@ -36,7 +35,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class UsageVolumeDaoImpl extends GenericDaoBase implements UsageVolumeDao { - public static final Logger s_logger = Logger.getLogger(UsageVolumeDaoImpl.class.getName()); protected static final String REMOVE_BY_USERID_VOLID = "DELETE FROM usage_volume WHERE account_id = ? AND volume_id = ?"; protected static final String UPDATE_DELETED = "UPDATE usage_volume SET deleted = ? WHERE account_id = ? AND volume_id = ? and deleted IS NULL"; @@ -69,7 +67,7 @@ public class UsageVolumeDaoImpl extends GenericDaoBase impl txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error removing usageVolumeVO:"+e.getMessage(), e); + logger.warn("Error removing usageVolumeVO:"+e.getMessage(), e); } finally { txn.close(); } @@ -91,7 +89,7 @@ public class UsageVolumeDaoImpl extends GenericDaoBase impl txn.commit(); } catch (Exception e) { txn.rollback(); - s_logger.warn("Error updating UsageVolumeVO", e); + logger.warn("Error updating UsageVolumeVO", e); } finally { txn.close(); } @@ -169,7 +167,7 @@ public class UsageVolumeDaoImpl extends GenericDaoBase impl } } catch (Exception e) { txn.rollback(); - s_logger.warn("Error getting usage records", e); + logger.warn("Error getting usage records", e); } finally { txn.close(); } diff --git a/engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java b/engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java index 3dacbb70f39..eed5572a0b2 100644 --- a/engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/user/dao/AccountDaoImpl.java @@ -32,7 +32,6 @@ import com.cloud.utils.db.SearchCriteria.Func; import com.cloud.utils.db.SearchCriteria.Op; import org.apache.commons.lang3.StringUtils; import com.cloud.utils.db.TransactionLegacy; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.sql.PreparedStatement; @@ -42,7 +41,6 @@ import java.util.List; @Component public class AccountDaoImpl extends GenericDaoBase implements AccountDao { - private static final Logger s_logger = Logger.getLogger(AccountDaoImpl.class); private static final String FIND_USER_ACCOUNT_BY_API_KEY = "SELECT u.id, u.username, u.account_id, u.secret_key, u.state, " + "a.id, a.account_name, a.type, a.role_id, a.domain_id, a.state " + "FROM `cloud`.`user` u, `cloud`.`account` a " + "WHERE u.account_id = a.id AND u.api_key = ? and u.removed IS NULL"; @@ -161,7 +159,7 @@ public class AccountDaoImpl extends GenericDaoBase implements A userAcctPair = new Pair(u, a); } } catch (Exception e) { - s_logger.warn("Exception finding user/acct by api key: " + apiKey, e); + logger.warn("Exception finding user/acct by api key: " + apiKey, e); } return userAcctPair; } @@ -300,7 +298,7 @@ public class AccountDaoImpl extends GenericDaoBase implements A if (!account.getNeedsCleanup()) { account.setNeedsCleanup(true); if (!update(accountId, account)) { - s_logger.warn("Failed to mark account id=" + accountId + " for cleanup"); + logger.warn("Failed to mark account id=" + accountId + " for cleanup"); } } } @@ -320,7 +318,7 @@ public class AccountDaoImpl extends GenericDaoBase implements A domain_id = account_vo.getDomainId(); } catch (Exception e) { - s_logger.warn("getDomainIdForGivenAccountId: Exception :" + e.getMessage()); + logger.warn("getDomainIdForGivenAccountId: Exception :" + e.getMessage()); } finally { return domain_id; diff --git a/engine/schema/src/main/java/com/cloud/user/dao/UserStatisticsDaoImpl.java b/engine/schema/src/main/java/com/cloud/user/dao/UserStatisticsDaoImpl.java index acadc2f0908..6f10c5d2a1b 100644 --- a/engine/schema/src/main/java/com/cloud/user/dao/UserStatisticsDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/user/dao/UserStatisticsDaoImpl.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.TimeZone; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.user.UserStatisticsVO; @@ -36,7 +35,6 @@ import com.cloud.utils.db.TransactionLegacy; @Component public class UserStatisticsDaoImpl extends GenericDaoBase implements UserStatisticsDao { - private static final Logger s_logger = Logger.getLogger(UserStatisticsDaoImpl.class); private static final String ACTIVE_AND_RECENTLY_DELETED_SEARCH = "SELECT us.id, us.data_center_id, us.account_id, us.public_ip_address, us.device_id, us.device_type, us.network_id, us.agg_bytes_received, us.agg_bytes_sent " + "FROM user_statistics us, account a " + "WHERE us.account_id = a.id AND (a.removed IS NULL OR a.removed >= ?) " + "ORDER BY us.id"; @@ -109,7 +107,7 @@ public class UserStatisticsDaoImpl extends GenericDaoBase implements VmDiskStatisticsDao { - private static final Logger s_logger = Logger.getLogger(VmDiskStatisticsDaoImpl.class); private static final String ACTIVE_AND_RECENTLY_DELETED_SEARCH = "SELECT bcf.id, bcf.data_center_id, bcf.account_id, bcf.vm_id, bcf.volume_id, bcf.agg_io_read, bcf.agg_io_write, bcf.agg_bytes_read, bcf.agg_bytes_write " + "FROM vm_disk_statistics bcf, account a " + "WHERE bcf.account_id = a.id AND (a.removed IS NULL OR a.removed >= ?) " + "ORDER BY bcf.id"; @@ -104,7 +102,7 @@ public class VmDiskStatisticsDaoImpl extends GenericDaoBase { + @Override + public String convertToDatabaseColumn(StoragePoolType attribute) { + return attribute != null ? attribute.name() : null; + } + + @Override + public StoragePoolType convertToEntityAttribute(String dbData) { + return dbData != null ? StoragePoolType.valueOf(dbData) : null; + } +} diff --git a/engine/schema/src/main/java/com/cloud/vm/NicVO.java b/engine/schema/src/main/java/com/cloud/vm/NicVO.java index a32a943ea58..936efd112b7 100644 --- a/engine/schema/src/main/java/com/cloud/vm/NicVO.java +++ b/engine/schema/src/main/java/com/cloud/vm/NicVO.java @@ -30,6 +30,7 @@ import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.Transient; +import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -329,17 +330,7 @@ public class NicVO implements Nic { @Override public String toString() { - return new StringBuilder("Nic[").append(id) - .append("-") - .append(instanceId) - .append("-") - .append(deviceId) - .append("-") - .append(reservationId) - .append("-") - .append(iPv4Address) - .append("]") - .toString(); + return String.format("Nic %s", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "id", "instanceId", "deviceId", "broadcastUri", "reservationId", "iPv4Address")); } @Override diff --git a/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java b/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java index f3560d68f49..a1600e04350 100644 --- a/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java +++ b/engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; @@ -41,9 +42,11 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import org.apache.cloudstack.backup.Backup; +import org.apache.cloudstack.util.HypervisorTypeConverter; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.utils.db.Encrypt; @@ -59,7 +62,7 @@ import com.google.gson.Gson; @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, length = 32) public class VMInstanceVO implements VirtualMachine, FiniteStateObject { - private static final Logger s_logger = Logger.getLogger(VMInstanceVO.class); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @TableGenerator(name = "vm_instance_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "vm_instance_seq", allocationSize = 1) @Column(name = "id", updatable = false, nullable = false) @@ -158,7 +161,7 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject implements ConsoleProxyDao { - private static final Logger s_logger = Logger.getLogger(ConsoleProxyDaoImpl.class); // // query SQL for returning console proxy assignment info as following @@ -215,7 +213,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase im l.add(new Pair(rs.getLong(1), rs.getInt(2))); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return l; } @@ -240,7 +238,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase im l.add(new Pair(rs.getLong(1), rs.getInt(2))); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return l; } @@ -259,7 +257,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase im return rs.getInt(1); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return 0; } @@ -277,7 +275,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase im return rs.getInt(1); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return 0; } @@ -299,7 +297,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase im l.add(info); } } catch (SQLException e) { - s_logger.debug("Exception: ", e); + logger.debug("Exception: ", e); } return l; } @@ -321,7 +319,7 @@ public class ConsoleProxyDaoImpl extends GenericDaoBase im l.add(rs.getLong(1)); } } catch (SQLException e) { - s_logger.debug("Caught SQLException: ", e); + logger.debug("Caught SQLException: ", e); } return l; } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java b/engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java index 68f57329d77..23c26ea0718 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/NicDao.java @@ -44,6 +44,8 @@ public interface NicDao extends GenericDao { NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType); + NicVO findByNetworkIdAndTypeIncludingRemoved(long networkId, VirtualMachine.Type vmType); + NicVO findByIp4AddressAndNetworkId(String ip4Address, long networkId); NicVO findByNetworkIdAndMacAddress(long networkId, String mac); diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java index 59d2417b073..3eee1d4e749 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/NicDaoImpl.java @@ -176,12 +176,21 @@ public class NicDaoImpl extends GenericDaoBase implements NicDao { return findOneIncludingRemovedBy(sc); } - @Override - public NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType) { + private NicVO findByNetworkIdAndTypeInternal(long networkId, VirtualMachine.Type vmType, boolean includingRemoved) { SearchCriteria sc = AllFieldsSearch.create(); sc.setParameters("network", networkId); sc.setParameters("vmType", vmType); - return findOneBy(sc); + return includingRemoved ? findOneIncludingRemovedBy(sc) : findOneBy(sc); + } + + @Override + public NicVO findByNetworkIdAndType(long networkId, VirtualMachine.Type vmType) { + return findByNetworkIdAndTypeInternal(networkId, vmType, false); + } + + @Override + public NicVO findByNetworkIdAndTypeIncludingRemoved(long networkId, VirtualMachine.Type vmType) { + return findByNetworkIdAndTypeInternal(networkId, vmType, true); } @Override diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java index 2b3c0289b23..b2b719cd12e 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/SecondaryStorageVmDaoImpl.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Attribute; @@ -38,7 +37,6 @@ import com.cloud.vm.VirtualMachine.State; @Component public class SecondaryStorageVmDaoImpl extends GenericDaoBase implements SecondaryStorageVmDao { - private static final Logger s_logger = Logger.getLogger(SecondaryStorageVmDaoImpl.class); protected SearchBuilder DataCenterStatusSearch; protected SearchBuilder StateSearch; @@ -193,7 +191,7 @@ public class SecondaryStorageVmDaoImpl extends GenericDaoBase implements UserVmCloneSettingDao { - public static final Logger s_logger = Logger.getLogger(UserVmCloneSettingDaoImpl.class); protected SearchBuilder vmIdSearch; protected SearchBuilder cloneTypeSearch; diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java index 80fabf6a7f7..536779125e2 100644 --- a/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java @@ -26,12 +26,17 @@ import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.inject.Inject; +import com.cloud.configuration.Resource; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; +import org.apache.cloudstack.reservation.ReservationVO; +import org.apache.cloudstack.reservation.dao.ReservationDao; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.network.Network; import com.cloud.network.dao.NetworkDao; @@ -60,7 +65,6 @@ import com.cloud.vm.dao.UserVmData.NicData; import com.cloud.vm.dao.UserVmData.SecurityGroupData; public class UserVmDaoImpl extends GenericDaoBase implements UserVmDao { - public static final Logger s_logger = Logger.getLogger(UserVmDaoImpl.class); protected SearchBuilder AccountPodSearch; protected SearchBuilder AccountDataCenterSearch; @@ -93,6 +97,8 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use NetworkDao networkDao; @Inject NetworkOfferingServiceMapDao networkOfferingServiceMapDao; + @Inject + ReservationDao reservationDao; private static final String LIST_PODS_HAVING_VMS_FOR_ACCOUNT = "SELECT pod_id FROM cloud.vm_instance WHERE data_center_id = ? AND account_id = ? AND pod_id IS NOT NULL AND (state = 'Running' OR state = 'Stopped') " @@ -200,6 +206,7 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use CountByAccount.and("type", CountByAccount.entity().getType(), SearchCriteria.Op.EQ); CountByAccount.and("state", CountByAccount.entity().getState(), SearchCriteria.Op.NIN); CountByAccount.and("displayVm", CountByAccount.entity().isDisplayVm(), SearchCriteria.Op.EQ); + CountByAccount.and("idNIN", CountByAccount.entity().getId(), SearchCriteria.Op.NIN); CountByAccount.done(); CountActiveAccount = createSearchBuilder(Long.class); @@ -459,13 +466,13 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use } } catch (Exception e) { - s_logger.error("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage()); + logger.error("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage()); throw new CloudRuntimeException("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage(), e); } txn.commit(); return result; } catch (Exception e) { - s_logger.error("listPodIdsHavingVmsforAccount:Exception : " + e.getMessage()); + logger.error("listPodIdsHavingVmsforAccount:Exception : " + e.getMessage()); throw new CloudRuntimeException("listPodIdsHavingVmsforAccount:Exception: " + e.getMessage(), e); } finally { @@ -477,7 +484,7 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use } catch (Exception e) { - s_logger.error("listPodIdsHavingVmsforAccount:Exception:" + e.getMessage()); + logger.error("listPodIdsHavingVmsforAccount:Exception:" + e.getMessage()); } } @@ -514,7 +521,7 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } curr_index += VM_DETAILS_BATCH_SIZE; @@ -522,7 +529,7 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } } @@ -550,20 +557,20 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use } catch (Exception e) { - s_logger.error("listVmDetails: Exception:" + e.getMessage()); + logger.error("listVmDetails: Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails: Exception:" + e.getMessage(),e); } } txn.commit(); return userVmDataHash; } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); throw new CloudRuntimeException("listVmDetails:Exception : ", e); } finally { @@ -575,7 +582,7 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use } catch (Exception e) { - s_logger.error("listVmDetails:Exception:" + e.getMessage()); + logger.error("listVmDetails:Exception:" + e.getMessage()); } } @@ -699,6 +706,9 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use @Override public Long countAllocatedVMsForAccount(long accountId, boolean runningVMsonly) { + List reservations = reservationDao.getReservationsForAccount(accountId, Resource.ResourceType.user_vm, null); + List reservedResourceIds = reservations.stream().filter(reservation -> reservation.getReservedAmount() > 0).map(ReservationVO::getResourceId).collect(Collectors.toList()); + SearchCriteria sc = CountByAccount.create(); sc.setParameters("account", accountId); sc.setParameters("type", VirtualMachine.Type.User); @@ -707,6 +717,11 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use else sc.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging}); sc.setParameters("displayVm", 1); + + if (CollectionUtils.isNotEmpty(reservedResourceIds)) { + sc.setParameters("idNIN", reservedResourceIds.toArray()); + } + return customSearch(sc, null).get(0); } @@ -740,7 +755,7 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use } } } catch (SQLException e) { - s_logger.error("GetVmsDetailsByNames: Exception in sql: " + e.getMessage()); + logger.error("GetVmsDetailsByNames: Exception in sql: " + e.getMessage()); throw new CloudRuntimeException("GetVmsDetailsByNames: Exception: " + e.getMessage()); } @@ -763,7 +778,7 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use result.add(new Ternary(rs.getInt(1), rs.getInt(2), rs.getInt(3))); } } catch (Exception e) { - s_logger.warn("Error counting vms by size for dcId= " + dcId, e); + logger.warn("Error counting vms by size for dcId= " + dcId, e); } return result; } @@ -794,4 +809,15 @@ public class UserVmDaoImpl extends GenericDaoBase implements Use sc.setParameters("ids", ids.toArray()); return listBy(sc); } + + @Override + public UserVmVO persist(UserVmVO entity) { + return Transaction.execute((TransactionCallback) status -> { + UserVmVO userVM = super.persist(entity); + reservationDao.setResourceId(Resource.ResourceType.user_vm, userVM.getId()); + reservationDao.setResourceId(Resource.ResourceType.cpu, userVM.getId()); + reservationDao.setResourceId(Resource.ResourceType.memory, userVM.getId()); + return userVM; + }); + } } diff --git a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java index 916687baeb4..b7b787b0045 100755 --- a/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java @@ -28,7 +28,6 @@ import java.util.Map; import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.host.HostVO; @@ -65,8 +64,7 @@ import com.cloud.vm.VirtualMachine.Type; @Component public class VMInstanceDaoImpl extends GenericDaoBase implements VMInstanceDao { - public static final Logger s_logger = Logger.getLogger(VMInstanceDaoImpl.class); - private static final int MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT = 3; + static final int MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT = 3; protected SearchBuilder VMClusterSearch; protected SearchBuilder LHVMClusterSearch; @@ -504,8 +502,8 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem @Override public boolean updateState(State oldState, Event event, State newState, VirtualMachine vm, Object opaque) { if (newState == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString()); + if (logger.isDebugEnabled()) { + logger.debug("There's no way to transition from old state: " + oldState.toString() + " event: " + event.toString()); } return false; } @@ -547,7 +545,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem if (result == 0) { VMInstanceVO vo = findByIdIncludingRemoved(vm.getId()); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (vo != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); str.append(": DB Data={Host=").append(vo.getHostId()).append("; State=").append(vo.getState().toString()).append("; updated=").append(vo.getUpdated()) @@ -556,16 +554,16 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem .append("; time=").append(vo.getUpdateTime()); str.append("} Stale Data: {Host=").append(oldHostId).append("; State=").append(oldState).append("; updated=").append(oldUpdated).append("; time=") .append(oldUpdateDate).append("}"); - s_logger.debug(str.toString()); + logger.debug(str.toString()); } else { - s_logger.debug("Unable to update the vm id=" + vm.getId() + "; the vm either doesn't exist or already removed"); + logger.debug("Unable to update the vm id=" + vm.getId() + "; the vm either doesn't exist or already removed"); } } if (vo != null && vo.getState() == newState) { // allow for concurrent update if target state has already been matched - s_logger.debug("VM " + vo.getInstanceName() + " state has been already been updated to " + newState); + logger.debug("VM " + vo.getInstanceName() + " state has been already been updated to " + newState); return true; } } @@ -827,7 +825,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem return rs.getLong(1); } } catch (Exception e) { - s_logger.warn(String.format("Error counting vms by host tag for dcId= %s, hostTag= %s", dcId, hostTag), e); + logger.warn(String.format("Error counting vms by host tag for dcId= %s, hostTag= %s", dcId, hostTag), e); } return 0L; } @@ -897,17 +895,19 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem @Override public boolean updatePowerState(final long instanceId, final long powerHostId, final VirtualMachine.PowerState powerState, Date wisdomEra) { - return Transaction.execute(new TransactionCallback() { + return Transaction.execute(new TransactionCallback<>() { @Override public Boolean doInTransaction(TransactionStatus status) { boolean needToUpdate = false; VMInstanceVO instance = findById(instanceId); if (instance != null - && (null == instance.getPowerStateUpdateTime() + && (null == instance.getPowerStateUpdateTime() || instance.getPowerStateUpdateTime().before(wisdomEra))) { Long savedPowerHostId = instance.getPowerHostId(); - if (instance.getPowerState() != powerState || savedPowerHostId == null - || savedPowerHostId.longValue() != powerHostId) { + if (instance.getPowerState() != powerState + || savedPowerHostId == null + || savedPowerHostId != powerHostId + || !isPowerStateInSyncWithInstanceState(powerState, powerHostId, instance)) { instance.setPowerState(powerState); instance.setPowerHostId(powerHostId); instance.setPowerStateUpdateCount(1); @@ -929,6 +929,17 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem }); } + private boolean isPowerStateInSyncWithInstanceState(final VirtualMachine.PowerState powerState, final long powerHostId, final VMInstanceVO instance) { + State instanceState = instance.getState(); + if ((powerState == VirtualMachine.PowerState.PowerOff && instanceState == State.Running) + || (powerState == VirtualMachine.PowerState.PowerOn && instanceState == State.Stopped)) { + logger.debug(String.format("VM id: %d on host id: %d and power host id: %d is in %s state, but power state is %s", + instance.getId(), instance.getHostId(), powerHostId, instanceState, powerState)); + return false; + } + return true; + } + @Override public boolean isPowerStateUpToDate(final long instanceId) { VMInstanceVO instance = findById(instanceId); diff --git a/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java b/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java index 1b1842dfd89..062960130ac 100644 --- a/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java @@ -21,7 +21,6 @@ import java.util.Date; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -36,7 +35,6 @@ import com.cloud.vm.snapshot.VMSnapshotVO; @Component public class VMSnapshotDaoImpl extends GenericDaoBase implements VMSnapshotDao { - private static final Logger s_logger = Logger.getLogger(VMSnapshotDaoImpl.class); private final SearchBuilder SnapshotSearch; private final SearchBuilder ExpungingSnapshotSearch; private final SearchBuilder SnapshotStatusSearch; @@ -143,7 +141,7 @@ public class VMSnapshotDaoImpl extends GenericDaoBase implem builder.set(vo, "updated", new Date()); int rows = update((VMSnapshotVO)vo, sc); - if (rows == 0 && s_logger.isDebugEnabled()) { + if (rows == 0 && logger.isDebugEnabled()) { VMSnapshotVO dbVol = findByIdIncludingRemoved(vo.getId()); if (dbVol != null) { StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); @@ -176,7 +174,7 @@ public class VMSnapshotDaoImpl extends GenericDaoBase implem .append("; updatedTime=") .append(oldUpdatedTime); } else { - s_logger.debug("Unable to update VM snapshot: id=" + vo.getId() + ", as there is no such snapshot exists in the database anymore"); + logger.debug("Unable to update VM snapshot: id=" + vo.getId() + ", as there is no such snapshot exists in the database anymore"); } } return rows > 0; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/ProjectRolePermissionsDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/ProjectRolePermissionsDaoImpl.java index d88a6f5453d..d028ca58b32 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/ProjectRolePermissionsDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/ProjectRolePermissionsDaoImpl.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.acl.ProjectRole; import org.apache.cloudstack.acl.RolePermissionEntity.Permission; import org.apache.cloudstack.acl.ProjectRolePermission; import org.apache.cloudstack.acl.ProjectRolePermissionVO; -import org.apache.log4j.Logger; import com.cloud.utils.db.Attribute; import com.cloud.utils.db.Filter; @@ -42,7 +41,6 @@ import com.cloud.utils.exception.CloudRuntimeException; public class ProjectRolePermissionsDaoImpl extends GenericDaoBase implements ProjectRolePermissionsDao{ - private static final Logger LOGGER = Logger.getLogger(ProjectRolePermissionsDaoImpl.class); private final SearchBuilder ProjectRolePermissionsSearch; private Attribute sortOrderAttribute; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDao.java b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDao.java index a776f7b6fe6..2d4151afc7d 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDao.java @@ -37,4 +37,6 @@ public interface RoleDao extends GenericDao { Pair, Integer> findAllByRoleType(RoleType type, Long offset, Long limit, boolean showPrivateRole); Pair, Integer> listAllRoles(Long startIndex, Long limit, boolean showPrivateRole); + + List searchByIds(Long... ids); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDaoImpl.java index 06d3108076a..2e8fdd5fcc2 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RoleDaoImpl.java @@ -28,10 +28,13 @@ import org.apache.cloudstack.acl.RoleVO; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; +import java.util.Collections; import java.util.List; @Component public class RoleDaoImpl extends GenericDaoBase implements RoleDao { + + private final SearchBuilder RoleByIdsSearch; private final SearchBuilder RoleByNameSearch; private final SearchBuilder RoleByTypeSearch; private final SearchBuilder RoleByNameAndTypeSearch; @@ -40,6 +43,10 @@ public class RoleDaoImpl extends GenericDaoBase implements RoleDao public RoleDaoImpl() { super(); + RoleByIdsSearch = createSearchBuilder(); + RoleByIdsSearch.and("idIN", RoleByIdsSearch.entity().getId(), SearchCriteria.Op.IN); + RoleByIdsSearch.done(); + RoleByNameSearch = createSearchBuilder(); RoleByNameSearch.and("roleName", RoleByNameSearch.entity().getName(), SearchCriteria.Op.LIKE); RoleByNameSearch.and("isPublicRole", RoleByNameSearch.entity().isPublicRole(), SearchCriteria.Op.EQ); @@ -116,6 +123,16 @@ public class RoleDaoImpl extends GenericDaoBase implements RoleDao return searchAndCount(sc, new Filter(RoleVO.class, "id", true, startIndex, limit)); } + @Override + public List searchByIds(Long... ids) { + if (ids == null || ids.length == 0) { + return Collections.emptyList(); + } + SearchCriteria sc = RoleByIdsSearch.create(); + sc.setParameters("idIN", ids); + return listBy(sc); + } + public void filterPrivateRolesIfNeeded(SearchCriteria sc, boolean showPrivateRole) { if (!showPrivateRole) { sc.setParameters("isPublicRole", true); diff --git a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RolePermissionsDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RolePermissionsDaoImpl.java index b63dd502ee7..7802265928e 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RolePermissionsDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/acl/dao/RolePermissionsDaoImpl.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.acl.Role; import org.apache.cloudstack.acl.RolePermission; import org.apache.cloudstack.acl.RolePermissionEntity.Permission; import org.apache.cloudstack.acl.RolePermissionVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Attribute; @@ -43,7 +42,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class RolePermissionsDaoImpl extends GenericDaoBase implements RolePermissionsDao { - protected static final Logger LOGGER = Logger.getLogger(RolePermissionsDaoImpl.class); private final SearchBuilder RolePermissionsSearchByRoleAndRule; private final SearchBuilder RolePermissionsSearch; @@ -90,7 +88,7 @@ public class RolePermissionsDaoImpl extends GenericDaoBase implements AffinityGroupDomainMapDao { - public static Logger logger = Logger.getLogger(NetworkDomainDaoImpl.class.getName()); private SearchBuilder ListByAffinityGroup; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java index e5582609d68..3e5db0443d8 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/backup/BackupVO.java @@ -17,6 +17,8 @@ package org.apache.cloudstack.backup; +import com.cloud.utils.db.GenericDao; + import java.util.Date; import java.util.UUID; @@ -55,6 +57,9 @@ public class BackupVO implements Backup { @Temporal(value = TemporalType.DATE) private Date date; + @Column(name = GenericDao.REMOVED_COLUMN) + private Date removed; + @Column(name = "size") private Long size; @@ -196,4 +201,12 @@ public class BackupVO implements Backup { public String getName() { return null; } + + public Date getRemoved() { + return removed; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadCertificateVO.java b/engine/schema/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadCertificateVO.java index 1e43e164ba4..36aefa201f3 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadCertificateVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/direct/download/DirectDownloadCertificateVO.java @@ -17,8 +17,10 @@ package org.apache.cloudstack.direct.download; import com.cloud.hypervisor.Hypervisor; +import org.apache.cloudstack.util.HypervisorTypeConverter; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -45,6 +47,7 @@ public class DirectDownloadCertificateVO implements DirectDownloadCertificate { private String certificate; @Column(name = "hypervisor_type") + @Convert(converter = HypervisorTypeConverter.class) private Hypervisor.HypervisorType hypervisorType; @Column(name = "zone_id") diff --git a/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java b/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java index 4b96dd1641a..af48e5e04ac 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/engine/cloud/entity/api/db/VMEntityVO.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.UUID; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.Entity; @@ -48,6 +49,7 @@ import com.cloud.utils.fsm.FiniteStateObject; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachine.State; import com.google.gson.Gson; +import org.apache.cloudstack.util.HypervisorTypeConverter; @Entity @Table(name = "vm_instance") @@ -146,7 +148,7 @@ public class VMEntityVO implements VirtualMachine, FiniteStateObject implements VMEntityDao { - public static final Logger s_logger = Logger.getLogger(VMEntityDaoImpl.class); @Inject protected VMReservationDao _vmReservationDao; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/ha/dao/HAConfigDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/ha/dao/HAConfigDaoImpl.java index 4d74e2e6656..1a27bb1de67 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/ha/dao/HAConfigDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/ha/dao/HAConfigDaoImpl.java @@ -31,7 +31,6 @@ import com.cloud.utils.db.UpdateBuilder; import org.apache.cloudstack.ha.HAConfig; import org.apache.cloudstack.ha.HAConfigVO; import org.apache.cloudstack.ha.HAResource; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.sql.PreparedStatement; @@ -42,7 +41,6 @@ import java.util.List; @DB @Component public class HAConfigDaoImpl extends GenericDaoBase implements HAConfigDao { - private static final Logger LOG = Logger.getLogger(HAConfigDaoImpl.class); private static final String EXPIRE_OWNERSHIP = "UPDATE ha_config set mgmt_server_id=NULL where mgmt_server_id=?"; @@ -77,8 +75,8 @@ public class HAConfigDaoImpl extends GenericDaoBase implements public boolean updateState(HAConfig.HAState currentState, HAConfig.Event event, HAConfig.HAState nextState, HAConfig vo, Object data) { HAConfigVO haConfig = (HAConfigVO) vo; if (haConfig == null) { - if (LOG.isTraceEnabled()) { - LOG.trace("Invalid ha config view object provided"); + if (logger.isTraceEnabled()) { + logger.trace("Invalid ha config view object provided"); } return false; } @@ -104,8 +102,8 @@ public class HAConfigDaoImpl extends GenericDaoBase implements ub.set(haConfig, MsIdAttr, newManagementServerId); int result = update(ub, sc, null); - if (LOG.isTraceEnabled() && result <= 0) { - LOG.trace(String.format("Failed to update HA state from:%s to:%s due to event:%s for the ha_config id:%d", currentState, nextState, event, haConfig.getId())); + if (logger.isTraceEnabled() && result <= 0) { + logger.trace(String.format("Failed to update HA state from:%s to:%s due to event:%s for the ha_config id:%d", currentState, nextState, event, haConfig.getId())); } return result > 0; } @@ -141,7 +139,7 @@ public class HAConfigDaoImpl extends GenericDaoBase implements pstmt.executeUpdate(); } catch (SQLException e) { txn.rollback(); - LOG.warn("Failed to expire HA ownership of management server id: " + serverId); + logger.warn("Failed to expire HA ownership of management server id: " + serverId); } } }); diff --git a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDaoImpl.java index ffc62b15dc2..c4214e8dfce 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/network/dao/NetworkPermissionDaoImpl.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.network.dao; import java.util.ArrayList; import java.util.List; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.network.NetworkPermissionVO; @@ -31,7 +30,6 @@ import com.cloud.utils.db.SearchCriteria; @Component public class NetworkPermissionDaoImpl extends GenericDaoBase implements NetworkPermissionDao { - private static final Logger s_logger = Logger.getLogger(NetworkPermissionDaoImpl.class); private SearchBuilder NetworkAndAccountSearch; private SearchBuilder NetworkIdSearch; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDaoImpl.java index af164326da7..375bb43e40e 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/outofbandmanagement/dao/OutOfBandManagementDaoImpl.java @@ -31,7 +31,6 @@ import com.cloud.utils.db.TransactionStatus; import com.cloud.utils.db.UpdateBuilder; import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement; import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import java.sql.PreparedStatement; @@ -41,7 +40,6 @@ import java.util.List; @DB @Component public class OutOfBandManagementDaoImpl extends GenericDaoBase implements OutOfBandManagementDao { - private static final Logger LOG = Logger.getLogger(OutOfBandManagementDaoImpl.class); private SearchBuilder HostSearch; private SearchBuilder ManagementServerSearch; @@ -109,7 +107,7 @@ public class OutOfBandManagementDaoImpl extends GenericDaoBase 0; } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/region/dao/RegionDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/region/dao/RegionDaoImpl.java index e2ad5d9ed23..1e53c925e08 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/region/dao/RegionDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/region/dao/RegionDaoImpl.java @@ -17,7 +17,6 @@ package org.apache.cloudstack.region.dao; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.region.RegionVO; @@ -28,7 +27,6 @@ import com.cloud.utils.db.SearchCriteria; @Component public class RegionDaoImpl extends GenericDaoBase implements RegionDao { - private static final Logger s_logger = Logger.getLogger(RegionDaoImpl.class); protected SearchBuilder NameSearch; protected SearchBuilder AllFieldsSearch; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java index e5636f0bfc9..df888312a92 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/ReservationVO.java @@ -18,10 +18,6 @@ // package org.apache.cloudstack.reservation; -import com.cloud.configuration.Resource; -import org.apache.cloudstack.user.ResourceReservation; -import com.cloud.utils.exception.CloudRuntimeException; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -29,6 +25,11 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import org.apache.cloudstack.user.ResourceReservation; + +import com.cloud.configuration.Resource; +import com.cloud.utils.exception.CloudRuntimeException; + @Entity @Table(name = "resource_reservation") public class ReservationVO implements ResourceReservation { @@ -47,22 +48,33 @@ public class ReservationVO implements ResourceReservation { @Column(name = "resource_type", nullable = false) Resource.ResourceType resourceType; + @Column(name = "tag") + String tag; + + @Column(name = "resource_id") + Long resourceId; + @Column(name = "amount") long amount; - protected ReservationVO() - {} + protected ReservationVO() { + } - public ReservationVO(Long accountId, Long domainId, Resource.ResourceType resourceType, Long delta) { - if (delta == null || delta <= 0) { - throw new CloudRuntimeException("resource reservations can not be made for no resources"); + public ReservationVO(Long accountId, Long domainId, Resource.ResourceType resourceType, String tag, Long delta) { + if (delta == null) { + throw new CloudRuntimeException("resource reservations can not be made for null resources"); } this.accountId = accountId; this.domainId = domainId; this.resourceType = resourceType; + this.tag = tag; this.amount = delta; } + public ReservationVO(Long accountId, Long domainId, Resource.ResourceType resourceType, Long delta) { + this(accountId, domainId, resourceType, null, delta); + } + @Override public long getId() { return this.id; @@ -83,8 +95,23 @@ public class ReservationVO implements ResourceReservation { return resourceType; } + @Override + public String getTag() { + return tag; + } + @Override public Long getReservedAmount() { return amount; } + + @Override + public Long getResourceId() { + return resourceId; + } + + public void setResourceId(long resourceId) { + this.resourceId = resourceId; + } + } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java index eead91c7b8e..0433dc8c57d 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDao.java @@ -18,11 +18,18 @@ // package org.apache.cloudstack.reservation.dao; -import com.cloud.configuration.Resource; import org.apache.cloudstack.reservation.ReservationVO; + +import com.cloud.configuration.Resource; import com.cloud.utils.db.GenericDao; +import java.util.List; + public interface ReservationDao extends GenericDao { - long getAccountReservation(Long account, Resource.ResourceType resourceType); - long getDomainReservation(Long domain, Resource.ResourceType resourceType); + long getAccountReservation(Long account, Resource.ResourceType resourceType, String tag); + long getDomainReservation(Long domain, Resource.ResourceType resourceType, String tag); + void setResourceId(Resource.ResourceType type, Long resourceId); + List getResourceIds(long accountId, Resource.ResourceType type); + List getReservationsForAccount(long accountId, Resource.ResourceType type, String tag); + void removeByIds(List reservationIds); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java index 6703de0b13c..8d6e0b6eee0 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/reservation/dao/ReservationDaoImpl.java @@ -18,41 +18,94 @@ // package org.apache.cloudstack.reservation.dao; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.reservation.ReservationVO; + import com.cloud.configuration.Resource; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; -import org.apache.cloudstack.reservation.ReservationVO; - -import java.util.List; +import org.apache.cloudstack.user.ResourceReservation; +import org.apache.commons.collections.CollectionUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ReservationDaoImpl extends GenericDaoBase implements ReservationDao { + protected transient Logger logger = LogManager.getLogger(getClass()); private static final String RESOURCE_TYPE = "resourceType"; + private static final String RESOURCE_TAG = "resourceTag"; + private static final String RESOURCE_ID = "resourceId"; private static final String ACCOUNT_ID = "accountId"; private static final String DOMAIN_ID = "domainId"; + private static final String IDS = "ids"; + private final SearchBuilder listResourceByAccountAndTypeSearch; private final SearchBuilder listAccountAndTypeSearch; + private final SearchBuilder listAccountAndTypeAndNoTagSearch; private final SearchBuilder listDomainAndTypeSearch; + private final SearchBuilder listDomainAndTypeAndNoTagSearch; + private final SearchBuilder listResourceByAccountAndTypeAndNoTagSearch; + private final SearchBuilder listIdsSearch; public ReservationDaoImpl() { + + listResourceByAccountAndTypeSearch = createSearchBuilder(); + listResourceByAccountAndTypeSearch.and(ACCOUNT_ID, listResourceByAccountAndTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeSearch.and(RESOURCE_TYPE, listResourceByAccountAndTypeSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeSearch.and(RESOURCE_ID, listResourceByAccountAndTypeSearch.entity().getResourceId(), SearchCriteria.Op.NNULL); + listResourceByAccountAndTypeSearch.and(RESOURCE_TAG, listResourceByAccountAndTypeSearch.entity().getTag(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeSearch.done(); + + listResourceByAccountAndTypeAndNoTagSearch = createSearchBuilder(); + listResourceByAccountAndTypeAndNoTagSearch.and(ACCOUNT_ID, listResourceByAccountAndTypeAndNoTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeAndNoTagSearch.and(RESOURCE_TYPE, listResourceByAccountAndTypeAndNoTagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listResourceByAccountAndTypeAndNoTagSearch.and(RESOURCE_ID, listResourceByAccountAndTypeAndNoTagSearch.entity().getResourceId(), SearchCriteria.Op.NNULL); + listResourceByAccountAndTypeAndNoTagSearch.and(RESOURCE_TAG, listResourceByAccountAndTypeAndNoTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + listResourceByAccountAndTypeAndNoTagSearch.done(); + listAccountAndTypeSearch = createSearchBuilder(); listAccountAndTypeSearch.and(ACCOUNT_ID, listAccountAndTypeSearch.entity().getAccountId(), SearchCriteria.Op.EQ); listAccountAndTypeSearch.and(RESOURCE_TYPE, listAccountAndTypeSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listAccountAndTypeSearch.and(RESOURCE_TAG, listAccountAndTypeSearch.entity().getTag(), SearchCriteria.Op.EQ); listAccountAndTypeSearch.done(); + listAccountAndTypeAndNoTagSearch = createSearchBuilder(); + listAccountAndTypeAndNoTagSearch.and(ACCOUNT_ID, listAccountAndTypeAndNoTagSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + listAccountAndTypeAndNoTagSearch.and(RESOURCE_TYPE, listAccountAndTypeAndNoTagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listAccountAndTypeAndNoTagSearch.and(RESOURCE_TAG, listAccountAndTypeAndNoTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + listAccountAndTypeAndNoTagSearch.done(); + listDomainAndTypeSearch = createSearchBuilder(); listDomainAndTypeSearch.and(DOMAIN_ID, listDomainAndTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ); listDomainAndTypeSearch.and(RESOURCE_TYPE, listDomainAndTypeSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listDomainAndTypeSearch.and(RESOURCE_TAG, listDomainAndTypeSearch.entity().getTag(), SearchCriteria.Op.EQ); listDomainAndTypeSearch.done(); + + listDomainAndTypeAndNoTagSearch = createSearchBuilder(); + listDomainAndTypeAndNoTagSearch.and(DOMAIN_ID, listDomainAndTypeAndNoTagSearch.entity().getDomainId(), SearchCriteria.Op.EQ); + listDomainAndTypeAndNoTagSearch.and(RESOURCE_TYPE, listDomainAndTypeAndNoTagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + listDomainAndTypeAndNoTagSearch.and(RESOURCE_TAG, listDomainAndTypeAndNoTagSearch.entity().getTag(), SearchCriteria.Op.NULL); + listDomainAndTypeAndNoTagSearch.done(); + + listIdsSearch = createSearchBuilder(); + listIdsSearch.and(IDS, listIdsSearch.entity().getId(), SearchCriteria.Op.IN); + listIdsSearch.done(); } @Override - public long getAccountReservation(Long accountId, Resource.ResourceType resourceType) { + public long getAccountReservation(Long accountId, Resource.ResourceType resourceType, String tag) { long total = 0; - SearchCriteria sc = listAccountAndTypeSearch.create(); + SearchCriteria sc = tag == null ? + listAccountAndTypeAndNoTagSearch.create() : listAccountAndTypeSearch.create(); sc.setParameters(ACCOUNT_ID, accountId); sc.setParameters(RESOURCE_TYPE, resourceType); + if (tag != null) { + sc.setParameters(RESOURCE_TAG, tag); + } List reservations = listBy(sc); for (ReservationVO reservation : reservations) { total += reservation.getReservedAmount(); @@ -61,15 +114,67 @@ public class ReservationDaoImpl extends GenericDaoBase impl } @Override - public long getDomainReservation(Long domainId, Resource.ResourceType resourceType) { + public long getDomainReservation(Long domainId, Resource.ResourceType resourceType, String tag) { long total = 0; - SearchCriteria sc = listDomainAndTypeSearch.create(); + SearchCriteria sc = tag == null ? + listDomainAndTypeAndNoTagSearch.create() : listDomainAndTypeSearch.create(); sc.setParameters(DOMAIN_ID, domainId); sc.setParameters(RESOURCE_TYPE, resourceType); + if (tag != null) { + sc.setParameters(RESOURCE_TAG, tag); + } List reservations = listBy(sc); for (ReservationVO reservation : reservations) { total += reservation.getReservedAmount(); } return total; } + + @Override + public void setResourceId(Resource.ResourceType type, Long resourceId) { + Object obj = CallContext.current().getContextParameter(String.format("%s-%s", ResourceReservation.class.getSimpleName(), type.getName())); + if (obj instanceof List) { + try { + List reservationIds = (List)obj; + for (Long reservationId : reservationIds) { + ReservationVO reservation = findById(reservationId); + if (reservation != null) { + reservation.setResourceId(resourceId); + persist(reservation); + } + } + } catch (Exception e) { + logger.warn("Failed to persist reservation for resource type " + type.getName() + " for resource id " + resourceId, e); + } + } + } + + @Override + public List getResourceIds(long accountId, Resource.ResourceType type) { + SearchCriteria sc = listResourceByAccountAndTypeSearch.create(); + sc.setParameters(ACCOUNT_ID, accountId); + sc.setParameters(RESOURCE_TYPE, type); + return listBy(sc).stream().map(ReservationVO::getResourceId).collect(Collectors.toList()); + } + + @Override + public List getReservationsForAccount(long accountId, Resource.ResourceType type, String tag) { + SearchCriteria sc = tag == null ? + listResourceByAccountAndTypeAndNoTagSearch.create() : listResourceByAccountAndTypeSearch.create(); + sc.setParameters(ACCOUNT_ID, accountId); + sc.setParameters(RESOURCE_TYPE, type); + if (tag != null) { + sc.setParameters(RESOURCE_TAG, tag); + } + return listBy(sc); + } + + @Override + public void removeByIds(List reservationIds) { + if (CollectionUtils.isNotEmpty(reservationIds)) { + SearchCriteria sc = listIdsSearch.create(); + sc.setParameters(IDS, reservationIds.toArray()); + remove(sc); + } + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/DiskOfferingDetailVO.java b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/DiskOfferingDetailVO.java index f4d98c3fb7f..7b0500680b9 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/DiskOfferingDetailVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/resourcedetail/DiskOfferingDetailVO.java @@ -65,6 +65,10 @@ public class DiskOfferingDetailVO implements ResourceDetail { return name; } + public void setName(String name) { + this.name = name; + } + @Override public String getValue() { return value; diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java index 1c31b3e0cc4..7aab5bbf7b3 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDao.java @@ -51,4 +51,6 @@ public interface ImageStoreDao extends GenericDao { ImageStoreVO findOneByZoneAndProtocol(long zoneId, String protocol); List listImageStoresByZoneIds(Long... zoneIds); + + List listByIds(List ids); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDaoImpl.java index a4827a1beae..84b88c215ca 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/ImageStoreDaoImpl.java @@ -18,12 +18,14 @@ */ package org.apache.cloudstack.storage.datastore.db; +import java.util.Collections; import java.util.List; import java.util.Map; import javax.naming.ConfigurationException; import com.cloud.utils.db.Filter; +import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; @@ -44,6 +46,7 @@ public class ImageStoreDaoImpl extends GenericDaoBase implem private SearchBuilder zoneProtocolSearch; private SearchBuilder zonesInSearch; + private SearchBuilder IdsSearch; public ImageStoreDaoImpl() { super(); @@ -62,6 +65,9 @@ public class ImageStoreDaoImpl extends GenericDaoBase implem zonesInSearch.and("zonesIn", zonesInSearch.entity().getDcId(), SearchCriteria.Op.IN); zonesInSearch.done(); + IdsSearch = createSearchBuilder(); + IdsSearch.and("ids", IdsSearch.entity().getId(), SearchCriteria.Op.IN); + IdsSearch.done(); } @Override public boolean configure(String name, Map params) throws ConfigurationException { @@ -206,4 +212,14 @@ public class ImageStoreDaoImpl extends GenericDaoBase implem sc.setParametersIfNotNull("zonesIn", zoneIds); return listBy(sc); } + + @Override + public List listByIds(List ids) { + if (CollectionUtils.isEmpty(ids)) { + return Collections.emptyList(); + } + SearchCriteria sc = IdsSearch.create(); + sc.setParameters("ids", ids.toArray()); + return listBy(sc); + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java index 8f77b4ba63e..d42e863cbed 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java @@ -21,7 +21,10 @@ import java.util.Map; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.ScopeType; +import com.cloud.storage.Storage; import com.cloud.storage.StoragePoolStatus; +import com.cloud.utils.Pair; +import com.cloud.utils.db.Filter; import com.cloud.utils.db.GenericDao; /** @@ -39,6 +42,8 @@ public interface PrimaryDataStoreDao extends GenericDao { */ List listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope); + List listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope, String keyword); + /** * Set capacity of storage pool in bytes * @param id pool id. @@ -114,15 +119,19 @@ public interface PrimaryDataStoreDao extends GenericDao { List findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags, boolean validateTagRule); + List findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags, boolean validateTagRule, String keyword); + List findZoneWideStoragePoolsByTags(long dcId, String[] tags, boolean validateTagRule); List findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType); + List findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType, String keyword); + List findLocalStoragePoolsByHostAndTags(long hostId, String[] tags); List listLocalStoragePoolByPath(long datacenterId, String path); - List findPoolsInClusters(List clusterIds); + List findPoolsInClusters(List clusterIds, String keyword); void deletePoolTags(long poolId); @@ -130,7 +139,13 @@ public interface PrimaryDataStoreDao extends GenericDao { Integer countAll(); - List findPoolsByStorageType(String storageType); + List findPoolsByStorageType(Storage.StoragePoolType storageType); List listStoragePoolsWithActiveVolumesByOfferingId(long offeringid); + + Pair, Integer> searchForIdsAndCount(Long storagePoolId, String storagePoolName, Long zoneId, + String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status, + String keyword, Filter searchFilter); + + List listByIds(List ids); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java index af7dbdc0225..e4dd66a86b8 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -20,17 +20,22 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.utils.Pair; +import com.cloud.utils.db.Filter; import org.apache.commons.collections.CollectionUtils; import com.cloud.host.Status; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.ScopeType; +import com.cloud.storage.Storage; import com.cloud.storage.StoragePoolHostVO; import com.cloud.storage.StoragePoolStatus; import com.cloud.storage.StoragePoolTagVO; @@ -57,6 +62,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase private final SearchBuilder DcLocalStorageSearch; private final GenericSearchBuilder StatusCountSearch; private final SearchBuilder ClustersSearch; + private final SearchBuilder IdsSearch; @Inject private StoragePoolDetailsDao _detailsDao; @@ -143,6 +149,11 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase ClustersSearch = createSearchBuilder(); ClustersSearch.and("clusterIds", ClustersSearch.entity().getClusterId(), Op.IN); ClustersSearch.and("status", ClustersSearch.entity().getStatus(), Op.EQ); + ClustersSearch.done(); + + IdsSearch = createSearchBuilder(); + IdsSearch.and("ids", IdsSearch.entity().getId(), SearchCriteria.Op.IN); + IdsSearch.done(); } @@ -243,6 +254,11 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase @Override public List listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope) { + return listBy(datacenterId, podId, clusterId, scope, null); + } + + @Override + public List listBy(long datacenterId, Long podId, Long clusterId, ScopeType scope, String keyword) { SearchCriteria sc = null; if (clusterId != null) { sc = DcPodSearch.create(); @@ -254,6 +270,9 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase sc.setParameters("datacenterId", datacenterId); sc.setParameters("podId", podId); sc.setParameters("status", Status.Up); + if (keyword != null) { + sc.addAnd("name", Op.LIKE, "%" + keyword + "%"); + } if (scope != null) { sc.setParameters("scope", scope); } @@ -443,9 +462,14 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase @Override public List findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags, boolean validateTagRule) { + return findLocalStoragePoolsByTags(dcId, podId, clusterId, tags, validateTagRule, null); + } + + @Override + public List findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags, boolean validateTagRule, String keyword) { List storagePools = null; if (tags == null || tags.length == 0) { - storagePools = listBy(dcId, podId, clusterId, ScopeType.HOST); + storagePools = listBy(dcId, podId, clusterId, ScopeType.HOST, keyword); if (validateTagRule) { storagePools = getPoolsWithoutTagRule(storagePools); @@ -582,11 +606,19 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase @Override public List findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType) { + return findZoneWideStoragePoolsByHypervisor(dataCenterId, hypervisorType, null); + } + + @Override + public List findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType, String keyword) { QueryBuilder sc = QueryBuilder.create(StoragePoolVO.class); sc.and(sc.entity().getDataCenterId(), Op.EQ, dataCenterId); sc.and(sc.entity().getStatus(), Op.EQ, Status.Up); sc.and(sc.entity().getScope(), Op.EQ, ScopeType.ZONE); sc.and(sc.entity().getHypervisor(), Op.EQ, hypervisorType); + if (keyword != null) { + sc.and(sc.entity().getName(), Op.LIKE, "%" + keyword + "%"); + } return sc.list(); } @@ -611,15 +643,18 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase } @Override - public List findPoolsInClusters(List clusterIds) { + public List findPoolsInClusters(List clusterIds, String keyword) { SearchCriteria sc = ClustersSearch.create(); sc.setParameters("clusterIds", clusterIds.toArray()); sc.setParameters("status", StoragePoolStatus.Up); + if (keyword != null) { + sc.addAnd("name", Op.LIKE, "%" + keyword + "%"); + } return listBy(sc); } @Override - public List findPoolsByStorageType(String storageType) { + public List findPoolsByStorageType(Storage.StoragePoolType storageType) { SearchCriteria sc = AllFieldSearch.create(); sc.setParameters("poolType", storageType); return listBy(sc); @@ -645,4 +680,92 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase throw new CloudRuntimeException("Caught: " + sql, e); } } + + @Override + public Pair, Integer> searchForIdsAndCount(Long storagePoolId, String storagePoolName, Long zoneId, + String path, Long podId, Long clusterId, String address, ScopeType scopeType, StoragePoolStatus status, + String keyword, Filter searchFilter) { + SearchCriteria sc = createStoragePoolSearchCriteria(storagePoolId, storagePoolName, zoneId, path, podId, clusterId, address, scopeType, status, keyword); + Pair, Integer> uniquePair = searchAndCount(sc, searchFilter); + List idList = uniquePair.first().stream().map(StoragePoolVO::getId).collect(Collectors.toList()); + return new Pair<>(idList, uniquePair.second()); + } + + @Override + public List listByIds(List ids) { + if (CollectionUtils.isEmpty(ids)) { + return Collections.emptyList(); + } + SearchCriteria sc = IdsSearch.create(); + sc.setParameters("ids", ids.toArray()); + return listBy(sc); + } + + private SearchCriteria createStoragePoolSearchCriteria(Long storagePoolId, String storagePoolName, + Long zoneId, String path, Long podId, Long clusterId, String address, ScopeType scopeType, + StoragePoolStatus status, String keyword) { + SearchBuilder sb = createSearchBuilder(); + sb.select(null, SearchCriteria.Func.DISTINCT, sb.entity().getId()); // select distinct + // ids + sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); + sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); + sb.and("path", sb.entity().getPath(), SearchCriteria.Op.EQ); + sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); + sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); + sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ); + sb.and("hostAddress", sb.entity().getHostAddress(), SearchCriteria.Op.EQ); + sb.and("scope", sb.entity().getScope(), SearchCriteria.Op.EQ); + sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ); + sb.and("parent", sb.entity().getParent(), SearchCriteria.Op.EQ); + + SearchCriteria sc = sb.create(); + + if (keyword != null) { + SearchCriteria ssc = createSearchCriteria(); + ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); + ssc.addOr("poolType", SearchCriteria.Op.LIKE, new Storage.StoragePoolType("%" + keyword + "%")); + + sc.addAnd("name", SearchCriteria.Op.SC, ssc); + } + + if (storagePoolId != null) { + sc.setParameters("id", storagePoolId); + } + + if (storagePoolName != null) { + sc.setParameters("name", storagePoolName); + } + + if (path != null) { + sc.setParameters("path", path); + } + if (zoneId != null) { + sc.setParameters("dataCenterId", zoneId); + } + if (podId != null) { + SearchCriteria ssc = createSearchCriteria(); + ssc.addOr("podId", SearchCriteria.Op.EQ, podId); + ssc.addOr("podId", SearchCriteria.Op.NULL); + + sc.addAnd("podId", SearchCriteria.Op.SC, ssc); + } + if (address != null) { + sc.setParameters("hostAddress", address); + } + if (clusterId != null) { + SearchCriteria ssc = createSearchCriteria(); + ssc.addOr("clusterId", SearchCriteria.Op.EQ, clusterId); + ssc.addOr("clusterId", SearchCriteria.Op.NULL); + + sc.addAnd("clusterId", SearchCriteria.Op.SC, ssc); + } + if (scopeType != null) { + sc.setParameters("scope", scopeType.toString()); + } + if (status != null) { + sc.setParameters("status", status.toString()); + } + sc.setParameters("parent", 0); + return sc; + } } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java index 98cb6ca5b42..c095f4222e7 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreState import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.hypervisor.Hypervisor; @@ -50,7 +49,6 @@ import com.cloud.utils.db.UpdateBuilder; @Component public class SnapshotDataStoreDaoImpl extends GenericDaoBase implements SnapshotDataStoreDao { - private static final Logger s_logger = Logger.getLogger(SnapshotDataStoreDaoImpl.class); private static final String STORE_ID = "store_id"; private static final String STORE_ROLE = "store_role"; private static final String STATE = "state"; @@ -188,7 +186,7 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase snapshots = listBy(sc); if (snapshots == null) { - s_logger.debug(String.format("There are no snapshots on cache store to duplicate to region store [%s].", storeId)); + logger.debug(String.format("There are no snapshots on cache store to duplicate to region store [%s].", storeId)); return; } - s_logger.info(String.format("Duplicating [%s] snapshot cache store records to region store [%s].", snapshots.size(), storeId)); + logger.info(String.format("Duplicating [%s] snapshot cache store records to region store [%s].", snapshots.size(), storeId)); for (SnapshotDataStoreVO snap : snapshots) { SnapshotDataStoreVO snapStore = findByStoreSnapshot(DataStoreRole.Image, storeId, snap.getSnapshotId()); if (snapStore != null) { - s_logger.debug(String.format("There is already an entry for snapshot [%s] on region store [%s].", snap.getSnapshotId(), storeId)); + logger.debug(String.format("There is already an entry for snapshot [%s] on region store [%s].", snap.getSnapshotId(), storeId)); continue; } - s_logger.info(String.format("Persisting an entry for snapshot [%s] on region store [%s].", snap.getSnapshotId(), storeId)); + logger.info(String.format("Persisting an entry for snapshot [%s] on region store [%s].", snap.getSnapshotId(), storeId)); SnapshotDataStoreVO ss = new SnapshotDataStoreVO(); ss.setSnapshotId(snap.getSnapshotId()); ss.setDataStoreId(storeId); @@ -434,9 +432,9 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase snaps = listBy(sc); if (snaps != null) { - s_logger.info(String.format("Updating role to cache store for [%s] entries in snapshot_store_ref.", snaps.size())); + logger.info(String.format("Updating role to cache store for [%s] entries in snapshot_store_ref.", snaps.size())); for (SnapshotDataStoreVO snap : snaps) { - s_logger.debug(String.format("Updating role to cache store for entry [%s].", snap)); + logger.debug(String.format("Updating role to cache store for entry [%s].", snap)); snap.setRole(DataStoreRole.ImageCache); update(snap.getId(), snap); } diff --git a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java index 6f6ed4e08f2..a1dc05fce58 100644 --- a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java +++ b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreVO.java @@ -29,7 +29,8 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; @@ -47,7 +48,7 @@ import com.cloud.utils.fsm.StateObject; @Entity @Table(name = "snapshot_store_ref") public class SnapshotDataStoreVO implements StateObject, DataObjectInStore { - private static final Logger s_logger = Logger.getLogger(SnapshotDataStoreVO.class); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -297,7 +298,7 @@ public class SnapshotDataStoreVO implements StateObject, DataObjectInStore { - private static final Logger s_logger = Logger.getLogger(TemplateDataStoreVO.class); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -382,7 +383,7 @@ public class TemplateDataStoreVO implements StateObject, DataObjectInStore { - private static final Logger s_logger = Logger.getLogger(VolumeDataStoreVO.class); + protected transient Logger logger = LogManager.getLogger(getClass()); @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -362,7 +363,7 @@ public class VolumeDataStoreVO implements StateObject { + @Override + public String convertToDatabaseColumn(Hypervisor.HypervisorType attribute) { + return attribute != null ? attribute.name() : null; + } + + @Override + public Hypervisor.HypervisorType convertToEntityAttribute(String dbData) { + return dbData != null ? Hypervisor.HypervisorType.valueOf(dbData) : null; + } +} diff --git a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-common-daos-between-management-and-usage-context.xml b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-common-daos-between-management-and-usage-context.xml index 0c46c5ff934..80a92426f17 100644 --- a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-common-daos-between-management-and-usage-context.xml +++ b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-common-daos-between-management-and-usage-context.xml @@ -68,5 +68,6 @@ + diff --git a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml index 5d958383161..5df32fb4731 100644 --- a/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml +++ b/engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml @@ -136,6 +136,7 @@ + @@ -157,7 +158,6 @@ - diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql b/engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql index 27170fcac14..a6f45c261ce 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql @@ -21,6 +21,8 @@ ALTER TABLE `cloud`.`mshost` MODIFY COLUMN `state` varchar(25); +UPDATE `cloud`.`network_offerings` SET conserve_mode=1 WHERE name='DefaultIsolatedNetworkOfferingForVpcNetworks'; + -- Invalidate existing console_session records UPDATE `cloud`.`console_session` SET removed=now(); -- Modify acquired column in console_session to datetime type @@ -314,3 +316,10 @@ CREATE TABLE `cloud_usage`.`bucket_statistics` ( `size` bigint unsigned COMMENT 'total size of bucket objects', PRIMARY KEY(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- Add remover account ID to quarantined IPs table. +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.quarantined_ips', 'remover_account_id', 'bigint(20) unsigned DEFAULT NULL COMMENT "ID of the account that removed the IP from quarantine, foreign key to `account` table"'); + +-- Explicitly add support for VMware 8.0b (8.0.0.2), 8.0c (8.0.0.3) +INSERT IGNORE INTO `cloud`.`hypervisor_capabilities` (uuid, hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled, max_data_volumes_limit, max_hosts_per_cluster, storage_motion_supported, vm_snapshot_enabled) values (UUID(), 'VMware', '8.0.0.2', 1024, 0, 59, 64, 1, 1); +INSERT IGNORE INTO `cloud`.`hypervisor_capabilities` (uuid, hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled, max_data_volumes_limit, max_hosts_per_cluster, storage_motion_supported, vm_snapshot_enabled) values (UUID(), 'VMware', '8.0.0.3', 1024, 0, 59, 64, 1, 1); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41900to41910-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-41900to41910-cleanup.sql new file mode 100644 index 00000000000..b580d42686f --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/schema-41900to41910-cleanup.sql @@ -0,0 +1,20 @@ +-- 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. + +--; +-- Schema upgrade cleanup from 4.19.0.0 to 4.19.1.0 +--; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41900to41910.sql b/engine/schema/src/main/resources/META-INF/db/schema-41900to41910.sql new file mode 100644 index 00000000000..e704d61d70c --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/schema-41900to41910.sql @@ -0,0 +1,32 @@ +-- 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. + +--; +-- Schema upgrade from 4.19.0.0 to 4.19.1.0 +--; + +-- Updates the populated Quota tariff's types VM_DISK_BYTES_READ, VM_DISK_BYTES_WRITE, VM_DISK_IO_READ and VM_DISK_IO_WRITE to the correct unit. + +UPDATE cloud_usage.quota_tariff +SET usage_unit = 'Bytes', updated_on = NOW() +WHERE effective_on = '2010-05-04 00:00:00' +AND name IN ('VM_DISK_BYTES_READ', 'VM_DISK_BYTES_WRITE'); + +UPDATE cloud_usage.quota_tariff +SET usage_unit = 'IOPS', updated_on = NOW() +WHERE effective_on = '2010-05-04 00:00:00' +AND name IN ('VM_DISK_IO_READ', 'VM_DISK_IO_WRITE'); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41900to42000-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-41900to42000-cleanup.sql new file mode 100644 index 00000000000..4bbeadaf811 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/schema-41900to42000-cleanup.sql @@ -0,0 +1,20 @@ +-- 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. + +--; +-- Schema upgrade cleanup from 4.19.0.0 to 4.20.0.0 +--; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41900to42000.sql b/engine/schema/src/main/resources/META-INF/db/schema-41900to42000.sql new file mode 100644 index 00000000000..1bb1905443a --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/schema-41900to42000.sql @@ -0,0 +1,81 @@ +-- 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. + +--; +-- Schema upgrade from 4.19.0.0 to 4.20.0.0 +--; + +-- Add tag column to tables +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_limit', 'tag', 'varchar(64) DEFAULT NULL COMMENT "tag for the limit" '); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_count', 'tag', 'varchar(64) DEFAULT NULL COMMENT "tag for the resource count" '); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.resource_reservation', 'tag', 'varchar(64) DEFAULT NULL COMMENT "tag for the resource reservation" '); +ALTER TABLE `resource_count` +DROP INDEX `i_resource_count__type_accountId`, +DROP INDEX `i_resource_count__type_domaintId`, +ADD UNIQUE INDEX `i_resource_count__type_tag_accountId` (`type`,`tag`,`account_id`), +ADD UNIQUE INDEX `i_resource_count__type_tag_domaintId` (`type`,`tag`,`domain_id`); + + +ALTER TABLE `cloud`.`resource_reservation` + ADD COLUMN `resource_id` bigint unsigned NULL; + +ALTER TABLE `cloud`.`resource_reservation` + MODIFY COLUMN `amount` bigint NOT NULL; + + +-- Update Default System offering for Router to 512MiB +UPDATE `cloud`.`service_offering` SET ram_size = 512 WHERE unique_name IN ("Cloud.Com-SoftwareRouter", "Cloud.Com-SoftwareRouter-Local", + "Cloud.Com-InternalLBVm", "Cloud.Com-InternalLBVm-Local", + "Cloud.Com-ElasticLBVm", "Cloud.Com-ElasticLBVm-Local") + AND system_use = 1 AND ram_size < 512; + +-- NSX Plugin -- +CREATE TABLE `cloud`.`nsx_providers` ( + `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', + `uuid` varchar(40), + `zone_id` bigint unsigned NOT NULL COMMENT 'Zone ID', + `host_id` bigint unsigned NOT NULL COMMENT 'Host ID', + `provider_name` varchar(40), + `hostname` varchar(255) NOT NULL, + `port` varchar(255), + `username` varchar(255) NOT NULL, + `password` varchar(255) NOT NULL, + `tier0_gateway` varchar(255), + `edge_cluster` varchar(255), + `transport_zone` varchar(255), + `created` datetime NOT NULL COMMENT 'date created', + `removed` datetime COMMENT 'date removed if not null', + PRIMARY KEY (`id`), + CONSTRAINT `fk_nsx_providers__zone_id` FOREIGN KEY `fk_nsx_providers__zone_id` (`zone_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE, + INDEX `i_nsx_providers__zone_id`(`zone_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- NSX Plugin -- +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings','for_nsx', 'int(1) unsigned DEFAULT "0" COMMENT "is nsx enabled for the resource"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.network_offerings','nsx_mode', 'varchar(32) COMMENT "mode in which the network would route traffic"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','for_nsx', 'int(1) unsigned DEFAULT "0" COMMENT "is nsx enabled for the resource"'); +CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','nsx_mode', 'varchar(32) COMMENT "mode in which the network would route traffic"'); + + +-- Create table to persist quota email template configurations +CREATE TABLE IF NOT EXISTS `cloud_usage`.`quota_email_configuration`( + `account_id` int(11) NOT NULL, + `email_template_id` bigint(20) NOT NULL, + `enabled` int(1) UNSIGNED NOT NULL, + PRIMARY KEY (`account_id`, `email_template_id`), + CONSTRAINT `FK_quota_email_configuration_account_id` FOREIGN KEY (`account_id`) REFERENCES `cloud_usage`.`quota_account`(`account_id`), + CONSTRAINT `FK_quota_email_configuration_email_template_id` FOREIGN KEY (`email_template_id`) REFERENCES `cloud_usage`.`quota_email_templates`(`id`)); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.account_netstats_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_netstats_view.sql new file mode 100644 index 00000000000..11193c465fd --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_netstats_view.sql @@ -0,0 +1,31 @@ +-- 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. + +-- cloud.account_netstats_view source + + +DROP VIEW IF EXISTS `cloud`.`account_netstats_view`; + +CREATE VIEW `cloud`.`account_netstats_view` AS +select + `user_statistics`.`account_id` AS `account_id`, + (sum(`user_statistics`.`net_bytes_received`) + sum(`user_statistics`.`current_bytes_received`)) AS `bytesReceived`, + (sum(`user_statistics`.`net_bytes_sent`) + sum(`user_statistics`.`current_bytes_sent`)) AS `bytesSent` +from + `user_statistics` +group by + `user_statistics`.`account_id`; diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql new file mode 100644 index 00000000000..87546a9d118 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_view.sql @@ -0,0 +1,164 @@ +-- 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. + +-- VIEW `cloud`.`account_view`; + +DROP VIEW IF EXISTS `cloud`.`account_view`; +CREATE VIEW `cloud`.`account_view` AS +select + `account`.`id` AS `id`, + `account`.`uuid` AS `uuid`, + `account`.`account_name` AS `account_name`, + `account`.`type` AS `type`, + `account`.`role_id` AS `role_id`, + `account`.`state` AS `state`, + `account`.`created` AS `created`, + `account`.`removed` AS `removed`, + `account`.`cleanup_needed` AS `cleanup_needed`, + `account`.`network_domain` AS `network_domain` , + `account`.`default` AS `default`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path`, + `data_center`.`id` AS `data_center_id`, + `data_center`.`uuid` AS `data_center_uuid`, + `data_center`.`name` AS `data_center_name`, + `account_netstats_view`.`bytesReceived` AS `bytesReceived`, + `account_netstats_view`.`bytesSent` AS `bytesSent`, + `vmlimit`.`max` AS `vmLimit`, + `vmcount`.`count` AS `vmTotal`, + `runningvm`.`vmcount` AS `runningVms`, + `stoppedvm`.`vmcount` AS `stoppedVms`, + `iplimit`.`max` AS `ipLimit`, + `ipcount`.`count` AS `ipTotal`, + `free_ip_view`.`free_ip` AS `ipFree`, + `volumelimit`.`max` AS `volumeLimit`, + `volumecount`.`count` AS `volumeTotal`, + `snapshotlimit`.`max` AS `snapshotLimit`, + `snapshotcount`.`count` AS `snapshotTotal`, + `templatelimit`.`max` AS `templateLimit`, + `templatecount`.`count` AS `templateTotal`, + `vpclimit`.`max` AS `vpcLimit`, + `vpccount`.`count` AS `vpcTotal`, + `projectlimit`.`max` AS `projectLimit`, + `projectcount`.`count` AS `projectTotal`, + `networklimit`.`max` AS `networkLimit`, + `networkcount`.`count` AS `networkTotal`, + `cpulimit`.`max` AS `cpuLimit`, + `cpucount`.`count` AS `cpuTotal`, + `memorylimit`.`max` AS `memoryLimit`, + `memorycount`.`count` AS `memoryTotal`, + `primary_storage_limit`.`max` AS `primaryStorageLimit`, + `primary_storage_count`.`count` AS `primaryStorageTotal`, + `secondary_storage_limit`.`max` AS `secondaryStorageLimit`, + `secondary_storage_count`.`count` AS `secondaryStorageTotal`, + `async_job`.`id` AS `job_id`, + `async_job`.`uuid` AS `job_uuid`, + `async_job`.`job_status` AS `job_status`, + `async_job`.`account_id` AS `job_account_id` +from + `cloud`.`free_ip_view`, + `cloud`.`account` + inner join + `cloud`.`domain` ON account.domain_id = domain.id + left join + `cloud`.`data_center` ON account.default_zone_id = data_center.id + left join + `cloud`.`account_netstats_view` ON account.id = account_netstats_view.account_id + left join + `cloud`.`resource_limit` vmlimit ON account.id = vmlimit.account_id + and vmlimit.type = 'user_vm' and vmlimit.tag IS NULL + left join + `cloud`.`resource_count` vmcount ON account.id = vmcount.account_id + and vmcount.type = 'user_vm' and vmcount.tag IS NULL + left join + `cloud`.`account_vmstats_view` runningvm ON account.id = runningvm.account_id + and runningvm.state = 'Running' + left join + `cloud`.`account_vmstats_view` stoppedvm ON account.id = stoppedvm.account_id + and stoppedvm.state = 'Stopped' + left join + `cloud`.`resource_limit` iplimit ON account.id = iplimit.account_id + and iplimit.type = 'public_ip' + left join + `cloud`.`resource_count` ipcount ON account.id = ipcount.account_id + and ipcount.type = 'public_ip' + left join + `cloud`.`resource_limit` volumelimit ON account.id = volumelimit.account_id + and volumelimit.type = 'volume' and volumelimit.tag IS NULL + left join + `cloud`.`resource_count` volumecount ON account.id = volumecount.account_id + and volumecount.type = 'volume' and volumecount.tag IS NULL + left join + `cloud`.`resource_limit` snapshotlimit ON account.id = snapshotlimit.account_id + and snapshotlimit.type = 'snapshot' + left join + `cloud`.`resource_count` snapshotcount ON account.id = snapshotcount.account_id + and snapshotcount.type = 'snapshot' + left join + `cloud`.`resource_limit` templatelimit ON account.id = templatelimit.account_id + and templatelimit.type = 'template' + left join + `cloud`.`resource_count` templatecount ON account.id = templatecount.account_id + and templatecount.type = 'template' + left join + `cloud`.`resource_limit` vpclimit ON account.id = vpclimit.account_id + and vpclimit.type = 'vpc' + left join + `cloud`.`resource_count` vpccount ON account.id = vpccount.account_id + and vpccount.type = 'vpc' + left join + `cloud`.`resource_limit` projectlimit ON account.id = projectlimit.account_id + and projectlimit.type = 'project' + left join + `cloud`.`resource_count` projectcount ON account.id = projectcount.account_id + and projectcount.type = 'project' + left join + `cloud`.`resource_limit` networklimit ON account.id = networklimit.account_id + and networklimit.type = 'network' + left join + `cloud`.`resource_count` networkcount ON account.id = networkcount.account_id + and networkcount.type = 'network' + left join + `cloud`.`resource_limit` cpulimit ON account.id = cpulimit.account_id + and cpulimit.type = 'cpu' and cpulimit.tag IS NULL + left join + `cloud`.`resource_count` cpucount ON account.id = cpucount.account_id + and cpucount.type = 'cpu' and cpucount.tag IS NULL + left join + `cloud`.`resource_limit` memorylimit ON account.id = memorylimit.account_id + and memorylimit.type = 'memory' and memorylimit.tag IS NULL + left join + `cloud`.`resource_count` memorycount ON account.id = memorycount.account_id + and memorycount.type = 'memory' and memorycount.tag IS NULL + left join + `cloud`.`resource_limit` primary_storage_limit ON account.id = primary_storage_limit.account_id + and primary_storage_limit.type = 'primary_storage' and primary_storage_limit.tag IS NULL + left join + `cloud`.`resource_count` primary_storage_count ON account.id = primary_storage_count.account_id + and primary_storage_count.type = 'primary_storage' and primary_storage_count.tag IS NULL + left join + `cloud`.`resource_limit` secondary_storage_limit ON account.id = secondary_storage_limit.account_id + and secondary_storage_limit.type = 'secondary_storage' + left join + `cloud`.`resource_count` secondary_storage_count ON account.id = secondary_storage_count.account_id + and secondary_storage_count.type = 'secondary_storage' + left join + `cloud`.`async_job` ON async_job.instance_id = account.id + and async_job.instance_type = 'Account' + and async_job.job_status = 0; diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.account_vmstats_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_vmstats_view.sql new file mode 100644 index 00000000000..df6a216b0f8 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.account_vmstats_view.sql @@ -0,0 +1,35 @@ +-- 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. + +-- cloud.account_vmstats_view source + + +DROP VIEW IF EXISTS `cloud`.`account_vmstats_view`; + +CREATE VIEW `cloud`.`account_vmstats_view` AS +select + `vm_instance`.`account_id` AS `account_id`, + `vm_instance`.`state` AS `state`, + count(0) AS `vmcount` +from + `vm_instance` +where + ((`vm_instance`.`vm_type` = 'User') + and (`vm_instance`.`removed` is null)) +group by + `vm_instance`.`account_id`, + `vm_instance`.`state`; diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.affinity_group_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.affinity_group_view.sql new file mode 100644 index 00000000000..90a398e1ec5 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.affinity_group_view.sql @@ -0,0 +1,60 @@ +-- 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. + +-- cloud.affinity_group_view source + + +DROP VIEW IF EXISTS `cloud`.`affinity_group_view`; + +CREATE VIEW `cloud`.`affinity_group_view` AS +select + `affinity_group`.`id` AS `id`, + `affinity_group`.`name` AS `name`, + `affinity_group`.`type` AS `type`, + `affinity_group`.`description` AS `description`, + `affinity_group`.`uuid` AS `uuid`, + `affinity_group`.`acl_type` AS `acl_type`, + `account`.`id` AS `account_id`, + `account`.`uuid` AS `account_uuid`, + `account`.`account_name` AS `account_name`, + `account`.`type` AS `account_type`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path`, + `projects`.`id` AS `project_id`, + `projects`.`uuid` AS `project_uuid`, + `projects`.`name` AS `project_name`, + `vm_instance`.`id` AS `vm_id`, + `vm_instance`.`uuid` AS `vm_uuid`, + `vm_instance`.`name` AS `vm_name`, + `vm_instance`.`state` AS `vm_state`, + `user_vm`.`display_name` AS `vm_display_name` +from + ((((((`affinity_group` +join `account` on + ((`affinity_group`.`account_id` = `account`.`id`))) +join `domain` on + ((`affinity_group`.`domain_id` = `domain`.`id`))) +left join `projects` on + ((`projects`.`project_account_id` = `account`.`id`))) +left join `affinity_group_vm_map` on + ((`affinity_group`.`id` = `affinity_group_vm_map`.`affinity_group_id`))) +left join `vm_instance` on + ((`vm_instance`.`id` = `affinity_group_vm_map`.`instance_id`))) +left join `user_vm` on + ((`user_vm`.`id` = `vm_instance`.`id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.disk_offering_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.disk_offering_view.sql index 10dd3c2f9de..dffaec575ce 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.disk_offering_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.disk_offering_view.sql @@ -76,7 +76,5 @@ FROM LEFT JOIN `cloud`.`disk_offering_details` AS `vsphere_storage_policy` ON `vsphere_storage_policy`.`offering_id` = `disk_offering`.`id` AND `vsphere_storage_policy`.`name` = 'storagepolicy' -WHERE - `disk_offering`.`state`='Active' GROUP BY `disk_offering`.`id`; diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql new file mode 100644 index 00000000000..201ece95023 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_view.sql @@ -0,0 +1,135 @@ +-- 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. + +-- VIEW `cloud`.`domain_view`; + +DROP VIEW IF EXISTS `cloud`.`domain_view`; + +CREATE VIEW `cloud`.`domain_view` AS +select + `domain`.`id` AS `id`, + `domain`.`parent` AS `parent`, + `domain`.`name` AS `name`, + `domain`.`uuid` AS `uuid`, + `domain`.`owner` AS `owner`, + `domain`.`path` AS `path`, + `domain`.`level` AS `level`, + `domain`.`child_count` AS `child_count`, + `domain`.`next_child_seq` AS `next_child_seq`, + `domain`.`created` AS `created`, + `domain`.`removed` AS `removed`, + `domain`.`state` AS `state`, + `domain`.`network_domain` AS `network_domain`, + `domain`.`type` AS `type`, + `vmlimit`.`max` AS `vmLimit`, + `vmcount`.`count` AS `vmTotal`, + `iplimit`.`max` AS `ipLimit`, + `ipcount`.`count` AS `ipTotal`, + `volumelimit`.`max` AS `volumeLimit`, + `volumecount`.`count` AS `volumeTotal`, + `snapshotlimit`.`max` AS `snapshotLimit`, + `snapshotcount`.`count` AS `snapshotTotal`, + `templatelimit`.`max` AS `templateLimit`, + `templatecount`.`count` AS `templateTotal`, + `vpclimit`.`max` AS `vpcLimit`, + `vpccount`.`count` AS `vpcTotal`, + `projectlimit`.`max` AS `projectLimit`, + `projectcount`.`count` AS `projectTotal`, + `networklimit`.`max` AS `networkLimit`, + `networkcount`.`count` AS `networkTotal`, + `cpulimit`.`max` AS `cpuLimit`, + `cpucount`.`count` AS `cpuTotal`, + `memorylimit`.`max` AS `memoryLimit`, + `memorycount`.`count` AS `memoryTotal`, + `primary_storage_limit`.`max` AS `primaryStorageLimit`, + `primary_storage_count`.`count` AS `primaryStorageTotal`, + `secondary_storage_limit`.`max` AS `secondaryStorageLimit`, + `secondary_storage_count`.`count` AS `secondaryStorageTotal` +from + `cloud`.`domain` + left join + `cloud`.`resource_limit` vmlimit ON domain.id = vmlimit.domain_id + and vmlimit.type = 'user_vm' and vmlimit.tag IS NULL + left join + `cloud`.`resource_count` vmcount ON domain.id = vmcount.domain_id + and vmcount.type = 'user_vm' and vmcount.tag IS NULL + left join + `cloud`.`resource_limit` iplimit ON domain.id = iplimit.domain_id + and iplimit.type = 'public_ip' + left join + `cloud`.`resource_count` ipcount ON domain.id = ipcount.domain_id + and ipcount.type = 'public_ip' + left join + `cloud`.`resource_limit` volumelimit ON domain.id = volumelimit.domain_id + and volumelimit.type = 'volume' and volumelimit.tag IS NULL + left join + `cloud`.`resource_count` volumecount ON domain.id = volumecount.domain_id + and volumecount.type = 'volume' and volumecount.tag IS NULL + left join + `cloud`.`resource_limit` snapshotlimit ON domain.id = snapshotlimit.domain_id + and snapshotlimit.type = 'snapshot' + left join + `cloud`.`resource_count` snapshotcount ON domain.id = snapshotcount.domain_id + and snapshotcount.type = 'snapshot' + left join + `cloud`.`resource_limit` templatelimit ON domain.id = templatelimit.domain_id + and templatelimit.type = 'template' + left join + `cloud`.`resource_count` templatecount ON domain.id = templatecount.domain_id + and templatecount.type = 'template' + left join + `cloud`.`resource_limit` vpclimit ON domain.id = vpclimit.domain_id + and vpclimit.type = 'vpc' + left join + `cloud`.`resource_count` vpccount ON domain.id = vpccount.domain_id + and vpccount.type = 'vpc' + left join + `cloud`.`resource_limit` projectlimit ON domain.id = projectlimit.domain_id + and projectlimit.type = 'project' + left join + `cloud`.`resource_count` projectcount ON domain.id = projectcount.domain_id + and projectcount.type = 'project' + left join + `cloud`.`resource_limit` networklimit ON domain.id = networklimit.domain_id + and networklimit.type = 'network' + left join + `cloud`.`resource_count` networkcount ON domain.id = networkcount.domain_id + and networkcount.type = 'network' + left join + `cloud`.`resource_limit` cpulimit ON domain.id = cpulimit.domain_id + and cpulimit.type = 'cpu' and cpulimit.tag IS NULL + left join + `cloud`.`resource_count` cpucount ON domain.id = cpucount.domain_id + and cpucount.type = 'cpu' and cpucount.tag IS NULL + left join + `cloud`.`resource_limit` memorylimit ON domain.id = memorylimit.domain_id + and memorylimit.type = 'memory' and memorylimit.tag IS NULL + left join + `cloud`.`resource_count` memorycount ON domain.id = memorycount.domain_id + and memorycount.type = 'memory' and memorycount.tag IS NULL + left join + `cloud`.`resource_limit` primary_storage_limit ON domain.id = primary_storage_limit.domain_id + and primary_storage_limit.type = 'primary_storage' and primary_storage_limit.tag IS NULL + left join + `cloud`.`resource_count` primary_storage_count ON domain.id = primary_storage_count.domain_id + and primary_storage_count.type = 'primary_storage' and primary_storage_count.tag IS NULL + left join + `cloud`.`resource_limit` secondary_storage_limit ON domain.id = secondary_storage_limit.domain_id + and secondary_storage_limit.type = 'secondary_storage' + left join + `cloud`.`resource_count` secondary_storage_count ON domain.id = secondary_storage_count.domain_id + and secondary_storage_count.type = 'secondary_storage'; diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.event_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.event_view.sql new file mode 100644 index 00000000000..0a15ae4c0c9 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.event_view.sql @@ -0,0 +1,63 @@ +-- 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. + +-- cloud.event_view source + + +DROP VIEW IF EXISTS `cloud`.`event_view`; + +CREATE VIEW `cloud`.`event_view` AS +select + `event`.`id` AS `id`, + `event`.`uuid` AS `uuid`, + `event`.`type` AS `type`, + `event`.`state` AS `state`, + `event`.`description` AS `description`, + `event`.`resource_id` AS `resource_id`, + `event`.`resource_type` AS `resource_type`, + `event`.`created` AS `created`, + `event`.`level` AS `level`, + `event`.`parameters` AS `parameters`, + `event`.`start_id` AS `start_id`, + `eve`.`uuid` AS `start_uuid`, + `event`.`user_id` AS `user_id`, + `event`.`archived` AS `archived`, + `event`.`display` AS `display`, + `user`.`username` AS `user_name`, + `account`.`id` AS `account_id`, + `account`.`uuid` AS `account_uuid`, + `account`.`account_name` AS `account_name`, + `account`.`type` AS `account_type`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path`, + `projects`.`id` AS `project_id`, + `projects`.`uuid` AS `project_uuid`, + `projects`.`name` AS `project_name` +from + (((((`event` +join `account` on + ((`event`.`account_id` = `account`.`id`))) +join `domain` on + ((`event`.`domain_id` = `domain`.`id`))) +join `user` on + ((`event`.`user_id` = `user`.`id`))) +left join `projects` on + ((`projects`.`project_account_id` = `event`.`account_id`))) +left join `event` `eve` on + ((`event`.`start_id` = `eve`.`id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.free_ip_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.free_ip_view.sql new file mode 100644 index 00000000000..29c22f33215 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.free_ip_view.sql @@ -0,0 +1,32 @@ +-- 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. + +-- cloud.free_ip_view source + + +DROP VIEW IF EXISTS `cloud`.`free_ip_view`; + +CREATE VIEW `cloud`.`free_ip_view` AS +select + count(`user_ip_address`.`id`) AS `free_ip` +from + (`user_ip_address` +join `vlan` on + (((`vlan`.`id` = `user_ip_address`.`vlan_db_id`) + and (`vlan`.`vlan_type` = 'VirtualNetwork')))) +where + (`user_ip_address`.`state` = 'Free'); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.image_store_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.image_store_view.sql new file mode 100644 index 00000000000..88d68302d4c --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.image_store_view.sql @@ -0,0 +1,45 @@ +-- 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. + +-- cloud.image_store_view source + + +DROP VIEW IF EXISTS `cloud`.`image_store_view`; + +CREATE VIEW `cloud`.`image_store_view` AS +select + `image_store`.`id` AS `id`, + `image_store`.`uuid` AS `uuid`, + `image_store`.`name` AS `name`, + `image_store`.`image_provider_name` AS `image_provider_name`, + `image_store`.`protocol` AS `protocol`, + `image_store`.`url` AS `url`, + `image_store`.`scope` AS `scope`, + `image_store`.`role` AS `role`, + `image_store`.`readonly` AS `readonly`, + `image_store`.`removed` AS `removed`, + `data_center`.`id` AS `data_center_id`, + `data_center`.`uuid` AS `data_center_uuid`, + `data_center`.`name` AS `data_center_name`, + `image_store_details`.`name` AS `detail_name`, + `image_store_details`.`value` AS `detail_value` +from + ((`image_store` +left join `data_center` on + ((`image_store`.`data_center_id` = `data_center`.`id`))) +left join `image_store_details` on + ((`image_store_details`.`store_id` = `image_store`.`id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.instance_group_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.instance_group_view.sql new file mode 100644 index 00000000000..8bdc8184718 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.instance_group_view.sql @@ -0,0 +1,48 @@ +-- 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. + +-- cloud.instance_group_view source + + +DROP VIEW IF EXISTS `cloud`.`instance_group_view`; + +CREATE VIEW `cloud`.`instance_group_view` AS +select + `instance_group`.`id` AS `id`, + `instance_group`.`uuid` AS `uuid`, + `instance_group`.`name` AS `name`, + `instance_group`.`removed` AS `removed`, + `instance_group`.`created` AS `created`, + `account`.`id` AS `account_id`, + `account`.`uuid` AS `account_uuid`, + `account`.`account_name` AS `account_name`, + `account`.`type` AS `account_type`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path`, + `projects`.`id` AS `project_id`, + `projects`.`uuid` AS `project_uuid`, + `projects`.`name` AS `project_name` +from + (((`instance_group` +join `account` on + ((`instance_group`.`account_id` = `account`.`id`))) +join `domain` on + ((`account`.`domain_id` = `domain`.`id`))) +left join `projects` on + ((`projects`.`project_account_id` = `instance_group`.`account_id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.last_annotation_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.last_annotation_view.sql new file mode 100644 index 00000000000..f317fbacc4d --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.last_annotation_view.sql @@ -0,0 +1,43 @@ +-- 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. + +-- cloud.last_annotation_view source + + +DROP VIEW IF EXISTS `cloud`.`last_annotation_view`; + +CREATE VIEW `cloud`.`last_annotation_view` AS +select + `annotations`.`uuid` AS `uuid`, + `annotations`.`annotation` AS `annotation`, + `annotations`.`entity_uuid` AS `entity_uuid`, + `annotations`.`entity_type` AS `entity_type`, + `annotations`.`user_uuid` AS `user_uuid`, + `annotations`.`created` AS `created`, + `annotations`.`removed` AS `removed` +from + `annotations` +where + `annotations`.`created` in ( + select + max(`annotations`.`created`) + from + `annotations` + where + (`annotations`.`removed` is null) + group by + `annotations`.`entity_uuid`); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.mshost_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.mshost_view.sql new file mode 100644 index 00000000000..9b68f170e38 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.mshost_view.sql @@ -0,0 +1,46 @@ +-- 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. + +-- cloud.mshost_view source + + +DROP VIEW IF EXISTS `cloud`.`mshost_view`; + +CREATE VIEW `cloud`.`mshost_view` AS +select + `mshost`.`id` AS `id`, + `mshost`.`msid` AS `msid`, + `mshost`.`runid` AS `runid`, + `mshost`.`name` AS `name`, + `mshost`.`uuid` AS `uuid`, + `mshost`.`state` AS `state`, + `mshost`.`version` AS `version`, + `mshost`.`service_ip` AS `service_ip`, + `mshost`.`service_port` AS `service_port`, + `mshost`.`last_update` AS `last_update`, + `mshost`.`removed` AS `removed`, + `mshost`.`alert_count` AS `alert_count`, + `mshost_status`.`last_jvm_start` AS `last_jvm_start`, + `mshost_status`.`last_jvm_stop` AS `last_jvm_stop`, + `mshost_status`.`last_system_boot` AS `last_system_boot`, + `mshost_status`.`os_distribution` AS `os_distribution`, + `mshost_status`.`java_name` AS `java_name`, + `mshost_status`.`java_version` AS `java_version` +from + (`mshost` +left join `mshost_status` on + ((`mshost`.`uuid` = `mshost_status`.`ms_id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql index 8ba291e154c..bae73deda32 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql @@ -60,6 +60,8 @@ SELECT `network_offerings`.`supports_vm_autoscaling` AS `supports_vm_autoscaling`, `network_offerings`.`for_vpc` AS `for_vpc`, `network_offerings`.`for_tungsten` AS `for_tungsten`, + `network_offerings`.`for_nsx` AS `for_nsx`, + `network_offerings`.`nsx_mode` AS `nsx_mode`, `network_offerings`.`service_package_id` AS `service_package_id`, GROUP_CONCAT(DISTINCT(domain.id)) AS domain_id, GROUP_CONCAT(DISTINCT(domain.uuid)) AS domain_uuid, diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.project_account_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.project_account_view.sql new file mode 100644 index 00000000000..c89618970cd --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.project_account_view.sql @@ -0,0 +1,54 @@ +-- 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. + +-- cloud.project_account_view source + + +DROP VIEW IF EXISTS `cloud`.`project_account_view`; + +CREATE VIEW `cloud`.`project_account_view` AS +select + `project_account`.`id` AS `id`, + `account`.`id` AS `account_id`, + `account`.`uuid` AS `account_uuid`, + `account`.`account_name` AS `account_name`, + `account`.`type` AS `account_type`, + `user`.`id` AS `user_id`, + `user`.`uuid` AS `user_uuid`, + `user`.`username` AS `user_name`, + `project_account`.`account_role` AS `account_role`, + `project_role`.`id` AS `project_role_id`, + `project_role`.`uuid` AS `project_role_uuid`, + `projects`.`id` AS `project_id`, + `projects`.`uuid` AS `project_uuid`, + `projects`.`name` AS `project_name`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path` +from + (((((`project_account` +join `account` on + ((`project_account`.`account_id` = `account`.`id`))) +join `domain` on + ((`account`.`domain_id` = `domain`.`id`))) +join `projects` on + ((`projects`.`id` = `project_account`.`project_id`))) +left join `project_role` on + ((`project_account`.`project_role_id` = `project_role`.`id`))) +left join `user` on + ((`project_account`.`user_id` = `user`.`id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.project_invitation_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.project_invitation_view.sql new file mode 100644 index 00000000000..fae35b9373e --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.project_invitation_view.sql @@ -0,0 +1,52 @@ +-- 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. + +-- cloud.project_invitation_view source + + +DROP VIEW IF EXISTS `cloud`.`project_invitation_view`; + +CREATE VIEW `cloud`.`project_invitation_view` AS +select + `project_invitations`.`id` AS `id`, + `project_invitations`.`uuid` AS `uuid`, + `project_invitations`.`email` AS `email`, + `project_invitations`.`created` AS `created`, + `project_invitations`.`state` AS `state`, + `project_invitations`.`project_role_id` AS `project_role_id`, + `projects`.`id` AS `project_id`, + `projects`.`uuid` AS `project_uuid`, + `projects`.`name` AS `project_name`, + `account`.`id` AS `account_id`, + `account`.`uuid` AS `account_uuid`, + `account`.`account_name` AS `account_name`, + `account`.`type` AS `account_type`, + `user`.`id` AS `user_id`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path` +from + ((((`project_invitations` +left join `account` on + ((`project_invitations`.`account_id` = `account`.`id`))) +left join `domain` on + ((`project_invitations`.`domain_id` = `domain`.`id`))) +left join `projects` on + ((`projects`.`id` = `project_invitations`.`project_id`))) +left join `user` on + ((`project_invitations`.`user_id` = `user`.`id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.project_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.project_view.sql new file mode 100644 index 00000000000..31461b1dd1e --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.project_view.sql @@ -0,0 +1,50 @@ +-- 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. + +-- cloud.project_view source + + +DROP VIEW IF EXISTS `cloud`.`project_view`; + +CREATE VIEW `cloud`.`project_view` AS +select + `projects`.`id` AS `id`, + `projects`.`uuid` AS `uuid`, + `projects`.`name` AS `name`, + `projects`.`display_text` AS `display_text`, + `projects`.`state` AS `state`, + `projects`.`removed` AS `removed`, + `projects`.`created` AS `created`, + `projects`.`project_account_id` AS `project_account_id`, + `account`.`account_name` AS `owner`, + `pacct`.`account_id` AS `account_id`, + `pacct`.`user_id` AS `user_id`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path` +from + ((((`projects` +join `domain` on + ((`projects`.`domain_id` = `domain`.`id`))) +join `project_account` on + (((`projects`.`id` = `project_account`.`project_id`) + and (`project_account`.`account_role` = 'Admin')))) +join `account` on + ((`account`.`id` = `project_account`.`account_id`))) +left join `project_account` `pacct` on + ((`projects`.`id` = `pacct`.`project_id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.resource_tag_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.resource_tag_view.sql new file mode 100644 index 00000000000..3d77d49f870 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.resource_tag_view.sql @@ -0,0 +1,51 @@ +-- 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. + +-- cloud.resource_tag_view source + + +DROP VIEW IF EXISTS `cloud`.`resource_tag_view`; + +CREATE VIEW `cloud`.`resource_tag_view` AS +select + `resource_tags`.`id` AS `id`, + `resource_tags`.`uuid` AS `uuid`, + `resource_tags`.`key` AS `key`, + `resource_tags`.`value` AS `value`, + `resource_tags`.`resource_id` AS `resource_id`, + `resource_tags`.`resource_uuid` AS `resource_uuid`, + `resource_tags`.`resource_type` AS `resource_type`, + `resource_tags`.`customer` AS `customer`, + `account`.`id` AS `account_id`, + `account`.`uuid` AS `account_uuid`, + `account`.`account_name` AS `account_name`, + `account`.`type` AS `account_type`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path`, + `projects`.`id` AS `project_id`, + `projects`.`uuid` AS `project_uuid`, + `projects`.`name` AS `project_name` +from + (((`resource_tags` +join `account` on + ((`resource_tags`.`account_id` = `account`.`id`))) +join `domain` on + ((`resource_tags`.`domain_id` = `domain`.`id`))) +left join `projects` on + ((`projects`.`project_account_id` = `resource_tags`.`account_id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.security_group_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.security_group_view.sql new file mode 100644 index 00000000000..3cae860c1c3 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.security_group_view.sql @@ -0,0 +1,79 @@ +-- 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. + +-- cloud.security_group_view source + + +DROP VIEW IF EXISTS `cloud`.`security_group_view`; + +CREATE VIEW `cloud`.`security_group_view` AS +select + `security_group`.`id` AS `id`, + `security_group`.`name` AS `name`, + `security_group`.`description` AS `description`, + `security_group`.`uuid` AS `uuid`, + `account`.`id` AS `account_id`, + `account`.`uuid` AS `account_uuid`, + `account`.`account_name` AS `account_name`, + `account`.`type` AS `account_type`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path`, + `projects`.`id` AS `project_id`, + `projects`.`uuid` AS `project_uuid`, + `projects`.`name` AS `project_name`, + `security_group_rule`.`id` AS `rule_id`, + `security_group_rule`.`uuid` AS `rule_uuid`, + `security_group_rule`.`type` AS `rule_type`, + `security_group_rule`.`start_port` AS `rule_start_port`, + `security_group_rule`.`end_port` AS `rule_end_port`, + `security_group_rule`.`protocol` AS `rule_protocol`, + `security_group_rule`.`allowed_network_id` AS `rule_allowed_network_id`, + `security_group_rule`.`allowed_ip_cidr` AS `rule_allowed_ip_cidr`, + `security_group_rule`.`create_status` AS `rule_create_status`, + `resource_tags`.`id` AS `tag_id`, + `resource_tags`.`uuid` AS `tag_uuid`, + `resource_tags`.`key` AS `tag_key`, + `resource_tags`.`value` AS `tag_value`, + `resource_tags`.`domain_id` AS `tag_domain_id`, + `resource_tags`.`account_id` AS `tag_account_id`, + `resource_tags`.`resource_id` AS `tag_resource_id`, + `resource_tags`.`resource_uuid` AS `tag_resource_uuid`, + `resource_tags`.`resource_type` AS `tag_resource_type`, + `resource_tags`.`customer` AS `tag_customer`, + `async_job`.`id` AS `job_id`, + `async_job`.`uuid` AS `job_uuid`, + `async_job`.`job_status` AS `job_status`, + `async_job`.`account_id` AS `job_account_id` +from + ((((((`security_group` +left join `security_group_rule` on + ((`security_group`.`id` = `security_group_rule`.`security_group_id`))) +join `account` on + ((`security_group`.`account_id` = `account`.`id`))) +join `domain` on + ((`security_group`.`domain_id` = `domain`.`id`))) +left join `projects` on + ((`projects`.`project_account_id` = `security_group`.`account_id`))) +left join `resource_tags` on + (((`resource_tags`.`resource_id` = `security_group`.`id`) + and (`resource_tags`.`resource_type` = 'SecurityGroup')))) +left join `async_job` on + (((`async_job`.`instance_id` = `security_group`.`id`) + and (`async_job`.`instance_type` = 'SecurityGroup') + and (`async_job`.`job_status` = 0)))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.service_offering_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.service_offering_view.sql index e859af482b4..c894429adf8 100644 --- a/engine/schema/src/main/resources/META-INF/db/views/cloud.service_offering_view.sql +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.service_offering_view.sql @@ -24,6 +24,7 @@ SELECT `service_offering`.`id` AS `id`, `service_offering`.`uuid` AS `uuid`, `service_offering`.`name` AS `name`, + `service_offering`.`state` AS `state`, `service_offering`.`display_text` AS `display_text`, `disk_offering`.`provisioning_type` AS `provisioning_type`, `service_offering`.`created` AS `created`, @@ -84,7 +85,7 @@ SELECT FROM `cloud`.`service_offering` INNER JOIN - `cloud`.`disk_offering_view` AS `disk_offering` ON service_offering.disk_offering_id = disk_offering.id + `cloud`.`disk_offering` ON service_offering.disk_offering_id = disk_offering.id LEFT JOIN `cloud`.`service_offering_details` AS `domain_details` ON `domain_details`.`service_offering_id` = `service_offering`.`id` AND `domain_details`.`name`='domainid' LEFT JOIN @@ -108,7 +109,5 @@ FROM LEFT JOIN `cloud`.`service_offering_details` AS `vsphere_storage_policy` ON `vsphere_storage_policy`.`service_offering_id` = `service_offering`.`id` AND `vsphere_storage_policy`.`name` = 'storagepolicy' -WHERE - `service_offering`.`state`='Active' GROUP BY `service_offering`.`id`; diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.volume_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.volume_view.sql new file mode 100644 index 00000000000..fd21fff1494 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.volume_view.sql @@ -0,0 +1,156 @@ +-- 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. + +-- VIEW `cloud`.`volume_view`; + +DROP VIEW IF EXISTS `cloud`.`volume_view`; + +CREATE VIEW `cloud`.`volume_view` AS +SELECT + `volumes`.`id` AS `id`, + `volumes`.`uuid` AS `uuid`, + `volumes`.`name` AS `name`, + `volumes`.`device_id` AS `device_id`, + `volumes`.`volume_type` AS `volume_type`, + `volumes`.`provisioning_type` AS `provisioning_type`, + `volumes`.`size` AS `size`, + `volumes`.`min_iops` AS `min_iops`, + `volumes`.`max_iops` AS `max_iops`, + `volumes`.`created` AS `created`, + `volumes`.`state` AS `state`, + `volumes`.`attached` AS `attached`, + `volumes`.`removed` AS `removed`, + `volumes`.`display_volume` AS `display_volume`, + `volumes`.`format` AS `format`, + `volumes`.`path` AS `path`, + `volumes`.`chain_info` AS `chain_info`, + `volumes`.`external_uuid` AS `external_uuid`, + `account`.`id` AS `account_id`, + `account`.`uuid` AS `account_uuid`, + `account`.`account_name` AS `account_name`, + `account`.`type` AS `account_type`, + `domain`.`id` AS `domain_id`, + `domain`.`uuid` AS `domain_uuid`, + `domain`.`name` AS `domain_name`, + `domain`.`path` AS `domain_path`, + `projects`.`id` AS `project_id`, + `projects`.`uuid` AS `project_uuid`, + `projects`.`name` AS `project_name`, + `data_center`.`id` AS `data_center_id`, + `data_center`.`uuid` AS `data_center_uuid`, + `data_center`.`name` AS `data_center_name`, + `data_center`.`networktype` AS `data_center_type`, + `vm_instance`.`id` AS `vm_id`, + `vm_instance`.`uuid` AS `vm_uuid`, + `vm_instance`.`name` AS `vm_name`, + `vm_instance`.`state` AS `vm_state`, + `vm_instance`.`vm_type` AS `vm_type`, + `user_vm`.`display_name` AS `vm_display_name`, + `volume_store_ref`.`size` AS `volume_store_size`, + `volume_store_ref`.`download_pct` AS `download_pct`, + `volume_store_ref`.`download_state` AS `download_state`, + `volume_store_ref`.`error_str` AS `error_str`, + `volume_store_ref`.`created` AS `created_on_store`, + `disk_offering`.`id` AS `disk_offering_id`, + `disk_offering`.`uuid` AS `disk_offering_uuid`, + `disk_offering`.`name` AS `disk_offering_name`, + `disk_offering`.`display_text` AS `disk_offering_display_text`, + `disk_offering`.`use_local_storage` AS `use_local_storage`, + `service_offering`.`system_use` AS `system_use`, + `disk_offering`.`bytes_read_rate` AS `bytes_read_rate`, + `disk_offering`.`bytes_write_rate` AS `bytes_write_rate`, + `disk_offering`.`iops_read_rate` AS `iops_read_rate`, + `disk_offering`.`iops_write_rate` AS `iops_write_rate`, + `disk_offering`.`cache_mode` AS `cache_mode`, + `storage_pool`.`id` AS `pool_id`, + `storage_pool`.`uuid` AS `pool_uuid`, + `storage_pool`.`name` AS `pool_name`, + `cluster`.`id` AS `cluster_id`, + `cluster`.`name` AS `cluster_name`, + `cluster`.`uuid` AS `cluster_uuid`, + `cluster`.`hypervisor_type` AS `hypervisor_type`, + `vm_template`.`id` AS `template_id`, + `vm_template`.`uuid` AS `template_uuid`, + `vm_template`.`extractable` AS `extractable`, + `vm_template`.`type` AS `template_type`, + `vm_template`.`name` AS `template_name`, + `vm_template`.`display_text` AS `template_display_text`, + `iso`.`id` AS `iso_id`, + `iso`.`uuid` AS `iso_uuid`, + `iso`.`name` AS `iso_name`, + `iso`.`display_text` AS `iso_display_text`, + `resource_tags`.`id` AS `tag_id`, + `resource_tags`.`uuid` AS `tag_uuid`, + `resource_tags`.`key` AS `tag_key`, + `resource_tags`.`value` AS `tag_value`, + `resource_tags`.`domain_id` AS `tag_domain_id`, + `resource_tags`.`account_id` AS `tag_account_id`, + `resource_tags`.`resource_id` AS `tag_resource_id`, + `resource_tags`.`resource_uuid` AS `tag_resource_uuid`, + `resource_tags`.`resource_type` AS `tag_resource_type`, + `resource_tags`.`customer` AS `tag_customer`, + `async_job`.`id` AS `job_id`, + `async_job`.`uuid` AS `job_uuid`, + `async_job`.`job_status` AS `job_status`, + `async_job`.`account_id` AS `job_account_id`, + `host_pod_ref`.`id` AS `pod_id`, + `host_pod_ref`.`uuid` AS `pod_uuid`, + `host_pod_ref`.`name` AS `pod_name`, + `resource_tag_account`.`account_name` AS `tag_account_name`, + `resource_tag_domain`.`uuid` AS `tag_domain_uuid`, + `resource_tag_domain`.`name` AS `tag_domain_name` +FROM + ((((((((((((((((((`volumes` +JOIN `account`ON + ((`volumes`.`account_id` = `account`.`id`))) +JOIN `domain`ON + ((`volumes`.`domain_id` = `domain`.`id`))) +LEFT JOIN `projects`ON + ((`projects`.`project_account_id` = `account`.`id`))) +LEFT JOIN `data_center`ON + ((`volumes`.`data_center_id` = `data_center`.`id`))) +LEFT JOIN `vm_instance`ON + ((`volumes`.`instance_id` = `vm_instance`.`id`))) +LEFT JOIN `user_vm`ON + ((`user_vm`.`id` = `vm_instance`.`id`))) +LEFT JOIN `volume_store_ref`ON + ((`volumes`.`id` = `volume_store_ref`.`volume_id`))) +LEFT JOIN `service_offering`ON + ((`vm_instance`.`service_offering_id` = `service_offering`.`id`))) +LEFT JOIN `disk_offering`ON + ((`volumes`.`disk_offering_id` = `disk_offering`.`id`))) +LEFT JOIN `storage_pool`ON + ((`volumes`.`pool_id` = `storage_pool`.`id`))) +LEFT JOIN `host_pod_ref`ON + ((`storage_pool`.`pod_id` = `host_pod_ref`.`id`))) +LEFT JOIN `cluster`ON + ((`storage_pool`.`cluster_id` = `cluster`.`id`))) +LEFT JOIN `vm_template`ON + ((`volumes`.`template_id` = `vm_template`.`id`))) +LEFT JOIN `vm_template` `iso`ON + ((`iso`.`id` = `volumes`.`iso_id`))) +LEFT JOIN `resource_tags`ON + (((`resource_tags`.`resource_id` = `volumes`.`id`) + and (`resource_tags`.`resource_type` = 'Volume')))) +LEFT JOIN `async_job`ON + (((`async_job`.`instance_id` = `volumes`.`id`) + and (`async_job`.`instance_type` = 'Volume') + and (`async_job`.`job_status` = 0)))) +LEFT JOIN `account` `resource_tag_account`ON + ((`resource_tag_account`.`id` = `resource_tags`.`account_id`))) +LEFT JOIN `domain` `resource_tag_domain`ON + ((`resource_tag_domain`.`id` = `resource_tags`.`domain_id`))); diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.vpc_offering_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.vpc_offering_view.sql new file mode 100644 index 00000000000..9aca869b510 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.vpc_offering_view.sql @@ -0,0 +1,64 @@ +-- 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. + +-- cloud.vpc_offering_view source + +DROP VIEW IF EXISTS `cloud`.`vpc_offering_view`; + +CREATE VIEW `cloud`.`vpc_offering_view` AS +select + `vpc_offerings`.`id` AS `id`, + `vpc_offerings`.`uuid` AS `uuid`, + `vpc_offerings`.`name` AS `name`, + `vpc_offerings`.`unique_name` AS `unique_name`, + `vpc_offerings`.`display_text` AS `display_text`, + `vpc_offerings`.`state` AS `state`, + `vpc_offerings`.`default` AS `default`, + `vpc_offerings`.`for_nsx` AS `for_nsx`, + `vpc_offerings`.`nsx_mode` AS `nsx_mode`, + `vpc_offerings`.`created` AS `created`, + `vpc_offerings`.`removed` AS `removed`, + `vpc_offerings`.`service_offering_id` AS `service_offering_id`, + `vpc_offerings`.`supports_distributed_router` AS `supports_distributed_router`, + `vpc_offerings`.`supports_region_level_vpc` AS `supports_region_level_vpc`, + `vpc_offerings`.`redundant_router_service` AS `redundant_router_service`, + `vpc_offerings`.`sort_key` AS `sort_key`, + group_concat(distinct `domain`.`id` separator ',') AS `domain_id`, + group_concat(distinct `domain`.`uuid` separator ',') AS `domain_uuid`, + group_concat(distinct `domain`.`name` separator ',') AS `domain_name`, + group_concat(distinct `domain`.`path` separator ',') AS `domain_path`, + group_concat(distinct `zone`.`id` separator ',') AS `zone_id`, + group_concat(distinct `zone`.`uuid` separator ',') AS `zone_uuid`, + group_concat(distinct `zone`.`name` separator ',') AS `zone_name`, + `offering_details`.`value` AS `internet_protocol` +from + (((((`vpc_offerings` +left join `vpc_offering_details` `domain_details` on + (((`domain_details`.`offering_id` = `vpc_offerings`.`id`) + and (`domain_details`.`name` = 'domainid')))) +left join `domain` on + ((0 <> find_in_set(`domain`.`id`, `domain_details`.`value`)))) +left join `vpc_offering_details` `zone_details` on + (((`zone_details`.`offering_id` = `vpc_offerings`.`id`) + and (`zone_details`.`name` = 'zoneid')))) +left join `data_center` `zone` on + ((0 <> find_in_set(`zone`.`id`, `zone_details`.`value`)))) +left join `vpc_offering_details` `offering_details` on + (((`offering_details`.`offering_id` = `vpc_offerings`.`id`) + and (`offering_details`.`name` = 'internetprotocol')))) +group by + `vpc_offerings`.`id`; diff --git a/engine/schema/src/test/java/com/cloud/host/HostVOTest.java b/engine/schema/src/test/java/com/cloud/host/HostVOTest.java index 76bc5270b4f..cd9ac3cc172 100755 --- a/engine/schema/src/test/java/com/cloud/host/HostVOTest.java +++ b/engine/schema/src/test/java/com/cloud/host/HostVOTest.java @@ -1,84 +1,126 @@ -// 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.host; - -import com.cloud.service.ServiceOfferingVO; -import com.cloud.vm.VirtualMachine; -import java.util.Arrays; -import java.util.List; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.junit.Before; - -public class HostVOTest { - HostVO host; - ServiceOfferingVO offering; - - @Before - public void setUp() throws Exception { - host = new HostVO(); - offering = new ServiceOfferingVO("TestSO", 0, 0, 0, 0, 0, - false, "TestSO", false,VirtualMachine.Type.User,false); - } - - @Test - public void testNoSO() { - assertFalse(host.checkHostServiceOfferingTags(null)); - } - - @Test - public void testNoTag() { - assertTrue(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void testRightTag() { - host.setHostTags(Arrays.asList("tag1","tag2"), false); - offering.setHostTag("tag2,tag1"); - assertTrue(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void testWrongTag() { - host.setHostTags(Arrays.asList("tag1","tag2"), false); - offering.setHostTag("tag2,tag4"); - assertFalse(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatMatches() { - host.setHostTags(List.of("tags[0] == 'A'"), true); - offering.setHostTag("A"); - assertTrue(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatDoesNotMatch() { - host.setHostTags(List.of("tags[0] == 'A'"), true); - offering.setHostTag("B"); - assertFalse(host.checkHostServiceOfferingTags(offering)); - } - - @Test - public void checkHostServiceOfferingTagsTestRuleTagWithNullServiceTag() { - host.setHostTags(List.of("tags[0] == 'A'"), true); - offering.setHostTag(null); - assertFalse(host.checkHostServiceOfferingTags(offering)); - } -} +// 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.host; + +import com.cloud.offering.ServiceOffering; +import com.cloud.service.ServiceOfferingVO; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.vm.VirtualMachine; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.Before; +import org.mockito.Mockito; + +public class HostVOTest { + HostVO host; + ServiceOfferingVO offering; + + @Before + public void setUp() throws Exception { + host = new HostVO(); + offering = new ServiceOfferingVO("TestSO", 0, 0, 0, 0, 0, + false, "TestSO", false,VirtualMachine.Type.User,false); + } + + @Test + public void testNoSO() { + assertFalse(host.checkHostServiceOfferingTags(null)); + } + + @Test + public void testNoTag() { + assertTrue(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void testRightTag() { + host.setHostTags(Arrays.asList("tag1","tag2"), false); + offering.setHostTag("tag2,tag1"); + assertTrue(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void testWrongTag() { + host.setHostTags(Arrays.asList("tag1","tag2"), false); + offering.setHostTag("tag2,tag4"); + assertFalse(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatMatches() { + host.setHostTags(List.of("tags[0] == 'A'"), true); + offering.setHostTag("A"); + assertTrue(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void checkHostServiceOfferingTagsTestRuleTagWithServiceTagThatDoesNotMatch() { + host.setHostTags(List.of("tags[0] == 'A'"), true); + offering.setHostTag("B"); + assertFalse(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void checkHostServiceOfferingTagsTestRuleTagWithNullServiceTag() { + host.setHostTags(List.of("tags[0] == 'A'"), true); + offering.setHostTag(null); + assertFalse(host.checkHostServiceOfferingTags(offering)); + } + + @Test + public void testEitherNoSOOrTemplate() { + assertFalse(host.checkHostServiceOfferingAndTemplateTags(null, Mockito.mock(VirtualMachineTemplate.class))); + assertFalse(host.checkHostServiceOfferingAndTemplateTags(Mockito.mock(ServiceOffering.class), null)); + } + + @Test + public void testNoTagOfferingTemplate() { + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, Mockito.mock(VirtualMachineTemplate.class))); + } + + @Test + public void testRightTagOfferingTemplate() { + host.setHostTags(Arrays.asList("tag1", "tag2"), false); + offering.setHostTag("tag2,tag1"); + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, Mockito.mock(VirtualMachineTemplate.class))); + host.setHostTags(Arrays.asList("tag1", "tag2", "tag3"), false); + offering.setHostTag("tag2,tag1"); + VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class); + Mockito.when(template.getTemplateTag()).thenReturn("tag3"); + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, template)); + host.setHostTags(List.of("tag3"), false); + offering.setHostTag(null); + assertTrue(host.checkHostServiceOfferingAndTemplateTags(offering, template)); + } + + @Test + public void testWrongOfferingTag() { + host.setHostTags(Arrays.asList("tag1","tag2"), false); + offering.setHostTag("tag2,tag4"); + VirtualMachineTemplate template = Mockito.mock(VirtualMachineTemplate.class); + Mockito.when(template.getTemplateTag()).thenReturn("tag1"); + assertFalse(host.checkHostServiceOfferingAndTemplateTags(offering, template)); + offering.setHostTag("tag1,tag2"); + template = Mockito.mock(VirtualMachineTemplate.class); + Mockito.when(template.getTemplateTag()).thenReturn("tag3"); + assertFalse(host.checkHostServiceOfferingAndTemplateTags(offering, template)); + } +} diff --git a/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java b/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java index 6c894de7fb2..64941d99bb6 100644 --- a/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/offerings/dao/NetworkOfferingDaoImplTest.java @@ -17,6 +17,7 @@ package com.cloud.offerings.dao; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -37,9 +38,16 @@ public class NetworkOfferingDaoImplTest { final long offeringId = 1L; + private AutoCloseable closeable; + @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); + } + + @After + public void tearDown() throws Exception { + closeable.close(); } @Test diff --git a/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java b/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java index 9277bf915c1..85fe0e09542 100755 --- a/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/storage/dao/StoragePoolTagsDaoImplTest.java @@ -21,7 +21,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; @@ -72,7 +72,7 @@ public class StoragePoolTagsDaoImplTest extends TestCase { public void setup() { when(_configDao.getValue(batchSizeConfigurationKey)).thenReturn(batchSizeValue); doReturn(storagePoolTagList).when(_storagePoolTagsDaoImpl).searchIncludingRemoved( - Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); } @Test @@ -91,7 +91,7 @@ public class StoragePoolTagsDaoImplTest extends TestCase { List storagePoolTags = new ArrayList(); _storagePoolTagsDaoImpl.searchForStoragePoolIdsInternal(0, storageTagsIds.length, storageTagsIds, storagePoolTags); - verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); assertEquals(2, storagePoolTags.size()); } @@ -99,30 +99,30 @@ public class StoragePoolTagsDaoImplTest extends TestCase { public void testSearchForStoragePoolIdsInternalStorageTagsNullSearch() { List storagePoolTags = new ArrayList(); doReturn(null).when(_storagePoolTagsDaoImpl).searchIncludingRemoved( - Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); _storagePoolTagsDaoImpl.searchForStoragePoolIdsInternal(0, storageTagsIds.length, storageTagsIds, storagePoolTags); - verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(Matchers.any(SearchCriteria.class), Matchers.isNull(Filter.class), Matchers.isNull(Boolean.class), Matchers.eq(false)); + verify(_storagePoolTagsDaoImpl).searchIncludingRemoved(ArgumentMatchers.any(SearchCriteria.class), ArgumentMatchers.isNull(Filter.class), ArgumentMatchers.isNull(Boolean.class), ArgumentMatchers.eq(false)); assertEquals(0, storagePoolTags.size()); } @Test public void testSearchByIdsStorageTagsIdsGreaterOrEqualThanBatchSize() { when(_configDao.getValue(batchSizeConfigurationKey)).thenReturn(batchSizeLow); - doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.anyInt(), Matchers.anyInt(), Matchers.any(Long[].class), Matchers.anyList()); + doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); _storagePoolTagsDaoImpl.searchByIds(storageTagsIds); int batchSize = Integer.parseInt(batchSizeLow); int difference = storageTagsIds.length - 2 * batchSize; - verify(_storagePoolTagsDaoImpl, Mockito.times(2)).searchForStoragePoolIdsInternal(Matchers.anyInt(), Matchers.eq(batchSize), Matchers.any(Long[].class), Matchers.anyList()); - verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.eq(2 * batchSize), Matchers.eq(difference), Matchers.any(Long[].class), Matchers.anyList()); + verify(_storagePoolTagsDaoImpl, Mockito.times(2)).searchForStoragePoolIdsInternal(ArgumentMatchers.anyInt(), ArgumentMatchers.eq(batchSize), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); + verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.eq(2 * batchSize), ArgumentMatchers.eq(difference), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); } @Test public void testSearchByIdsStorageTagsIdsLowerThanBatchSize() { - doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.anyInt(), Matchers.anyInt(), Matchers.any(Long[].class), Matchers.anyList()); + doNothing().when(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); _storagePoolTagsDaoImpl.searchByIds(storageTagsIds); - verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(Matchers.eq(0), Matchers.eq(storageTagsIds.length), Matchers.any(Long[].class), Matchers.anyList()); + verify(_storagePoolTagsDaoImpl).searchForStoragePoolIdsInternal(ArgumentMatchers.eq(0), ArgumentMatchers.eq(storageTagsIds.length), ArgumentMatchers.any(Long[].class), ArgumentMatchers.anyList()); } } diff --git a/engine/schema/src/test/java/com/cloud/storage/dao/VolumeDaoImplTest.java b/engine/schema/src/test/java/com/cloud/storage/dao/VolumeDaoImplTest.java new file mode 100644 index 00000000000..7968ee4a375 --- /dev/null +++ b/engine/schema/src/test/java/com/cloud/storage/dao/VolumeDaoImplTest.java @@ -0,0 +1,105 @@ +// 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.storage.dao; + +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.startsWith; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +import com.cloud.utils.db.TransactionLegacy; + +@RunWith(MockitoJUnitRunner.class) +public class VolumeDaoImplTest { + @Mock + private PreparedStatement preparedStatementMock; + + @Mock + private TransactionLegacy transactionMock; + + private static MockedStatic mockedTransactionLegacy; + + private final VolumeDaoImpl volumeDao = new VolumeDaoImpl(); + + @BeforeClass + public static void init() { + mockedTransactionLegacy = Mockito.mockStatic(TransactionLegacy.class); + } + + @AfterClass + public static void close() { + mockedTransactionLegacy.close(); + } + + @Test + public void testListPoolIdsByVolumeCount_with_cluster_details() throws SQLException { + final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_QUERY_WITH_CLUSTER = + "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? AND pool.pod_id = ? AND pool.cluster_id = ? GROUP BY pool.id ORDER BY 2 ASC "; + final long dcId = 1, accountId = 1; + final Long podId = 1L, clusterId = 1L; + + when(TransactionLegacy.currentTxn()).thenReturn(transactionMock); + when(transactionMock.prepareAutoCloseStatement(startsWith(ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_QUERY_WITH_CLUSTER))).thenReturn(preparedStatementMock); + ResultSet rs = Mockito.mock(ResultSet.class); + when(preparedStatementMock.executeQuery()).thenReturn(rs, rs); + + volumeDao.listPoolIdsByVolumeCount(dcId, podId, clusterId, accountId); + + verify(transactionMock, times(1)).prepareAutoCloseStatement(ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_QUERY_WITH_CLUSTER); + verify(preparedStatementMock, times(1)).setLong(1, accountId); + verify(preparedStatementMock, times(1)).setLong(2, dcId); + verify(preparedStatementMock, times(1)).setLong(3, podId); + verify(preparedStatementMock, times(1)).setLong(4, clusterId); + verify(preparedStatementMock, times(4)).setLong(anyInt(), anyLong()); + verify(preparedStatementMock, times(1)).executeQuery(); + } + + @Test + public void testListPoolIdsByVolumeCount_without_cluster_details() throws SQLException { + final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_QUERY_WITHOUT_CLUSTER = + "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? GROUP BY pool.id ORDER BY 2 ASC "; + final long dcId = 1, accountId = 1; + + when(TransactionLegacy.currentTxn()).thenReturn(transactionMock); + when(transactionMock.prepareAutoCloseStatement(startsWith(ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_QUERY_WITHOUT_CLUSTER))).thenReturn(preparedStatementMock); + ResultSet rs = Mockito.mock(ResultSet.class); + when(preparedStatementMock.executeQuery()).thenReturn(rs, rs); + + volumeDao.listPoolIdsByVolumeCount(dcId, null, null, accountId); + + verify(transactionMock, times(1)).prepareAutoCloseStatement(ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_QUERY_WITHOUT_CLUSTER); + verify(preparedStatementMock, times(1)).setLong(1, accountId); + verify(preparedStatementMock, times(1)).setLong(2, dcId); + verify(preparedStatementMock, times(2)).setLong(anyInt(), anyLong()); + verify(preparedStatementMock, times(1)).executeQuery(); + } +} diff --git a/engine/schema/src/test/java/com/cloud/upgrade/DatabaseUpgradeCheckerTest.java b/engine/schema/src/test/java/com/cloud/upgrade/DatabaseUpgradeCheckerTest.java index d7ef18a4f32..1a9372f73ea 100644 --- a/engine/schema/src/test/java/com/cloud/upgrade/DatabaseUpgradeCheckerTest.java +++ b/engine/schema/src/test/java/com/cloud/upgrade/DatabaseUpgradeCheckerTest.java @@ -223,4 +223,87 @@ public class DatabaseUpgradeCheckerTest { assertEquals("We should have 1 upgrade step", 1, upgrades.length); assertTrue(upgrades[0] instanceof NoopDbUpgrade); } + + @Test + public void testCalculateUpgradePathFrom41800toNextSecurityRelease() { + + final CloudStackVersion dbVersion = CloudStackVersion.parse("4.18.0.0"); + assertNotNull(dbVersion); + + final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker(); + final CloudStackVersion currentVersion = checker.getLatestVersion(); + assertNotNull(currentVersion); + + final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion); + assertNotNull(upgrades); + + final CloudStackVersion nextSecurityRelease = CloudStackVersion.parse(currentVersion.getMajorRelease() + "." + + currentVersion.getMinorRelease() + "." + + currentVersion.getPatchRelease() + "." + + (currentVersion.getSecurityRelease() + 1)); + assertNotNull(nextSecurityRelease); + + final DbUpgrade[] upgradesToNext = checker.calculateUpgradePath(dbVersion, nextSecurityRelease); + assertNotNull(upgradesToNext); + + assertEquals(upgrades.length + 1, upgradesToNext.length); + assertTrue(upgradesToNext[upgradesToNext.length - 1] instanceof NoopDbUpgrade); + } + + @Test + public void testCalculateUpgradePathFromSecurityReleaseToLatest() { + + final CloudStackVersion dbVersion = CloudStackVersion.parse("4.17.2.0"); // a EOL version + assertNotNull(dbVersion); + + final CloudStackVersion oldSecurityRelease = CloudStackVersion.parse(dbVersion.getMajorRelease() + "." + + dbVersion.getMinorRelease() + "." + + dbVersion.getPatchRelease() + "." + + (dbVersion.getSecurityRelease() + 100)); + assertNotNull(oldSecurityRelease); // fake security release 4.17.2.100 + + final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker(); + final CloudStackVersion currentVersion = checker.getLatestVersion(); + assertNotNull(currentVersion); + + final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion); + assertNotNull(upgrades); + + final DbUpgrade[] upgradesFromSecurityRelease = checker.calculateUpgradePath(oldSecurityRelease, currentVersion); + assertNotNull(upgradesFromSecurityRelease); + + assertEquals("The upgrade paths should be the same", upgrades.length, upgradesFromSecurityRelease.length); + } + + @Test + public void testCalculateUpgradePathFromSecurityReleaseToNextSecurityRelease() { + + final CloudStackVersion dbVersion = CloudStackVersion.parse("4.17.2.0"); // a EOL version + assertNotNull(dbVersion); + + final CloudStackVersion oldSecurityRelease = CloudStackVersion.parse(dbVersion.getMajorRelease() + "." + + dbVersion.getMinorRelease() + "." + + dbVersion.getPatchRelease() + "." + + (dbVersion.getSecurityRelease() + 100)); + assertNotNull(oldSecurityRelease); // fake security release 4.17.2.100 + + final DatabaseUpgradeChecker checker = new DatabaseUpgradeChecker(); + final CloudStackVersion currentVersion = checker.getLatestVersion(); + assertNotNull(currentVersion); + + final CloudStackVersion nextSecurityRelease = CloudStackVersion.parse(currentVersion.getMajorRelease() + "." + + currentVersion.getMinorRelease() + "." + + currentVersion.getPatchRelease() + "." + + (currentVersion.getSecurityRelease() + 1)); + assertNotNull(nextSecurityRelease); // fake security release + + final DbUpgrade[] upgrades = checker.calculateUpgradePath(dbVersion, currentVersion); + assertNotNull(upgrades); + + final DbUpgrade[] upgradesFromSecurityReleaseToNext = checker.calculateUpgradePath(oldSecurityRelease, nextSecurityRelease); + assertNotNull(upgradesFromSecurityReleaseToNext); + + assertEquals(upgrades.length + 1, upgradesFromSecurityReleaseToNext.length); + assertTrue(upgradesFromSecurityReleaseToNext[upgradesFromSecurityReleaseToNext.length - 1] instanceof NoopDbUpgrade); + } } diff --git a/engine/schema/src/test/java/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java b/engine/schema/src/test/java/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java index bd05fbe3c4c..4c07abda938 100644 --- a/engine/schema/src/test/java/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java +++ b/engine/schema/src/test/java/com/cloud/upgrade/dao/DatabaseAccessObjectTest.java @@ -16,7 +16,6 @@ // under the License. package com.cloud.upgrade.dao; - import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.contains; @@ -32,14 +31,13 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.test.util.ReflectionTestUtils; @RunWith(MockitoJUnitRunner.class) public class DatabaseAccessObjectTest { @@ -60,8 +58,7 @@ public class DatabaseAccessObjectTest { @Before public void setup() { - ReflectionTestUtils.setField(dao, "s_logger", loggerMock); - + dao.logger = loggerMock; } @Test diff --git a/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java b/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java index c3ad42a9130..05d9154b6a4 100644 --- a/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/usage/dao/UsageStorageDaoImplTest.java @@ -17,7 +17,7 @@ package com.cloud.usage.dao; -import static org.mockito.Matchers.contains; +import static org.mockito.ArgumentMatchers.contains; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java b/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java index 767b41420b7..4a32dc08359 100644 --- a/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java +++ b/engine/schema/src/test/java/com/cloud/vm/dao/VMInstanceDaoImplTest.java @@ -17,22 +17,33 @@ package com.cloud.vm.dao; -import com.cloud.utils.Pair; -import com.cloud.vm.VirtualMachine; -import org.joda.time.DateTime; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.mockito.Mock; - import static com.cloud.vm.VirtualMachine.State.Running; import static com.cloud.vm.VirtualMachine.State.Stopped; - +import static com.cloud.vm.dao.VMInstanceDaoImpl.MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.cloud.vm.VMInstanceVO; + +import java.util.Date; + +import org.joda.time.DateTime; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.Spy; +import com.cloud.utils.Pair; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; + /** * Created by sudharma_jain on 3/2/17. */ @@ -45,26 +56,147 @@ public class VMInstanceDaoImplTest { @Mock VMInstanceVO vm; + private AutoCloseable closeable; + @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); Long hostId = null; when(vm.getHostId()).thenReturn(hostId); when(vm.getUpdated()).thenReturn(5L); when(vm.getUpdateTime()).thenReturn(DateTime.now().toDate()); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test - public void testUpdateState() throws Exception { + public void testUpdateState() { Long destHostId = null; - Pair opaqueMock = new Pair(new Long(1), destHostId); + Pair opaqueMock = new Pair<>(1L, destHostId); vmInstanceDao.updateState(Stopped, VirtualMachine.Event.FollowAgentPowerOffReport, Stopped, vm , opaqueMock); } @Test - public void testIfStateAndHostUnchanged() throws Exception { - Assert.assertEquals(vmInstanceDao.ifStateUnchanged(Stopped, Stopped, null, null), true); - Assert.assertEquals(vmInstanceDao.ifStateUnchanged(Stopped, Running, null, null), false); + public void testIfStateAndHostUnchanged() { + assertTrue(vmInstanceDao.ifStateUnchanged(Stopped, Stopped, null, null)); + assertFalse(vmInstanceDao.ifStateUnchanged(Stopped, Running, null, null)); } + @Test + public void testUpdatePowerStateDifferentPowerState() { + when(vm.getPowerStateUpdateTime()).thenReturn(null); + when(vm.getPowerHostId()).thenReturn(1L); + when(vm.getPowerState()).thenReturn(VirtualMachine.PowerState.PowerOn); + doReturn(vm).when(vmInstanceDao).findById(anyLong()); + doReturn(true).when(vmInstanceDao).update(anyLong(), any()); + + boolean result = vmInstanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOff, new Date()); + + verify(vm, times(1)).setPowerState(VirtualMachine.PowerState.PowerOff); + verify(vm, times(1)).setPowerHostId(1L); + verify(vm, times(1)).setPowerStateUpdateCount(1); + verify(vm, times(1)).setPowerStateUpdateTime(any(Date.class)); + + assertTrue(result); + } + + @Test + public void testUpdatePowerStateVmNotFound() { + when(vm.getPowerStateUpdateTime()).thenReturn(null); + when(vm.getPowerHostId()).thenReturn(1L); + when(vm.getPowerState()).thenReturn(VirtualMachine.PowerState.PowerOn); + doReturn(null).when(vmInstanceDao).findById(anyLong()); + + boolean result = vmInstanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOff, new Date()); + + verify(vm, never()).setPowerState(any()); + verify(vm, never()).setPowerHostId(anyLong()); + verify(vm, never()).setPowerStateUpdateCount(any(Integer.class)); + verify(vm, never()).setPowerStateUpdateTime(any(Date.class)); + + assertFalse(result); + } + + @Test + public void testUpdatePowerStateNoChangeFirstUpdate() { + when(vm.getPowerStateUpdateTime()).thenReturn(null); + when(vm.getPowerHostId()).thenReturn(1L); + when(vm.getPowerState()).thenReturn(VirtualMachine.PowerState.PowerOn); + when(vm.getState()).thenReturn(Running); + when(vm.getPowerStateUpdateCount()).thenReturn(1); + doReturn(vm).when(vmInstanceDao).findById(anyLong()); + doReturn(true).when(vmInstanceDao).update(anyLong(), any()); + + boolean result = vmInstanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOn, new Date()); + + verify(vm, never()).setPowerState(any()); + verify(vm, never()).setPowerHostId(anyLong()); + verify(vm, times(1)).setPowerStateUpdateCount(2); + verify(vm, times(1)).setPowerStateUpdateTime(any(Date.class)); + + assertTrue(result); + } + + @Test + public void testUpdatePowerStateNoChangeMaxUpdatesValidState() { + when(vm.getPowerStateUpdateTime()).thenReturn(null); + when(vm.getPowerHostId()).thenReturn(1L); + when(vm.getPowerState()).thenReturn(VirtualMachine.PowerState.PowerOn); + when(vm.getPowerStateUpdateCount()).thenReturn(MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT); + when(vm.getState()).thenReturn(Running); + doReturn(vm).when(vmInstanceDao).findById(anyLong()); + doReturn(true).when(vmInstanceDao).update(anyLong(), any()); + + boolean result = vmInstanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOn, new Date()); + + verify(vm, never()).setPowerState(any()); + verify(vm, never()).setPowerHostId(anyLong()); + verify(vm, never()).setPowerStateUpdateCount(any(Integer.class)); + verify(vm, never()).setPowerStateUpdateTime(any(Date.class)); + + assertFalse(result); + } + + @Test + public void testUpdatePowerStateNoChangeMaxUpdatesInvalidStateVmStopped() { + when(vm.getPowerStateUpdateTime()).thenReturn(null); + when(vm.getPowerHostId()).thenReturn(1L); + when(vm.getPowerState()).thenReturn(VirtualMachine.PowerState.PowerOn); + when(vm.getPowerStateUpdateCount()).thenReturn(MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT); + when(vm.getState()).thenReturn(Stopped); + doReturn(vm).when(vmInstanceDao).findById(anyLong()); + doReturn(true).when(vmInstanceDao).update(anyLong(), any()); + + boolean result = vmInstanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOn, new Date()); + + verify(vm, times(1)).setPowerState(any()); + verify(vm, times(1)).setPowerHostId(anyLong()); + verify(vm, times(1)).setPowerStateUpdateCount(1); + verify(vm, times(1)).setPowerStateUpdateTime(any(Date.class)); + + assertTrue(result); + } + + @Test + public void testUpdatePowerStateNoChangeMaxUpdatesInvalidStateVmRunning() { + when(vm.getPowerStateUpdateTime()).thenReturn(null); + when(vm.getPowerHostId()).thenReturn(1L); + when(vm.getPowerState()).thenReturn(VirtualMachine.PowerState.PowerOff); + when(vm.getPowerStateUpdateCount()).thenReturn(MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT); + when(vm.getState()).thenReturn(Running); + doReturn(vm).when(vmInstanceDao).findById(anyLong()); + doReturn(true).when(vmInstanceDao).update(anyLong(), any()); + + boolean result = vmInstanceDao.updatePowerState(1L, 1L, VirtualMachine.PowerState.PowerOff, new Date()); + + verify(vm, times(1)).setPowerState(any()); + verify(vm, times(1)).setPowerHostId(anyLong()); + verify(vm, times(1)).setPowerStateUpdateCount(1); + verify(vm, times(1)).setPowerStateUpdateTime(any(Date.class)); + + assertTrue(result); + } } diff --git a/engine/schema/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/schema/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/schema/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/service/pom.xml b/engine/service/pom.xml index 8519fe9c0d1..a3e07890bb6 100644 --- a/engine/service/pom.xml +++ b/engine/service/pom.xml @@ -22,7 +22,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT cloud-engine-service war diff --git a/engine/service/src/main/webapp/WEB-INF/log4j.xml b/engine/service/src/main/webapp/WEB-INF/log4j.xml index 19d48b47e83..48d61a10b41 100644 --- a/engine/service/src/main/webapp/WEB-INF/log4j.xml +++ b/engine/service/src/main/webapp/WEB-INF/log4j.xml @@ -16,24 +16,41 @@ specific language governing permissions and limitations under the License. --> - - - - - - - - - + + - - - - - - - - - - - + + net.sf.cglib.proxy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/engine/storage/cache/pom.xml b/engine/storage/cache/pom.xml index 989402c0635..a1b7aff7afd 100644 --- a/engine/storage/cache/pom.xml +++ b/engine/storage/cache/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java b/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java index 22b3f46a946..fe3bb5cf00d 100644 --- a/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java +++ b/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/allocator/StorageCacheRandomAllocator.java @@ -22,7 +22,8 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; @@ -39,7 +40,7 @@ import com.cloud.storage.ScopeType; @Component public class StorageCacheRandomAllocator implements StorageCacheAllocator { - private static final Logger s_logger = Logger.getLogger(StorageCacheRandomAllocator.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject DataStoreManager dataStoreMgr; @Inject @@ -52,13 +53,13 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator { @Override public DataStore getCacheStore(Scope scope) { if (scope.getScopeType() != ScopeType.ZONE) { - s_logger.debug("Can only support zone wide cache storage"); + logger.debug("Can only support zone wide cache storage"); return null; } List cacheStores = dataStoreMgr.getImageCacheStores(scope); if ((cacheStores == null) || (cacheStores.size() <= 0)) { - s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); + logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); return null; } @@ -68,13 +69,13 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator { @Override public DataStore getCacheStore(DataObject data, Scope scope) { if (scope.getScopeType() != ScopeType.ZONE) { - s_logger.debug("Can only support zone wide cache storage"); + logger.debug("Can only support zone wide cache storage"); return null; } List cacheStores = dataStoreMgr.getImageCacheStores(scope); if (cacheStores.size() <= 0) { - s_logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); + logger.debug("Can't find staging storage in zone: " + scope.getScopeId()); return null; } @@ -83,7 +84,7 @@ public class StorageCacheRandomAllocator implements StorageCacheAllocator { for (DataStore store : cacheStores) { DataObjectInStore obj = objectInStoreMgr.findObject(data, store); if (obj != null && obj.getState() == ObjectInDataStoreStateMachine.State.Ready && statsCollector.imageStoreHasEnoughCapacity(store)) { - s_logger.debug("pick the cache store " + store.getId() + " where data is already there"); + logger.debug("pick the cache store " + store.getId() + " where data is already there"); return store; } } diff --git a/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java b/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java index a687ddfc437..889d0ce14cc 100644 --- a/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java +++ b/engine/storage/cache/src/main/java/org/apache/cloudstack/storage/cache/manager/StorageCacheManagerImpl.java @@ -32,7 +32,8 @@ import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService; @@ -64,7 +65,7 @@ import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.exception.CloudRuntimeException; public class StorageCacheManagerImpl implements StorageCacheManager, Manager { - private static final Logger s_logger = Logger.getLogger(StorageCacheManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject List storageCacheAllocator; @Inject @@ -195,7 +196,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { } } } catch (Exception e) { - s_logger.debug("Failed to execute CacheReplacementRunner: " + e.toString()); + logger.debug("Failed to execute CacheReplacementRunner: " + e.toString()); } finally { if (replacementLock != null) { replacementLock.unlock(); @@ -245,7 +246,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { String msg = "unsupported DataObject comes, then can't acquire correct lock object"; throw new CloudRuntimeException(msg); } - s_logger.debug("check " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")"); + logger.debug("check " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")"); DataObject existingDataObj = null; synchronized (lock) { @@ -271,13 +272,13 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { * Threads must release lock within waiting for cache copy and * must be waken up at completion. */ - s_logger.debug("waiting cache copy completion type: " + typeName + ", id: " + obj.getObjectId() + ", lock: " + lock.hashCode()); + logger.debug("waiting cache copy completion type: " + typeName + ", id: " + obj.getObjectId() + ", lock: " + lock.hashCode()); try { lock.wait(milliSeconds); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while waiting for cache copy completion."); + logger.debug("[ignored] interrupted while waiting for cache copy completion."); } - s_logger.debug("waken up"); + logger.debug("waken up"); now = new Date(); if (now.after(expiredDate)) { @@ -290,7 +291,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { } if (st == ObjectInDataStoreStateMachine.State.Ready) { - s_logger.debug("there is already one in the cache store"); + logger.debug("there is already one in the cache store"); DataObject dataObj = objectInStoreMgr.get(data, store, null); dataObj.incRefCount(); existingDataObj = dataObj; @@ -298,7 +299,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { } if(existingDataObj == null) { - s_logger.debug("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")"); + logger.debug("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ")"); objOnCacheStore = store.create(data); } lock.notifyAll(); @@ -307,7 +308,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { return existingDataObj; } if (objOnCacheStore == null) { - s_logger.error("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ") failed"); + logger.error("create " + typeName + " cache entry(id: " + dataId + ") on store(id: " + storeId + ") failed"); return null; } @@ -327,10 +328,10 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { return objOnCacheStore; } } catch (InterruptedException e) { - s_logger.debug("create cache storage failed: " + e.toString()); + logger.debug("create cache storage failed: " + e.toString()); throw new CloudRuntimeException(e); } catch (ExecutionException e) { - s_logger.debug("create cache storage failed: " + e.toString()); + logger.debug("create cache storage failed: " + e.toString()); throw new CloudRuntimeException(e); } finally { if (result == null) { @@ -340,7 +341,7 @@ public class StorageCacheManagerImpl implements StorageCacheManager, Manager { /* * Wake up all threads waiting for cache copy. */ - s_logger.debug("wake up all waiting threads(lock: " + lock.hashCode() + ")"); + logger.debug("wake up all waiting threads(lock: " + lock.hashCode() + ")"); lock.notifyAll(); } } diff --git a/engine/storage/configdrive/pom.xml b/engine/storage/configdrive/pom.xml index 041616d5eaa..b14acf10138 100644 --- a/engine/storage/configdrive/pom.xml +++ b/engine/storage/configdrive/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java b/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java index e02c0920004..e1d51120efa 100644 --- a/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java +++ b/engine/storage/configdrive/src/main/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java @@ -37,7 +37,8 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.MapUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.joda.time.Duration; import com.cloud.network.NetworkModel; @@ -49,7 +50,7 @@ import com.google.gson.JsonObject; public class ConfigDriveBuilder { - public static final Logger LOG = Logger.getLogger(ConfigDriveBuilder.class); + protected static Logger LOGGER = LogManager.getLogger(ConfigDriveBuilder.class); /** * This is for mocking the File class. We cannot mock the File class directly because Mockito uses it internally. @@ -98,7 +99,7 @@ public class ConfigDriveBuilder { try { Files.createDirectories(destPath.getParent()); } catch (final IOException e) { - LOG.warn("Exception hit while trying to recreate directory: " + destPath.getParent().toString()); + LOGGER.warn("Exception hit while trying to recreate directory: " + destPath.getParent().toString()); } return Files.write(destPath, decoded).toFile(); } @@ -139,7 +140,7 @@ public class ConfigDriveBuilder { FileUtils.deleteDirectory(tempDir.toFile()); } } catch (IOException ioe) { - LOG.warn("Failed to delete ConfigDrive temporary directory: " + tempDir.toString(), ioe); + LOGGER.warn("Failed to delete ConfigDrive temporary directory: " + tempDir.toString(), ioe); } } @@ -151,7 +152,7 @@ public class ConfigDriveBuilder { */ static String generateAndRetrieveIsoAsBase64Iso(String isoFileName, String driveLabel, String tempDirName) throws IOException { File tmpIsoStore = getFile(tempDirName, isoFileName); - Script command = new Script(getProgramToGenerateIso(), Duration.standardSeconds(300), LOG); + Script command = new Script(getProgramToGenerateIso(), Duration.standardSeconds(300), LOGGER); command.add("-o", tmpIsoStore.getAbsolutePath()); command.add("-ldots"); command.add("-allow-lowercase"); @@ -163,11 +164,11 @@ public class ConfigDriveBuilder { command.add("-r"); command.add("-V", driveLabel); command.add(tempDirName); - LOG.debug("Executing config drive creation command: " + command.toString()); + LOGGER.debug("Executing config drive creation command: " + command.toString()); String result = command.execute(); if (StringUtils.isNotBlank(result)) { String errMsg = "Unable to create iso file: " + isoFileName + " due to ge" + result; - LOG.warn(errMsg); + LOGGER.warn(errMsg); throw new CloudRuntimeException(errMsg); } File tmpIsoFile = getFile(tmpIsoStore.getAbsolutePath()); @@ -242,7 +243,7 @@ public class ConfigDriveBuilder { String dataType = item[CONFIGDATA_DIR]; String fileName = item[CONFIGDATA_FILE]; String content = item[CONFIGDATA_CONTENT]; - LOG.debug(String.format("[createConfigDriveIsoForVM] dataType=%s, filename=%s, content=%s", dataType, fileName, (PASSWORD_FILE.equals(fileName) ? "********" : content))); + LOGGER.debug(String.format("[createConfigDriveIsoForVM] dataType=%s, filename=%s, content=%s", dataType, fileName, (PASSWORD_FILE.equals(fileName) ? "********" : content))); createFileInTempDirAnAppendOpenStackMetadataToJsonObject(tempDirName, metaData, dataType, fileName, content, customUserdataParams); } @@ -299,10 +300,10 @@ public class ConfigDriveBuilder { String userDataFilePath = tempDirName + ConfigDrive.cloudStackConfigDriveName + "userdata/user_data.txt"; File file = getFile(userDataFilePath); if (file.exists()) { - Script hardLink = new Script("ln", Duration.standardSeconds(300), LOG); + Script hardLink = new Script("ln", Duration.standardSeconds(300), LOGGER); hardLink.add(userDataFilePath); hardLink.add(tempDirName + ConfigDrive.openStackConfigDriveName + "user_data"); - LOG.debug("execute command: " + hardLink.toString()); + LOGGER.debug("execute command: " + hardLink.toString()); String executionResult = hardLink.execute(); if (StringUtils.isNotBlank(executionResult)) { diff --git a/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java b/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java index 6ef248fdd62..eff881065c2 100644 --- a/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java +++ b/engine/storage/configdrive/src/test/java/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilderTest.java @@ -131,7 +131,7 @@ public class ConfigDriveBuilderTest { configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(Mockito.any(File.class))).then(invocationOnMock -> null); - configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVmMetadata(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.any(File.class), anyMap())).then(invocationOnMock -> null); + configDriveBuilderMocked.when(() -> ConfigDriveBuilder.writeVmMetadata(Mockito.anyList(), Mockito.anyString(), Mockito.any(File.class), anyMap())).then(invocationOnMock -> null); configDriveBuilderMocked.when(() -> ConfigDriveBuilder.linkUserData((Mockito.anyString()))).then(invocationOnMock -> null); @@ -145,7 +145,7 @@ public class ConfigDriveBuilderTest { configDriveBuilderMocked.verify(() -> { ConfigDriveBuilder.writeVendorAndNetworkEmptyJsonFile(Mockito.any(File.class)); - ConfigDriveBuilder.writeVmMetadata(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.any(File.class), anyMap()); + ConfigDriveBuilder.writeVmMetadata(Mockito.anyList(), Mockito.anyString(), Mockito.any(File.class), anyMap()); ConfigDriveBuilder.linkUserData(Mockito.anyString()); ConfigDriveBuilder.generateAndRetrieveIsoAsBase64Iso(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); }); @@ -194,7 +194,7 @@ public class ConfigDriveBuilderTest { @Test public void writeVmMetadataTest() { try (MockedStatic configDriveBuilderMocked = Mockito.mockStatic(ConfigDriveBuilder.class)) { - Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.anyMap())).thenReturn(new JsonObject()); + Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyList(), Mockito.anyString(), Mockito.anyMap())).thenReturn(new JsonObject()); List vmData = new ArrayList<>(); vmData.add(new String[]{"dataType", "fileName", "content"}); @@ -347,7 +347,7 @@ public class ConfigDriveBuilderTest { try (MockedStatic configDriveBuilderMocked = Mockito.mockStatic(ConfigDriveBuilder.class)) { - Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyListOf(String[].class), Mockito.anyString(), Mockito.nullable(Map.class))).thenCallRealMethod(); + Mockito.when(ConfigDriveBuilder.createJsonObjectWithVmData(Mockito.anyList(), Mockito.anyString(), Mockito.nullable(Map.class))).thenCallRealMethod(); List vmData = new ArrayList<>(); vmData.add(new String[]{"dataType", "fileName", "content"}); diff --git a/engine/storage/configdrive/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/storage/configdrive/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/storage/configdrive/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/storage/datamotion/pom.xml b/engine/storage/datamotion/pom.xml index aa3b9867f35..5620ca8ef70 100644 --- a/engine/storage/datamotion/pom.xml +++ b/engine/storage/datamotion/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java index 370753ed923..0b0065361d0 100644 --- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java +++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java @@ -51,7 +51,8 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.api.Answer; @@ -81,7 +82,7 @@ import com.cloud.vm.VirtualMachineManager; @Component public class AncientDataMotionStrategy implements DataMotionStrategy { - private static final Logger s_logger = Logger.getLogger(AncientDataMotionStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String NO_REMOTE_ENDPOINT_SSVM = "No remote endpoint to send command, check if host or ssvm is down?"; private static final String NO_REMOTE_ENDPOINT_WITH_ENCRYPTION = "No remote endpoint to send command, unable to find a valid endpoint. Requires encryption support: %s"; @@ -126,8 +127,8 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { if (destStoreTO instanceof NfsTO || destStoreTO.getRole() == DataStoreRole.ImageCache) { return false; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("needCacheStorage true, dest at " + destTO.getPath() + " dest role " + destStoreTO.getRole().toString() + srcTO.getPath() + " src role " + + if (logger.isDebugEnabled()) { + logger.debug("needCacheStorage true, dest at " + destTO.getPath() + " dest role " + destStoreTO.getRole().toString() + srcTO.getPath() + " src role " + srcStoreTO.getRole().toString()); } return true; @@ -157,7 +158,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { } else if (destScope.getScopeId() != null) { selectedScope = getZoneScope(destScope); } else { - s_logger.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); + logger.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); } return selectedScope; } @@ -177,7 +178,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { VirtualMachineManager.ExecuteInSequence.value()); EndPoint ep = destHost != null ? RemoteHostEndPoint.getHypervisorHostEndPoint(destHost) : selector.select(srcForCopy, destData); if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -193,19 +194,19 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { destData.getType() == DataObjectType.TEMPLATE)) { // volume transfer from primary to secondary. Volume transfer between primary pools are already handled by copyVolumeBetweenPools // Delete cache in order to certainly transfer a latest image. - if (s_logger.isDebugEnabled()) s_logger.debug("Delete " + cacheType + " cache(id: " + cacheId + + if (logger.isDebugEnabled()) logger.debug("Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")"); cacheMgr.deleteCacheObject(srcForCopy); } else { // for template, we want to leave it on cache for performance reason if ((answer == null || !answer.getResult()) && srcForCopy.getRefCount() < 2) { // cache object created by this copy, not already there - s_logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + + logger.warn("Copy may not be handled correctly by agent(id: " + (ep != null ? ep.getId() : "\"unspecified\"") + ")." + " Delete " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")"); cacheMgr.deleteCacheObject(srcForCopy); } else { - if (s_logger.isDebugEnabled()) s_logger.debug("Decrease reference count of " + cacheType + + if (logger.isDebugEnabled()) logger.debug("Decrease reference count of " + cacheType + " cache(id: " + cacheId + ", uuid: " + cacheUuid + ")"); cacheMgr.releaseCacheObject(srcForCopy); } @@ -213,7 +214,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { } return answer; } catch (Exception e) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy object failed: ", e); + if (logger.isDebugEnabled()) logger.debug("copy object failed: ", e); if (cacheData != null) { cacheMgr.deleteCacheObject(cacheData); } @@ -300,7 +301,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { Answer answer = null; if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -308,7 +309,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { return answer; } catch (Exception e) { - s_logger.error(basicErrMsg, e); + logger.error(basicErrMsg, e); throw new CloudRuntimeException(basicErrMsg); } finally { if (!(storTO instanceof NfsTO)) { @@ -324,14 +325,14 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { EndPoint ep = selector.select(volume, anyVolumeRequiresEncryption(volume)); Answer answer = null; if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); } return answer; } catch (Exception e) { - if (s_logger.isDebugEnabled()) s_logger.debug("Failed to send to storage pool", e); + if (logger.isDebugEnabled()) logger.debug("Failed to send to storage pool", e); throw new CloudRuntimeException("Failed to send to storage pool", e); } } @@ -364,7 +365,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { Answer answer = null; if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -388,7 +389,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { if (answer == null || !answer.getResult()) { if (answer != null) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy to image store failed: " + answer.getDetails()); + if (logger.isDebugEnabled()) logger.debug("copy to image store failed: " + answer.getDetails()); } objOnImageStore.processEvent(Event.OperationFailed); imageStore.delete(objOnImageStore); @@ -403,7 +404,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { EndPoint ep = selector.select(objOnImageStore, destData, encryptionRequired); if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -411,7 +412,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { if (answer == null || !answer.getResult()) { if (answer != null) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy to primary store failed: " + answer.getDetails()); + if (logger.isDebugEnabled()) logger.debug("copy to primary store failed: " + answer.getDetails()); } objOnImageStore.processEvent(Event.OperationFailed); imageStore.delete(objOnImageStore); @@ -422,7 +423,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { objOnImageStore.processEvent(Event.OperationFailed); imageStore.delete(objOnImageStore); } - s_logger.error("Failed to perform operation: "+ e.getLocalizedMessage()); + logger.error("Failed to perform operation: "+ e.getLocalizedMessage()); throw e; } @@ -436,7 +437,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { Answer answer = null; if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -468,19 +469,19 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { Answer answer = null; if (ep == null) { String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired); - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(command, false, errMsg); } else { - if (s_logger.isDebugEnabled()) s_logger.debug("Sending MIGRATE_COPY request to node " + ep); + if (logger.isDebugEnabled()) logger.debug("Sending MIGRATE_COPY request to node " + ep); answer = ep.sendMessage(command); - if (s_logger.isDebugEnabled()) s_logger.debug("Received MIGRATE_COPY response from node with answer: " + answer); + if (logger.isDebugEnabled()) logger.debug("Received MIGRATE_COPY response from node with answer: " + answer); } if (answer == null || !answer.getResult()) { throw new CloudRuntimeException("Failed to migrate volume " + volume + " to storage pool " + destPool); } else { // Update the volume details after migration. - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE_COPY updating volume"); + if (logger.isDebugEnabled()) logger.debug("MIGRATE_COPY updating volume"); VolumeVO volumeVo = volDao.findById(volume.getId()); Long oldPoolId = volume.getPoolId(); @@ -500,7 +501,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { } volumeVo.setFolder(folder); volDao.update(volume.getId(), volumeVo); - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE_COPY update volume data complete"); + if (logger.isDebugEnabled()) logger.debug("MIGRATE_COPY update volume data complete"); } @@ -513,7 +514,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { Answer answer = null; String errMsg = null; try { - if (s_logger.isDebugEnabled()) s_logger.debug("copyAsync inspecting src type " + srcData.getType().toString() + " copyAsync inspecting dest type " + destData.getType().toString()); + if (logger.isDebugEnabled()) logger.debug("copyAsync inspecting src type " + srcData.getType().toString() + " copyAsync inspecting dest type " + destData.getType().toString()); if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.VOLUME) { answer = copyVolumeFromSnapshot(srcData, destData); } else if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.TEMPLATE) { @@ -522,16 +523,16 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { answer = cloneVolume(srcData, destData); } else if (destData.getType() == DataObjectType.VOLUME && srcData.getType() == DataObjectType.VOLUME && srcData.getDataStore().getRole() == DataStoreRole.Primary && destData.getDataStore().getRole() == DataStoreRole.Primary) { - if (s_logger.isDebugEnabled()) s_logger.debug("About to MIGRATE copy between datasources"); + if (logger.isDebugEnabled()) logger.debug("About to MIGRATE copy between datasources"); if (srcData.getId() == destData.getId()) { // The volume has to be migrated across storage pools. - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE copy using migrateVolumeToPool STARTING"); + if (logger.isDebugEnabled()) logger.debug("MIGRATE copy using migrateVolumeToPool STARTING"); answer = migrateVolumeToPool(srcData, destData); - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE copy using migrateVolumeToPool DONE: " + answer.getResult()); + if (logger.isDebugEnabled()) logger.debug("MIGRATE copy using migrateVolumeToPool DONE: " + answer.getResult()); } else { - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE copy using copyVolumeBetweenPools STARTING"); + if (logger.isDebugEnabled()) logger.debug("MIGRATE copy using copyVolumeBetweenPools STARTING"); answer = copyVolumeBetweenPools(srcData, destData); - if (s_logger.isDebugEnabled()) s_logger.debug("MIGRATE copy using copyVolumeBetweenPools DONE: " + answer.getResult()); + if (logger.isDebugEnabled()) logger.debug("MIGRATE copy using copyVolumeBetweenPools DONE: " + answer.getResult()); } } else if (srcData.getType() == DataObjectType.SNAPSHOT && destData.getType() == DataObjectType.SNAPSHOT) { answer = copySnapshot(srcData, destData); @@ -543,7 +544,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { errMsg = answer.getDetails(); } } catch (Exception e) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy failed", e); + if (logger.isDebugEnabled()) logger.debug("copy failed", e); errMsg = e.toString(); } CopyCommandResult result = new CopyCommandResult(null, answer); @@ -574,7 +575,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { CopyCommand cmd = new CopyCommand(srcData.getTO(), addFullCloneAndDiskprovisiongStrictnessFlagOnVMwareDest(destData.getTO()), _createprivatetemplatefromsnapshotwait, VirtualMachineManager.ExecuteInSequence.value()); Answer answer = null; if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -614,7 +615,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { cmd.setOptions(options); EndPoint ep = selector.select(srcData, destData, encryptionRequired); if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -625,7 +626,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { cmd.setOptions(options); EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT, encryptionRequired); if (ep == null) { - s_logger.error(NO_REMOTE_ENDPOINT_SSVM); + logger.error(NO_REMOTE_ENDPOINT_SSVM); answer = new Answer(cmd, false, NO_REMOTE_ENDPOINT_SSVM); } else { answer = ep.sendMessage(cmd); @@ -638,7 +639,7 @@ public class AncientDataMotionStrategy implements DataMotionStrategy { } return answer; } catch (Exception e) { - if (s_logger.isDebugEnabled()) s_logger.debug("copy snasphot failed: ", e); + if (logger.isDebugEnabled()) logger.debug("copy snasphot failed: ", e); if (cacheData != null) { cacheMgr.deleteCacheObject(cacheData); } diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java index c8edb7b8abc..e55302b8044 100644 --- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java +++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java @@ -36,7 +36,8 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.secret.dao.PassphraseDao; import org.apache.cloudstack.storage.command.CopyCmdAnswer; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.api.to.VirtualMachineTO; @@ -48,7 +49,7 @@ import com.cloud.storage.dao.VolumeDao; @Component public class DataMotionServiceImpl implements DataMotionService { - private static final Logger LOGGER = Logger.getLogger(DataMotionServiceImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject StorageStrategyFactory storageStrategyFactory; diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java index f2ccce75690..bf8fa43fe6c 100644 --- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java +++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java @@ -36,7 +36,6 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.MigrateCommand; @@ -74,7 +73,6 @@ public class KvmNonManagedStorageDataMotionStrategy extends StorageSystemDataMot @Inject private VirtualMachineManager virtualMachineManager; - private static final Logger LOGGER = Logger.getLogger(KvmNonManagedStorageDataMotionStrategy.class); /** * Uses the canHandle from the Super class {@link StorageSystemDataMotionStrategy}. If the storage pool is of file and the internalCanHandle from {@link StorageSystemDataMotionStrategy} CANT_HANDLE, returns the StrategyPriority.HYPERVISOR strategy priority. otherwise returns CANT_HANDLE. @@ -212,7 +210,7 @@ public class KvmNonManagedStorageDataMotionStrategy extends StorageSystemDataMot TemplateInfo directDownloadTemplateInfo = templateDataFactory.getReadyBypassedTemplateOnPrimaryStore(srcVolumeInfo.getTemplateId(), destDataStore.getId(), destHost.getId()); if (directDownloadTemplateInfo != null) { - LOGGER.debug(String.format("Template %s was of direct download type and successfully staged to primary store %s", directDownloadTemplateInfo.getId(), directDownloadTemplateInfo.getDataStore().getId())); + logger.debug(String.format("Template %s was of direct download type and successfully staged to primary store %s", directDownloadTemplateInfo.getId(), directDownloadTemplateInfo.getDataStore().getId())); return; } @@ -223,7 +221,7 @@ public class KvmNonManagedStorageDataMotionStrategy extends StorageSystemDataMot TemplateInfo sourceTemplateInfo = templateDataFactory.getTemplate(srcVolumeInfo.getTemplateId(), sourceTemplateDataStore); TemplateObjectTO sourceTemplate = new TemplateObjectTO(sourceTemplateInfo); - LOGGER.debug(String.format("Could not find template [id=%s, name=%s] on the storage pool [id=%s]; copying the template to the target storage pool.", + logger.debug(String.format("Could not find template [id=%s, name=%s] on the storage pool [id=%s]; copying the template to the target storage pool.", srcVolumeInfo.getTemplateId(), sourceTemplateInfo.getName(), destDataStore.getId())); TemplateInfo destTemplateInfo = templateDataFactory.getTemplate(srcVolumeInfo.getTemplateId(), destDataStore); @@ -236,7 +234,7 @@ public class KvmNonManagedStorageDataMotionStrategy extends StorageSystemDataMot return; } } - LOGGER.debug(String.format("Skipping 'copy template to target filesystem storage before migration' due to the template [%s] already exist on the storage pool [%s].", srcVolumeInfo.getTemplateId(), destStoragePool.getId())); + logger.debug(String.format("Skipping 'copy template to target filesystem storage before migration' due to the template [%s] already exist on the storage pool [%s].", srcVolumeInfo.getTemplateId(), destStoragePool.getId())); } /** @@ -282,7 +280,7 @@ public class KvmNonManagedStorageDataMotionStrategy extends StorageSystemDataMot if (copyCommandAnswer.getDetails() != null) { failureDetails = " Details: " + copyCommandAnswer.getDetails(); } - LOGGER.error(generateFailToCopyTemplateMessage(sourceTemplate, destDataStore) + failureDetails); + logger.error(generateFailToCopyTemplateMessage(sourceTemplate, destDataStore) + failureDetails); } } diff --git a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java index a93f624aa53..03aa5b50988 100644 --- a/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java +++ b/engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java @@ -71,7 +71,8 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -141,7 +142,7 @@ import java.util.stream.Collectors; import org.apache.commons.collections.CollectionUtils; public class StorageSystemDataMotionStrategy implements DataMotionStrategy { - private static final Logger LOGGER = Logger.getLogger(StorageSystemDataMotionStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final Random RANDOM = new Random(System.nanoTime()); private static final int LOCK_TIME_IN_SECONDS = 300; private static final String OPERATION_NOT_SUPPORTED = "This operation is not supported."; @@ -263,7 +264,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { Boolean supportsStorageSystemSnapshots = Boolean.valueOf(value); if (supportsStorageSystemSnapshots) { - LOGGER.info("Using 'StorageSystemDataMotionStrategy' (dataObject is a volume or snapshot and the storage system supports snapshots)"); + logger.info("Using 'StorageSystemDataMotionStrategy' (dataObject is a volume or snapshot and the storage system supports snapshots)"); return true; } @@ -273,7 +274,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { Boolean canCloneVolume = Boolean.valueOf(value); if (canCloneVolume) { - LOGGER.info("Using 'StorageSystemDataMotionStrategy' (dataObject is a template and the storage system can create a volume from a volume)"); + logger.info("Using 'StorageSystemDataMotionStrategy' (dataObject is a template and the storage system can create a volume from a volume)"); return true; } @@ -434,7 +435,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } private void handleError(String errMsg, AsyncCompletionCallback callback) { - LOGGER.warn(errMsg); + logger.warn(errMsg); invokeCallback(errMsg, callback); @@ -638,8 +639,8 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { return false; } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("needCacheStorage true; dest at " + destTO.getPath() + ", dest role " + destStoreTO.getRole().toString() + "; src at " + + if (logger.isDebugEnabled()) { + logger.debug("needCacheStorage true; dest at " + destTO.getPath() + ", dest role " + destStoreTO.getRole().toString() + "; src at " + srcTO.getPath() + ", src role " + srcStoreTO.getRole().toString()); } @@ -657,7 +658,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } else if (destScope.getScopeId() != null) { selectedScope = getZoneScope(destScope); } else { - LOGGER.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); + logger.warn("Cannot find a zone-wide scope for movement that needs a cache storage"); } return selectedScope; @@ -770,7 +771,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { if (ep == null) { String errMsg = "No remote endpoint to send command to; check if host or SSVM is down"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(command, false, errMsg); } else { @@ -811,7 +812,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { _volumeService.revokeAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore()); } catch (Exception ex) { - LOGGER.warn("Failed to revoke access to the volume with the following ID: " + destVolumeInfo.getId()); + logger.warn("Failed to revoke access to the volume with the following ID: " + destVolumeInfo.getId()); } try { @@ -825,7 +826,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { volumeDetailsDao.removeDetails(srcVolumeInfo.getId()); } catch (Exception ex) { - LOGGER.warn(ex.getMessage()); + logger.warn(ex.getMessage()); } VolumeVO volumeVO = _volumeDao.findById(srcVolumeInfo.getId()); @@ -972,7 +973,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId(); - LOGGER.warn(noSupportForResignErrMsg); + logger.warn(noSupportForResignErrMsg); throw new CloudRuntimeException(noSupportForResignErrMsg); } @@ -1053,7 +1054,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { if (!copyCmdAnswer.getResult()) { errMsg = copyCmdAnswer.getDetails(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -1074,7 +1075,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { if (ep == null) { errMsg = "No remote endpoint to send command, check if host or SSVM is down"; - LOGGER.error(errMsg); + logger.error(errMsg); copyCmdAnswer = new CopyCmdAnswer(errMsg); } else { @@ -1087,7 +1088,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) { String msg = "Failed to create template from snapshot (Snapshot ID = " + snapshotInfo.getId() + ") : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } finally { @@ -1122,7 +1123,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } } catch (Exception ex) { - LOGGER.warn("Error processing snapshot event: " + ex.getMessage(), ex); + logger.warn("Error processing snapshot event: " + ex.getMessage(), ex); } } } @@ -1182,7 +1183,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + volumeStoragePoolVO.getClusterId(); - LOGGER.warn(noSupportForResignErrMsg); + logger.warn(noSupportForResignErrMsg); throw new CloudRuntimeException(noSupportForResignErrMsg); } @@ -1219,7 +1220,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { if (!copyCmdAnswer.getResult()) { errMsg = copyCmdAnswer.getDetails(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -1239,7 +1240,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { _volumeService.revokeAccess(snapshotInfo, hostVO, snapshotDataStore); } catch (Exception e) { - LOGGER.debug("Failed to revoke access from dest volume", e); + logger.debug("Failed to revoke access from dest volume", e); } if (usingBackendSnapshot) { @@ -1255,7 +1256,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } } catch (Exception ex) { - LOGGER.warn("Error processing snapshot event: " + ex.getMessage(), ex); + logger.warn("Error processing snapshot event: " + ex.getMessage(), ex); } if (copyCmdAnswer == null) { @@ -1314,7 +1315,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { VolumeApiResult result = future.get(); if (result.isFailed()) { - LOGGER.error("Failed to create a volume: " + result.getResult()); + logger.error("Failed to create a volume: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } @@ -1409,7 +1410,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId(); - LOGGER.warn(noSupportForResignErrMsg); + logger.warn(noSupportForResignErrMsg); throw new CloudRuntimeException(noSupportForResignErrMsg); } @@ -1442,7 +1443,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } if (result.isFailed()) { - LOGGER.warn("Failed to create a volume: " + result.getResult()); + logger.warn("Failed to create a volume: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } @@ -1486,7 +1487,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { volumeInfo.getDataStore().getDriver().deleteAsync(volumeInfo.getDataStore(), volumeInfo, null); } catch (Exception exc) { - LOGGER.warn("Failed to delete volume", exc); + logger.warn("Failed to delete volume", exc); } if (templateInfo != null) { @@ -1533,7 +1534,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId(); - LOGGER.warn(noSupportForResignErrMsg); + logger.warn(noSupportForResignErrMsg); throw new CloudRuntimeException(noSupportForResignErrMsg); } @@ -1569,7 +1570,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } if (result.isFailed()) { - LOGGER.warn("Failed to create a volume: " + result.getResult()); + logger.warn("Failed to create a volume: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } @@ -1713,7 +1714,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) { String msg = "Failed to copy image : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } @@ -1829,7 +1830,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { ((PrimaryDataStoreDriver)volumeInfo.getDataStore().getDriver()).handleQualityOfServiceForVolumeMigration(volumeInfo, qualityOfServiceState); } catch (Exception ex) { - LOGGER.warn(ex); + logger.warn(ex); } } @@ -1933,10 +1934,10 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } if (srcVolumeInfo.getTemplateId() != null) { - LOGGER.debug(String.format("Copying template [%s] of volume [%s] from source storage pool [%s] to target storage pool [%s].", srcVolumeInfo.getTemplateId(), srcVolumeInfo.getId(), sourceStoragePool.getId(), destStoragePool.getId())); + logger.debug(String.format("Copying template [%s] of volume [%s] from source storage pool [%s] to target storage pool [%s].", srcVolumeInfo.getTemplateId(), srcVolumeInfo.getId(), sourceStoragePool.getId(), destStoragePool.getId())); copyTemplateToTargetFilesystemStorageIfNeeded(srcVolumeInfo, sourceStoragePool, destDataStore, destStoragePool, destHost); } else { - LOGGER.debug(String.format("Skipping copy template from source storage pool [%s] to target storage pool [%s] before migration due to volume [%s] does not have a template.", sourceStoragePool.getId(), destStoragePool.getId(), srcVolumeInfo.getId())); + logger.debug(String.format("Skipping copy template from source storage pool [%s] to target storage pool [%s] before migration due to volume [%s] does not have a template.", sourceStoragePool.getId(), destStoragePool.getId(), srcVolumeInfo.getId())); } VolumeVO destVolume = duplicateVolumeOnAnotherStorage(srcVolume, destStoragePool); @@ -2026,7 +2027,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { Integer newVmCpuShares = ((PrepareForMigrationAnswer) pfma).getNewVmCpuShares(); if (newVmCpuShares != null) { - LOGGER.debug(String.format("Setting CPU shares to [%d] as part of migrate VM with volumes command for VM [%s].", newVmCpuShares, vmTO)); + logger.debug(String.format("Setting CPU shares to [%d] as part of migrate VM with volumes command for VM [%s].", newVmCpuShares, vmTO)); migrateCommand.setNewVmCpuShares(newVmCpuShares); } @@ -2052,7 +2053,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { String volumesAndStorages = volumeDataStoreMap.entrySet().stream().map(entry -> formatEntryOfVolumesAndStoragesAsJsonToDisplayOnLog(entry)).collect(Collectors.joining(",")); errMsg = String.format("Copy volume(s) to storage(s) [%s] and VM to host [%s] failed in StorageSystemDataMotionStrategy.copyAsync. Error message: [%s].", volumesAndStorages, formatMigrationElementsAsJsonToDisplayOnLog("vm", vmTO.getId(), srcHost.getId(), destHost.getId()), ex.getMessage()); - LOGGER.error(errMsg, ex); + logger.error(errMsg, ex); throw new CloudRuntimeException(errMsg); } finally { @@ -2176,7 +2177,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } } catch (Exception e) { - LOGGER.debug("Failed to disconnect one or more (original) dest volumes", e); + logger.debug("Failed to disconnect one or more (original) dest volumes", e); } } @@ -2205,14 +2206,14 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { disconnectHostFromVolume(destHost, destVolumeInfo.getPoolId(), destVolumeInfo.get_iScsiName()); } catch (Exception e) { - LOGGER.debug("Failed to disconnect (new) dest volume", e); + logger.debug("Failed to disconnect (new) dest volume", e); } try { _volumeService.revokeAccess(destVolumeInfo, destHost, destVolumeInfo.getDataStore()); } catch (Exception e) { - LOGGER.debug("Failed to revoke access from dest volume", e); + logger.debug("Failed to revoke access from dest volume", e); } destVolumeInfo.processEvent(Event.OperationFailed); @@ -2226,10 +2227,10 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { AsyncCallFuture destroyFuture = _volumeService.expungeVolumeAsync(destVolumeInfo); if (destroyFuture.get().isFailed()) { - LOGGER.debug("Failed to clean up dest volume on storage"); + logger.debug("Failed to clean up dest volume on storage"); } } catch (Exception e) { - LOGGER.debug("Failed to clean up dest volume on storage", e); + logger.debug("Failed to clean up dest volume on storage", e); } } } @@ -2342,7 +2343,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { */ protected void prepareDiskWithSecretConsumerDetail(VirtualMachineTO vmTO, VolumeInfo srcVolume, String destPath) { if (vmTO.getDisks() != null) { - LOGGER.debug(String.format("Preparing VM TO '%s' disks with migration data", vmTO)); + logger.debug(String.format("Preparing VM TO '%s' disks with migration data", vmTO)); Arrays.stream(vmTO.getDisks()).filter(diskTO -> diskTO.getData().getId() == srcVolume.getId()).forEach( diskTO -> { if (diskTO.getDetails() == null) { diskTO.setDetails(new HashMap<>()); @@ -2396,7 +2397,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { */ protected void addSourcePoolToPoolsMap(Map sourcePools, StoragePoolVO srcStoragePoolVO, StoragePoolVO destStoragePoolVO) { if (destStoragePoolVO.isManaged() || !StoragePoolType.NetworkFilesystem.equals(destStoragePoolVO.getPoolType())) { - LOGGER.trace(String.format("Skipping adding source pool [%s] to map due to destination pool [%s] is managed or not NFS.", srcStoragePoolVO, destStoragePoolVO)); + logger.trace(String.format("Skipping adding source pool [%s] to map due to destination pool [%s] is managed or not NFS.", srcStoragePoolVO, destStoragePoolVO)); return; } @@ -2413,7 +2414,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { */ private void verifyDestinationStorage(Map sourcePools, Host destHost) { if (MapUtils.isNotEmpty(sourcePools)) { - LOGGER.debug("Verifying source pools are already available on destination host " + destHost.getUuid()); + logger.debug("Verifying source pools are already available on destination host " + destHost.getUuid()); CheckStorageAvailabilityCommand cmd = new CheckStorageAvailabilityCommand(sourcePools); try { Answer answer = agentManager.send(destHost.getId(), cmd); @@ -2514,7 +2515,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { if (!copyCmdAnswer.getResult()) { errMsg = copyCmdAnswer.getDetails(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -2528,7 +2529,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) { String msg = "Failed to create template from volume (Volume ID = " + volumeInfo.getId() + ") : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } @@ -2538,7 +2539,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { _volumeService.revokeAccess(volumeInfo, hostVO, srcDataStore); } catch (Exception ex) { - LOGGER.warn("Error revoking access to volume (Volume ID = " + volumeInfo.getId() + "): " + ex.getMessage(), ex); + logger.warn("Error revoking access to volume (Volume ID = " + volumeInfo.getId() + "): " + ex.getMessage(), ex); } } @@ -2562,7 +2563,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { } } catch (Exception ex) { - LOGGER.warn("Error processing snapshot event: " + ex.getMessage(), ex); + logger.warn("Error processing snapshot event: " + ex.getMessage(), ex); } } } @@ -2778,7 +2779,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { if (!lock.lock(LOCK_TIME_IN_SECONDS)) { String errMsg = "Couldn't lock the DB (in performResignature) on the following string: " + dataStore.getUuid(); - LOGGER.warn(errMsg); + logger.warn(errMsg); throw new CloudRuntimeException(errMsg); } @@ -2793,7 +2794,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { String msg = "Failed to resign the DataObject with the following ID: " + dataObj.getId(); - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage()); } @@ -2877,9 +2878,9 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { _volumeService.revokeAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore()); handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION); } catch (Throwable e) { - LOGGER.warn("During cleanup post-migration and exception occured: " + e); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Exception during post-migration cleanup.", e); + logger.warn("During cleanup post-migration and exception occured: " + e); + if (logger.isDebugEnabled()) { + logger.debug("Exception during post-migration cleanup.", e); } } } @@ -2920,7 +2921,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { catch (Exception ex) { String msg = "Failed to perform volume copy to secondary storage : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage()); } @@ -2997,7 +2998,7 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy { catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) { String msg = "Failed to perform VDI copy : "; - LOGGER.warn(msg, ex); + logger.warn(msg, ex); throw new CloudRuntimeException(msg + ex.getMessage(), ex); } diff --git a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java index 8f1ada87458..87a2288cfdc 100644 --- a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java +++ b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java @@ -51,7 +51,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; diff --git a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java index ea1a221c8c0..cea9de3f1b4 100644 --- a/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java +++ b/engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java @@ -47,7 +47,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.mockito.verification.VerificationMode; import com.cloud.agent.api.MigrateCommand; diff --git a/engine/storage/image/pom.xml b/engine/storage/image/pom.xml index bf7b7f8eab4..278b3672b2f 100644 --- a/engine/storage/image/pom.xml +++ b/engine/storage/image/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/SecondaryStorageServiceImpl.java b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/SecondaryStorageServiceImpl.java index 3557921a893..730b003fcb0 100644 --- a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/SecondaryStorageServiceImpl.java +++ b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/SecondaryStorageServiceImpl.java @@ -44,7 +44,8 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.secstorage.CommandExecLogDao; @@ -53,7 +54,7 @@ import com.cloud.utils.Pair; public class SecondaryStorageServiceImpl implements SecondaryStorageService { - private static final Logger s_logger = Logger.getLogger(SecondaryStorageServiceImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject DataMotionService motionSrv; @@ -126,11 +127,11 @@ public class SecondaryStorageServiceImpl implements SecondaryStorageService { else { // Check if template in destination store, if yes, do not proceed if (srcDataObject instanceof TemplateInfo) { - s_logger.debug("Checking if template present at destination"); + logger.debug("Checking if template present at destination"); TemplateDataStoreVO templateStoreVO = templateStoreDao.findByStoreTemplate(destDatastore.getId(), srcDataObject.getId()); if (templateStoreVO != null) { String msg = "Template already exists in destination store"; - s_logger.debug(msg); + logger.debug(msg); res.setResult(msg); res.setSuccess(true); future.complete(res); @@ -143,9 +144,9 @@ public class SecondaryStorageServiceImpl implements SecondaryStorageService { migrateJob(future, srcDataObject, destDataObject, destDatastore); } } catch (Exception e) { - s_logger.debug("Failed to copy Data", e); + logger.debug("Failed to copy Data", e); if (destDataObject != null) { - s_logger.info("Deleting data on destination store: " + destDataObject.getDataStore().getName()); + logger.info("Deleting data on destination store: " + destDataObject.getDataStore().getName()); destDataObject.getDataStore().delete(destDataObject); } if (!(srcDataObject instanceof VolumeInfo)) { @@ -178,7 +179,7 @@ public class SecondaryStorageServiceImpl implements SecondaryStorageService { Answer answer = result.getAnswer(); try { if (!answer.getResult()) { - s_logger.warn("Migration failed for "+srcData.getUuid()); + logger.warn("Migration failed for "+srcData.getUuid()); res.setResult(result.getResult()); if (!(srcData instanceof VolumeInfo) ) { srcData.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed); @@ -200,14 +201,14 @@ public class SecondaryStorageServiceImpl implements SecondaryStorageService { destData.processEvent(ObjectInDataStoreStateMachine.Event.OperationSuccessed, answer); } updateDataObject(srcData, destData); - s_logger.debug("Deleting source data"); + logger.debug("Deleting source data"); srcData.getDataStore().delete(srcData); - s_logger.debug("Successfully migrated "+srcData.getUuid()); + logger.debug("Successfully migrated "+srcData.getUuid()); } _cmdExecLogDao.expunge(Long.parseLong(answer.getContextParam("cmd"))); future.complete(res); } catch (Exception e) { - s_logger.error("Failed to process migrate data callback", e); + logger.error("Failed to process migrate data callback", e); res.setResult(e.toString()); _cmdExecLogDao.expunge(Long.parseLong(answer.getContextParam("cmd"))); future.complete(res); @@ -243,7 +244,7 @@ public class SecondaryStorageServiceImpl implements SecondaryStorageService { templateStoreDao.update(destTemplate.getId(), destTemplate); } } else { - s_logger.debug("Unsupported data object type"); + logger.debug("Unsupported data object type"); } } } diff --git a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java index 8951b9d7c24..ba783e81586 100644 --- a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java +++ b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateDataFactoryImpl.java @@ -37,7 +37,8 @@ import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.storage.image.store.TemplateObject; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.host.HostVO; @@ -53,7 +54,7 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class TemplateDataFactoryImpl implements TemplateDataFactory { - private static final Logger s_logger = Logger.getLogger(TemplateDataFactoryImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject VMTemplateDao imageDataDao; @Inject @@ -73,7 +74,7 @@ public class TemplateDataFactoryImpl implements TemplateDataFactory { public TemplateInfo getTemplateOnPrimaryStorage(long templateId, DataStore store, String configuration) { VMTemplateVO templ = imageDataDao.findByIdIncludingRemoved(templateId); if (templ == null) { - s_logger.error("Could not find a template with id " + templateId); + logger.error("Could not find a template with id " + templateId); return null; } if (store.getRole() == DataStoreRole.Primary) { @@ -117,11 +118,11 @@ public class TemplateDataFactoryImpl implements TemplateDataFactory { } } - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (!found) { - s_logger.debug("template " + templateId + " is not in store:" + store.getId() + ", type:" + store.getRole()); + logger.debug("template " + templateId + " is not in store:" + store.getId() + ", type:" + store.getRole()); } else { - s_logger.debug("template " + templateId + " is already in store:" + store.getId() + ", type:" + store.getRole()); + logger.debug("template " + templateId + " is already in store:" + store.getId() + ", type:" + store.getRole()); } } diff --git a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateServiceImpl.java b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateServiceImpl.java index e6235a63c77..39d4618f81c 100644 --- a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateServiceImpl.java +++ b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/TemplateServiceImpl.java @@ -67,7 +67,8 @@ import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; import org.apache.cloudstack.storage.image.store.TemplateObject; import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.api.Answer; @@ -91,6 +92,7 @@ import com.cloud.storage.ScopeType; import com.cloud.storage.Storage; import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.TemplateType; +import com.cloud.storage.StorageManager; import com.cloud.storage.StoragePool; import com.cloud.storage.VMTemplateStorageResourceAssoc; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; @@ -114,7 +116,7 @@ import com.cloud.vm.VmDetailConstants; @Component public class TemplateServiceImpl implements TemplateService { - private static final Logger s_logger = Logger.getLogger(TemplateServiceImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject ObjectInDataStoreManager _objectInDataStoreMgr; @Inject @@ -278,7 +280,7 @@ public class TemplateServiceImpl implements TemplateService { TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId()); if (tmpltHost == null) { associateTemplateToZone(template.getId(), dcId); - s_logger.info("Downloading builtin template " + template.getUniqueName() + " to data center: " + dcId); + logger.info("Downloading builtin template " + template.getUniqueName() + " to data center: " + dcId); TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image); createTemplateAsync(tmplt, store, null); } @@ -297,7 +299,7 @@ public class TemplateServiceImpl implements TemplateService { return false; } if (zoneId != null && _vmTemplateStoreDao.findByTemplateZone(template.getId(), zoneId, DataStoreRole.Image) == null) { - s_logger.debug(String.format("Template %s is not present on any image store for the zone ID: %d, its download cannot be skipped", template.getUniqueName(), zoneId)); + logger.debug(String.format("Template %s is not present on any image store for the zone ID: %d, its download cannot be skipped", template.getUniqueName(), zoneId)); return false; } return true; @@ -306,7 +308,7 @@ public class TemplateServiceImpl implements TemplateService { @Override public void handleTemplateSync(DataStore store) { if (store == null) { - s_logger.warn("Huh? image store is null"); + logger.warn("Huh? image store is null"); return; } long storeId = store.getId(); @@ -366,6 +368,7 @@ public class TemplateServiceImpl implements TemplateService { toBeDownloaded.addAll(allTemplates); final StateMachine2 stateMachine = VirtualMachineTemplate.State.getStateMachine(); + Boolean followRedirect = StorageManager.DataStoreDownloadFollowRedirects.value(); for (VMTemplateVO tmplt : allTemplates) { String uniqueName = tmplt.getUniqueName(); TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId()); @@ -373,7 +376,7 @@ public class TemplateServiceImpl implements TemplateService { TemplateProp tmpltInfo = templateInfos.remove(uniqueName); toBeDownloaded.remove(tmplt); if (tmpltStore != null) { - s_logger.info("Template Sync found " + uniqueName + " already in the image store"); + logger.info("Template Sync found " + uniqueName + " already in the image store"); if (tmpltStore.getDownloadState() != Status.DOWNLOADED) { tmpltStore.setErrorString(""); } @@ -381,21 +384,21 @@ public class TemplateServiceImpl implements TemplateService { tmpltStore.setDownloadState(Status.DOWNLOAD_ERROR); String msg = "Template " + tmplt.getName() + ":" + tmplt.getId() + " is corrupted on secondary storage " + tmpltStore.getId(); tmpltStore.setErrorString(msg); - s_logger.info(msg); + logger.info(msg); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, zoneId, null, msg, msg); if (tmplt.getState() == VirtualMachineTemplate.State.NotUploaded || tmplt.getState() == VirtualMachineTemplate.State.UploadInProgress) { - s_logger.info("Template Sync found " + uniqueName + " on image store " + storeId + " uploaded using SSVM as corrupted, marking it as failed"); + logger.info("Template Sync found " + uniqueName + " on image store " + storeId + " uploaded using SSVM as corrupted, marking it as failed"); tmpltStore.setState(State.Failed); try { stateMachine.transitTo(tmplt, VirtualMachineTemplate.Event.OperationFailed, null, _templateDao); } catch (NoTransitionException e) { - s_logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage()); + logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage()); } } else if (tmplt.getUrl() == null) { msg = "Private template (" + tmplt + ") with install path " + tmpltInfo.getInstallPath() + " is corrupted, please check in image store: " + tmpltStore.getDataStoreId(); - s_logger.warn(msg); + logger.warn(msg); } else { - s_logger.info("Removing template_store_ref entry for corrupted template " + tmplt.getName()); + logger.info("Removing template_store_ref entry for corrupted template " + tmplt.getName()); _vmTemplateStoreDao.remove(tmpltStore.getId()); toBeDownloaded.add(tmplt); } @@ -435,7 +438,7 @@ public class TemplateServiceImpl implements TemplateService { try { stateMachine.transitTo(tmplt, event, null, _templateDao); } catch (NoTransitionException e) { - s_logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage()); + logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage()); } } @@ -446,9 +449,10 @@ public class TemplateServiceImpl implements TemplateService { try { _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(accountId), com.cloud.configuration.Resource.ResourceType.secondary_storage, - tmpltInfo.getSize() - UriUtils.getRemoteSize(tmplt.getUrl())); + tmpltInfo.getSize() - UriUtils.getRemoteSize(tmplt.getUrl(), + followRedirect)); } catch (ResourceAllocationException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED, zoneId, null, e.getMessage(), e.getMessage()); } finally { _resourceLimitMgr.recalculateResourceCount(accountId, _accountMgr.getAccount(accountId).getDomainId(), @@ -479,7 +483,7 @@ public class TemplateServiceImpl implements TemplateService { tmpltInfo.getPhysicalSize(), tmpltInfo.getSize(), VirtualMachineTemplate.class.getName(), tmplt.getUuid()); } } else if (tmplt.getState() == VirtualMachineTemplate.State.NotUploaded || tmplt.getState() == VirtualMachineTemplate.State.UploadInProgress) { - s_logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId + " uploaded using SSVM, marking it as failed"); + logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId + " uploaded using SSVM, marking it as failed"); toBeDownloaded.remove(tmplt); tmpltStore.setDownloadState(Status.DOWNLOAD_ERROR); String msg = "Template " + tmplt.getName() + ":" + tmplt.getId() + " is corrupted on secondary storage " + tmpltStore.getId(); @@ -489,20 +493,20 @@ public class TemplateServiceImpl implements TemplateService { try { stateMachine.transitTo(tmplt, VirtualMachineTemplate.Event.OperationFailed, null, _templateDao); } catch (NoTransitionException e) { - s_logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage()); + logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage()); } } else if (tmplt.isDirectDownload()) { - s_logger.info("Template " + tmplt.getName() + ":" + tmplt.getId() + " is marked for direct download, discarding it for download on image stores"); + logger.info("Template " + tmplt.getName() + ":" + tmplt.getId() + " is marked for direct download, discarding it for download on image stores"); toBeDownloaded.remove(tmplt); } else { - s_logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId + ", may request download based on available hypervisor types"); + logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId + ", may request download based on available hypervisor types"); if (tmpltStore != null) { if (_storeMgr.isRegionStore(store) && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && tmpltStore.getState() == State.Ready && tmpltStore.getInstallPath() == null) { - s_logger.info("Keep fake entry in template store table for migration of previous NFS to object store"); + logger.info("Keep fake entry in template store table for migration of previous NFS to object store"); } else { - s_logger.info("Removing leftover template " + uniqueName + " entry from template store table"); + logger.info("Removing leftover template " + uniqueName + " entry from template store table"); // remove those leftover entries _vmTemplateStoreDao.remove(tmpltStore.getId()); } @@ -526,12 +530,12 @@ public class TemplateServiceImpl implements TemplateService { // download. for (VMTemplateVO tmplt : toBeDownloaded) { if (tmplt.getUrl() == null) { // If url is null, skip downloading - s_logger.info("Skip downloading template " + tmplt.getUniqueName() + " since no url is specified."); + logger.info("Skip downloading template " + tmplt.getUniqueName() + " since no url is specified."); continue; } // if this is private template, skip sync to a new image store if (isSkipTemplateStoreDownload(tmplt, zoneId)) { - s_logger.info("Skip sync downloading private template " + tmplt.getUniqueName() + " to a new image store"); + logger.info("Skip sync downloading private template " + tmplt.getUniqueName() + " to a new image store"); continue; } @@ -541,13 +545,13 @@ public class TemplateServiceImpl implements TemplateService { TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId()); if (tmpltStore != null && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && tmpltStore.getState() == State.Ready && tmpltStore.getInstallPath() == null) { - s_logger.info("Skip sync template for migration of previous NFS to object store"); + logger.info("Skip sync template for migration of previous NFS to object store"); continue; } } if (availHypers.contains(tmplt.getHypervisorType())) { - s_logger.info("Downloading template " + tmplt.getUniqueName() + " to image store " + store.getName()); + logger.info("Downloading template " + tmplt.getUniqueName() + " to image store " + store.getName()); associateTemplateToZone(tmplt.getId(), zoneId); TemplateInfo tmpl = _templateFactory.getTemplate(tmplt.getId(), store); TemplateOpContext context = new TemplateOpContext<>(null,(TemplateObject)tmpl, null); @@ -556,7 +560,7 @@ public class TemplateServiceImpl implements TemplateService { caller.setContext(context); createTemplateAsync(tmpl, store, caller); } else { - s_logger.info("Skip downloading template " + tmplt.getUniqueName() + " since current data center does not have hypervisor " + + logger.info("Skip downloading template " + tmplt.getUniqueName() + " since current data center does not have hypervisor " + tmplt.getHypervisorType().toString()); } } @@ -575,17 +579,17 @@ public class TemplateServiceImpl implements TemplateService { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(dtCommand, false, errMsg); } else { answer = ep.sendMessage(dtCommand); } if (answer == null || !answer.getResult()) { - s_logger.info("Failed to deleted template at store: " + store.getName()); + logger.info("Failed to deleted template at store: " + store.getName()); } else { String description = "Deleted template " + tInfo.getTemplateName() + " on secondary storage " + storeId; - s_logger.info(description); + logger.info(description); } } @@ -594,7 +598,7 @@ public class TemplateServiceImpl implements TemplateService { syncLock.unlock(); } } else { - s_logger.info("Couldn't get global lock on " + lockString + ", another thread may be doing template sync on data store " + storeId + " now."); + logger.info("Couldn't get global lock on " + lockString + ", another thread may be doing template sync on data store " + storeId + " now."); } } finally { syncLock.releaseRef(); @@ -669,7 +673,7 @@ public class TemplateServiceImpl implements TemplateService { if (tmpltStore != null) { physicalSize = tmpltStore.getPhysicalSize(); } else { - s_logger.warn("No entry found in template_store_ref for template id: " + template.getId() + " and image store id: " + ds.getId() + + logger.warn("No entry found in template_store_ref for template id: " + template.getId() + " and image store id: " + ds.getId() + " at the end of registering template!"); } Scope dsScope = ds.getScope(); @@ -677,7 +681,7 @@ public class TemplateServiceImpl implements TemplateService { UsageEventUtils.publishUsageEvent(etype, template.getAccountId(), dsScope.getScopeId(), template.getId(), template.getName(), null, null, physicalSize, template.getSize(), VirtualMachineTemplate.class.getName(), template.getUuid()); } else { - s_logger.warn("Zone scope image store " + ds.getId() + " has a null scope id"); + logger.warn("Zone scope image store " + ds.getId() + " has a null scope id"); } _resourceLimitMgr.incrementResourceCount(accountId, Resource.ResourceType.secondary_storage, template.getSize()); } @@ -693,7 +697,7 @@ public class TemplateServiceImpl implements TemplateService { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -702,8 +706,8 @@ public class TemplateServiceImpl implements TemplateService { ListTemplateAnswer tanswer = (ListTemplateAnswer)answer; return tanswer.getTemplateInfo(); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("can not list template for secondary storage host " + ssStore.getId()); + if (logger.isDebugEnabled()) { + logger.debug("can not list template for secondary storage host " + ssStore.getId()); } } @@ -840,7 +844,7 @@ public class TemplateServiceImpl implements TemplateService { _resourceLimitMgr.incrementResourceCount(template.getAccountId(), ResourceType.secondary_storage, templateVO.getSize()); } else { // Delete the Datadisk templates that were already created as they are now invalid - s_logger.debug("Since creation of Datadisk template: " + templateVO.getId() + " failed, delete other Datadisk templates that were created as part of parent" + logger.debug("Since creation of Datadisk template: " + templateVO.getId() + " failed, delete other Datadisk templates that were created as part of parent" + " template download"); TemplateInfo parentTemplateInfo = imageFactory.getTemplate(templateVO.getParentTemplateId(), imageStore); cleanupDatadiskTemplates(parentTemplateInfo); @@ -855,7 +859,7 @@ public class TemplateServiceImpl implements TemplateService { TemplateApiResult result = null; result = templateFuture.get(); if (!result.isSuccess()) { - s_logger.debug("Since creation of parent template: " + templateInfo.getId() + " failed, delete Datadisk templates that were created as part of parent" + logger.debug("Since creation of parent template: " + templateInfo.getId() + " failed, delete Datadisk templates that were created as part of parent" + " template download"); cleanupDatadiskTemplates(templateInfo); } @@ -905,18 +909,18 @@ public class TemplateServiceImpl implements TemplateService { DataStore imageStore = parentTemplateInfo.getDataStore(); List datadiskTemplatesToDelete = _templateDao.listByParentTemplatetId(parentTemplateInfo.getId()); for (VMTemplateVO datadiskTemplateToDelete: datadiskTemplatesToDelete) { - s_logger.info("Delete template: " + datadiskTemplateToDelete.getId() + " from image store: " + imageStore.getName()); + logger.info("Delete template: " + datadiskTemplateToDelete.getId() + " from image store: " + imageStore.getName()); AsyncCallFuture future = deleteTemplateAsync(imageFactory.getTemplate(datadiskTemplateToDelete.getId(), imageStore)); try { TemplateApiResult result = future.get(); if (!result.isSuccess()) { - s_logger.warn("Failed to delete datadisk template: " + datadiskTemplateToDelete + " from image store: " + imageStore.getName() + " due to: " + result.getResult()); + logger.warn("Failed to delete datadisk template: " + datadiskTemplateToDelete + " from image store: " + imageStore.getName() + " due to: " + result.getResult()); break; } _vmTemplateZoneDao.deletePrimaryRecordsForTemplate(datadiskTemplateToDelete.getId()); _resourceLimitMgr.decrementResourceCount(datadiskTemplateToDelete.getAccountId(), ResourceType.secondary_storage, datadiskTemplateToDelete.getSize()); } catch (Exception e) { - s_logger.debug("Delete datadisk template failed", e); + logger.debug("Delete datadisk template failed", e); throw new CloudRuntimeException("Delete template Failed", e); } } @@ -1012,7 +1016,7 @@ public class TemplateServiceImpl implements TemplateService { } future.complete(res); } catch (Exception e) { - s_logger.debug("Failed to process sync template callback", e); + logger.debug("Failed to process sync template callback", e); res.setResult(e.toString()); future.complete(res); } @@ -1025,8 +1029,8 @@ public class TemplateServiceImpl implements TemplateService { @Override public void syncTemplateToRegionStore(long templateId, DataStore store) { if (_storeMgr.isRegionStore(store)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sync template " + templateId + " from cache to object store..."); + if (logger.isDebugEnabled()) { + logger.debug("Sync template " + templateId + " from cache to object store..."); } // if template is on region wide object store, check if it is really downloaded there (by checking install_path). Sync template to region // wide store if it is not there physically. @@ -1067,19 +1071,19 @@ public class TemplateServiceImpl implements TemplateService { // generate a URL from source template ssvm to download to destination data store String url = generateCopyUrl(srcTemplate); if (url == null) { - s_logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + + logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + ", no secondary storage vm in running state in source zone"); throw new CloudRuntimeException("No secondary VM in running state in source template zone "); } TemplateObject tmplForCopy = (TemplateObject)_templateFactory.getTemplate(srcTemplate, destStore, null); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Setting source template url to " + url); + if (logger.isDebugEnabled()) { + logger.debug("Setting source template url to " + url); } tmplForCopy.setUrl(url); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Mark template_store_ref entry as Creating"); + if (logger.isDebugEnabled()) { + logger.debug("Mark template_store_ref entry as Creating"); } AsyncCallFuture future = new AsyncCallFuture(); DataObject templateOnStore = destStore.create(tmplForCopy); @@ -1089,8 +1093,8 @@ public class TemplateServiceImpl implements TemplateService { ((TemplateObject)templateOnStore).getImage().setChecksum(null); } // else we don't know what to do. - if (s_logger.isDebugEnabled()) { - s_logger.debug("Invoke datastore driver createAsync to create template on destination store"); + if (logger.isDebugEnabled()) { + logger.debug("Invoke datastore driver createAsync to create template on destination store"); } try { TemplateOpContext context = new TemplateOpContext(null, (TemplateObject)templateOnStore, future); @@ -1121,7 +1125,7 @@ public class TemplateServiceImpl implements TemplateService { _sslCopy = Boolean.parseBoolean(sslCfg); } if(_sslCopy && (_ssvmUrlDomain == null || _ssvmUrlDomain.isEmpty())){ - s_logger.warn("Empty secondary storage url domain, ignoring SSL"); + logger.warn("Empty secondary storage url domain, ignoring SSL"); _sslCopy = false; } if (_sslCopy) { @@ -1141,7 +1145,7 @@ public class TemplateServiceImpl implements TemplateService { EndPoint ep = _epSelector.select(srcTemplate); if (ep != null) { if (ep.getPublicAddr() == null) { - s_logger.warn("A running secondary storage vm has a null public ip?"); + logger.warn("A running secondary storage vm has a null public ip?"); return null; } return generateCopyUrl(ep.getPublicAddr(), ((ImageStoreEntity)srcStore).getMountPoint(), srcTemplate.getInstallPath()); @@ -1194,7 +1198,7 @@ public class TemplateServiceImpl implements TemplateService { } future.complete(res); } catch (Exception e) { - s_logger.debug("Failed to process copy template callback", e); + logger.debug("Failed to process copy template callback", e); res.setResult(e.toString()); future.complete(res); } @@ -1203,8 +1207,8 @@ public class TemplateServiceImpl implements TemplateService { } protected Void copyTemplateCrossZoneCallBack(AsyncCallbackDispatcher callback, TemplateOpContext context) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Performing copy template cross zone callback after completion"); + if (logger.isDebugEnabled()) { + logger.debug("Performing copy template cross zone callback after completion"); } TemplateInfo destTemplate = context.getTemplate(); CreateCmdResult result = callback.getResult(); @@ -1219,7 +1223,7 @@ public class TemplateServiceImpl implements TemplateService { } future.complete(res); } catch (Exception e) { - s_logger.debug("Failed to process copy template cross zones callback", e); + logger.debug("Failed to process copy template cross zones callback", e); res.setResult(e.toString()); future.complete(res); } @@ -1307,7 +1311,7 @@ public class TemplateServiceImpl implements TemplateService { dataDiskTemplateResult.setResult(result.getResult()); } } catch (CloudRuntimeException e) { - s_logger.debug("Failed to process create template callback", e); + logger.debug("Failed to process create template callback", e); dataDiskTemplateResult.setResult(e.toString()); } future.complete(dataDiskTemplateResult); diff --git a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java index 5bb0d19be74..11a13e7ccb4 100644 --- a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java +++ b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/manager/ImageStoreProviderManagerImpl.java @@ -42,7 +42,8 @@ import org.apache.cloudstack.storage.image.ImageStoreDriver; import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; import org.apache.cloudstack.storage.image.store.ImageStoreImpl; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.server.StatsCollector; @@ -51,7 +52,7 @@ import com.cloud.storage.dao.VMTemplateDao; @Component public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager, Configurable { - private static final Logger s_logger = Logger.getLogger(ImageStoreProviderManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject ImageStoreDao dataStoreDao; @Inject @@ -158,7 +159,7 @@ public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager, @Override public List listImageCacheStores(Scope scope) { if (scope.getScopeType() != ScopeType.ZONE) { - s_logger.debug("only support zone wide image cache stores"); + logger.debug("only support zone wide image cache stores"); return null; } List stores = dataStoreDao.findImageCacheByScope(new ZoneScope(scope.getScopeId())); @@ -200,7 +201,7 @@ public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager, } // No store with space found - s_logger.error(String.format("Can't find an image storage in zone with less than %d usage", + logger.error(String.format("Can't find an image storage in zone with less than %d usage", Math.round(_statsCollector.getImageStoreCapacityThreshold()*100))); return null; } @@ -242,7 +243,7 @@ public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager, // No store with space found if (stores.isEmpty()) { - s_logger.error(String.format("Can't find image storage in zone with less than %d usage", + logger.error(String.format("Can't find image storage in zone with less than %d usage", Math.round(_statsCollector.getImageStoreCapacityThreshold() * 100))); } return stores; diff --git a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java index d4e2c056763..d59f6d4c54d 100644 --- a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java +++ b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/ImageStoreImpl.java @@ -26,7 +26,8 @@ import java.util.concurrent.ExecutionException; import javax.inject.Inject; import com.cloud.storage.Upload; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; @@ -54,7 +55,7 @@ import com.cloud.storage.dao.VMTemplateDao; import com.cloud.utils.component.ComponentContext; public class ImageStoreImpl implements ImageStoreEntity { - private static final Logger s_logger = Logger.getLogger(ImageStoreImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject VMTemplateDao imageDao; @Inject @@ -153,10 +154,10 @@ public class ImageStoreImpl implements ImageStoreEntity { try { future.get(); } catch (InterruptedException e) { - s_logger.debug("failed delete obj", e); + logger.debug("failed delete obj", e); return false; } catch (ExecutionException e) { - s_logger.debug("failed delete obj", e); + logger.debug("failed delete obj", e); return false; } objectInStoreMgr.delete(obj); diff --git a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java index b688197bfb9..fdb4fe6753a 100644 --- a/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java +++ b/engine/storage/image/src/main/java/org/apache/cloudstack/storage/image/store/TemplateObject.java @@ -23,8 +23,10 @@ import java.util.Map; import javax.inject.Inject; +import com.cloud.storage.StorageManager; import com.cloud.user.UserData; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -59,7 +61,7 @@ import org.apache.commons.lang3.StringUtils; @SuppressWarnings("serial") public class TemplateObject implements TemplateInfo { - private static final Logger s_logger = Logger.getLogger(TemplateObject.class); + protected Logger logger = LogManager.getLogger(getClass()); private VMTemplateVO imageVO; private DataStore dataStore; private String url; @@ -73,8 +75,10 @@ public class TemplateObject implements TemplateInfo { VMTemplatePoolDao templatePoolDao; @Inject TemplateDataStoreDao templateStoreDao; + final private boolean followRedirects; public TemplateObject() { + this.followRedirects = StorageManager.DataStoreDownloadFollowRedirects.value(); } protected void configure(VMTemplateVO template, DataStore dataStore) { @@ -243,10 +247,10 @@ public class TemplateObject implements TemplateInfo { } objectInStoreMgr.update(this, event); } catch (NoTransitionException e) { - s_logger.debug("failed to update state", e); + logger.debug("failed to update state", e); throw new CloudRuntimeException("Failed to update state" + e.toString()); } catch (Exception ex) { - s_logger.debug("failed to process event and answer", ex); + logger.debug("failed to process event and answer", ex); objectInStoreMgr.delete(this); throw new CloudRuntimeException("Failed to process event", ex); } finally { @@ -398,7 +402,7 @@ public class TemplateObject implements TemplateInfo { // Marking downloaded templates for deletion, but might skip any deletion handled for failed templates. // Only templates not downloaded and in error state (with no install path) cannot be deleted from the datastore, so doesn't impact last behavior for templates with other states if (downloadStatus == null || downloadStatus == Status.NOT_DOWNLOADED || (downloadStatus == Status.DOWNLOAD_ERROR && downloadPercent == 0)) { - s_logger.debug("Template: " + getId() + " cannot be deleted from the store: " + getDataStore().getId()); + logger.debug("Template: " + getId() + " cannot be deleted from the store: " + getDataStore().getId()); return false; } @@ -573,4 +577,9 @@ public class TemplateObject implements TemplateInfo { // TODO Auto-generated method stub return null; } + + @Override + public boolean isFollowRedirects() { + return followRedirects; + } } diff --git a/engine/storage/integration-test/pom.xml b/engine/storage/integration-test/pom.xml index 735c1a0615e..a5bc225f4f6 100644 --- a/engine/storage/integration-test/pom.xml +++ b/engine/storage/integration-test/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java index c6003afee57..1d072985a66 100644 --- a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java +++ b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/DirectAgentManagerSimpleImpl.java @@ -26,7 +26,6 @@ import java.util.Map; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -60,7 +59,6 @@ import com.cloud.utils.fsm.NoTransitionException; import com.cloud.utils.fsm.StateMachine2; public class DirectAgentManagerSimpleImpl extends ManagerBase implements AgentManager { - private static final Logger logger = Logger.getLogger(DirectAgentManagerSimpleImpl.class); private final Map hostResourcesMap = new HashMap(); @Inject HostDao hostDao; diff --git a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/MockRpcCallBack.java b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/MockRpcCallBack.java index 25f96c26750..8b3de65b4cc 100644 --- a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/MockRpcCallBack.java +++ b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/MockRpcCallBack.java @@ -18,7 +18,8 @@ package org.apache.cloudstack.storage.test; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; @@ -28,7 +29,7 @@ import com.cloud.agent.api.Command; import com.cloud.utils.db.DB; public class MockRpcCallBack implements Runnable { - private static final Logger s_logger = Logger.getLogger(MockRpcCallBack.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject AgentManager agentMgr; private Command cmd; @@ -54,7 +55,7 @@ public class MockRpcCallBack implements Runnable { Answer answer = agentMgr.send(hostId, cmd); callback.complete(answer); } catch (Throwable e) { - s_logger.debug("send command failed:", e); + logger.debug("send command failed:", e); } } diff --git a/engine/storage/object/pom.xml b/engine/storage/object/pom.xml index 5bad4e8a3d6..7159a646fbb 100644 --- a/engine/storage/object/pom.xml +++ b/engine/storage/object/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/ObjectStorageServiceImpl.java b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/ObjectStorageServiceImpl.java index a0db89bad4e..40edc66d4d0 100644 --- a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/ObjectStorageServiceImpl.java +++ b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/ObjectStorageServiceImpl.java @@ -18,11 +18,8 @@ package org.apache.cloudstack.storage.object; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectStorageService; -import org.apache.log4j.Logger; public class ObjectStorageServiceImpl implements ObjectStorageService { - private static final Logger s_logger = Logger.getLogger(ObjectStorageServiceImpl.class); - } diff --git a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/manager/ObjectStoreProviderManagerImpl.java b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/manager/ObjectStoreProviderManagerImpl.java index 40f503692e1..222b21e0ce8 100644 --- a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/manager/ObjectStoreProviderManagerImpl.java +++ b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/manager/ObjectStoreProviderManagerImpl.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.storage.object.ObjectStoreDriver; import org.apache.cloudstack.storage.object.ObjectStoreEntity; import org.apache.cloudstack.storage.object.datastore.ObjectStoreProviderManager; import org.apache.cloudstack.storage.object.store.ObjectStoreImpl; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @@ -41,7 +40,6 @@ import java.util.Map; @Component public class ObjectStoreProviderManagerImpl implements ObjectStoreProviderManager, Configurable { - private static final Logger s_logger = Logger.getLogger(ObjectStoreProviderManagerImpl.class); @Inject ObjectStoreDao objectStoreDao; diff --git a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java index 825b349bdfc..3c525ba9364 100644 --- a/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java +++ b/engine/storage/object/src/main/java/org/apache/cloudstack/storage/object/store/ObjectStoreImpl.java @@ -29,14 +29,12 @@ import org.apache.cloudstack.engine.subsystem.api.storage.Scope; import org.apache.cloudstack.storage.datastore.db.ObjectStoreVO; import org.apache.cloudstack.storage.object.ObjectStoreDriver; import org.apache.cloudstack.storage.object.ObjectStoreEntity; -import org.apache.log4j.Logger; import java.util.Date; import java.util.List; import java.util.Map; public class ObjectStoreImpl implements ObjectStoreEntity { - private static final Logger s_logger = Logger.getLogger(ObjectStoreImpl.class); protected ObjectStoreDriver driver; protected ObjectStoreVO objectStoreVO; diff --git a/engine/storage/object/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/storage/object/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/storage/object/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/storage/pom.xml b/engine/storage/pom.xml index 86bb8473487..e16e88e235d 100644 --- a/engine/storage/pom.xml +++ b/engine/storage/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/engine/storage/snapshot/pom.xml b/engine/storage/snapshot/pom.xml index 9ba5e3a5dfe..ac0daeabf76 100644 --- a/engine/storage/snapshot/pom.xml +++ b/engine/storage/snapshot/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategy.java index 19b3fc87f4e..04cca2e8f92 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategy.java @@ -27,7 +27,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import com.cloud.storage.DataStoreRole; import com.cloud.storage.Snapshot; @@ -44,7 +43,6 @@ public class CephSnapshotStrategy extends StorageSystemSnapshotStrategy { @Inject private VolumeDao volumeDao; - private static final Logger s_logger = Logger.getLogger(CephSnapshotStrategy.class); @Override public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperation op) { @@ -71,7 +69,7 @@ public class CephSnapshotStrategy extends StorageSystemSnapshotStrategy { VolumeInfo volumeInfo = snapshotInfo.getBaseVolume(); ImageFormat imageFormat = volumeInfo.getFormat(); if (!ImageFormat.RAW.equals(imageFormat)) { - s_logger.error(String.format("Does not support revert snapshot of the image format [%s] on Ceph/RBD. Can only rollback snapshots of format RAW", imageFormat)); + logger.error(String.format("Does not support revert snapshot of the image format [%s] on Ceph/RBD. Can only rollback snapshots of format RAW", imageFormat)); return false; } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java index f1f073db170..7e902bc61fe 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/DefaultSnapshotStrategy.java @@ -44,7 +44,6 @@ import org.apache.cloudstack.utils.identity.ManagementServerNode; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.to.DataTO; import com.cloud.event.EventTypes; @@ -79,7 +78,6 @@ import com.cloud.utils.fsm.NoTransitionException; public class DefaultSnapshotStrategy extends SnapshotStrategyBase { - private static final Logger s_logger = Logger.getLogger(DefaultSnapshotStrategy.class); @Inject SnapshotService snapshotSvr; @@ -136,12 +134,12 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { try { snapObj.processEvent(Snapshot.Event.OperationNotPerformed); } catch (NoTransitionException e) { - s_logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString()); + logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString()); throw new CloudRuntimeException(e.toString()); } return snapshotDataFactory.getSnapshot(snapObj.getId(), store); } else { - s_logger.debug("parent snapshot hasn't been backed up yet"); + logger.debug("parent snapshot hasn't been backed up yet"); } } @@ -195,7 +193,7 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { protected boolean deleteSnapshotChain(SnapshotInfo snapshot, String storageToString) { DataTO snapshotTo = snapshot.getTO(); - s_logger.debug(String.format("Deleting %s chain of snapshots.", snapshotTo)); + logger.debug(String.format("Deleting %s chain of snapshots.", snapshotTo)); boolean result = false; boolean resultIsSet = false; @@ -205,11 +203,11 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { SnapshotInfo child = snapshot.getChild(); if (child != null) { - s_logger.debug(String.format("Snapshot [%s] has child [%s], not deleting it on the storage [%s]", snapshotTo, child.getTO(), storageToString)); + logger.debug(String.format("Snapshot [%s] has child [%s], not deleting it on the storage [%s]", snapshotTo, child.getTO(), storageToString)); break; } - s_logger.debug(String.format("Snapshot [%s] does not have children; therefore, we will delete it and its parents.", snapshotTo)); + logger.debug(String.format("Snapshot [%s] does not have children; therefore, we will delete it and its parents.", snapshotTo)); SnapshotInfo parent = snapshot.getParent(); boolean deleted = false; @@ -217,7 +215,7 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { if (parent.getPath() != null && parent.getPath().equalsIgnoreCase(snapshot.getPath())) { //NOTE: if both snapshots share the same path, it's for xenserver's empty delta snapshot. We can't delete the snapshot on the backend, as parent snapshot still reference to it //Instead, mark it as destroyed in the db. - s_logger.debug(String.format("Snapshot [%s] is an empty delta snapshot; therefore, we will only mark it as destroyed in the database.", snapshotTo)); + logger.debug(String.format("Snapshot [%s] is an empty delta snapshot; therefore, we will only mark it as destroyed in the database.", snapshotTo)); deleted = true; if (!resultIsSet) { result = true; @@ -232,7 +230,7 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { if (r) { List cacheSnaps = snapshotDataFactory.listSnapshotOnCache(snapshot.getId()); for (SnapshotInfo cacheSnap : cacheSnaps) { - s_logger.debug(String.format("Deleting snapshot %s from image cache [%s].", snapshotTo, cacheSnap.getDataStore().getName())); + logger.debug(String.format("Deleting snapshot %s from image cache [%s].", snapshotTo, cacheSnap.getDataStore().getName())); cacheSnap.delete(); } } @@ -242,14 +240,14 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { resultIsSet = true; } } catch (Exception e) { - s_logger.error(String.format("Failed to delete snapshot [%s] on storage [%s] due to [%s].", snapshotTo, storageToString, e.getMessage()), e); + logger.error(String.format("Failed to delete snapshot [%s] on storage [%s] due to [%s].", snapshotTo, storageToString, e.getMessage()), e); } } snapshot = parent; } } catch (Exception e) { - s_logger.error(String.format("Failed to delete snapshot [%s] on storage [%s] due to [%s].", snapshotTo, storageToString, e.getMessage()), e); + logger.error(String.format("Failed to delete snapshot [%s] on storage [%s] due to [%s].", snapshotTo, storageToString, e.getMessage()), e); } return result; } @@ -362,9 +360,9 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { if (!DataStoreRole.Primary.equals(dataStore.getRole())) { verifyIfTheSnapshotIsBeingUsedByAnyVolume(snapshotObject); if (deleteSnapshotChain(snapshotInfo, storageToString)) { - s_logger.debug(String.format("%s was deleted on %s. We will mark the snapshot as destroyed.", snapshotVo, storageToString)); + logger.debug(String.format("%s was deleted on %s. We will mark the snapshot as destroyed.", snapshotVo, storageToString)); } else { - s_logger.debug(String.format("%s was not deleted on %s; however, we will mark the snapshot as destroyed for future garbage collecting.", snapshotVo, + logger.debug(String.format("%s was not deleted on %s; however, we will mark the snapshot as destroyed for future garbage collecting.", snapshotVo, storageToString)); } snapshotStoreDao.updateDisplayForSnapshotStoreRole(snapshotVo.getId(), dataStore.getId(), dataStore.getRole(), false); @@ -376,12 +374,12 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { snapshotStoreDao.updateDisplayForSnapshotStoreRole(snapshotVo.getId(), dataStore.getId(), dataStore.getRole(), false); return true; } - s_logger.debug(String.format("Failed to delete %s on %s.", snapshotVo, storageToString)); + logger.debug(String.format("Failed to delete %s on %s.", snapshotVo, storageToString)); if (isLastSnapshotRef) { snapshotObject.processEvent(Snapshot.Event.OperationFailed); } } catch (NoTransitionException ex) { - s_logger.warn(String.format("Failed to delete %s on %s due to %s.", snapshotVo, storageToString, ex.getMessage()), ex); + logger.warn(String.format("Failed to delete %s on %s due to %s.", snapshotVo, storageToString, ex.getMessage()), ex); } return false; } @@ -395,11 +393,11 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { msg = String.format("%s We will mark the snapshot as destroyed.", msg); snapshotObject.processEvent(Snapshot.Event.OperationSucceeded); } - s_logger.debug(msg); + logger.debug(msg); return true; } } catch (CloudRuntimeException ex) { - s_logger.warn(String.format("Unable do delete snapshot %s on %s due to [%s]. The reference will be marked as 'Destroying' for future garbage collecting.", + logger.warn(String.format("Unable do delete snapshot %s on %s due to [%s]. The reference will be marked as 'Destroying' for future garbage collecting.", snapshotVo, storageToString, ex.getMessage()), ex); } return false; @@ -464,7 +462,7 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { result = snapshotSvr.revertSnapshot(snapshot); if (!result) { - s_logger.debug("Failed to revert snapshot: " + snapshot.getId()); + logger.debug("Failed to revert snapshot: " + snapshot.getId()); throw new CloudRuntimeException("Failed to revert snapshot: " + snapshot.getId()); } @@ -509,7 +507,7 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { try { result = snapshotSvr.takeSnapshot(snapshot); if (result.isFailed()) { - s_logger.debug("Failed to take snapshot: " + result.getResult()); + logger.debug("Failed to take snapshot: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } } finally { @@ -564,7 +562,7 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { } } } catch (Exception e) { - s_logger.debug("Failed to clean up snapshots on primary storage", e); + logger.debug("Failed to clean up snapshots on primary storage", e); } } }); @@ -583,7 +581,7 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase { return StrategyPriority.CANT_HANDLE; } if (zoneId != null && SnapshotOperation.DELETE.equals(op)) { - s_logger.debug(String.format("canHandle for zone ID: %d, operation: %s - %s", zoneId, op, StrategyPriority.DEFAULT)); + logger.debug(String.format("canHandle for zone ID: %d, operation: %s - %s", zoneId, op, StrategyPriority.DEFAULT)); } return StrategyPriority.DEFAULT; } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/ScaleIOSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/ScaleIOSnapshotStrategy.java index 3dee4f4aa94..0d48cb944ae 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/ScaleIOSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/ScaleIOSnapshotStrategy.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import com.cloud.storage.DataStoreRole; import com.cloud.storage.Snapshot; @@ -42,7 +41,6 @@ public class ScaleIOSnapshotStrategy extends StorageSystemSnapshotStrategy { @Inject private VolumeDao volumeDao; - private static final Logger LOG = Logger.getLogger(ScaleIOSnapshotStrategy.class); @Override public StrategyPriority canHandle(Snapshot snapshot, Long zoneId, SnapshotOperation op) { @@ -73,7 +71,7 @@ public class ScaleIOSnapshotStrategy extends StorageSystemSnapshotStrategy { VolumeInfo volumeInfo = snapshotInfo.getBaseVolume(); Storage.ImageFormat imageFormat = volumeInfo.getFormat(); if (!Storage.ImageFormat.RAW.equals(imageFormat)) { - LOG.error(String.format("Does not support revert snapshot of the image format [%s] on PowerFlex. Can only rollback snapshots of format RAW", imageFormat)); + logger.error(String.format("Does not support revert snapshot of the image format [%s] on PowerFlex. Can only rollback snapshots of format RAW", imageFormat)); return false; } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotObject.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotObject.java index 6cf68f64fd9..961a647d7a8 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotObject.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotObject.java @@ -41,7 +41,8 @@ import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.to.SnapshotObjectTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.to.DataObjectType; @@ -60,7 +61,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.fsm.NoTransitionException; public class SnapshotObject implements SnapshotInfo { - private static final Logger s_logger = Logger.getLogger(SnapshotObject.class); + protected Logger logger = LogManager.getLogger(getClass()); private SnapshotVO snapshot; private DataStore store; private Object payload; @@ -182,7 +183,7 @@ public class SnapshotObject implements SnapshotInfo { try { processEvent(Event.OperationNotPerformed); } catch (NoTransitionException ex) { - s_logger.error("no transition error: ", ex); + logger.error("no transition error: ", ex); throw new CloudRuntimeException("Error marking snapshot backed up: " + this.snapshot.getId() + " " + ex.getMessage()); } @@ -235,7 +236,7 @@ public class SnapshotObject implements SnapshotInfo { try { objectInStoreMgr.update(this, event); } catch (Exception e) { - s_logger.debug("Failed to update state:" + e.toString()); + logger.debug("Failed to update state:" + e.toString()); throw new CloudRuntimeException("Failed to update state: " + e.toString()); } finally { DataObjectInStore obj = objectInStoreMgr.findObject(this, this.getDataStore()); @@ -369,12 +370,12 @@ public class SnapshotObject implements SnapshotInfo { if (snapshotTO.getVolume() != null && snapshotTO.getVolume().getPath() != null) { VolumeVO vol = volumeDao.findByUuid(snapshotTO.getVolume().getUuid()); if (vol != null) { - s_logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + + logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + snapshotTO.getVolume().getPath()); vol.setPath(snapshotTO.getVolume().getPath()); volumeDao.update(vol.getId(), vol); } else { - s_logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid()); + logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid()); } } } else { diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java index 9c7ee983474..dafc40e0674 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java @@ -57,7 +57,8 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.heuristics.HeuristicRuleHelper; import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; import org.apache.cloudstack.storage.to.SnapshotObjectTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.configuration.Config; @@ -79,7 +80,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.fsm.NoTransitionException; public class SnapshotServiceImpl implements SnapshotService { - private static final Logger s_logger = Logger.getLogger(SnapshotServiceImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject protected SnapshotDao _snapshotDao; @Inject @@ -176,7 +177,7 @@ public class SnapshotServiceImpl implements SnapshotService { _sslCopy = Boolean.parseBoolean(sslCfg); } if(_sslCopy && (_ssvmUrlDomain == null || _ssvmUrlDomain.isEmpty())){ - s_logger.warn("Empty secondary storage url domain, ignoring SSL"); + logger.warn("Empty secondary storage url domain, ignoring SSL"); _sslCopy = false; } if (_sslCopy) { @@ -197,12 +198,12 @@ public class SnapshotServiceImpl implements SnapshotService { AsyncCallFuture future = context.future; SnapshotResult snapResult = new SnapshotResult(snapshot, result.getAnswer()); if (result.isFailed()) { - s_logger.debug("create snapshot " + context.snapshot.getName() + " failed: " + result.getResult()); + logger.debug("create snapshot " + context.snapshot.getName() + " failed: " + result.getResult()); try { snapshot.processEvent(Snapshot.Event.OperationFailed); snapshot.processEvent(Event.OperationFailed); } catch (Exception e) { - s_logger.debug("Failed to update snapshot state due to " + e.getMessage()); + logger.debug("Failed to update snapshot state due to " + e.getMessage()); } snapResult.setResult(result.getResult()); @@ -214,12 +215,12 @@ public class SnapshotServiceImpl implements SnapshotService { snapshot.processEvent(Event.OperationSuccessed, result.getAnswer()); snapshot.processEvent(Snapshot.Event.OperationSucceeded); } catch (Exception e) { - s_logger.debug("Failed to create snapshot: ", e); + logger.debug("Failed to create snapshot: ", e); snapResult.setResult(e.toString()); try { snapshot.processEvent(Snapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.debug("Failed to change snapshot state: " + e1.toString()); + logger.debug("Failed to change snapshot state: " + e1.toString()); } } @@ -235,25 +236,25 @@ public class SnapshotServiceImpl implements SnapshotService { try { snapshotOnPrimary = (SnapshotObject)snap.getDataStore().create(snapshot); } catch (Exception e) { - s_logger.debug("Failed to create snapshot state on data store due to " + e.getMessage()); + logger.debug("Failed to create snapshot state on data store due to " + e.getMessage()); throw new CloudRuntimeException(e); } try { snapshotOnPrimary.processEvent(Snapshot.Event.CreateRequested); } catch (NoTransitionException e) { - s_logger.debug("Failed to change snapshot state: " + e.toString()); + logger.debug("Failed to change snapshot state: " + e.toString()); throw new CloudRuntimeException(e); } try { snapshotOnPrimary.processEvent(Event.CreateOnlyRequested); } catch (Exception e) { - s_logger.debug("Failed to change snapshot state: " + e.toString()); + logger.debug("Failed to change snapshot state: " + e.toString()); try { snapshotOnPrimary.processEvent(Snapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.debug("Failed to change snapshot state: " + e1.toString()); + logger.debug("Failed to change snapshot state: " + e1.toString()); } throw new CloudRuntimeException(e); } @@ -266,12 +267,12 @@ public class SnapshotServiceImpl implements SnapshotService { PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver)snapshotOnPrimary.getDataStore().getDriver(); primaryStore.takeSnapshot(snapshot, caller); } catch (Exception e) { - s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e); + logger.debug("Failed to take snapshot: " + snapshot.getId(), e); try { snapshot.processEvent(Snapshot.Event.OperationFailed); snapshot.processEvent(Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.debug("Failed to change state for event: OperationFailed", e); + logger.debug("Failed to change state for event: OperationFailed", e); } throw new CloudRuntimeException("Failed to take snapshot" + snapshot.getId()); } @@ -284,10 +285,10 @@ public class SnapshotServiceImpl implements SnapshotService { snap.getName(), null, null, snapshotOnPrimary.getSize(), snapshotOnPrimary.getSize(), snap.getClass().getName(), snap.getUuid()); return result; } catch (InterruptedException e) { - s_logger.debug("Failed to create snapshot", e); + logger.debug("Failed to create snapshot", e); throw new CloudRuntimeException("Failed to create snapshot", e); } catch (ExecutionException e) { - s_logger.debug("Failed to create snapshot", e); + logger.debug("Failed to create snapshot", e); throw new CloudRuntimeException("Failed to create snapshot", e); } } @@ -360,7 +361,7 @@ public class SnapshotServiceImpl implements SnapshotService { caller.setCallback(caller.getTarget().copySnapshotAsyncCallback(null, null)).setContext(context); motionSrv.copyAsync(snapshot, snapshotOnImageStore, caller); } catch (Exception e) { - s_logger.debug("Failed to copy snapshot", e); + logger.debug("Failed to copy snapshot", e); result.setResult("Failed to copy snapshot:" + e.toString()); try { // When error archiving an already existing snapshot, emit OperationNotPerformed. @@ -371,7 +372,7 @@ public class SnapshotServiceImpl implements SnapshotService { snapObj.processEvent(Snapshot.Event.OperationFailed); } } catch (NoTransitionException e1) { - s_logger.debug("Failed to change state: " + e1.toString()); + logger.debug("Failed to change state: " + e1.toString()); } future.complete(result); } @@ -384,10 +385,10 @@ public class SnapshotServiceImpl implements SnapshotService { SnapshotInfo destSnapshot = res.getSnapshot(); return destSnapshot; } catch (InterruptedException e) { - s_logger.debug("failed copy snapshot", e); + logger.debug("failed copy snapshot", e); throw new CloudRuntimeException("Failed to copy snapshot", e); } catch (ExecutionException e) { - s_logger.debug("Failed to copy snapshot", e); + logger.debug("Failed to copy snapshot", e); throw new CloudRuntimeException("Failed to copy snapshot", e); } @@ -413,7 +414,7 @@ public class SnapshotServiceImpl implements SnapshotService { cleanupOnSnapshotBackupFailure(context.srcSnapshot); } } catch (SnapshotBackupException e) { - s_logger.debug("Failed to create backup: " + e.toString()); + logger.debug("Failed to create backup: " + e.toString()); } snapResult.setResult(result.getResult()); future.complete(snapResult); @@ -427,7 +428,7 @@ public class SnapshotServiceImpl implements SnapshotService { snapResult = new SnapshotResult(_snapshotFactory.getSnapshot(destSnapshot.getId(), destSnapshot.getDataStore()), copyCmdAnswer); future.complete(snapResult); } catch (Exception e) { - s_logger.debug("Failed to update snapshot state", e); + logger.debug("Failed to update snapshot state", e); snapResult.setResult(e.toString()); future.complete(snapResult); } @@ -451,7 +452,7 @@ public class SnapshotServiceImpl implements SnapshotService { snapResult = new SnapshotResult(_snapshotFactory.getSnapshot(destSnapshot.getId(), destSnapshot.getDataStore()), answer); future.complete(snapResult); } catch (Exception e) { - s_logger.debug("Failed to update snapshot state", e); + logger.debug("Failed to update snapshot state", e); snapResult.setResult(e.toString()); future.complete(snapResult); } @@ -485,7 +486,7 @@ public class SnapshotServiceImpl implements SnapshotService { SnapshotResult res = null; try { if (result.isFailed()) { - s_logger.debug(String.format("Failed to delete snapshot [%s] due to: [%s].", snapshot.getUuid(), result.getResult())); + logger.debug(String.format("Failed to delete snapshot [%s] due to: [%s].", snapshot.getUuid(), result.getResult())); snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed); res = new SnapshotResult(context.snapshot, null); res.setResult(result.getResult()); @@ -494,8 +495,8 @@ public class SnapshotServiceImpl implements SnapshotService { res = new SnapshotResult(context.snapshot, null); } } catch (Exception e) { - s_logger.error(String.format("An exception occurred while processing an event in delete snapshot callback from snapshot [%s].", snapshot.getUuid())); - s_logger.debug(String.format("Exception while processing an event in delete snapshot callback from snapshot [%s].", snapshot.getUuid()), e); + logger.error(String.format("An exception occurred while processing an event in delete snapshot callback from snapshot [%s].", snapshot.getUuid())); + logger.debug(String.format("Exception while processing an event in delete snapshot callback from snapshot [%s].", snapshot.getUuid()), e); res.setResult(e.toString()); } future.complete(res); @@ -509,14 +510,14 @@ public class SnapshotServiceImpl implements SnapshotService { SnapshotResult res = null; try { if (result.isFailed()) { - s_logger.debug("revert snapshot failed" + result.getResult()); + logger.debug("revert snapshot failed" + result.getResult()); res = new SnapshotResult(context.snapshot, null); res.setResult(result.getResult()); } else { res = new SnapshotResult(context.snapshot, null); } } catch (Exception e) { - s_logger.debug("Failed to in revertSnapshotCallback", e); + logger.debug("Failed to in revertSnapshotCallback", e); res.setResult(e.toString()); } future.complete(res); @@ -540,11 +541,11 @@ public class SnapshotServiceImpl implements SnapshotService { if (result.isFailed()) { throw new CloudRuntimeException(result.getResult()); } - s_logger.debug(String.format("Successfully deleted snapshot [%s] with ID [%s].", snapInfo.getName(), snapInfo.getUuid())); + logger.debug(String.format("Successfully deleted snapshot [%s] with ID [%s].", snapInfo.getName(), snapInfo.getUuid())); return true; } catch (InterruptedException | ExecutionException e) { - s_logger.error(String.format("Failed to delete snapshot [%s] due to: [%s].", snapInfo.getUuid(), e.getMessage())); - s_logger.debug(String.format("Failed to delete snapshot [%s].", snapInfo.getUuid()), e); + logger.error(String.format("Failed to delete snapshot [%s] due to: [%s].", snapInfo.getUuid(), e.getMessage())); + logger.debug(String.format("Failed to delete snapshot [%s].", snapInfo.getUuid()), e); } return false; @@ -555,7 +556,7 @@ public class SnapshotServiceImpl implements SnapshotService { PrimaryDataStore store = null; SnapshotInfo snapshotOnPrimaryStore = _snapshotFactory.getSnapshotOnPrimaryStore(snapshot.getId()); if (snapshotOnPrimaryStore == null) { - s_logger.warn("Cannot find an entry for snapshot " + snapshot.getId() + " on primary storage pools, searching with volume's primary storage pool"); + logger.warn("Cannot find an entry for snapshot " + snapshot.getId() + " on primary storage pools, searching with volume's primary storage pool"); VolumeInfo volumeInfo = volFactory.getVolume(snapshot.getVolumeId(), DataStoreRole.Primary); store = (PrimaryDataStore)volumeInfo.getDataStore(); } else { @@ -577,9 +578,9 @@ public class SnapshotServiceImpl implements SnapshotService { } return true; } catch (InterruptedException e) { - s_logger.debug("revert snapshot is failed: " + e.toString()); + logger.debug("revert snapshot is failed: " + e.toString()); } catch (ExecutionException e) { - s_logger.debug("revert snapshot is failed: " + e.toString()); + logger.debug("revert snapshot is failed: " + e.toString()); } return false; @@ -608,13 +609,13 @@ public class SnapshotServiceImpl implements SnapshotService { if (snaphsot.getState() != Snapshot.State.BackedUp) { List snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId); for (SnapshotDataStoreVO snapshotDataStoreVO : snapshotDataStoreVOs) { - s_logger.debug("Remove snapshot " + snapshotId + ", status " + snapshotDataStoreVO.getState() + + logger.debug("Remove snapshot " + snapshotId + ", status " + snapshotDataStoreVO.getState() + " on snapshot_store_ref table with id: " + snapshotDataStoreVO.getId()); _snapshotStoreDao.remove(snapshotDataStoreVO.getId()); } - s_logger.debug("Remove snapshot " + snapshotId + " status " + snaphsot.getState() + " from snapshot table"); + logger.debug("Remove snapshot " + snapshotId + " status " + snaphsot.getState() + " from snapshot table"); _snapshotDao.remove(snapshotId); } } @@ -631,8 +632,8 @@ public class SnapshotServiceImpl implements SnapshotService { throw new CloudRuntimeException("Cannot find an entry in snapshot_store_ref for snapshot " + snapshotId + " on region store: " + store.getName()); } if (snapOnStore.getPath() == null || snapOnStore.getPath().length() == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("sync snapshot " + snapshotId + " from cache to object store..."); + if (logger.isDebugEnabled()) { + logger.debug("sync snapshot " + snapshotId + " from cache to object store..."); } // snapshot is not on region store yet, sync to region store SnapshotInfo srcSnapshot = _snapshotFactory.getReadySnapshotOnCache(snapshotId); @@ -688,7 +689,7 @@ public class SnapshotServiceImpl implements SnapshotService { } future.complete(res); } catch (Exception e) { - s_logger.debug("Failed to process sync snapshot callback", e); + logger.debug("Failed to process sync snapshot callback", e); res.setResult(e.toString()); future.complete(res); } @@ -702,7 +703,7 @@ public class SnapshotServiceImpl implements SnapshotService { try { object.processEvent(event); } catch (NoTransitionException e) { - s_logger.debug("Unable to update the state " + e.toString()); + logger.debug("Unable to update the state " + e.toString()); } } @@ -721,7 +722,7 @@ public class SnapshotServiceImpl implements SnapshotService { _snapshotDetailsDao.removeDetail(srcSnapshot.getId(), AsyncJob.Constants.MS_ID); _snapshotDao.remove(srcSnapshot.getId()); } catch (NoTransitionException ex) { - s_logger.debug("Failed to create backup " + ex.toString()); + logger.debug("Failed to create backup " + ex.toString()); throw new CloudRuntimeException("Failed to backup snapshot" + snapshot.getId()); } } @@ -734,16 +735,16 @@ public class SnapshotServiceImpl implements SnapshotService { SnapshotObject snapshotForCopy = (SnapshotObject)_snapshotFactory.getSnapshot(snapshot, store); snapshotForCopy.setUrl(copyUrl); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Mark snapshot_store_ref entry as Creating"); + if (logger.isDebugEnabled()) { + logger.debug("Mark snapshot_store_ref entry as Creating"); } AsyncCallFuture future = new AsyncCallFuture(); DataObject snapshotOnStore = store.create(snapshotForCopy); ((SnapshotObject)snapshotOnStore).setUrl(copyUrl); snapshotOnStore.processEvent(Event.CreateOnlyRequested); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Invoke datastore driver createAsync to create snapshot on destination store"); + if (logger.isDebugEnabled()) { + logger.debug("Invoke datastore driver createAsync to create snapshot on destination store"); } try { CopySnapshotContext context = new CopySnapshotContext<>(null, (SnapshotObject)snapshotOnStore, snapshotForCopy, future); @@ -768,7 +769,7 @@ public class SnapshotServiceImpl implements SnapshotService { AsyncCallFuture future = new AsyncCallFuture<>(); EndPoint ep = epSelector.select(snapshot); if (ep == null) { - s_logger.error(String.format("Failed to find endpoint for generating copy URL for snapshot %d with store %d", snapshot.getId(), snapshot.getDataStore().getId())); + logger.error(String.format("Failed to find endpoint for generating copy URL for snapshot %d with store %d", snapshot.getId(), snapshot.getDataStore().getId())); throw new ResourceUnavailableException("No secondary VM in running state in source snapshot zone", DataCenter.class, snapshot.getDataCenterId()); } DataStore store = snapshot.getDataStore(); diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotStrategyBase.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotStrategyBase.java index ba16e75f737..2bfcbc107f7 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotStrategyBase.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotStrategyBase.java @@ -21,8 +21,11 @@ import javax.inject.Inject; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public abstract class SnapshotStrategyBase implements SnapshotStrategy { + protected Logger logger = LogManager.getLogger(getClass()); @Inject SnapshotService snapshotSvr; diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java index dabb8d17702..9838e41f8f6 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java @@ -45,7 +45,6 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -91,7 +90,6 @@ import com.google.common.base.Preconditions; @Component public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { - private static final Logger s_logger = Logger.getLogger(StorageSystemSnapshotStrategy.class); @Inject private AgentManager agentMgr; @Inject private ClusterDao clusterDao; @@ -132,7 +130,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { if (!canStorageSystemCreateVolumeFromSnapshot) { String msg = "Cannot archive snapshot: 'canStorageSystemCreateVolumeFromSnapshot' was false."; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } @@ -142,7 +140,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { if (!computeClusterSupportsResign) { String msg = "Cannot archive snapshot: 'computeClusterSupportsResign' was false."; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } @@ -185,7 +183,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { SnapshotObject snapshotObj = (SnapshotObject)snapshotDataFactory.getSnapshotOnPrimaryStore(snapshotId); if (snapshotObj == null) { - s_logger.debug("Can't find snapshot; deleting it in DB"); + logger.debug("Can't find snapshot; deleting it in DB"); snapshotDao.remove(snapshotId); @@ -205,14 +203,14 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { try { snapshotObj.processEvent(Snapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.debug("Failed to change snapshot state: " + e1.toString()); + logger.debug("Failed to change snapshot state: " + e1.toString()); } throw new InvalidParameterValueException("Unable to perform delete operation, Snapshot with id: " + snapshotId + " is in use "); } } catch (NoTransitionException e) { - s_logger.debug("Failed to set the state to destroying: ", e); + logger.debug("Failed to set the state to destroying: ", e); return false; } @@ -226,13 +224,13 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { snapshotObj.getName(), null, null, 0L, snapshotObj.getClass().getName(), snapshotObj.getUuid()); } catch (Exception e) { - s_logger.debug("Failed to delete snapshot: ", e); + logger.debug("Failed to delete snapshot: ", e); try { snapshotObj.processEvent(Snapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.debug("Failed to change snapshot state: " + e.toString()); + logger.debug("Failed to change snapshot state: " + e.toString()); } return false; @@ -302,7 +300,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { if (!volumeInfo.getPoolId().equals(snapshotStoragePoolId)) { String errMsg = "Storage pool mismatch"; - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -313,7 +311,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { if (!storageSystemSupportsCapability) { String errMsg = "Storage pool revert capability not supported"; - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -335,7 +333,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { if (snapshotVO == null) { String errMsg = "Failed to acquire lock on the following snapshot: " + snapshotInfo.getId(); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -362,7 +360,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { String errMsg = String.format("Failed to revert volume [name:%s, format:%s] to snapshot [id:%s] state", volumeInfo.getName(), volumeInfo.getFormat(), snapshotInfo.getSnapshotId()); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } @@ -500,7 +498,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { result = snapshotSvr.takeSnapshot(snapshotInfo); if (result.isFailed()) { - s_logger.debug("Failed to take a snapshot: " + result.getResult()); + logger.debug("Failed to take a snapshot: " + result.getResult()); throw new CloudRuntimeException(result.getResult()); } @@ -539,7 +537,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { try { snapshotSvr.deleteSnapshot(snapshot); } catch (Exception e) { - s_logger.warn("Failed to clean up snapshot '" + snapshot.getId() + "' on primary storage: " + e.getMessage()); + logger.warn("Failed to clean up snapshot '" + snapshot.getId() + "' on primary storage: " + e.getMessage()); } } @@ -571,7 +569,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { Thread.sleep(60000); } catch (Exception ex) { - s_logger.warn(ex.getMessage(), ex); + logger.warn(ex.getMessage(), ex); } return vmSnapshot; @@ -686,7 +684,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { if (hostVO == null) { final String errMsg = "Unable to locate an applicable host"; - s_logger.error("performSnapshotAndCopyOnHostSide: " + errMsg); + logger.error("performSnapshotAndCopyOnHostSide: " + errMsg); throw new CloudRuntimeException(errMsg); } @@ -724,7 +722,7 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { } } catch (Exception ex) { - s_logger.debug(ex.getMessage(), ex); + logger.debug(ex.getMessage(), ex); } } @@ -894,13 +892,13 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase { snapshotObj.processEvent(Snapshot.Event.OperationSucceeded); } catch (NoTransitionException ex) { - s_logger.debug("Failed to change state: " + ex.toString()); + logger.debug("Failed to change state: " + ex.toString()); try { snapshotObj.processEvent(Snapshot.Event.OperationFailed); } catch (NoTransitionException ex2) { - s_logger.debug("Failed to change state: " + ex2.toString()); + logger.debug("Failed to change state: " + ex2.toString()); } } } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java index e2815c005c4..1d3788a0301 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -77,7 +76,6 @@ import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDao; public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshotStrategy { - private static final Logger s_logger = Logger.getLogger(DefaultVMSnapshotStrategy.class); @Inject VMSnapshotHelper vmSnapshotHelper; @Inject @@ -164,7 +162,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot answer = (CreateVMSnapshotAnswer)agentMgr.send(hostId, ccmd); if (answer != null && answer.getResult()) { processAnswer(vmSnapshotVO, userVm, answer, hostId); - s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); + logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); result = true; long new_chain_size=0; for (VolumeObjectTO volumeTo : answer.getVolumeTOs()) { @@ -177,21 +175,21 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot String errMsg = "Creating VM snapshot: " + vmSnapshot.getName() + " failed"; if (answer != null && answer.getDetails() != null) errMsg = errMsg + " due to " + answer.getDetails(); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } catch (OperationTimedoutException e) { - s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); + logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); } catch (AgentUnavailableException e) { - s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e); + logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e); throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -204,7 +202,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } @@ -235,7 +233,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot return true; } else { String errMsg = (answer == null) ? null : answer.getDetails(); - s_logger.error("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg); + logger.error("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg); processAnswer(vmSnapshotVO, userVm, answer, hostId); throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg); } @@ -271,7 +269,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot }); } catch (Exception e) { String errMsg = "Error while process answer: " + as.getClass() + " due to " + e.getMessage(); - s_logger.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -377,7 +375,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot UsageEventUtils.publishUsageEvent(type, vmSnapshot.getAccountId(), userVm.getDataCenterId(), userVm.getId(), vmSnapshot.getName(), 0L, 0L, vmSnapSize, virtualSize, VMSnapshot.class.getName(), vmSnapshot.getUuid(), details); } catch (Exception e) { - s_logger.error("Failed to publis usage event " + type, e); + logger.error("Failed to publis usage event " + type, e); } } @@ -420,21 +418,21 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot String errMsg = "Revert VM: " + userVm.getInstanceName() + " to snapshot: " + vmSnapshotVO.getName() + " failed"; if (answer != null && answer.getDetails() != null) errMsg = errMsg + " due to " + answer.getDetails(); - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } catch (OperationTimedoutException e) { - s_logger.debug("Failed to revert vm snapshot", e); + logger.debug("Failed to revert vm snapshot", e); throw new CloudRuntimeException(e.getMessage()); } catch (AgentUnavailableException e) { - s_logger.debug("Failed to revert vm snapshot", e); + logger.debug("Failed to revert vm snapshot", e); throw new CloudRuntimeException(e.getMessage()); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -451,7 +449,7 @@ public class DefaultVMSnapshotStrategy extends ManagerBase implements VMSnapshot try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } UserVm userVm = userVmDao.findById(vmSnapshot.getVmId()); diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java index 50afa647dc3..d27beecfdda 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/ScaleIOVMSnapshotStrategy.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.util.ScaleIOUtil; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.VMSnapshotTO; import com.cloud.alert.AlertManager; @@ -70,7 +69,6 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDao; import com.cloud.vm.snapshot.dao.VMSnapshotDetailsDao; public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshotStrategy { - private static final Logger LOGGER = Logger.getLogger(ScaleIOVMSnapshotStrategy.class); @Inject VMSnapshotHelper vmSnapshotHelper; @Inject @@ -213,7 +211,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot finalizeCreate(vmSnapshotVO, volumeTOs); result = true; - LOGGER.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); + logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); long new_chain_size=0; for (VolumeObjectTO volumeTo : volumeTOs) { @@ -224,7 +222,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot return vmSnapshot; } catch (Exception e) { String errMsg = "Unable to take vm snapshot due to: " + e.getMessage(); - LOGGER.warn(errMsg, e); + logger.warn(errMsg, e); throw new CloudRuntimeException(errMsg); } } finally { @@ -236,7 +234,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot String message = "Snapshot operation failed for VM: " + userVm.getDisplayName() + ", Please check and delete if any stale volumes created with VM snapshot id: " + vmSnapshot.getVmId(); alertManager.sendAlert(AlertManager.AlertType.ALERT_TYPE_VM_SNAPSHOT, userVm.getDataCenterId(), userVm.getPodIdToDeployIn(), subject, message); } catch (NoTransitionException e1) { - LOGGER.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -274,7 +272,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot }); } catch (Exception e) { String errMsg = "Error while finalize create vm snapshot: " + vmSnapshot.getName() + " due to " + e.getMessage(); - LOGGER.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -317,14 +315,14 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot result = true; } catch (Exception e) { String errMsg = "Revert VM: " + userVm.getInstanceName() + " to snapshot: " + vmSnapshotVO.getName() + " failed due to " + e.getMessage(); - LOGGER.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - LOGGER.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -361,7 +359,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot }); } catch (Exception e) { String errMsg = "Error while finalize revert vm snapshot: " + vmSnapshot.getName() + " due to " + e.getMessage(); - LOGGER.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -374,7 +372,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - LOGGER.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } @@ -397,7 +395,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot if (volumesDeleted <= 0) { throw new CloudRuntimeException("Failed to delete VM snapshot: " + vmSnapshot.getName()); } else if (volumesDeleted != volumeTOs.size()) { - LOGGER.warn("Unable to delete all volumes of the VM snapshot: " + vmSnapshot.getName()); + logger.warn("Unable to delete all volumes of the VM snapshot: " + vmSnapshot.getName()); } finalizeDelete(vmSnapshotVO, volumeTOs); @@ -410,7 +408,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot return true; } catch (Exception e) { String errMsg = "Unable to delete vm snapshot: " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " due to " + e.getMessage(); - LOGGER.warn(errMsg, e); + logger.warn(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -453,7 +451,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot }); } catch (Exception e) { String errMsg = "Error while finalize delete vm snapshot: " + vmSnapshot.getName() + " due to " + e.getMessage(); - LOGGER.error(errMsg, e); + logger.error(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -463,7 +461,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - LOGGER.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } UserVm userVm = userVmDao.findById(vmSnapshot.getVmId()); @@ -507,7 +505,7 @@ public class ScaleIOVMSnapshotStrategy extends ManagerBase implements VMSnapshot UsageEventUtils.publishUsageEvent(type, vmSnapshot.getAccountId(), userVm.getDataCenterId(), userVm.getId(), vmSnapshot.getName(), 0L, 0L, vmSnapSize, virtualSize, VMSnapshot.class.getName(), vmSnapshot.getUuid(), details); } catch (Exception e) { - LOGGER.error("Failed to publish usage event " + type, e); + logger.error("Failed to publish usage event " + type, e); } } diff --git a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/StorageVMSnapshotStrategy.java b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/StorageVMSnapshotStrategy.java index f5d70817333..ec73246851c 100644 --- a/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/StorageVMSnapshotStrategy.java +++ b/engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/vmsnapshot/StorageVMSnapshotStrategy.java @@ -39,7 +39,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.CreateVMSnapshotAnswer; import com.cloud.agent.api.CreateVMSnapshotCommand; @@ -75,7 +74,6 @@ import com.cloud.vm.snapshot.VMSnapshotVO; import com.cloud.vm.snapshot.dao.VMSnapshotDetailsDao; public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { - private static final Logger s_logger = Logger.getLogger(StorageVMSnapshotStrategy.class); @Inject VolumeApiService volumeService; @Inject @@ -148,7 +146,7 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { vmSnapshotVO.setParent(current.getId()); } CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(userVm.getInstanceName(), userVm.getUuid(), target, volumeTOs, guestOS.getDisplayName()); - s_logger.info("Creating VM snapshot for KVM hypervisor without memory"); + logger.info("Creating VM snapshot for KVM hypervisor without memory"); List vinfos = new ArrayList<>(); for (VolumeObjectTO volumeObjectTO : volumeTOs) { @@ -166,7 +164,7 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { thawCmd = new FreezeThawVMCommand(userVm.getInstanceName()); thawCmd.setOption(FreezeThawVMCommand.THAW); if (freezeAnswer != null && freezeAnswer.getResult()) { - s_logger.info("The virtual machine is frozen"); + logger.info("The virtual machine is frozen"); for (VolumeInfo vol : vinfos) { long startSnapshtot = System.nanoTime(); SnapshotInfo snapInfo = createDiskSnapshot(vmSnapshot, forRollback, vol); @@ -175,14 +173,14 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { thawAnswer = (FreezeThawVMAnswer) agentMgr.send(hostId, thawCmd); throw new CloudRuntimeException("Could not take snapshot for volume with id=" + vol.getId()); } - s_logger.info(String.format("Snapshot with id=%s, took %s milliseconds", snapInfo.getId(), + logger.info(String.format("Snapshot with id=%s, took %s milliseconds", snapInfo.getId(), TimeUnit.MILLISECONDS.convert(elapsedTime(startSnapshtot), TimeUnit.NANOSECONDS))); } answer = new CreateVMSnapshotAnswer(ccmd, true, ""); answer.setVolumeTOs(volumeTOs); thawAnswer = (FreezeThawVMAnswer) agentMgr.send(hostId, thawCmd); if (thawAnswer != null && thawAnswer.getResult()) { - s_logger.info(String.format( + logger.info(String.format( "Virtual machne is thawed. The freeze of virtual machine took %s milliseconds.", TimeUnit.MILLISECONDS.convert(elapsedTime(startFreeze), TimeUnit.NANOSECONDS))); } @@ -191,7 +189,7 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { } if (answer != null && answer.getResult()) { processAnswer(vmSnapshotVO, userVm, answer, null); - s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); + logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName()); long new_chain_size = 0; for (VolumeObjectTO volumeTo : answer.getVolumeTOs()) { publishUsageEvent(EventTypes.EVENT_VM_SNAPSHOT_CREATE, vmSnapshot, userVm, volumeTo); @@ -202,27 +200,27 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { return vmSnapshot; } else { String errMsg = "Creating VM snapshot: " + vmSnapshot.getName() + " failed"; - s_logger.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg); } } catch (OperationTimedoutException e) { - s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); + logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); throw new CloudRuntimeException( "Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); } catch (AgentUnavailableException e) { - s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e); + logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e); throw new CloudRuntimeException( "Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString()); } catch (CloudRuntimeException e) { throw new CloudRuntimeException(e.getMessage()); } finally { if (thawAnswer == null && freezeAnswer != null) { - s_logger.info(String.format("Freeze of virtual machine took %s milliseconds.", TimeUnit.MILLISECONDS + logger.info(String.format("Freeze of virtual machine took %s milliseconds.", TimeUnit.MILLISECONDS .convert(elapsedTime(startFreeze), TimeUnit.NANOSECONDS))); try { thawAnswer = (FreezeThawVMAnswer) agentMgr.send(hostId, thawCmd); } catch (AgentUnavailableException | OperationTimedoutException e) { - s_logger.debug("Could not unfreeze the VM due to " + e); + logger.debug("Could not unfreeze the VM due to " + e); } } if (!result) { @@ -238,7 +236,7 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { } vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -251,7 +249,7 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested); } catch (NoTransitionException e) { - s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); + logger.debug("Failed to change vm snapshot state with event ExpungeRequested"); throw new CloudRuntimeException( "Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage()); } @@ -289,7 +287,7 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { } } String errMsg = String.format("Delete of VM snapshot [%s] of VM [%s] failed due to [%s]", vmSnapshot.getName(), userVm.getUserId(), err); - s_logger.error(errMsg, err); + logger.error(errMsg, err); throw new CloudRuntimeException(errMsg, err); } } @@ -325,14 +323,14 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { processAnswer(vmSnapshotVO, userVm, answer, null); result = true; } catch (CloudRuntimeException e) { - s_logger.error(e); + logger.error(e); throw new CloudRuntimeException(e); } finally { if (!result) { try { vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed); } catch (NoTransitionException e1) { - s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); + logger.error("Cannot set vm snapshot state due to: " + e1.getMessage()); } } } @@ -382,7 +380,7 @@ public class StorageVMSnapshotStrategy extends DefaultVMSnapshotStrategy { Long snapshotID = snapshotInfo.getId(); SnapshotVO snapshot = snapshotDao.findById(snapshotID); deleteSnapshotByStrategy(snapshot); - s_logger.debug("Rollback is executed: deleting snapshot with id:" + snapshotID); + logger.debug("Rollback is executed: deleting snapshot with id:" + snapshotID); } protected void deleteSnapshotByStrategy(SnapshotVO snapshot) { diff --git a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java index b33f57c685c..0a8bba821f8 100644 --- a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java +++ b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/snapshot/CephSnapshotStrategyTest.java @@ -33,7 +33,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.storage.Snapshot; import com.cloud.storage.Storage.ImageFormat; diff --git a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java index d438fef5638..6aab8d32384 100644 --- a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java +++ b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyKVMTest.java @@ -47,7 +47,7 @@ import org.apache.cloudstack.test.utils.SpringUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -192,22 +192,22 @@ public class VMSnapshotStrategyKVMTest extends TestCase{ UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); @@ -270,22 +270,22 @@ public class VMSnapshotStrategyKVMTest extends TestCase{ UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class); diff --git a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java index 5fd6dee9083..7bcfd4dda58 100644 --- a/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java +++ b/engine/storage/snapshot/src/test/java/org/apache/cloudstack/storage/vmsnapshot/VMSnapshotStrategyTest.java @@ -33,7 +33,7 @@ import org.apache.cloudstack.test.utils.SpringUtils; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -115,18 +115,18 @@ public class VMSnapshotStrategyTest extends TestCase { UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(null); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); Exception e = null; @@ -139,8 +139,8 @@ public class VMSnapshotStrategyTest extends TestCase { assertNotNull(e); CreateVMSnapshotAnswer answer = Mockito.mock(CreateVMSnapshotAnswer.class); Mockito.when(answer.getResult()).thenReturn(true); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(answer); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); VMSnapshot snapshot = null; snapshot = vmSnapshotStrategy.takeVMSnapshot(vmSnapshot); assertNotNull(snapshot); @@ -159,23 +159,23 @@ public class VMSnapshotStrategyTest extends TestCase { UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(null); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); Exception e = null; @@ -189,7 +189,7 @@ public class VMSnapshotStrategyTest extends TestCase { RevertToVMSnapshotAnswer answer = Mockito.mock(RevertToVMSnapshotAnswer.class); Mockito.when(answer.getResult()).thenReturn(Boolean.TRUE); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(answer); boolean result = vmSnapshotStrategy.revertVMSnapshot(vmSnapshot); assertTrue(result); } @@ -207,23 +207,23 @@ public class VMSnapshotStrategyTest extends TestCase { UserVmVO userVmVO = Mockito.mock(UserVmVO.class); Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId); Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId); - Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId); - Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs); - Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO); + Mockito.when(vmSnapshotHelper.pickRunningHost(ArgumentMatchers.anyLong())).thenReturn(hostId); + Mockito.when(vmSnapshotHelper.getVolumeTOList(ArgumentMatchers.anyLong())).thenReturn(volumeObjectTOs); + Mockito.when(userVmDao.findById(ArgumentMatchers.anyLong())).thenReturn(userVmVO); GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class); - Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO); + Mockito.when(guestOSDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSVO); GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class); Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName); - Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO); - Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findById(ArgumentMatchers.anyLong())).thenReturn(guestOSHypervisorVO); + Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(ArgumentMatchers.anyLong(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(guestOSHypervisorVO); VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class); - Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); - Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot); + Mockito.when(vmSnapshotHelper.getSnapshotWithParents(ArgumentMatchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO); + Mockito.when(vmSnapshotDao.findById(ArgumentMatchers.anyLong())).thenReturn(vmSnapshot); Mockito.when(vmSnapshot.getId()).thenReturn(1L); Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date()); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(null); HostVO hostVO = Mockito.mock(HostVO.class); - Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO); + Mockito.when(hostDao.findById(ArgumentMatchers.anyLong())).thenReturn(hostVO); Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType); Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion); @@ -238,7 +238,7 @@ public class VMSnapshotStrategyTest extends TestCase { DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class); Mockito.when(answer.getResult()).thenReturn(true); - Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer); + Mockito.when(agentMgr.send(ArgumentMatchers.anyLong(), ArgumentMatchers.any(Command.class))).thenReturn(answer); boolean result = vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot); assertTrue(result); diff --git a/engine/storage/snapshot/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/engine/storage/snapshot/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/engine/storage/snapshot/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/RemoteHostEndPoint.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/RemoteHostEndPoint.java index b438bc121e4..fdde4ce3e62 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/RemoteHostEndPoint.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/RemoteHostEndPoint.java @@ -26,7 +26,8 @@ import javax.inject.Inject; import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -51,7 +52,7 @@ import com.cloud.vm.SecondaryStorageVmVO; import com.cloud.vm.dao.SecondaryStorageVmDao; public class RemoteHostEndPoint implements EndPoint { - private static final Logger s_logger = Logger.getLogger(RemoteHostEndPoint.class); + protected Logger logger = LogManager.getLogger(getClass()); private long hostId; private String hostAddress; @@ -125,10 +126,10 @@ public class RemoteHostEndPoint implements EndPoint { return agentMgr.send(newHostId, cmd); } catch (AgentUnavailableException e) { errMsg = e.toString(); - s_logger.debug("Failed to send command, due to Agent:" + getId() + ", " + e.toString()); + logger.debug("Failed to send command, due to Agent:" + getId() + ", " + e.toString()); } catch (OperationTimedoutException e) { errMsg = e.toString(); - s_logger.debug("Failed to send command, due to Agent:" + getId() + ", " + e.toString()); + logger.debug("Failed to send command, due to Agent:" + getId() + ", " + e.toString()); } throw new CloudRuntimeException("Failed to send command, due to Agent:" + getId() + ", " + errMsg); } @@ -216,8 +217,8 @@ public class RemoteHostEndPoint implements EndPoint { // update endpoint with new host if changed setId(newHostId); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sending command " + cmd.toString() + " to host: " + newHostId); + if (logger.isDebugEnabled()) { + logger.debug("Sending command " + cmd.toString() + " to host: " + newHostId); } agentMgr.send(newHostId, new Commands(cmd), new CmdRunner(callback)); } catch (AgentUnavailableException e) { diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java index 89a7b577ae7..63524ccb6db 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.commons.lang3.StringUtils; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; @@ -66,7 +65,6 @@ import com.cloud.vm.DiskProfile; import com.cloud.vm.VirtualMachineProfile; public abstract class AbstractStoragePoolAllocator extends AdapterBase implements StoragePoolAllocator { - private static final Logger s_logger = Logger.getLogger(AbstractStoragePoolAllocator.class); protected BigDecimal storageOverprovisioningFactor = new BigDecimal(1); protected String allocationAlgorithm = "random"; @@ -106,16 +104,20 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement return false; } - protected abstract List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck); + protected abstract List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword); @Override public List allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { - return allocateToPool(dskCh, vmProfile, plan, avoid, returnUpTo, false); + return allocateToPool(dskCh, vmProfile, plan, avoid, returnUpTo, false, null); } @Override public List allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) { - List pools = select(dskCh, vmProfile, plan, avoid, returnUpTo, bypassStorageTypeCheck); + return allocateToPool(dskCh, vmProfile, plan, avoid, returnUpTo, bypassStorageTypeCheck, null); + } + + public List allocateToPool(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) { + List pools = select(dskCh, vmProfile, plan, avoid, returnUpTo, bypassStorageTypeCheck, keyword); return reorderPools(pools, vmProfile, plan, dskCh); } @@ -136,7 +138,7 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement List poolIdsByCapacity = capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType); - s_logger.debug(String.format("List of pools in descending order of available capacity [%s].", poolIdsByCapacity)); + logger.debug(String.format("List of pools in descending order of available capacity [%s].", poolIdsByCapacity)); //now filter the given list of Pools by this ordered list @@ -165,7 +167,7 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement Long clusterId = plan.getClusterId(); List poolIdsByVolCount = volumeDao.listPoolIdsByVolumeCount(dcId, podId, clusterId, account.getAccountId()); - s_logger.debug(String.format("List of pools in ascending order of number of volumes for account [%s] is [%s].", account, poolIdsByVolCount)); + logger.debug(String.format("List of pools in ascending order of number of volumes for account [%s] is [%s].", account, poolIdsByVolCount)); // now filter the given list of Pools by this ordered list Map poolMap = new HashMap<>(); @@ -186,15 +188,15 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement @Override public List reorderPools(List pools, VirtualMachineProfile vmProfile, DeploymentPlan plan, DiskProfile dskCh) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("reordering pools"); + if (logger.isTraceEnabled()) { + logger.trace("reordering pools"); } if (pools == null) { - s_logger.trace("There are no pools to reorder; returning null."); + logger.trace("There are no pools to reorder; returning null."); return null; } - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("reordering %d pools", pools.size())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("reordering %d pools", pools.size())); } Account account = null; if (vmProfile.getVirtualMachine() != null) { @@ -204,8 +206,8 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement pools = reorderStoragePoolsBasedOnAlgorithm(pools, plan, account); if (vmProfile.getVirtualMachine() == null) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("The VM is null, skipping pools reordering by disk provisioning type."); + if (logger.isTraceEnabled()) { + logger.trace("The VM is null, skipping pools reordering by disk provisioning type."); } return pools; } @@ -222,8 +224,8 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement if (allocationAlgorithm.equals("random") || allocationAlgorithm.equals("userconcentratedpod_random") || (account == null)) { reorderRandomPools(pools); } else if (StringUtils.equalsAny(allocationAlgorithm, "userdispersing", "firstfitleastconsumed")) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Using reordering algorithm [%s]", allocationAlgorithm)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Using reordering algorithm [%s]", allocationAlgorithm)); } if (allocationAlgorithm.equals("userdispersing")) { @@ -236,13 +238,13 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement } void reorderRandomPools(List pools) { - StorageUtil.traceLogStoragePools(pools, s_logger, "pools to choose from: "); - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Shuffle this so that we don't check the pools in the same order. Algorithm == '%s' (or no account?)", allocationAlgorithm)); + StorageUtil.traceLogStoragePools(pools, logger, "pools to choose from: "); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Shuffle this so that we don't check the pools in the same order. Algorithm == '%s' (or no account?)", allocationAlgorithm)); } - StorageUtil.traceLogStoragePools(pools, s_logger, "pools to shuffle: "); + StorageUtil.traceLogStoragePools(pools, logger, "pools to shuffle: "); Collections.shuffle(pools, secureRandom); - StorageUtil.traceLogStoragePools(pools, s_logger, "shuffled list of pools to choose from: "); + StorageUtil.traceLogStoragePools(pools, logger, "shuffled list of pools to choose from: "); } private List reorderPoolsByDiskProvisioningType(List pools, DiskProfile diskProfile) { @@ -267,15 +269,15 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement } protected boolean filter(ExcludeList avoid, StoragePool pool, DiskProfile dskCh, DeploymentPlan plan) { - s_logger.debug(String.format("Checking if storage pool [%s] is suitable to disk [%s].", pool, dskCh)); + logger.debug(String.format("Checking if storage pool [%s] is suitable to disk [%s].", pool, dskCh)); if (avoid.shouldAvoid(pool)) { - s_logger.debug(String.format("StoragePool [%s] is in avoid set, skipping this pool to allocation of disk [%s].", pool, dskCh)); + logger.debug(String.format("StoragePool [%s] is in avoid set, skipping this pool to allocation of disk [%s].", pool, dskCh)); return false; } if (dskCh.requiresEncryption() && !pool.getPoolType().supportsEncryption()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Storage pool type '%s' doesn't support encryption required for volume, skipping this pool", pool.getPoolType())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Storage pool type '%s' doesn't support encryption required for volume, skipping this pool", pool.getPoolType())); } return false; } @@ -284,20 +286,20 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement if (clusterId != null) { ClusterVO cluster = clusterDao.findById(clusterId); if (!(cluster.getHypervisorType() == dskCh.getHypervisorType())) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("StoragePool's Cluster does not have required hypervisorType, skipping this pool"); + if (logger.isDebugEnabled()) { + logger.debug("StoragePool's Cluster does not have required hypervisorType, skipping this pool"); } return false; } } else if (pool.getHypervisor() != null && !pool.getHypervisor().equals(HypervisorType.Any) && !(pool.getHypervisor() == dskCh.getHypervisorType())) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("StoragePool does not have required hypervisorType, skipping this pool"); + if (logger.isDebugEnabled()) { + logger.debug("StoragePool does not have required hypervisorType, skipping this pool"); } return false; } if (!checkDiskProvisioningSupport(dskCh, pool)) { - s_logger.debug(String.format("Storage pool [%s] does not have support to disk provisioning of disk [%s].", pool, ReflectionToStringBuilderUtils.reflectOnlySelectedFields(dskCh, + logger.debug(String.format("Storage pool [%s] does not have support to disk provisioning of disk [%s].", pool, ReflectionToStringBuilderUtils.reflectOnlySelectedFields(dskCh, "type", "name", "diskOfferingId", "templateId", "volumeId", "provisioningType", "hyperType"))); return false; } @@ -306,14 +308,18 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement return false; } - Volume volume = volumeDao.findById(dskCh.getVolumeId()); - if(!storageMgr.storagePoolCompatibleWithVolumePool(pool, volume)) { - s_logger.debug(String.format("Pool [%s] is not compatible with volume [%s], skipping it.", pool, volume)); - return false; + Volume volume = null; + boolean isTempVolume = dskCh.getVolumeId() == Volume.DISK_OFFERING_SUITABILITY_CHECK_VOLUME_ID; + if (!isTempVolume) { + volume = volumeDao.findById(dskCh.getVolumeId()); + if (!storageMgr.storagePoolCompatibleWithVolumePool(pool, volume)) { + logger.debug(String.format("Pool [%s] is not compatible with volume [%s], skipping it.", pool, volume)); + return false; + } } if (pool.isManaged() && !storageUtil.managedStoragePoolCanScale(pool, plan.getClusterId(), plan.getHostId())) { - s_logger.debug(String.format("Cannot allocate pool [%s] to volume [%s] because the max number of managed clustered filesystems has been exceeded.", pool, volume)); + logger.debug(String.format("Cannot allocate pool [%s] to volume [%s] because the max number of managed clustered filesystems has been exceeded.", pool, volume)); return false; } @@ -322,29 +328,35 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement requestVolumeDiskProfilePairs.add(new Pair<>(volume, dskCh)); if (dskCh.getHypervisorType() == HypervisorType.VMware) { if (pool.getPoolType() == Storage.StoragePoolType.DatastoreCluster && storageMgr.isStoragePoolDatastoreClusterParent(pool)) { - s_logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is a parent datastore cluster.", pool, volume)); + logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is a parent datastore cluster.", pool, volume)); return false; } if (pool.getParent() != 0L) { StoragePoolVO datastoreCluster = storagePoolDao.findById(pool.getParent()); if (datastoreCluster == null || (datastoreCluster != null && datastoreCluster.getStatus() != StoragePoolStatus.Up)) { - s_logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not in [%s] state.", datastoreCluster, volume, StoragePoolStatus.Up)); + logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not in [%s] state.", datastoreCluster, volume, StoragePoolStatus.Up)); return false; } } try { - boolean isStoragePoolStoragepolicyComplaince = storageMgr.isStoragePoolCompliantWithStoragePolicy(requestVolumeDiskProfilePairs, pool); - if (!isStoragePoolStoragepolicyComplaince) { - s_logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not compliant with the storage policy required by the volume.", pool, volume)); + boolean isStoragePoolStoragePolicyCompliance = isTempVolume ? + storageMgr.isStoragePoolCompliantWithStoragePolicy(dskCh.getDiskOfferingId(), pool) : + storageMgr.isStoragePoolCompliantWithStoragePolicy(requestVolumeDiskProfilePairs, pool); + if (!isStoragePoolStoragePolicyCompliance) { + logger.debug(String.format("Skipping allocation of pool [%s] to volume [%s] because this pool is not compliant with the storage policy required by the volume.", pool, volume)); return false; } } catch (StorageUnavailableException e) { - s_logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", pool.getUuid(), e.getMessage())); + logger.warn(String.format("Could not verify storage policy complaince against storage pool %s due to exception %s", pool.getUuid(), e.getMessage())); return false; } } - return storageMgr.storagePoolHasEnoughIops(requestVolumeDiskProfilePairs, pool) && storageMgr.storagePoolHasEnoughSpace(requestVolumeDiskProfilePairs, pool, plan.getClusterId()); + return isTempVolume ? + (storageMgr.storagePoolHasEnoughIops(dskCh.getMinIops(), pool) && + storageMgr.storagePoolHasEnoughSpace(dskCh.getSize(), pool)): + (storageMgr.storagePoolHasEnoughIops(requestVolumeDiskProfilePairs, pool) && + storageMgr.storagePoolHasEnoughSpace(requestVolumeDiskProfilePairs, pool, plan.getClusterId())); } private boolean checkDiskProvisioningSupport(DiskProfile dskCh, StoragePool pool) { @@ -368,13 +380,13 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement //LXC ROOT disks supports NFS and local storage pools only if(!(Storage.StoragePoolType.NetworkFilesystem.equals(poolType) || Storage.StoragePoolType.Filesystem.equals(poolType)) ){ - s_logger.debug("StoragePool does not support LXC ROOT disk, skipping this pool"); + logger.debug("StoragePool does not support LXC ROOT disk, skipping this pool"); return false; } } else if (Volume.Type.DATADISK.equals(volType)){ //LXC DATA disks supports RBD storage pool only if(!Storage.StoragePoolType.RBD.equals(poolType)){ - s_logger.debug("StoragePool does not support LXC DATA disk, skipping this pool"); + logger.debug("StoragePool does not support LXC DATA disk, skipping this pool"); return false; } } @@ -385,18 +397,18 @@ public abstract class AbstractStoragePoolAllocator extends AdapterBase implement protected void logDisabledStoragePools(long dcId, Long podId, Long clusterId, ScopeType scope) { List disabledPools = storagePoolDao.findDisabledPoolsByScope(dcId, podId, clusterId, scope); if (disabledPools != null && !disabledPools.isEmpty()) { - s_logger.trace(String.format("Ignoring pools [%s] as they are in disabled state.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(disabledPools))); + logger.trace(String.format("Ignoring pools [%s] as they are in disabled state.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(disabledPools))); } } protected void logStartOfSearch(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, int returnUpTo, boolean bypassStorageTypeCheck){ - s_logger.trace(String.format("%s is looking for storage pools that match the VM's disk profile [%s], virtual machine profile [%s] and " + logger.trace(String.format("%s is looking for storage pools that match the VM's disk profile [%s], virtual machine profile [%s] and " + "deployment plan [%s]. Returning up to [%d] and bypassStorageTypeCheck [%s].", this.getClass().getSimpleName(), dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck)); } protected void logEndOfSearch(List storagePoolList) { - s_logger.debug(String.format("%s is returning [%s] suitable storage pools [%s].", this.getClass().getSimpleName(), storagePoolList.size(), + logger.debug(String.format("%s is returning [%s] suitable storage pools [%s].", this.getClass().getSimpleName(), storagePoolList.size(), Arrays.toString(storagePoolList.toArray()))); } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java index 9c0f84ab14a..a52372fb3ca 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ClusterScopeStoragePoolAllocator.java @@ -26,7 +26,6 @@ import javax.naming.ConfigurationException; import com.cloud.storage.VolumeApiServiceImpl; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.deploy.DeploymentPlan; @@ -40,13 +39,12 @@ import com.cloud.vm.VirtualMachineProfile; @Component public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocator { - private static final Logger s_logger = Logger.getLogger(ClusterScopeStoragePoolAllocator.class); @Inject DiskOfferingDao _diskOfferingDao; @Override - protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) { + protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) { logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck); if (!bypassStorageTypeCheck && dskCh.useLocalStorage()) { @@ -64,35 +62,35 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat // clusterId == null here because it will break ClusterWide primary // storage volume operation where // only podId is passed into this call. - s_logger.debug("ClusterScopeStoragePoolAllocator is returning null since the pod ID is null. This may be a zone wide storage."); + logger.debug("ClusterScopeStoragePoolAllocator is returning null since the pod ID is null. This may be a zone wide storage."); return null; } if (dskCh.getTags() != null && dskCh.getTags().length != 0) { - s_logger.debug(String.format("Looking for pools in dc [%s], pod [%s], cluster [%s], and having tags [%s]. Disabled pools will be ignored.", dcId, podId, clusterId, + logger.debug(String.format("Looking for pools in dc [%s], pod [%s], cluster [%s], and having tags [%s]. Disabled pools will be ignored.", dcId, podId, clusterId, Arrays.toString(dskCh.getTags()))); } else { - s_logger.debug(String.format("Looking for pools in dc [%s], pod [%s] and cluster [%s]. Disabled pools will be ignored.", dcId, podId, clusterId)); + logger.debug(String.format("Looking for pools in dc [%s], pod [%s] and cluster [%s]. Disabled pools will be ignored.", dcId, podId, clusterId)); } - if (s_logger.isTraceEnabled()) { + if (logger.isTraceEnabled()) { // Log the pools details that are ignored because they are in disabled state logDisabledStoragePools(dcId, podId, clusterId, ScopeType.CLUSTER); } List pools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags(), true, VolumeApiServiceImpl.storageTagRuleExecutionTimeout.value()); pools.addAll(storagePoolJoinDao.findStoragePoolByScopeAndRuleTags(dcId, podId, clusterId, ScopeType.CLUSTER, List.of(dskCh.getTags()))); - s_logger.debug(String.format("Found pools [%s] that match with tags [%s].", pools, Arrays.toString(dskCh.getTags()))); + logger.debug(String.format("Found pools [%s] that match with tags [%s].", pools, Arrays.toString(dskCh.getTags()))); // add remaining pools in cluster, that did not match tags, to avoid set List allPools = storagePoolDao.findPoolsByTags(dcId, podId, clusterId, null, false, 0); allPools.removeAll(pools); for (StoragePoolVO pool : allPools) { - s_logger.trace(String.format("Adding pool [%s] to the 'avoid' set since it did not match any tags.", pool)); + logger.trace(String.format("Adding pool [%s] to the 'avoid' set since it did not match any tags.", pool)); avoid.addPool(pool.getId()); } if (pools.size() == 0) { - s_logger.debug(String.format("No storage pools available for [%s] volume allocation.", ServiceOffering.StorageType.shared)); + logger.debug(String.format("No storage pools available for [%s] volume allocation.", ServiceOffering.StorageType.shared)); return suitablePools; } @@ -102,10 +100,10 @@ public class ClusterScopeStoragePoolAllocator extends AbstractStoragePoolAllocat } StoragePool storagePool = (StoragePool)dataStoreMgr.getPrimaryDataStore(pool.getId()); if (filter(avoid, storagePool, dskCh, plan)) { - s_logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); + logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); suitablePools.add(storagePool); } else { - s_logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); + logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); avoid.addPool(pool.getId()); } } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java index 3fa69499ff1..39c29bd2c6e 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/GarbageCollectingStoragePoolAllocator.java @@ -22,7 +22,6 @@ import java.util.Map; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; @@ -36,7 +35,6 @@ import com.cloud.vm.DiskProfile; import com.cloud.vm.VirtualMachineProfile; public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAllocator { - private static final Logger s_logger = Logger.getLogger(GarbageCollectingStoragePoolAllocator.class); StoragePoolAllocator _firstFitStoragePoolAllocator; StoragePoolAllocator _localStoragePoolAllocator; @@ -47,10 +45,10 @@ public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAl boolean _storagePoolCleanupEnabled; @Override - public List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) { + public List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) { logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck); if (!_storagePoolCleanupEnabled) { - s_logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped."); + logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped."); return null; } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java index 4ec15b9e43f..b8dcfb0ba7b 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java @@ -26,7 +26,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.capacity.dao.CapacityDao; @@ -44,7 +43,6 @@ import com.cloud.vm.dao.VMInstanceDao; @Component public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator { - private static final Logger s_logger = Logger.getLogger(LocalStoragePoolAllocator.class); @Inject StoragePoolHostDao _poolHostDao; @@ -60,15 +58,15 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator { ConfigurationDao _configDao; @Override - protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) { + protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) { logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck); if (!bypassStorageTypeCheck && !dskCh.useLocalStorage()) { - s_logger.debug("LocalStoragePoolAllocator is returning null since the disk profile does not use local storage and bypassStorageTypeCheck is false."); + logger.debug("LocalStoragePoolAllocator is returning null since the disk profile does not use local storage and bypassStorageTypeCheck is false."); return null; } - if (s_logger.isTraceEnabled()) { + if (logger.isTraceEnabled()) { // Log the pools details that are ignored because they are in disabled state logDisabledStoragePools(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), ScopeType.HOST); } @@ -82,10 +80,10 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator { if (pool != null && pool.isLocal()) { StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId()); if (filter(avoid, storagePool, dskCh, plan)) { - s_logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); + logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); suitablePools.add(storagePool); } else { - s_logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); + logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); avoid.addPool(pool.getId()); } } @@ -97,11 +95,11 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator { } else { if (plan.getPodId() == null) { // zone wide primary storage deployment - s_logger.debug("LocalStoragePoolAllocator is returning null since both the host ID and pod ID are null. That means this should be a zone wide primary storage deployment."); + logger.debug("LocalStoragePoolAllocator is returning null since both the host ID and pod ID are null. That means this should be a zone wide primary storage deployment."); return null; } List availablePools = - storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), dskCh.getTags(), true); + storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), dskCh.getTags(), true, keyword); availablePools.addAll(storagePoolJoinDao.findStoragePoolByScopeAndRuleTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), ScopeType.HOST, List.of(dskCh.getTags()))); for (StoragePoolVO pool : availablePools) { if (suitablePools.size() == returnUpTo) { @@ -109,10 +107,10 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator { } StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId()); if (filter(avoid, storagePool, dskCh, plan)) { - s_logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); + logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", pool, dskCh)); suitablePools.add(storagePool); } else { - s_logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); + logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", pool, dskCh)); avoid.addPool(pool.getId()); } } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java index ba130b4e2e5..0c59cf24fc5 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java @@ -24,7 +24,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; @@ -43,21 +42,20 @@ import com.cloud.vm.VirtualMachineProfile; @Component public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator { - private static final Logger LOGGER = Logger.getLogger(ZoneWideStoragePoolAllocator.class); @Inject private DataStoreManager dataStoreMgr; @Inject private CapacityDao capacityDao; @Override - protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) { + protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) { logStartOfSearch(dskCh, vmProfile, plan, returnUpTo, bypassStorageTypeCheck); if (!bypassStorageTypeCheck && dskCh.useLocalStorage()) { return null; } - if (LOGGER.isTraceEnabled()) { + if (logger.isTraceEnabled()) { // Log the pools details that are ignored because they are in disabled state logDisabledStoragePools(plan.getDataCenterId(), null, null, ScopeType.ZONE); } @@ -66,7 +64,7 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator { List storagePools = storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags(), true); storagePools.addAll(storagePoolJoinDao.findStoragePoolByScopeAndRuleTags(plan.getDataCenterId(), null, null, ScopeType.ZONE, List.of(dskCh.getTags()))); if (storagePools.isEmpty()) { - LOGGER.debug(String.format("Could not find any zone wide storage pool that matched with any of the following tags [%s].", Arrays.toString(dskCh.getTags()))); + logger.debug(String.format("Could not find any zone wide storage pool that matched with any of the following tags [%s].", Arrays.toString(dskCh.getTags()))); storagePools = new ArrayList<>(); } @@ -94,11 +92,11 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator { } StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(storage.getId()); if (filter(avoid, storagePool, dskCh, plan)) { - LOGGER.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", storagePool, dskCh)); + logger.debug(String.format("Found suitable local storage pool [%s] to allocate disk [%s] to it, adding to list.", storagePool, dskCh)); suitablePools.add(storagePool); } else { if (canAddStoragePoolToAvoidSet(storage)) { - LOGGER.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", storagePool, dskCh)); + logger.debug(String.format("Adding storage pool [%s] to avoid set during allocation of disk [%s].", storagePool, dskCh)); avoid.addPool(storagePool.getId()); } } @@ -125,8 +123,8 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator { } List poolIdsByCapacity = capacityDao.orderHostsByFreeCapacity(zoneId, null, capacityType); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("List of zone-wide storage pools in descending order of free capacity: "+ poolIdsByCapacity); + if (logger.isDebugEnabled()) { + logger.debug("List of zone-wide storage pools in descending order of free capacity: "+ poolIdsByCapacity); } //now filter the given list of Pools by this ordered list @@ -154,8 +152,8 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator { long dcId = plan.getDataCenterId(); List poolIdsByVolCount = volumeDao.listZoneWidePoolIdsByVolumeCount(dcId, account.getAccountId()); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("List of pools in ascending order of number of volumes for account id: " + account.getAccountId() + " is: " + poolIdsByVolCount); + if (logger.isDebugEnabled()) { + logger.debug("List of pools in ascending order of number of volumes for account id: " + account.getAccountId() + " is: " + poolIdsByVolCount); } // now filter the given list of Pools by this ordered list diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java index 460f869bebf..7c1cbb55b3b 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java @@ -20,7 +20,8 @@ package org.apache.cloudstack.storage.datastore; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; @@ -42,7 +43,7 @@ import com.cloud.utils.fsm.NoTransitionException; @Component public class DataObjectManagerImpl implements DataObjectManager { - private static final Logger s_logger = Logger.getLogger(DataObjectManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject ObjectInDataStoreManager objectInDataStoreMgr; @Inject @@ -57,13 +58,13 @@ public class DataObjectManagerImpl implements DataObjectManager { try { Thread.sleep(waitingTime); } catch (InterruptedException e) { - s_logger.debug("sleep interrupted", e); + logger.debug("sleep interrupted", e); throw new CloudRuntimeException("sleep interrupted", e); } obj = objectInDataStoreMgr.findObject(dataObj, dataStore); if (obj == null) { - s_logger.debug("can't find object in db, maybe it's cleaned up already, exit waiting"); + logger.debug("can't find object in db, maybe it's cleaned up already, exit waiting"); break; } if (obj.getState() == ObjectInDataStoreStateMachine.State.Ready) { @@ -73,7 +74,7 @@ public class DataObjectManagerImpl implements DataObjectManager { } while (retries > 0); if (obj == null || retries <= 0) { - s_logger.debug("waiting too long for template downloading, marked it as failed"); + logger.debug("waiting too long for template downloading, marked it as failed"); throw new CloudRuntimeException("waiting too long for template downloading, marked it as failed"); } return objectInDataStoreMgr.get(dataObj, dataStore, null); @@ -138,7 +139,7 @@ public class DataObjectManagerImpl implements DataObjectManager { try { objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("state transaction failed", e1); + logger.debug("state transaction failed", e1); } CreateCmdResult result = new CreateCmdResult(null, null); result.setSuccess(false); @@ -149,7 +150,7 @@ public class DataObjectManagerImpl implements DataObjectManager { try { objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("state transaction failed", e1); + logger.debug("state transaction failed", e1); } CreateCmdResult result = new CreateCmdResult(null, null); result.setSuccess(false); @@ -182,7 +183,7 @@ public class DataObjectManagerImpl implements DataObjectManager { try { objectInDataStoreMgr.update(objInStrore, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("failed to change state", e1); + logger.debug("failed to change state", e1); } upResult.setResult(e.toString()); @@ -192,7 +193,7 @@ public class DataObjectManagerImpl implements DataObjectManager { try { objectInDataStoreMgr.update(objInStrore, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("failed to change state", e1); + logger.debug("failed to change state", e1); } upResult.setResult(e.toString()); @@ -220,21 +221,21 @@ public class DataObjectManagerImpl implements DataObjectManager { try { objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.CopyingRequested); } catch (NoTransitionException e) { - s_logger.debug("failed to change state", e); + logger.debug("failed to change state", e); try { objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("failed to further change state to OperationFailed", e1); + logger.debug("failed to further change state to OperationFailed", e1); } CreateCmdResult res = new CreateCmdResult(null, null); res.setResult("Failed to change state: " + e.toString()); callback.complete(res); } catch (ConcurrentOperationException e) { - s_logger.debug("failed to change state", e); + logger.debug("failed to change state", e); try { objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("failed to further change state to OperationFailed", e1); + logger.debug("failed to further change state to OperationFailed", e1); } CreateCmdResult res = new CreateCmdResult(null, null); res.setResult("Failed to change state: " + e.toString()); @@ -256,9 +257,9 @@ public class DataObjectManagerImpl implements DataObjectManager { try { objectInDataStoreMgr.update(destObj, Event.OperationFailed); } catch (NoTransitionException e) { - s_logger.debug("Failed to update copying state", e); + logger.debug("Failed to update copying state", e); } catch (ConcurrentOperationException e) { - s_logger.debug("Failed to update copying state", e); + logger.debug("Failed to update copying state", e); } CreateCmdResult res = new CreateCmdResult(null, null); res.setResult(result.getResult()); @@ -268,21 +269,21 @@ public class DataObjectManagerImpl implements DataObjectManager { try { objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationSuccessed); } catch (NoTransitionException e) { - s_logger.debug("Failed to update copying state: ", e); + logger.debug("Failed to update copying state: ", e); try { objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("failed to further change state to OperationFailed", e1); + logger.debug("failed to further change state to OperationFailed", e1); } CreateCmdResult res = new CreateCmdResult(null, null); res.setResult("Failed to update copying state: " + e.toString()); context.getParentCallback().complete(res); } catch (ConcurrentOperationException e) { - s_logger.debug("Failed to update copying state: ", e); + logger.debug("Failed to update copying state: ", e); try { objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationFailed); } catch (Exception e1) { - s_logger.debug("failed to further change state to OperationFailed", e1); + logger.debug("failed to further change state to OperationFailed", e1); } CreateCmdResult res = new CreateCmdResult(null, null); res.setResult("Failed to update copying state: " + e.toString()); @@ -308,11 +309,11 @@ public class DataObjectManagerImpl implements DataObjectManager { try { objectInDataStoreMgr.update(data, Event.DestroyRequested); } catch (NoTransitionException e) { - s_logger.debug("destroy failed", e); + logger.debug("destroy failed", e); CreateCmdResult res = new CreateCmdResult(null, null); callback.complete(res); } catch (ConcurrentOperationException e) { - s_logger.debug("destroy failed", e); + logger.debug("destroy failed", e); CreateCmdResult res = new CreateCmdResult(null, null); callback.complete(res); } @@ -333,18 +334,18 @@ public class DataObjectManagerImpl implements DataObjectManager { try { objectInDataStoreMgr.update(destObj, Event.OperationFailed); } catch (NoTransitionException e) { - s_logger.debug("delete failed", e); + logger.debug("delete failed", e); } catch (ConcurrentOperationException e) { - s_logger.debug("delete failed", e); + logger.debug("delete failed", e); } } else { try { objectInDataStoreMgr.update(destObj, Event.OperationSuccessed); } catch (NoTransitionException e) { - s_logger.debug("delete failed", e); + logger.debug("delete failed", e); } catch (ConcurrentOperationException e) { - s_logger.debug("delete failed", e); + logger.debug("delete failed", e); } } @@ -366,10 +367,10 @@ public class DataObjectManagerImpl implements DataObjectManager { objectInDataStoreMgr.update(objInStore, ObjectInDataStoreStateMachine.Event.OperationSuccessed); } catch (NoTransitionException e) { - s_logger.debug("Failed to update state", e); + logger.debug("Failed to update state", e); throw new CloudRuntimeException("Failed to update state", e); } catch (ConcurrentOperationException e) { - s_logger.debug("Failed to update state", e); + logger.debug("Failed to update state", e); throw new CloudRuntimeException("Failed to update state", e); } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java index 3059018f8ee..570a47a752c 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java @@ -18,7 +18,8 @@ package org.apache.cloudstack.storage.datastore; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; @@ -58,7 +59,7 @@ import com.cloud.utils.fsm.StateMachine2; @Component public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { - private static final Logger s_logger = Logger.getLogger(ObjectInDataStoreManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject TemplateDataFactory imageFactory; @Inject @@ -136,7 +137,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { if (parentSnap != null) { ss.setParentSnapshotId(snapshotDataStoreVO.getSnapshotId()); } else { - s_logger.debug("find inconsistent db for snapshot " + snapshotDataStoreVO.getSnapshotId()); + logger.debug("find inconsistent db for snapshot " + snapshotDataStoreVO.getSnapshotId()); } } ss.setState(ObjectInDataStoreStateMachine.State.Allocated); @@ -210,7 +211,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { if (destTmpltPool != null) { return templatePoolDao.remove(destTmpltPool.getId()); } else { - s_logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete"); + logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete"); return true; } } @@ -222,7 +223,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { if (destTmpltStore != null) { return templateDataStoreDao.remove(destTmpltStore.getId()); } else { - s_logger.warn("Template " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); + logger.warn("Template " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); return true; } case SNAPSHOT: @@ -230,7 +231,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { if (destSnapshotStore != null) { return snapshotDataStoreDao.remove(destSnapshotStore.getId()); } else { - s_logger.warn("Snapshot " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); + logger.warn("Snapshot " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); return true; } case VOLUME: @@ -238,13 +239,13 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { if (destVolumeStore != null) { return volumeDataStoreDao.remove(destVolumeStore.getId()); } else { - s_logger.warn("Volume " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); + logger.warn("Volume " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); return true; } } } - s_logger.warn("Unsupported data object (" + dataObj.getType() + ", " + dataObj.getDataStore() + ")"); + logger.warn("Unsupported data object (" + dataObj.getType() + ", " + dataObj.getDataStore() + ")"); return false; } @@ -258,7 +259,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { if (destTmpltPool != null && destTmpltPool.getState() != ObjectInDataStoreStateMachine.State.Ready) { return templatePoolDao.remove(destTmpltPool.getId()); } else { - s_logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete"); + logger.warn("Template " + objId + " is not found on storage pool " + dataStore.getId() + ", so no need to delete"); return true; } } else if (dataObj.getType() == DataObjectType.SNAPSHOT) { @@ -278,7 +279,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { if (destSnapshotStore != null && destSnapshotStore.getState() != ObjectInDataStoreStateMachine.State.Ready) { return snapshotDataStoreDao.remove(destSnapshotStore.getId()); } else { - s_logger.warn("Snapshot " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); + logger.warn("Snapshot " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); return true; } case VOLUME: @@ -286,13 +287,13 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { if (destVolumeStore != null && destVolumeStore.getState() != ObjectInDataStoreStateMachine.State.Ready) { return volumeDataStoreDao.remove(destVolumeStore.getId()); } else { - s_logger.warn("Volume " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); + logger.warn("Volume " + objId + " is not found on image store " + dataStore.getId() + ", so no need to delete"); return true; } } } - s_logger.warn("Unsupported data object (" + dataObj.getType() + ", " + dataObj.getDataStore() + "), no need to delete from object in store ref table"); + logger.warn("Unsupported data object (" + dataObj.getType() + ", " + dataObj.getDataStore() + "), no need to delete from object in store ref table"); return false; } @@ -374,7 +375,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager { } else if (type == DataObjectType.SNAPSHOT && role == DataStoreRole.Primary) { vo = snapshotDataStoreDao.findByStoreSnapshot(role, dataStoreId, objId); } else { - s_logger.debug("Invalid data or store type: " + type + " " + role); + logger.debug("Invalid data or store type: " + type + " " + role); throw new CloudRuntimeException("Invalid data or store type: " + type + " " + role); } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java index 35e758accca..665dd81888f 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java @@ -32,7 +32,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.storage.object.ObjectStoreDriver; import org.apache.cloudstack.storage.object.datastore.ObjectStoreProviderManager; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.api.response.StorageProviderResponse; @@ -50,7 +49,6 @@ import com.cloud.utils.component.Registry; @Component public class DataStoreProviderManagerImpl extends ManagerBase implements DataStoreProviderManager, Registry { - private static final Logger s_logger = Logger.getLogger(DataStoreProviderManagerImpl.class); List providers; protected Map providerMap = new ConcurrentHashMap(); @@ -127,18 +125,18 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto String providerName = provider.getName(); if (providerMap.get(providerName) != null) { - s_logger.debug("Did not register data store provider, provider name: " + providerName + " is not unique"); + logger.debug("Did not register data store provider, provider name: " + providerName + " is not unique"); return false; } - s_logger.debug("registering data store provider:" + provider.getName()); + logger.debug("registering data store provider:" + provider.getName()); providerMap.put(providerName, provider); try { boolean registrationResult = provider.configure(copyParams); if (!registrationResult) { providerMap.remove(providerName); - s_logger.debug("Failed to register data store provider: " + providerName); + logger.debug("Failed to register data store provider: " + providerName); return false; } @@ -152,7 +150,7 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto objectStoreProviderMgr.registerDriver(provider.getName(), (ObjectStoreDriver)provider.getDataStoreDriver()); } } catch (Exception e) { - s_logger.debug("configure provider failed", e); + logger.debug("configure provider failed", e); providerMap.remove(providerName); return false; } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/db/ObjectInDataStoreDaoImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/db/ObjectInDataStoreDaoImpl.java index a492e76b991..4b13c100a44 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/db/ObjectInDataStoreDaoImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/db/ObjectInDataStoreDaoImpl.java @@ -21,7 +21,6 @@ import java.util.Map; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; @@ -36,7 +35,6 @@ import com.cloud.utils.db.UpdateBuilder; @Component public class ObjectInDataStoreDaoImpl extends GenericDaoBase implements ObjectInDataStoreDao { - private static final Logger s_logger = Logger.getLogger(ObjectInDataStoreDaoImpl.class); private SearchBuilder updateStateSearch; @Override @@ -69,7 +67,7 @@ public class ObjectInDataStoreDaoImpl extends GenericDaoBase 0; diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java index bc16bafd7a9..e6fac9a4063 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java @@ -46,7 +46,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.storage.LocalHostEndpoint; import org.apache.cloudstack.storage.RemoteHostEndPoint; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.capacity.CapacityManager; @@ -69,7 +70,7 @@ import static com.cloud.host.Host.HOST_VOLUME_ENCRYPTION; @Component public class DefaultEndPointSelector implements EndPointSelector { - private static final Logger s_logger = Logger.getLogger(DefaultEndPointSelector.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private HostDao hostDao; @Inject @@ -174,10 +175,10 @@ public class DefaultEndPointSelector implements EndPointSelector { host = hostDao.findById(id); } } catch (SQLException e) { - s_logger.warn("can't find endpoint", e); + logger.warn("can't find endpoint", e); } } catch (SQLException e) { - s_logger.warn("can't find endpoint", e); + logger.warn("can't find endpoint", e); } if (host == null) { return null; @@ -298,7 +299,7 @@ public class DefaultEndPointSelector implements EndPointSelector { @Override public EndPoint select(DataObject srcData, DataObject destData, StorageAction action, boolean encryptionRequired) { - s_logger.error("IR24 select BACKUPSNAPSHOT from primary to secondary " + srcData.getId() + " dest=" + destData.getId()); + logger.error("IR24 select BACKUPSNAPSHOT from primary to secondary " + srcData.getId() + " dest=" + destData.getId()); if (action == StorageAction.BACKUPSNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) { SnapshotInfo srcSnapshot = (SnapshotInfo)srcData; VolumeInfo volumeInfo = srcSnapshot.getBaseVolume(); @@ -424,11 +425,11 @@ public class DefaultEndPointSelector implements EndPointSelector { } } catch (URISyntaxException e) { - s_logger.debug("Received URISyntaxException for url" +downloadUrl); + logger.debug("Received URISyntaxException for url" +downloadUrl); } // If ssvm doesn't exist then find any ssvm in the zone. - s_logger.debug("Couldn't find ssvm for url" +downloadUrl); + logger.debug("Couldn't find ssvm for url" +downloadUrl); return findEndpointForImageStorage(store); } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java index 9b7007dc4d6..10af5d55d61 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java @@ -23,7 +23,8 @@ import java.util.UUID; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; @@ -56,7 +57,7 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.snapshot.VMSnapshot; public class HypervisorHelperImpl implements HypervisorHelper { - private static final Logger s_logger = Logger.getLogger(HypervisorHelperImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject EndPointSelector selector; @Inject @@ -79,7 +80,7 @@ public class HypervisorHelperImpl implements HypervisorHelper { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -99,7 +100,7 @@ public class HypervisorHelperImpl implements HypervisorHelper { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -107,7 +108,7 @@ public class HypervisorHelperImpl implements HypervisorHelper { if (answer == null || !answer.getResult()) { String errMsg = answer == null ? null : answer.getDetails(); if (errMsg != null) { - s_logger.debug("Failed to forget object: " + errMsg); + logger.debug("Failed to forget object: " + errMsg); } return false; } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java index 369630a1a73..9606da1e337 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java @@ -55,7 +55,8 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.endpoint.DefaultEndPointSelector; import org.apache.cloudstack.storage.image.deployasis.DeployAsIsHelper; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -93,7 +94,7 @@ import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.SecondaryStorageVmDao; public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { - private static final Logger LOGGER = Logger.getLogger(BaseImageStoreDriverImpl.class); + protected Logger logger = LogManager.getLogger(BaseImageStoreDriverImpl.class); @Inject protected VMTemplateDao _templateDao; @@ -179,20 +180,20 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { caller.setContext(context); if (data.getType() == DataObjectType.TEMPLATE) { caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null)); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Downloading template to data store " + dataStore.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Downloading template to data store " + dataStore.getId()); } _downloadMonitor.downloadTemplateToStorage(data, caller); } else if (data.getType() == DataObjectType.VOLUME) { caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null)); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Downloading volume to data store " + dataStore.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Downloading volume to data store " + dataStore.getId()); } _downloadMonitor.downloadVolumeToStorage(data, caller); } else if (data.getType() == DataObjectType.SNAPSHOT) { caller.setCallback(caller.getTarget().createSnapshotAsyncCallback(null, null)); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Downloading volume to data store " + dataStore.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Downloading volume to data store " + dataStore.getId()); } _downloadMonitor.downloadSnapshotToStorage(data, caller); } @@ -200,8 +201,8 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher callback, CreateContext context) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Performing image store createTemplate async callback"); + if (logger.isDebugEnabled()) { + logger.debug("Performing image store createTemplate async callback"); } DownloadAnswer answer = callback.getResult(); DataObject obj = context.data; @@ -215,16 +216,16 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { OVFInformationTO ovfInformationTO = answer.getOvfInformationTO(); boolean persistDeployAsIs = deployAsIsHelper.persistTemplateOVFInformationAndUpdateGuestOS(template.getId(), ovfInformationTO, tmpltStoreVO); if (!persistDeployAsIs) { - LOGGER.info("Failed persisting deploy-as-is template details for template " + template.getName()); + logger.info("Failed persisting deploy-as-is template details for template " + template.getName()); return null; } } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer"); + if (logger.isDebugEnabled()) { + logger.debug("Template is already in DOWNLOADED state, ignore further incoming DownloadAnswer"); } return null; } - LOGGER.info("Updating store ref entry for template " + template.getName()); + logger.info("Updating store ref entry for template " + template.getName()); TemplateDataStoreVO updateBuilder = _templateStoreDao.createForUpdate(); updateBuilder.setDownloadPercent(answer.getDownloadPct()); updateBuilder.setDownloadState(answer.getDownloadStatus()); @@ -252,7 +253,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { caller.complete(result); String msg = "Failed to register template: " + obj.getUuid() + " with error: " + answer.getErrorString(); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, _vmTemplateZoneDao.listByTemplateId(obj.getId()).get(0).getZoneId(), null, msg, msg); - LOGGER.error(msg); + logger.error(msg); } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { if (answer.getCheckSum() != null) { VMTemplateVO templateDaoBuilder = _templateDao.createForUpdate(); @@ -275,8 +276,8 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId()); if (volStoreVO != null) { if (volStoreVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Volume is already in DOWNLOADED state, ignore further incoming DownloadAnswer"); + if (logger.isDebugEnabled()) { + logger.debug("Volume is already in DOWNLOADED state, ignore further incoming DownloadAnswer"); } return null; } @@ -308,7 +309,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { String msg = "Failed to upload volume: " + obj.getUuid() + " with error: " + answer.getErrorString(); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, (volStoreVO == null ? -1L : volStoreVO.getZoneId()), null, msg, msg); - LOGGER.error(msg); + logger.error(msg); } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { CreateCmdResult result = new CreateCmdResult(null, null); caller.complete(result); @@ -324,8 +325,8 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { SnapshotDataStoreVO snapshotStoreVO = snapshotDataStoreDao.findByStoreSnapshot(DataStoreRole.Image, store.getId(), obj.getId()); if (snapshotStoreVO != null) { if (VMTemplateStorageResourceAssoc.Status.DOWNLOADED.equals(snapshotStoreVO.getDownloadState())) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Snapshot is already in DOWNLOADED state, ignore further incoming DownloadAnswer"); + if (logger.isDebugEnabled()) { + logger.debug("Snapshot is already in DOWNLOADED state, ignore further incoming DownloadAnswer"); } return null; } @@ -355,7 +356,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { Long zoneId = dataStoreManager.getStoreZoneId(store.getId(), store.getRole()); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, zoneId, null, msg, msg); - LOGGER.error(msg); + logger.error(msg); } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { CreateCmdResult result = new CreateCmdResult(null, null); caller.complete(result); @@ -372,7 +373,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -381,7 +382,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { result.setResult(answer.getDetails()); } } catch (Exception ex) { - LOGGER.debug("Unable to destroy " + data.getType().toString() + ": " + data.getId(), ex); + logger.debug("Unable to destroy " + data.getType().toString() + ": " + data.getId(), ex); result.setResult(ex.toString()); } callback.complete(result); @@ -405,7 +406,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { List eps = _epSelector.findAllEndpointsForScope(srcdata.getDataStore()); if (eps == null || eps.isEmpty()) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { // select endpoint with least number of commands running on them @@ -447,10 +448,10 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { return answer; } catch (AgentUnavailableException e) { errMsg = e.toString(); - LOGGER.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString()); + logger.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString()); } catch (OperationTimedoutException e) { errMsg = e.toString(); - LOGGER.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString()); + logger.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString()); } throw new CloudRuntimeException("Failed to send command, due to Agent:" + endPoint.getId() + ", " + errMsg); } @@ -480,8 +481,8 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { @Override public List getDataDiskTemplates(DataObject obj, String configurationId) { List dataDiskDetails = new ArrayList(); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Get the data disks present in the OVA template"); + if (logger.isDebugEnabled()) { + logger.debug("Get the data disks present in the OVA template"); } DataStore store = obj.getDataStore(); GetDatadisksCommand cmd = new GetDatadisksCommand(obj.getTO(), configurationId); @@ -489,7 +490,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -508,14 +509,14 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { public Void createDataDiskTemplateAsync(TemplateInfo dataDiskTemplate, String path, String diskId, boolean bootable, long fileSize, AsyncCompletionCallback callback) { Answer answer = null; String errMsg = null; - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Create Datadisk template: " + dataDiskTemplate.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Create Datadisk template: " + dataDiskTemplate.getId()); } CreateDatadiskTemplateCommand cmd = new CreateDatadiskTemplateCommand(dataDiskTemplate.getTO(), path, diskId, fileSize, bootable); EndPoint ep = _defaultEpSelector.select(dataDiskTemplate.getDataStore()); if (ep == null) { errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - LOGGER.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -534,7 +535,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { } private List ssvmWithLeastMigrateJobs() { - LOGGER.debug("Picking ssvm from the pool with least commands running on it"); + logger.debug("Picking ssvm from the pool with least commands running on it"); String query = "select host_id, count(*) from cmd_exec_log group by host_id order by 2;"; TransactionLegacy txn = TransactionLegacy.currentTxn(); @@ -547,7 +548,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { result.add((long) rs.getInt(1)); } } catch (SQLException e) { - LOGGER.debug("SQLException caught", e); + logger.debug("SQLException caught", e); } return result; } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java index cb14506ad17..aceab450678 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java @@ -28,7 +28,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -58,7 +57,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class TemplateDataStoreDaoImpl extends GenericDaoBase implements TemplateDataStoreDao { - private static final Logger s_logger = Logger.getLogger(TemplateDataStoreDaoImpl.class); private SearchBuilder updateStateSearch; private SearchBuilder storeSearch; private SearchBuilder cacheSearch; @@ -199,7 +197,7 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase 0; @@ -494,7 +492,7 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase tmpls = listBy(sc); // create an entry for each template record, but with empty install path since the content is not yet on region-wide store yet if (tmpls != null) { - s_logger.info("Duplicate " + tmpls.size() + " template cache store records to region store"); + logger.info("Duplicate " + tmpls.size() + " template cache store records to region store"); for (TemplateDataStoreVO tmpl : tmpls) { long templateId = tmpl.getTemplateId(); VMTemplateVO template = _tmpltDao.findById(templateId); @@ -502,15 +500,15 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase tmpls = listBy(sc); if (tmpls != null) { - s_logger.info("Update to cache store role for " + tmpls.size() + " entries in template_store_ref"); + logger.info("Update to cache store role for " + tmpls.size() + " entries in template_store_ref"); for (TemplateDataStoreVO tmpl : tmpls) { tmpl.setDataStoreRole(DataStoreRole.ImageCache); update(tmpl.getId(), tmpl); @@ -605,7 +603,7 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase implements VolumeDataStoreDao { - private static final Logger s_logger = Logger.getLogger(VolumeDataStoreDaoImpl.class); private SearchBuilder updateStateSearch; private SearchBuilder volumeSearch; private SearchBuilder storeSearch; @@ -150,7 +148,7 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase 0; @@ -296,14 +294,14 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase guestOsMappings = guestOSHypervisorDao.listByOsNameAndHypervisorMinimumVersion(guestOsType, hypervisor.toString(), minimumHypervisorVersion); if (CollectionUtils.isNotEmpty(guestOsMappings)) { - if (LOGGER.isDebugEnabled()) { + if (logger.isDebugEnabled()) { String msg = String.format("number of hypervisor mappings for guest os \"%s\" is: %d", guestOsType, guestOsMappings.size()); - LOGGER.debug(msg); + logger.debug(msg); } Long guestOsId = null; if (guestOsMappings.size() == 1) { @@ -207,7 +208,7 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { String minimumHardwareVersion) { Long guestOsId = retrieveTemplateGuestOsIdFromGuestOsInfo(templateId, guestOsType, guestOsDescription, minimumHardwareVersion); if (guestOsId != null) { - LOGGER.info("Updating deploy-as-is template guest OS to " + guestOsType); + logger.info("Updating deploy-as-is template guest OS to " + guestOsType); VMTemplateVO template = templateDao.findById(templateId); updateTemplateGuestOsId(template, guestOsId); } @@ -223,7 +224,7 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { Hypervisor.HypervisorType hypervisor, Collection hypervisorVersions) { GuestOSVO newGuestOs = createGuestOsEntry(guestOsDescription); for (String hypervisorVersion : hypervisorVersions) { - LOGGER.info(String.format("Adding a new guest OS mapping for hypervisor: %s version: %s and " + + logger.info(String.format("Adding a new guest OS mapping for hypervisor: %s version: %s and " + "guest OS: %s", hypervisor.toString(), hypervisorVersion, guestOsType)); createGuestOsHypervisorMapping(newGuestOs.getId(), guestOsType, hypervisor.toString(), hypervisorVersion); } @@ -278,7 +279,7 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { hypervisorVersion = "6.7"; } } catch (NumberFormatException e) { - LOGGER.error("Cannot parse hardware version " + hwVersion + " to integer. Using default hypervisor version", e); + logger.error("Cannot parse hardware version " + hwVersion + " to integer. Using default hypervisor version", e); } return hypervisorVersion; } @@ -332,7 +333,7 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { if (ArrayUtils.isNotEmpty(nics)) { if (nics.length != networks.size()) { String msg = "Different number of networks provided vs networks defined in deploy-as-is template"; - LOGGER.error(msg); + logger.error(msg); return map; } for (int i = 0; i < nics.length; i++) { @@ -347,16 +348,16 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { List informationTOList) { for (TemplateDeployAsIsInformationTO informationTO : informationTOList) { String propKey = getKeyFromInformationTO(informationTO); - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Saving property %s for template %d as detail", propKey, templateId)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Saving property %s for template %d as detail", propKey, templateId)); } String propValue = null; try { propValue = getValueFromInformationTO(informationTO); } catch (RuntimeException re) { - LOGGER.error("gson marshalling of property object fails: " + propKey,re); + logger.error("gson marshalling of property object fails: " + propKey,re); } catch (IOException e) { - LOGGER.error("Could not decompress the license for template " + templateId, e); + logger.error("Could not decompress the license for template " + templateId, e); } saveTemplateDeployAsIsPropertyAttribute(templateId, propKey, propValue); } @@ -391,18 +392,18 @@ public class DeployAsIsHelperImpl implements DeployAsIsHelper { } private void saveTemplateDeployAsIsPropertyAttribute(long templateId, String key, String value) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Saving property %s for template %d as detail", key, templateId)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Saving property %s for template %d as detail", key, templateId)); } if (templateDeployAsIsDetailsDao.findDetail(templateId,key) != null) { - LOGGER.debug(String.format("Detail '%s' existed for template %d, deleting.", key, templateId)); + logger.debug(String.format("Detail '%s' existed for template %d, deleting.", key, templateId)); templateDeployAsIsDetailsDao.removeDetail(templateId,key); } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Template detail for template %d to save is '%s': '%s'", templateId, key, value)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Template detail for template %d to save is '%s': '%s'", templateId, key, value)); } TemplateDeployAsIsDetailVO detailVO = new TemplateDeployAsIsDetailVO(templateId, key, value); - LOGGER.debug("Persisting template details " + detailVO.getName() + " from OVF properties for template " + templateId); + logger.debug("Persisting template details " + detailVO.getName() + " from OVF properties for template " + templateId); templateDeployAsIsDetailsDao.persist(detailVO); } diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/object/BaseObjectStoreDriverImpl.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/object/BaseObjectStoreDriverImpl.java index e6027a1959f..8d45c959b59 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/object/BaseObjectStoreDriverImpl.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/object/BaseObjectStoreDriverImpl.java @@ -27,12 +27,13 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.async.AsyncRpcContext; import org.apache.cloudstack.storage.command.CommandResult; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Map; public abstract class BaseObjectStoreDriverImpl implements ObjectStoreDriver { - private static final Logger LOGGER = Logger.getLogger(BaseObjectStoreDriverImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Override public Map getCapabilities() { diff --git a/engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java b/engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java index fbb4a6e1618..8044a2dfa5e 100644 --- a/engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java +++ b/engine/storage/src/main/java/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java @@ -28,7 +28,8 @@ import javax.inject.Inject; import org.apache.cloudstack.annotation.AnnotationService; import org.apache.cloudstack.annotation.dao.AnnotationDao; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; @@ -57,7 +58,7 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class PrimaryDataStoreHelper { - private static final Logger s_logger = Logger.getLogger(PrimaryDataStoreHelper.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private PrimaryDataStoreDao dataStoreDao; @Inject @@ -108,7 +109,7 @@ public class PrimaryDataStoreHelper { if (user == null || password == null) { String errMsg = "Missing cifs user and password details. Add them as details parameter."; - s_logger.warn(errMsg); + logger.warn(errMsg); throw new InvalidParameterValueException(errMsg); } else { try { @@ -261,7 +262,7 @@ public class PrimaryDataStoreHelper { this._capacityDao.removeBy(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, null, null, null, poolVO.getId()); txn.commit(); - s_logger.debug("Storage pool id=" + poolVO.getId() + " is removed successfully"); + logger.debug("Storage pool id=" + poolVO.getId() + " is removed successfully"); return true; } diff --git a/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java b/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java index 493ea089ef4..ae25017db31 100644 --- a/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java +++ b/engine/storage/src/test/java/org/apache/cloudstack/engine/subsystem/api/storage/StrategyPriorityTest.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.engine.subsystem.api.storage; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; diff --git a/engine/storage/src/test/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocatorTest.java b/engine/storage/src/test/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocatorTest.java index 58b6fc99a59..cddbc9e93cb 100644 --- a/engine/storage/src/test/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocatorTest.java +++ b/engine/storage/src/test/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocatorTest.java @@ -17,13 +17,13 @@ package org.apache.cloudstack.storage.allocator; -import com.cloud.deploy.DeploymentPlan; -import com.cloud.deploy.DeploymentPlanner; -import com.cloud.storage.Storage; -import com.cloud.storage.StoragePool; -import com.cloud.user.Account; -import com.cloud.vm.DiskProfile; -import com.cloud.vm.VirtualMachineProfile; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.junit.After; import org.junit.Assert; @@ -34,10 +34,14 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import com.cloud.deploy.DeploymentPlan; +import com.cloud.deploy.DeploymentPlanner; +import com.cloud.storage.Storage; +import com.cloud.storage.StoragePool; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.user.Account; +import com.cloud.vm.DiskProfile; +import com.cloud.vm.VirtualMachineProfile; @RunWith(MockitoJUnitRunner.class) public class AbstractStoragePoolAllocatorTest { @@ -51,6 +55,9 @@ public class AbstractStoragePoolAllocatorTest { Account account; private List pools; + @Mock + VolumeDao volumeDao; + @Before public void setUp() { pools = new ArrayList<>(); @@ -83,6 +90,29 @@ public class AbstractStoragePoolAllocatorTest { Mockito.verify(allocator, Mockito.times(0)).reorderRandomPools(pools); } + @Test + public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() { + allocator.allocationAlgorithm = "userdispersing"; + allocator.volumeDao = volumeDao; + + when(plan.getDataCenterId()).thenReturn(1l); + when(plan.getPodId()).thenReturn(1l); + when(plan.getClusterId()).thenReturn(1l); + when(account.getAccountId()).thenReturn(1l); + List poolIds = new ArrayList<>(); + poolIds.add(1l); + poolIds.add(9l); + when(volumeDao.listPoolIdsByVolumeCount(1l,1l,1l,1l)).thenReturn(poolIds); + + List reorderedPools = allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account); + Assert.assertEquals(poolIds.size(),reorderedPools.size()); + + Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByCapacity(plan, pools); + Mockito.verify(allocator, Mockito.times(1)).reorderPoolsByNumberOfVolumes(plan, pools, account); + Mockito.verify(allocator, Mockito.times(0)).reorderRandomPools(pools); + Mockito.verify(volumeDao, Mockito.times(1)).listPoolIdsByVolumeCount(1l,1l,1l,1l); + } + @Test public void reorderStoragePoolsBasedOnAlgorithm_firstfitleastconsumed() { allocator.allocationAlgorithm = "firstfitleastconsumed"; @@ -107,7 +137,7 @@ public class AbstractStoragePoolAllocatorTest { class MockStorapoolAllocater extends AbstractStoragePoolAllocator { @Override - protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, DeploymentPlanner.ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) { + protected List select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, DeploymentPlanner.ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck, String keyword) { return null; } } diff --git a/engine/storage/volume/pom.xml b/engine/storage/volume/pom.xml index acaa38c94c7..a00c3314126 100644 --- a/engine/storage/volume/pom.xml +++ b/engine/storage/volume/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java index e392c2615f1..7f373fa9988 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/PrimaryDataStoreImpl.java @@ -47,7 +47,8 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.volume.VolumeObject; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.to.DataObjectType; import com.cloud.agent.api.to.DataStoreTO; @@ -69,7 +70,7 @@ import com.cloud.utils.storage.encoding.EncodingType; @SuppressWarnings("serial") public class PrimaryDataStoreImpl implements PrimaryDataStore { - private static final Logger s_logger = Logger.getLogger(PrimaryDataStoreImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); protected PrimaryDataStoreDriver driver; protected StoragePoolVO pdsv; @@ -186,7 +187,7 @@ public class PrimaryDataStoreImpl implements PrimaryDataStore { if (poolHosts.size() > 0) { return new HostScope(poolHosts.get(0).getHostId(), vo.getClusterId(), vo.getDataCenterId()); } - s_logger.debug("can't find a local storage in pool host table: " + vo.getId()); + logger.debug("can't find a local storage in pool host table: " + vo.getId()); } return null; } @@ -296,29 +297,29 @@ public class PrimaryDataStoreImpl implements PrimaryDataStore { VMTemplateStoragePoolVO templateStoragePoolRef; GlobalLock lock = GlobalLock.getInternLock(templateIdPoolIdString); if (!lock.lock(5)) { - s_logger.debug("Couldn't lock the db on the string " + templateIdPoolIdString); + logger.debug("Couldn't lock the db on the string " + templateIdPoolIdString); return null; } try { templateStoragePoolRef = templatePoolDao.findByPoolTemplate(getId(), obj.getId(), configuration); if (templateStoragePoolRef == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Not found (" + templateIdPoolIdString + ") in template_spool_ref, persisting it"); + if (logger.isDebugEnabled()) { + logger.debug("Not found (" + templateIdPoolIdString + ") in template_spool_ref, persisting it"); } templateStoragePoolRef = new VMTemplateStoragePoolVO(getId(), obj.getId(), configuration); templateStoragePoolRef = templatePoolDao.persist(templateStoragePoolRef); } } catch (Throwable t) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Failed to insert (" + templateIdPoolIdString + ") to template_spool_ref", t); + if (logger.isDebugEnabled()) { + logger.debug("Failed to insert (" + templateIdPoolIdString + ") to template_spool_ref", t); } templateStoragePoolRef = templatePoolDao.findByPoolTemplate(getId(), obj.getId(), configuration); if (templateStoragePoolRef == null) { throw new CloudRuntimeException("Failed to create template storage pool entry"); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Another thread already inserts " + templateStoragePoolRef.getId() + " to template_spool_ref", t); + if (logger.isDebugEnabled()) { + logger.debug("Another thread already inserts " + templateStoragePoolRef.getId() + " to template_spool_ref", t); } } } finally { @@ -326,7 +327,7 @@ public class PrimaryDataStoreImpl implements PrimaryDataStore { lock.releaseRef(); } } catch (Exception e) { - s_logger.debug("Caught exception ", e); + logger.debug("Caught exception ", e); } } else if (obj.getType() == DataObjectType.SNAPSHOT) { return objectInStoreMgr.create(obj, this); diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java index e344a87831d..b8f90e46538 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java @@ -50,13 +50,20 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import javax.inject.Inject; import java.util.List; public class DefaultHostListener implements HypervisorHostListener { - private static final Logger s_logger = Logger.getLogger(DefaultHostListener.class); + protected Logger logger = LogManager.getLogger(getClass()); + + /** + * Wait time for modify storage pool command to complete. We should wait for 5 minutes for the command to complete. + * This should ideally be externalised as a global configuration parameter in the future (See #8506). + **/ + private final int modifyStoragePoolCommandWait = 300; // 5 minutes @Inject AgentManager agentMgr; @Inject @@ -84,7 +91,6 @@ public class DefaultHostListener implements HypervisorHostListener { @Inject NetworkDao networkDao; - @Override public boolean hostAdded(long hostId) { return true; @@ -93,7 +99,7 @@ public class DefaultHostListener implements HypervisorHostListener { private boolean createPersistentNetworkResourcesOnHost(long hostId) { HostVO host = hostDao.findById(hostId); if (host == null) { - s_logger.warn(String.format("Host with id %ld can't be found", hostId)); + logger.warn(String.format("Host with id %ld can't be found", hostId)); return false; } setupPersistentNetwork(host); @@ -121,6 +127,9 @@ public class DefaultHostListener implements HypervisorHostListener { public boolean hostConnect(long hostId, long poolId) throws StorageConflictException { StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary); ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool); + cmd.setWait(modifyStoragePoolCommandWait); + logger.debug(String.format("Sending modify storage pool command to agent: %d for storage pool: %d with timeout %d seconds", + hostId, poolId, cmd.getWait())); final Answer answer = agentMgr.easySend(hostId, cmd); if (answer == null) { @@ -142,7 +151,7 @@ public class DefaultHostListener implements HypervisorHostListener { List localStoragePools = this.primaryStoreDao.listLocalStoragePoolByPath(pool.getDataCenterId(), datastoreName); for (StoragePoolVO localStoragePool : localStoragePools) { if (datastoreName.equals(localStoragePool.getPath())) { - s_logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName()); + logger.warn("Storage pool: " + pool.getId() + " has already been added as local storage: " + localStoragePool.getName()); throw new StorageConflictException("Cannot add shared storage pool: " + pool.getId() + " because it has already been added as local storage:" + localStoragePool.getName()); } @@ -158,7 +167,7 @@ public class DefaultHostListener implements HypervisorHostListener { storageService.updateStorageCapabilities(poolId, false); - s_logger.info("Connection established between storage pool " + pool + " and host " + hostId); + logger.info("Connection established between storage pool " + pool + " and host " + hostId); return createPersistentNetworkResourcesOnHost(hostId); } @@ -196,7 +205,7 @@ public class DefaultHostListener implements HypervisorHostListener { // send host the cleanup persistent network resources HostVO host = hostDao.findById(hostId); if (host == null) { - s_logger.warn("Host with id " + hostId + " can't be found"); + logger.warn("Host with id " + hostId + " can't be found"); return false; } @@ -207,12 +216,12 @@ public class DefaultHostListener implements HypervisorHostListener { new CleanupPersistentNetworkResourceCommand(createNicTOFromNetworkAndOffering(persistentNetworkVO, networkOfferingVO, host)); Answer answer = agentMgr.easySend(hostId, cleanupCmd); if (answer == null) { - s_logger.error("Unable to get answer to the cleanup persistent network command " + persistentNetworkVO.getId()); + logger.error("Unable to get answer to the cleanup persistent network command " + persistentNetworkVO.getId()); continue; } if (!answer.getResult()) { String msg = String.format("Unable to cleanup persistent network resources from network %d on the host %d", persistentNetworkVO.getId(), hostId); - s_logger.error(msg); + logger.error(msg); } } return true; @@ -227,7 +236,7 @@ public class DefaultHostListener implements HypervisorHostListener { public boolean hostEnabled(long hostId) { HostVO host = hostDao.findById(hostId); if (host == null) { - s_logger.warn(String.format("Host with id %d can't be found", hostId)); + logger.warn(String.format("Host with id %d can't be found", hostId)); return false; } setupPersistentNetwork(host); @@ -247,7 +256,7 @@ public class DefaultHostListener implements HypervisorHostListener { } if (!answer.getResult()) { String msg = String.format("Unable to create persistent network resources for network %d on the host %d in zone %d", networkVO.getId(), host.getId(), networkVO.getDataCenterId()); - s_logger.error(msg); + logger.error(msg); } } } diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java index 5ebee87acd4..1b3bec0e907 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeObject.java @@ -23,6 +23,7 @@ import javax.inject.Inject; import com.cloud.configuration.Resource.ResourceType; import com.cloud.dc.VsphereStoragePolicyVO; import com.cloud.dc.dao.VsphereStoragePolicyDao; +import com.cloud.storage.StorageManager; import com.cloud.utils.db.Transaction; import com.cloud.utils.db.TransactionCallbackNoReturn; import com.cloud.utils.db.TransactionStatus; @@ -50,7 +51,8 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.DownloadAnswer; @@ -84,7 +86,7 @@ import java.util.function.Function; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; public class VolumeObject implements VolumeInfo { - private static final Logger s_logger = Logger.getLogger(VolumeObject.class); + protected Logger logger = LogManager.getLogger(getClass()); protected VolumeVO volumeVO; private StateMachine2 _volStateMachine; protected DataStore dataStore; @@ -117,6 +119,7 @@ public class VolumeObject implements VolumeInfo { private MigrationOptions migrationOptions; private boolean directDownload; private String vSphereStoragePolicyId; + private boolean followRedirects; private final List volumeStatesThatShouldNotTransitWhenDataStoreRoleIsImage = Arrays.asList(Volume.State.Migrating, Volume.State.Uploaded, Volume.State.Copying, Volume.State.Expunged); @@ -127,6 +130,7 @@ public class VolumeObject implements VolumeInfo { public VolumeObject() { _volStateMachine = Volume.State.getStateMachine(); + this.followRedirects = StorageManager.DataStoreDownloadFollowRedirects.value(); } protected void configure(DataStore dataStore, VolumeVO volumeVO) { @@ -231,7 +235,7 @@ public class VolumeObject implements VolumeInfo { } } catch (NoTransitionException e) { String errorMessage = String.format("Failed to transit volume %s to [%s] due to [%s].", volumeVO.getVolumeDescription(), event, e.getMessage()); - s_logger.warn(errorMessage, e); + logger.warn(errorMessage, e); throw new CloudRuntimeException(errorMessage, e); } return result; @@ -442,7 +446,7 @@ public class VolumeObject implements VolumeInfo { } catch (ConcurrentOperationException | NoTransitionException e) { String message = String.format("Failed to update %sto state [%s] due to [%s].", volumeVO == null ? "" : String.format("volume %s ", volumeVO.getVolumeDescription()), getMapOfEvents().get(event), e.getMessage()); - s_logger.warn(message, e); + logger.warn(message, e); throw new CloudRuntimeException(message, e); } finally { expungeEntryOnOperationFailed(event, callExpungeEntry); @@ -688,7 +692,7 @@ public class VolumeObject implements VolumeInfo { volumeDao.update(volumeVo.getId(), volumeVo); String newValues = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volumeVo, "path", "size", "format", "encryptFormat", "poolId"); - s_logger.debug(String.format("Updated %s from %s to %s ", volumeVo.getVolumeDescription(), previousValues, newValues)); + logger.debug(String.format("Updated %s from %s to %s ", volumeVo.getVolumeDescription(), previousValues, newValues)); } protected void updateResourceCount(VolumeObjectTO newVolume, VolumeVO oldVolume) { @@ -722,7 +726,7 @@ public class VolumeObject implements VolumeInfo { volumeStoreDao.update(volStore.getId(), volStore); String newValues = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volStore, "installPath", "size"); - s_logger.debug(String.format("Updated volume_store_ref %s from %s to %s.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volStore, "id", "volumeId"), + logger.debug(String.format("Updated volume_store_ref %s from %s to %s.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volStore, "id", "volumeId"), previousValues, newValues)); } @@ -754,7 +758,7 @@ public class VolumeObject implements VolumeInfo { volumeStoreDao.update(volumeDataStoreVo.getId(), volumeDataStoreVo); String newValues = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(volumeDataStoreVo, "installPath", "checksum"); - s_logger.debug(String.format("Updated volume_store_ref %s from %s to %s.", ReflectionToStringBuilderUtils. + logger.debug(String.format("Updated volume_store_ref %s from %s to %s.", ReflectionToStringBuilderUtils. reflectOnlySelectedFields(volumeDataStoreVo, "id", "volumeId"), previousValues, newValues)); } @Override @@ -851,7 +855,7 @@ public class VolumeObject implements VolumeInfo { @Override public boolean delete() { - return dataStore == null ? true : dataStore.delete(this); + return dataStore == null || dataStore.delete(this); } @Override @@ -896,15 +900,15 @@ public class VolumeObject implements VolumeInfo { volumeVO.setPassphraseId(null); volumeDao.persist(volumeVO); - s_logger.debug(String.format("Checking to see if we can delete passphrase id %s", passphraseId)); + logger.debug(String.format("Checking to see if we can delete passphrase id %s", passphraseId)); List volumes = volumeDao.listVolumesByPassphraseId(passphraseId); if (volumes != null && !volumes.isEmpty()) { - s_logger.debug("Other volumes use this passphrase, skipping deletion"); + logger.debug("Other volumes use this passphrase, skipping deletion"); return; } - s_logger.debug(String.format("Deleting passphrase %s", passphraseId)); + logger.debug(String.format("Deleting passphrase %s", passphraseId)); passphraseDao.remove(passphraseId); } } @@ -930,4 +934,9 @@ public class VolumeObject implements VolumeInfo { public void setEncryptFormat(String encryptFormat) { volumeVO.setEncryptFormat(encryptFormat); } + + @Override + public boolean isFollowRedirects() { + return followRedirects; + } } diff --git a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index c0ef227251c..49f7abccda5 100644 --- a/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -32,12 +32,10 @@ import java.util.concurrent.ExecutionException; import javax.inject.Inject; -import org.apache.cloudstack.secret.dao.PassphraseDao; -import com.cloud.storage.VMTemplateVO; -import com.cloud.storage.dao.VMTemplateDao; -import com.cloud.storage.resource.StorageProcessor; +import com.cloud.storage.VolumeApiServiceImpl; import org.apache.cloudstack.annotation.AnnotationService; import org.apache.cloudstack.annotation.dao.AnnotationDao; +import org.apache.cloudstack.api.command.user.volume.CheckAndRepairVolumeCmd; import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity; import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService; import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo; @@ -66,6 +64,7 @@ import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.async.AsyncRpcContext; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; +import org.apache.cloudstack.secret.dao.PassphraseDao; import org.apache.cloudstack.storage.RemoteHostEndPoint; import org.apache.cloudstack.storage.command.CommandResult; import org.apache.cloudstack.storage.command.CopyCmdAnswer; @@ -83,15 +82,21 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.image.store.TemplateObject; import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; import com.cloud.agent.api.ModifyTargetsCommand; +import com.cloud.agent.api.storage.CheckAndRepairVolumeAnswer; +import com.cloud.agent.api.storage.CheckAndRepairVolumeCommand; import com.cloud.agent.api.storage.ListVolumeAnswer; import com.cloud.agent.api.storage.ListVolumeCommand; import com.cloud.agent.api.storage.ResizeVolumeCommand; +import com.cloud.agent.api.to.DataObjectType; import com.cloud.agent.api.to.StorageFilerTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.alert.AlertManager; @@ -112,6 +117,7 @@ import com.cloud.org.Cluster; import com.cloud.org.Grouping.AllocationState; import com.cloud.resource.ResourceState; import com.cloud.server.ManagementService; +import com.cloud.storage.CheckAndRepairVolumePayload; import com.cloud.storage.DataStoreRole; import com.cloud.storage.RegisterVolumePayload; import com.cloud.storage.ScopeType; @@ -122,13 +128,17 @@ import com.cloud.storage.StoragePool; import com.cloud.storage.VMTemplateStoragePoolVO; import com.cloud.storage.VMTemplateStorageResourceAssoc; import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; +import com.cloud.storage.VMTemplateVO; import com.cloud.storage.Volume; import com.cloud.storage.Volume.State; import com.cloud.storage.VolumeDetailVO; import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.DiskOfferingDao; +import com.cloud.storage.dao.VMTemplateDao; import com.cloud.storage.dao.VMTemplatePoolDao; import com.cloud.storage.dao.VolumeDao; import com.cloud.storage.dao.VolumeDetailsDao; +import com.cloud.storage.resource.StorageProcessor; import com.cloud.storage.snapshot.SnapshotApiService; import com.cloud.storage.snapshot.SnapshotManager; import com.cloud.storage.template.TemplateConstants; @@ -142,11 +152,10 @@ import com.cloud.utils.db.DB; import com.cloud.utils.db.GlobalLock; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine; -import org.apache.commons.lang3.StringUtils; @Component public class VolumeServiceImpl implements VolumeService { - private static final Logger s_logger = Logger.getLogger(VolumeServiceImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject protected AgentManager agentMgr; @Inject @@ -198,15 +207,15 @@ public class VolumeServiceImpl implements VolumeService { @Inject private VolumeOrchestrationService _volumeMgr; @Inject - private StorageManager _storageMgr; + protected StorageManager _storageMgr; @Inject private AnnotationDao annotationDao; @Inject private SnapshotApiService snapshotApiService; @Inject private PassphraseDao passphraseDao; - - private final static String SNAPSHOT_ID = "SNAPSHOT_ID"; + @Inject + private DiskOfferingDao diskOfferingDao; public VolumeServiceImpl() { } @@ -266,6 +275,19 @@ public class VolumeServiceImpl implements VolumeService { } } + @Override + public boolean requiresAccessForMigration(DataObject dataObject, DataStore dataStore) { + DataStoreDriver dataStoreDriver = dataStore != null ? dataStore.getDriver() : null; + if (dataStoreDriver == null) { + return false; + } + + if (dataStoreDriver instanceof PrimaryDataStoreDriver) { + return ((PrimaryDataStoreDriver)dataStoreDriver).requiresAccessForMigration(dataObject); + } + return false; + } + @Override public AsyncCallFuture createVolumeAsync(VolumeInfo volume, DataStore dataStore) { AsyncCallFuture future = new AsyncCallFuture(); @@ -352,9 +374,9 @@ public class VolumeServiceImpl implements VolumeService { AsyncCallFuture future = new AsyncCallFuture(); VolumeApiResult result = new VolumeApiResult(volume); if (volume.getDataStore() == null) { - s_logger.info("Expunge volume with no data store specified"); + logger.info("Expunge volume with no data store specified"); if (canVolumeBeRemoved(volume.getId())) { - s_logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table"); + logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table"); volDao.remove(volume.getId()); } future.complete(result); @@ -366,7 +388,7 @@ public class VolumeServiceImpl implements VolumeService { if (volumeStore != null) { if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) { String msg = "Volume: " + volume.getName() + " is currently being uploaded; can't delete it."; - s_logger.debug(msg); + logger.debug(msg); result.setSuccess(false); result.setResult(msg); future.complete(result); @@ -376,7 +398,7 @@ public class VolumeServiceImpl implements VolumeService { VolumeVO vol = volDao.findById(volume.getId()); if (vol == null) { - s_logger.debug("Volume " + volume.getId() + " is not found"); + logger.debug("Volume " + volume.getId() + " is not found"); future.complete(result); return future; } @@ -385,8 +407,8 @@ public class VolumeServiceImpl implements VolumeService { // not created on primary store if (volumeStore == null) { // also not created on secondary store - if (s_logger.isDebugEnabled()) { - s_logger.debug("Marking volume that was never created as destroyed: " + vol); + if (logger.isDebugEnabled()) { + logger.debug("Marking volume that was never created as destroyed: " + vol); } VMTemplateVO template = templateDao.findById(vol.getTemplateId()); if (template != null && !template.isDeployAsIs()) { @@ -460,7 +482,7 @@ public class VolumeServiceImpl implements VolumeService { } if (canVolumeBeRemoved(vo.getId())) { - s_logger.info("Volume " + vo.getId() + " is not referred anywhere, remove it from volumes table"); + logger.info("Volume " + vo.getId() + " is not referred anywhere, remove it from volumes table"); volDao.remove(vo.getId()); } @@ -490,7 +512,7 @@ public class VolumeServiceImpl implements VolumeService { apiResult.setResult(result.getResult()); } } catch (Exception e) { - s_logger.debug("ignore delete volume status update failure, it will be picked up by storage clean up thread later", e); + logger.debug("ignore delete volume status update failure, it will be picked up by storage clean up thread later", e); } context.getFuture().complete(apiResult); return null; @@ -593,7 +615,7 @@ public class VolumeServiceImpl implements VolumeService { try { Thread.sleep(sleepTime * 1000); } catch (InterruptedException e) { - s_logger.debug("waiting for template download been interrupted: " + e.toString()); + logger.debug("waiting for template download been interrupted: " + e.toString()); } tries--; } @@ -609,8 +631,8 @@ public class VolumeServiceImpl implements VolumeService { if (templatePoolRef == null) { throw new CloudRuntimeException("Failed to find template " + template.getUniqueName() + " in storage pool " + dataStore.getId()); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found template " + template.getUniqueName() + " in storage pool " + dataStore.getId() + " with VMTemplateStoragePool id: " + templatePoolRef.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Found template " + template.getUniqueName() + " in storage pool " + dataStore.getId() + " with VMTemplateStoragePool id: " + templatePoolRef.getId()); } } long templatePoolRefId = templatePoolRef.getId(); @@ -619,18 +641,18 @@ public class VolumeServiceImpl implements VolumeService { caller.setCallback(caller.getTarget().copyBaseImageCallback(null, null)).setContext(context); int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds"); + if (logger.isDebugEnabled()) { + logger.debug("Acquire lock on VMTemplateStoragePool " + templatePoolRefId + " with timeout " + storagePoolMaxWaitSeconds + " seconds"); } templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, storagePoolMaxWaitSeconds); if (templatePoolRef == null) { - if (s_logger.isDebugEnabled()) { - s_logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId); + if (logger.isDebugEnabled()) { + logger.info("Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId); } templatePoolRef = _tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId(), deployAsIsConfiguration); if (templatePoolRef != null && templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) { - s_logger.info( + logger.info( "Unable to acquire lock on VMTemplateStoragePool " + templatePoolRefId + ", But Template " + template.getUniqueName() + " is already copied to primary storage, skip copying"); createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future); return; @@ -638,27 +660,27 @@ public class VolumeServiceImpl implements VolumeService { throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + templatePoolRefId); } - if (s_logger.isDebugEnabled()) { - s_logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId); + if (logger.isDebugEnabled()) { + logger.info("lock is acquired for VMTemplateStoragePool " + templatePoolRefId); } try { if (templatePoolRef.getState() == ObjectInDataStoreStateMachine.State.Ready) { - s_logger.info("Template " + template.getUniqueName() + " is already copied to primary storage, skip copying"); + logger.info("Template " + template.getUniqueName() + " is already copied to primary storage, skip copying"); createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, dataStore, future); return; } templateOnPrimaryStoreObj.processEvent(Event.CreateOnlyRequested); motionSrv.copyAsync(template, templateOnPrimaryStoreObj, caller); } catch (Throwable e) { - s_logger.debug("failed to create template on storage", e); + logger.debug("failed to create template on storage", e); templateOnPrimaryStoreObj.processEvent(Event.OperationFailed); dataStore.create(template, deployAsIsConfiguration); // make sure that template_spool_ref entry is still present so that the second thread can acquire the lock VolumeApiResult result = new VolumeApiResult(volume); result.setResult(e.toString()); future.complete(result); } finally { - if (s_logger.isDebugEnabled()) { - s_logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId); + if (logger.isDebugEnabled()) { + logger.info("releasing lock for VMTemplateStoragePool " + templatePoolRefId); } _tmpltPoolDao.releaseFromLockTable(templatePoolRefId); } @@ -813,14 +835,14 @@ public class VolumeServiceImpl implements VolumeService { Answer ans = result.getAnswer(); if (ans instanceof CopyCmdAnswer && ans.getDetails().contains(StorageProcessor.REQUEST_TEMPLATE_RELOAD)) { if (tmplOnPrimary != null) { - s_logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try"); + logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try"); VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(tmplOnPrimary.getDataStore().getId(), tmplOnPrimary.getId(), deployAsIsConfiguration); if (templatePoolRef != null) { long templatePoolRefId = templatePoolRef.getId(); templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, 1200); try { if (templatePoolRef == null) { - s_logger.warn("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId); + logger.warn("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId); } else { templatePoolRef.setTemplateSize(0); templatePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED); @@ -865,7 +887,7 @@ public class VolumeServiceImpl implements VolumeService { try { destroyAndReallocateManagedVolume((VolumeInfo) vo); } catch (CloudRuntimeException ex) { - s_logger.warn("Couldn't destroy managed volume: " + vo.getId()); + logger.warn("Couldn't destroy managed volume: " + vo.getId()); } } @@ -925,7 +947,7 @@ public class VolumeServiceImpl implements VolumeService { templateOnPrimary.processEvent(Event.OperationSuccessed); } catch (Throwable e) { - s_logger.debug("Failed to create template volume on storage", e); + logger.debug("Failed to create template volume on storage", e); templateOnPrimary.processEvent(Event.OperationFailed); throw new CloudRuntimeException(e.getMessage()); } finally { @@ -973,7 +995,7 @@ public class VolumeServiceImpl implements VolumeService { if (templatePoolRef.getDownloadState() == Status.DOWNLOADED) { // There can be cases where we acquired the lock, but the template // was already copied by a previous thread. Just return in that case. - s_logger.debug("Template already downloaded, nothing to do"); + logger.debug("Template already downloaded, nothing to do"); return; } @@ -1044,7 +1066,7 @@ public class VolumeServiceImpl implements VolumeService { } catch (StorageAccessException e) { throw e; } catch (Throwable e) { - s_logger.debug("Failed to create a template on primary storage", e); + logger.debug("Failed to create a template on primary storage", e); templateOnPrimary.processEvent(Event.OperationFailed); @@ -1071,11 +1093,11 @@ public class VolumeServiceImpl implements VolumeService { if (answer == null) { String msg = "Unable to get an answer to the modify targets command"; - s_logger.warn(msg); + logger.warn(msg); } else if (!answer.getResult()) { String msg = "Unable to modify target on the following host: " + hostId; - s_logger.warn(msg); + logger.warn(msg); } } @@ -1111,7 +1133,7 @@ public class VolumeServiceImpl implements VolumeService { motionSrv.copyAsync(templateOnPrimary, volumeInfo, caller); } catch (Throwable e) { - s_logger.debug("Failed to clone template on primary storage", e); + logger.debug("Failed to clone template on primary storage", e); volumeInfo.processEvent(Event.OperationFailed); @@ -1179,13 +1201,13 @@ public class VolumeServiceImpl implements VolumeService { } catch (StorageAccessException e) { throw e; } catch (Throwable e) { - s_logger.debug("Failed to copy managed template on primary storage", e); + logger.debug("Failed to copy managed template on primary storage", e); String errMsg = "Failed due to " + e.toString(); try { destroyAndReallocateManagedVolume(volumeInfo); } catch (CloudRuntimeException ex) { - s_logger.warn("Failed to destroy managed volume: " + volumeInfo.getId()); + logger.warn("Failed to destroy managed volume: " + volumeInfo.getId()); errMsg += " : " + ex.getMessage(); } @@ -1222,20 +1244,20 @@ public class VolumeServiceImpl implements VolumeService { VolumeVO newVolume = (VolumeVO) newVol; newVolume.set_iScsiName(null); volDao.update(newVolume.getId(), newVolume); - s_logger.debug("Allocated new volume: " + newVolume.getId() + " for the VM: " + volume.getInstanceId()); + logger.debug("Allocated new volume: " + newVolume.getId() + " for the VM: " + volume.getInstanceId()); try { AsyncCallFuture expungeVolumeFuture = expungeVolumeAsync(volumeInfo); VolumeApiResult expungeVolumeResult = expungeVolumeFuture.get(); if (expungeVolumeResult.isFailed()) { - s_logger.warn("Failed to expunge volume: " + volumeInfo.getId() + " that was created"); + logger.warn("Failed to expunge volume: " + volumeInfo.getId() + " that was created"); throw new CloudRuntimeException("Failed to expunge volume: " + volumeInfo.getId() + " that was created"); } } catch (Exception ex) { if (canVolumeBeRemoved(volumeInfo.getId())) { volDao.remove(volumeInfo.getId()); } - s_logger.warn("Unable to expunge volume: " + volumeInfo.getId() + " due to: " + ex.getMessage()); + logger.warn("Unable to expunge volume: " + volumeInfo.getId() + " due to: " + ex.getMessage()); throw new CloudRuntimeException("Unable to expunge volume: " + volumeInfo.getId() + " due to: " + ex.getMessage()); } } @@ -1342,7 +1364,7 @@ public class VolumeServiceImpl implements VolumeService { int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); if (!lock.lock(storagePoolMaxWaitSeconds)) { - s_logger.debug("Unable to create managed storage template, couldn't lock on " + templateIdManagedPoolIdLockString); + logger.debug("Unable to create managed storage template, couldn't lock on " + templateIdManagedPoolIdLockString); throw new CloudRuntimeException("Unable to create managed storage template, couldn't lock on " + templateIdManagedPoolIdLockString); } @@ -1390,7 +1412,7 @@ public class VolumeServiceImpl implements VolumeService { //Download and copy template to the managed volume TemplateInfo templateOnPrimaryNow = tmplFactory.getReadyBypassedTemplateOnManagedStorage(srcTemplateId, templateOnPrimary, destDataStoreId, destHostId); if (templateOnPrimaryNow == null) { - s_logger.debug("Failed to prepare ready bypassed template: " + srcTemplateId + " on primary storage: " + templateOnPrimary.getId()); + logger.debug("Failed to prepare ready bypassed template: " + srcTemplateId + " on primary storage: " + templateOnPrimary.getId()); throw new CloudRuntimeException("Failed to prepare ready bypassed template: " + srcTemplateId + " on primary storage: " + templateOnPrimary.getId()); } templateOnPrimary.processEvent(Event.OperationSuccessed); @@ -1403,7 +1425,7 @@ public class VolumeServiceImpl implements VolumeService { } catch (StorageAccessException e) { throw e; } catch (Throwable e) { - s_logger.debug("Failed to create template on managed primary storage", e); + logger.debug("Failed to create template on managed primary storage", e); if (templateOnPrimary != null) { templateOnPrimary.processEvent(Event.OperationFailed); } @@ -1433,7 +1455,7 @@ public class VolumeServiceImpl implements VolumeService { AsyncCallFuture future = new AsyncCallFuture<>(); if (storageCanCloneVolume && computeSupportsVolumeClone) { - s_logger.debug("Storage " + destDataStoreId + " can support cloning using a cached template and compute side is OK with volume cloning."); + logger.debug("Storage " + destDataStoreId + " can support cloning using a cached template and compute side is OK with volume cloning."); GlobalLock lock = null; TemplateInfo templateOnPrimary = null; @@ -1447,7 +1469,7 @@ public class VolumeServiceImpl implements VolumeService { int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); if (!lock.lock(storagePoolMaxWaitSeconds)) { - s_logger.debug("Unable to create managed storage template/volume, couldn't lock on " + tmplIdManagedPoolIdLockString); + logger.debug("Unable to create managed storage template/volume, couldn't lock on " + tmplIdManagedPoolIdLockString); throw new CloudRuntimeException("Unable to create managed storage template/volume, couldn't lock on " + tmplIdManagedPoolIdLockString); } @@ -1479,7 +1501,7 @@ public class VolumeServiceImpl implements VolumeService { result.setResult(e.getLocalizedMessage()); result.setSuccess(false); future.complete(result); - s_logger.warn("Failed to create template on primary storage", e); + logger.warn("Failed to create template on primary storage", e); return future; } finally { if (lock != null) { @@ -1490,7 +1512,7 @@ public class VolumeServiceImpl implements VolumeService { if (destPrimaryDataStore.getPoolType() != StoragePoolType.PowerFlex) { // We have a template on primary storage. Clone it to new volume. - s_logger.debug("Creating a clone from template on primary storage " + destDataStoreId); + logger.debug("Creating a clone from template on primary storage " + destDataStoreId); createManagedVolumeCloneTemplateAsync(volumeInfo, templateOnPrimary, destPrimaryDataStore, future); } else { @@ -1499,7 +1521,7 @@ public class VolumeServiceImpl implements VolumeService { destHost, future, destDataStoreId, srcTemplateInfo.getId()); } } else { - s_logger.debug("Primary storage does not support cloning or no support for UUID resigning on the host side; copying the template normally"); + logger.debug("Primary storage does not support cloning or no support for UUID resigning on the host side; copying the template normally"); createManagedVolumeCopyTemplateAsync(volumeInfo, destPrimaryDataStore, srcTemplateInfo, destHost, future); } @@ -1519,11 +1541,11 @@ public class VolumeServiceImpl implements VolumeService { int storagePoolMaxWaitSeconds = NumbersUtil.parseInt(configDao.getValue(Config.StoragePoolMaxWaitSeconds.key()), 3600); if (!lock.lock(storagePoolMaxWaitSeconds)) { - s_logger.debug("Unable to create volume from template, couldn't lock on " + tmplIdManagedPoolIdDestinationHostLockString); + logger.debug("Unable to create volume from template, couldn't lock on " + tmplIdManagedPoolIdDestinationHostLockString); throw new CloudRuntimeException("Unable to create volume from template, couldn't lock on " + tmplIdManagedPoolIdDestinationHostLockString); } - s_logger.debug("Copying the template to the volume on primary storage"); + logger.debug("Copying the template to the volume on primary storage"); createManagedVolumeCopyManagedTemplateAsync(volumeInfo, destPrimaryDataStore, templateOnPrimary, destHost, future); } finally { if (lock != null) { @@ -1611,8 +1633,7 @@ public class VolumeServiceImpl implements VolumeService { if (vol.getAttachedVM() == null || vol.getAttachedVM().getType() == VirtualMachine.Type.User) { // Decrement the resource count for volumes and primary storage belonging user VM's only - _resourceLimitMgr.decrementResourceCount(vol.getAccountId(), ResourceType.volume, vol.isDisplay()); - _resourceLimitMgr.decrementResourceCount(vol.getAccountId(), ResourceType.primary_storage, vol.isDisplay(), new Long(vol.getSize())); + _resourceLimitMgr.decrementVolumeResourceCount(vol.getAccountId(), vol.isDisplay(), vol.getSize(), diskOfferingDao.findById(vol.getDiskOfferingId())); } } @@ -1630,7 +1651,7 @@ public class VolumeServiceImpl implements VolumeService { caller.setCallback(caller.getTarget().createVolumeFromSnapshotCallback(null, null)).setContext(context); motionSrv.copyAsync(snapshot, volumeOnStore, caller); } catch (Exception e) { - s_logger.debug("create volume from snapshot failed", e); + logger.debug("create volume from snapshot failed", e); VolumeApiResult result = new VolumeApiResult(volume); result.setResult(e.toString()); future.complete(result); @@ -1661,7 +1682,7 @@ public class VolumeServiceImpl implements VolumeService { _volumeDetailsDao.removeDetail(volume.getId(), SNAPSHOT_ID); } catch (Exception e) { - s_logger.debug("create volume from snapshot failed", e); + logger.debug("create volume from snapshot failed", e); apiResult.setResult(e.toString()); } @@ -1727,7 +1748,7 @@ public class VolumeServiceImpl implements VolumeService { motionSrv.copyAsync(srcVolume, destVolume, caller); return future; } catch (Exception e) { - s_logger.error("failed to copy volume from image store", e); + logger.error("failed to copy volume from image store", e); if (destVolume != null) { destVolume.processEvent(Event.OperationFailed); } @@ -1781,7 +1802,7 @@ public class VolumeServiceImpl implements VolumeService { motionSrv.copyAsync(srcVolume, destVolume, caller); return future; } catch (Exception e) { - s_logger.error("failed to copy volume to image store", e); + logger.error("failed to copy volume to image store", e); if (destVolume != null) { destVolume.getDataStore().delete(destVolume); } @@ -1819,7 +1840,7 @@ public class VolumeServiceImpl implements VolumeService { @Override public AsyncCallFuture copyVolume(VolumeInfo srcVolume, DataStore destStore) { DataStore srcStore = srcVolume.getDataStore(); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { String srcRole = (srcStore != null && srcStore.getRole() != null ? srcVolume.getDataStore().getRole().toString() : ""); String msg = String.format("copying %s(id=%d, role=%s) to %s (id=%d, role=%s)" @@ -1829,7 +1850,7 @@ public class VolumeServiceImpl implements VolumeService { , destStore.getName() , destStore.getId() , destStore.getRole()); - s_logger.debug(msg); + logger.debug(msg); } if (srcVolume.getState() == Volume.State.Uploaded) { @@ -1851,7 +1872,7 @@ public class VolumeServiceImpl implements VolumeService { VolumeApiResult res = new VolumeApiResult(srcVolume); try { if (!snapshotMgr.canOperateOnVolume(srcVolume)) { - s_logger.debug("There are snapshots creating on this volume, can not move this volume"); + logger.debug("There are snapshots creating on this volume, can not move this volume"); res.setResult("There are snapshots creating on this volume, can not move this volume"); future.complete(res); @@ -1868,9 +1889,9 @@ public class VolumeServiceImpl implements VolumeService { caller.setCallback(caller.getTarget().copyVolumeCallBack(null, null)).setContext(context); motionSrv.copyAsync(srcVolume, destVolume, caller); } catch (Exception e) { - s_logger.error("Failed to copy volume:" + e); - if(s_logger.isDebugEnabled()) { - s_logger.debug("Failed to copy volume.", e); + logger.error("Failed to copy volume:" + e); + if(logger.isDebugEnabled()) { + logger.debug("Failed to copy volume.", e); } res.setResult(e.toString()); future.complete(res); @@ -1891,7 +1912,7 @@ public class VolumeServiceImpl implements VolumeService { srcVolume.processEvent(Event.OperationFailed); destroyVolume(destVolume.getId()); if (destVolume.getStoragePoolType() == StoragePoolType.PowerFlex) { - s_logger.info("Dest volume " + destVolume.getId() + " can be removed"); + logger.info("Dest volume " + destVolume.getId() + " can be removed"); destVolume.processEvent(Event.ExpungeRequested); destVolume.processEvent(Event.OperationSuccessed); volDao.remove(destVolume.getId()); @@ -1908,7 +1929,7 @@ public class VolumeServiceImpl implements VolumeService { } } } catch (Exception e) { - s_logger.debug("Failed to process copy volume callback", e); + logger.debug("Failed to process copy volume callback", e); res.setResult(e.toString()); future.complete(res); } @@ -1935,12 +1956,12 @@ public class VolumeServiceImpl implements VolumeService { volDao.updateUuid(sourceVolumeId, destinationVolume.getId()); volDao.detachVolume(sourceVolumeId); - s_logger.info(String.format("Cleaning up %s on storage [%s].", sourceVolumeVo.getVolumeDescription(), sourceVolumeVo.getPoolId())); + logger.info(String.format("Cleaning up %s on storage [%s].", sourceVolumeVo.getVolumeDescription(), sourceVolumeVo.getPoolId())); destroyVolume(sourceVolumeId); try { if (sourceVolume.getStoragePoolType() == StoragePoolType.PowerFlex) { - s_logger.info(String.format("Source volume %s can be removed.", sourceVolumeVo.getVolumeDescription())); + logger.info(String.format("Source volume %s can be removed.", sourceVolumeVo.getVolumeDescription())); sourceVolume.processEvent(Event.ExpungeRequested); sourceVolume.processEvent(Event.OperationSuccessed); volDao.remove(sourceVolume.getId()); @@ -1949,7 +1970,7 @@ public class VolumeServiceImpl implements VolumeService { expungeSourceVolumeAfterMigration(sourceVolumeVo, retryExpungeVolumeAsync); return true; } catch (InterruptedException | ExecutionException e) { - s_logger.error(String.format("Failed to clean up %s on storage [%s].", sourceVolumeVo.getVolumeDescription(), sourceVolumeVo.getPoolId()), e); + logger.error(String.format("Failed to clean up %s on storage [%s].", sourceVolumeVo.getVolumeDescription(), sourceVolumeVo.getPoolId()), e); return false; } } @@ -1962,7 +1983,7 @@ public class VolumeServiceImpl implements VolumeService { VolumeApiResult volumeApiResult = destroyFuture.get(); if (volumeApiResult.isSuccess()) { - s_logger.debug(String.format("%s on storage [%s] was cleaned up successfully.", sourceVolumeVo.getVolumeDescription(), sourceVolumeVo.getPoolId())); + logger.debug(String.format("%s on storage [%s] was cleaned up successfully.", sourceVolumeVo.getVolumeDescription(), sourceVolumeVo.getPoolId())); return; } @@ -1970,10 +1991,10 @@ public class VolumeServiceImpl implements VolumeService { volumeApiResult.getResult()); if (!retryExpungeVolumeAsync) { - s_logger.warn(message); + logger.warn(message); } else { int intervalBetweenExpungeVolumeAsyncTriesInSeconds = 5; - s_logger.info(String.format("%s Trying again in [%s] seconds.", message, intervalBetweenExpungeVolumeAsyncTriesInSeconds)); + logger.info(String.format("%s Trying again in [%s] seconds.", message, intervalBetweenExpungeVolumeAsyncTriesInSeconds)); Thread.sleep(intervalBetweenExpungeVolumeAsyncTriesInSeconds * 1000); destroyFuture = expungeVolumeAsync(sourceVolume); @@ -2001,14 +2022,14 @@ public class VolumeServiceImpl implements VolumeService { VolumeApiResult res = new VolumeApiResult(srcVolume); try { if (!snapshotMgr.canOperateOnVolume(srcVolume)) { - s_logger.debug("There are snapshots creating for this volume, can not move this volume"); + logger.debug("There are snapshots creating for this volume, can not move this volume"); res.setResult("There are snapshots creating for this volume, can not move this volume"); future.complete(res); return future; } if (snapshotMgr.backedUpSnapshotsExistsForVolume(srcVolume)) { - s_logger.debug("There are backed up snapshots for this volume, can not move."); + logger.debug("There are backed up snapshots for this volume, can not move."); res.setResult("[UNSUPPORTED] There are backed up snapshots for this volume, can not move. Please try again after removing them."); future.complete(res); return future; @@ -2020,7 +2041,7 @@ public class VolumeServiceImpl implements VolumeService { Host hostWithPoolsAccess = _storageMgr.findUpAndEnabledHostWithAccessToStoragePools(poolIds); if (hostWithPoolsAccess == null) { - s_logger.debug("No host(s) available with pool access, can not move this volume"); + logger.debug("No host(s) available with pool access, can not move this volume"); res.setResult("No host(s) available with pool access, can not move this volume"); future.complete(res); return future; @@ -2033,7 +2054,7 @@ public class VolumeServiceImpl implements VolumeService { AsyncCallFuture createVolumeFuture = createVolumeAsync(destVolume, destStore); VolumeApiResult createVolumeResult = createVolumeFuture.get(); if (createVolumeResult.isFailed()) { - s_logger.debug("Failed to create dest volume " + destVolume.getId() + ", volume can be removed"); + logger.debug("Failed to create dest volume " + destVolume.getId() + ", volume can be removed"); destroyVolume(destVolume.getId()); destVolume.processEvent(Event.ExpungeRequested); destVolume.processEvent(Event.OperationSuccessed); @@ -2080,9 +2101,9 @@ public class VolumeServiceImpl implements VolumeService { motionSrv.copyAsync(srcVolume, destVolume, hostWithPoolsAccess, caller); } catch (Exception e) { - s_logger.error("Copy to managed volume failed due to: " + e); - if(s_logger.isDebugEnabled()) { - s_logger.debug("Copy to managed volume failed.", e); + logger.error("Copy to managed volume failed due to: " + e); + if(logger.isDebugEnabled()) { + logger.debug("Copy to managed volume failed.", e); } res.setResult(e.toString()); future.complete(res); @@ -2122,7 +2143,7 @@ public class VolumeServiceImpl implements VolumeService { } future.complete(res); } catch (Exception e) { - s_logger.debug("failed to clean up managed volume on storage", e); + logger.debug("failed to clean up managed volume on storage", e); } } else { srcVolume.processEvent(Event.OperationSuccessed); @@ -2141,11 +2162,11 @@ public class VolumeServiceImpl implements VolumeService { } future.complete(res); } catch (Exception e) { - s_logger.debug("failed to clean up volume on storage", e); + logger.debug("failed to clean up volume on storage", e); } } } catch (Exception e) { - s_logger.debug("Failed to process copy managed volume callback", e); + logger.debug("Failed to process copy managed volume callback", e); res.setResult(e.toString()); future.complete(res); } @@ -2155,7 +2176,7 @@ public class VolumeServiceImpl implements VolumeService { private boolean requiresNewManagedVolumeInDestStore(PrimaryDataStore srcDataStore, PrimaryDataStore destDataStore) { if (srcDataStore == null || destDataStore == null) { - s_logger.warn("Unable to check for new volume, either src or dest pool is null"); + logger.warn("Unable to check for new volume, either src or dest pool is null"); return false; } @@ -2178,13 +2199,13 @@ public class VolumeServiceImpl implements VolumeService { } if (StringUtils.isAnyEmpty(srcPoolSystemId, destPoolSystemId)) { - s_logger.warn("PowerFlex src pool: " + srcDataStore.getId() + " or dest pool: " + destDataStore.getId() + + logger.warn("PowerFlex src pool: " + srcDataStore.getId() + " or dest pool: " + destDataStore.getId() + " storage instance details are not available"); return false; } if (!srcPoolSystemId.equals(destPoolSystemId)) { - s_logger.debug("PowerFlex src pool: " + srcDataStore.getId() + " and dest pool: " + destDataStore.getId() + + logger.debug("PowerFlex src pool: " + srcDataStore.getId() + " and dest pool: " + destDataStore.getId() + " belongs to different storage instances, create new managed volume"); return true; } @@ -2216,7 +2237,7 @@ public class VolumeServiceImpl implements VolumeService { VolumeApiResult res = new VolumeApiResult(srcVolume); try { if (!snapshotMgr.canOperateOnVolume(srcVolume)) { - s_logger.debug("Snapshots are being created on this volume. This volume cannot be migrated now."); + logger.debug("Snapshots are being created on this volume. This volume cannot be migrated now."); res.setResult("Snapshots are being created on this volume. This volume cannot be migrated now."); future.complete(res); return future; @@ -2229,7 +2250,7 @@ public class VolumeServiceImpl implements VolumeService { caller.setCallback(caller.getTarget().migrateVolumeCallBack(null, null)).setContext(context); motionSrv.copyAsync(srcVolume, destVolume, caller); } catch (Exception e) { - s_logger.debug("Failed to migrate volume", e); + logger.debug("Failed to migrate volume", e); res.setResult(e.toString()); future.complete(res); } @@ -2256,7 +2277,7 @@ public class VolumeServiceImpl implements VolumeService { future.complete(res); } } catch (Exception e) { - s_logger.error("Failed to process migrate volume callback", e); + logger.error("Failed to process migrate volume callback", e); res.setResult(e.toString()); future.complete(res); } @@ -2287,7 +2308,7 @@ public class VolumeServiceImpl implements VolumeService { for (Map.Entry entry : volumeMap.entrySet()) { VolumeInfo volume = entry.getKey(); if (!snapshotMgr.canOperateOnVolume(volume)) { - s_logger.debug("Snapshots are being created on a volume. Volumes cannot be migrated now."); + logger.debug("Snapshots are being created on a volume. Volumes cannot be migrated now."); res.setResult("Snapshots are being created on a volume. Volumes cannot be migrated now."); future.complete(res); @@ -2309,7 +2330,7 @@ public class VolumeServiceImpl implements VolumeService { motionSrv.copyAsync(volumeMap, vmTo, srcHost, destHost, caller); } catch (Exception e) { - s_logger.debug("Failed to copy volume", e); + logger.debug("Failed to copy volume", e); res.setResult(e.toString()); future.complete(res); } @@ -2339,7 +2360,7 @@ public class VolumeServiceImpl implements VolumeService { future.complete(res); } } catch (Exception e) { - s_logger.error("Failed to process copy volume callback", e); + logger.error("Failed to process copy volume callback", e); res.setResult(e.toString()); future.complete(res); } @@ -2382,7 +2403,7 @@ public class VolumeServiceImpl implements VolumeService { EndPoint ep = _epSelector.select(store); if (ep == null) { String errorMessage = "There is no secondary storage VM for image store " + store.getName(); - s_logger.warn(errorMessage); + logger.warn(errorMessage); throw new CloudRuntimeException(errorMessage); } DataObject volumeOnStore = store.create(volume); @@ -2413,7 +2434,7 @@ public class VolumeServiceImpl implements VolumeService { if (volStore != null) { physicalSize = volStore.getPhysicalSize(); } else { - s_logger.warn("No entry found in volume_store_ref for volume id: " + vo.getId() + " and image store id: " + ds.getId() + " at the end of uploading volume!"); + logger.warn("No entry found in volume_store_ref for volume id: " + vo.getId() + " and image store id: " + ds.getId() + " at the end of uploading volume!"); } Scope dsScope = ds.getScope(); if (dsScope.getScopeType() == ScopeType.ZONE) { @@ -2421,7 +2442,7 @@ public class VolumeServiceImpl implements VolumeService { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_UPLOAD, vo.getAccountId(), dsScope.getScopeId(), vo.getId(), vo.getName(), null, null, physicalSize, vo.getSize(), Volume.class.getName(), vo.getUuid()); } else { - s_logger.warn("Zone scope image store " + ds.getId() + " has a null scope id"); + logger.warn("Zone scope image store " + ds.getId() + " has a null scope id"); } } else if (dsScope.getScopeType() == ScopeType.REGION) { // publish usage event for region-wide image store using a -1 zoneId for 4.2, need to revisit post-4.2 @@ -2437,7 +2458,7 @@ public class VolumeServiceImpl implements VolumeService { return null; } catch (Exception e) { - s_logger.error("register volume failed: ", e); + logger.error("register volume failed: ", e); // delete the volume entry from volumes table in case of failure VolumeVO vol = volDao.findById(vo.getId()); if (vol != null) { @@ -2456,7 +2477,7 @@ public class VolumeServiceImpl implements VolumeService { try { volume.processEvent(Event.ResizeRequested); } catch (Exception e) { - s_logger.debug("Failed to change state to resize", e); + logger.debug("Failed to change state to resize", e); result.setResult(e.toString()); future.complete(result); return future; @@ -2468,7 +2489,7 @@ public class VolumeServiceImpl implements VolumeService { try { volume.getDataStore().getDriver().resize(volume, caller); } catch (Exception e) { - s_logger.debug("Failed to change state to resize", e); + logger.debug("Failed to change state to resize", e); result.setResult(e.toString()); @@ -2515,7 +2536,7 @@ public class VolumeServiceImpl implements VolumeService { try { volume.processEvent(Event.OperationFailed); } catch (Exception e) { - s_logger.debug("Failed to change state", e); + logger.debug("Failed to change state", e); } VolumeApiResult res = new VolumeApiResult(volume); res.setResult(result.getResult()); @@ -2526,7 +2547,7 @@ public class VolumeServiceImpl implements VolumeService { try { volume.processEvent(Event.OperationSuccessed); } catch (Exception e) { - s_logger.debug("Failed to change state", e); + logger.debug("Failed to change state", e); VolumeApiResult res = new VolumeApiResult(volume); res.setResult(result.getResult()); future.complete(res); @@ -2542,7 +2563,7 @@ public class VolumeServiceImpl implements VolumeService { @Override public void handleVolumeSync(DataStore store) { if (store == null) { - s_logger.warn("Huh? image store is null"); + logger.warn("Huh? image store is null"); return; } long storeId = store.getId(); @@ -2564,7 +2585,7 @@ public class VolumeServiceImpl implements VolumeService { for (VolumeDataStoreVO volumeStore : dbVolumes) { VolumeVO volume = volDao.findById(volumeStore.getVolumeId()); if (volume == null) { - s_logger.warn("Volume_store_ref table shows that volume " + volumeStore.getVolumeId() + " is on image store " + storeId + logger.warn("Volume_store_ref table shows that volume " + volumeStore.getVolumeId() + " is on image store " + storeId + ", but the volume is not found in volumes table, potentially some bugs in deleteVolume, so we just treat this volume to be deleted and mark it as destroyed"); volumeStore.setDestroyed(true); _volumeStoreDao.update(volumeStore.getId(), volumeStore); @@ -2574,7 +2595,7 @@ public class VolumeServiceImpl implements VolumeService { if (volumeInfos.containsKey(volume.getId())) { TemplateProp volInfo = volumeInfos.remove(volume.getId()); toBeDownloaded.remove(volumeStore); - s_logger.info("Volume Sync found " + volume.getUuid() + " already in the volume image store table"); + logger.info("Volume Sync found " + volume.getUuid() + " already in the volume image store table"); if (volumeStore.getDownloadState() != Status.DOWNLOADED) { volumeStore.setErrorString(""); } @@ -2582,9 +2603,9 @@ public class VolumeServiceImpl implements VolumeService { volumeStore.setDownloadState(Status.DOWNLOAD_ERROR); String msg = "Volume " + volume.getUuid() + " is corrupted on image store"; volumeStore.setErrorString(msg); - s_logger.info(msg); + logger.info(msg); if (volume.getState() == State.NotUploaded || volume.getState() == State.UploadInProgress) { - s_logger.info("Volume Sync found " + volume.getUuid() + " uploaded using SSVM on image store " + storeId + " as corrupted, marking it as failed"); + logger.info("Volume Sync found " + volume.getUuid() + " uploaded using SSVM on image store " + storeId + " as corrupted, marking it as failed"); _volumeStoreDao.update(volumeStore.getId(), volumeStore); // mark volume as failed, so that storage GC will clean it up VolumeObject volObj = (VolumeObject)volFactory.getVolume(volume.getId()); @@ -2592,9 +2613,9 @@ public class VolumeServiceImpl implements VolumeService { } else if (volumeStore.getDownloadUrl() == null) { msg = "Volume (" + volume.getUuid() + ") with install path " + volInfo.getInstallPath() + " is corrupted, please check in image store: " + volumeStore.getDataStoreId(); - s_logger.warn(msg); + logger.warn(msg); } else { - s_logger.info("Removing volume_store_ref entry for corrupted volume " + volume.getName()); + logger.info("Removing volume_store_ref entry for corrupted volume " + volume.getName()); _volumeStoreDao.remove(volumeStore.getId()); toBeDownloaded.add(volumeStore); } @@ -2624,7 +2645,7 @@ public class VolumeServiceImpl implements VolumeService { _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(volume.getAccountId()), com.cloud.configuration.Resource.ResourceType.secondary_storage, volInfo.getSize() - volInfo.getPhysicalSize()); } catch (ResourceAllocationException e) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED, volume.getDataCenterId(), volume.getPodId(), e.getMessage(), e.getMessage()); } finally { _resourceLimitMgr.recalculateResourceCount(volume.getAccountId(), volume.getDomainId(), @@ -2634,7 +2655,7 @@ public class VolumeServiceImpl implements VolumeService { } continue; } else if (volume.getState() == State.NotUploaded || volume.getState() == State.UploadInProgress) { // failed uploads through SSVM - s_logger.info("Volume Sync did not find " + volume.getUuid() + " uploaded using SSVM on image store " + storeId + ", marking it as failed"); + logger.info("Volume Sync did not find " + volume.getUuid() + " uploaded using SSVM on image store " + storeId + ", marking it as failed"); toBeDownloaded.remove(volumeStore); volumeStore.setDownloadState(Status.DOWNLOAD_ERROR); String msg = "Volume " + volume.getUuid() + " is corrupted on image store"; @@ -2647,7 +2668,7 @@ public class VolumeServiceImpl implements VolumeService { } // Volume is not on secondary but we should download. if (volumeStore.getDownloadState() != Status.DOWNLOADED) { - s_logger.info("Volume Sync did not find " + volume.getName() + " ready on image store " + storeId + ", will request download to start/resume shortly"); + logger.info("Volume Sync did not find " + volume.getName() + " ready on image store " + storeId + ", will request download to start/resume shortly"); } } @@ -2655,7 +2676,7 @@ public class VolumeServiceImpl implements VolumeService { if (toBeDownloaded.size() > 0) { for (VolumeDataStoreVO volumeHost : toBeDownloaded) { if (volumeHost.getDownloadUrl() == null) { // If url is null, skip downloading - s_logger.info("Skip downloading volume " + volumeHost.getVolumeId() + " since no download url is specified."); + logger.info("Skip downloading volume " + volumeHost.getVolumeId() + " since no download url is specified."); continue; } @@ -2663,12 +2684,12 @@ public class VolumeServiceImpl implements VolumeService { // means that this is a duplicate entry from migration of previous NFS to staging. if (store.getScope().getScopeType() == ScopeType.REGION) { if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && volumeHost.getInstallPath() == null) { - s_logger.info("Skip sync volume for migration of previous NFS to object store"); + logger.info("Skip sync volume for migration of previous NFS to object store"); continue; } } - s_logger.debug("Volume " + volumeHost.getVolumeId() + " needs to be downloaded to " + store.getName()); + logger.debug("Volume " + volumeHost.getVolumeId() + " needs to be downloaded to " + store.getName()); // reset volume status back to Allocated VolumeObject vol = (VolumeObject)volFactory.getVolume(volumeHost.getVolumeId()); vol.processEvent(Event.OperationFailed); // reset back volume status @@ -2697,24 +2718,24 @@ public class VolumeServiceImpl implements VolumeService { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(dtCommand, false, errMsg); } else { answer = ep.sendMessage(dtCommand); } if (answer == null || !answer.getResult()) { - s_logger.info("Failed to deleted volume at store: " + store.getName()); + logger.info("Failed to deleted volume at store: " + store.getName()); } else { String description = "Deleted volume " + tInfo.getTemplateName() + " on secondary storage " + storeId; - s_logger.info(description); + logger.info(description); } } } finally { syncLock.unlock(); } } else { - s_logger.info("Couldn't get global lock on " + lockString + ", another thread may be doing volume sync on data store " + storeId + " now."); + logger.info("Couldn't get global lock on " + lockString + ", another thread may be doing volume sync on data store " + storeId + " now."); } } finally { syncLock.releaseRef(); @@ -2727,7 +2748,7 @@ public class VolumeServiceImpl implements VolumeService { Answer answer = null; if (ep == null) { String errMsg = "No remote endpoint to send command, check if host or ssvm is down?"; - s_logger.error(errMsg); + logger.error(errMsg); answer = new Answer(cmd, false, errMsg); } else { answer = ep.sendMessage(cmd); @@ -2736,8 +2757,8 @@ public class VolumeServiceImpl implements VolumeService { ListVolumeAnswer tanswer = (ListVolumeAnswer)answer; return tanswer.getTemplateInfo(); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Can not list volumes for image store " + store.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Can not list volumes for image store " + store.getId()); } } @@ -2750,11 +2771,11 @@ public class VolumeServiceImpl implements VolumeService { try { snapshot = snapshotMgr.takeSnapshot(volume); } catch (CloudRuntimeException cre) { - s_logger.error("Take snapshot: " + volume.getId() + " failed", cre); + logger.error("Take snapshot: " + volume.getId() + " failed", cre); throw cre; } catch (Exception e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("unknown exception while taking snapshot for volume " + volume.getId() + " was caught", e); + if (logger.isDebugEnabled()) { + logger.debug("unknown exception while taking snapshot for volume " + volume.getId() + " was caught", e); } throw new CloudRuntimeException("Failed to take snapshot", e); } @@ -2762,6 +2783,62 @@ public class VolumeServiceImpl implements VolumeService { return snapshot; } + @Override + public void checkAndRepairVolumeBasedOnConfig(DataObject dataObject, Host host) { + if (HypervisorType.KVM.equals(host.getHypervisorType()) && DataObjectType.VOLUME.equals(dataObject.getType())) { + VolumeInfo volumeInfo = volFactory.getVolume(dataObject.getId()); + if (VolumeApiServiceImpl.AllowCheckAndRepairVolume.valueIn(volumeInfo.getPoolId())) { + logger.info(String.format("Trying to check and repair the volume %d", dataObject.getId())); + String repair = CheckAndRepairVolumeCmd.RepairValues.LEAKS.name().toLowerCase(); + CheckAndRepairVolumePayload payload = new CheckAndRepairVolumePayload(repair); + volumeInfo.addPayload(payload); + checkAndRepairVolumeThroughHost(volumeInfo, host); + } + } + } + + @Override + public Pair checkAndRepairVolume(VolumeInfo volume) { + Long poolId = volume.getPoolId(); + List hostIds = _storageMgr.getUpHostsInPool(poolId); + if (CollectionUtils.isEmpty(hostIds)) { + throw new CloudRuntimeException("Unable to find Up hosts to run the check volume command"); + } + Collections.shuffle(hostIds); + Host host = _hostDao.findById(hostIds.get(0)); + + return checkAndRepairVolumeThroughHost(volume, host); + + } + + private Pair checkAndRepairVolumeThroughHost(VolumeInfo volume, Host host) { + Long poolId = volume.getPoolId(); + StoragePool pool = _storageMgr.getStoragePool(poolId); + CheckAndRepairVolumePayload payload = (CheckAndRepairVolumePayload) volume.getpayload(); + CheckAndRepairVolumeCommand command = new CheckAndRepairVolumeCommand(volume.getPath(), new StorageFilerTO(pool), payload.getRepair(), + volume.getPassphrase(), volume.getEncryptFormat()); + + try { + grantAccess(volume, host, volume.getDataStore()); + CheckAndRepairVolumeAnswer answer = (CheckAndRepairVolumeAnswer) _storageMgr.sendToPool(pool, new long[]{host.getId()}, command); + if (answer != null && answer.getResult()) { + logger.debug(String.format("Check volume response result: %s", answer.getDetails())); + return new Pair<>(answer.getVolumeCheckExecutionResult(), answer.getVolumeRepairExecutionResult()); + } else { + String errMsg = (answer == null) ? null : answer.getDetails(); + logger.debug(String.format("Failed to check and repair the volume with error %s", errMsg)); + } + + } catch (Exception e) { + logger.debug("sending check and repair volume command failed", e); + } finally { + revokeAccess(volume, host, volume.getDataStore()); + command.clearPassphrase(); + } + + return null; + } + // For managed storage on Xen and VMware, we need to potentially make space for hypervisor snapshots. // The disk offering can collect this information and pass it on to the volume that's about to be created. // Ex. if you want a 10 GB CloudStack volume to reside on managed storage on Xen, this leads to an SR @@ -2809,10 +2886,10 @@ public class VolumeServiceImpl implements VolumeService { VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId()); if (volumeStore == null) { - s_logger.debug(String.format("Volume [%s] is not present in the secondary storage. Therefore we do not need to move it in the secondary storage.", volume)); + logger.debug(String.format("Volume [%s] is not present in the secondary storage. Therefore we do not need to move it in the secondary storage.", volume)); return; } - s_logger.debug(String.format("Volume [%s] is present in secondary storage. It will be necessary to move it from the source account's [%s] folder to the destination " + logger.debug(String.format("Volume [%s] is present in secondary storage. It will be necessary to move it from the source account's [%s] folder to the destination " + "account's [%s] folder.", volume.getUuid(), sourceAccount, destAccount)); @@ -2831,17 +2908,17 @@ public class VolumeServiceImpl implements VolumeService { String msg = String.format("Unable to move volume [%s] from [%s] (source account's [%s] folder) to [%s] (destination account's [%s] folder) in the secondary storage, due " + "to [%s].", volume.getUuid(), srcPath.getParent(), sourceAccount, destPath, destAccount, answer.getDetails()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } - s_logger.debug(String.format("Volume [%s] was moved from [%s] (source account's [%s] folder) to [%s] (destination account's [%s] folder) in the secondary storage.", + logger.debug(String.format("Volume [%s] was moved from [%s] (source account's [%s] folder) to [%s] (destination account's [%s] folder) in the secondary storage.", volume.getUuid(), srcPath.getParent(), sourceAccount, destPath, destAccount)); volumeStore.setInstallPath(String.format("%s/%s", destPath, srcPath.getFileName().toString())); if (!_volumeStoreDao.update(volumeStore.getId(), volumeStore)) { String msg = String.format("Unable to update volume [%s] install path in the DB.", volumeStore.getVolumeId()); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } diff --git a/engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceTest.java b/engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceTest.java index ee4b77c269c..3a7fcfb6338 100644 --- a/engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceTest.java +++ b/engine/storage/volume/src/test/java/org/apache/cloudstack/storage/volume/VolumeServiceTest.java @@ -19,14 +19,12 @@ package org.apache.cloudstack.storage.volume; -import com.cloud.storage.VolumeVO; -import com.cloud.storage.dao.VolumeDao; -import com.cloud.storage.snapshot.SnapshotManager; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutionException; -import junit.framework.TestCase; + import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; @@ -41,6 +39,23 @@ import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import com.cloud.agent.api.storage.CheckAndRepairVolumeAnswer; +import com.cloud.agent.api.storage.CheckAndRepairVolumeCommand; +import com.cloud.agent.api.to.StorageFilerTO; +import com.cloud.exception.StorageUnavailableException; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; +import com.cloud.storage.CheckAndRepairVolumePayload; +import com.cloud.storage.Storage; +import com.cloud.storage.StorageManager; +import com.cloud.storage.StoragePool; +import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.storage.snapshot.SnapshotManager; +import com.cloud.utils.Pair; + +import junit.framework.TestCase; + @RunWith(MockitoJUnitRunner.class) public class VolumeServiceTest extends TestCase{ @@ -65,15 +80,26 @@ public class VolumeServiceTest extends TestCase{ @Mock SnapshotManager snapshotManagerMock; + @Mock + StorageManager storageManagerMock; + @Mock VolumeVO volumeVoMock; + @Mock + HostVO hostMock; + + @Mock + HostDao hostDaoMock; + @Before public void setup(){ volumeServiceImplSpy = Mockito.spy(new VolumeServiceImpl()); volumeServiceImplSpy.volFactory = volumeDataFactoryMock; volumeServiceImplSpy.volDao = volumeDaoMock; volumeServiceImplSpy.snapshotMgr = snapshotManagerMock; + volumeServiceImplSpy._storageMgr = storageManagerMock; + volumeServiceImplSpy._hostDao = hostDaoMock; } @Test(expected = InterruptedException.class) @@ -185,7 +211,9 @@ public class VolumeServiceTest extends TestCase{ public void validateDestroySourceVolumeAfterMigrationExpungeSourceVolumeAfterMigrationThrowExceptionReturnFalse() throws ExecutionException, InterruptedException{ VolumeObject volumeObject = new VolumeObject(); - volumeObject.configure(null, new VolumeVO() {}); + VolumeVO vo = new VolumeVO() {}; + vo.setPoolType(Storage.StoragePoolType.Filesystem); + volumeObject.configure(null, vo); List exceptions = new ArrayList<>(Arrays.asList(new InterruptedException(), new ExecutionException() {})); @@ -210,4 +238,75 @@ public class VolumeServiceTest extends TestCase{ volumeServiceImplSpy.destroySourceVolumeAfterMigration(ObjectInDataStoreStateMachine.Event.DestroyRequested, null, volumeObject, volumeObject, true); } + + @Test + public void testCheckAndRepairVolume() throws StorageUnavailableException { + VolumeInfo volume = Mockito.mock(VolumeInfo.class); + Mockito.when(volume.getPoolId()).thenReturn(1L); + StoragePool pool = Mockito.mock(StoragePool.class); + Mockito.when(storageManagerMock.getStoragePool(1L)).thenReturn(pool); + List hostIds = new ArrayList<>(); + hostIds.add(1L); + Mockito.when(storageManagerMock.getUpHostsInPool(1L)).thenReturn(hostIds); + Mockito.when(hostMock.getId()).thenReturn(1L); + Mockito.when(hostDaoMock.findById(1L)).thenReturn(hostMock); + + CheckAndRepairVolumePayload payload = new CheckAndRepairVolumePayload(null); + Mockito.when(volume.getpayload()).thenReturn(payload); + Mockito.when(volume.getPath()).thenReturn("cbac516a-0f1f-4559-921c-1a7c6c408ccf"); + Mockito.when(volume.getPassphrase()).thenReturn(new byte[] {3, 1, 2, 3}); + Mockito.when(volume.getEncryptFormat()).thenReturn("LUKS"); + + String checkResult = "{\n" + + " \"image-end-offset\": 6442582016,\n" + + " \"total-clusters\": 163840,\n" + + " \"check-errors\": 0,\n" + + " \"leaks\": 124,\n" + + " \"allocated-clusters\": 98154,\n" + + " \"filename\": \"/var/lib/libvirt/images/26be20c7-b9d0-43f6-a76e-16c70737a0e0\",\n" + + " \"format\": \"qcow2\",\n" + + " \"fragmented-clusters\": 96135\n" + + "}"; + + CheckAndRepairVolumeCommand command = new CheckAndRepairVolumeCommand(volume.getPath(), new StorageFilerTO(pool), payload.getRepair(), + volume.getPassphrase(), volume.getEncryptFormat()); + + CheckAndRepairVolumeAnswer answer = new CheckAndRepairVolumeAnswer(command, true, checkResult); + answer.setVolumeCheckExecutionResult(checkResult); + Mockito.when(storageManagerMock.sendToPool(pool, new long[]{1L}, command)).thenReturn(answer); + + Pair result = volumeServiceImplSpy.checkAndRepairVolume(volume); + + Assert.assertEquals(result.first(), checkResult); + Assert.assertEquals(result.second(), null); + } + + @Test + public void testCheckAndRepairVolumeWhenFailure() throws StorageUnavailableException { + VolumeInfo volume = Mockito.mock(VolumeInfo.class); + Mockito.when(volume.getPoolId()).thenReturn(1L); + StoragePool pool = Mockito.mock(StoragePool.class); + Mockito.when(storageManagerMock.getStoragePool(1L)).thenReturn(pool); + List hostIds = new ArrayList<>(); + hostIds.add(1L); + Mockito.when(storageManagerMock.getUpHostsInPool(1L)).thenReturn(hostIds); + Mockito.when(hostMock.getId()).thenReturn(1L); + Mockito.when(hostDaoMock.findById(1L)).thenReturn(hostMock); + + CheckAndRepairVolumePayload payload = new CheckAndRepairVolumePayload(null); + Mockito.when(volume.getpayload()).thenReturn(payload); + Mockito.when(volume.getPath()).thenReturn("cbac516a-0f1f-4559-921c-1a7c6c408ccf"); + Mockito.when(volume.getPassphrase()).thenReturn(new byte[] {3, 1, 2, 3}); + Mockito.when(volume.getEncryptFormat()).thenReturn("LUKS"); + + CheckAndRepairVolumeCommand command = new CheckAndRepairVolumeCommand(volume.getPath(), new StorageFilerTO(pool), payload.getRepair(), + volume.getPassphrase(), volume.getEncryptFormat()); + + CheckAndRepairVolumeAnswer answer = new CheckAndRepairVolumeAnswer(command, false, "Unable to execute qemu command"); + Mockito.when(storageManagerMock.sendToPool(pool, new long[]{1L}, command)).thenReturn(answer); + + Pair result = volumeServiceImplSpy.checkAndRepairVolume(volume); + + Assert.assertEquals(null, result); + } } diff --git a/engine/userdata/cloud-init/pom.xml b/engine/userdata/cloud-init/pom.xml index 7e641bd6b5e..d4396ba382a 100644 --- a/engine/userdata/cloud-init/pom.xml +++ b/engine/userdata/cloud-init/pom.xml @@ -23,7 +23,7 @@ cloud-engine org.apache.cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/engine/userdata/cloud-init/src/main/java/org/apache/cloudstack/userdata/CloudInitUserDataProvider.java b/engine/userdata/cloud-init/src/main/java/org/apache/cloudstack/userdata/CloudInitUserDataProvider.java index 65996f181a9..6e1086c631e 100644 --- a/engine/userdata/cloud-init/src/main/java/org/apache/cloudstack/userdata/CloudInitUserDataProvider.java +++ b/engine/userdata/cloud-init/src/main/java/org/apache/cloudstack/userdata/CloudInitUserDataProvider.java @@ -38,7 +38,6 @@ import javax.mail.internet.MimeMultipart; import org.apache.commons.codec.binary.Base64; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.exception.CloudRuntimeException; @@ -62,8 +61,6 @@ public class CloudInitUserDataProvider extends AdapterBase implements UserDataPr Map.entry(FormatType.INCLUDE_FILE, INCLUDE_FILE_CONTENT_TYPE) ); - private static final Logger LOGGER = Logger.getLogger(CloudInitUserDataProvider.class); - private static final Session session = Session.getDefaultInstance(new Properties()); @Override @@ -108,7 +105,7 @@ public class CloudInitUserDataProvider extends AdapterBase implements UserDataPr } else { String msg = String.format("Cannot recognise the user data format type from the header line: %s." + "Supported types are: cloud-config, bash script, cloud-boothook, include file or MIME", header); - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } @@ -120,7 +117,7 @@ public class CloudInitUserDataProvider extends AdapterBase implements UserDataPr protected FormatType getUserDataFormatType(String userdata) { if (StringUtils.isBlank(userdata)) { String msg = "User data expected but provided empty user data"; - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -263,7 +260,7 @@ public class CloudInitUserDataProvider extends AdapterBase implements UserDataPr } catch (MessagingException | IOException | CloudRuntimeException e) { String msg = String.format("Error attempting to merge user data as a multipart user data. " + "Reason: %s", e.getMessage()); - LOGGER.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(msg, e); } } diff --git a/engine/userdata/pom.xml b/engine/userdata/pom.xml index e487af4f22d..038aa18f290 100644 --- a/engine/userdata/pom.xml +++ b/engine/userdata/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloud-engine - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/agent-lb/pom.xml b/framework/agent-lb/pom.xml index db750997d80..50e0bd47b90 100644 --- a/framework/agent-lb/pom.xml +++ b/framework/agent-lb/pom.xml @@ -24,7 +24,7 @@ cloudstack-framework org.apache.cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/ca/pom.xml b/framework/ca/pom.xml index 9e1cffcc236..d82389cd008 100644 --- a/framework/ca/pom.xml +++ b/framework/ca/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/cluster/pom.xml b/framework/cluster/pom.xml index 7cb833433a3..ef511584ae6 100644 --- a/framework/cluster/pom.xml +++ b/framework/cluster/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterFenceManagerImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterFenceManagerImpl.java index 4f5e0344e73..203ebe6e3d4 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterFenceManagerImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterFenceManagerImpl.java @@ -23,14 +23,12 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.cloudstack.management.ManagementServerHost; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.component.ManagerBase; @Component public class ClusterFenceManagerImpl extends ManagerBase implements ClusterFenceManager, ClusterManagerListener { - private static final Logger s_logger = Logger.getLogger(ClusterFenceManagerImpl.class); @Inject ClusterManager _clusterMgr; @@ -51,7 +49,7 @@ public class ClusterFenceManagerImpl extends ManagerBase implements ClusterFence @Override public void onManagementNodeIsolated() { - s_logger.error("Received node isolation notification, will perform self-fencing and shut myself down"); + logger.error("Received node isolation notification, will perform self-fencing and shut myself down"); System.exit(SELF_FENCING_EXIT_CODE); } } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java index 289638fe22d..e4e55eb9348 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterManagerImpl.java @@ -47,7 +47,6 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.utils.identity.ManagementServerNode; -import org.apache.log4j.Logger; import com.cloud.cluster.dao.ManagementServerHostDao; import com.cloud.cluster.dao.ManagementServerHostPeerDao; @@ -70,7 +69,6 @@ import com.cloud.utils.mgmt.JmxUtil; import com.cloud.utils.net.NetUtils; public class ClusterManagerImpl extends ManagerBase implements ClusterManager, Configurable { - private static final Logger s_logger = Logger.getLogger(ClusterManagerImpl.class); private static final int EXECUTOR_SHUTDOWN_TIMEOUT = 1000; // 1 second private static final int DEFAULT_OUTGOING_WORKERS = 5; @@ -176,7 +174,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } for (final ClusterServiceRequestPdu pdu : candidates) { - s_logger.warn("Cancel cluster request PDU to peer: " + strPeer + ", pdu: " + pdu.getJsonPackage()); + logger.warn("Cancel cluster request PDU to peer: " + strPeer + ", pdu: " + pdu.getJsonPackage()); synchronized (pdu) { pdu.notifyAll(); } @@ -260,13 +258,13 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C try { peerService = getPeerService(pdu.getDestPeer()); } catch (final RemoteException e) { - s_logger.error("Unable to get cluster service on peer : " + pdu.getDestPeer()); + logger.error("Unable to get cluster service on peer : " + pdu.getDestPeer()); } if (peerService != null) { try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + ". agent: " + pdu.getAgentId() + ", pdu seq: " + + if (logger.isDebugEnabled()) { + logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + ". agent: " + pdu.getAgentId() + ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage()); } @@ -276,8 +274,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C final String strResult = peerService.execute(pdu); profiler.stop(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + " completed. time: " + + if (logger.isDebugEnabled()) { + logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + " completed. time: " + profiler.getDurationInMillis() + "ms. agent: " + pdu.getAgentId() + ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage()); } @@ -288,15 +286,15 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } catch (final RemoteException e) { invalidatePeerService(pdu.getDestPeer()); - if (s_logger.isInfoEnabled()) { - s_logger.info("Exception on remote execution, peer: " + pdu.getDestPeer() + ", iteration: " + i + ", exception message :" + + if (logger.isInfoEnabled()) { + logger.info("Exception on remote execution, peer: " + pdu.getDestPeer() + ", iteration: " + i + ", exception message :" + e.getMessage()); } } } } } catch (final Throwable e) { - s_logger.error("Unexcpeted exception: ", e); + logger.error("Unexcpeted exception: ", e); } } } @@ -320,11 +318,11 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C requestPdu.notifyAll(); } } else { - s_logger.warn("Original request has already been cancelled. pdu: " + pdu.getJsonPackage()); + logger.warn("Original request has already been cancelled. pdu: " + pdu.getJsonPackage()); } } else if (pdu.getPduType() == ClusterServicePdu.PDU_TYPE_STATUS_UPDATE) { if (statusAdministrator == null) { - s_logger.warn("No status administration to report a status update too."); + logger.warn("No status administration to report a status update too."); } else { statusAdministrator.newStatus(pdu); } @@ -348,7 +346,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } }); } catch (final Throwable e) { - s_logger.error("Unexcpeted exception: ", e); + logger.error("Unexcpeted exception: ", e); } } } @@ -381,12 +379,12 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C continue; // Skip myself. } try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Forwarding " + cmds + " to " + peer.getMsid()); + if (logger.isDebugEnabled()) { + logger.debug("Forwarding " + cmds + " to " + peer.getMsid()); } executeAsync(peerName, agentId, cmds, true); } catch (final Exception e) { - s_logger.warn("Caught exception while talkign to " + peer.getMsid()); + logger.warn("Caught exception while talkign to " + peer.getMsid()); } } } @@ -409,14 +407,14 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C for (final ManagementServerHostVO peer : peers) { final String peerName = Long.toString(peer.getMsid()); try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Forwarding " + status + " to " + peer.getMsid()); + if (logger.isDebugEnabled()) { + logger.debug("Forwarding " + status + " to " + peer.getMsid()); } sendStatus(peerName, status); } catch (final Exception e) { String msg = String.format("Caught exception while talking to %d", peer.getMsid()); - s_logger.warn(msg); - s_logger.debug(msg, e); + logger.warn(msg); + logger.debug(msg, e); } } } @@ -434,8 +432,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C @Override public String execute(final String strPeer, final long agentId, final String cmds, final boolean stopOnError) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(getSelfPeerName() + " -> " + strPeer + "." + agentId + " " + cmds); + if (logger.isDebugEnabled()) { + logger.debug(getSelfPeerName() + " -> " + strPeer + "." + agentId + " " + cmds); } final ClusterServiceRequestPdu pdu = new ClusterServiceRequestPdu(); @@ -454,8 +452,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } } - if (s_logger.isDebugEnabled()) { - s_logger.debug(getSelfPeerName() + " -> " + strPeer + "." + agentId + " completed. result: " + pdu.getResponseResult()); + if (logger.isDebugEnabled()) { + logger.debug(getSelfPeerName() + " -> " + strPeer + "." + agentId + " completed. result: " + pdu.getResponseResult()); } if (pdu.getResponseResult() != null && pdu.getResponseResult().length() > 0) { @@ -484,7 +482,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C // Note : we don't check duplicates synchronized (_listeners) { - s_logger.info("register cluster listener " + listener.getClass()); + logger.info("register cluster listener " + listener.getClass()); _listeners.add(listener); } @@ -493,18 +491,18 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C @Override public void unregisterListener(final ClusterManagerListener listener) { synchronized (_listeners) { - s_logger.info("unregister cluster listener " + listener.getClass()); + logger.info("unregister cluster listener " + listener.getClass()); _listeners.remove(listener); } } public void notifyNodeJoined(final List nodeList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notify management server node join to listeners."); + if (logger.isDebugEnabled()) { + logger.debug("Notify management server node join to listeners."); for (final ManagementServerHostVO mshost : nodeList) { - s_logger.debug("Joining node, IP: " + mshost.getServiceIP() + ", msid: " + mshost.getMsid()); + logger.debug("Joining node, IP: " + mshost.getServiceIP() + ", msid: " + mshost.getMsid()); } } @@ -518,13 +516,13 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } public void notifyNodeLeft(final List nodeList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notify management server node left to listeners."); + if (logger.isDebugEnabled()) { + logger.debug("Notify management server node left to listeners."); } for (final ManagementServerHostVO mshost : nodeList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Leaving node, IP: " + mshost.getServiceIP() + ", msid: " + mshost.getMsid()); + if (logger.isDebugEnabled()) { + logger.debug("Leaving node, IP: " + mshost.getServiceIP() + ", msid: " + mshost.getMsid()); } cancelClusterRequestToPeer(String.valueOf(mshost.getMsid())); } @@ -539,8 +537,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } public void notifyNodeIsolated() { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notify management server node isolation to listeners"); + if (logger.isDebugEnabled()) { + logger.debug("Notify management server node isolation to listeners"); } synchronized (_listeners) { @@ -595,16 +593,16 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C profilerHeartbeatUpdate.start(); txn.transitToAutoManagedConnection(TransactionLegacy.CLOUD_DB); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Cluster manager heartbeat update, id:" + _mshostId); + if (logger.isTraceEnabled()) { + logger.trace("Cluster manager heartbeat update, id:" + _mshostId); } _mshostDao.update(_mshostId, _runId, DateUtil.currentGMTTime()); profilerHeartbeatUpdate.stop(); profilerPeerScan.start(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Cluster manager peer-scan, id:" + _mshostId); + if (logger.isTraceEnabled()) { + logger.trace("Cluster manager peer-scan, id:" + _mshostId); } if (!_peerScanInited) { @@ -619,18 +617,18 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C profiler.stop(); if (profiler.getDurationInMillis() >= HeartbeatInterval.value()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Management server heartbeat takes too long to finish. profiler: " + profiler.toString() + ", profilerHeartbeatUpdate: " + + if (logger.isDebugEnabled()) { + logger.debug("Management server heartbeat takes too long to finish. profiler: " + profiler.toString() + ", profilerHeartbeatUpdate: " + profilerHeartbeatUpdate.toString() + ", profilerPeerScan: " + profilerPeerScan.toString()); } } } } catch (final CloudRuntimeException e) { - s_logger.error("Runtime DB exception ", e.getCause()); + logger.error("Runtime DB exception ", e.getCause()); if (e.getCause() instanceof ClusterInvalidSessionException) { - s_logger.error("Invalid cluster session found, fence it"); + logger.error("Invalid cluster session found, fence it"); queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated)); } @@ -640,7 +638,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } catch (final ActiveFencingException e) { queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated)); } catch (final Throwable e) { - s_logger.error("Unexpected exception in cluster heartbeat", e); + logger.error("Unexpected exception in cluster heartbeat", e); if (isRootCauseConnectionRelated(e.getCause())) { invalidHeartbeatConnection(); } @@ -669,7 +667,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C if (conn != null) { _heartbeatConnection.reset(conn); } else { - s_logger.error("DB communication problem detected, fence it"); + logger.error("DB communication problem detected, fence it"); queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated)); } // The stand-alone connection does not have to be closed here because there will be another reference to it. @@ -702,11 +700,11 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C profiler.stop(); if (profiler.getDurationInMillis() > 1000) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notifying management server join event took " + profiler.getDurationInMillis() + " ms"); + if (logger.isDebugEnabled()) { + logger.debug("Notifying management server join event took " + profiler.getDurationInMillis() + " ms"); } } else { - s_logger.warn("Notifying management server join event took " + profiler.getDurationInMillis() + " ms"); + logger.warn("Notifying management server join event took " + profiler.getDurationInMillis() + " ms"); } } break; @@ -720,11 +718,11 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C profiler.stop(); if (profiler.getDurationInMillis() > 1000) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms"); + if (logger.isDebugEnabled()) { + logger.debug("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms"); } } else { - s_logger.warn("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms"); + logger.warn("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms"); } } break; @@ -739,7 +737,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } } catch (final Throwable e) { - s_logger.warn("Unexpected exception during cluster notification. ", e); + logger.warn("Unexpected exception during cluster notification. ", e); } } @@ -806,18 +804,18 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C if (orphanList.size() > 0) { for (final Long orphanMsid : orphanList) { // construct fake ManagementServerHostVO based on orphan MSID - s_logger.info("Add orphan management server msid found in host table to initial clustering notification, orphan msid: " + orphanMsid); + logger.info("Add orphan management server msid found in host table to initial clustering notification, orphan msid: " + orphanMsid); inactiveList.add(new ManagementServerHostVO(orphanMsid, 0, "orphan", 0, new Date())); } } else { - s_logger.info("We are good, no orphan management server msid in host table is found"); + logger.info("We are good, no orphan management server msid in host table is found"); } if (inactiveList.size() > 0) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Found " + inactiveList.size() + " inactive management server node based on timestamp"); + if (logger.isInfoEnabled()) { + logger.info("Found " + inactiveList.size() + " inactive management server node based on timestamp"); for (final ManagementServerHostVO host : inactiveList) { - s_logger.info("management server node msid: " + host.getMsid() + ", name: " + host.getName() + ", service ip: " + host.getServiceIP() + + logger.info("management server node msid: " + host.getMsid() + ", name: " + host.getName() + ", service ip: " + host.getServiceIP() + ", version: " + host.getVersion()); } } @@ -825,7 +823,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C final List downHostList = new ArrayList(); for (final ManagementServerHostVO host : inactiveList) { if (!pingManagementNode(host)) { - s_logger.warn("Management node " + host.getId() + " is detected inactive by timestamp and also not pingable"); + logger.warn("Management node " + host.getId() + " is detected inactive by timestamp and also not pingable"); downHostList.add(host); } } @@ -834,7 +832,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeRemoved, downHostList)); } } else { - s_logger.info("No inactive management server node found"); + logger.info("No inactive management server node found"); } } @@ -859,7 +857,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C if (_mshostPeerDao.countStateSeenInPeers(_mshostId, _runId, ManagementServerHost.State.Down) > 0) { final String msg = "We have detected that at least one management server peer reports that this management server is down, perform active fencing to avoid split-brain situation"; - s_logger.error(msg); + logger.error(msg); throw new ActiveFencingException(msg); } @@ -869,24 +867,24 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C final ManagementServerHostVO current = getInListById(entry.getKey(), currentList); if (current == null) { if (entry.getKey().longValue() != _mshostId.longValue()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Detected management node left, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); + if (logger.isDebugEnabled()) { + logger.debug("Detected management node left, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); } removedNodeList.add(entry.getValue()); } } else { if (current.getRunid() == 0) { if (entry.getKey().longValue() != _mshostId.longValue()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Detected management node left because of invalidated session, id:" + entry.getKey() + ", nodeIP:" + + if (logger.isDebugEnabled()) { + logger.debug("Detected management node left because of invalidated session, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); } invalidatedNodeList.add(entry.getValue()); } } else { if (entry.getValue().getRunid() != current.getRunid()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Detected management node left and rejoined quickly, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); + if (logger.isDebugEnabled()) { + logger.debug("Detected management node left and rejoined quickly, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP()); } entry.getValue().setRunid(current.getRunid()); @@ -906,7 +904,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C try { JmxUtil.unregisterMBean("ClusterManager", "Node " + mshost.getId()); } catch (final Exception e) { - s_logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString()); + logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString()); } } @@ -921,15 +919,15 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C while (it.hasNext()) { final ManagementServerHostVO mshost = it.next(); if (!pingManagementNode(mshost)) { - s_logger.warn("Management node " + mshost.getId() + " is detected inactive by timestamp and also not pingable"); + logger.warn("Management node " + mshost.getId() + " is detected inactive by timestamp and also not pingable"); _activePeers.remove(mshost.getId()); try { JmxUtil.unregisterMBean("ClusterManager", "Node " + mshost.getId()); } catch (final Exception e) { - s_logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString()); + logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString()); } } else { - s_logger.info("Management node " + mshost.getId() + " is detected inactive by timestamp but is pingable"); + logger.info("Management node " + mshost.getId() + " is detected inactive by timestamp but is pingable"); it.remove(); } } @@ -944,15 +942,15 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C if (!_activePeers.containsKey(mshost.getId())) { _activePeers.put(mshost.getId(), mshost); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Detected management node joined, id:" + mshost.getId() + ", nodeIP:" + mshost.getServiceIP()); + if (logger.isDebugEnabled()) { + logger.debug("Detected management node joined, id:" + mshost.getId() + ", nodeIP:" + mshost.getServiceIP()); } newNodeList.add(mshost); try { JmxUtil.registerMBean("ClusterManager", "Node " + mshost.getId(), new ClusterManagerMBeanImpl(this, mshost)); } catch (final Exception e) { - s_logger.warn("Unable to register cluster node into JMX monitoring due to exception " + ExceptionUtil.toString(e)); + logger.warn("Unable to register cluster node into JMX monitoring due to exception " + ExceptionUtil.toString(e)); } } } @@ -964,8 +962,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C profiler.stop(); if (profiler.getDurationInMillis() >= HeartbeatInterval.value()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Peer scan takes too long to finish. profiler: " + profiler.toString() + ", profilerQueryActiveList: " + + if (logger.isDebugEnabled()) { + logger.debug("Peer scan takes too long to finish. profiler: " + profiler.toString() + ", profilerQueryActiveList: " + profilerQueryActiveList.toString() + ", profilerSyncClusterInfo: " + profilerSyncClusterInfo.toString() + ", profilerInvalidatedNodeList: " + profilerInvalidatedNodeList.toString() + ", profilerRemovedList: " + profilerRemovedList.toString()); } @@ -984,8 +982,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C @Override @DB public boolean start() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Starting Cluster manager, msid : " + _msId); + if (logger.isInfoEnabled()) { + logger.info("Starting Cluster manager, msid : " + _msId); } final ManagementServerHostVO mshost = Transaction.execute(new TransactionCallback() { @@ -1010,14 +1008,14 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C mshost.setState(ManagementServerHost.State.Up); mshost.setUuid(UUID.randomUUID().toString()); _mshostDao.persist(mshost); - if (s_logger.isInfoEnabled()) { - s_logger.info("New instance of management server msid " + _msId + ", runId " + _runId + " is being started"); + if (logger.isInfoEnabled()) { + logger.info("New instance of management server msid " + _msId + ", runId " + _runId + " is being started"); } } else { _mshostDao.update(mshost.getId(), _runId, NetUtils.getCanonicalHostName(), version, _clusterNodeIP, _currentServiceAdapter.getServicePort(), DateUtil.currentGMTTime()); - if (s_logger.isInfoEnabled()) { - s_logger.info("Management server " + _msId + ", runId " + _runId + " is being started"); + if (logger.isInfoEnabled()) { + logger.info("Management server " + _msId + ", runId " + _runId + " is being started"); } } @@ -1026,8 +1024,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C }); _mshostId = mshost.getId(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Management server (host id : " + _mshostId + ") is being started at " + _clusterNodeIP + ":" + _currentServiceAdapter.getServicePort()); + if (logger.isInfoEnabled()) { + logger.info("Management server (host id : " + _mshostId + ") is being started at " + _clusterNodeIP + ":" + _currentServiceAdapter.getServicePort()); } _mshostPeerDao.clearPeerInfo(_mshostId); @@ -1036,8 +1034,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C _heartbeatScheduler.scheduleAtFixedRate(getHeartbeatTask(), HeartbeatInterval.value(), HeartbeatInterval.value(), TimeUnit.MILLISECONDS); _notificationExecutor.submit(getNotificationTask()); - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster manager was started successfully"); + if (logger.isInfoEnabled()) { + logger.info("Cluster manager was started successfully"); } return true; @@ -1046,8 +1044,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C @Override @DB public boolean stop() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Stopping Cluster manager, msid : " + _msId); + if (logger.isInfoEnabled()) { + logger.info("Stopping Cluster manager, msid : " + _msId); } if (_mshostId != null) { @@ -1068,8 +1066,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } catch (final InterruptedException e) { } - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster manager is stopped"); + if (logger.isInfoEnabled()) { + logger.info("Cluster manager is stopped"); } return true; @@ -1077,8 +1075,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C @Override public boolean configure(final String name, final Map params) throws ConfigurationException { - if (s_logger.isInfoEnabled()) { - s_logger.info("Start configuring cluster manager : " + name); + if (logger.isInfoEnabled()) { + logger.info("Start configuring cluster manager : " + name); } final Properties dbProps = DbProperties.getDbProperties(); @@ -1088,8 +1086,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } _clusterNodeIP = _clusterNodeIP.trim(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster node IP : " + _clusterNodeIP); + if (logger.isInfoEnabled()) { + logger.info("Cluster node IP : " + _clusterNodeIP); } if (!NetUtils.isLocalAddress(_clusterNodeIP)) { @@ -1114,8 +1112,8 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C checkConflicts(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster manager is configured."); + if (logger.isInfoEnabled()) { + logger.info("Cluster manager is configured."); } return true; } @@ -1173,7 +1171,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C final String targetIp = mshost.getServiceIP(); if ("127.0.0.1".equals(targetIp) || "0.0.0.0".equals(targetIp)) { - s_logger.info("ping management node cluster service can not be performed on self"); + logger.info("ping management node cluster service can not be performed on self"); return false; } @@ -1181,7 +1179,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C while (--retry > 0) { SocketChannel sch = null; try { - s_logger.info("Trying to connect to " + targetIp); + logger.info("Trying to connect to " + targetIp); sch = SocketChannel.open(); sch.configureBlocking(true); sch.socket().setSoTimeout(5000); @@ -1191,9 +1189,9 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C return true; } catch (final IOException e) { if (e instanceof ConnectException) { - s_logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException"); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException", e); + logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException"); + if (logger.isDebugEnabled()) { + logger.debug("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " due to ConnectException", e); } return false; } @@ -1212,7 +1210,7 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C } } - s_logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " after retries"); + logger.error("Unable to ping management server at " + targetIp + ":" + mshost.getServicePort() + " after retries"); return false; } @@ -1229,25 +1227,25 @@ public class ClusterManagerImpl extends ManagerBase implements ClusterManager, C if ("127.0.0.1".equals(_clusterNodeIP)) { if (pingManagementNode(peer.getMsid())) { final String msg = "Detected another management node with localhost IP is already running, please check your cluster configuration"; - s_logger.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } else { final String msg = "Detected another management node with localhost IP is considered as running in DB, however it is not pingable, we will continue cluster initialization with this management server node"; - s_logger.info(msg); + logger.info(msg); } } else { if (pingManagementNode(peer.getMsid())) { final String msg = "Detected that another management node with the same IP " + peer.getServiceIP() + " is already running, please check your cluster configuration"; - s_logger.error(msg); + logger.error(msg); throw new ConfigurationException(msg); } else { final String msg = "Detected that another management node with the same IP " + peer.getServiceIP() + " is considered as running in DB, however it is not pingable, we will continue cluster initialization with this management server node"; - s_logger.info(msg); + logger.info(msg); } } } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletAdapter.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletAdapter.java index 7451b5f4226..937ef4a6249 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletAdapter.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletAdapter.java @@ -23,7 +23,6 @@ import java.util.Properties; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.config.ConfigDepot; import com.cloud.cluster.dao.ManagementServerHostDao; @@ -34,7 +33,6 @@ import com.cloud.utils.db.DbProperties; public class ClusterServiceServletAdapter extends AdapterBase implements ClusterServiceAdapter { - private static final Logger s_logger = Logger.getLogger(ClusterServiceServletAdapter.class); private static final int DEFAULT_SERVICE_PORT = 9090; private static final int DEFAULT_REQUEST_TIMEOUT = 300; // 300 seconds @@ -59,7 +57,7 @@ public class ClusterServiceServletAdapter extends AdapterBase implements Cluster try { init(); } catch (ConfigurationException e) { - s_logger.error("Unable to init ClusterServiceServletAdapter"); + logger.error("Unable to init ClusterServiceServletAdapter"); throw new RemoteException("Unable to init ClusterServiceServletAdapter"); } @@ -75,7 +73,7 @@ public class ClusterServiceServletAdapter extends AdapterBase implements Cluster try { init(); } catch (ConfigurationException e) { - s_logger.error("Unable to init ClusterServiceServletAdapter"); + logger.error("Unable to init ClusterServiceServletAdapter"); return null; } @@ -126,7 +124,7 @@ public class ClusterServiceServletAdapter extends AdapterBase implements Cluster Properties dbProps = DbProperties.getDbProperties(); _clusterServicePort = NumbersUtil.parseInt(dbProps.getProperty("cluster.servlet.port"), DEFAULT_SERVICE_PORT); - if (s_logger.isInfoEnabled()) - s_logger.info("Cluster servlet port : " + _clusterServicePort); + if (logger.isInfoEnabled()) + logger.info("Cluster servlet port : " + _clusterServicePort); } } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletContainer.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletContainer.java index 69cc871dc64..ac468089f47 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletContainer.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletContainer.java @@ -41,14 +41,14 @@ import org.apache.http.protocol.ResponseConnControl; import org.apache.http.protocol.ResponseContent; import org.apache.http.protocol.ResponseDate; import org.apache.http.protocol.ResponseServer; -import org.apache.log4j.Logger; import org.apache.cloudstack.managed.context.ManagedContextRunnable; import com.cloud.utils.concurrency.NamedThreadFactory; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class ClusterServiceServletContainer { - private static final Logger s_logger = Logger.getLogger(ClusterServiceServletContainer.class); private ListenerThread listenerThread; @@ -70,6 +70,8 @@ public class ClusterServiceServletContainer { } static class ListenerThread extends Thread { + + private static Logger LOGGER = LogManager.getLogger(ListenerThread.class); private HttpService _httpService = null; private volatile ServerSocket _serverSocket = null; private HttpParams _params = null; @@ -81,7 +83,7 @@ public class ClusterServiceServletContainer { try { _serverSocket = new ServerSocket(port); } catch (IOException ioex) { - s_logger.error("error initializing cluster service servlet container", ioex); + LOGGER.error("error initializing cluster service servlet container", ioex); return; } @@ -114,7 +116,7 @@ public class ClusterServiceServletContainer { try { _serverSocket.close(); } catch (IOException e) { - s_logger.info("[ignored] error on closing server socket", e); + LOGGER.info("[ignored] error on closing server socket", e); } _serverSocket = null; } @@ -122,8 +124,8 @@ public class ClusterServiceServletContainer { @Override public void run() { - if (s_logger.isInfoEnabled()) - s_logger.info("Cluster service servlet container listening on port " + _serverSocket.getLocalPort()); + if (LOGGER.isInfoEnabled()) + LOGGER.info("Cluster service servlet container listening on port " + _serverSocket.getLocalPort()); while (_serverSocket != null) { try { @@ -138,47 +140,47 @@ public class ClusterServiceServletContainer { HttpContext context = new BasicHttpContext(null); try { while (!Thread.interrupted() && conn.isOpen()) { - if (s_logger.isTraceEnabled()) - s_logger.trace("dispatching cluster request from " + conn.getRemoteAddress().toString()); + if (LOGGER.isTraceEnabled()) + LOGGER.trace("dispatching cluster request from " + conn.getRemoteAddress().toString()); _httpService.handleRequest(conn, context); - if (s_logger.isTraceEnabled()) - s_logger.trace("Cluster request from " + conn.getRemoteAddress().toString() + " is processed"); + if (LOGGER.isTraceEnabled()) + LOGGER.trace("Cluster request from " + conn.getRemoteAddress().toString() + " is processed"); } } catch (ConnectionClosedException ex) { // client close and read time out exceptions are expected // when KEEP-AVLIE is enabled - s_logger.trace("Client closed connection", ex); + LOGGER.trace("Client closed connection", ex); } catch (IOException ex) { - s_logger.trace("I/O error", ex); + LOGGER.trace("I/O error", ex); } catch (HttpException ex) { - s_logger.error("Unrecoverable HTTP protocol violation", ex); + LOGGER.error("Unrecoverable HTTP protocol violation", ex); } finally { try { conn.shutdown(); } catch (IOException ignore) { - s_logger.error("unexpected exception", ignore); + LOGGER.error("unexpected exception", ignore); } } } }); } catch (Throwable e) { - s_logger.error("Unexpected exception ", e); + LOGGER.error("Unexpected exception ", e); // back off to avoid spinning if the exception condition keeps coming back try { Thread.sleep(1000); } catch (InterruptedException e1) { - s_logger.debug("[ignored] interrupted while waiting to retry running the servlet container."); + LOGGER.debug("[ignored] interrupted while waiting to retry running the servlet container."); } } } _executor.shutdown(); - if (s_logger.isInfoEnabled()) - s_logger.info("Cluster service servlet container shutdown"); + if (LOGGER.isInfoEnabled()) + LOGGER.info("Cluster service servlet container shutdown"); } } } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletHttpHandler.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletHttpHandler.java index f697ade8a39..4e94f434f8f 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletHttpHandler.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletHttpHandler.java @@ -29,10 +29,11 @@ import org.apache.http.entity.BasicHttpEntity; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpRequestHandler; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class ClusterServiceServletHttpHandler implements HttpRequestHandler { - private static final Logger s_logger = Logger.getLogger(ClusterServiceServletHttpHandler.class); + protected Logger logger = LogManager.getLogger(getClass()); private final ClusterManager manager; @@ -44,27 +45,27 @@ public class ClusterServiceServletHttpHandler implements HttpRequestHandler { public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Start Handling cluster HTTP request"); + if (logger.isTraceEnabled()) { + logger.trace("Start Handling cluster HTTP request"); } parseRequest(request); handleRequest(request, response); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Handle cluster HTTP request done"); + if (logger.isTraceEnabled()) { + logger.trace("Handle cluster HTTP request done"); } } catch (final Throwable e) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Exception " + e.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Exception " + e.toString()); } try { writeResponse(response, HttpStatus.SC_INTERNAL_SERVER_ERROR, null); } catch (final Throwable e2) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Exception " + e2.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Exception " + e2.toString()); } } } @@ -88,8 +89,8 @@ public class ClusterServiceServletHttpHandler implements HttpRequestHandler { final String name = URLDecoder.decode(paramValue[0]); final String value = URLDecoder.decode(paramValue[1]); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Parsed request parameter " + name + "=" + value); + if (logger.isTraceEnabled()) { + logger.trace("Parsed request parameter " + name + "=" + value); } request.getParams().setParameter(name, value); } @@ -134,22 +135,22 @@ public class ClusterServiceServletHttpHandler implements HttpRequestHandler { case RemoteMethodConstants.METHOD_UNKNOWN: default: assert false; - s_logger.error("unrecognized method " + nMethod); + logger.error("unrecognized method " + nMethod); break; } } catch (final Throwable e) { - s_logger.error("Unexpected exception when processing cluster service request : ", e); + logger.error("Unexpected exception when processing cluster service request : ", e); } if (responseContent != null) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Write response with HTTP OK " + responseContent); + if (logger.isTraceEnabled()) { + logger.trace("Write response with HTTP OK " + responseContent); } writeResponse(response, HttpStatus.SC_OK, responseContent); } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Write response with HTTP Bad request"); + if (logger.isTraceEnabled()) { + logger.trace("Write response with HTTP Bad request"); } writeResponse(response, HttpStatus.SC_BAD_REQUEST, null); @@ -184,8 +185,8 @@ public class ClusterServiceServletHttpHandler implements HttpRequestHandler { private String handlePingMethodCall(HttpRequest req) { final String callingPeer = (String)req.getParams().getParameter("callingPeer"); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Handle ping request from " + callingPeer); + if (logger.isDebugEnabled()) { + logger.debug("Handle ping request from " + callingPeer); } return "true"; diff --git a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java index ec8b90866d0..b60012dbeef 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java @@ -25,13 +25,14 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.params.HttpClientParams; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.Profiler; public class ClusterServiceServletImpl implements ClusterService { private static final long serialVersionUID = 4574025200012566153L; - private static final Logger s_logger = Logger.getLogger(ClusterServiceServletImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private String _serviceUrl; @@ -41,7 +42,7 @@ public class ClusterServiceServletImpl implements ClusterService { } public ClusterServiceServletImpl(final String serviceUrl) { - s_logger.info("Setup cluster service servlet. service url: " + serviceUrl + ", request timeout: " + ClusterServiceAdapter.ClusterMessageTimeOut.value() + + logger.info("Setup cluster service servlet. service url: " + serviceUrl + ", request timeout: " + ClusterServiceAdapter.ClusterMessageTimeOut.value() + " seconds"); _serviceUrl = serviceUrl; @@ -68,8 +69,8 @@ public class ClusterServiceServletImpl implements ClusterService { @Override public boolean ping(final String callingPeer) throws RemoteException { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping at " + _serviceUrl); + if (logger.isDebugEnabled()) { + logger.debug("Ping at " + _serviceUrl); } final HttpClient client = getHttpClient(); @@ -95,20 +96,20 @@ public class ClusterServiceServletImpl implements ClusterService { if (response == HttpStatus.SC_OK) { result = method.getResponseBodyAsString(); profiler.stop(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("POST " + _serviceUrl + " response :" + result + ", responding time: " + profiler.getDurationInMillis() + " ms"); + if (logger.isDebugEnabled()) { + logger.debug("POST " + _serviceUrl + " response :" + result + ", responding time: " + profiler.getDurationInMillis() + " ms"); } } else { profiler.stop(); - s_logger.error("Invalid response code : " + response + ", from : " + _serviceUrl + ", method : " + method.getParameter("method") + " responding time: " + + logger.error("Invalid response code : " + response + ", from : " + _serviceUrl + ", method : " + method.getParameter("method") + " responding time: " + profiler.getDurationInMillis()); } } catch (final HttpException e) { - s_logger.error("HttpException from : " + _serviceUrl + ", method : " + method.getParameter("method")); + logger.error("HttpException from : " + _serviceUrl + ", method : " + method.getParameter("method")); } catch (final IOException e) { - s_logger.error("IOException from : " + _serviceUrl + ", method : " + method.getParameter("method")); + logger.error("IOException from : " + _serviceUrl + ", method : " + method.getParameter("method")); } catch (final Throwable e) { - s_logger.error("Exception from : " + _serviceUrl + ", method : " + method.getParameter("method") + ", exception :", e); + logger.error("Exception from : " + _serviceUrl + ", method : " + method.getParameter("method") + ", exception :", e); } finally { method.releaseConnection(); } diff --git a/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java b/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java index 715dfe26bae..7b69889c853 100644 --- a/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java +++ b/framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java @@ -26,7 +26,6 @@ import java.util.TimeZone; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import com.cloud.cluster.ClusterInvalidSessionException; import org.apache.cloudstack.management.ManagementServerHost; @@ -42,7 +41,6 @@ import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.exception.CloudRuntimeException; public class ManagementServerHostDaoImpl extends GenericDaoBase implements ManagementServerHostDao { - private static final Logger s_logger = Logger.getLogger(ManagementServerHostDaoImpl.class); private final SearchBuilder MsIdSearch; private final SearchBuilder ActiveSearch; @@ -99,7 +97,7 @@ public class ManagementServerHostDaoImpl extends GenericDaoBase implements ManagementServerHostPeerDao { - private static final Logger s_logger = Logger.getLogger(ManagementServerHostPeerDaoImpl.class); private final SearchBuilder ClearPeerSearch; private final SearchBuilder FindForUpdateSearch; @@ -85,7 +83,7 @@ public class ManagementServerHostPeerDaoImpl extends GenericDaoBase org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigDepot.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigDepot.java index 1ed37ab9969..b38b30e88b8 100644 --- a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigDepot.java +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigDepot.java @@ -31,4 +31,5 @@ public interface ConfigDepot { void set(ConfigKey key, T value); void createOrUpdateConfigObject(String componentName, ConfigKey key, String value); + boolean isNewConfig(ConfigKey configKey); } diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java index 192c556bd2a..df93f78fa83 100644 --- a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java @@ -34,6 +34,7 @@ public class ConfigKey { public static final String CATEGORY_ADVANCED = "Advanced"; public static final String CATEGORY_ALERT = "Alert"; + public static final String CATEGORY_NETWORK = "Network"; public enum Scope { Global, Zone, Cluster, StoragePool, Account, ManagementServer, ImageStore, Domain diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapper.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapper.java new file mode 100644 index 00000000000..b8d7e782971 --- /dev/null +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapper.java @@ -0,0 +1,114 @@ +// 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 org.apache.cloudstack.framework.config; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import static java.util.concurrent.TimeUnit.NANOSECONDS; + +/** + * Uses a ScheduledExecutorService and config key to execute a runnable, + * dynamically rescheduling based on the long value of the config key. + * Timing is similar to ScheduledExecutorService.scheduleAtFixedRate(), + * but we look up the next runtime dynamically via the config key. + *

+ * If config key is zero, this disables the execution. We skip execution + * and check once a minute in order to re-start execution if re-enabled. + */ +public class ConfigKeyScheduledExecutionWrapper implements Runnable { + protected Logger logger = LogManager.getLogger(getClass()); + private final ScheduledExecutorService executorService; + private final Runnable command; + private final ConfigKey configKey; + private final TimeUnit unit; + private long enableIntervalSeconds = 60; + + private void validateArgs(ScheduledExecutorService executorService, Runnable command, ConfigKey configKey) { + if (executorService == null) { + throw new IllegalArgumentException("ExecutorService cannot be null"); + } + if (command == null) { + throw new IllegalArgumentException("Command cannot be null"); + } + if (configKey == null) { + throw new IllegalArgumentException("ConfigKey cannot be null"); + } + if (!(configKey.value() instanceof Long || configKey.value() instanceof Integer)) { + throw new IllegalArgumentException("ConfigKey value must be a Long or Integer"); + } + } + + public ConfigKeyScheduledExecutionWrapper(ScheduledExecutorService executorService, Runnable command, + ConfigKey configKey, TimeUnit unit) { + validateArgs(executorService, command, configKey); + this.executorService = executorService; + this.command = command; + this.configKey = configKey; + this.unit = unit; + } + + protected ConfigKeyScheduledExecutionWrapper(ScheduledExecutorService executorService, Runnable command, + ConfigKey configKey, int enableIntervalSeconds, TimeUnit unit) { + validateArgs(executorService, command, configKey); + this.executorService = executorService; + this.command = command; + this.configKey = configKey; + this.unit = unit; + this.enableIntervalSeconds = enableIntervalSeconds; + } + + public ScheduledFuture start() { + long duration = getConfigValue(); + duration = duration < 0 ? 0 : duration; + return this.executorService.schedule(this, duration, this.unit); + } + + long getConfigValue() { + if (this.configKey.value() instanceof Long) { + return (Long) this.configKey.value(); + } else if (this.configKey.value() instanceof Integer) { + return (Integer) this.configKey.value(); + } else { + throw new IllegalArgumentException("ConfigKey value must be a Long or Integer"); + } + } + + @Override + public void run() { + if (getConfigValue() <= 0) { + executorService.schedule(this, enableIntervalSeconds, TimeUnit.SECONDS); + return; + } + + long startTime = System.nanoTime(); + try { + command.run(); + } catch (Throwable t) { + logger.warn(String.format("Last run of %s encountered an error", this.command.getClass()), t); + } finally { + long elapsed = System.nanoTime() - startTime; + long delay = this.unit.toNanos(getConfigValue()) - elapsed; + delay = delay > 0 ? delay : 0; + executorService.schedule(this, delay, NANOSECONDS); + } + } +} diff --git a/framework/config/src/main/java/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java b/framework/config/src/main/java/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java index 4e7b127a417..7c4a6f9a609 100644 --- a/framework/config/src/main/java/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java +++ b/framework/config/src/main/java/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java @@ -25,7 +25,6 @@ import javax.annotation.PostConstruct; import javax.naming.ConfigurationException; import org.apache.cloudstack.framework.config.impl.ConfigurationVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.component.ComponentLifecycle; @@ -39,7 +38,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @Component public class ConfigurationDaoImpl extends GenericDaoBase implements ConfigurationDao { - private static final Logger s_logger = Logger.getLogger(ConfigurationDaoImpl.class); private Map _configs = null; private boolean _premium; @@ -145,7 +143,7 @@ public class ConfigurationDaoImpl extends GenericDaoBase _configurables; List _scopedStorages; Set _configured = Collections.synchronizedSet(new HashSet()); + Set newConfigs = Collections.synchronizedSet(new HashSet<>()); private HashMap>> _allKeys = new HashMap>>(1007); @@ -125,7 +127,7 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { if (_configured.contains(configurable)) return; - s_logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName()); + logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName()); for (ConfigKey key : configurable.getConfigKeys()) { Pair> previous = _allKeys.get(key.key()); @@ -193,6 +195,7 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { } _configDao.persist(vo); + newConfigs.add(vo.getName()); } else { boolean configUpdated = false; if (vo.isDynamic() != key.isDynamic() || !ObjectUtils.equals(vo.getDescription(), key.description()) || !ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue()) || @@ -343,4 +346,9 @@ public class ConfigDepotImpl implements ConfigDepot, ConfigDepotAdmin { return new Pair<>(groupId, subGroupId); } + + @Override + public boolean isNewConfig(ConfigKey configKey) { + return newConfigs.contains(configKey.key()); + } } diff --git a/framework/config/src/test/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapperTest.java b/framework/config/src/test/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapperTest.java new file mode 100644 index 00000000000..fbb4dc24fca --- /dev/null +++ b/framework/config/src/test/java/org/apache/cloudstack/framework/config/ConfigKeyScheduledExecutionWrapperTest.java @@ -0,0 +1,177 @@ +// 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 org.apache.cloudstack.framework.config; + +import com.cloud.utils.concurrency.NamedThreadFactory; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.isOneOf; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigKeyScheduledExecutionWrapperTest { + private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1, new NamedThreadFactory("TestExecutor")); + + @Mock + ConfigKey configKey; + + @Test(expected = IllegalArgumentException.class) + public void nullExecutorTest() { + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(null, runnable, configKey, TimeUnit.SECONDS); + } + + @Test(expected = IllegalArgumentException.class) + public void nullCommandTest() { + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, null, configKey, TimeUnit.SECONDS); + } + + @Test(expected = IllegalArgumentException.class) + public void nullConfigKeyTest() { + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, null, TimeUnit.SECONDS); + } + + @Test(expected = IllegalArgumentException.class) + public void invalidConfigKeyTest() { + TestRunnable runnable = new TestRunnable(); + ConfigKey configKey = new ConfigKey<>(String.class, "test", "test", "test", "test", true, + ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.SECONDS); + } + + @Test + public void scheduleOncePerSecondTest() { + when(configKey.value()).thenReturn(1); + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.SECONDS); + runner.start(); + + waitSeconds(3); + assertThat("Runnable ran once per second", runnable.getRunCount(), isOneOf(2, 3)); + } + + private void waitSeconds(int seconds) { + try { + Thread.sleep(seconds * 1000L + 100); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + @Test + public void scheduleTwicePerSecondTest() { + when(configKey.value()).thenReturn(500); + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.MILLISECONDS); + runner.start(); + + waitSeconds(2); + assertThat("Runnable ran twice per second", runnable.getRunCount(), isOneOf(3, 4)); + } + + @Test + public void scheduleDynamicTest() { + // start with twice per second, then switch to four times per second + when(configKey.value()).thenReturn(500); + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.MILLISECONDS); + runner.start(); + + waitSeconds(2); + assertThat("Runnable ran twice per second", runnable.getRunCount(), isOneOf(3, 4)); + + runnable.resetRunCount(); + when(configKey.value()).thenReturn(250); + waitSeconds(2); + assertThat("Runnable ran four times per second", runnable.getRunCount(), isOneOf(7, 8)); + } + + @Test + public void noOverlappingRunsTest() { + when(configKey.value()).thenReturn(200); + TestRunnable runnable = new TestRunnable(1); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, TimeUnit.MILLISECONDS); + runner.start(); + + waitSeconds(3); + assertThat("Slow runnable on tight schedule runs without overlap", runnable.getRunCount(), isOneOf(2, 3)); + } + + @Test + public void temporaryDisableRunsTest() { + // start with twice per second, then disable, then start again + when(configKey.value()).thenReturn(500); + TestRunnable runnable = new TestRunnable(); + ConfigKeyScheduledExecutionWrapper runner = new ConfigKeyScheduledExecutionWrapper(executorService, runnable, configKey, 1, TimeUnit.MILLISECONDS); + runner.start(); + + waitSeconds(2); + assertThat("Runnable ran twice per second", runnable.getRunCount(), isOneOf(3, 4)); + + runnable.resetRunCount(); + when(configKey.value()).thenReturn(0); + waitSeconds(2); + assertThat("Runnable ran zero times per second", runnable.getRunCount(), is(0)); + + runnable.resetRunCount(); + when(configKey.value()).thenReturn(500); + waitSeconds(2); + assertThat("Runnable ran twice per second", runnable.getRunCount(), isOneOf(3, 4)); + } + + static class TestRunnable implements Runnable { + private Integer runCount = 0; + private int waitSeconds = 0; + + TestRunnable(int waitSeconds) { + this.waitSeconds = waitSeconds; + } + + TestRunnable() { + } + + @Override + public void run() { + runCount++; + if (waitSeconds > 0) { + try { + Thread.sleep(waitSeconds * 1000L); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + + public int getRunCount() { + return this.runCount; + } + + public void resetRunCount() { + this.runCount = 0; + } + } +} diff --git a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java index 54e30ebed95..476e378cf57 100644 --- a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java +++ b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotAdminTest.java @@ -17,7 +17,7 @@ package org.apache.cloudstack.framework.config.impl; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -28,6 +28,7 @@ import junit.framework.TestCase; import org.apache.cloudstack.framework.config.dao.ConfigurationGroupDao; import org.apache.cloudstack.framework.config.dao.ConfigurationSubGroupDao; +import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -74,13 +75,15 @@ public class ConfigDepotAdminTest extends TestCase { @Mock ScopedConfigStorage _scopedStorage; + private AutoCloseable closeable; + /** * @throws java.lang.Exception */ @Override @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); _depotAdmin = new ConfigDepotImpl(); _depotAdmin._configDao = _configDao; _depotAdmin._configGroupDao = _configGroupDao; @@ -91,6 +94,12 @@ public class ConfigDepotAdminTest extends TestCase { _depotAdmin._scopedStorages.add(_scopedStorage); } + @Override + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testAutoPopulation() { ConfigurationVO dynamicIntCV = new ConfigurationVO("UnitTestComponent", DynamicIntCK); diff --git a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java index fed784cfe2d..8dd6f71af3c 100644 --- a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java +++ b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java @@ -18,9 +18,14 @@ // package org.apache.cloudstack.framework.config.impl; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + import org.apache.cloudstack.framework.config.ConfigKey; import org.junit.Assert; import org.junit.Test; +import org.springframework.test.util.ReflectionTestUtils; public class ConfigDepotImplTest { @@ -40,4 +45,16 @@ public class ConfigDepotImplTest { } } + @Test + public void testIsNewConfig() { + String validNewConfigKey = "CONFIG"; + ConfigKey validNewConfig = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class, "CONFIG", "true", "", true); + ConfigKey invalidNewConfig = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED, Boolean.class, "CONFIG1", "true", "", true); + Set newConfigs = Collections.synchronizedSet(new HashSet<>()); + newConfigs.add(validNewConfigKey); + ReflectionTestUtils.setField(configDepotImpl, "newConfigs", newConfigs); + Assert.assertTrue(configDepotImpl.isNewConfig(validNewConfig)); + Assert.assertFalse(configDepotImpl.isNewConfig(invalidNewConfig)); + } + } diff --git a/framework/db/pom.xml b/framework/db/pom.xml index 846c9007708..d4d3b6b8772 100644 --- a/framework/db/pom.xml +++ b/framework/db/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/db/src/main/java/com/cloud/utils/db/Attribute.java b/framework/db/src/main/java/com/cloud/utils/db/Attribute.java index 82c2bdbaa79..3e5128d97b4 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/Attribute.java +++ b/framework/db/src/main/java/com/cloud/utils/db/Attribute.java @@ -81,6 +81,7 @@ public class Attribute { protected String table; protected String columnName; + protected Object value; protected Field field; protected int flags; protected Column column; @@ -100,6 +101,10 @@ public class Attribute { this.column = null; } + public Attribute(Object value) { + this.value = value; + } + protected void setupColumnInfo(Class clazz, AttributeOverride[] overrides, String tableName, boolean isEmbedded, boolean isId) { flags = Flag.Selectable.setTrue(flags); GeneratedValue gv = field.getAnnotation(GeneratedValue.class); @@ -214,6 +219,10 @@ public class Attribute { return field; } + public Object getValue() { + return value; + } + public Object get(Object entity) { try { return field.get(entity); diff --git a/framework/db/src/main/java/com/cloud/utils/db/ConnectionConcierge.java b/framework/db/src/main/java/com/cloud/utils/db/ConnectionConcierge.java index 2ae0de90f26..7cf34e6955c 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/ConnectionConcierge.java +++ b/framework/db/src/main/java/com/cloud/utils/db/ConnectionConcierge.java @@ -30,7 +30,8 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.management.StandardMBean; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.managed.context.ManagedContextRunnable; @@ -45,9 +46,9 @@ import com.cloud.utils.mgmt.JmxUtil; */ public class ConnectionConcierge { - static final Logger s_logger = Logger.getLogger(ConnectionConcierge.class); + protected Logger logger = LogManager.getLogger(getClass()); - static final ConnectionConciergeManager s_mgr = new ConnectionConciergeManager(); + private final ConnectionConciergeManager sMgr = new ConnectionConciergeManager(); Connection _conn; String _name; @@ -57,7 +58,7 @@ public class ConnectionConcierge { int _holdability; public ConnectionConcierge(String name, Connection conn, boolean keepAlive) { - _name = name + s_mgr.getNextId(); + _name = name + sMgr.getNextId(); _keepAlive = keepAlive; try { _autoCommit = conn.getAutoCommit(); @@ -73,7 +74,7 @@ public class ConnectionConcierge { try { release(); } catch (Throwable th) { - s_logger.error("Unable to release a connection", th); + logger.error("Unable to release a connection", th); } _conn = conn; try { @@ -81,10 +82,10 @@ public class ConnectionConcierge { _conn.setHoldability(_holdability); _conn.setTransactionIsolation(_isolationLevel); } catch (SQLException e) { - s_logger.error("Unable to release a connection", e); + logger.error("Unable to release a connection", e); } - s_mgr.register(_name, this); - s_logger.debug("Registering a database connection for " + _name); + sMgr.register(_name, this); + logger.debug("Registering a database connection for " + _name); } public final Connection conn() { @@ -92,7 +93,7 @@ public class ConnectionConcierge { } public void release() { - s_mgr.unregister(_name); + sMgr.unregister(_name); try { if (_conn != null) { _conn.close(); @@ -114,7 +115,7 @@ public class ConnectionConcierge { return _keepAlive; } - protected static class ConnectionConciergeManager extends StandardMBean implements ConnectionConciergeMBean { + protected class ConnectionConciergeManager extends StandardMBean implements ConnectionConciergeMBean { ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ConnectionKeeper")); final ConcurrentHashMap _conns = new ConcurrentHashMap(); final AtomicInteger _idGenerator = new AtomicInteger(); @@ -125,7 +126,7 @@ public class ConnectionConcierge { try { JmxUtil.registerMBean("DB Connections", "DB Connections", this); } catch (Exception e) { - s_logger.error("Unable to register mbean", e); + logger.error("Unable to register mbean", e); } } @@ -147,7 +148,7 @@ public class ConnectionConcierge { try (PreparedStatement pstmt = conn.prepareStatement("SELECT 1");) { pstmt.executeQuery(); } catch (Throwable th) { - s_logger.error("Unable to keep the db connection for " + name, th); + logger.error("Unable to keep the db connection for " + name, th); return th.toString(); } } @@ -187,7 +188,7 @@ public class ConnectionConcierge { try { _executor.shutdown(); } catch (Exception e) { - s_logger.error("Unable to shutdown executor", e); + logger.error("Unable to shutdown executor", e); } } @@ -196,13 +197,13 @@ public class ConnectionConcierge { _executor.scheduleAtFixedRate(new ManagedContextRunnable() { @Override protected void runInContext() { - s_logger.trace("connection concierge keep alive task"); + logger.trace("connection concierge keep alive task"); for (Map.Entry entry : _conns.entrySet()) { String name = entry.getKey(); ConnectionConcierge concierge = entry.getValue(); if (concierge.keepAlive()) { if (testValidity(name, concierge.conn()) != null) { - s_logger.info("Resetting DB connection " + name); + logger.info("Resetting DB connection " + name); resetConnection(name); } } diff --git a/framework/db/src/main/java/com/cloud/utils/db/DbUtil.java b/framework/db/src/main/java/com/cloud/utils/db/DbUtil.java index 68424bc5dd9..88397f54d4f 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/DbUtil.java +++ b/framework/db/src/main/java/com/cloud/utils/db/DbUtil.java @@ -41,12 +41,13 @@ import javax.persistence.SecondaryTables; import javax.persistence.Table; import javax.persistence.Transient; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import static com.cloud.utils.AutoCloseableUtil.closeAutoCloseable; public class DbUtil { - protected final static Logger LOGGER = Logger.getLogger(DbUtil.class); + protected static Logger LOGGER = LogManager.getLogger(DbUtil.class); private static Map s_connectionForGlobalLocks = new HashMap(); diff --git a/framework/db/src/main/java/com/cloud/utils/db/DriverLoader.java b/framework/db/src/main/java/com/cloud/utils/db/DriverLoader.java index 55fc1dbb6ed..ac783fa046f 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/DriverLoader.java +++ b/framework/db/src/main/java/com/cloud/utils/db/DriverLoader.java @@ -23,13 +23,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.exception.CloudRuntimeException; public class DriverLoader { - private static final Logger LOGGER = Logger.getLogger(DriverLoader.class.getName()); + protected static Logger LOGGER = LogManager.getLogger(DriverLoader.class); private static final List LOADED_DRIVERS; private static final Map DRIVERS; diff --git a/framework/db/src/main/java/com/cloud/utils/db/GenericDao.java b/framework/db/src/main/java/com/cloud/utils/db/GenericDao.java index b2a9e6f733a..2fc02301cb7 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/GenericDao.java +++ b/framework/db/src/main/java/com/cloud/utils/db/GenericDao.java @@ -286,4 +286,6 @@ public interface GenericDao { Pair, Integer> searchAndDistinctCount(final SearchCriteria sc, final Filter filter, final String[] distinctColumns); Integer countAll(); + + List findByUuids(String... uuidArray); } diff --git a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java index 6bf36df0941..a09f323905e 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java +++ b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java @@ -42,13 +42,16 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.TimeZone; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import javax.naming.ConfigurationException; +import javax.persistence.AttributeConverter; import javax.persistence.AttributeOverride; import javax.persistence.Column; +import javax.persistence.Convert; import javax.persistence.EmbeddedId; import javax.persistence.EntityExistsException; import javax.persistence.EnumType; @@ -56,7 +59,8 @@ import javax.persistence.Enumerated; import javax.persistence.Table; import javax.persistence.TableGenerator; -import org.apache.log4j.Logger; +import com.amazonaws.util.CollectionUtils; +import org.apache.commons.lang3.ArrayUtils; import com.cloud.utils.DateUtil; import com.cloud.utils.NumbersUtil; @@ -118,11 +122,11 @@ import net.sf.ehcache.Element; **/ @DB public abstract class GenericDaoBase extends ComponentLifecycleBase implements GenericDao, ComponentMethodInterceptable { - private final static Logger s_logger = Logger.getLogger(GenericDaoBase.class); protected final static TimeZone s_gmtTimeZone = TimeZone.getTimeZone("GMT"); protected final static Map, GenericDao> s_daoMaps = new ConcurrentHashMap, GenericDao>(71); + private final ConversionSupport _conversionSupport; protected Class _entityBeanType; protected String _table; @@ -264,29 +268,30 @@ public abstract class GenericDaoBase extends Compone _searchEnhancer.setSuperclass(_entityBeanType); _searchEnhancer.setCallback(new UpdateBuilder(this)); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Select SQL: " + _partialSelectSql.first().toString()); - s_logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql")); - s_logger.trace("Select by Id SQL: " + _selectByIdSql); - s_logger.trace("Table References: " + _tables); - s_logger.trace("Insert SQLs:"); + if (logger.isTraceEnabled()) { + logger.trace("Select SQL: " + _partialSelectSql.first().toString()); + logger.trace("Remove SQL: " + (_removeSql != null ? _removeSql.first() : "No remove sql")); + logger.trace("Select by Id SQL: " + _selectByIdSql); + logger.trace("Table References: " + _tables); + logger.trace("Insert SQLs:"); for (final Pair insertSql : _insertSqls) { - s_logger.trace(insertSql.first()); + logger.trace(insertSql.first()); } - s_logger.trace("Delete SQLs"); + logger.trace("Delete SQLs"); for (final Pair deletSql : _deleteSqls) { - s_logger.trace(deletSql.first()); + logger.trace(deletSql.first()); } - s_logger.trace("Collection SQLs"); + logger.trace("Collection SQLs"); for (Attribute attr : _ecAttributes) { EcInfo info = (EcInfo)attr.attache; - s_logger.trace(info.insertSql); - s_logger.trace(info.selectSql); + logger.trace(info.insertSql); + logger.trace(info.selectSql); } } + _conversionSupport = new ConversionSupport(); setRunLevel(ComponentLifecycle.RUN_LEVEL_SYSTEM); } @@ -373,10 +378,11 @@ public abstract class GenericDaoBase extends Compone } Collection>> joins = null; + List joinAttrList = null; if (sc != null) { joins = sc.getJoins(); if (joins != null) { - addJoins(str, joins); + joinAttrList = addJoins(str, joins); } } @@ -396,6 +402,13 @@ public abstract class GenericDaoBase extends Compone try { pstmt = txn.prepareAutoCloseStatement(sql); int i = 1; + + if (!CollectionUtils.isNullOrEmpty(joinAttrList)) { + for (Attribute attr : joinAttrList) { + prepareAttribute(i++, pstmt, attr, null); + } + } + if (clause != null) { for (final Pair value : sc.getValues()) { prepareAttribute(i++, pstmt, value.first(), value.second()); @@ -412,7 +425,7 @@ public abstract class GenericDaoBase extends Compone } } - if (s_logger.isDebugEnabled() && lock != null) { + if (logger.isDebugEnabled() && lock != null) { txn.registerLock(pstmt.toString()); } final ResultSet rs = pstmt.executeQuery(); @@ -448,8 +461,9 @@ public abstract class GenericDaoBase extends Compone Collection>> joins = null; joins = sc.getJoins(); + List joinAttrList = null; if (joins != null) { - addJoins(str, joins); + joinAttrList = addJoins(str, joins); } List groupByValues = addGroupBy(str, sc); @@ -462,6 +476,13 @@ public abstract class GenericDaoBase extends Compone try { pstmt = txn.prepareAutoCloseStatement(sql); int i = 1; + + if (!CollectionUtils.isNullOrEmpty(joinAttrList)) { + for (Attribute attr : joinAttrList) { + prepareAttribute(i++, pstmt, attr, null); + } + } + if (clause != null) { for (final Pair value : sc.getValues()) { prepareAttribute(i++, pstmt, value.first(), value.second()); @@ -649,6 +670,9 @@ public abstract class GenericDaoBase extends Compone } } else if (type == byte[].class) { field.set(entity, rs.getBytes(index)); + } else if (field.getDeclaredAnnotation(Convert.class) != null) { + Object val = _conversionSupport.convertToEntityAttribute(field, rs.getObject(index)); + field.set(entity, val); } else { field.set(entity, rs.getObject(index)); } @@ -776,8 +800,8 @@ public abstract class GenericDaoBase extends Compone } } - if (s_logger.isTraceEnabled()) { - s_logger.trace("join search statement is " + pstmt); + if (logger.isTraceEnabled()) { + logger.trace("join search statement is " + pstmt); } return count; } @@ -874,7 +898,7 @@ public abstract class GenericDaoBase extends Compone if (_idField.getAnnotation(EmbeddedId.class) == null) { sql.append(_table).append(".").append(DbUtil.getColumnName(_idField, null)).append(" = ? "); } else { - s_logger.debug(String.format("field type vs declarator : %s vs %s", _idField.getType(), _idField.getDeclaringClass())); + logger.debug(String.format("field type vs declarator : %s vs %s", _idField.getType(), _idField.getDeclaringClass())); final Class clazz = _idField.getType(); final AttributeOverride[] overrides = DbUtil.getAttributeOverrides(_idField); for (final Field field : clazz.getDeclaredFields()) { @@ -1272,12 +1296,13 @@ public abstract class GenericDaoBase extends Compone } @DB() - protected void addJoins(StringBuilder str, Collection>> joins) { - addJoins(str, joins, new HashMap<>()); + protected List addJoins(StringBuilder str, Collection>> joins) { + return addJoins(str, joins, new HashMap<>()); } @DB() - protected void addJoins(StringBuilder str, Collection>> joins, Map joinedTableNames) { + protected List addJoins(StringBuilder str, Collection>> joins, Map joinedTableNames) { + List joinAttrList = new ArrayList<>(); boolean hasWhereClause = true; int fromIndex = str.lastIndexOf("WHERE"); if (fromIndex == -1) { @@ -1288,8 +1313,14 @@ public abstract class GenericDaoBase extends Compone } for (JoinBuilder> join : joins) { - String joinTableName = join.getSecondAttribute().table; - String joinTableAlias = findNextJoinTableName(joinTableName, joinedTableNames); + String joinTableName = join.getSecondAttribute()[0].table; + String joinTableAlias; + if (StringUtils.isNotEmpty(join.getName())) { + joinTableAlias = join.getName(); + joinedTableNames.put(joinTableName, joinTableAlias); + } else { + joinTableAlias = joinedTableNames.getOrDefault(joinTableName, joinTableName); + } StringBuilder onClause = new StringBuilder(); onClause.append(" ") .append(join.getType().getName()) @@ -1298,21 +1329,36 @@ public abstract class GenericDaoBase extends Compone if (!joinTableAlias.equals(joinTableName)) { onClause.append(" ").append(joinTableAlias); } - onClause.append(" ON ") - .append(join.getFirstAttribute().table) - .append(".") - .append(join.getFirstAttribute().columnName) - .append("="); - if(!joinTableAlias.equals(joinTableName)) { - onClause.append(joinTableAlias); - } else { - onClause.append(joinTableName); + onClause.append(" ON "); + for (int i = 0; i < join.getFirstAttributes().length; i++) { + if (i > 0) { + onClause.append(join.getCondition().getName()); + } + if (join.getFirstAttributes()[i].getValue() != null) { + onClause.append("?"); + joinAttrList.add(join.getFirstAttributes()[i]); + } else { + onClause.append(joinedTableNames.getOrDefault(join.getFirstAttributes()[i].table, join.getFirstAttributes()[i].table)) + .append(".") + .append(join.getFirstAttributes()[i].columnName); + } + onClause.append("="); + if (join.getSecondAttribute()[i].getValue() != null) { + onClause.append("?"); + joinAttrList.add(join.getSecondAttribute()[i]); + } else { + if(!joinTableAlias.equals(joinTableName)) { + onClause.append(joinTableAlias); + } else { + onClause.append(joinTableName); + } + onClause.append(".") + .append(join.getSecondAttribute()[i].columnName); + } } - onClause.append(".") - .append(join.getSecondAttribute().columnName) - .append(" "); + onClause.append(" "); str.insert(fromIndex, onClause); - String whereClause = join.getT().getWhereClause(); + String whereClause = join.getT().getWhereClause(joinTableAlias); if (StringUtils.isNotEmpty(whereClause)) { if (!hasWhereClause) { str.append(" WHERE "); @@ -1329,20 +1375,10 @@ public abstract class GenericDaoBase extends Compone for (JoinBuilder> join : joins) { if (join.getT().getJoins() != null) { - addJoins(str, join.getT().getJoins(), joinedTableNames); + joinAttrList.addAll(addJoins(str, join.getT().getJoins(), joinedTableNames)); } } - } - - protected static String findNextJoinTableName(String tableName, Map usedTableNames) { - if (usedTableNames.containsKey(tableName)) { - Integer tableCounter = usedTableNames.get(tableName); - usedTableNames.put(tableName, ++tableCounter); - tableName = tableName + tableCounter; - } else { - usedTableNames.put(tableName, 0); - } - return tableName; + return joinAttrList; } private void removeAndClause(StringBuilder sql) { @@ -1386,9 +1422,9 @@ public abstract class GenericDaoBase extends Compone } String stackTrace = ExceptionUtils.getStackTrace(new CloudRuntimeException(String.format("The query to count all the records of [%s] resulted in a value smaller than" - + " the result set's size [count of records: %s, result set's size: %s]. Using the result set's size instead.", _entityBeanType, + + " the result set's size [count of records: %s, result set's size: %s]. Using the result set's size instead.", _entityBeanType, count, resultSetSize))); - s_logger.warn(stackTrace); + logger.warn(stackTrace); return resultSetSize; } @@ -1496,9 +1532,9 @@ public abstract class GenericDaoBase extends Compone } else { _idField.set(entity, id); } - } else { - id = (ID)_idField.get(entity); } + + id = (ID)_idField.get(entity); } } catch (final IllegalAccessException e) { throw new CloudRuntimeException("Yikes! ", e); @@ -1595,10 +1631,32 @@ public abstract class GenericDaoBase extends Compone return; } } - if (attr.field.getType() == String.class) { - final String str = (String)value; - if (str == null) { - pstmt.setString(j, null); + + if (attr.getValue() != null && attr.getValue() instanceof String) { + pstmt.setString(j, (String)attr.getValue()); + } else if (attr.getValue() != null && attr.getValue() instanceof Long) { + pstmt.setLong(j, (Long)attr.getValue()); + } else if(attr.field.getDeclaredAnnotation(Convert.class) != null) { + if (value instanceof String) { + pstmt.setString(j, (String)value); + } else { + Object val = _conversionSupport.convertToDatabaseColumn(attr.field, value); + pstmt.setObject(j, val); + } + } else if (attr.field.getType() == String.class) { + final String str; + try { + str = (String) value; + if (str == null) { + pstmt.setString(j, null); + return; + } + } catch (ClassCastException ex) { + // This happens when we pass in an integer, long or any other object which can't be cast to String. + // Converting to string in case of integer or long can result in different results. Required specifically for details tables. + // So, we set the value for the object directly. + logger.debug("ClassCastException when casting value to String. Setting the value of the object directly."); + pstmt.setObject(j, value); return; } final Column column = attr.field.getAnnotation(Column.class); @@ -1719,7 +1777,7 @@ public abstract class GenericDaoBase extends Compone try { _cache.put(new Element(_idField.get(entity), entity)); } catch (final Exception e) { - s_logger.debug("Can't put it in the cache", e); + logger.debug("Can't put it in the cache", e); } } @@ -1741,7 +1799,7 @@ public abstract class GenericDaoBase extends Compone try { _cache.put(new Element(_idField.get(entity), entity)); } catch (final Exception e) { - s_logger.debug("Can't put it in the cache", e); + logger.debug("Can't put it in the cache", e); } } @@ -1948,7 +2006,7 @@ public abstract class GenericDaoBase extends Compone final int idle = NumbersUtil.parseInt((String)params.get("cache.time.to.idle"), 300); _cache = new Cache(getName(), maxElements, false, live == -1, live == -1 ? Integer.MAX_VALUE : live, idle); cm.addCache(_cache); - s_logger.info("Cache created: " + _cache.toString()); + logger.info("Cache created: " + _cache.toString()); } else { _cache = null; } @@ -2018,10 +2076,11 @@ public abstract class GenericDaoBase extends Compone } Collection>> joins = null; + List joinAttrList = null; if (sc != null) { joins = sc.getJoins(); if (joins != null) { - addJoins(str, joins); + joinAttrList = addJoins(str, joins); } } @@ -2034,6 +2093,13 @@ public abstract class GenericDaoBase extends Compone try { pstmt = txn.prepareAutoCloseStatement(sql); int i = 1; + + if (!CollectionUtils.isNullOrEmpty(joinAttrList)) { + for (Attribute attr : joinAttrList) { + prepareAttribute(i++, pstmt, attr, null); + } + } + if (clause != null) { for (final Pair value : sc.getValues()) { prepareAttribute(i++, pstmt, value.first(), value.second()); @@ -2081,10 +2147,11 @@ public abstract class GenericDaoBase extends Compone } Collection>> joins = null; + List joinAttrList = null; if (sc != null) { joins = sc.getJoins(); if (joins != null) { - addJoins(str, joins); + joinAttrList = addJoins(str, joins); } } @@ -2093,6 +2160,13 @@ public abstract class GenericDaoBase extends Compone try (PreparedStatement pstmt = txn.prepareAutoCloseStatement(sql)) { int i = 1; + + if (!CollectionUtils.isNullOrEmpty(joinAttrList)) { + for (Attribute attr : joinAttrList) { + prepareAttribute(i++, pstmt, attr, null); + } + } + if (clause != null) { for (final Pair value : sc.getValues()) { prepareAttribute(i++, pstmt, value.first(), value.second()); @@ -2119,6 +2193,16 @@ public abstract class GenericDaoBase extends Compone return getCount(null); } + @Override + public List findByUuids(String... uuidArray) { + if (ArrayUtils.isEmpty(uuidArray)) { + return new ArrayList(); + } + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("uuid", SearchCriteria.Op.IN, uuidArray); + return search(sc, null); + } + public Integer getCount(SearchCriteria sc) { sc = checkAndSetRemovedIsNull(sc); return getCountIncludingRemoved(sc); @@ -2136,10 +2220,11 @@ public abstract class GenericDaoBase extends Compone } Collection>> joins = null; + List joinAttrList = null; if (sc != null) { joins = sc.getJoins(); if (joins != null) { - addJoins(str, joins); + joinAttrList = addJoins(str, joins); } } @@ -2150,6 +2235,13 @@ public abstract class GenericDaoBase extends Compone try { pstmt = txn.prepareAutoCloseStatement(sql); int i = 1; + + if (!CollectionUtils.isNullOrEmpty(joinAttrList)) { + for (Attribute attr : joinAttrList) { + prepareAttribute(i++, pstmt, attr, null); + } + } + if (clause != null) { for (final Pair value : sc.getValues()) { prepareAttribute(i++, pstmt, value.first(), value.second()); @@ -2221,4 +2313,50 @@ public abstract class GenericDaoBase extends Compone return sql; } + + /** + * Support conversion between DB and Entity values. + * Detects whether field is annotated with {@link Convert} annotation and use converter instance from the annotation. + */ + static class ConversionSupport { + /** + * Contains cache of {@link AttributeConverter} instances. + */ + private static final Map, AttributeConverter> s_converterCacheMap = new ConcurrentHashMap<>(); + + /** + * Checks whether field annotated with {@link Convert} annotation and tries to convert source value with converter. + * + * @param field Entity field + * @param value DB value + * @return converted value if field is annotated with {@link Convert} or original value otherwise + */ + private T convertToEntityAttribute(Field field, Object value) { + return (T) getConverter(field).map(converter -> converter.convertToEntityAttribute(value)).orElse(value); + } + + /** + * Checks whether field annotated with {@link Convert} annotation and tries to convert source value with converter. + * + * @param field Entity field + * @param value Entity value + * @return converted value if field is annotated with {@link Convert} or original value otherwise + */ + private T convertToDatabaseColumn(Field field, Object value) { + return (T) getConverter(field).map(converter -> converter.convertToDatabaseColumn(value)).orElse(value); + } + + private Optional> getConverter(Field field) { + return Optional.of(field).map(f -> f.getAnnotation(Convert.class)).map(Convert::converter).filter(AttributeConverter.class::isAssignableFrom).map(converterType -> { + return (AttributeConverter) s_converterCacheMap.computeIfAbsent(converterType, ct -> { + try { + return (AttributeConverter) ct.getDeclaredConstructor().newInstance(); + } catch (ReflectiveOperationException e) { + throw new CloudRuntimeException("Unable to create converter for the class " + converterType, e); + } + }); + }); + } + } + } diff --git a/framework/db/src/main/java/com/cloud/utils/db/GenericSearchBuilder.java b/framework/db/src/main/java/com/cloud/utils/db/GenericSearchBuilder.java index df6f1f7602f..f4385efb3b8 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/GenericSearchBuilder.java +++ b/framework/db/src/main/java/com/cloud/utils/db/GenericSearchBuilder.java @@ -80,6 +80,12 @@ public class GenericSearchBuilder extends SearchBase and(String joinName, String name, Object field, Op op) { + SearchBase join = _joins.get(joinName).getT(); + constructCondition(joinName, name, " AND ", join._specifiedAttrs.get(0), op); + return this; + } + /** * Adds an AND condition. Some prefer this method because it looks like * the actual SQL query. @@ -134,6 +140,12 @@ public class GenericSearchBuilder extends SearchBase left(String joinName, Object field, Op op, String name) { + SearchBase joinSb = _joins.get(joinName).getT(); + constructCondition(joinName, name, " ( ", joinSb._specifiedAttrs.get(0), op); + return this; + } + protected Preset left(Object field, Op op) { Condition condition = constructCondition(UUID.randomUUID().toString(), " ( ", _specifiedAttrs.get(0), op); return new Preset(this, condition); @@ -169,6 +181,10 @@ public class GenericSearchBuilder extends SearchBase op(String joinName, String name, Object field, Op op) { + return left(joinName, field, op, name); + } + /** * Adds an OR condition to the SearchBuilder. * @@ -182,6 +198,12 @@ public class GenericSearchBuilder extends SearchBase or(String joinName, String name, Object field, Op op) { + SearchBase join = _joins.get(joinName).getT(); + constructCondition(joinName, name, " OR ", join._specifiedAttrs.get(0), op); + return this; + } + /** * Adds an OR condition * diff --git a/framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java b/framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java index 662ba921ce9..523f90b2866 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java +++ b/framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java @@ -22,7 +22,8 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.Callable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.Profiler; @@ -43,7 +44,7 @@ import com.cloud.utils.Profiler; // lock.releaseRef(); // public class GlobalLock { - protected final static Logger s_logger = Logger.getLogger(GlobalLock.class); + protected Logger logger = LogManager.getLogger(getClass()); private String name; private int lockCount = 0; @@ -74,7 +75,7 @@ public class GlobalLock { refCount = referenceCount; if (referenceCount < 0) - s_logger.warn("Unmatched Global lock " + name + " reference usage detected, check your code!"); + logger.warn("Unmatched Global lock " + name + " reference usage detected, check your code!"); if (referenceCount == 0) needToRemove = true; @@ -101,14 +102,14 @@ public class GlobalLock { } } - private static void releaseInternLock(String name) { + private void releaseInternLock(String name) { synchronized (s_lockMap) { GlobalLock lock = s_lockMap.get(name); if (lock != null) { if (lock.referenceCount == 0) s_lockMap.remove(name); } else { - s_logger.warn("Releasing " + name + ", but it is already released."); + logger.warn("Releasing " + name + ", but it is already released."); } } } @@ -121,12 +122,12 @@ public class GlobalLock { while (true) { synchronized (this) { if (ownerThread != null && ownerThread == Thread.currentThread()) { - s_logger.warn("Global lock re-entrance detected"); + logger.warn("Global lock re-entrance detected"); lockCount++; - if (s_logger.isTraceEnabled()) - s_logger.trace("lock " + name + " is acquired, lock count :" + lockCount); + if (logger.isTraceEnabled()) + logger.trace("lock " + name + " is acquired, lock count :" + lockCount); return true; } @@ -156,8 +157,8 @@ public class GlobalLock { lockCount++; holdingStartTick = System.currentTimeMillis(); - if (s_logger.isTraceEnabled()) - s_logger.trace("lock " + name + " is acquired, lock count :" + lockCount); + if (logger.isTraceEnabled()) + logger.trace("lock " + name + " is acquired, lock count :" + lockCount); return true; } } else { @@ -183,8 +184,8 @@ public class GlobalLock { ownerThread = null; DbUtil.releaseGlobalLock(name); - if (s_logger.isTraceEnabled()) - s_logger.trace("lock " + name + " is returned to free state, total holding time :" + (System.currentTimeMillis() - holdingStartTick)); + if (logger.isTraceEnabled()) + logger.trace("lock " + name + " is returned to free state, total holding time :" + (System.currentTimeMillis() - holdingStartTick)); holdingStartTick = 0; // release holding position in intern map when we released the DB connection @@ -192,8 +193,8 @@ public class GlobalLock { notifyAll(); } - if (s_logger.isTraceEnabled()) - s_logger.trace("lock " + name + " is released, lock count :" + lockCount); + if (logger.isTraceEnabled()) + logger.trace("lock " + name + " is released, lock count :" + lockCount); return true; } return false; @@ -204,15 +205,15 @@ public class GlobalLock { return name; } - public static T executeWithLock(final String operationId, final int lockAcquisitionTimeout, final Callable operation) throws Exception { + public T executeWithLock(final String operationId, final int lockAcquisitionTimeout, final Callable operation) throws Exception { final GlobalLock lock = GlobalLock.getInternLock(operationId); try { if (!lock.lock(lockAcquisitionTimeout)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(format("Failed to acquire lock for operation id %1$s", operationId)); + if (logger.isDebugEnabled()) { + logger.debug(format("Failed to acquire lock for operation id %1$s", operationId)); } return null; } @@ -229,7 +230,7 @@ public class GlobalLock { } - public static T executeWithNoWaitLock(final String operationId, final Callable operation) throws Exception { + public T executeWithNoWaitLock(final String operationId, final Callable operation) throws Exception { return executeWithLock(operationId, 0, operation); diff --git a/framework/db/src/main/java/com/cloud/utils/db/JoinBuilder.java b/framework/db/src/main/java/com/cloud/utils/db/JoinBuilder.java index 60e392170be..f0a3ad82596 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/JoinBuilder.java +++ b/framework/db/src/main/java/com/cloud/utils/db/JoinBuilder.java @@ -31,19 +31,57 @@ public class JoinBuilder { return _name; } } + public enum JoinCondition { + AND(" AND "), OR(" OR "); + + private final String name; + + JoinCondition(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } private final T t; + private final String name; private JoinType type; - private Attribute firstAttribute; - private Attribute secondAttribute; - public JoinBuilder(T t, Attribute firstAttribute, Attribute secondAttribute, JoinType type) { + private JoinCondition condition; + private Attribute[] firstAttributes; + private Attribute[] secondAttribute; + + public JoinBuilder(String name, T t, Attribute firstAttributes, Attribute secondAttribute, JoinType type) { + this.name = name; this.t = t; - this.firstAttribute = firstAttribute; + this.firstAttributes = new Attribute[]{firstAttributes}; + this.secondAttribute = new Attribute[]{secondAttribute}; + this.type = type; + } + + public JoinBuilder(String name, T t, Attribute[] firstAttributes, Attribute[] secondAttribute, JoinType type) { + this.name = name; + this.t = t; + this.firstAttributes = firstAttributes; this.secondAttribute = secondAttribute; this.type = type; } + public JoinBuilder(String name, T t, Attribute[] firstAttributes, Attribute[] secondAttribute, JoinType type, JoinCondition condition) { + this.name = name; + this.t = t; + this.firstAttributes = firstAttributes; + this.secondAttribute = secondAttribute; + this.type = type; + this.condition = condition; + } + + public String getName() { + return name; + } + public T getT() { return t; } @@ -56,19 +94,23 @@ public class JoinBuilder { this.type = type; } - public Attribute getFirstAttribute() { - return firstAttribute; + public JoinCondition getCondition() { + return condition; } - public void setFirstAttribute(Attribute firstAttribute) { - this.firstAttribute = firstAttribute; + public Attribute[] getFirstAttributes() { + return firstAttributes; } - public Attribute getSecondAttribute() { + public void setFirstAttributes(Attribute[] firstAttributes) { + this.firstAttributes = firstAttributes; + } + + public Attribute[] getSecondAttribute() { return secondAttribute; } - public void setSecondAttribute(Attribute secondAttribute) { + public void setSecondAttribute(Attribute[] secondAttribute) { this.secondAttribute = secondAttribute; } diff --git a/framework/db/src/main/java/com/cloud/utils/db/Merovingian2.java b/framework/db/src/main/java/com/cloud/utils/db/Merovingian2.java index 485a68ab313..a9a1ce4272e 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/Merovingian2.java +++ b/framework/db/src/main/java/com/cloud/utils/db/Merovingian2.java @@ -29,7 +29,8 @@ import java.util.TimeZone; import javax.management.StandardMBean; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.DateUtil; import com.cloud.utils.exception.CloudRuntimeException; @@ -37,7 +38,7 @@ import com.cloud.utils.mgmt.JmxUtil; import com.cloud.utils.time.InaccurateClock; public class Merovingian2 extends StandardMBean implements MerovingianMBean { - private static final Logger s_logger = Logger.getLogger(Merovingian2.class); + protected static Logger LOGGER = LogManager.getLogger(Merovingian2.class); private static final String ACQUIRE_SQL = "INSERT INTO op_lock (op_lock.key, op_lock.mac, op_lock.ip, op_lock.thread, op_lock.acquired_on, waiters) VALUES (?, ?, ?, ?, ?, 1)"; @@ -70,14 +71,14 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { conn.setAutoCommit(true); _concierge = new ConnectionConcierge("LockController", conn, true); } catch (SQLException e) { - s_logger.error("Unable to get a new db connection", e); + LOGGER.error("Unable to get a new db connection", e); throw new CloudRuntimeException("Unable to initialize a connection to the database for locking purposes", e); } finally { if (_concierge == null && conn != null) { try { conn.close(); } catch (SQLException e) { - s_logger.debug("closing connection failed after everything else.", e); + LOGGER.debug("closing connection failed after everything else.", e); } } } @@ -90,7 +91,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { try { JmxUtil.registerMBean("Locks", "Locks", s_instance); } catch (Exception e) { - s_logger.error("Unable to register for JMX", e); + LOGGER.error("Unable to register for JMX", e); } return s_instance; } @@ -123,8 +124,8 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { String threadName = th.getName(); int threadId = System.identityHashCode(th); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Acquiring lck-" + key + " with wait time of " + timeInSeconds); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Acquiring lck-" + key + " with wait time of " + timeInSeconds); } long startTime = InaccurateClock.getTime(); @@ -139,17 +140,17 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { } } try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Sleeping more time while waiting for lck-" + key); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Sleeping more time while waiting for lck-" + key); } Thread.sleep(5000); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while aquiring " + key); + LOGGER.debug("[ignored] interrupted while aquiring " + key); } } String msg = "Timed out on acquiring lock " + key + " . Waited for " + ((InaccurateClock.getTime() - startTime)/1000) + "seconds"; Exception e = new CloudRuntimeException(msg); - s_logger.warn(msg, e); + LOGGER.warn(msg, e); return false; } @@ -161,8 +162,8 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { pstmt.setInt(4, threadId); int rows = pstmt.executeUpdate(); assert (rows <= 1) : "hmm...non unique key? " + pstmt; - if (s_logger.isTraceEnabled()) { - s_logger.trace("lck-" + key + (rows == 1 ? " acquired again" : " failed to acquire again")); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("lck-" + key + (rows == 1 ? " acquired again" : " failed to acquire again")); } if (rows == 1) { incrCount(); @@ -170,7 +171,7 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { } return false; } catch (Exception e) { - s_logger.error("increment:Exception:"+e.getMessage()); + LOGGER.error("increment:Exception:"+e.getMessage()); throw new CloudRuntimeException("increment:Exception:"+e.getMessage(), e); } } @@ -186,8 +187,8 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { try { int rows = pstmt.executeUpdate(); if (rows == 1) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Acquired for lck-" + key); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Acquired for lck-" + key); } incrCount(); return true; @@ -198,11 +199,11 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { } } } catch (SQLException e) { - s_logger.error("doAcquire:Exception:"+e.getMessage()); + LOGGER.error("doAcquire:Exception:"+e.getMessage()); throw new CloudRuntimeException("Unable to lock " + key + ". Waited " + (InaccurateClock.getTime() - startTime), e); } - s_logger.trace("Unable to acquire lck-" + key); + LOGGER.trace("Unable to acquire lck-" + key); return false; } @@ -216,11 +217,11 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { } return toLock(rs); }catch (SQLException e) { - s_logger.error("isLocked:Exception:"+e.getMessage()); + LOGGER.error("isLocked:Exception:"+e.getMessage()); throw new CloudRuntimeException("isLocked:Exception:"+e.getMessage(), e); } } catch (SQLException e) { - s_logger.error("isLocked:Exception:"+e.getMessage()); + LOGGER.error("isLocked:Exception:"+e.getMessage()); throw new CloudRuntimeException("isLocked:Exception:"+e.getMessage(), e); } } @@ -231,20 +232,20 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { @Override public void cleanupForServer(long msId) { - s_logger.info("Cleaning up locks for " + msId); + LOGGER.info("Cleaning up locks for " + msId); try { synchronized (_concierge.conn()) { try(PreparedStatement pstmt = _concierge.conn().prepareStatement(CLEANUP_MGMT_LOCKS_SQL);) { pstmt.setLong(1, msId); int rows = pstmt.executeUpdate(); - s_logger.info("Released " + rows + " locks for " + msId); + LOGGER.info("Released " + rows + " locks for " + msId); }catch (Exception e) { - s_logger.error("cleanupForServer:Exception:"+e.getMessage()); + LOGGER.error("cleanupForServer:Exception:"+e.getMessage()); throw new CloudRuntimeException("cleanupForServer:Exception:"+e.getMessage(), e); } } } catch (Exception e) { - s_logger.error("cleanupForServer:Exception:"+e.getMessage()); + LOGGER.error("cleanupForServer:Exception:"+e.getMessage()); throw new CloudRuntimeException("cleanupForServer:Exception:"+e.getMessage(), e); } } @@ -262,30 +263,30 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { int rows = pstmt.executeUpdate(); assert (rows <= 1) : "hmmm....keys not unique? " + pstmt; - if (s_logger.isTraceEnabled()) { - s_logger.trace("lck-" + key + " released"); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("lck-" + key + " released"); } if (rows == 1) { try (PreparedStatement rel_sql_pstmt = _concierge.conn().prepareStatement(RELEASE_SQL);) { rel_sql_pstmt.setString(1, key); rel_sql_pstmt.setLong(2, _msId); int result = rel_sql_pstmt.executeUpdate(); - if (result == 1 && s_logger.isTraceEnabled()) { - s_logger.trace("lck-" + key + " removed"); + if (result == 1 && LOGGER.isTraceEnabled()) { + LOGGER.trace("lck-" + key + " removed"); } decrCount(); }catch (Exception e) { - s_logger.error("release:Exception:"+ e.getMessage()); + LOGGER.error("release:Exception:"+ e.getMessage()); throw new CloudRuntimeException("release:Exception:"+ e.getMessage(), e); } } else if (rows < 1) { String msg = ("Was unable to find lock for the key " + key + " and thread id " + threadId); Exception e = new CloudRuntimeException(msg); - s_logger.warn(msg, e); + LOGGER.warn(msg, e); } return rows == 1; } catch (Exception e) { - s_logger.error("release:Exception:"+ e.getMessage()); + LOGGER.error("release:Exception:"+ e.getMessage()); throw new CloudRuntimeException("release:Exception:"+ e.getMessage(), e); } } @@ -320,11 +321,11 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { { return toLocks(rs); }catch (Exception e) { - s_logger.error("getLocks:Exception:"+e.getMessage()); + LOGGER.error("getLocks:Exception:"+e.getMessage()); throw new CloudRuntimeException("getLocks:Exception:"+e.getMessage(), e); } } catch (Exception e) { - s_logger.error("getLocks:Exception:"+e.getMessage()); + LOGGER.error("getLocks:Exception:"+e.getMessage()); throw new CloudRuntimeException("getLocks:Exception:"+e.getMessage(), e); } } @@ -360,11 +361,11 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { return toLocks(rs); } catch (Exception e) { - s_logger.error("getLocksAcquiredBy:Exception:"+e.getMessage()); + LOGGER.error("getLocksAcquiredBy:Exception:"+e.getMessage()); throw new CloudRuntimeException("Can't get locks " + pstmt, e); } } catch (Exception e) { - s_logger.error("getLocksAcquiredBy:Exception:"+e.getMessage()); + LOGGER.error("getLocksAcquiredBy:Exception:"+e.getMessage()); throw new CloudRuntimeException("getLocksAcquiredBy:Exception:"+e.getMessage(), e); } } @@ -390,21 +391,21 @@ public class Merovingian2 extends StandardMBean implements MerovingianMBean { assert (false) : "Abandon hope, all ye who enter here....There were still " + rows + ":" + c + " locks not released when the transaction ended, check for lock not released or @DB is not added to the code that using the locks!"; } catch (Exception e) { - s_logger.error("cleanupThread:Exception:" + e.getMessage()); + LOGGER.error("cleanupThread:Exception:" + e.getMessage()); throw new CloudRuntimeException("cleanupThread:Exception:" + e.getMessage(), e); } } @Override public boolean releaseLockAsLastResortAndIReallyKnowWhatIAmDoing(String key) { - s_logger.info("Releasing a lock from JMX lck-" + key); + LOGGER.info("Releasing a lock from JMX lck-" + key); try (PreparedStatement pstmt = _concierge.conn().prepareStatement(RELEASE_LOCK_SQL);) { pstmt.setString(1, key); int rows = pstmt.executeUpdate(); return rows > 0; } catch (Exception e) { - s_logger.error("releaseLockAsLastResortAndIReallyKnowWhatIAmDoing : Exception: " + e.getMessage()); + LOGGER.error("releaseLockAsLastResortAndIReallyKnowWhatIAmDoing : Exception: " + e.getMessage()); return false; } } diff --git a/framework/db/src/main/java/com/cloud/utils/db/ScriptRunner.java b/framework/db/src/main/java/com/cloud/utils/db/ScriptRunner.java index 51124f693c5..56fa8593161 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/ScriptRunner.java +++ b/framework/db/src/main/java/com/cloud/utils/db/ScriptRunner.java @@ -29,13 +29,14 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; /** * Tool to run database scripts */ public class ScriptRunner { - private static Logger s_logger = Logger.getLogger(ScriptRunner.class); + private static Logger LOGGER = LogManager.getLogger(ScriptRunner.class); private static final String DEFAULT_DELIMITER = ";"; @@ -208,17 +209,17 @@ public class ScriptRunner { private void println(Object o) { _logBuffer.append(o); if (verbosity) - s_logger.debug(_logBuffer.toString()); + LOGGER.debug(_logBuffer.toString()); _logBuffer = new StringBuffer(); } private void printlnError(Object o) { - s_logger.error("" + o); + LOGGER.error("" + o); } private void flush() { if (_logBuffer.length() > 0) { - s_logger.debug(_logBuffer.toString()); + LOGGER.debug(_logBuffer.toString()); _logBuffer = new StringBuffer(); } } diff --git a/framework/db/src/main/java/com/cloud/utils/db/SearchBase.java b/framework/db/src/main/java/com/cloud/utils/db/SearchBase.java index 3d41a62b43c..fcc9ded684d 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/SearchBase.java +++ b/framework/db/src/main/java/com/cloud/utils/db/SearchBase.java @@ -36,6 +36,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import net.sf.cglib.proxy.Factory; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; +import org.apache.commons.lang3.StringUtils; /** * SearchBase contains the methods that are used to build up search @@ -70,6 +71,14 @@ public abstract class SearchBase, T, K> { init(entityType, resultType); } + public SearchBase getJoinSB(String name) { + JoinBuilder> jb = null; + if (_joins != null) { + jb = _joins.get(name); + } + return jb == null ? null : jb.getT(); + } + protected void init(final Class entityType, final Class resultType) { _dao = (GenericDaoBase)GenericDaoBase.getDao(entityType); if (_dao == null) { @@ -194,15 +203,45 @@ public abstract class SearchBase, T, K> { * @param joinType type of join * @return itself */ - @SuppressWarnings("unchecked") public J join(final String name, final SearchBase builder, final Object joinField1, final Object joinField2, final JoinBuilder.JoinType joinType) { - assert _entity != null : "SearchBuilder cannot be modified once it has been setup"; - assert _specifiedAttrs.size() == 1 : "You didn't select the attribute."; - assert builder._entity != null : "SearchBuilder cannot be modified once it has been setup"; - assert builder._specifiedAttrs.size() == 1 : "You didn't select the attribute."; - assert builder != this : "You can't add yourself, can you? Really think about it!"; + if (_specifiedAttrs.size() != 1) + throw new CloudRuntimeException("You didn't select the attribute."); + if (builder._specifiedAttrs.size() != 1) + throw new CloudRuntimeException("You didn't select the attribute."); - final JoinBuilder> t = new JoinBuilder>(builder, _specifiedAttrs.get(0), builder._specifiedAttrs.get(0), joinType); + return join(name, builder, joinType, null, joinField1, joinField2); + } + + + /** + * joins this search with another search with multiple conditions in the join clause + * + * @param name name given to the other search. used for setJoinParameters. + * @param builder The other search + * @param joinType type of join + * @param condition condition to be used for multiple conditions in the join clause + * @param joinFields fields the first and second table used to perform the join. + * The fields should be in the order of the checks between the two tables. + * + * @return + */ + public J join(final String name, final SearchBase builder, final JoinBuilder.JoinType joinType, final + JoinBuilder.JoinCondition condition, final Object... joinFields) { + if (_entity == null) + throw new CloudRuntimeException("SearchBuilder cannot be modified once it has been setup"); + if (_specifiedAttrs.isEmpty()) + throw new CloudRuntimeException("Attribute not specified."); + if (builder._entity == null) + throw new CloudRuntimeException("SearchBuilder cannot be modified once it has been setup"); + if (builder._specifiedAttrs.isEmpty()) + throw new CloudRuntimeException("Attribute not specified."); + if (builder == this) + throw new CloudRuntimeException("Can't join with itself. Create a new SearchBuilder for the same entity and use that."); + if (_specifiedAttrs.size() != builder._specifiedAttrs.size()) + throw new CloudRuntimeException("Number of attributes to join on must be the same."); + + final JoinBuilder> t = new JoinBuilder<>(name, builder, _specifiedAttrs.toArray(new Attribute[0]), + builder._specifiedAttrs.toArray(new Attribute[0]), joinType, condition); if (_joins == null) { _joins = new HashMap>>(); } @@ -223,6 +262,16 @@ public abstract class SearchBase, T, K> { _specifiedAttrs.add(attr); } + /* + Allows to set conditions in join where one entity is equivalent to a string or a long + e.g. join("vm", vmSearch, VmDetailVO.class, entity.getName(), "vm.id", SearchCriteria.Op.EQ); + will create a condition 'vm.name = "vm.id"' + */ + protected void setAttr(final Object obj) { + final Attribute attr = new Attribute(obj); + _specifiedAttrs.add(attr); + } + /** * @return entity object. This allows the caller to use the entity return * to specify the field to be selected in many of the search parameters. @@ -242,17 +291,26 @@ public abstract class SearchBase, T, K> { return _specifiedAttrs; } - protected Condition constructCondition(final String conditionName, final String cond, final Attribute attr, final Op op) { + protected Condition constructCondition(final String joinName, final String conditionName, final String cond, final Attribute attr, final Op op) { assert _entity != null : "SearchBuilder cannot be modified once it has been setup"; assert op == null || _specifiedAttrs.size() == 1 : "You didn't select the attribute."; assert op != Op.SC : "Call join"; final Condition condition = new Condition(conditionName, cond, attr, op); + if (StringUtils.isNotEmpty(joinName)) { + condition.setJoinName(joinName); + } _conditions.add(condition); _specifiedAttrs.clear(); return condition; } + + protected Condition constructCondition(final String conditionName, final String cond, final Attribute attr, final Op op) { + return constructCondition(null, conditionName, cond, attr, op); + } + + /** * creates the SearchCriteria so the actual values can be filled in. * @@ -364,6 +422,7 @@ public abstract class SearchBase, T, K> { protected static class Condition { protected final String name; protected final String cond; + protected String joinName; protected final Op op; protected final Attribute attr; protected Object[] presets; @@ -388,11 +447,15 @@ public abstract class SearchBase, T, K> { this.presets = presets; } + public void setJoinName(final String joinName) { + this.joinName = joinName; + } + public Object[] getPresets() { return presets; } - public void toSql(final StringBuilder sql, final Object[] params, final int count) { + public void toSql(final StringBuilder sql, String tableAlias, final Object[] params, final int count) { if (count > 0) { sql.append(cond); } @@ -414,7 +477,15 @@ public abstract class SearchBase, T, K> { sql.append(" FIND_IN_SET(?, "); } - sql.append(attr.table).append(".").append(attr.columnName).append(op.toString()); + if (tableAlias == null) { + if (joinName != null) { + tableAlias = joinName; + } else { + tableAlias = attr.table; + } + } + + sql.append(tableAlias).append(".").append(attr.columnName).append(op.toString()); if (op == Op.IN && params.length == 1) { sql.delete(sql.length() - op.toString().length(), sql.length()); sql.append("=?"); @@ -485,6 +556,8 @@ public abstract class SearchBase, T, K> { final String fieldName = Character.toLowerCase(name.charAt(2)) + name.substring(3); set(fieldName); return null; + } else if (name.equals("setLong") || name.equals("setString")) { + setAttr(args[0]); } else { final Column ann = method.getAnnotation(Column.class); if (ann != null) { diff --git a/framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java b/framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java index 6f90d2391e6..8affbd5300a 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java +++ b/framework/db/src/main/java/com/cloud/utils/db/SearchCriteria.java @@ -106,7 +106,7 @@ public class SearchCriteria { for (Map.Entry>> entry : sb._joins.entrySet()) { JoinBuilder> value = entry.getValue(); _joins.put(entry.getKey(), - new JoinBuilder>(value.getT().create(), value.getFirstAttribute(), value.getSecondAttribute(), value.getType())); + new JoinBuilder>(entry.getKey(), value.getT().create(), value.getFirstAttributes(), value.getSecondAttribute(), value.getType(), value.getCondition())); } } _selects = sb._selects; @@ -250,7 +250,7 @@ public class SearchCriteria { _additionals.add(condition); } - public String getWhereClause() { + public String getWhereClause(String tableAlias) { StringBuilder sql = new StringBuilder(); int i = 0; for (Condition condition : _conditions) { @@ -259,7 +259,7 @@ public class SearchCriteria { } Object[] params = _params.get(condition.name); if ((condition.op == null || condition.op.params == 0) || (params != null)) { - condition.toSql(sql, params, i++); + condition.toSql(sql, tableAlias, params, i++); } } @@ -269,13 +269,17 @@ public class SearchCriteria { } Object[] params = _params.get(condition.name); if ((condition.op.params == 0) || (params != null)) { - condition.toSql(sql, params, i++); + condition.toSql(sql, tableAlias, params, i++); } } return sql.toString(); } + public String getWhereClause() { + return getWhereClause(null); + } + public List> getValues() { ArrayList> params = new ArrayList>(_params.size()); for (Condition condition : _conditions) { diff --git a/framework/db/src/main/java/com/cloud/utils/db/SequenceFetcher.java b/framework/db/src/main/java/com/cloud/utils/db/SequenceFetcher.java index 0ea8401a03c..f902fda3bf1 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/SequenceFetcher.java +++ b/framework/db/src/main/java/com/cloud/utils/db/SequenceFetcher.java @@ -29,7 +29,8 @@ import java.util.concurrent.TimeUnit; import javax.persistence.TableGenerator; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.concurrency.NamedThreadFactory; @@ -42,7 +43,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory; * */ public class SequenceFetcher { - private final static Logger s_logger = Logger.getLogger(SequenceFetcher.class); + protected Logger logger = LogManager.getLogger(getClass()); ExecutorService _executors; private final static Random random = new Random(); @@ -63,7 +64,7 @@ public class SequenceFetcher { try { return future.get(); } catch (Exception e) { - s_logger.warn("Unable to get sequeunce for " + tg.table() + ":" + tg.pkColumnValue(), e); + logger.warn("Unable to get sequeunce for " + tg.table() + ":" + tg.pkColumnValue(), e); return null; } } @@ -138,11 +139,11 @@ public class SequenceFetcher { } } } catch (SQLException e) { - s_logger.warn("Caught this exception when running: " + (selectStmt != null ? selectStmt.toString() : ""), e); + logger.warn("Caught this exception when running: " + (selectStmt != null ? selectStmt.toString() : ""), e); } if (obj == null) { - s_logger.warn("Unable to get a sequence: " + updateStmt.toString()); + logger.warn("Unable to get a sequence: " + updateStmt.toString()); return null; } @@ -153,7 +154,7 @@ public class SequenceFetcher { txn.commit(); return (T)obj; } catch (SQLException e) { - s_logger.warn("Caught this exception when running: " + (updateStmt != null ? updateStmt.toString() : ""), e); + logger.warn("Caught this exception when running: " + (updateStmt != null ? updateStmt.toString() : ""), e); } } } diff --git a/framework/db/src/main/java/com/cloud/utils/db/Transaction.java b/framework/db/src/main/java/com/cloud/utils/db/Transaction.java index c6a491a216d..24cd76e2e10 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/Transaction.java +++ b/framework/db/src/main/java/com/cloud/utils/db/Transaction.java @@ -18,14 +18,12 @@ package com.cloud.utils.db; import java.util.concurrent.atomic.AtomicLong; -import org.apache.log4j.Logger; public class Transaction { private final static AtomicLong counter = new AtomicLong(0); private final static TransactionStatus STATUS = new TransactionStatus() { }; - private static final Logger s_logger = Logger.getLogger(Transaction.class); @SuppressWarnings("deprecation") public static T execute(TransactionCallbackWithException callback) throws E { diff --git a/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java b/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java index df0df60f519..00fa8e4c0d5 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java +++ b/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java @@ -42,7 +42,8 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.pool2.ObjectPool; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.Pair; import com.cloud.utils.PropertiesUtil; @@ -64,10 +65,10 @@ import com.cloud.utils.mgmt.JmxUtil; * it is stored with TLS and is one per thread. Use appropriately. */ public class TransactionLegacy implements Closeable { - private static final Logger s_logger = Logger.getLogger(Transaction.class.getName() + "." + "Transaction"); - private static final Logger s_stmtLogger = Logger.getLogger(Transaction.class.getName() + "." + "Statement"); - private static final Logger s_lockLogger = Logger.getLogger(Transaction.class.getName() + "." + "Lock"); - private static final Logger s_connLogger = Logger.getLogger(Transaction.class.getName() + "." + "Connection"); + protected static Logger LOGGER = LogManager.getLogger(Transaction.class.getName() + "." + "Transaction"); + protected Logger stmtLogger = LogManager.getLogger(Transaction.class.getName() + "." + "Statement"); + protected Logger lockLogger = LogManager.getLogger(Transaction.class.getName() + "." + "Lock"); + protected static Logger CONN_LOGGER = LogManager.getLogger(Transaction.class.getName() + "." + "Connection"); private static final ThreadLocal tls = new ThreadLocal(); private static final String START_TXN = "start_txn"; @@ -82,6 +83,7 @@ public class TransactionLegacy implements Closeable { public static final short SIMULATOR_DB = 3; public static final short CONNECTED_DB = -1; + public static final String CONNECTION_PARAMS = "scrollTolerantForwardOnly=true"; private static AtomicLong s_id = new AtomicLong(); private static final TransactionMBeanImpl s_mbean = new TransactionMBeanImpl(); @@ -89,7 +91,7 @@ public class TransactionLegacy implements Closeable { try { JmxUtil.registerMBean("Transaction", "Transaction", s_mbean); } catch (Exception e) { - s_logger.error("Unable to register mbean for transaction", e); + LOGGER.error("Unable to register mbean for transaction", e); } } @@ -152,8 +154,8 @@ public class TransactionLegacy implements Closeable { public static TransactionLegacy open(final String name, final short databaseId, final boolean forceDbChange) { TransactionLegacy txn = tls.get(); if (txn == null) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Creating the transaction: " + name); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Creating the transaction: " + name); } txn = new TransactionLegacy(name, false, databaseId); tls.set(txn); @@ -198,7 +200,7 @@ public class TransactionLegacy implements Closeable { } public void registerLock(String sql) { - if (_txn && s_lockLogger.isDebugEnabled()) { + if (_txn && lockLogger.isDebugEnabled()) { Pair time = new Pair(sql, System.currentTimeMillis()); _lockTimes.add(time); } @@ -210,8 +212,8 @@ public class TransactionLegacy implements Closeable { public static Connection getStandaloneConnectionWithException() throws SQLException { Connection conn = s_ds.getConnection(); - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn)); + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Retrieving a standalone connection: dbconn" + System.identityHashCode(conn)); } return conn; } @@ -220,7 +222,7 @@ public class TransactionLegacy implements Closeable { try { return getStandaloneConnectionWithException(); } catch (SQLException e) { - s_logger.error("Unexpected exception: ", e); + LOGGER.error("Unexpected exception: ", e); return null; } } @@ -228,12 +230,12 @@ public class TransactionLegacy implements Closeable { public static Connection getStandaloneUsageConnection() { try { Connection conn = s_usageDS.getConnection(); - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Retrieving a standalone connection for usage: dbconn" + System.identityHashCode(conn)); + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Retrieving a standalone connection for usage: dbconn" + System.identityHashCode(conn)); } return conn; } catch (SQLException e) { - s_logger.warn("Unexpected exception: ", e); + LOGGER.warn("Unexpected exception: ", e); return null; } } @@ -241,12 +243,12 @@ public class TransactionLegacy implements Closeable { public static Connection getStandaloneSimulatorConnection() { try { Connection conn = s_simulatorDS.getConnection(); - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Retrieving a standalone connection for simulator: dbconn" + System.identityHashCode(conn)); + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Retrieving a standalone connection for simulator: dbconn" + System.identityHashCode(conn)); } return conn; } catch (SQLException e) { - s_logger.warn("Unexpected exception: ", e); + LOGGER.warn("Unexpected exception: ", e); return null; } } @@ -301,12 +303,12 @@ public class TransactionLegacy implements Closeable { } // relax stack structure for several places that @DB required injection is not in place - s_logger.warn("Non-standard stack context that Transaction context is manaully placed into the calling chain. Stack chain: " + sb); + LOGGER.warn("Non-standard stack context that Transaction context is manaully placed into the calling chain. Stack chain: " + sb); return true; } protected static String buildName() { - if (s_logger.isDebugEnabled()) { + if (LOGGER.isDebugEnabled()) { final StackTraceElement[] stacks = Thread.currentThread().getStackTrace(); final StringBuilder str = new StringBuilder(); int i = 3, j = 3; @@ -398,14 +400,14 @@ public class TransactionLegacy implements Closeable { */ @Deprecated public void start() { - if (s_logger.isTraceEnabled()) { - s_logger.trace("txn: start requested by: " + buildName()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("txn: start requested by: " + buildName()); } _stack.push(new StackElement(START_TXN, null)); if (_txn) { - s_logger.trace("txn: has already been started."); + LOGGER.trace("txn: has already been started."); return; } @@ -414,10 +416,10 @@ public class TransactionLegacy implements Closeable { _txnTime = System.currentTimeMillis(); if (_conn != null) { try { - s_logger.trace("txn: set auto commit to false"); + LOGGER.trace("txn: set auto commit to false"); _conn.setAutoCommit(false); } catch (final SQLException e) { - s_logger.warn("Unable to set auto commit: ", e); + LOGGER.warn("Unable to set auto commit: ", e); throw new CloudRuntimeException("Unable to set auto commit: ", e); } } @@ -426,8 +428,8 @@ public class TransactionLegacy implements Closeable { protected void closePreviousStatement() { if (_stmt != null) { try { - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Closing: " + _stmt.toString()); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Closing: " + _stmt.toString()); } try { ResultSet rs = _stmt.getResultSet(); @@ -435,11 +437,11 @@ public class TransactionLegacy implements Closeable { rs.close(); } } catch (SQLException e) { - s_stmtLogger.trace("Unable to close resultset"); + stmtLogger.trace("Unable to close resultset"); } _stmt.close(); } catch (final SQLException e) { - s_stmtLogger.trace("Unable to close statement: " + _stmt.toString()); + stmtLogger.trace("Unable to close statement: " + _stmt.toString()); } finally { _stmt = null; } @@ -466,8 +468,8 @@ public class TransactionLegacy implements Closeable { public PreparedStatement prepareStatement(final String sql) throws SQLException { final Connection conn = getConnection(); final PreparedStatement pstmt = conn.prepareStatement(sql); - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Preparing: " + sql); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Preparing: " + sql); } return pstmt; } @@ -486,8 +488,8 @@ public class TransactionLegacy implements Closeable { public PreparedStatement prepareAutoCloseStatement(final String sql, final int autoGeneratedKeys) throws SQLException { final Connection conn = getConnection(); final PreparedStatement pstmt = conn.prepareStatement(sql, autoGeneratedKeys); - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Preparing: " + sql); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Preparing: " + sql); } closePreviousStatement(); _stmt = pstmt; @@ -508,8 +510,8 @@ public class TransactionLegacy implements Closeable { public PreparedStatement prepareAutoCloseStatement(final String sql, final String[] columnNames) throws SQLException { final Connection conn = getConnection(); final PreparedStatement pstmt = conn.prepareStatement(sql, columnNames); - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Preparing: " + sql); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Preparing: " + sql); } closePreviousStatement(); _stmt = pstmt; @@ -529,8 +531,8 @@ public class TransactionLegacy implements Closeable { public PreparedStatement prepareAutoCloseStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { final Connection conn = getConnection(); final PreparedStatement pstmt = conn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Preparing: " + sql); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Preparing: " + sql); } closePreviousStatement(); _stmt = pstmt; @@ -555,7 +557,7 @@ public class TransactionLegacy implements Closeable { if (s_ds != null) { _conn = s_ds.getConnection(); } else { - s_logger.warn("A static-initialized variable becomes null, process is dying?"); + LOGGER.warn("A static-initialized variable becomes null, process is dying?"); throw new CloudRuntimeException("Database is not initialized, process is dying?"); } break; @@ -563,7 +565,7 @@ public class TransactionLegacy implements Closeable { if (s_usageDS != null) { _conn = s_usageDS.getConnection(); } else { - s_logger.warn("A static-initialized variable becomes null, process is dying?"); + LOGGER.warn("A static-initialized variable becomes null, process is dying?"); throw new CloudRuntimeException("Database is not initialized, process is dying?"); } break; @@ -571,7 +573,7 @@ public class TransactionLegacy implements Closeable { if (s_simulatorDS != null) { _conn = s_simulatorDS.getConnection(); } else { - s_logger.warn("A static-initialized variable becomes null, process is dying?"); + LOGGER.warn("A static-initialized variable becomes null, process is dying?"); throw new CloudRuntimeException("Database is not initialized, process is dying?"); } break; @@ -587,12 +589,12 @@ public class TransactionLegacy implements Closeable { // see http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html // _stack.push(new StackElement(CREATE_CONN, null)); - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + " for " + _dbId + ": dbconn" + System.identityHashCode(_conn) + + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + " for " + _dbId + ": dbconn" + System.identityHashCode(_conn) + ". Stack: " + buildName()); } } else { - s_logger.trace("conn: Using existing DB connection"); + LOGGER.trace("conn: Using existing DB connection"); } return _conn; @@ -602,8 +604,8 @@ public class TransactionLegacy implements Closeable { if (_stack.size() != 0) { if (!create) { // If it is not a create transaction, then let's just use the current one. - if (s_logger.isTraceEnabled()) { - s_logger.trace("Using current transaction: " + toString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Using current transaction: " + toString()); } mark(name); return false; @@ -613,19 +615,19 @@ public class TransactionLegacy implements Closeable { if (se.type == CREATE_TXN) { // This create is called inside of another create. Which is ok? // We will let that create be responsible for cleaning up. - if (s_logger.isTraceEnabled()) { - s_logger.trace("Create using current transaction: " + toString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Create using current transaction: " + toString()); } mark(name); return false; } - s_logger.warn("Encountered a transaction that has leaked. Cleaning up. " + toString()); + LOGGER.warn("Encountered a transaction that has leaked. Cleaning up. " + toString()); cleanup(); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Took over the transaction: " + name); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Took over the transaction: " + name); } _stack.push(new StackElement(create ? CREATE_TXN : CURRENT_TXN, name)); _name = name; @@ -656,7 +658,7 @@ public class TransactionLegacy implements Closeable { removeUpTo(CURRENT_TXN, null); if (_stack.size() == 0) { - s_logger.trace("Transaction is done"); + LOGGER.trace("Transaction is done"); cleanup(); } } @@ -670,8 +672,8 @@ public class TransactionLegacy implements Closeable { */ public boolean close(final String name) { if (_name == null) { // Already cleaned up. - if (s_logger.isTraceEnabled()) { - s_logger.trace("Already cleaned up." + buildName()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Already cleaned up." + buildName()); } return true; } @@ -681,13 +683,13 @@ public class TransactionLegacy implements Closeable { return false; } - if (s_logger.isDebugEnabled() && _stack.size() > 2) { - s_logger.debug("Transaction is not closed properly: " + toString() + ". Called by " + buildName()); + if (LOGGER.isDebugEnabled() && _stack.size() > 2) { + LOGGER.debug("Transaction is not closed properly: " + toString() + ". Called by " + buildName()); } cleanup(); - s_logger.trace("All done"); + LOGGER.trace("All done"); return true; } @@ -696,9 +698,9 @@ public class TransactionLegacy implements Closeable { } protected void clearLockTimes() { - if (s_lockLogger.isDebugEnabled()) { + if (lockLogger.isDebugEnabled()) { for (Pair time : _lockTimes) { - s_lockLogger.trace("SQL " + time.first() + " took " + (System.currentTimeMillis() - time.second())); + lockLogger.trace("SQL " + time.first() + " took " + (System.currentTimeMillis() - time.second())); } _lockTimes.clear(); } @@ -706,7 +708,7 @@ public class TransactionLegacy implements Closeable { public boolean commit() { if (!_txn) { - s_logger.warn("txn: Commit called when it is not a transaction: " + buildName()); + LOGGER.warn("txn: Commit called when it is not a transaction: " + buildName()); return false; } @@ -720,8 +722,8 @@ public class TransactionLegacy implements Closeable { } if (hasTxnInStack()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("txn: Not committing because transaction started elsewhere: " + buildName() + " / " + toString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("txn: Not committing because transaction started elsewhere: " + buildName() + " / " + toString()); } return false; } @@ -730,7 +732,7 @@ public class TransactionLegacy implements Closeable { try { if (_conn != null) { _conn.commit(); - s_logger.trace("txn: DB Changes committed. Time = " + (System.currentTimeMillis() - _txnTime)); + LOGGER.trace("txn: DB Changes committed. Time = " + (System.currentTimeMillis() - _txnTime)); clearLockTimes(); closeConnection(); } @@ -749,22 +751,22 @@ public class TransactionLegacy implements Closeable { } if (_txn) { - s_connLogger.trace("txn: Not closing DB connection because we're still in a transaction."); + CONN_LOGGER.trace("txn: Not closing DB connection because we're still in a transaction."); return; } try { // we should only close db connection when it is not user managed if (_dbId != CONNECTED_DB) { - if (s_connLogger.isTraceEnabled()) { - s_connLogger.trace("Closing DB connection: dbconn" + System.identityHashCode(_conn)); + if (CONN_LOGGER.isTraceEnabled()) { + CONN_LOGGER.trace("Closing DB connection: dbconn" + System.identityHashCode(_conn)); } _conn.close(); _conn = null; s_mbean.removeTransaction(this); } } catch (final SQLException e) { - s_logger.warn("Unable to close connection", e); + LOGGER.warn("Unable to close connection", e); } } @@ -782,8 +784,8 @@ public class TransactionLegacy implements Closeable { } if (item.type == CURRENT_TXN) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Releasing the current txn: " + (item.ref != null ? item.ref : "")); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Releasing the current txn: " + (item.ref != null ? item.ref : "")); } } else if (item.type == CREATE_CONN) { closeConnection(); @@ -795,13 +797,13 @@ public class TransactionLegacy implements Closeable { _conn.rollback((Savepoint)ref); rollback = false; } catch (final SQLException e) { - s_logger.warn("Unable to rollback Txn.", e); + LOGGER.warn("Unable to rollback Txn.", e); } } } else if (item.type == STATEMENT) { try { - if (s_stmtLogger.isTraceEnabled()) { - s_stmtLogger.trace("Closing: " + ref.toString()); + if (stmtLogger.isTraceEnabled()) { + stmtLogger.trace("Closing: " + ref.toString()); } Statement stmt = (Statement)ref; try { @@ -810,21 +812,21 @@ public class TransactionLegacy implements Closeable { rs.close(); } } catch (SQLException e) { - s_stmtLogger.trace("Unable to close resultset"); + stmtLogger.trace("Unable to close resultset"); } stmt.close(); } catch (final SQLException e) { - s_stmtLogger.trace("Unable to close statement: " + item); + stmtLogger.trace("Unable to close statement: " + item); } } else if (item.type == ATTACHMENT) { TransactionAttachment att = (TransactionAttachment)item.ref; - if (s_logger.isTraceEnabled()) { - s_logger.trace("Cleaning up " + att.getName()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Cleaning up " + att.getName()); } att.cleanup(); } } catch (Exception e) { - s_logger.error("Unable to clean up " + item, e); + LOGGER.error("Unable to clean up " + item, e); } } @@ -836,8 +838,8 @@ public class TransactionLegacy implements Closeable { protected void rollbackTransaction() { closePreviousStatement(); if (!_txn) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Rollback called for " + _name + " when there's no transaction: " + buildName()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Rollback called for " + _name + " when there's no transaction: " + buildName()); } return; } @@ -845,15 +847,15 @@ public class TransactionLegacy implements Closeable { _txn = false; try { if (_conn != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Rolling back the transaction: Time = " + (System.currentTimeMillis() - _txnTime) + " Name = " + _name + "; called by " + buildName()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Rolling back the transaction: Time = " + (System.currentTimeMillis() - _txnTime) + " Name = " + _name + "; called by " + buildName()); } _conn.rollback(); } clearLockTimes(); closeConnection(); } catch (final SQLException e) { - s_logger.warn("Unable to rollback", e); + LOGGER.warn("Unable to rollback", e); } } @@ -863,7 +865,7 @@ public class TransactionLegacy implements Closeable { _conn.rollback(sp); } } catch (SQLException e) { - s_logger.warn("Unable to rollback to savepoint " + sp); + LOGGER.warn("Unable to rollback to savepoint " + sp); } if (!hasTxnInStack()) { @@ -979,7 +981,7 @@ public class TransactionLegacy implements Closeable { protected void finalize() throws Throwable { if (!(_conn == null && (_stack == null || _stack.size() == 0))) { assert (false) : "Oh Alex oh alex...something is wrong with how we're doing this"; - s_logger.error("Something went wrong that a transaction is orphaned before db connection is closed"); + LOGGER.error("Something went wrong that a transaction is orphaned before db connection is closed"); cleanup(); } } @@ -1025,7 +1027,7 @@ public class TransactionLegacy implements Closeable { return; s_dbHAEnabled = Boolean.valueOf(dbProps.getProperty("db.ha.enabled")); - s_logger.info("Is Data Base High Availiability enabled? Ans : " + s_dbHAEnabled); + LOGGER.info("Is Data Base High Availiability enabled? Ans : " + s_dbHAEnabled); String loadBalanceStrategy = dbProps.getProperty("db.ha.loadBalanceStrategy"); // FIXME: If params are missing...default them???? final int cloudMaxActive = Integer.parseInt(dbProps.getProperty("db.cloud.maxActive")); @@ -1048,7 +1050,7 @@ public class TransactionLegacy implements Closeable { } else if (cloudIsolationLevel.equalsIgnoreCase("readuncommitted")) { isolationLevel = Connection.TRANSACTION_READ_UNCOMMITTED; } else { - s_logger.warn("Unknown isolation level " + cloudIsolationLevel + ". Using read uncommitted"); + LOGGER.warn("Unknown isolation level " + cloudIsolationLevel + ". Using read uncommitted"); } final boolean cloudTestOnBorrow = Boolean.parseBoolean(dbProps.getProperty("db.cloud.testOnBorrow")); @@ -1111,7 +1113,7 @@ public class TransactionLegacy implements Closeable { simulatorConnectionUri = simulatorDriver + "://" + simulatorHost + ":" + simulatorPort + "/" + simulatorDbName + "?autoReconnect=" + simulatorAutoReconnect; } else { - s_logger.warn("db.simulator.uri was set, ignoring the following properties on db.properties: [db.simulator.driver, db.simulator.host, db.simulator.port, " + LOGGER.warn("db.simulator.uri was set, ignoring the following properties on db.properties: [db.simulator.driver, db.simulator.host, db.simulator.port, " + "db.simulator.name, db.simulator.autoReconnect]."); String[] splitUri = simulatorUri.split(":"); simulatorDriver = String.format("%s:%s", splitUri[0], splitUri[1]); @@ -1123,13 +1125,13 @@ public class TransactionLegacy implements Closeable { s_simulatorDS = createDataSource(simulatorConnectionUri, simulatorUsername, simulatorPassword, simulatorMaxActive, simulatorMaxIdle, simulatorMaxWait, null, null, null, null, cloudValidationQuery, isolationLevel); } catch (Exception e) { - s_logger.debug("Simulator DB properties are not available. Not initializing simulator DS"); + LOGGER.debug("Simulator DB properties are not available. Not initializing simulator DS"); } } catch (final Exception e) { s_ds = getDefaultDataSource("cloud"); s_usageDS = getDefaultDataSource("cloud_usage"); s_simulatorDS = getDefaultDataSource("cloud_simulator"); - s_logger.warn( + LOGGER.warn( "Unable to load db configuration, using defaults with 5 connections. Falling back on assumed datasource on localhost:3306 using username:password=cloud:cloud. Please check your configuration", e); } @@ -1144,7 +1146,7 @@ public class TransactionLegacy implements Closeable { driver = dbProps.getProperty(String.format("db.%s.driver", schema)); connectionUri = getPropertiesAndBuildConnectionUri(dbProps, loadBalanceStrategy, driver, useSSL, schema); } else { - s_logger.warn(String.format("db.%s.uri was set, ignoring the following properties for schema %s of db.properties: [host, port, name, driver, autoReconnect, url.params," + LOGGER.warn(String.format("db.%s.uri was set, ignoring the following properties for schema %s of db.properties: [host, port, name, driver, autoReconnect, url.params," + " replicas, ha.loadBalanceStrategy, ha.enable, failOverReadOnly, reconnectAtTxEnd, autoReconnectForPools, secondsBeforeRetrySource, queriesBeforeRetrySource, " + "initialTimeout].", schema, schema)); @@ -1153,7 +1155,7 @@ public class TransactionLegacy implements Closeable { connectionUri = propertyUri; } - s_logger.info(String.format("Using the following URI to connect to %s database [%s].", schema, connectionUri)); + LOGGER.info(String.format("Using the following URI to connect to %s database [%s].", schema, connectionUri)); return new Pair<>(connectionUri, driver); } @@ -1169,7 +1171,7 @@ public class TransactionLegacy implements Closeable { if (s_dbHAEnabled) { dbHaParams = getDBHAParams(schema, dbProps); replicas = dbProps.getProperty(String.format("db.%s.replicas", schema)); - s_logger.info(String.format("The replicas configured for %s data base are %s.", schema, replicas)); + LOGGER.info(String.format("The replicas configured for %s data base are %s.", schema, replicas)); } return buildConnectionUri(loadBalanceStrategy, driver, useSSL, host, replicas, port, dbName, autoReconnect, urlParams, dbHaParams); @@ -1211,6 +1213,9 @@ public class TransactionLegacy implements Closeable { connectionUri.append(loadBalanceStrategy); } + connectionUri.append("&"); + connectionUri.append(CONNECTION_PARAMS); + return connectionUri.toString(); } @@ -1275,7 +1280,7 @@ public class TransactionLegacy implements Closeable { @SuppressWarnings({"unchecked", "rawtypes"}) private static DataSource getDefaultDataSource(final String database) { - final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/" + database, "cloud", "cloud"); + final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/" + database + "?" + CONNECTION_PARAMS, "cloud", "cloud"); final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); final GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory); return new PoolingDataSource(connectionPool); diff --git a/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java b/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java index a2153fee506..7ae7368e173 100644 --- a/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java +++ b/framework/db/src/test/java/com/cloud/utils/DbUtilTest.java @@ -36,10 +36,10 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.utils.db.DbUtil; import com.cloud.utils.db.TransactionLegacy; @@ -150,13 +150,13 @@ public class DbUtilTest { @Test public void getGlobalLock() throws SQLException { Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.when(connection.prepareStatement(Matchers.anyString())).thenReturn(preparedStatement); + Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement); Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.first()).thenReturn(true); Mockito.when(resultSet.getInt(1)).thenReturn(1); Assert.assertTrue(DbUtil.getGlobalLock("TEST", 600)); - Mockito.verify(connection).prepareStatement(Matchers.anyString()); + Mockito.verify(connection).prepareStatement(ArgumentMatchers.anyString()); Mockito.verify(preparedStatement).close(); Mockito.verify(resultSet).close(); } @@ -164,13 +164,13 @@ public class DbUtilTest { @Test public void getGlobalLockTimeout() throws SQLException { Mockito.when(dataSource.getConnection()).thenReturn(connection); - Mockito.when(connection.prepareStatement(Matchers.anyString())).thenReturn(preparedStatement); + Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement); Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.first()).thenReturn(true); Mockito.when(resultSet.getInt(1)).thenReturn(0); Assert.assertFalse(DbUtil.getGlobalLock("TEST", 600)); - Mockito.verify(connection).prepareStatement(Matchers.anyString()); + Mockito.verify(connection).prepareStatement(ArgumentMatchers.anyString()); Mockito.verify(preparedStatement).close(); Mockito.verify(resultSet).close(); Mockito.verify(connection).close(); @@ -237,7 +237,7 @@ public class DbUtilTest { @Test public void releaseGlobalLock() throws SQLException { - Mockito.when(connection.prepareStatement(Matchers.anyString())).thenReturn(preparedStatement); + Mockito.when(connection.prepareStatement(ArgumentMatchers.anyString())).thenReturn(preparedStatement); Mockito.when(preparedStatement.executeQuery()).thenReturn(resultSet); Mockito.when(resultSet.first()).thenReturn(true); Mockito.when(resultSet.getInt(1)).thenReturn(1); diff --git a/framework/db/src/test/java/com/cloud/utils/db/DbAnnotatedBase.java b/framework/db/src/test/java/com/cloud/utils/db/DbAnnotatedBase.java index 146f79adf0b..8a010203b51 100644 --- a/framework/db/src/test/java/com/cloud/utils/db/DbAnnotatedBase.java +++ b/framework/db/src/test/java/com/cloud/utils/db/DbAnnotatedBase.java @@ -21,13 +21,14 @@ import javax.inject.Inject; import junit.framework.Assert; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; @Component @DB public class DbAnnotatedBase { - private static final Logger s_logger = Logger.getLogger(DbAnnotatedBase.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject DummyComponent _dummy; @@ -38,7 +39,7 @@ public class DbAnnotatedBase { } public void MethodWithClassDbAnnotated() { - s_logger.info("called"); + logger.info("called"); _dummy.sayHello(); } } diff --git a/framework/db/src/test/java/com/cloud/utils/db/ElementCollectionTest.java b/framework/db/src/test/java/com/cloud/utils/db/ElementCollectionTest.java index 44f183dc8cd..aed076a6d6b 100644 --- a/framework/db/src/test/java/com/cloud/utils/db/ElementCollectionTest.java +++ b/framework/db/src/test/java/com/cloud/utils/db/ElementCollectionTest.java @@ -29,10 +29,8 @@ import java.util.Set; import junit.framework.TestCase; -import org.apache.log4j.Logger; public class ElementCollectionTest extends TestCase { - static final Logger s_logger = Logger.getLogger(ElementCollectionTest.class); ArrayList ar = null; List lst = null; Collection coll = null; diff --git a/framework/db/src/test/java/com/cloud/utils/db/GenericDaoBaseTest.java b/framework/db/src/test/java/com/cloud/utils/db/GenericDaoBaseTest.java index b950501337b..308600341c3 100644 --- a/framework/db/src/test/java/com/cloud/utils/db/GenericDaoBaseTest.java +++ b/framework/db/src/test/java/com/cloud/utils/db/GenericDaoBaseTest.java @@ -20,8 +20,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; -import java.util.Map; import org.junit.Assert; import org.junit.Before; @@ -229,12 +227,16 @@ public class GenericDaoBaseTest { Attribute attr2 = new Attribute("table2", "column2"); Attribute attr3 = new Attribute("table3", "column1"); Attribute attr4 = new Attribute("table4", "column2"); + Attribute attr5 = new Attribute("table3", "column1"); + Attribute attr6 = new Attribute("XYZ"); - joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), attr1, attr2, JoinBuilder.JoinType.INNER)); - joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), attr3, attr4, JoinBuilder.JoinType.INNER)); + joins.add(new JoinBuilder<>("", dbTestDao.createSearchCriteria(), attr1, attr2, JoinBuilder.JoinType.INNER)); + joins.add(new JoinBuilder<>("", dbTestDao.createSearchCriteria(), + new Attribute[]{attr3, attr5}, new Attribute[]{attr4, attr6}, JoinBuilder.JoinType.INNER, JoinBuilder.JoinCondition.OR)); dbTestDao.addJoins(joinString, joins); - Assert.assertEquals(" INNER JOIN table2 ON table1.column1=table2.column2 INNER JOIN table4 ON table3.column1=table4.column2 ", joinString.toString()); + Assert.assertEquals(" INNER JOIN table2 ON table1.column1=table2.column2 " + + " INNER JOIN table4 ON table3.column1=table4.column2 OR table3.column1=? ", joinString.toString()); } @Test @@ -248,22 +250,17 @@ public class GenericDaoBaseTest { Attribute tBc2 = new Attribute("tableB", "column2"); Attribute tCc3 = new Attribute("tableC", "column3"); Attribute tDc4 = new Attribute("tableD", "column4"); + Attribute tDc5 = new Attribute("tableD", "column5"); + Attribute attr = new Attribute(123); - joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), tBc2, tAc1, JoinBuilder.JoinType.INNER)); - joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), tCc3, tAc2, JoinBuilder.JoinType.INNER)); - joins.add(new JoinBuilder<>(dbTestDao.createSearchCriteria(), tDc4, tAc3, JoinBuilder.JoinType.INNER)); + joins.add(new JoinBuilder<>("tableA1Alias", dbTestDao.createSearchCriteria(), tBc2, tAc1, JoinBuilder.JoinType.INNER)); + joins.add(new JoinBuilder<>("tableA2Alias", dbTestDao.createSearchCriteria(), tCc3, tAc2, JoinBuilder.JoinType.INNER)); + joins.add(new JoinBuilder<>("tableA3Alias", dbTestDao.createSearchCriteria(), + new Attribute[]{tDc4, tDc5}, new Attribute[]{tAc3, attr}, JoinBuilder.JoinType.INNER, JoinBuilder.JoinCondition.AND)); dbTestDao.addJoins(joinString, joins); - Assert.assertEquals(" INNER JOIN tableA ON tableB.column2=tableA.column1 INNER JOIN tableA tableA1 ON tableC.column3=tableA1.column2 INNER JOIN tableA tableA2 ON tableD.column4=tableA2.column3 ", joinString.toString()); - } - - @Test - public void findNextTableNameTest() { - Map usedTables = new HashMap<>(); - - Assert.assertEquals("tableA", GenericDaoBase.findNextJoinTableName("tableA", usedTables)); - Assert.assertEquals("tableA1", GenericDaoBase.findNextJoinTableName("tableA", usedTables)); - Assert.assertEquals("tableA2", GenericDaoBase.findNextJoinTableName("tableA", usedTables)); - Assert.assertEquals("tableA3", GenericDaoBase.findNextJoinTableName("tableA", usedTables)); + Assert.assertEquals(" INNER JOIN tableA tableA1Alias ON tableB.column2=tableA1Alias.column1 " + + " INNER JOIN tableA tableA2Alias ON tableC.column3=tableA2Alias.column2 " + + " INNER JOIN tableA tableA3Alias ON tableD.column4=tableA3Alias.column3 AND tableD.column5=? ", joinString.toString()); } } diff --git a/framework/db/src/test/java/com/cloud/utils/db/GlobalLockTest.java b/framework/db/src/test/java/com/cloud/utils/db/GlobalLockTest.java index 19927edb81c..afd756eb270 100644 --- a/framework/db/src/test/java/com/cloud/utils/db/GlobalLockTest.java +++ b/framework/db/src/test/java/com/cloud/utils/db/GlobalLockTest.java @@ -16,7 +16,8 @@ // under the License. package com.cloud.utils.db; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; @@ -27,10 +28,10 @@ import com.cloud.utils.Profiler; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:/testContext.xml") public class GlobalLockTest { - public static final Logger s_logger = Logger.getLogger(GlobalLockTest.class); + protected Logger logger = LogManager.getLogger(getClass()); private final static GlobalLock WorkLock = GlobalLock.getInternLock("SecurityGroupWork"); - public static class Worker implements Runnable { + public class Worker implements Runnable { int id = 0; int timeoutSeconds = 10; int jobDuration = 2; @@ -54,7 +55,7 @@ public class GlobalLockTest { Thread.sleep(jobDuration * 1000); } } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while testing global lock."); + logger.debug("[ignored] interrupted while testing global lock."); } finally { if (locked) { boolean unlocked = WorkLock.unlock(); diff --git a/framework/db/src/test/java/com/cloud/utils/db/Merovingian2Test.java b/framework/db/src/test/java/com/cloud/utils/db/Merovingian2Test.java index eb8b96dc747..37c0ba776d0 100644 --- a/framework/db/src/test/java/com/cloud/utils/db/Merovingian2Test.java +++ b/framework/db/src/test/java/com/cloud/utils/db/Merovingian2Test.java @@ -19,13 +19,14 @@ package com.cloud.utils.db; import junit.framework.Assert; import junit.framework.TestCase; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.After; import org.junit.Before; import org.junit.Test; public class Merovingian2Test extends TestCase { - static final Logger s_logger = Logger.getLogger(Merovingian2Test.class); + protected Logger logger = LogManager.getLogger(Merovingian2Test.class); Merovingian2 _lockController = Merovingian2.createLockController(1234); @Override @@ -43,15 +44,15 @@ public class Merovingian2Test extends TestCase { @Test public void testLockAndRelease() { - s_logger.info("Testing first acquire"); + logger.info("Testing first acquire"); boolean result = _lockController.acquire("first" + 1234, 5); Assert.assertTrue(result); - s_logger.info("Testing acquire of different lock"); + logger.info("Testing acquire of different lock"); result = _lockController.acquire("second" + 1234, 5); Assert.assertTrue(result); - s_logger.info("Testing reacquire of the same lock"); + logger.info("Testing reacquire of the same lock"); result = _lockController.acquire("first" + 1234, 5); Assert.assertTrue(result); @@ -61,14 +62,14 @@ public class Merovingian2Test extends TestCase { count = _lockController.owns("second" + 1234); Assert.assertEquals(count, 1); - s_logger.info("Testing release of the first lock"); + logger.info("Testing release of the first lock"); result = _lockController.release("first" + 1234); Assert.assertTrue(result); count = _lockController.owns("first" + 1234); Assert.assertEquals(count, 1); - s_logger.info("Testing release of the second lock"); + logger.info("Testing release of the second lock"); result = _lockController.release("second" + 1234); Assert.assertTrue(result); diff --git a/framework/direct-download/pom.xml b/framework/direct-download/pom.xml index 4a2dfb44c64..1915377f222 100644 --- a/framework/direct-download/pom.xml +++ b/framework/direct-download/pom.xml @@ -25,14 +25,14 @@ org.apache.cloudstack cloud-utils - 4.19.0.0-SNAPSHOT + ${project.version} compile cloudstack-framework org.apache.cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/events/pom.xml b/framework/events/pom.xml index 050c4450afd..3f457920cc9 100644 --- a/framework/events/pom.xml +++ b/framework/events/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/ipc/pom.xml b/framework/ipc/pom.xml index 02b508b530a..3c03ed04e28 100644 --- a/framework/ipc/pom.xml +++ b/framework/ipc/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java index b9aa12bc5b0..2eafe21e593 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/async/AsyncCallbackDispatcher.java @@ -29,11 +29,12 @@ import net.sf.cglib.proxy.Factory; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; @SuppressWarnings("rawtypes") public class AsyncCallbackDispatcher implements AsyncCompletionCallback { - private static final Logger s_logger = Logger.getLogger(AsyncCallbackDispatcher.class); + protected Logger logger = LogManager.getLogger(getClass()); private Method _callbackMethod; private final T _targetObject; @@ -100,7 +101,7 @@ public class AsyncCallbackDispatcher implements AsyncCompletionCallback { }); return t; } catch (Throwable e) { - s_logger.error("Unexpected exception", e); + logger.error("Unexpected exception", e); } return null; diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/client/ClientTransportProvider.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/client/ClientTransportProvider.java index ae28f900e54..b2fbd60351a 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/client/ClientTransportProvider.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/client/ClientTransportProvider.java @@ -23,7 +23,8 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.framework.serializer.MessageSerializer; import org.apache.cloudstack.framework.transport.TransportEndpoint; @@ -34,7 +35,7 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable; import com.cloud.utils.concurrency.NamedThreadFactory; public class ClientTransportProvider implements TransportProvider { - final static Logger s_logger = Logger.getLogger(ClientTransportProvider.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final int DEFAULT_WORKER_POOL_SIZE = 5; private final Map _endpointSites = new HashMap(); @@ -72,7 +73,7 @@ public class ClientTransportProvider implements TransportProvider { try { _connection.connect(_serverAddress, _serverPort); } catch (Throwable e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "error during ipc client initialization: " + e.getLocalizedMessage()); } } diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageBusBase.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageBusBase.java index c0713567cd6..742fd90c33e 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageBusBase.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageBusBase.java @@ -26,7 +26,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.framework.serializer.MessageSerializer; @@ -41,7 +42,7 @@ public class MessageBusBase implements MessageBus { private final SubscriptionNode _subscriberRoot; private MessageSerializer _messageSerializer; - private static final Logger s_logger = Logger.getLogger(MessageBusBase.class); + protected Logger logger = LogManager.getLogger(getClass()); public MessageBusBase() { _gate = new Gate(); @@ -65,8 +66,8 @@ public class MessageBusBase implements MessageBus { assert (subject != null); assert (subscriber != null); if (_gate.enter()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus subscribe"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus subscribe"); } try { SubscriptionNode current = locate(subject, null, true); @@ -85,8 +86,8 @@ public class MessageBusBase implements MessageBus { @Override public void unsubscribe(String subject, MessageSubscriber subscriber) { if (_gate.enter()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus unsubscribe"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus unsubscribe"); } try { if (subject != null) { @@ -109,8 +110,8 @@ public class MessageBusBase implements MessageBus { @Override public void clearAll() { if (_gate.enter()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus clearAll"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus clearAll"); } try { _subscriberRoot.clearAll(); @@ -128,8 +129,8 @@ public class MessageBusBase implements MessageBus { @Override public void prune() { if (_gate.enter()) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus prune"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus prune"); } try { doPrune(); @@ -164,11 +165,11 @@ public class MessageBusBase implements MessageBus { // publish cannot be in DB transaction, which may hold DB lock too long, and we are guarding this here if (!noDbTxn()){ String errMsg = "NO EVENT PUBLISH CAN BE WRAPPED WITHIN DB TRANSACTION!"; - s_logger.error(errMsg, new CloudRuntimeException(errMsg)); + logger.error(errMsg, new CloudRuntimeException(errMsg)); } if (_gate.enter(true)) { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Enter gate in message bus publish"); + if (logger.isTraceEnabled()) { + logger.trace("Enter gate in message bus publish"); } try { List chainFromTop = new ArrayList(); @@ -326,7 +327,7 @@ public class MessageBusBase implements MessageBus { try { wait(); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while guarding re-entrance on message bus."); + logger.debug("[ignored] interrupted while guarding re-entrance on message bus."); } } else { break; @@ -346,8 +347,8 @@ public class MessageBusBase implements MessageBus { onGateOpen(); } finally { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Open gate of message bus"); + if (logger.isTraceEnabled()) { + logger.trace("Open gate of message bus"); } _reentranceCount--; assert (_reentranceCount == 0); diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDetector.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDetector.java index 4bcf9b1ebf4..6e8919ddc06 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDetector.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDetector.java @@ -18,10 +18,11 @@ */ package org.apache.cloudstack.framework.messagebus; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class MessageDetector implements MessageSubscriber { - private static final Logger s_logger = Logger.getLogger(MessageDetector.class); + protected Logger logger = LogManager.getLogger(getClass()); private MessageBus _messageBus; private String[] _subjects; @@ -33,7 +34,7 @@ public class MessageDetector implements MessageSubscriber { public void waitAny(long timeoutInMilliseconds) { if (timeoutInMilliseconds < 100) { - s_logger.warn("waitAny is passed with a too short time-out interval. " + timeoutInMilliseconds + "ms"); + logger.warn("waitAny is passed with a too short time-out interval. " + timeoutInMilliseconds + "ms"); timeoutInMilliseconds = 100; } @@ -41,7 +42,7 @@ public class MessageDetector implements MessageSubscriber { try { wait(timeoutInMilliseconds); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while waiting on any message."); + logger.debug("[ignored] interrupted while waiting on any message."); } } } diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDispatcher.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDispatcher.java index e93bbc2ad4a..5584aa11ef9 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDispatcher.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/messagebus/MessageDispatcher.java @@ -25,10 +25,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class MessageDispatcher implements MessageSubscriber { - private static final Logger s_logger = Logger.getLogger(MessageDispatcher.class); + protected Logger logger = LogManager.getLogger(getClass()); private static Map, List> s_handlerCache = new HashMap, List>(); @@ -63,7 +64,7 @@ public class MessageDispatcher implements MessageSubscriber { } } - public static boolean dispatch(Object target, String subject, String senderAddress, Object args) { + public boolean dispatch(Object target, String subject, String senderAddress, Object args) { assert (subject != null); assert (target != null); @@ -74,20 +75,20 @@ public class MessageDispatcher implements MessageSubscriber { try { handler.invoke(target, subject, senderAddress, args); } catch (IllegalArgumentException e) { - s_logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); + logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); throw new RuntimeException("IllegalArgumentException when invoking event handler for subject: " + subject); } catch (IllegalAccessException e) { - s_logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); + logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); throw new RuntimeException("IllegalAccessException when invoking event handler for subject: " + subject); } catch (InvocationTargetException e) { - s_logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); + logger.error("Unexpected exception when calling " + target.getClass().getName() + "." + handler.getName(), e); throw new RuntimeException("InvocationTargetException when invoking event handler for subject: " + subject); } return true; } - public static Method resolveHandler(Class handlerClz, String subject) { + public Method resolveHandler(Class handlerClz, String subject) { synchronized (s_handlerCache) { List handlerList = s_handlerCache.get(handlerClz); if (handlerList != null) { @@ -100,7 +101,7 @@ public class MessageDispatcher implements MessageSubscriber { } } } else { - s_logger.error("Handler class " + handlerClz.getName() + " is not registered"); + logger.error("Handler class " + handlerClz.getName() + " is not registered"); } } @@ -112,8 +113,8 @@ public class MessageDispatcher implements MessageSubscriber { } private void buildHandlerMethodCache(Class handlerClz) { - if (s_logger.isInfoEnabled()) - s_logger.info("Build message handler cache for " + handlerClz.getName()); + if (logger.isInfoEnabled()) + logger.info("Build message handler cache for " + handlerClz.getName()); synchronized (s_handlerCache) { List handlerList = s_handlerCache.get(handlerClz); @@ -130,20 +131,20 @@ public class MessageDispatcher implements MessageSubscriber { method.setAccessible(true); handlerList.add(method); - if (s_logger.isInfoEnabled()) - s_logger.info("Add message handler " + handlerClz.getName() + "." + method.getName() + " to cache"); + if (logger.isInfoEnabled()) + logger.info("Add message handler " + handlerClz.getName() + "." + method.getName() + " to cache"); } } clz = clz.getSuperclass(); } } else { - if (s_logger.isInfoEnabled()) - s_logger.info("Message handler for class " + handlerClz.getName() + " is already in cache"); + if (logger.isInfoEnabled()) + logger.info("Message handler for class " + handlerClz.getName() + " is already in cache"); } } - if (s_logger.isInfoEnabled()) - s_logger.info("Done building message handler cache for " + handlerClz.getName()); + if (logger.isInfoEnabled()) + logger.info("Done building message handler cache for " + handlerClz.getName()); } } diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java index 24ccfe42afc..3cc643956e9 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/serializer/OnwireClassRegistry.java @@ -32,7 +32,8 @@ import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; // @@ -40,7 +41,7 @@ import org.apache.log4j.Logger; // Credit: http://internna.blogspot.com/2007/11/java-5-retrieving-all-classes-from.html // public class OnwireClassRegistry { - private static final Logger s_logger = Logger.getLogger(OnwireClassRegistry.class); + protected Logger logger = LogManager.getLogger(getClass()); private List packages = new ArrayList(); private final Map> registry = new HashMap>(); @@ -89,7 +90,7 @@ public class OnwireClassRegistry { return registry.get(onwireName); } - static Set> getClasses(String packageName) { + private Set> getClasses(String packageName) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); return getClasses(loader, packageName); } @@ -98,7 +99,7 @@ public class OnwireClassRegistry { // Following helper methods can be put in a separated helper class, // will do that later // - static Set> getClasses(ClassLoader loader, String packageName) { + private Set> getClasses(ClassLoader loader, String packageName) { Set> classes = new HashSet>(); String path = packageName.replace('.', '/'); try { @@ -123,14 +124,14 @@ public class OnwireClassRegistry { } } } catch (IOException e) { - s_logger.debug("Encountered IOException", e); + logger.debug("Encountered IOException", e); } catch (ClassNotFoundException e) { - s_logger.info("[ignored] class not found", e); + logger.info("[ignored] class not found", e); } return classes; } - static Set> getFromDirectory(File directory, String packageName) throws ClassNotFoundException { + private Set> getFromDirectory(File directory, String packageName) throws ClassNotFoundException { Set> classes = new HashSet>(); if (directory.exists()) { for (String file : directory.list()) { @@ -140,9 +141,9 @@ public class OnwireClassRegistry { Class clazz = Class.forName(name); classes.add(clazz); } catch (ClassNotFoundException e) { - s_logger.info("[ignored] class not found in directory " + directory, e); + logger.info("[ignored] class not found in directory " + directory, e); } catch (Exception e) { - s_logger.debug("Encountered unexpect exception! ", e); + logger.debug("Encountered unexpect exception! ", e); } } else { File f = new File(directory.getPath() + "/" + file); @@ -155,7 +156,7 @@ public class OnwireClassRegistry { return classes; } - static Set> getFromJARFile(String jar, String packageName) throws IOException, ClassNotFoundException { + private Set> getFromJARFile(String jar, String packageName) throws IOException, ClassNotFoundException { Set> classes = new HashSet>(); try (JarInputStream jarFile = new JarInputStream(new FileInputStream(jar));) { JarEntry jarEntry; @@ -170,7 +171,7 @@ public class OnwireClassRegistry { Class clz = Class.forName(className.replace('/', '.')); classes.add(clz); } catch (ClassNotFoundException | NoClassDefFoundError e) { - s_logger.warn("Unable to load class from jar file", e); + logger.warn("Unable to load class from jar file", e); } } } diff --git a/framework/ipc/src/main/java/org/apache/cloudstack/framework/server/ServerTransportProvider.java b/framework/ipc/src/main/java/org/apache/cloudstack/framework/server/ServerTransportProvider.java index 06215a78b70..2302fe4e39b 100644 --- a/framework/ipc/src/main/java/org/apache/cloudstack/framework/server/ServerTransportProvider.java +++ b/framework/ipc/src/main/java/org/apache/cloudstack/framework/server/ServerTransportProvider.java @@ -27,7 +27,8 @@ import org.apache.cloudstack.framework.transport.TransportEndpointSite; import org.apache.cloudstack.framework.transport.TransportPdu; import org.apache.cloudstack.framework.transport.TransportProvider; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.bouncycastle.jce.provider.BouncyCastleProvider; import java.security.SecureRandom; @@ -38,7 +39,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class ServerTransportProvider implements TransportProvider { - private static final Logger s_logger = Logger.getLogger(ServerTransportProvider.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final int DEFAULT_WORKER_POOL_SIZE = 5; @@ -150,7 +151,7 @@ public class ServerTransportProvider implements TransportProvider { site.processOutput(); site.ackOutputProcessSignal(); } catch (Throwable e) { - s_logger.error("Unhandled exception", e); + logger.error("Unhandled exception", e); } } }); diff --git a/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagementServer.java b/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagementServer.java index af5862c48e6..bb59d1e2398 100644 --- a/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagementServer.java +++ b/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagementServer.java @@ -18,17 +18,18 @@ */ package org.apache.cloudstack.framework.sampleserver; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class SampleManagementServer { - private static final Logger s_logger = Logger.getLogger(SampleManagementServer.class); + protected Logger logger = LogManager.getLogger(getClass()); public void mainLoop() { while (true) { try { Thread.sleep(1000); } catch (InterruptedException e) { - s_logger.debug("[ignored] ."); + logger.debug("[ignored] ."); } } } diff --git a/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagementServerApp.java b/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagementServerApp.java index 47eb9d94b94..340e2068b52 100644 --- a/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagementServerApp.java +++ b/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagementServerApp.java @@ -22,7 +22,7 @@ import java.io.File; import java.net.URISyntaxException; import java.net.URL; -import org.apache.log4j.xml.DOMConfigurator; +import org.apache.logging.log4j.core.config.Configurator; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -37,7 +37,7 @@ public class SampleManagementServerApp { File file = new File(configUrl.toURI()); System.out.println("Log4j configuration from : " + file.getAbsolutePath()); - DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); + Configurator.initialize(null, file.getAbsolutePath()); } catch (URISyntaxException e) { System.out.println("Unable to convert log4j configuration Url to URI"); } diff --git a/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagerComponent.java b/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagerComponent.java index e3abcca9d46..77a2a72066e 100644 --- a/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagerComponent.java +++ b/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagerComponent.java @@ -24,7 +24,8 @@ import java.util.TimerTask; import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.framework.messagebus.MessageBus; @@ -39,7 +40,7 @@ import org.apache.cloudstack.framework.rpc.RpcServiceHandler; @Component public class SampleManagerComponent { - private static final Logger s_logger = Logger.getLogger(SampleManagerComponent.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private MessageBus _eventBus; @@ -88,12 +89,12 @@ public class SampleManagerComponent { .addCallbackListener(new RpcCallbackListener() { @Override public void onSuccess(SampleStoragePrepareAnswer result) { - s_logger.info("StoragePrepare return result: " + result.getResult()); + logger.info("StoragePrepare return result: " + result.getResult()); } @Override public void onFailure(RpcException e) { - s_logger.info("StoragePrepare failed"); + logger.info("StoragePrepare failed"); } }) .apply(); diff --git a/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagerComponent2.java b/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagerComponent2.java index 13040c1c935..294d1c979eb 100644 --- a/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagerComponent2.java +++ b/framework/ipc/src/test/java/org/apache/cloudstack/framework/sampleserver/SampleManagerComponent2.java @@ -21,7 +21,8 @@ package org.apache.cloudstack.framework.sampleserver; import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import org.apache.cloudstack.framework.messagebus.MessageBus; @@ -34,7 +35,7 @@ import org.apache.cloudstack.framework.rpc.RpcServiceHandler; @Component public class SampleManagerComponent2 { - private static final Logger s_logger = Logger.getLogger(SampleManagerComponent2.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private MessageBus _eventBus; @@ -55,10 +56,10 @@ public class SampleManagerComponent2 { @RpcServiceHandler(command = "StoragePrepare") void onStartCommand(RpcServerCall call) { - s_logger.info("Reevieved StoragePrpare call"); + logger.info("Reevieved StoragePrpare call"); SampleStoragePrepareCommand cmd = call.getCommandArgument(); - s_logger.info("StoragePrepare command arg. pool: " + cmd.getStoragePool() + ", vol: " + cmd.getVolumeId()); + logger.info("StoragePrepare command arg. pool: " + cmd.getStoragePool() + ", vol: " + cmd.getVolumeId()); SampleStoragePrepareAnswer answer = new SampleStoragePrepareAnswer(); answer.setResult("Successfully executed StoragePrepare command"); diff --git a/framework/ipc/src/test/java/org/apache/cloudstack/messagebus/TestMessageBus.java b/framework/ipc/src/test/java/org/apache/cloudstack/messagebus/TestMessageBus.java index 3ee48803e29..5dd38642258 100644 --- a/framework/ipc/src/test/java/org/apache/cloudstack/messagebus/TestMessageBus.java +++ b/framework/ipc/src/test/java/org/apache/cloudstack/messagebus/TestMessageBus.java @@ -26,7 +26,6 @@ import org.apache.cloudstack.framework.messagebus.MessageBus; import org.apache.cloudstack.framework.messagebus.MessageDetector; import org.apache.cloudstack.framework.messagebus.MessageSubscriber; import org.apache.cloudstack.framework.messagebus.PublishScope; -import org.apache.log4j.Logger; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,7 +36,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:/MessageBusTestContext.xml") public class TestMessageBus extends TestCase { - private static final Logger s_logger = Logger.getLogger(TestMessageBus.class); @Inject MessageBus _messageBus; @@ -129,7 +127,6 @@ public class TestMessageBus extends TestCase { try { Thread.sleep(3000); } catch (InterruptedException e) { - s_logger.debug("[ignored] ."); } _messageBus.publish(null, "Host", PublishScope.GLOBAL, null); } @@ -150,7 +147,6 @@ public class TestMessageBus extends TestCase { try { thread.join(); } catch (InterruptedException e) { - s_logger.debug("[ignored] ."); } } } diff --git a/framework/ipc/src/test/resources/log4j-cloud.xml b/framework/ipc/src/test/resources/log4j-cloud.xml index e9b1918b6e6..6bd50829d82 100644 --- a/framework/ipc/src/test/resources/log4j-cloud.xml +++ b/framework/ipc/src/test/resources/log4j-cloud.xml @@ -17,78 +17,57 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - + + + + + - + + + + + + + + - - - + + + - - - - - + + + + + - - + - - - - - - - - + + + - - - + - - - - + - - - - - - - + - - - + - - - - - - - - + - - - - - - - + - - - + + + - - - - - + + + + - + + diff --git a/framework/jobs/pom.xml b/framework/jobs/pom.xml index b00875ee3e7..a82f514635f 100644 --- a/framework/jobs/pom.xml +++ b/framework/jobs/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java index 5575ab394ee..465a80b62c7 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/AsyncJobExecutionContext.java @@ -16,7 +16,8 @@ // under the License. package org.apache.cloudstack.framework.jobs; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.framework.jobs.dao.AsyncJobJoinMapDao; @@ -33,7 +34,7 @@ import com.cloud.user.Account; import com.cloud.user.User; public class AsyncJobExecutionContext { - private static final Logger s_logger = Logger.getLogger(AsyncJobExecutionContext.class); + protected static Logger LOGGER = LogManager.getLogger(AsyncJobExecutionContext.class); private AsyncJob _job; @@ -132,24 +133,24 @@ public class AsyncJobExecutionContext { Object exception = JobSerializerHelper.fromObjectSerializedString(record.getJoinResult()); if (exception != null && exception instanceof Exception) { if (exception instanceof InsufficientCapacityException) { - s_logger.error("Job " + joinedJobId + " failed with InsufficientCapacityException"); + LOGGER.error("Job " + joinedJobId + " failed with InsufficientCapacityException"); throw (InsufficientCapacityException)exception; } else if (exception instanceof ConcurrentOperationException) { - s_logger.error("Job " + joinedJobId + " failed with ConcurrentOperationException"); + LOGGER.error("Job " + joinedJobId + " failed with ConcurrentOperationException"); throw (ConcurrentOperationException)exception; } else if (exception instanceof ResourceUnavailableException) { - s_logger.error("Job " + joinedJobId + " failed with ResourceUnavailableException"); + LOGGER.error("Job " + joinedJobId + " failed with ResourceUnavailableException"); throw (ResourceUnavailableException)exception; } else { - s_logger.error("Job " + joinedJobId + " failed with exception"); + LOGGER.error("Job " + joinedJobId + " failed with exception"); throw new RuntimeException((Exception)exception); } } } else { - s_logger.error("Job " + joinedJobId + " failed without providing an error object"); + LOGGER.error("Job " + joinedJobId + " failed without providing an error object"); throw new RuntimeException("Job " + joinedJobId + " failed without providing an error object"); } } @@ -172,7 +173,7 @@ public class AsyncJobExecutionContext { // TODO, this has security implications, operations carried from API layer should always // set its context, otherwise, the fall-back here will use system security context // - s_logger.warn("Job is executed without a context, setup psudo job for the executing thread"); + LOGGER.warn("Job is executed without a context, setup psudo job for the executing thread"); if (CallContext.current() != null) context = registerPseudoExecutionContext(CallContext.current().getCallingAccountId(), CallContext.current().getCallingUserId()); diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobDaoImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobDaoImpl.java index 1914ff71460..a2f1f36b863 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobDaoImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobDaoImpl.java @@ -22,7 +22,6 @@ import java.util.Date; import java.util.List; import org.apache.cloudstack.api.ApiConstants; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO; import org.apache.cloudstack.jobs.JobInfo; @@ -37,7 +36,6 @@ import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.TransactionLegacy; public class AsyncJobDaoImpl extends GenericDaoBase implements AsyncJobDao { - private static final Logger s_logger = Logger.getLogger(AsyncJobDaoImpl.class.getName()); private final SearchBuilder pendingAsyncJobSearch; private final SearchBuilder pendingAsyncJobsSearch; @@ -121,7 +119,7 @@ public class AsyncJobDaoImpl extends GenericDaoBase implements List l = listIncludingRemovedBy(sc); if (l != null && l.size() > 0) { if (l.size() > 1) { - s_logger.warn("Instance " + instanceType + "-" + instanceId + " has multiple pending async-job"); + logger.warn("Instance " + instanceType + "-" + instanceId + " has multiple pending async-job"); } return l.get(0); @@ -208,9 +206,9 @@ public class AsyncJobDaoImpl extends GenericDaoBase implements pstmt.setLong(6, msid); pstmt.execute(); } catch (SQLException e) { - s_logger.warn("Unable to reset job status for management server " + msid, e); + logger.warn("Unable to reset job status for management server " + msid, e); } catch (Throwable e) { - s_logger.warn("Unable to reset job status for management server " + msid, e); + logger.warn("Unable to reset job status for management server " + msid, e); } } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobJoinMapDaoImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobJoinMapDaoImpl.java index d70864c755b..da7ba36c919 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobJoinMapDaoImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/AsyncJobJoinMapDaoImpl.java @@ -24,7 +24,6 @@ import java.util.Date; import java.util.List; import java.util.TimeZone; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO; import org.apache.cloudstack.jobs.JobInfo; @@ -39,7 +38,6 @@ import com.cloud.utils.db.UpdateBuilder; import com.cloud.utils.exception.CloudRuntimeException; public class AsyncJobJoinMapDaoImpl extends GenericDaoBase implements AsyncJobJoinMapDao { - public static final Logger s_logger = Logger.getLogger(AsyncJobJoinMapDaoImpl.class); private final SearchBuilder RecordSearch; private final SearchBuilder RecordSearchByOwner; @@ -202,7 +200,7 @@ public class AsyncJobJoinMapDaoImpl extends GenericDaoBase implements SyncQueueDao { - private static final Logger s_logger = Logger.getLogger(SyncQueueDaoImpl.class.getName()); SearchBuilder TypeIdSearch = createSearchBuilder(); @@ -60,9 +58,9 @@ public class SyncQueueDaoImpl extends GenericDaoBase implemen pstmt.setString(4, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), dt)); pstmt.execute(); } catch (SQLException e) { - s_logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); + logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); } catch (Throwable e) { - s_logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); + logger.warn("Unable to create sync queue " + syncObjType + "-" + syncObjId + ":" + e.getMessage(), e); } } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueItemDaoImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueItemDaoImpl.java index 29c3f1b289f..756cbb7efb0 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueItemDaoImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/SyncQueueItemDaoImpl.java @@ -25,7 +25,6 @@ import java.util.Date; import java.util.List; import java.util.TimeZone; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.impl.SyncQueueItemVO; @@ -42,7 +41,6 @@ import com.cloud.utils.db.TransactionLegacy; @DB public class SyncQueueItemDaoImpl extends GenericDaoBase implements SyncQueueItemDao { - private static final Logger s_logger = Logger.getLogger(SyncQueueItemDaoImpl.class); final GenericSearchBuilder queueIdSearch; final GenericSearchBuilder queueActiveItemSearch; @@ -116,9 +114,9 @@ public class SyncQueueItemDaoImpl extends GenericDaoBase l.add(item); } } catch (SQLException e) { - s_logger.error("Unexpected sql exception, ", e); + logger.error("Unexpected sql exception, ", e); } catch (Throwable e) { - s_logger.error("Unexpected exception, ", e); + logger.error("Unexpected exception, ", e); } return l; } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java index 4a10727546e..e66221cc8fe 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java @@ -24,7 +24,6 @@ import java.util.List; import javax.annotation.PostConstruct; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO; import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO.Step; @@ -43,7 +42,6 @@ import com.cloud.utils.db.TransactionStatus; import com.cloud.vm.VirtualMachine; public class VmWorkJobDaoImpl extends GenericDaoBase implements VmWorkJobDao { - private static final Logger s_logger = Logger.getLogger(VmWorkJobDaoImpl.class); protected SearchBuilder PendingWorkJobSearch; protected SearchBuilder PendingWorkJobByCommandSearch; @@ -159,8 +157,8 @@ public class VmWorkJobDaoImpl extends GenericDaoBase implemen sc.setParameters("dispatcher", "VmWorkJobDispatcher"); List expungeList = listBy(sc); for (VmWorkJobVO job : expungeList) { - if (s_logger.isDebugEnabled()) - s_logger.debug("Expunge completed work job-" + job.getId()); + if (logger.isDebugEnabled()) + logger.debug("Expunge completed work job-" + job.getId()); expunge(job.getId()); _baseJobDao.expunge(job.getId()); } @@ -190,10 +188,10 @@ public class VmWorkJobDaoImpl extends GenericDaoBase implemen pstmt.execute(); } catch (SQLException e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "SQL failed to delete vm work job: " + e.getLocalizedMessage()); } catch (Throwable e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "caught an error during delete vm work job: " + e.getLocalizedMessage()); } @@ -205,10 +203,10 @@ public class VmWorkJobDaoImpl extends GenericDaoBase implemen pstmt.execute(); } catch (SQLException e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "SQL failed to delete async job: " + e.getLocalizedMessage()); } catch (Throwable e) { - s_logger.info("[ignored]" + logger.info("[ignored]" + "caught an error during delete async job: " + e.getLocalizedMessage()); } } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java index 9100ee5e34b..92a2acb9d4f 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java @@ -38,9 +38,13 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.context.CallContext; +import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.jobs.AsyncJob; @@ -60,12 +64,14 @@ import org.apache.cloudstack.jobs.JobInfo.Status; import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.cloudstack.management.ManagementServerHost; import org.apache.cloudstack.utils.identity.ManagementServerNode; -import org.apache.log4j.Logger; -import org.apache.log4j.MDC; -import org.apache.log4j.NDC; import com.cloud.cluster.ClusterManagerListener; +import com.cloud.network.Network; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkVO; import com.cloud.storage.Snapshot; +import com.cloud.storage.Volume; +import com.cloud.storage.VolumeDetailVO; import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.SnapshotDetailsDao; import com.cloud.storage.dao.SnapshotDetailsVO; @@ -93,9 +99,15 @@ import com.cloud.utils.db.TransactionCallbackNoReturn; import com.cloud.utils.db.TransactionStatus; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.ExceptionUtil; +import com.cloud.utils.fsm.NoTransitionException; import com.cloud.utils.mgmt.JmxUtil; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.VMInstanceDao; +import org.apache.logging.log4j.ThreadContext; + public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, ClusterManagerListener, Configurable { // Advanced public static final ConfigKey JobExpireMinutes = new ConfigKey("Advanced", Long.class, "job.expire.minutes", "1440", @@ -107,7 +119,6 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, "Time in seconds to wait in acquiring lock to submit a vm worker job", false); private static final ConfigKey HidePassword = new ConfigKey("Advanced", Boolean.class, "log.hide.password", "true", "If set to true, the password is hidden", true, ConfigKey.Scope.Global); - private static final Logger s_logger = Logger.getLogger(AsyncJobManagerImpl.class); private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds @@ -148,6 +159,15 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, @Inject private SnapshotDetailsDao _snapshotDetailsDao; + @Inject + private VolumeDataFactory volFactory; + @Inject + private VirtualMachineManager virtualMachineManager; + @Inject + private NetworkDao networkDao; + @Inject + private NetworkOrchestrationService networkOrchestrationService; + private volatile long _executionRunNumber = 1; private final ScheduledExecutorService _heartbeatScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AsyncJobMgr-Heartbeat")); @@ -218,8 +238,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, publishOnEventBus(job, "submit"); scheduleExecution(job, scheduleJobExecutionInContext); - if (s_logger.isDebugEnabled()) { - s_logger.debug("submit async job-" + job.getId() + ", details: " + StringUtils.cleanString(job.toString())); + if (logger.isDebugEnabled()) { + logger.debug("submit async job-" + job.getId() + ", details: " + StringUtils.cleanString(job.toString())); } return job.getId(); } @@ -261,7 +281,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, } } catch (Exception e) { String errMsg = "Unable to schedule async job for command " + job.getCmd() + ", unexpected exception."; - s_logger.warn(errMsg, e); + logger.warn(errMsg, e); throw new CloudRuntimeException(errMsg); } } @@ -270,16 +290,16 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, @DB public void completeAsyncJob(final long jobId, final Status jobStatus, final int resultCode, final String resultObject) { String resultObj = null; - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { resultObj = convertHumanReadableJson(obfuscatePassword(resultObject, HidePassword.value())); - s_logger.debug("Complete async job-" + jobId + ", jobStatus: " + jobStatus + ", resultCode: " + resultCode + ", result: " + resultObj); + logger.debug("Complete async job-" + jobId + ", jobStatus: " + jobStatus + ", resultCode: " + resultCode + ", result: " + resultObj); } final AsyncJobVO job = _jobDao.findById(jobId); if (job == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus + ", resultCode: " + resultCode + ", result: " + + if (logger.isDebugEnabled()) { + logger.debug("job-" + jobId + " no longer exists, we just log completion info here. " + jobStatus + ", resultCode: " + resultCode + ", result: " + resultObj); } // still purge item from queue to avoid any blocking @@ -288,8 +308,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, } if (job.getStatus() != JobInfo.Status.IN_PROGRESS) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("job-" + jobId + " is already completed."); + if (logger.isDebugEnabled()) { + logger.debug("job-" + jobId + " is already completed."); } // still purge item from queue to avoid any blocking _queueMgr.purgeAsyncJobQueueItemId(jobId); @@ -300,18 +320,18 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, job.setResult(resultObject); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Publish async job-" + jobId + " complete on message bus"); + if (logger.isDebugEnabled()) { + logger.debug("Publish async job-" + jobId + " complete on message bus"); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Wake up jobs related to job-" + jobId); + if (logger.isDebugEnabled()) { + logger.debug("Wake up jobs related to job-" + jobId); } final List wakeupList = Transaction.execute(new TransactionCallback>() { @Override public List doInTransaction(final TransactionStatus status) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Update db status for job-" + jobId); + if (logger.isDebugEnabled()) { + logger.debug("Update db status for job-" + jobId); } job.setCompleteMsid(getMsid()); job.setStatus(jobStatus); @@ -329,8 +349,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, job.setExecutingMsid(null); _jobDao.update(jobId, job); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Wake up jobs joined with job-" + jobId + " and disjoin all subjobs created from job- " + jobId); + if (logger.isDebugEnabled()) { + logger.debug("Wake up jobs joined with job-" + jobId + " and disjoin all subjobs created from job- " + jobId); } final List wakeupList = wakeupByJoinedJobCompletion(jobId); _joinMapDao.disjoinAllJobs(jobId); @@ -370,14 +390,14 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, @Override @DB public void updateAsyncJobStatus(final long jobId, final int processStatus, final String resultObject) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Update async-job progress, job-" + jobId + ", processStatus: " + processStatus + ", result: " + resultObject); + if (logger.isDebugEnabled()) { + logger.debug("Update async-job progress, job-" + jobId + ", processStatus: " + processStatus + ", result: " + resultObject); } final AsyncJobVO job = _jobDao.findById(jobId); if (job == null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus); + if (logger.isDebugEnabled()) { + logger.debug("job-" + jobId + " no longer exists, we just log progress info here. progress status: " + processStatus); } return; @@ -400,8 +420,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, @Override @DB public void updateAsyncJobAttachment(final long jobId, final String instanceType, final Long instanceId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Update async-job attachment, job-" + jobId + ", instanceType: " + instanceType + ", instanceId: " + instanceId); + if (logger.isDebugEnabled()) { + logger.debug("Update async-job attachment, job-" + jobId + ", instanceType: " + instanceType + ", instanceId: " + instanceId); } final AsyncJobVO job = _jobDao.findById(jobId); @@ -466,8 +486,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, @Override public void syncAsyncJobExecution(AsyncJob job, String syncObjType, long syncObjId, long queueSizeLimit) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Sync job-" + job.getId() + " execution on object " + syncObjType + "." + syncObjId); + if (logger.isDebugEnabled()) { + logger.debug("Sync job-" + job.getId() + " execution on object " + syncObjType + "." + syncObjId); } SyncQueueVO queue = null; @@ -543,7 +563,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, return dispatcher; } } else { - s_logger.warn("job-" + job.getId() + " is scheduled for wakeup run, but there is no joining info anymore"); + logger.warn("job-" + job.getId() + " is scheduled for wakeup run, but there is no joining info anymore"); } } return null; @@ -567,19 +587,19 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, String related = job.getRelated(); String logContext = job.getShortUuid(); if (related != null && !related.isEmpty()) { - NDC.push("job-" + related + "/" + "job-" + job.getId()); + ThreadContext.push("job-" + related + "/" + "job-" + job.getId()); AsyncJob relatedJob = _jobDao.findByIdIncludingRemoved(Long.parseLong(related)); if (relatedJob != null) { logContext = relatedJob.getShortUuid(); } } else { - NDC.push("job-" + job.getId()); + ThreadContext.push("job-" + job.getId()); } - MDC.put("logcontextid", logContext); + ThreadContext.put("logcontextid", logContext); try { super.run(); } finally { - NDC.pop(); + ThreadContext.pop(); } } @@ -596,8 +616,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, } catch (Exception e) { // Due to co-existence of normal-dispatched-job/wakeup-dispatched-job, MBean register() call // is expected to fail under situations - if (s_logger.isTraceEnabled()) - s_logger.trace("Unable to register active job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e)); + if (logger.isTraceEnabled()) + logger.trace("Unable to register active job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e)); } _jobMonitor.registerActiveTask(runNumber, job.getId()); @@ -610,11 +630,11 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, logContext = relatedJob.getShortUuid(); } } - MDC.put("logcontextid", logContext); + ThreadContext.put("logcontextid", logContext); // execute the job - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing " + StringUtils.cleanString(job.toString())); + if (logger.isDebugEnabled()) { + logger.debug("Executing " + StringUtils.cleanString(job.toString())); } if ((getAndResetPendingSignals(job) & AsyncJob.Constants.SIGNAL_MASK_WAKEUP) != 0) { @@ -623,25 +643,25 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, jobDispatcher.runJob(job); } else { // TODO, job wakeup is not in use yet - if (s_logger.isTraceEnabled()) - s_logger.trace("Unable to find a wakeup dispatcher from the joined job: " + job); + if (logger.isTraceEnabled()) + logger.trace("Unable to find a wakeup dispatcher from the joined job: " + job); } } else { AsyncJobDispatcher jobDispatcher = getDispatcher(job.getDispatcher()); if (jobDispatcher != null) { jobDispatcher.runJob(job); } else { - s_logger.error("Unable to find job dispatcher, job will be cancelled"); + logger.error("Unable to find job dispatcher, job will be cancelled"); completeAsyncJob(job.getId(), JobInfo.Status.FAILED, ApiErrorCode.INTERNAL_ERROR.getHttpCode(), null); } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Done executing " + job.getCmd() + " for job-" + job.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Done executing " + job.getCmd() + " for job-" + job.getId()); } } catch (Throwable e) { - s_logger.error("Unexpected exception", e); + logger.error("Unexpected exception", e); completeAsyncJob(job.getId(), JobInfo.Status.FAILED, ApiErrorCode.INTERNAL_ERROR.getHttpCode(), null); } finally { // guard final clause as well @@ -656,8 +676,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, } catch (Exception e) { // Due to co-existence of normal-dispatched-job/wakeup-dispatched-job, MBean unregister() call // is expected to fail under situations - if (s_logger.isTraceEnabled()) - s_logger.trace("Unable to unregister job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e)); + if (logger.isTraceEnabled()) + logger.trace("Unable to unregister job " + job.getId() + " to JMX monitoring due to exception " + ExceptionUtil.toString(e)); } // @@ -667,7 +687,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, _jobMonitor.unregisterActiveTask(runNumber); } catch (Throwable e) { - s_logger.error("Double exception", e); + logger.error("Double exception", e); } } } @@ -687,8 +707,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, private void executeQueueItem(SyncQueueItemVO item, boolean fromPreviousSession) { AsyncJobVO job = _jobDao.findById(item.getContentId()); if (job != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Schedule queued job-" + job.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Schedule queued job-" + job.getId()); } job.setSyncSource(item); @@ -702,37 +722,37 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, job.setExecutingMsid(getMsid()); _jobDao.update(job.getId(), job); } catch (Exception e) { - s_logger.warn("Unexpected exception while dispatching job-" + item.getContentId(), e); + logger.warn("Unexpected exception while dispatching job-" + item.getContentId(), e); try { _queueMgr.returnItem(item.getId()); } catch (Throwable thr) { - s_logger.error("Unexpected exception while returning job-" + item.getContentId() + " to queue", thr); + logger.error("Unexpected exception while returning job-" + item.getContentId() + " to queue", thr); } } try { scheduleExecution(job); } catch (RejectedExecutionException e) { - s_logger.warn("Execution for job-" + job.getId() + " is rejected, return it to the queue for next turn"); + logger.warn("Execution for job-" + job.getId() + " is rejected, return it to the queue for next turn"); try { _queueMgr.returnItem(item.getId()); } catch (Exception e2) { - s_logger.error("Unexpected exception while returning job-" + item.getContentId() + " to queue", e2); + logger.error("Unexpected exception while returning job-" + item.getContentId() + " to queue", e2); } try { job.setExecutingMsid(null); _jobDao.update(job.getId(), job); } catch (Exception e3) { - s_logger.warn("Unexpected exception while update job-" + item.getContentId() + " msid for bookkeeping"); + logger.warn("Unexpected exception while update job-" + item.getContentId() + " msid for bookkeeping"); } } } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unable to find related job for queue item: " + item.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Unable to find related job for queue item: " + item.toString()); } _queueMgr.purgeItem(item.getId()); @@ -745,8 +765,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, assert (executionContext != null); if (executionContext.getSyncSource() != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Release sync source for job-" + executionContext.getJob().getId() + " sync source: " + executionContext.getSyncSource().getContentType() + + if (logger.isDebugEnabled()) { + logger.debug("Release sync source for job-" + executionContext.getJob().getId() + " sync source: " + executionContext.getSyncSource().getContentType() + "-" + executionContext.getSyncSource().getContentId()); } @@ -803,8 +823,8 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, try { SyncQueueItemVO item = _queueMgr.dequeueFromOne(queueId, getMsid()); if (item != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing sync queue item: " + item.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Executing sync queue item: " + item.toString()); } executeQueueItem(item, false); @@ -812,7 +832,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, break; } } catch (Throwable e) { - s_logger.error("Unexpected exception when kicking sync queue-" + queueId, e); + logger.error("Unexpected exception when kicking sync queue-" + queueId, e); break; } } @@ -840,15 +860,15 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, protected void reallyRun() { try { if (!isAsyncJobsEnabled()) { - s_logger.info("A shutdown has been triggered. Not executing any async job"); + logger.info("A shutdown has been triggered. Not executing any async job"); return; } List l = _queueMgr.dequeueFromAny(getMsid(), MAX_ONETIME_SCHEDULE_SIZE); if (l != null && l.size() > 0) { for (SyncQueueItemVO item : l) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Execute sync-queue item: " + item.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Execute sync-queue item: " + item.toString()); } executeQueueItem(item, false); } @@ -862,7 +882,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, scheduleExecution(job, false); } } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to execute queue item, ", e); + logger.error("Unexpected exception when trying to execute queue item, ", e); } } }; @@ -889,7 +909,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, public void reallyRun() { try { - s_logger.trace("Begin cleanup expired async-jobs"); + logger.trace("Begin cleanup expired async-jobs"); // forcefully cancel blocking queue items if they've been staying there for too long List blockItems = _queueMgr.getBlockedQueueItems(JobCancelThresholdMinutes.value() * 60000, false); @@ -897,7 +917,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, for (SyncQueueItemVO item : blockItems) { try { if (item.getContentType().equalsIgnoreCase(SyncQueueItem.AsyncJobContentType)) { - s_logger.info("Remove Job-" + item.getContentId() + " from Queue-" + item.getId() + " since it has been blocked for too long"); + logger.info("Remove Job-" + item.getContentId() + " from Queue-" + item.getId() + " since it has been blocked for too long"); completeAsyncJob(item.getContentId(), JobInfo.Status.FAILED, 0, "Job is cancelled as it has been blocking others for too long"); _jobMonitor.unregisterByJobId(item.getContentId()); @@ -906,7 +926,7 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, // purge the item and resume queue processing _queueMgr.purgeItem(item.getId()); } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to remove job from sync queue, ", e); + logger.error("Unexpected exception when trying to remove job from sync queue, ", e); } } } @@ -918,12 +938,12 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, List unfinishedJobs = _jobDao.getExpiredUnfinishedJobs(cutTime, 100); for (AsyncJobVO job : unfinishedJobs) { try { - s_logger.info("Expunging unfinished job-" + job.getId()); + logger.info("Expunging unfinished job-" + job.getId()); _jobMonitor.unregisterByJobId(job.getId()); expungeAsyncJob(job); } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to expunge job-" + job.getId(), e); + logger.error("Unexpected exception when trying to expunge job-" + job.getId(), e); } } @@ -931,17 +951,17 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, List completedJobs = _jobDao.getExpiredCompletedJobs(cutTime, 100); for (AsyncJobVO job : completedJobs) { try { - s_logger.info("Expunging completed job-" + job.getId()); + logger.info("Expunging completed job-" + job.getId()); expungeAsyncJob(job); } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to expunge job-" + job.getId(), e); + logger.error("Unexpected exception when trying to expunge job-" + job.getId(), e); } } - s_logger.trace("End cleanup expired async-jobs"); + logger.trace("End cleanup expired async-jobs"); } catch (Throwable e) { - s_logger.error("Unexpected exception when trying to execute queue item, ", e); + logger.error("Unexpected exception when trying to execute queue item, ", e); } } }; @@ -1036,10 +1056,10 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, int apiPoolSize = cloudMaxActive / 2; int workPoolSize = (cloudMaxActive * 2) / 3; - s_logger.info("Start AsyncJobManager API executor thread pool in size " + apiPoolSize); + logger.info("Start AsyncJobManager API executor thread pool in size " + apiPoolSize); _apiJobExecutor = Executors.newFixedThreadPool(apiPoolSize, new NamedThreadFactory(AsyncJobManager.API_JOB_POOL_THREAD_PREFIX)); - s_logger.info("Start AsyncJobManager Work executor thread pool in size " + workPoolSize); + logger.info("Start AsyncJobManager Work executor thread pool in size " + workPoolSize); _workerJobExecutor = Executors.newFixedThreadPool(workPoolSize, new NamedThreadFactory(AsyncJobManager.WORK_JOB_POOL_THREAD_PREFIX)); } catch (final Exception e) { throw new ConfigurationException("Unable to load db.properties to configure AsyncJobManagerImpl"); @@ -1086,9 +1106,10 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, // reset job status for all jobs running on this ms node final List jobs = _jobDao.getResetJobs(msid); for (final AsyncJobVO job : jobs) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Cancel left-over job-" + job.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Cancel left-over job-" + job.getId()); } + cleanupResources(job); job.setStatus(JobInfo.Status.FAILED); job.setResultCode(ApiErrorCode.INTERNAL_ERROR.getHttpCode()); job.setResult("job cancelled because of management server restart or shutdown"); @@ -1097,34 +1118,116 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager, job.setLastUpdated(currentGMTTime); job.setRemoved(currentGMTTime); _jobDao.update(job.getId(), job); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Purge queue item for cancelled job-" + job.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Purge queue item for cancelled job-" + job.getId()); } _queueMgr.purgeAsyncJobQueueItemId(job.getId()); - if (ApiCommandResourceType.Volume.toString().equals(job.getInstanceType())) { - - try { - _volumeDetailsDao.removeDetail(job.getInstanceId(), "SNAPSHOT_ID"); - _volsDao.remove(job.getInstanceId()); - } catch (Exception e) { - s_logger.error("Unexpected exception while removing concurrent request meta data :" + e.getLocalizedMessage()); - } - } - } - final List snapshotList = _snapshotDetailsDao.findDetails(AsyncJob.Constants.MS_ID, Long.toString(msid), false); - for (final SnapshotDetailsVO snapshotDetailsVO : snapshotList) { - SnapshotInfo snapshot = snapshotFactory.getSnapshotOnPrimaryStore(snapshotDetailsVO.getResourceId()); - if (snapshot == null) { - _snapshotDetailsDao.remove(snapshotDetailsVO.getId()); - continue; - } - snapshotSrv.processEventOnSnapshotObject(snapshot, Snapshot.Event.OperationFailed); - _snapshotDetailsDao.removeDetail(snapshotDetailsVO.getResourceId(), AsyncJob.Constants.MS_ID); } + cleanupFailedSnapshotsCreatedWithDefaultStrategy(msid); } }); } catch (Throwable e) { - s_logger.warn("Unexpected exception in cleaning up left over jobs for mamagement server node " + msid, e); + logger.warn("Unexpected exception in cleaning up left over jobs for mamagement server node " + msid, e); + } + } + + /* + Cleanup Resources in transition state and move them to appropriate state + This will allow other operation on the resource, instead of being stuck in transition state + */ + protected boolean cleanupResources(AsyncJobVO job) { + try { + ApiCommandResourceType resourceType = ApiCommandResourceType.fromString(job.getInstanceType()); + if (resourceType == null) { + logger.warn("Unknown ResourceType. Skip Cleanup: " + job.getInstanceType()); + return true; + } + switch (resourceType) { + case Volume: + return cleanupVolume(job.getInstanceId()); + case VirtualMachine: + return cleanupVirtualMachine(job.getInstanceId()); + case Network: + return cleanupNetwork(job.getInstanceId()); + } + } catch (Exception e) { + logger.warn("Error while cleaning up resource: [" + job.getInstanceType().toString() + "] with Id: " + job.getInstanceId(), e); + return false; + } + return true; + } + + private boolean cleanupVolume(final long volumeId) { + VolumeInfo vol = volFactory.getVolume(volumeId); + if (vol == null) { + logger.warn("Volume not found. Skip Cleanup. VolumeId: " + volumeId); + return true; + } + if (vol.getState().isTransitional()) { + logger.debug("Cleaning up volume with Id: " + volumeId); + boolean status = vol.stateTransit(Volume.Event.OperationFailed); + cleanupFailedVolumesCreatedFromSnapshots(volumeId); + return status; + } + logger.debug("Volume not in transition state. Skip cleanup. VolumeId: " + volumeId); + return true; + } + + private boolean cleanupVirtualMachine(final long vmId) throws Exception { + VMInstanceVO vmInstanceVO = _vmInstanceDao.findById(vmId); + if (vmInstanceVO == null) { + logger.warn("Instance not found. Skip Cleanup. InstanceId: " + vmId); + return true; + } + if (vmInstanceVO.getState().isTransitional()) { + logger.debug("Cleaning up Instance with Id: " + vmId); + return virtualMachineManager.stateTransitTo(vmInstanceVO, VirtualMachine.Event.OperationFailed, vmInstanceVO.getHostId()); + } + logger.debug("Instance not in transition state. Skip cleanup. InstanceId: " + vmId); + return true; + } + + private boolean cleanupNetwork(final long networkId) throws Exception { + NetworkVO networkVO = networkDao.findById(networkId); + if (networkVO == null) { + logger.warn("Network not found. Skip Cleanup. NetworkId: " + networkId); + return true; + } + if (Network.State.Implementing.equals(networkVO.getState())) { + try { + logger.debug("Cleaning up Network with Id: " + networkId); + return networkOrchestrationService.stateTransitTo(networkVO, Network.Event.OperationFailed); + } catch (final NoTransitionException e) { + networkVO.setState(Network.State.Shutdown); + networkDao.update(networkVO.getId(), networkVO); + } + } + logger.debug("Network not in transition state. Skip cleanup. NetworkId: " + networkId); + return true; + } + + private void cleanupFailedVolumesCreatedFromSnapshots(final long volumeId) { + try { + VolumeDetailVO volumeDetail = _volumeDetailsDao.findDetail(volumeId, VolumeService.SNAPSHOT_ID); + if (volumeDetail != null) { + _volumeDetailsDao.removeDetail(volumeId, VolumeService.SNAPSHOT_ID); + _volsDao.remove(volumeId); + } + } catch (Exception e) { + logger.error("Unexpected exception while removing concurrent request meta data :" + e.getLocalizedMessage()); + } + } + + private void cleanupFailedSnapshotsCreatedWithDefaultStrategy(final long msid) { + final List snapshotList = _snapshotDetailsDao.findDetails(AsyncJob.Constants.MS_ID, Long.toString(msid), false); + for (final SnapshotDetailsVO snapshotDetailsVO : snapshotList) { + SnapshotInfo snapshot = snapshotFactory.getSnapshotOnPrimaryStore(snapshotDetailsVO.getResourceId()); + if (snapshot == null) { + _snapshotDetailsDao.remove(snapshotDetailsVO.getId()); + continue; + } + snapshotSrv.processEventOnSnapshotObject(snapshot, Snapshot.Event.OperationFailed); + _snapshotDetailsDao.removeDetail(snapshotDetailsVO.getResourceId(), AsyncJob.Constants.MS_ID); } } diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobMonitor.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobMonitor.java index b1cac3e79a5..b2216cb7502 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobMonitor.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobMonitor.java @@ -25,7 +25,6 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.AsyncJob; import org.apache.cloudstack.framework.jobs.AsyncJobManager; @@ -37,7 +36,6 @@ import org.apache.cloudstack.managed.context.ManagedContextTimerTask; import com.cloud.utils.component.ManagerBase; public class AsyncJobMonitor extends ManagerBase { - public static final Logger s_logger = Logger.getLogger(AsyncJobMonitor.class); @Inject private MessageBus _messageBus; @@ -86,7 +84,7 @@ public class AsyncJobMonitor extends ManagerBase { synchronized (this) { for (Map.Entry entry : _activeTasks.entrySet()) { if (entry.getValue().millisSinceLastJobHeartbeat() > _inactivityWarningThresholdMs) { - s_logger.warn("Task (job-" + entry.getValue().getJobId() + ") has been pending for " + logger.warn("Task (job-" + entry.getValue().getJobId() + ") has been pending for " + entry.getValue().millisSinceLastJobHeartbeat() / 1000 + " seconds"); } } @@ -110,7 +108,7 @@ public class AsyncJobMonitor extends ManagerBase { public void registerActiveTask(long runNumber, long jobId) { synchronized (this) { - s_logger.info("Add job-" + jobId + " into job monitoring"); + logger.info("Add job-" + jobId + " into job monitoring"); assert (_activeTasks.get(runNumber) == null); @@ -130,7 +128,7 @@ public class AsyncJobMonitor extends ManagerBase { ActiveTaskRecord record = _activeTasks.get(runNumber); assert (record != null); if (record != null) { - s_logger.info("Remove job-" + record.getJobId() + " from job monitoring"); + logger.info("Remove job-" + record.getJobId() + " from job monitoring"); if (record.isPoolThread()) _activePoolThreads.decrementAndGet(); @@ -148,7 +146,7 @@ public class AsyncJobMonitor extends ManagerBase { while (it.hasNext()) { Map.Entry entry = it.next(); if (entry.getValue().getJobId() == jobId) { - s_logger.info("Remove Job-" + entry.getValue().getJobId() + " from job monitoring due to job cancelling"); + logger.info("Remove Job-" + entry.getValue().getJobId() + " from job monitoring due to job cancelling"); if (entry.getValue().isPoolThread()) _activePoolThreads.decrementAndGet(); diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/JobSerializerHelper.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/JobSerializerHelper.java index 735d7cf73e2..fa1d175c45f 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/JobSerializerHelper.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/JobSerializerHelper.java @@ -27,7 +27,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Type; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.utils.exception.CloudRuntimeException; import com.google.gson.Gson; @@ -45,14 +46,14 @@ import com.google.gson.JsonSerializer; * Note: toPairList and appendPairList only support simple POJO objects currently */ public class JobSerializerHelper { - private static final Logger s_logger = Logger.getLogger(JobSerializerHelper.class); + protected static Logger LOGGER = LogManager.getLogger(JobSerializerHelper.class); public static final String token = "/"; private static Gson s_gson; static { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setVersion(1.5); - s_logger.debug("Job GSON Builder initialized."); + LOGGER.debug("Job GSON Builder initialized."); gsonBuilder.registerTypeAdapter(Class.class, new ClassTypeAdapter()); gsonBuilder.registerTypeAdapter(Throwable.class, new ThrowableTypeAdapter()); s_gson = gsonBuilder.create(); diff --git a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/SyncQueueManagerImpl.java b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/SyncQueueManagerImpl.java index 2f97991e3e3..3397daa5819 100644 --- a/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/SyncQueueManagerImpl.java +++ b/framework/jobs/src/main/java/org/apache/cloudstack/framework/jobs/impl/SyncQueueManagerImpl.java @@ -22,7 +22,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.jobs.dao.SyncQueueDao; import org.apache.cloudstack.framework.jobs.dao.SyncQueueItemDao; @@ -36,7 +35,6 @@ import com.cloud.utils.db.TransactionStatus; import com.cloud.utils.exception.CloudRuntimeException; public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManager { - public static final Logger s_logger = Logger.getLogger(SyncQueueManagerImpl.class.getName()); @Inject private SyncQueueDao _syncQueueDao; @@ -70,7 +68,7 @@ public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManage } }); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } return null; } @@ -84,7 +82,7 @@ public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManage public SyncQueueItemVO doInTransaction(TransactionStatus status) { SyncQueueVO queueVO = _syncQueueDao.findById(queueId); if(queueVO == null) { - s_logger.error("Sync queue(id: " + queueId + ") does not exist"); + logger.error("Sync queue(id: " + queueId + ") does not exist"); return null; } @@ -109,19 +107,19 @@ public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManage return itemVO; } else { - if (s_logger.isDebugEnabled()) - s_logger.debug("Sync queue (" + queueId + ") is currently empty"); + if (logger.isDebugEnabled()) + logger.debug("Sync queue (" + queueId + ") is currently empty"); } } else { - if (s_logger.isDebugEnabled()) - s_logger.debug("There is a pending process in sync queue(id: " + queueId + ")"); + if (logger.isDebugEnabled()) + logger.debug("There is a pending process in sync queue(id: " + queueId + ")"); } return null; } }); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } return null; @@ -169,7 +167,7 @@ public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManage return resultList; } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } return null; @@ -200,14 +198,14 @@ public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManage } }); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } } @Override @DB public void returnItem(final long queueItemId) { - s_logger.info("Returning queue item " + queueItemId + " back to queue for second try in case of DB deadlock"); + logger.info("Returning queue item " + queueItemId + " back to queue for second try in case of DB deadlock"); try { Transaction.execute(new TransactionCallbackNoReturn() { @Override @@ -228,7 +226,7 @@ public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManage } }); } catch (Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); } } @@ -247,8 +245,8 @@ public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManage if (nActiveItems < queueVO.getQueueSizeLimit()) return true; - if (s_logger.isDebugEnabled()) - s_logger.debug("Queue (queue id, sync type, sync id) - (" + queueVO.getId() + if (logger.isDebugEnabled()) + logger.debug("Queue (queue id, sync type, sync id) - (" + queueVO.getId() + "," + queueVO.getSyncObjType() + ", " + queueVO.getSyncObjId() + ") is reaching concurrency limit " + queueVO.getQueueSizeLimit()); return false; @@ -266,8 +264,8 @@ public class SyncQueueManagerImpl extends ManagerBase implements SyncQueueManage public void cleanupActiveQueueItems(Long msid, boolean exclusive) { List l = getActiveQueueItems(msid, false); for (SyncQueueItemVO item : l) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Discard left-over queue item: " + item.toString()); + if (logger.isInfoEnabled()) { + logger.info("Discard left-over queue item: " + item.toString()); } purgeItem(item.getId()); } diff --git a/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/AsyncJobTestDispatcher.java b/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/AsyncJobTestDispatcher.java index eb30a804978..604eae74afc 100644 --- a/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/AsyncJobTestDispatcher.java +++ b/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/AsyncJobTestDispatcher.java @@ -20,15 +20,12 @@ import java.util.Random; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.jobs.JobInfo.Status; import com.cloud.utils.component.AdapterBase; public class AsyncJobTestDispatcher extends AdapterBase implements AsyncJobDispatcher { - private static final Logger s_logger = - Logger.getLogger(AsyncJobTestDispatcher.class); @Inject private AsyncJobManager _asyncJobMgr; @@ -45,14 +42,14 @@ public class AsyncJobTestDispatcher extends AdapterBase implements AsyncJobDispa public void runJob(final AsyncJob job) { _testDashboard.increaseConcurrency(); - s_logger.info("Execute job " + job.getId() + ", current concurrency " + _testDashboard.getConcurrencyCount()); + logger.info("Execute job " + job.getId() + ", current concurrency " + _testDashboard.getConcurrencyCount()); int interval = 3000; try { Thread.sleep(interval); } catch (InterruptedException e) { - s_logger.debug("[ignored] ."); + logger.debug("[ignored] ."); } _asyncJobMgr.completeAsyncJob(job.getId(), Status.SUCCEEDED, 0, null); diff --git a/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImplTest.java b/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImplTest.java new file mode 100644 index 00000000000..0be5dbc01cb --- /dev/null +++ b/framework/jobs/src/test/java/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImplTest.java @@ -0,0 +1,96 @@ +// 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 org.apache.cloudstack.framework.jobs.impl; + +import com.cloud.network.Network; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkVO; +import com.cloud.storage.Volume; +import com.cloud.utils.fsm.NoTransitionException; +import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineManager; +import com.cloud.vm.dao.VMInstanceDao; +import org.apache.cloudstack.api.ApiCommandResourceType; +import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; +import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class AsyncJobManagerImplTest { + @Spy + @InjectMocks + AsyncJobManagerImpl asyncJobManager; + @Mock + VolumeDataFactory volFactory; + @Mock + VMInstanceDao vmInstanceDao; + @Mock + VirtualMachineManager virtualMachineManager; + @Mock + NetworkDao networkDao; + @Mock + NetworkOrchestrationService networkOrchestrationService; + + @Test + public void testCleanupVolumeResource() { + AsyncJobVO job = new AsyncJobVO(); + job.setInstanceType(ApiCommandResourceType.Volume.toString()); + job.setInstanceId(1L); + VolumeInfo volumeInfo = Mockito.mock(VolumeInfo.class); + when(volFactory.getVolume(Mockito.anyLong())).thenReturn(volumeInfo); + when(volumeInfo.getState()).thenReturn(Volume.State.Attaching); + asyncJobManager.cleanupResources(job); + Mockito.verify(volumeInfo, Mockito.times(1)).stateTransit(Volume.Event.OperationFailed); + } + + @Test + public void testCleanupVmResource() throws NoTransitionException { + AsyncJobVO job = new AsyncJobVO(); + job.setInstanceType(ApiCommandResourceType.VirtualMachine.toString()); + job.setInstanceId(1L); + VMInstanceVO vmInstanceVO = Mockito.mock(VMInstanceVO.class); + when(vmInstanceDao.findById(Mockito.anyLong())).thenReturn(vmInstanceVO); + when(vmInstanceVO.getState()).thenReturn(VirtualMachine.State.Starting); + when(vmInstanceVO.getHostId()).thenReturn(1L); + asyncJobManager.cleanupResources(job); + Mockito.verify(virtualMachineManager, Mockito.times(1)).stateTransitTo(vmInstanceVO, VirtualMachine.Event.OperationFailed, 1L); + } + + @Test + public void testCleanupNetworkResource() throws NoTransitionException { + AsyncJobVO job = new AsyncJobVO(); + job.setInstanceType(ApiCommandResourceType.Network.toString()); + job.setInstanceId(1L); + NetworkVO networkVO = Mockito.mock(NetworkVO.class); + when(networkDao.findById(Mockito.anyLong())).thenReturn(networkVO); + when(networkVO.getState()).thenReturn(Network.State.Implementing); + asyncJobManager.cleanupResources(job); + Mockito.verify(networkOrchestrationService, Mockito.times(1)).stateTransitTo(networkVO, + Network.Event.OperationFailed); + } +} diff --git a/framework/managed-context/pom.xml b/framework/managed-context/pom.xml index b8ac33e5514..bc7fa17940b 100644 --- a/framework/managed-context/pom.xml +++ b/framework/managed-context/pom.xml @@ -24,14 +24,17 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml - ch.qos.reload4j - reload4j - ${cs.reload4j.version} + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api diff --git a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/ManagedContextRunnable.java b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/ManagedContextRunnable.java index fed4e180ff8..be0ddceebb6 100644 --- a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/ManagedContextRunnable.java +++ b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/ManagedContextRunnable.java @@ -18,7 +18,8 @@ */ package org.apache.cloudstack.managed.context; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.managed.context.impl.DefaultManagedContext; @@ -26,7 +27,7 @@ public abstract class ManagedContextRunnable implements Runnable { private static final int SLEEP_COUNT = 120; - private static final Logger log = Logger.getLogger(ManagedContextRunnable.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final ManagedContext DEFAULT_MANAGED_CONTEXT = new DefaultManagedContext(); private static ManagedContext context; private static boolean managedContext = false; @@ -62,7 +63,7 @@ public abstract class ManagedContextRunnable implements Runnable { Thread.sleep(1000); if (context == null) - log.info("Sleeping until ManagedContext becomes available"); + logger.info("Sleeping until ManagedContext becomes available"); } catch (InterruptedException e) { throw new RuntimeException(e); } diff --git a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/impl/DefaultManagedContext.java b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/impl/DefaultManagedContext.java index 76e6d458028..33d181b3af1 100644 --- a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/impl/DefaultManagedContext.java +++ b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/context/impl/DefaultManagedContext.java @@ -23,7 +23,8 @@ import java.util.Stack; import java.util.concurrent.Callable; import java.util.concurrent.CopyOnWriteArrayList; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.managed.context.ManagedContext; import org.apache.cloudstack.managed.context.ManagedContextListener; @@ -32,7 +33,7 @@ import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal; public class DefaultManagedContext implements ManagedContext { - private static final Logger log = Logger.getLogger(DefaultManagedContext.class); + protected Logger logger = LogManager.getLogger(getClass()); List> listeners = new CopyOnWriteArrayList>(); @@ -87,7 +88,7 @@ public class DefaultManagedContext implements ManagedContext { if (firstError == null) { firstError = t; } - log.error("Failed onEnterContext for listener: " + listener, t); + logger.error("Failed onEnterContext for listener: " + listener, t); } /* Stack data structure is used because in between onEnter and onLeave @@ -113,7 +114,7 @@ public class DefaultManagedContext implements ManagedContext { invocation.listener.onLeaveContext(invocation.data, reentry); } catch (Throwable t) { lastError = t; - log.error("Failed onLeaveContext for listener: [" + invocation.listener + "]", t); + logger.error("Failed onLeaveContext for listener: [" + invocation.listener + "]", t); } } diff --git a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/threadlocal/ManagedThreadLocal.java b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/threadlocal/ManagedThreadLocal.java index f323d9a212a..96b9ad80324 100644 --- a/framework/managed-context/src/main/java/org/apache/cloudstack/managed/threadlocal/ManagedThreadLocal.java +++ b/framework/managed-context/src/main/java/org/apache/cloudstack/managed/threadlocal/ManagedThreadLocal.java @@ -21,7 +21,8 @@ package org.apache.cloudstack.managed.threadlocal; import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.managed.context.ManagedContextUtils; @@ -35,7 +36,7 @@ public class ManagedThreadLocal extends ThreadLocal { }; private static boolean s_validateContext = false; - private static final Logger log = Logger.getLogger(ManagedThreadLocal.class); + protected static Logger LOGGER = LogManager.getLogger(ManagedThreadLocal.class); @SuppressWarnings("unchecked") @Override @@ -71,7 +72,7 @@ public class ManagedThreadLocal extends ThreadLocal { private static void validateInContext(Object tl) { if (s_validateContext && !ManagedContextUtils.isInContext()) { String msg = "Using a managed thread local in a non managed context this WILL cause errors at runtime. TL [" + tl + "]"; - log.error(msg, new IllegalStateException(msg)); + LOGGER.error(msg, new IllegalStateException(msg)); } } diff --git a/framework/pom.xml b/framework/pom.xml index 679796c9370..79b1036eae7 100644 --- a/framework/pom.xml +++ b/framework/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT diff --git a/framework/quota/pom.xml b/framework/quota/pom.xml index 437577fbb33..2e608d7a248 100644 --- a/framework/quota/pom.xml +++ b/framework/quota/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManager.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManager.java index 44204e8d116..f4ee2362c7e 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManager.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManager.java @@ -16,11 +16,14 @@ //under the License. package org.apache.cloudstack.quota; +import com.cloud.user.AccountVO; import com.cloud.utils.component.Manager; import org.apache.cloudstack.quota.QuotaAlertManagerImpl.DeferredQuotaEmail; +import org.apache.cloudstack.quota.constant.QuotaConfig; public interface QuotaAlertManager extends Manager { + boolean isQuotaEmailTypeEnabledForAccount(AccountVO account, QuotaConfig.QuotaEmailTemplateTypes quotaEmailTemplateType); void checkAndSendQuotaAlertEmails(); void sendQuotaAlert(DeferredQuotaEmail emailToBeSent); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java index 555757ec847..b26b3171f5b 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaAlertManagerImpl.java @@ -29,18 +29,20 @@ import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.utils.DateUtil; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.constant.QuotaConfig.QuotaEmailTemplateTypes; import org.apache.cloudstack.quota.dao.QuotaAccountDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDao; import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.text.StrSubstitutor; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.ObjectUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.domain.DomainVO; @@ -64,7 +66,6 @@ import org.apache.commons.lang3.BooleanUtils; @Component public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertManager { - private static final Logger s_logger = Logger.getLogger(QuotaAlertManagerImpl.class); @Inject private AccountDao _accountDao; @@ -81,7 +82,10 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana @Inject private QuotaManager _quotaManager; - private boolean _lockAccountEnforcement = false; + @Inject + private QuotaEmailConfigurationDao quotaEmailConfigurationDao; + + protected boolean _lockAccountEnforcement = false; private String senderAddress; protected SMTPMailSender mailSender; @@ -126,69 +130,114 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana @Override public boolean start() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Starting Alert Manager"); + if (logger.isInfoEnabled()) { + logger.info("Starting Alert Manager"); } return true; } @Override public boolean stop() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Stopping Alert Manager"); + if (logger.isInfoEnabled()) { + logger.info("Stopping Alert Manager"); } return true; } + /** + * Returns whether a Quota email type is enabled or not for the provided account. + */ + @Override + public boolean isQuotaEmailTypeEnabledForAccount(AccountVO account, QuotaEmailTemplateTypes quotaEmailTemplateType) { + boolean quotaEmailsEnabled = QuotaConfig.QuotaEnableEmails.valueIn(account.getAccountId()); + if (!quotaEmailsEnabled) { + logger.debug("Configuration [{}] is disabled for account [{}]. Therefore, the account will not receive Quota email of type [{}].", QuotaConfig.QuotaEnableEmails.key(), account, quotaEmailTemplateType); + return false; + } + + QuotaEmailConfigurationVO quotaEmail = quotaEmailConfigurationDao.findByAccountIdAndEmailTemplateType(account.getAccountId(), quotaEmailTemplateType); + + boolean emailEnabled = quotaEmail == null || quotaEmail.isEnabled(); + if (emailEnabled) { + logger.debug("Quota email [{}] is enabled for account [{}].", quotaEmailTemplateType, account); + } else { + logger.debug("Quota email [{}] has been manually disabled for account [{}] through the API quotaConfigureEmail.", quotaEmailTemplateType, account); + } + return emailEnabled; + } + + @Override public void checkAndSendQuotaAlertEmails() { List deferredQuotaEmailList = new ArrayList(); - final BigDecimal zeroBalance = new BigDecimal(0); + + logger.info("Checking and sending quota alert emails."); for (final QuotaAccountVO quotaAccount : _quotaAcc.listAllQuotaAccount()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("checkAndSendQuotaAlertEmails accId=" + quotaAccount.getId()); - } - BigDecimal accountBalance = quotaAccount.getQuotaBalance(); - Date balanceDate = quotaAccount.getQuotaBalanceDate(); - Date alertDate = quotaAccount.getQuotaAlertDate(); - int lockable = quotaAccount.getQuotaEnforce(); - BigDecimal thresholdBalance = quotaAccount.getQuotaMinBalance(); - if (accountBalance != null) { - AccountVO account = _accountDao.findById(quotaAccount.getId()); - if (account == null) { - continue; // the account is removed - } - if (s_logger.isDebugEnabled()) { - s_logger.debug("checkAndSendQuotaAlertEmails: Check id=" + account.getId() + " bal=" + accountBalance + ", alertDate=" + alertDate + ", lockable=" + lockable); - } - if (accountBalance.compareTo(zeroBalance) < 0) { - if (_lockAccountEnforcement && (lockable == 1)) { - if (_quotaManager.isLockable(account)) { - s_logger.info("Locking account " + account.getAccountName() + " due to quota < 0."); - lockAccount(account.getId()); - } - } - if (alertDate == null || (balanceDate.after(alertDate) && getDifferenceDays(alertDate, new Date()) > 1)) { - s_logger.info("Sending alert " + account.getAccountName() + " due to quota < 0."); - deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY)); - } - } else if (accountBalance.compareTo(thresholdBalance) < 0) { - if (alertDate == null || (balanceDate.after(alertDate) && getDifferenceDays(alertDate, new Date()) > 1)) { - s_logger.info("Sending alert " + account.getAccountName() + " due to quota below threshold."); - deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW)); - } - } - } + checkQuotaAlertEmailForAccount(deferredQuotaEmailList, quotaAccount); } for (DeferredQuotaEmail emailToBeSent : deferredQuotaEmailList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("checkAndSendQuotaAlertEmails: Attempting to send quota alert email to users of account: " + emailToBeSent.getAccount().getAccountName()); - } + logger.debug("Attempting to send a quota alert email to users of account [{}].", emailToBeSent.getAccount().getAccountName()); sendQuotaAlert(emailToBeSent); } } + /** + * Checks a given quota account to see if they should receive any emails. First by checking if it has any balance at all, if its account can be found, then checks + * if they should receive either QUOTA_EMPTY or QUOTA_LOW emails, taking into account if these email templates are disabled or not for that account. + * */ + protected void checkQuotaAlertEmailForAccount(List deferredQuotaEmailList, QuotaAccountVO quotaAccount) { + logger.debug("Checking {} for email alerts.", quotaAccount); + BigDecimal accountBalance = quotaAccount.getQuotaBalance(); + + if (accountBalance == null) { + logger.debug("{} has a null balance, therefore it will not receive quota alert emails.", quotaAccount); + return; + } + + AccountVO account = _accountDao.findById(quotaAccount.getId()); + if (account == null) { + logger.debug("Account of {} is removed, thus it will not receive quota alert emails.", quotaAccount); + return; + } + + checkBalanceAndAddToEmailList(deferredQuotaEmailList, quotaAccount, account, accountBalance); + } + + private void checkBalanceAndAddToEmailList(List deferredQuotaEmailList, QuotaAccountVO quotaAccount, AccountVO account, BigDecimal accountBalance) { + Date balanceDate = quotaAccount.getQuotaBalanceDate(); + Date alertDate = quotaAccount.getQuotaAlertDate(); + int lockable = quotaAccount.getQuotaEnforce(); + BigDecimal thresholdBalance = quotaAccount.getQuotaMinBalance(); + + logger.debug("Checking {} with accountBalance [{}], alertDate [{}] and lockable [{}] to see if a quota alert email should be sent.", account, + accountBalance, DateUtil.displayDateInTimezone(QuotaManagerImpl.getUsageAggregationTimeZone(), alertDate), lockable); + + boolean shouldSendEmail = alertDate == null || (balanceDate.after(alertDate) && getDifferenceDays(alertDate, new Date()) > 1); + + if (accountBalance.compareTo(BigDecimal.ZERO) < 0) { + if (_lockAccountEnforcement && lockable == 1 && _quotaManager.isLockable(account)) { + logger.info("Locking {}, as quota balance is lower than 0.", account); + lockAccount(account.getId()); + } + + boolean quotaEmptyEmailEnabled = isQuotaEmailTypeEnabledForAccount(account, QuotaEmailTemplateTypes.QUOTA_EMPTY); + if (quotaEmptyEmailEnabled && shouldSendEmail) { + logger.debug("Adding {} to the deferred emails list, as quota balance is lower than 0.", account); + deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaEmailTemplateTypes.QUOTA_EMPTY)); + return; + } + } else if (accountBalance.compareTo(thresholdBalance) < 0) { + boolean quotaLowEmailEnabled = isQuotaEmailTypeEnabledForAccount(account, QuotaEmailTemplateTypes.QUOTA_LOW); + if (quotaLowEmailEnabled && shouldSendEmail) { + logger.debug("Adding {} to the deferred emails list, as quota balance [{}] is below the threshold [{}].", account, accountBalance, thresholdBalance); + deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, QuotaEmailTemplateTypes.QUOTA_LOW)); + return; + } + } + logger.debug("{} will not receive any quota alert emails in this round.", account); + } + @Override public void sendQuotaAlert(DeferredQuotaEmail emailToBeSent) { final AccountVO account = emailToBeSent.getAccount(); @@ -222,8 +271,8 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana final Map subjectOptionMap = generateOptionMap(account, userNames, accountDomain, balanceStr, usageStr, emailType, false); final Map bodyOptionMap = generateOptionMap(account, userNames, accountDomain, balanceStr, usageStr, emailType, true); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Sending quota alert with values: accountName [%s], accountID [%s], accountUsers [%s], domainName [%s], domainID [%s].", + if (logger.isDebugEnabled()) { + logger.debug(String.format("Sending quota alert with values: accountName [%s], accountID [%s], accountUsers [%s], domainName [%s], domainID [%s].", account.getAccountName(), account.getUuid(), userNames, accountDomain.getName(), accountDomain.getUuid())); } @@ -237,14 +286,14 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana sendQuotaAlert(account, emailRecipients, subject, body); emailToBeSent.sentSuccessfully(_quotaAcc); } catch (Exception e) { - s_logger.error(String.format("Unable to send quota alert email (subject=%s; body=%s) to account %s (%s) recipients (%s) due to error (%s)", subject, body, account.getAccountName(), + logger.error(String.format("Unable to send quota alert email (subject=%s; body=%s) to account %s (%s) recipients (%s) due to error (%s)", subject, body, account.getAccountName(), account.getUuid(), emailRecipients, e)); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Exception", e); + if (logger.isDebugEnabled()) { + logger.debug("Exception", e); } } } else { - s_logger.error(String.format("No quota email template found for type %s, cannot send quota alert email to account %s(%s)", emailType, account.getAccountName(), account.getUuid())); + logger.error(String.format("No quota email template found for type %s, cannot send quota alert email to account %s(%s)", emailType, account.getAccountName(), account.getUuid())); } } @@ -286,7 +335,7 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana return optionMap; } - public static long getDifferenceDays(Date d1, Date d2) { + public long getDifferenceDays(Date d1, Date d2) { long diff = d2.getTime() - d1.getTime(); return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS); } @@ -304,15 +353,15 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana acctForUpdate.setState(State.LOCKED); success = _accountDao.update(Long.valueOf(accountId), acctForUpdate); } else { - if (s_logger.isInfoEnabled()) { - s_logger.info("Attempting to lock a non-enabled account, current state is " + account.getState() + " (accountId: " + accountId + "), locking failed."); + if (logger.isInfoEnabled()) { + logger.info("Attempting to lock a non-enabled account, current state is " + account.getState() + " (accountId: " + accountId + "), locking failed."); } } } else { - s_logger.warn("Failed to lock account " + accountId + ", account not found."); + logger.warn("Failed to lock account " + accountId + ", account not found."); } } catch (Exception e) { - s_logger.error("Exception occurred while locking account by Quota Alert Manager", e); + logger.error("Exception occurred while locking account by Quota Alert Manager", e); throw e; } finally { TransactionLegacy.open(opendb).close(); @@ -387,7 +436,7 @@ public class QuotaAlertManagerImpl extends ManagerBase implements QuotaAlertMana mailProperties.setContentType("text/html; charset=utf-8"); if (CollectionUtils.isEmpty(emails)) { - s_logger.warn(String.format("Account [%s] does not have users with email registered, " + logger.warn(String.format("Account [%s] does not have users with email registered, " + "therefore we are unable to send quota alert email with subject [%s] and content [%s].", account.getUuid(), subject, body)); return; } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java index 56a6edf5db4..9c15a47444a 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaManagerImpl.java @@ -49,12 +49,11 @@ import org.apache.cloudstack.usage.UsageUnitTypes; import org.apache.cloudstack.utils.bytescale.ByteScaleUtils; import org.apache.cloudstack.utils.jsinterpreter.JsInterpreter; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.cloudstack.utils.usage.UsageUtils; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.usage.UsageVO; @@ -67,7 +66,6 @@ import com.cloud.utils.component.ManagerBase; @Component public class QuotaManagerImpl extends ManagerBase implements QuotaManager { - private static final Logger s_logger = Logger.getLogger(QuotaManagerImpl.class.getName()); @Inject private AccountDao _accountDao; @@ -87,8 +85,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { @Inject protected PresetVariableHelper presetVariableHelper; - private TimeZone _usageTimezone; - private int _aggregationDuration = 0; + private static TimeZone usageAggregationTimeZone = TimeZone.getTimeZone("GMT"); static final BigDecimal GiB_DECIMAL = BigDecimal.valueOf(ByteScaleUtils.GiB); List lockablesAccountTypes = Arrays.asList(Account.Type.NORMAL, Account.Type.DOMAIN_ADMIN); @@ -114,36 +111,28 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { mergeConfigs(configs, params); } - String aggregationRange = configs.get("usage.stats.job.aggregation.range"); - String timeZoneStr = configs.get("usage.aggregation.timezone"); - - if (timeZoneStr == null) { - timeZoneStr = "GMT"; - } - _usageTimezone = TimeZone.getTimeZone(timeZoneStr); - - _aggregationDuration = Integer.parseInt(aggregationRange); - if (_aggregationDuration < UsageUtils.USAGE_AGGREGATION_RANGE_MIN) { - s_logger.warn("Usage stats job aggregation range is to small, using the minimum value of " + UsageUtils.USAGE_AGGREGATION_RANGE_MIN); - _aggregationDuration = UsageUtils.USAGE_AGGREGATION_RANGE_MIN; - } - s_logger.info("Usage timezone = " + _usageTimezone + " AggregationDuration=" + _aggregationDuration); + String usageAggregationTimeZoneStr = ObjectUtils.defaultIfNull(configs.get("usage.aggregation.timezone"), "GMT"); + usageAggregationTimeZone = TimeZone.getTimeZone(usageAggregationTimeZoneStr); return true; } + public static TimeZone getUsageAggregationTimeZone() { + return usageAggregationTimeZone; + } + @Override public boolean start() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Starting Quota Manager"); + if (logger.isInfoEnabled()) { + logger.info("Starting Quota Manager"); } return true; } @Override public boolean stop() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Stopping Quota Manager"); + if (logger.isInfoEnabled()) { + logger.info("Stopping Quota Manager"); } return true; } @@ -152,7 +141,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { String accountToString = accountVo.reflectionToString(); if (CollectionUtils.isEmpty(accountQuotaUsages)) { - s_logger.info(String.format("Account [%s] does not have quota usages to process. Skipping it.", accountToString)); + logger.info(String.format("Account [%s] does not have quota usages to process. Skipping it.", accountToString)); return; } @@ -160,8 +149,9 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { Date startDate = firstQuotaUsage.getStartDate(); Date endDate = firstQuotaUsage.getStartDate(); - s_logger.info(String.format("Processing quota balance for account [%s] between [%s] and [%s].", accountToString, startDate, - accountQuotaUsages.get(accountQuotaUsages.size() - 1).getEndDate())); + logger.info("Processing quota balance for account [{}] between [{}] and [{}].", accountToString, + DateUtil.displayDateInTimezone(usageAggregationTimeZone, startDate), + DateUtil.displayDateInTimezone(usageAggregationTimeZone, accountQuotaUsages.get(accountQuotaUsages.size() - 1).getEndDate())); BigDecimal aggregatedUsage = BigDecimal.ZERO; long accountId = accountVo.getAccountId(); @@ -214,7 +204,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { aggregatedUsage = aggregatedUsage.add(aggregateCreditBetweenDates(accountId, domainId, new Date(0), startDate, accountToString)); QuotaBalanceVO firstBalance = new QuotaBalanceVO(accountId, domainId, aggregatedUsage, startDate); - s_logger.debug(String.format("Persisting the first quota balance [%s] for account [%s].", firstBalance, accountToString)); + logger.debug(String.format("Persisting the first quota balance [%s] for account [%s].", firstBalance, accountToString)); _quotaBalanceDao.saveQuotaBalance(firstBalance); } else { QuotaBalanceVO lastRealBalance = _quotaBalanceDao.findLastBalanceEntry(accountId, domainId, endDate); @@ -223,7 +213,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { aggregatedUsage = aggregatedUsage.add(lastRealBalance.getCreditBalance()); aggregatedUsage = aggregatedUsage.add(aggregateCreditBetweenDates(accountId, domainId, lastRealBalance.getUpdatedOn(), endDate, accountToString)); } else { - s_logger.warn(String.format("Account [%s] has quota usage entries, however it does not have a quota balance.", accountToString)); + logger.warn(String.format("Account [%s] has quota usage entries, however it does not have a quota balance.", accountToString)); } } @@ -248,17 +238,20 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { protected BigDecimal aggregateCreditBetweenDates(Long accountId, Long domainId, Date startDate, Date endDate, String accountToString) { List creditsReceived = _quotaBalanceDao.findCreditBalance(accountId, domainId, startDate, endDate); - s_logger.debug(String.format("Account [%s] has [%s] credit entries before [%s].", accountToString, creditsReceived.size(), endDate)); + logger.debug("Account [{}] has [{}] credit entries before [{}].", accountToString, creditsReceived.size(), + DateUtil.displayDateInTimezone(usageAggregationTimeZone, endDate)); BigDecimal aggregatedUsage = BigDecimal.ZERO; - s_logger.debug(String.format("Aggregating the account [%s] credit entries before [%s].", accountToString, endDate)); + logger.debug("Aggregating the account [{}] credit entries before [{}].", accountToString, + DateUtil.displayDateInTimezone(usageAggregationTimeZone, endDate)); for (QuotaBalanceVO credit : creditsReceived) { aggregatedUsage = aggregatedUsage.add(credit.getCreditBalance()); } - s_logger.debug(String.format("The aggregation of the account [%s] credit entries before [%s] resulted in the value [%s].", accountToString, endDate, aggregatedUsage)); + logger.debug("The aggregation of the account [{}] credit entries before [{}] resulted in the value [{}].", + accountToString, DateUtil.displayDateInTimezone(usageAggregationTimeZone, endDate), aggregatedUsage); return aggregatedUsage; } @@ -268,7 +261,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { List accounts = _accountDao.listAll(); String accountsToString = ReflectionToStringBuilderUtils.reflectOnlySelectedFields(accounts, "id", "uuid", "accountName", "domainId"); - s_logger.info(String.format("Starting quota usage calculation for accounts [%s].", accountsToString)); + logger.info(String.format("Starting quota usage calculation for accounts [%s].", accountsToString)); Map, Boolean>> mapQuotaTariffsPerUsageType = createMapQuotaTariffsPerUsageType(); @@ -276,7 +269,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { List usageRecords = getPendingUsageRecordsForQuotaAggregation(account); if (usageRecords == null) { - s_logger.debug(String.format("Account [%s] does not have pending usage records. Skipping to next account.", account.reflectionToString())); + logger.debug(String.format("Account [%s] does not have pending usage records. Skipping to next account.", account.reflectionToString())); continue; } @@ -284,7 +277,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { processQuotaBalanceForAccount(account, quotaUsages); } - s_logger.info(String.format("Finished quota usage calculation for accounts [%s].", accountsToString)); + logger.info(String.format("Finished quota usage calculation for accounts [%s].", accountsToString)); return true; } @@ -300,7 +293,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { return null; } - s_logger.debug(String.format("Retrieved [%s] pending usage records for account [%s].", usageRecords.second(), account.reflectionToString())); + logger.debug(String.format("Retrieved [%s] pending usage records for account [%s].", usageRecords.second(), account.reflectionToString())); return records; } @@ -308,7 +301,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { protected List createQuotaUsagesAccordingToQuotaTariffs(AccountVO account, List usageRecords, Map, Boolean>> mapQuotaTariffsPerUsageType) { String accountToString = account.reflectionToString(); - s_logger.info(String.format("Calculating quota usage of [%s] usage records for account [%s].", usageRecords.size(), accountToString)); + logger.info("Calculating quota usage of [{}] usage records for account [{}].", usageRecords.size(), accountToString); List> pairsUsageAndQuotaUsage = new ArrayList<>(); @@ -316,7 +309,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { for (UsageVO usageRecord : usageRecords) { int usageType = usageRecord.getUsageType(); - if (Boolean.FALSE.equals(shouldCalculateUsageRecord(account,usageRecord))) { + if (!shouldCalculateUsageRecord(account, usageRecord)) { pairsUsageAndQuotaUsage.add(new Pair<>(usageRecord, null)); continue; } @@ -332,7 +325,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { pairsUsageAndQuotaUsage.add(new Pair<>(usageRecord, quotaUsage)); } } catch (Exception e) { - s_logger.error(String.format("Failed to calculate the quota usage for account [%s] due to [%s].", accountToString, e.getMessage()), e); + logger.error(String.format("Failed to calculate the quota usage for account [%s] due to [%s].", accountToString, e.getMessage()), e); return new ArrayList<>(); } @@ -341,8 +334,8 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { protected boolean shouldCalculateUsageRecord(AccountVO accountVO, UsageVO usageRecord) { if (Boolean.FALSE.equals(QuotaConfig.QuotaAccountEnabled.valueIn(accountVO.getAccountId()))) { - s_logger.debug(String.format("Considering usage record [%s] as calculated and skipping it because account [%s] has the quota plugin disabled.", - usageRecord, accountVO.reflectionToString())); + logger.debug("Considering usage record [{}] as calculated and skipping it because account [{}] has the quota plugin disabled.", + usageRecord.toString(usageAggregationTimeZone), accountVO.reflectionToString()); return false; } return true; @@ -368,9 +361,8 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { protected BigDecimal aggregateQuotaTariffsValues(UsageVO usageRecord, List quotaTariffs, boolean hasAnyQuotaTariffWithActivationRule, JsInterpreter jsInterpreter, String accountToString) { - String usageRecordToString = usageRecord.toString(); - s_logger.debug(String.format("Validating usage record [%s] for account [%s] against [%s] quota tariffs.", usageRecordToString, accountToString, - quotaTariffs.size())); + String usageRecordToString = usageRecord.toString(usageAggregationTimeZone); + logger.debug("Validating usage record [{}] for account [{}] against [{}] quota tariffs.", usageRecordToString, accountToString, quotaTariffs.size()); PresetVariables presetVariables = getPresetVariables(hasAnyQuotaTariffWithActivationRule, usageRecord); BigDecimal aggregatedQuotaTariffsValue = BigDecimal.ZERO; @@ -381,7 +373,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { } } - s_logger.debug(String.format("The aggregation of the quota tariffs resulted in the value [%s] for the usage record [%s]. We will use this value to calculate the final" + logger.debug(String.format("The aggregation of the quota tariffs resulted in the value [%s] for the usage record [%s]. We will use this value to calculate the final" + " usage value.", aggregatedQuotaTariffsValue, usageRecordToString)); return aggregatedQuotaTariffsValue; @@ -408,10 +400,10 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { protected BigDecimal getQuotaTariffValueToBeApplied(QuotaTariffVO quotaTariff, JsInterpreter jsInterpreter, PresetVariables presetVariables) { String activationRule = quotaTariff.getActivationRule(); BigDecimal quotaTariffValue = quotaTariff.getCurrencyValue(); - String quotaTariffToString = quotaTariff.toString(); + String quotaTariffToString = quotaTariff.toString(usageAggregationTimeZone); if (StringUtils.isEmpty(activationRule)) { - s_logger.debug(String.format("Quota tariff [%s] does not have an activation rule, therefore we will use the quota tariff value [%s] in the calculation.", + logger.debug(String.format("Quota tariff [%s] does not have an activation rule, therefore we will use the quota tariff value [%s] in the calculation.", quotaTariffToString, quotaTariffValue)); return quotaTariffValue; } @@ -421,20 +413,20 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { String scriptResult = jsInterpreter.executeScript(activationRule).toString(); if (NumberUtils.isParsable(scriptResult)) { - s_logger.debug(String.format("The script [%s] of quota tariff [%s] had a numeric value [%s], therefore we will use it in the calculation.", activationRule, + logger.debug(String.format("The script [%s] of quota tariff [%s] had a numeric value [%s], therefore we will use it in the calculation.", activationRule, quotaTariffToString, scriptResult)); return new BigDecimal(scriptResult); } if (BooleanUtils.toBoolean(scriptResult)) { - s_logger.debug(String.format("The script [%s] of quota tariff [%s] had a true boolean result, therefore we will use the quota tariff's value [%s] in the calculation.", + logger.debug(String.format("The script [%s] of quota tariff [%s] had a true boolean result, therefore we will use the quota tariff's value [%s] in the calculation.", activationRule, quotaTariffToString, quotaTariffValue)); return quotaTariffValue; } - s_logger.debug(String.format("The script [%s] of quota tariff [%s] had the result [%s], therefore we will not use this quota tariff in the calculation.", activationRule, + logger.debug(String.format("The script [%s] of quota tariff [%s] had the result [%s], therefore we will not use this quota tariff in the calculation.", activationRule, quotaTariffToString, quotaTariffValue)); return BigDecimal.ZERO; @@ -470,10 +462,11 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { Date quotaTariffEndDate = quotaTariff.getEndDate(); if ((quotaTariffEndDate != null && usageRecordStartDate.after(quotaTariffEndDate)) || usageRecordEndDate.before(quotaTariffStartDate)) { - s_logger.debug(String.format("Not applying quota tariff [%s] in usage record [%s] of account [%s] due to it is out of the period to be applied. Period of the usage" - + " record [startDate: %s, endDate: %s], period of the quota tariff [startDate: %s, endDate: %s].", quotaTariff, usageRecord.toString(), accountToString, - DateUtil.getOutputString(usageRecordStartDate), DateUtil.getOutputString(usageRecordEndDate), DateUtil.getOutputString(quotaTariffStartDate), - DateUtil.getOutputString(quotaTariffEndDate))); + logger.debug("Not applying quota tariff [{}] in usage record [{}] of account [{}] due to it is out of the period to be applied. Period of the usage" + + " record [startDate: {}, endDate: {}], period of the quota tariff [startDate: {}, endDate: {}].", quotaTariff.toString(usageAggregationTimeZone), + usageRecord.toString(usageAggregationTimeZone), accountToString, DateUtil.displayDateInTimezone(usageAggregationTimeZone, usageRecordStartDate), + DateUtil.displayDateInTimezone(usageAggregationTimeZone, usageRecordEndDate), DateUtil.displayDateInTimezone(usageAggregationTimeZone, quotaTariffStartDate), + DateUtil.displayDateInTimezone(usageAggregationTimeZone, quotaTariffEndDate)); return false; } @@ -499,23 +492,23 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { } protected QuotaUsageVO createQuotaUsageAccordingToUsageUnit(UsageVO usageRecord, BigDecimal aggregatedQuotaTariffsValue, String accountToString) { - String usageRecordToString = usageRecord.toString(); + String usageRecordToString = usageRecord.toString(usageAggregationTimeZone); if (aggregatedQuotaTariffsValue.equals(BigDecimal.ZERO)) { - s_logger.debug(String.format("Usage record [%s] for account [%s] does not have quota tariffs to be calculated, therefore we will mark it as calculated.", - usageRecordToString, accountToString)); + logger.debug("No tariffs were applied to usage record [{}] of account [{}] or they resulted in 0; We will only mark the usage record as calculated.", + usageRecordToString, accountToString); return null; } QuotaTypes quotaType = QuotaTypes.listQuotaTypes().get(usageRecord.getUsageType()); String quotaUnit = quotaType.getQuotaUnit(); - s_logger.debug(String.format("Calculating value of usage record [%s] for account [%s] according to the aggregated quota tariffs value [%s] and its usage unit [%s].", + logger.debug(String.format("Calculating value of usage record [%s] for account [%s] according to the aggregated quota tariffs value [%s] and its usage unit [%s].", usageRecordToString, accountToString, aggregatedQuotaTariffsValue, quotaUnit)); BigDecimal usageValue = getUsageValueAccordingToUsageUnitType(usageRecord, aggregatedQuotaTariffsValue, quotaUnit); - s_logger.debug(String.format("The calculation of the usage record [%s] for account [%s] according to the aggregated quota tariffs value [%s] and its usage unit [%s] " + logger.debug(String.format("The calculation of the usage record [%s] for account [%s] according to the aggregated quota tariffs value [%s] and its usage unit [%s] " + "resulted in the value [%s].", usageRecordToString, accountToString, aggregatedQuotaTariffsValue, quotaUnit, usageValue)); QuotaUsageVO quotaUsageVo = new QuotaUsageVO(); @@ -560,7 +553,7 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager { protected BigDecimal getCostPerHour(BigDecimal costPerMonth, Date date) { BigDecimal hoursInCurrentMonth = BigDecimal.valueOf(DateUtil.getHoursInCurrentMonth(date)); - s_logger.trace(String.format("Dividing tariff cost per month [%s] by [%s] to get the tariffs cost per hour.", costPerMonth, hoursInCurrentMonth)); + logger.trace(String.format("Dividing tariff cost per month [%s] by [%s] to get the tariffs cost per hour.", costPerMonth, hoursInCurrentMonth)); return costPerMonth.divide(hoursInCurrentMonth, 8, RoundingMode.HALF_EVEN); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaStatementImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaStatementImpl.java index 9523c874558..5ee327fb9a5 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaStatementImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/QuotaStatementImpl.java @@ -31,9 +31,10 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.quota.QuotaAlertManagerImpl.DeferredQuotaEmail; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.dao.QuotaAccountDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDao; +import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.dao.QuotaUsageDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.user.AccountVO; @@ -42,7 +43,6 @@ import com.cloud.utils.component.ManagerBase; @Component public class QuotaStatementImpl extends ManagerBase implements QuotaStatement { - private static final Logger s_logger = Logger.getLogger(QuotaStatementImpl.class); @Inject private AccountDao _accountDao; @@ -55,6 +55,12 @@ public class QuotaStatementImpl extends ManagerBase implements QuotaStatement { @Inject private ConfigurationDao _configDao; + @Inject + private QuotaEmailConfigurationDao quotaEmailConfigurationDao; + + @Inject + private QuotaEmailTemplatesDao quotaEmailTemplatesDao; + final public static int s_LAST_STATEMENT_SENT_DAYS = 6; //ideally should be less than 7 days public enum QuotaStatementPeriods { @@ -91,16 +97,16 @@ public class QuotaStatementImpl extends ManagerBase implements QuotaStatement { @Override public boolean start() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Starting Statement Manager"); + if (logger.isInfoEnabled()) { + logger.info("Starting Statement Manager"); } return true; } @Override public boolean stop() { - if (s_logger.isInfoEnabled()) { - s_logger.info("Stopping Statement Manager"); + if (logger.isInfoEnabled()) { + logger.info("Stopping Statement Manager"); } return true; } @@ -113,35 +119,40 @@ public class QuotaStatementImpl extends ManagerBase implements QuotaStatement { if (quotaAccount.getQuotaBalance() == null) { continue; // no quota usage for this account ever, ignore } + AccountVO account = _accountDao.findById(quotaAccount.getId()); + if (account == null) { + logger.debug("Could not find an account corresponding to [{}]. Therefore, the statement email will not be sent.", quotaAccount); + continue; + } + + boolean quotaStatementEmailEnabled = _quotaAlert.isQuotaEmailTypeEnabledForAccount(account, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_STATEMENT); + if (!quotaStatementEmailEnabled) { + logger.debug("{} has [{}] email disabled. Therefore the email will not be sent.", quotaAccount, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_STATEMENT); + continue; + } //check if it is statement time Calendar interval[] = statementTime(Calendar.getInstance(), _period); Date lastStatementDate = quotaAccount.getLastStatementDate(); if (interval != null) { - AccountVO account = _accountDao.findById(quotaAccount.getId()); - if (account != null) { - if (lastStatementDate == null || getDifferenceDays(lastStatementDate, new Date()) >= s_LAST_STATEMENT_SENT_DAYS + 1) { - BigDecimal quotaUsage = _quotaUsage.findTotalQuotaUsage(account.getAccountId(), account.getDomainId(), null, interval[0].getTime(), interval[1].getTime()); - s_logger.info("For account=" + quotaAccount.getId() + ", quota used = " + quotaUsage); - // send statement - deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, quotaUsage, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_STATEMENT)); - } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("For " + quotaAccount.getId() + " the statement has been sent recently"); + if (lastStatementDate == null || getDifferenceDays(lastStatementDate, new Date()) >= s_LAST_STATEMENT_SENT_DAYS + 1) { + BigDecimal quotaUsage = _quotaUsage.findTotalQuotaUsage(account.getAccountId(), account.getDomainId(), null, interval[0].getTime(), interval[1].getTime()); + logger.info("Quota statement for account [{}] has an usage of [{}].", quotaAccount, quotaUsage); - } - } + // send statement + deferredQuotaEmailList.add(new DeferredQuotaEmail(account, quotaAccount, quotaUsage, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_STATEMENT)); + } else { + logger.debug("Quota statement has already been sent recently to account [{}].", quotaAccount); } } else if (lastStatementDate != null) { - s_logger.info("For " + quotaAccount.getId() + " it is already more than " + getDifferenceDays(lastStatementDate, new Date()) - + " days, will send statement in next cycle"); + logger.info("For account {} it is already more than {} days, will send statement in next cycle.", quotaAccount.getId(), getDifferenceDays(lastStatementDate, new Date())); } } for (DeferredQuotaEmail emailToBeSent : deferredQuotaEmailList) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Attempting to send quota STATEMENT email to users of account: " + emailToBeSent.getAccount().getAccountName()); + if (logger.isDebugEnabled()) { + logger.debug("Attempting to send quota STATEMENT email to users of account: " + emailToBeSent.getAccount().getAccountName()); } _quotaAlert.sendQuotaAlert(emailToBeSent); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java index 9723d3e5899..afbcf346e0b 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/activationrule/presetvariables/PresetVariableHelper.java @@ -47,7 +47,8 @@ import org.apache.cloudstack.usage.UsageTypes; import org.apache.cloudstack.utils.bytescale.ByteScaleUtils; import org.apache.cloudstack.utils.jsinterpreter.JsInterpreter; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenterVO; @@ -99,7 +100,7 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDao; @Component public class PresetVariableHelper { - protected Logger logger = Logger.getLogger(PresetVariableHelper.class); + protected Logger logger = LogManager.getLogger(PresetVariableHelper.class); @Inject AccountDao accountDao; diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaConfig.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaConfig.java index 59aa54424cf..df7ffa5c3cd 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaConfig.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/constant/QuotaConfig.java @@ -72,6 +72,9 @@ public interface QuotaConfig { ConfigKey QuotaEmailFooter = new ConfigKey<>("Advanced", String.class, "quota.email.footer", "", "Text to be added as a footer for quota emails. Line breaks are not automatically inserted between this section and the body.", true, ConfigKey.Scope.Domain); + ConfigKey QuotaEnableEmails = new ConfigKey<>("Advanced", Boolean.class, "quota.enable.emails", "true", + "Indicates whether Quota emails should be sent or not to accounts. When enabled, the behavior for each account can be overridden through the API quotaConfigureEmail.", true, ConfigKey.Scope.Account); + enum QuotaEmailTemplateTypes { QUOTA_LOW, QUOTA_EMPTY, QUOTA_UNLOCK_ACCOUNT, QUOTA_STATEMENT } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.java index 084abcfc2b5..b03b75f04f7 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaAccountDaoImpl.java @@ -21,7 +21,6 @@ import java.util.List; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.vo.QuotaAccountVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.Pair; @@ -34,7 +33,6 @@ import com.cloud.utils.db.TransactionStatus; @Component public class QuotaAccountDaoImpl extends GenericDaoBase implements QuotaAccountDao { - public static final Logger s_logger = Logger.getLogger(QuotaAccountDaoImpl.class); @Override public List listAllQuotaAccount() { @@ -44,7 +42,7 @@ public class QuotaAccountDaoImpl extends GenericDaoBase im accountsWithQuotaEnabled.add(account); continue; } - s_logger.trace(String.format("Account [%s] has the quota plugin disabled. Thus, it will not receive quota emails.", account)); + logger.trace(String.format("Account [%s] has the quota plugin disabled. Thus, it will not receive quota emails.", account)); } return accountsWithQuotaEnabled; } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java index 0ca7d9dbf8d..01272d1a618 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaBalanceDaoImpl.java @@ -23,7 +23,6 @@ import java.util.Date; import java.util.List; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Filter; @@ -37,7 +36,6 @@ import com.cloud.utils.db.TransactionStatus; @Component public class QuotaBalanceDaoImpl extends GenericDaoBase implements QuotaBalanceDao { - private static final Logger s_logger = Logger.getLogger(QuotaBalanceDaoImpl.class.getName()); @Override public QuotaBalanceVO findLastBalanceEntry(final Long accountId, final Long domainId, final Date beforeThis) { @@ -158,8 +156,8 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase im // get records before startDate to find start balance for (QuotaBalanceVO entry : quotaUsageRecords) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("FindQuotaBalance Entry=" + entry); + if (logger.isDebugEnabled()) { + logger.debug("FindQuotaBalance Entry=" + entry); } if (entry.getCreditsId() > 0) { trimmedRecords.add(entry); @@ -178,12 +176,12 @@ public class QuotaBalanceDaoImpl extends GenericDaoBase im List quotaBalance = lastQuotaBalanceVO(accountId, domainId, startDate); BigDecimal finalBalance = new BigDecimal(0); if (quotaBalance.isEmpty()) { - s_logger.info("There are no balance entries on or before the requested date."); + logger.info("There are no balance entries on or before the requested date."); return finalBalance; } for (QuotaBalanceVO entry : quotaBalance) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("lastQuotaBalance Entry=" + entry); + if (logger.isDebugEnabled()) { + logger.debug("lastQuotaBalance Entry=" + entry); } finalBalance = finalBalance.add(entry.getCreditBalance()); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDao.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDao.java new file mode 100644 index 00000000000..4bb3395cc11 --- /dev/null +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDao.java @@ -0,0 +1,36 @@ +// 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 org.apache.cloudstack.quota.dao; + +import com.cloud.utils.db.GenericDao; +import org.apache.cloudstack.quota.constant.QuotaConfig; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; + +import java.util.List; + +public interface QuotaEmailConfigurationDao extends GenericDao { + + QuotaEmailConfigurationVO findByAccountIdAndEmailTemplateId(long accountId, long emailTemplateId); + + QuotaEmailConfigurationVO updateQuotaEmailConfiguration(QuotaEmailConfigurationVO quotaEmailConfigurationVO); + + void persistQuotaEmailConfiguration(QuotaEmailConfigurationVO quotaEmailConfigurationVO); + + List listByAccount(long accountId); + + QuotaEmailConfigurationVO findByAccountIdAndEmailTemplateType(long accountId, QuotaConfig.QuotaEmailTemplateTypes quotaEmailTemplateType); +} diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDaoImpl.java new file mode 100644 index 00000000000..9466340ad05 --- /dev/null +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailConfigurationDaoImpl.java @@ -0,0 +1,105 @@ +// 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 org.apache.cloudstack.quota.dao; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.TransactionCallback; +import com.cloud.utils.db.TransactionLegacy; +import org.apache.cloudstack.quota.constant.QuotaConfig; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; +import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.util.List; + +@Component +public class QuotaEmailConfigurationDaoImpl extends GenericDaoBase implements QuotaEmailConfigurationDao { + + @Inject + private QuotaEmailTemplatesDao quotaEmailTemplatesDao; + + private SearchBuilder searchBuilderFindByIds; + + private SearchBuilder searchBuilderFindByTemplateName; + + private SearchBuilder searchBuilderFindByTemplateTypeAndAccountId; + + @PostConstruct + public void init() { + searchBuilderFindByIds = createSearchBuilder(); + searchBuilderFindByIds.and("account_id", searchBuilderFindByIds.entity().getAccountId(), SearchCriteria.Op.EQ); + searchBuilderFindByIds.and("email_template_id", searchBuilderFindByIds.entity().getEmailTemplateId(), SearchCriteria.Op.EQ); + searchBuilderFindByIds.done(); + + searchBuilderFindByTemplateName = quotaEmailTemplatesDao.createSearchBuilder(); + searchBuilderFindByTemplateName.and("template_name", searchBuilderFindByTemplateName.entity().getTemplateName(), SearchCriteria.Op.EQ); + + searchBuilderFindByTemplateTypeAndAccountId = createSearchBuilder(); + searchBuilderFindByTemplateTypeAndAccountId.and("account_id", searchBuilderFindByTemplateTypeAndAccountId.entity().getAccountId(), SearchCriteria.Op.EQ); + searchBuilderFindByTemplateTypeAndAccountId.join("email_template_id", searchBuilderFindByTemplateName, searchBuilderFindByTemplateName.entity().getId(), + searchBuilderFindByTemplateTypeAndAccountId.entity().getEmailTemplateId(), JoinBuilder.JoinType.INNER); + + searchBuilderFindByTemplateName.done(); + searchBuilderFindByTemplateTypeAndAccountId.done(); + } + + @Override + public QuotaEmailConfigurationVO findByAccountIdAndEmailTemplateId(long accountId, long emailTemplateId) { + SearchCriteria sc = searchBuilderFindByIds.create(); + sc.setParameters("account_id", accountId); + sc.setParameters("email_template_id", emailTemplateId); + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> findOneBy(sc)); + } + + @Override + public QuotaEmailConfigurationVO updateQuotaEmailConfiguration(QuotaEmailConfigurationVO quotaEmailConfigurationVO) { + SearchCriteria sc = searchBuilderFindByIds.create(); + sc.setParameters("account_id", quotaEmailConfigurationVO.getAccountId()); + sc.setParameters("email_template_id", quotaEmailConfigurationVO.getEmailTemplateId()); + Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> update(quotaEmailConfigurationVO, sc)); + + return quotaEmailConfigurationVO; + } + + @Override + public void persistQuotaEmailConfiguration(QuotaEmailConfigurationVO quotaEmailConfigurationVO) { + Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> persist(quotaEmailConfigurationVO)); + } + + @Override + public List listByAccount(long accountId) { + SearchCriteria sc = searchBuilderFindByIds.create(); + sc.setParameters("account_id", accountId); + + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback>) status -> listBy(sc)); + } + + @Override + public QuotaEmailConfigurationVO findByAccountIdAndEmailTemplateType(long accountId, QuotaConfig.QuotaEmailTemplateTypes quotaEmailTemplateType) { + SearchCriteria sc = searchBuilderFindByTemplateTypeAndAccountId.create(); + sc.setParameters("account_id", accountId); + sc.setJoinParameters("email_template_id", "template_name", quotaEmailTemplateType.toString()); + + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> findOneBy(sc)); + } +} diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDao.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDao.java index 573a7539744..346bb9a4a6a 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDao.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDao.java @@ -24,4 +24,6 @@ import java.util.List; public interface QuotaEmailTemplatesDao extends GenericDao { List listAllQuotaEmailTemplates(String templateName); boolean updateQuotaEmailTemplate(QuotaEmailTemplatesVO template); + + QuotaEmailTemplatesVO findById(long id); } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java index e774a52648e..c27f2df299b 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.quota.dao; import java.util.List; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.GenericDaoBase; @@ -33,7 +32,6 @@ import org.apache.commons.lang3.StringUtils; @Component public class QuotaEmailTemplatesDaoImpl extends GenericDaoBase implements QuotaEmailTemplatesDao { - private static final Logger s_logger = Logger.getLogger(QuotaEmailTemplatesDaoImpl.class); protected SearchBuilder QuotaEmailTemplateSearch; @@ -68,4 +66,9 @@ public class QuotaEmailTemplatesDaoImpl extends GenericDaoBase) status -> QuotaEmailTemplatesDaoImpl.super.findById(id)); + } } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java index 470c84ac4e1..8cbec8c8598 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaTariffDaoImpl.java @@ -24,7 +24,6 @@ import java.util.List; import org.apache.cloudstack.quota.constant.QuotaTypes; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.Pair; @@ -39,7 +38,6 @@ import com.cloud.utils.db.TransactionStatus; @Component public class QuotaTariffDaoImpl extends GenericDaoBase implements QuotaTariffDao { - private static final Logger s_logger = Logger.getLogger(QuotaTariffDaoImpl.class.getName()); private final SearchBuilder searchUsageType; private final SearchBuilder listAllIncludedUsageType; @@ -70,8 +68,8 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl if (result != null && !result.isEmpty()) { return result.get(0); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("QuotaTariffDaoImpl::findTariffPlanByUsageType: Missing quota type " + quotaType); + if (logger.isDebugEnabled()) { + logger.debug("QuotaTariffDaoImpl::findTariffPlanByUsageType: Missing quota type " + quotaType); } return null; } @@ -124,8 +122,8 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl List result = search(sc, filter); if (result != null && !result.isEmpty()) { tariffs.add(result.get(0)); - if (s_logger.isDebugEnabled()) { - s_logger.debug("ListAllTariffPlans on or before " + effectiveDate + " quota type " + result.get(0).getUsageTypeDescription() + " , effective Date=" + if (logger.isDebugEnabled()) { + logger.debug("ListAllTariffPlans on or before " + effectiveDate + " quota type " + result.get(0).getUsageTypeDescription() + " , effective Date=" + result.get(0).getEffectiveOn() + " val=" + result.get(0).getCurrencyValue()); } } @@ -212,7 +210,7 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl List quotaTariffs = pairQuotaTariffs.first(); if (CollectionUtils.isEmpty(quotaTariffs)) { - s_logger.debug(String.format("Could not find quota tariff with name [%s].", name)); + logger.debug(String.format("Could not find quota tariff with name [%s].", name)); return null; } @@ -225,10 +223,20 @@ public class QuotaTariffDaoImpl extends GenericDaoBase impl List quotaTariffs = pairQuotaTariffs.first(); if (CollectionUtils.isEmpty(quotaTariffs)) { - s_logger.debug(String.format("Could not find quota tariff with UUID [%s].", uuid)); + logger.debug(String.format("Could not find quota tariff with UUID [%s].", uuid)); return null; } return quotaTariffs.get(0); } + + @Override + public QuotaTariffVO findByIdIncludingRemoved(Long id) { + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> super.findByIdIncludingRemoved(id)); + } + + @Override + public QuotaTariffVO findByUuidIncludingRemoved(String uuid) { + return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback) status -> super.findByUuidIncludingRemoved(uuid)); + } } diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.java index 9134a4472b4..32b9c8d1d64 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/dao/QuotaUsageDaoImpl.java @@ -22,7 +22,6 @@ import java.util.Date; import java.util.List; import org.apache.cloudstack.quota.vo.QuotaUsageVO; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.db.Filter; @@ -36,7 +35,6 @@ import com.cloud.utils.db.TransactionStatus; @Component public class QuotaUsageDaoImpl extends GenericDaoBase implements QuotaUsageDao { - private static final Logger s_logger = Logger.getLogger(QuotaUsageDaoImpl.class); @Override public BigDecimal findTotalQuotaUsage(final Long accountId, final Long domainId, final Integer usageType, final Date startDate, final Date endDate) { diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaEmailConfigurationVO.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaEmailConfigurationVO.java new file mode 100644 index 00000000000..e50c7ce6250 --- /dev/null +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaEmailConfigurationVO.java @@ -0,0 +1,68 @@ +// 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 org.apache.cloudstack.quota.vo; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + +@Entity +@Table(name = "quota_email_configuration") +public class QuotaEmailConfigurationVO { + + @Column(name = "account_id") + private long accountId; + + @Column(name = "email_template_id") + private long emailTemplateId; + + @Column(name = "enabled") + private boolean enabled; + + public QuotaEmailConfigurationVO() { + } + + public QuotaEmailConfigurationVO(long accountId, long emailTemplateId, boolean enable) { + this.accountId = accountId; + this.emailTemplateId = emailTemplateId; + this.enabled = enable; + } + + public long getAccountId() { + return accountId; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + public long getEmailTemplateId() { + return emailTemplateId; + } + + public void setEmailTemplateId(long emailTemplateId) { + this.emailTemplateId = emailTemplateId; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } +} diff --git a/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaTariffVO.java b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaTariffVO.java index 7bc2870e36a..40a751c6200 100644 --- a/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaTariffVO.java +++ b/framework/quota/src/main/java/org/apache/cloudstack/quota/vo/QuotaTariffVO.java @@ -16,11 +16,13 @@ //under the License. package org.apache.cloudstack.quota.vo; -import org.apache.cloudstack.api.InternalIdentity; +import com.cloud.utils.DateUtil; +import org.apache.cloudstack.quota.QuotaTariff; import org.apache.cloudstack.quota.constant.QuotaTypes; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import com.cloud.utils.db.GenericDao; +import org.apache.commons.lang3.StringUtils; import javax.persistence.Column; import javax.persistence.Entity; @@ -33,11 +35,12 @@ import javax.persistence.TemporalType; import java.math.BigDecimal; import java.util.Date; +import java.util.TimeZone; import java.util.UUID; @Entity @Table(name = "quota_tariff") -public class QuotaTariffVO implements InternalIdentity { +public class QuotaTariffVO implements QuotaTariff { private static final long serialVersionUID = -7117933766387653203L; @Id @@ -240,6 +243,7 @@ public class QuotaTariffVO implements InternalIdentity { return description; } + @Override public String getUuid() { return uuid; } @@ -261,6 +265,12 @@ public class QuotaTariffVO implements InternalIdentity { @Override public String toString() { - return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "uuid", "name", "effectiveOn", "endDate"); - }; + return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, "uuid", "name", "usageName"); + } + + public String toString(TimeZone timeZone) { + String startDateString = DateUtil.displayDateInTimezone(timeZone, getEffectiveOn()); + String endDateString = DateUtil.displayDateInTimezone(timeZone, getEndDate()); + return String.format("%s,\"startDate\":\"%s\",\"endDate\":\"%s\"}", StringUtils.chop(this.toString()), startDateString, endDateString); + } } diff --git a/framework/quota/src/main/resources/META-INF/cloudstack/quota/spring-framework-quota-context.xml b/framework/quota/src/main/resources/META-INF/cloudstack/quota/spring-framework-quota-context.xml index 5f1c274f049..e634321208f 100644 --- a/framework/quota/src/main/resources/META-INF/cloudstack/quota/spring-framework-quota-context.xml +++ b/framework/quota/src/main/resources/META-INF/cloudstack/quota/spring-framework-quota-context.xml @@ -30,5 +30,6 @@ + diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java index ae2f2e9926e..54d4f1d5b69 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaAlertManagerImplTest.java @@ -30,9 +30,12 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.dao.QuotaAccountDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDaoImpl; import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,7 +43,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; @@ -71,6 +74,9 @@ public class QuotaAlertManagerImplTest extends TestCase { @Mock private ConfigurationDao configDao; + @Mock + private QuotaEmailConfigurationDaoImpl quotaEmailConfigurationDaoMock; + @Mock private QuotaAccountVO quotaAccountVOMock; @@ -92,43 +98,142 @@ public class QuotaAlertManagerImplTest extends TestCase { @Before public void setup() throws IllegalAccessException, NoSuchFieldException, ConfigurationException { - TransactionLegacy.open("QuotaAlertManagerImplTest"); - } - - @Test - public void testCheckAndSendQuotaAlertEmails() { AccountVO accountVO = new AccountVO(); accountVO.setId(2L); accountVO.setDomainId(1L); accountVO.setType(Account.Type.NORMAL); Mockito.when(accountDao.findById(Mockito.anyLong())).thenReturn(accountVO); - QuotaAccountVO acc = new QuotaAccountVO(2L); - acc.setQuotaBalance(new BigDecimal(404)); - acc.setQuotaMinBalance(new BigDecimal(100)); - acc.setQuotaBalanceDate(new Date()); - acc.setQuotaAlertDate(null); - acc.setQuotaEnforce(0); - List accounts = new ArrayList<>(); - accounts.add(acc); - Mockito.when(quotaAcc.listAllQuotaAccount()).thenReturn(accounts); + Mockito.doReturn(new BigDecimal(404)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(new BigDecimal(100)).when(quotaAccountVOMock).getQuotaMinBalance(); + Mockito.doReturn(balanceDateMock).when(quotaAccountVOMock).getQuotaBalanceDate(); + Mockito.doReturn(null).when(quotaAccountVOMock).getQuotaAlertDate(); + Mockito.doReturn(0).when(quotaAccountVOMock).getQuotaEnforce(); - // Don't test sendQuotaAlert yet - Mockito.doNothing().when(quotaAlertManager).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); - Mockito.lenient().doReturn(true).when(quotaAlertManager).lockAccount(Mockito.anyLong()); + TransactionLegacy.open("QuotaAlertManagerImplTest"); + } - // call real method on send monthly statement - Mockito.doCallRealMethod().when(quotaAlertManager).checkAndSendQuotaAlertEmails(); + @Test + public void isQuotaEmailTypeEnabledForAccountTestConfigurationIsEnabledAndEmailIsConfiguredReturnConfiguredValue() { + boolean expectedValue = !QuotaConfig.QuotaEnableEmails.value(); + QuotaEmailConfigurationVO quotaEmailConfigurationVoMock = Mockito.mock(QuotaEmailConfigurationVO.class); + Mockito.when(quotaEmailConfigurationVoMock.isEnabled()).thenReturn(expectedValue); + Mockito.doReturn(quotaEmailConfigurationVoMock).when(quotaEmailConfigurationDaoMock).findByAccountIdAndEmailTemplateType(Mockito.anyLong(), Mockito.any(QuotaConfig.QuotaEmailTemplateTypes.class)); - // Case1: valid balance, no email should be sent - quotaAlertManager.checkAndSendQuotaAlertEmails(); - Mockito.verify(quotaAlertManager, Mockito.times(0)).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); + boolean result = quotaAlertManager.isQuotaEmailTypeEnabledForAccount(accountMock, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY); - // Case2: low balance, email should be sent - accounts.get(0).setQuotaBalance(new BigDecimal(99)); - //Mockito.when(quotaAcc.listAll()).thenReturn(accounts); - quotaAlertManager.checkAndSendQuotaAlertEmails(); - Mockito.verify(quotaAlertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); + Assert.assertEquals(expectedValue, result); + } + + @Test + public void isQuotaEmailTypeEnabledForAccountTestConfigurationIsEnabledAndEmailIsNotConfiguredReturnDefaultValue() { + boolean defaultValue = QuotaConfig.QuotaEnableEmails.value(); + + boolean result = quotaAlertManager.isQuotaEmailTypeEnabledForAccount(accountMock, QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY); + + Assert.assertEquals(defaultValue, result); + } + + @Test + public void checkQuotaAlertEmailForAccountTestNullAccountBalance() { + Mockito.doReturn(null).when(quotaAccountVOMock).getQuotaBalance(); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(accountDao, Mockito.never()).findById(Mockito.any()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestNullAccount() { + Mockito.doReturn(new BigDecimal(1)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(null).when(accountDao).findById(Mockito.any()); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAccountVOMock, Mockito.never()).getQuotaBalanceDate(); + } + + @Test + public void checkQuotaAlertEmailForAccountTestEnoughBalance() { + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager, Mockito.never()).lockAccount(Mockito.anyLong()); + Mockito.verify(deferredQuotaEmailListMock, Mockito.never()).add(Mockito.any()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndLockAccountEnforcementFalse() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + + quotaAlertManager._lockAccountEnforcement = false; + Mockito.doReturn(1).when(quotaAccountVOMock).getQuotaEnforce(); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager, Mockito.never()).lockAccount(Mockito.anyLong()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndLockableFalse() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + + quotaAlertManager._lockAccountEnforcement = true; + Mockito.doReturn(1).when(quotaAccountVOMock).getQuotaEnforce(); + Mockito.doReturn(false).when(quotaManagerMock).isLockable(Mockito.any()); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager, Mockito.never()).lockAccount(Mockito.anyLong()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndIsLockableFalse() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + + quotaAlertManager._lockAccountEnforcement = true; + Mockito.doReturn(1).when(quotaAccountVOMock).getQuotaEnforce(); + Mockito.doReturn(false).when(quotaManagerMock).isLockable(Mockito.any()); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager, Mockito.never()).lockAccount(Mockito.anyLong()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndLockAccount() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + + quotaAlertManager._lockAccountEnforcement = true; + Mockito.doReturn(1).when(quotaAccountVOMock).getQuotaEnforce(); + Mockito.doReturn(true).when(quotaManagerMock).isLockable(Mockito.any()); + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(quotaAlertManager).lockAccount(Mockito.anyLong()); + } + + @Test + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndAlertDateNotNullAndBalanceDateNotAfter() { + Mockito.doReturn(new Date()).when(quotaAccountVOMock).getQuotaAlertDate(); + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(false).when(balanceDateMock).after(Mockito.any()); + + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(deferredQuotaEmailListMock, Mockito.never()).add(Mockito.any()); + } + + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndAlertDateNotNullAndGetDifferenceDaysSmallerThanOne() { + Mockito.doReturn(new Date()).when(quotaAccountVOMock).getQuotaAlertDate(); + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(true).when(balanceDateMock).after(Mockito.any()); + Mockito.doReturn(0L).when(quotaAlertManager).getDifferenceDays(Mockito.any(), Mockito.any()); + + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(deferredQuotaEmailListMock, Mockito.never()).add(Mockito.any()); + } + + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndAlertDateNotNullAndBalanceAfterAndDifferenceBiggerThanOne() { + Mockito.doReturn(new Date()).when(quotaAccountVOMock).getQuotaAlertDate(); + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + Mockito.doReturn(true).when(balanceDateMock).after(Mockito.any()); + Mockito.doReturn(2).when(quotaAlertManager).getDifferenceDays(Mockito.any(), Mockito.any()); + + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(deferredQuotaEmailListMock).add(Mockito.any()); + } + + public void checkQuotaAlertEmailForAccountTestBalanceLowerThanZeroAndAlertDateNull() { + Mockito.doReturn(new BigDecimal(-1)).when(quotaAccountVOMock).getQuotaBalance(); + + quotaAlertManager.checkQuotaAlertEmailForAccount(deferredQuotaEmailListMock, quotaAccountVOMock); + Mockito.verify(deferredQuotaEmailListMock).add(Mockito.any()); } @Test @@ -177,7 +282,7 @@ public class QuotaAlertManagerImplTest extends TestCase { quotaAlertManager.sendQuotaAlert(email); assertTrue(email.getSendDate() != null); - Mockito.verify(quotaAlertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(), Mockito.anyListOf(String.class), Mockito.anyString(), Mockito.anyString()); + Mockito.verify(quotaAlertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(), Mockito.anyList(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(quotaAlertManager.mailSender, Mockito.times(1)).sendMail(Mockito.any(SMTPMailProperties.class)); } @@ -196,12 +301,12 @@ public class QuotaAlertManagerImplTest extends TestCase { @Test public void testGetDifferenceDays() { Date now = new Date(); - assertTrue(QuotaAlertManagerImpl.getDifferenceDays(now, now) == 0L); + assertTrue(quotaAlertManager.getDifferenceDays(now, now) == 0L); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("UTC")); Calendar c2 = (Calendar)c.clone(); c2.add(Calendar.DATE, 1); - assertEquals(1L, QuotaAlertManagerImpl.getDifferenceDays(c.getTime(), c2.getTime())); + assertEquals(1L, quotaAlertManager.getDifferenceDays(c.getTime(), c2.getTime())); } @Test diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java index 1b28f66b2bb..507834fef41 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/QuotaStatementTest.java @@ -16,7 +16,6 @@ // under the License. package org.apache.cloudstack.quota; -import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.math.BigDecimal; import java.util.ArrayList; @@ -24,21 +23,25 @@ import java.util.Calendar; import java.util.Date; import java.util.List; -import javax.mail.MessagingException; import javax.naming.ConfigurationException; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.quota.QuotaStatementImpl.QuotaStatementPeriods; +import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.dao.QuotaAccountDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDaoImpl; +import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.dao.QuotaUsageDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; +import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.Spy; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.user.AccountVO; import com.cloud.user.dao.AccountDao; @@ -60,7 +63,20 @@ public class QuotaStatementTest extends TestCase { @Mock QuotaAlertManager alertManager; + @Mock + QuotaEmailConfigurationDaoImpl quotaEmailConfigurationDaoMock; + + @Mock + QuotaEmailTemplatesDao quotaEmailTemplatesDaoMock; + + @Mock + QuotaEmailTemplatesVO quotaEmailTemplatesVOMock; + + @Mock + List listMock; + @Spy + @InjectMocks QuotaStatementImpl quotaStatement = new QuotaStatementImpl(); private void injectMockToField(Object mock, String fieldName) throws NoSuchFieldException, IllegalAccessException { @@ -227,7 +243,10 @@ public class QuotaStatementTest extends TestCase { @Test - public void testSendStatement() throws UnsupportedEncodingException, MessagingException { + public void sendStatementTestUnconfiguredEmail() { + boolean defaultConfigurationValue = QuotaConfig.QuotaEnableEmails.value(); + Mockito.doReturn(defaultConfigurationValue).when(alertManager).isQuotaEmailTypeEnabledForAccount(Mockito.any(AccountVO.class), Mockito.any(QuotaConfig.QuotaEmailTemplateTypes.class)); + Calendar date = Calendar.getInstance(); AccountVO accountVO = new AccountVO(); accountVO.setId(2L); @@ -252,4 +271,46 @@ public class QuotaStatementTest extends TestCase { } } + @Test + public void sendStatementTestEnabledEmail() { + Mockito.doReturn(true).when(alertManager).isQuotaEmailTypeEnabledForAccount(Mockito.any(AccountVO.class), Mockito.any(QuotaConfig.QuotaEmailTemplateTypes.class)); + + Calendar date = Calendar.getInstance(); + AccountVO accountVO = new AccountVO(); + accountVO.setId(2L); + accountVO.setDomainId(1L); + Mockito.lenient().when(accountDao.findById(Mockito.anyLong())).thenReturn(accountVO); + + QuotaAccountVO acc = new QuotaAccountVO(2L); + acc.setQuotaBalance(new BigDecimal(404)); + acc.setLastStatementDate(null); + List accounts = new ArrayList<>(); + accounts.add(acc); + Mockito.lenient().when(quotaAcc.listAllQuotaAccount()).thenReturn(accounts); + + Mockito.lenient().when(quotaUsage.findTotalQuotaUsage(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.any(Date.class), Mockito.any(Date.class))) + .thenReturn(new BigDecimal(100)); + + // call real method on send monthly statement + quotaStatement.sendStatement(); + Calendar period[] = quotaStatement.statementTime(date, QuotaStatementPeriods.MONTHLY); + if (period != null){ + Mockito.verify(alertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class)); + } + } + + @Test + public void sendStatementTestDisabledEmail() { + QuotaAccountVO quotaAccountVoMock = Mockito.mock(QuotaAccountVO.class); + Mockito.when(quotaAccountVoMock.getQuotaBalance()).thenReturn(BigDecimal.ONE); + Mockito.when(quotaAcc.listAllQuotaAccount()).thenReturn(List.of(quotaAccountVoMock)); + AccountVO accountVoMock = Mockito.mock(AccountVO.class); + Mockito.doReturn(accountVoMock).when(accountDao).findById(Mockito.anyLong()); + Mockito.doReturn(false).when(alertManager).isQuotaEmailTypeEnabledForAccount(Mockito.any(AccountVO.class), Mockito.any(QuotaConfig.QuotaEmailTemplateTypes.class)); + + quotaStatement.sendStatement(); + + Mockito.verify(quotaStatement, Mockito.never()).statementTime(Mockito.any(), Mockito.any()); + } + } diff --git a/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java b/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java index fc9b4af0ed2..c1e59f99863 100644 --- a/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java +++ b/framework/quota/src/test/java/org/apache/cloudstack/quota/constant/QuotaTypesTest.java @@ -22,7 +22,7 @@ import org.apache.cloudstack.api.response.UsageTypeResponse; import org.apache.cloudstack.usage.UsageTypes; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.util.List; import java.util.Map; diff --git a/framework/rest/pom.xml b/framework/rest/pom.xml index 5895ce05cbb..d1ffff3c7bd 100644 --- a/framework/rest/pom.xml +++ b/framework/rest/pom.xml @@ -22,7 +22,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml cloud-framework-rest @@ -68,7 +68,7 @@ com.sun.xml.bind jaxb-impl - ${cs.jaxb.version} + ${cs.jaxb.impl.version} org.apache.cxf diff --git a/framework/security/pom.xml b/framework/security/pom.xml index 956b1f97d21..f41d5460bb7 100644 --- a/framework/security/pom.xml +++ b/framework/security/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-framework - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/framework/security/src/main/java/org/apache/cloudstack/framework/security/keys/KeysManagerImpl.java b/framework/security/src/main/java/org/apache/cloudstack/framework/security/keys/KeysManagerImpl.java index 15bb49c65ff..fa092ebdd3c 100644 --- a/framework/security/src/main/java/org/apache/cloudstack/framework/security/keys/KeysManagerImpl.java +++ b/framework/security/src/main/java/org/apache/cloudstack/framework/security/keys/KeysManagerImpl.java @@ -23,7 +23,8 @@ import javax.inject.Inject; import javax.net.ssl.KeyManager; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.cloudstack.framework.config.ConfigDepot; import org.apache.cloudstack.framework.config.ConfigKey; @@ -50,7 +51,7 @@ import com.cloud.utils.db.SearchCriteria; * */ public class KeysManagerImpl implements KeysManager, Configurable { - private static final Logger s_logger = Logger.getLogger(KeysManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject ConfigurationDao _configDao; @@ -87,7 +88,7 @@ public class KeysManagerImpl implements KeysManager, Configurable { return EncryptionIV.value(); } - private static String getBase64EncodedRandomKey(int nBits) { + private String getBase64EncodedRandomKey(int nBits) { SecureRandom random; try { random = SecureRandom.getInstance("SHA1PRNG"); @@ -95,7 +96,7 @@ public class KeysManagerImpl implements KeysManager, Configurable { random.nextBytes(keyBytes); return Base64.encodeBase64URLSafeString(keyBytes); } catch (NoSuchAlgorithmException e) { - s_logger.error("Unhandled exception: ", e); + logger.error("Unhandled exception: ", e); } return null; } diff --git a/framework/security/src/main/java/org/apache/cloudstack/framework/security/keystore/KeystoreManagerImpl.java b/framework/security/src/main/java/org/apache/cloudstack/framework/security/keystore/KeystoreManagerImpl.java index 03a91fecc8e..3fc2ff3702e 100644 --- a/framework/security/src/main/java/org/apache/cloudstack/framework/security/keystore/KeystoreManagerImpl.java +++ b/framework/security/src/main/java/org/apache/cloudstack/framework/security/keystore/KeystoreManagerImpl.java @@ -31,7 +31,6 @@ import java.util.regex.Pattern; import javax.inject.Inject; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.utils.Ternary; @@ -41,7 +40,6 @@ import com.cloud.utils.security.CertificateHelper; @Component public class KeystoreManagerImpl extends ManagerBase implements KeystoreManager { - private static final Logger s_logger = Logger.getLogger(KeystoreManagerImpl.class); @Inject private KeystoreDao _ksDao; @@ -49,7 +47,7 @@ public class KeystoreManagerImpl extends ManagerBase implements KeystoreManager @Override public boolean validateCertificate(String certificate, String key, String domainSuffix) { if (StringUtils.isAnyEmpty(certificate, key, domainSuffix)) { - s_logger.error("Invalid parameter found in (certificate, key, domainSuffix) tuple for domain: " + domainSuffix); + logger.error("Invalid parameter found in (certificate, key, domainSuffix) tuple for domain: " + domainSuffix); return false; } @@ -60,9 +58,9 @@ public class KeystoreManagerImpl extends ManagerBase implements KeystoreManager if (ks != null) return true; - s_logger.error("Unabled to construct keystore for domain: " + domainSuffix); + logger.error("Unabled to construct keystore for domain: " + domainSuffix); } catch (Exception e) { - s_logger.error("Certificate validation failed due to exception for domain: " + domainSuffix, e); + logger.error("Certificate validation failed due to exception for domain: " + domainSuffix, e); } return false; } @@ -109,9 +107,9 @@ public class KeystoreManagerImpl extends ManagerBase implements KeystoreManager return CertificateHelper.buildAndSaveKeystore(certs, storePassword); } catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | InvalidKeySpecException | IOException e) { String msg = String.format("Unable to build keystore for %s due to %s", name, e.getClass().getSimpleName()); - s_logger.warn(msg); - if (s_logger.isDebugEnabled()) { - s_logger.debug(msg, e); + logger.warn(msg); + if (logger.isDebugEnabled()) { + logger.debug(msg, e); } } return null; diff --git a/framework/spring/lifecycle/pom.xml b/framework/spring/lifecycle/pom.xml index b27c583947c..fbdb2e60dc6 100644 --- a/framework/spring/lifecycle/pom.xml +++ b/framework/spring/lifecycle/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java index ad26fb19fc3..beb535cb296 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/AbstractSmartLifeCycle.java @@ -18,10 +18,13 @@ */ package org.apache.cloudstack.spring.lifecycle; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.context.SmartLifecycle; public abstract class AbstractSmartLifeCycle implements SmartLifecycle { + protected Logger logger = LogManager.getLogger(getClass()); boolean running = false; @Override diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java index b0c1dcc0760..15c1ccac5d9 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/CloudStackExtendedLifeCycle.java @@ -29,7 +29,6 @@ import javax.management.MalformedObjectNameException; import javax.management.NotCompliantMBeanException; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.utils.component.ComponentLifecycle; import com.cloud.utils.component.SystemIntegrityChecker; @@ -39,7 +38,6 @@ import com.cloud.utils.mgmt.ManagementBean; public class CloudStackExtendedLifeCycle extends AbstractBeanCollector { - private static final Logger log = Logger.getLogger(CloudStackExtendedLifeCycle.class); Map> sorted = new TreeMap>(); @@ -59,14 +57,14 @@ public class CloudStackExtendedLifeCycle extends AbstractBeanCollector { protected void checkIntegrity() { for (SystemIntegrityChecker checker : getBeans(SystemIntegrityChecker.class)) { - log.info("Running system integrity checker " + checker); + logger.info("Running system integrity checker " + checker); checker.check(); } } public void startBeans() { - log.info("Starting CloudStack Components"); + logger.info("Starting CloudStack Components"); with(new WithComponentLifeCycle() { @Override @@ -78,34 +76,34 @@ public class CloudStackExtendedLifeCycle extends AbstractBeanCollector { try { JmxUtil.registerMBean(mbean); } catch (MalformedObjectNameException e) { - log.warn("Unable to register MBean: " + mbean.getName(), e); + logger.warn("Unable to register MBean: " + mbean.getName(), e); } catch (InstanceAlreadyExistsException e) { - log.warn("Unable to register MBean: " + mbean.getName(), e); + logger.warn("Unable to register MBean: " + mbean.getName(), e); } catch (MBeanRegistrationException e) { - log.warn("Unable to register MBean: " + mbean.getName(), e); + logger.warn("Unable to register MBean: " + mbean.getName(), e); } catch (NotCompliantMBeanException e) { - log.warn("Unable to register MBean: " + mbean.getName(), e); + logger.warn("Unable to register MBean: " + mbean.getName(), e); } - log.info("Registered MBean: " + mbean.getName()); + logger.info("Registered MBean: " + mbean.getName()); } } }); - log.info("Done Starting CloudStack Components"); + logger.info("Done Starting CloudStack Components"); } public void stopBeans() { with(new WithComponentLifeCycle() { @Override public void with(ComponentLifecycle lifecycle) { - log.info("stopping bean " + lifecycle.getName()); + logger.info("stopping bean " + lifecycle.getName()); lifecycle.stop(); } }); } private void configure() { - log.info("Configuring CloudStack Components"); + logger.info("Configuring CloudStack Components"); with(new WithComponentLifeCycle() { @Override @@ -113,13 +111,13 @@ public class CloudStackExtendedLifeCycle extends AbstractBeanCollector { try { lifecycle.configure(lifecycle.getName(), lifecycle.getConfigParams()); } catch (ConfigurationException e) { - log.error("Failed to configure " + lifecycle.getName(), e); + logger.error("Failed to configure " + lifecycle.getName(), e); throw new CloudRuntimeException(e); } } }); - log.info("Done Configuring CloudStack Components"); + logger.info("Done Configuring CloudStack Components"); } private void sortBeans() { diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java index 5c5e9165b17..3a9bb04ce96 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/DumpRegistry.java @@ -22,7 +22,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.utils.component.ComponentLifecycleBase; import com.cloud.utils.component.Named; @@ -30,7 +29,6 @@ import com.cloud.utils.component.Registry; public class DumpRegistry extends ComponentLifecycleBase { - private static final Logger log = Logger.getLogger(DumpRegistry.class); List> registries; @@ -55,7 +53,7 @@ public class DumpRegistry extends ComponentLifecycleBase { buffer.append(getName(o)); } - log.info("Registry [" + registry.getName() + "] contains [" + buffer + "]"); + logger.info("Registry [" + registry.getName() + "] contains [" + buffer + "]"); } return super.start(); diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java index a077bc8f4f0..47aa82b9dc0 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/ExtensionRegistry.java @@ -28,7 +28,8 @@ import java.util.concurrent.CopyOnWriteArrayList; import javax.annotation.PostConstruct; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.factory.BeanNameAware; import org.apache.cloudstack.framework.config.ConfigKey; @@ -38,7 +39,7 @@ import com.cloud.utils.component.Registry; public class ExtensionRegistry implements Registry, Configurable, BeanNameAware { - private static final Logger log = Logger.getLogger(ExtensionRegistry.class); + protected Logger logger = LogManager.getLogger(getClass()); String name; String beanName; @@ -111,7 +112,7 @@ public class ExtensionRegistry implements Registry, Configurable, BeanNa registered.add(item); } - log.debug("Registering extension [" + name + "] in [" + this.name + "]"); + logger.debug("Registering extension [" + name + "] in [" + this.name + "]"); return true; } diff --git a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java index 43efd846184..19d1fe3acc5 100644 --- a/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java +++ b/framework/spring/lifecycle/src/main/java/org/apache/cloudstack/spring/lifecycle/registry/RegistryLifecycle.java @@ -23,7 +23,8 @@ import java.util.Iterator; import java.util.Properties; import java.util.Set; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ApplicationContext; @@ -35,7 +36,7 @@ import com.cloud.utils.component.Registry; public class RegistryLifecycle implements BeanPostProcessor, SmartLifecycle, ApplicationContextAware { - private static final Logger log = Logger.getLogger(RegistryLifecycle.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final String EXTENSION_EXCLUDE = "extensions.exclude"; public static final String EXTENSION_INCLUDE_PREFIX = "extensions.include."; @@ -70,7 +71,7 @@ public class RegistryLifecycle implements BeanPostProcessor, SmartLifecycle, App boolean result = excludes.contains(name); if (result) { - log.info("Excluding extension [" + name + "] based on configuration"); + logger.info("Excluding extension [" + name + "] based on configuration"); } return result; @@ -109,7 +110,7 @@ public class RegistryLifecycle implements BeanPostProcessor, SmartLifecycle, App while (iter.hasNext()) { Object next = iter.next(); if (registry.register(next)) { - log.debug("Registered " + next); + logger.debug("Registered " + next); } else { iter.remove(); } diff --git a/framework/spring/module/pom.xml b/framework/spring/module/pom.xml index cdeb4d35311..ea39e3a6141 100644 --- a/framework/spring/module/pom.xml +++ b/framework/spring/module/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java index f054d3998ac..8bbbc35f7e5 100644 --- a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/factory/CloudStackSpringContext.java @@ -24,7 +24,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.io.Resource; @@ -36,7 +37,7 @@ import org.apache.cloudstack.spring.module.model.ModuleDefinitionSet; public class CloudStackSpringContext { - private static final Logger log = Logger.getLogger(CloudStackSpringContext.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final String CLOUDSTACK_CONTEXT_SERVLET_KEY = CloudStackSpringContext.class.getSimpleName(); public static final String CLOUDSTACK_CONTEXT = "META-INF/cloudstack"; @@ -76,7 +77,7 @@ public class CloudStackSpringContext { for (String appName : contextMap.keySet()) { ApplicationContext contex = contextMap.get(appName); if (contex instanceof ConfigurableApplicationContext) { - log.trace("registering shutdown hook for bean "+ appName); + logger.trace("registering shutdown hook for bean "+ appName); ((ConfigurableApplicationContext)contex).registerShutdownHook(); } } @@ -129,7 +130,7 @@ public class CloudStackSpringContext { String urlString = r.getURL().toExternalForm(); urlList.add(urlString); } catch (IOException e) { - log.error("Failed to create URL for " + r.getDescription(), e); + logger.error("Failed to create URL for " + r.getDescription(), e); } } diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java index 83d2feaa845..d61e26fc3a8 100644 --- a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/model/impl/DefaultModuleDefinitionSet.java @@ -33,7 +33,8 @@ import java.util.Set; import java.util.Stack; import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -48,7 +49,7 @@ import org.apache.cloudstack.spring.module.model.ModuleDefinitionSet; public class DefaultModuleDefinitionSet implements ModuleDefinitionSet { - private static final Logger log = Logger.getLogger(DefaultModuleDefinitionSet.class); + protected Logger logger = LogManager.getLogger(getClass()); public static final String DEFAULT_CONFIG_RESOURCES = "DefaultConfigResources"; public static final String DEFAULT_CONFIG_PROPERTIES = "DefaultConfigProperties"; @@ -98,22 +99,26 @@ public class DefaultModuleDefinitionSet implements ModuleDefinitionSet { public void with(ModuleDefinition def, Stack parents) { try { String moduleDefinitionName = def.getName(); - log.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); + logger.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); ApplicationContext context = getApplicationContext(moduleDefinitionName); try { - Runnable runnable = context.getBean("moduleStartup", Runnable.class); - log.info(String.format("Starting module [%s].", moduleDefinitionName)); - runnable.run(); + if (context.containsBean("moduleStartup")) { + Runnable runnable = context.getBean("moduleStartup", Runnable.class); + logger.info(String.format("Starting module [%s].", moduleDefinitionName)); + runnable.run(); + } else { + logger.debug(String.format("Could not get module [%s] context bean.", moduleDefinitionName)); + } } catch (BeansException e) { - log.warn(String.format("Failed to start module [%s] due to: [%s].", moduleDefinitionName, e.getMessage())); - if (log.isDebugEnabled()) { - log.debug(String.format("module start failure of module [%s] was due to: ", moduleDefinitionName), e); + logger.warn(String.format("Failed to start module [%s] due to: [%s].", moduleDefinitionName, e.getMessage())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("module start failure of module [%s] was due to: ", moduleDefinitionName), e); } } } catch (EmptyStackException e) { - log.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); - if (log.isDebugEnabled()) { - log.debug("Failed to obtain module context: ", e); + logger.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); + if (logger.isDebugEnabled()) { + logger.debug("Failed to obtain module context: ", e); } } } @@ -126,19 +131,23 @@ public class DefaultModuleDefinitionSet implements ModuleDefinitionSet { public void with(ModuleDefinition def, Stack parents) { try { String moduleDefinitionName = def.getName(); - log.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); + if (parents.isEmpty()) { + logger.debug(String.format("Could not find module [%s] context as they have no parents.", moduleDefinitionName)); + return; + } + logger.debug(String.format("Trying to obtain module [%s] context.", moduleDefinitionName)); ApplicationContext parent = getApplicationContext(parents.peek().getName()); - log.debug(String.format("Trying to load module [%s] context.", moduleDefinitionName)); + logger.debug(String.format("Trying to load module [%s] context.", moduleDefinitionName)); loadContext(def, parent); } catch (EmptyStackException e) { - log.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); - if (log.isDebugEnabled()) { - log.debug("Failed to obtain module context: ", e); + logger.warn(String.format("Failed to obtain module context due to [%s]. Using root context instead.", e.getMessage())); + if (logger.isDebugEnabled()) { + logger.debug("Failed to obtain module context: ", e); } } catch (BeansException e) { - log.warn(String.format("Failed to start module [%s] due to: [%s].", def.getName(), e.getMessage())); - if (log.isDebugEnabled()) { - log.debug(String.format("module start failure of module [%s] was due to: ", def.getName()), e); + logger.warn(String.format("Failed to start module [%s] due to: [%s].", def.getName(), e.getMessage())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("module start failure of module [%s] was due to: ", def.getName()), e); } } } @@ -155,13 +164,13 @@ public class DefaultModuleDefinitionSet implements ModuleDefinitionSet { context.setClassLoader(def.getClassLoader()); long start = System.currentTimeMillis(); - if (log.isInfoEnabled()) { + if (logger.isInfoEnabled()) { for (Resource resource : resources) { - log.info("Loading module context [" + def.getName() + "] from " + resource); + logger.info("Loading module context [" + def.getName() + "] from " + resource); } } context.refresh(); - log.info("Loaded module context [" + def.getName() + "] in " + (System.currentTimeMillis() - start) + " ms"); + logger.info("Loaded module context [" + def.getName() + "] in " + (System.currentTimeMillis() - start) + " ms"); contexts.put(def.getName(), context); @@ -241,7 +250,7 @@ public class DefaultModuleDefinitionSet implements ModuleDefinitionSet { withModule(new WithModule() { @Override public void with(ModuleDefinition def, Stack parents) { - log.info(String.format("Module Hierarchy:%" + ((parents.size() * 2) + 1) + "s%s", "", def.getName())); + logger.info(String.format("Module Hierarchy:%" + ((parents.size() * 2) + 1) + "s%s", "", def.getName())); } }); } @@ -256,7 +265,7 @@ public class DefaultModuleDefinitionSet implements ModuleDefinitionSet { return; if (!shouldLoad(def)) { - log.info("Excluding context [" + def.getName() + "] based on configuration"); + logger.info("Excluding context [" + def.getName() + "] based on configuration"); return; } diff --git a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java index 549c69d5da9..3b6133b91b4 100644 --- a/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java +++ b/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/web/CloudStackContextLoaderListener.java @@ -23,7 +23,8 @@ import java.io.IOException; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.context.ApplicationContext; import org.springframework.web.context.ConfigurableWebApplicationContext; import org.springframework.web.context.ContextLoaderListener; @@ -35,7 +36,7 @@ public class CloudStackContextLoaderListener extends ContextLoaderListener { public static final String WEB_PARENT_MODULE = "parentModule"; public static final String WEB_PARENT_MODULE_DEFAULT = "web"; - private static final Logger log = Logger.getLogger(CloudStackContextLoaderListener.class); + protected Logger logger = LogManager.getLogger(getClass()); CloudStackSpringContext cloudStackContext; String configuredParentName; @@ -47,13 +48,13 @@ public class CloudStackContextLoaderListener extends ContextLoaderListener { @Override public void contextInitialized(ServletContextEvent event) { - log.trace("context initialized"); + logger.trace("context initialized"); try { cloudStackContext = new CloudStackSpringContext(); cloudStackContext.registerShutdownHook(); event.getServletContext().setAttribute(CloudStackSpringContext.CLOUDSTACK_CONTEXT_SERVLET_KEY, cloudStackContext); } catch (IOException e) { - log.error("Failed to start CloudStack", e); + logger.error("Failed to start CloudStack", e); throw new RuntimeException("Failed to initialize CloudStack Spring modules", e); } @@ -67,7 +68,7 @@ public class CloudStackContextLoaderListener extends ContextLoaderListener { @Override protected void customizeContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) { - log.trace("customize context"); + logger.trace("customize context"); super.customizeContext(servletContext, applicationContext); String[] newLocations = cloudStackContext.getConfigLocationsForWeb(configuredParentName, applicationContext.getConfigLocations()); diff --git a/packaging/centos7/cloud.spec b/packaging/centos7/cloud.spec index 0fe1a81a6cf..99ecca784ad 100644 --- a/packaging/centos7/cloud.spec +++ b/packaging/centos7/cloud.spec @@ -277,6 +277,9 @@ install -D client/target/utilities/bin/cloud-setup-management ${RPM_BUILD_ROOT}% install -D client/target/utilities/bin/cloud-setup-baremetal ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-baremetal install -D client/target/utilities/bin/cloud-sysvmadm ${RPM_BUILD_ROOT}%{_bindir}/%{name}-sysvmadm install -D client/target/utilities/bin/cloud-update-xenserver-licenses ${RPM_BUILD_ROOT}%{_bindir}/%{name}-update-xenserver-licenses +# Bundle cmk in cloudstack-management +wget https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64 -O ${RPM_BUILD_ROOT}%{_bindir}/cmk +chmod +x ${RPM_BUILD_ROOT}%{_bindir}/cmk cp -r client/target/utilities/scripts/db/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup @@ -298,7 +301,7 @@ do cp client/target/conf/$name ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/$name done -ln -sf log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/log4j.xml +ln -sf log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/log4j2.xml install python/bindir/cloud-external-ipallocator.py ${RPM_BUILD_ROOT}%{_bindir}/%{name}-external-ipallocator.py install -D client/target/pythonlibs/jasypt-1.9.3.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/lib/jasypt-1.9.3.jar @@ -320,6 +323,7 @@ rm -rf ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/templates/systemvm/md5sum # UI mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/ui mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/ +cp -r client/target/classes/META-INF/webapp/WEB-INF ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui cp ui/dist/config.json ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/ui/ cp -r ui/dist/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/ rm -f ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/config.json @@ -591,7 +595,7 @@ pip3 install --upgrade urllib3 %config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/management/server.properties %config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/management/config.json %config(noreplace) %{_sysconfdir}/%{name}/management/log4j-cloud.xml -%config(noreplace) %{_sysconfdir}/%{name}/management/log4j.xml +%config(noreplace) %{_sysconfdir}/%{name}/management/log4j2.xml %config(noreplace) %{_sysconfdir}/%{name}/management/environment.properties %config(noreplace) %{_sysconfdir}/%{name}/management/java.security.ciphers %attr(0644,root,root) %{_unitdir}/%{name}-management.service @@ -608,6 +612,7 @@ pip3 install --upgrade urllib3 %attr(0755,root,root) %{_bindir}/%{name}-set-guest-sshkey %attr(0755,root,root) %{_bindir}/%{name}-sysvmadm %attr(0755,root,root) %{_bindir}/%{name}-setup-encryption +%attr(0755,root,root) %{_bindir}/cmk %{_datadir}/%{name}-management/setup/*.sql %{_datadir}/%{name}-management/setup/*.sh %{_datadir}/%{name}-management/setup/server-setup.xml @@ -658,7 +663,7 @@ pip3 install --upgrade urllib3 %files ui %config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/ui/config.json -%attr(0644,root,root) %{_datadir}/%{name}-ui/* +%{_datadir}/%{name}-ui/* %{_defaultdocdir}/%{name}-ui-%{version}/LICENSE %{_defaultdocdir}/%{name}-ui-%{version}/NOTICE diff --git a/packaging/centos8/cloud.spec b/packaging/centos8/cloud.spec index ce425d38165..37fe007e3fb 100644 --- a/packaging/centos8/cloud.spec +++ b/packaging/centos8/cloud.spec @@ -52,7 +52,7 @@ intelligent IaaS cloud implementation. %package management Summary: CloudStack management server UI -Requires: java-11-openjdk +Requires: java-17-openjdk Requires: (tzdata-java or timezone-java) Requires: python3 Requires: bash @@ -98,7 +98,7 @@ The Apache CloudStack files shared between agent and management server %package agent Summary: CloudStack Agent for KVM hypervisors Requires: (openssh-clients or openssh) -Requires: java-11-openjdk +Requires: java-17-openjdk Requires: tzdata-java Requires: %{name}-common = %{_ver} Requires: libvirt @@ -135,7 +135,7 @@ The CloudStack baremetal agent %package usage Summary: CloudStack Usage calculation server -Requires: java-11-openjdk +Requires: java-17-openjdk Requires: tzdata-java Group: System Environment/Libraries %description usage @@ -259,6 +259,9 @@ install -D client/target/utilities/bin/cloud-setup-management ${RPM_BUILD_ROOT}% install -D client/target/utilities/bin/cloud-setup-baremetal ${RPM_BUILD_ROOT}%{_bindir}/%{name}-setup-baremetal install -D client/target/utilities/bin/cloud-sysvmadm ${RPM_BUILD_ROOT}%{_bindir}/%{name}-sysvmadm install -D client/target/utilities/bin/cloud-update-xenserver-licenses ${RPM_BUILD_ROOT}%{_bindir}/%{name}-update-xenserver-licenses +# Bundle cmk in cloudstack-management +wget https://github.com/apache/cloudstack-cloudmonkey/releases/download/6.3.0/cmk.linux.x86-64 -O ${RPM_BUILD_ROOT}%{_bindir}/cmk +chmod +x ${RPM_BUILD_ROOT}%{_bindir}/cmk cp -r client/target/utilities/scripts/db/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/setup @@ -280,7 +283,7 @@ do cp client/target/conf/$name ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/$name done -ln -sf log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/log4j.xml +ln -sf log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/management/log4j2.xml install python/bindir/cloud-external-ipallocator.py ${RPM_BUILD_ROOT}%{_bindir}/%{name}-external-ipallocator.py install -D client/target/pythonlibs/jasypt-1.9.3.jar ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/lib/jasypt-1.9.3.jar @@ -302,6 +305,7 @@ rm -rf ${RPM_BUILD_ROOT}%{_datadir}/%{name}-management/templates/systemvm/md5sum # UI mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/ui mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/ +cp -r client/target/classes/META-INF/webapp/WEB-INF ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui cp ui/dist/config.json ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/ui/ cp -r ui/dist/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/ rm -f ${RPM_BUILD_ROOT}%{_datadir}/%{name}-ui/config.json @@ -552,8 +556,8 @@ if [ -f "/usr/share/cloudstack-common/scripts/installer/cloudstack-help-text" ]; fi %post marvin -pip install --upgrade https://files.pythonhosted.org/packages/08/1f/42d74bae9dd6dcfec67c9ed0f3fa482b1ae5ac5f117ca82ab589ecb3ca19/mysql_connector_python-8.0.31-py2.py3-none-any.whl -pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz +pip3 install --upgrade https://files.pythonhosted.org/packages/08/1f/42d74bae9dd6dcfec67c9ed0f3fa482b1ae5ac5f117ca82ab589ecb3ca19/mysql_connector_python-8.0.31-py2.py3-none-any.whl +pip3 install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz #No default permission as the permission setup is complex %files management @@ -570,7 +574,7 @@ pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz %config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/management/server.properties %config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/management/config.json %config(noreplace) %{_sysconfdir}/%{name}/management/log4j-cloud.xml -%config(noreplace) %{_sysconfdir}/%{name}/management/log4j.xml +%config(noreplace) %{_sysconfdir}/%{name}/management/log4j2.xml %config(noreplace) %{_sysconfdir}/%{name}/management/environment.properties %config(noreplace) %{_sysconfdir}/%{name}/management/java.security.ciphers %attr(0644,root,root) %{_unitdir}/%{name}-management.service @@ -587,6 +591,7 @@ pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz %attr(0755,root,root) %{_bindir}/%{name}-set-guest-sshkey %attr(0755,root,root) %{_bindir}/%{name}-sysvmadm %attr(0755,root,root) %{_bindir}/%{name}-setup-encryption +%attr(0755,root,root) %{_bindir}/cmk %{_datadir}/%{name}-management/setup/*.sql %{_datadir}/%{name}-management/setup/*.sh %{_datadir}/%{name}-management/setup/server-setup.xml @@ -636,7 +641,7 @@ pip install --upgrade /usr/share/cloudstack-marvin/Marvin-*.tar.gz %files ui %config(noreplace) %attr(0640,root,cloud) %{_sysconfdir}/%{name}/ui/config.json -%attr(0644,root,root) %{_datadir}/%{name}-ui/* +%{_datadir}/%{name}-ui/* %{_defaultdocdir}/%{name}-ui-%{version}/LICENSE %{_defaultdocdir}/%{name}-ui-%{version}/NOTICE diff --git a/packaging/systemd/cloudstack-management.default b/packaging/systemd/cloudstack-management.default index 252fb4b78f6..ca8ff628fc1 100644 --- a/packaging/systemd/cloudstack-management.default +++ b/packaging/systemd/cloudstack-management.default @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -JAVA_OPTS="-Djava.security.properties=/etc/cloudstack/management/java.security.ciphers -Djava.awt.headless=true -Dcom.sun.management.jmxremote=false -Xmx2G -XX:+UseParallelGC -XX:MaxGCPauseMillis=500 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/cloudstack/management/ -XX:ErrorFile=/var/log/cloudstack/management/cloudstack-management.err " +JAVA_OPTS="-Djava.security.properties=/etc/cloudstack/management/java.security.ciphers -Djava.awt.headless=true -Dcom.sun.management.jmxremote=false -Xmx2G -XX:+UseParallelGC -XX:MaxGCPauseMillis=500 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/cloudstack/management/ -XX:ErrorFile=/var/log/cloudstack/management/cloudstack-management.err --add-opens=java.base/java.lang=ALL-UNNAMED --add-exports=java.base/sun.security.x509=ALL-UNNAMED" CLASSPATH="/usr/share/cloudstack-management/lib/*:/etc/cloudstack/management:/usr/share/cloudstack-common:/usr/share/cloudstack-management/setup:/usr/share/cloudstack-management:/usr/share/java/mysql-connector-java.jar:/usr/share/cloudstack-mysql-ha/lib/*" @@ -24,7 +24,7 @@ BOOTSTRAP_CLASS=org.apache.cloudstack.ServerDaemon ################################################################################################ #You can uncomment one of these options if you want to enable Java remote debugging. # #You can change the parameters at your will. The 'address' field defines the port to be used. # -################################################################################################ +################################################################################################ # This option here should be used with 'systemmd' based operating systems such as CentOS7, Ubuntu 16, and so on. #JAVA_DEBUG="-agentlib:jdwp=transport=dt_socket,address=*:8000,server=y,suspend=n" diff --git a/packaging/systemd/cloudstack-usage.default b/packaging/systemd/cloudstack-usage.default index 089f3eec09c..493f40c277a 100644 --- a/packaging/systemd/cloudstack-usage.default +++ b/packaging/systemd/cloudstack-usage.default @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -JAVA_OPTS="-Xms256m -Xmx2048m" +JAVA_OPTS="-Xms256m -Xmx2048m --add-opens=java.base/java.lang=ALL-UNNAMED" CLASSPATH="/usr/share/cloudstack-usage/*:/usr/share/cloudstack-usage/lib/*:/usr/share/cloudstack-mysql-ha/lib/*:/etc/cloudstack/usage:/usr/share/java/mysql-connector-java.jar" diff --git a/plugins/acl/dynamic-role-based/pom.xml b/plugins/acl/dynamic-role-based/pom.xml index 786d69d3b04..b1972a54ba5 100644 --- a/plugins/acl/dynamic-role-based/pom.xml +++ b/plugins/acl/dynamic-role-based/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java b/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java index cca9e338868..94b763d013f 100644 --- a/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java +++ b/plugins/acl/dynamic-role-based/src/main/java/org/apache/cloudstack/acl/DynamicRoleBasedAPIAccessChecker.java @@ -27,7 +27,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.cloudstack.api.APICommand; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RolePermissionEntity.Permission; import com.cloud.exception.PermissionDeniedException; @@ -49,7 +48,6 @@ public class DynamicRoleBasedAPIAccessChecker extends AdapterBase implements API private List services; private Map> annotationRoleBasedApisMap = new HashMap>(); - private static final Logger LOGGER = Logger.getLogger(DynamicRoleBasedAPIAccessChecker.class.getName()); protected DynamicRoleBasedAPIAccessChecker() { super(); @@ -92,8 +90,8 @@ public class DynamicRoleBasedAPIAccessChecker extends AdapterBase implements API return false; } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("The API [%s] is allowed for the role %s by the permission [%s].", apiName, role, permission.getRule().toString())); + if (logger.isTraceEnabled()) { + logger.trace(String.format("The API [%s] is allowed for the role %s by the permission [%s].", apiName, role, permission.getRule().toString())); } return true; } @@ -122,7 +120,7 @@ public class DynamicRoleBasedAPIAccessChecker extends AdapterBase implements API } if (accountRole.getRoleType() == RoleType.Admin && accountRole.getId() == RoleType.Admin.getId()) { - LOGGER.info(String.format("Account [%s] is Root Admin or Domain Admin, all APIs are allowed.", account)); + logger.info(String.format("Account [%s] is Root Admin or Domain Admin, all APIs are allowed.", account)); return true; } @@ -142,7 +140,7 @@ public class DynamicRoleBasedAPIAccessChecker extends AdapterBase implements API @Override public boolean isEnabled() { if (!roleService.isEnabled()) { - LOGGER.trace("RoleService is disabled. We will not use DynamicRoleBasedAPIAccessChecker."); + logger.trace("RoleService is disabled. We will not use DynamicRoleBasedAPIAccessChecker."); } return roleService.isEnabled(); } diff --git a/plugins/acl/project-role-based/pom.xml b/plugins/acl/project-role-based/pom.xml index fbbf688dab5..3f5d64d29a7 100644 --- a/plugins/acl/project-role-based/pom.xml +++ b/plugins/acl/project-role-based/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/acl/project-role-based/src/main/java/org/apache/cloudstack/acl/ProjectRoleBasedApiAccessChecker.java b/plugins/acl/project-role-based/src/main/java/org/apache/cloudstack/acl/ProjectRoleBasedApiAccessChecker.java index 0306a062df9..1e766468ba8 100644 --- a/plugins/acl/project-role-based/src/main/java/org/apache/cloudstack/acl/ProjectRoleBasedApiAccessChecker.java +++ b/plugins/acl/project-role-based/src/main/java/org/apache/cloudstack/acl/ProjectRoleBasedApiAccessChecker.java @@ -24,7 +24,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.acl.RolePermissionEntity.Permission; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.UnavailableCommandException; @@ -49,7 +48,6 @@ public class ProjectRoleBasedApiAccessChecker extends AdapterBase implements AP AccountService accountService; private List services; - private static final Logger LOGGER = Logger.getLogger(ProjectRoleBasedApiAccessChecker.class.getName()); protected ProjectRoleBasedApiAccessChecker() { super(); } @@ -61,9 +59,7 @@ public class ProjectRoleBasedApiAccessChecker extends AdapterBase implements AP @Override public boolean isEnabled() { if (!roleService.isEnabled()) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace("RoleService is disabled. We will not use ProjectRoleBasedApiAccessChecker."); - } + logger.trace("RoleService is disabled. We will not use ProjectRoleBasedApiAccessChecker."); } return roleService.isEnabled(); } @@ -76,7 +72,7 @@ public class ProjectRoleBasedApiAccessChecker extends AdapterBase implements AP Project project = CallContext.current().getProject(); if (project == null) { - LOGGER.warn(String.format("Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning APIs [%s] for user [%s] as allowed.", apiNames, user)); + logger.warn(String.format("Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning APIs [%s] for user [%s] as allowed.", apiNames, user)); return apiNames; } @@ -86,8 +82,8 @@ public class ProjectRoleBasedApiAccessChecker extends AdapterBase implements AP if (projectUser.getAccountRole() != ProjectAccount.Role.Admin) { apiNames.removeIf(apiName -> !isPermitted(project, projectUser, apiName)); } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Returning APIs [%s] as allowed for user [%s].", apiNames, user)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Returning APIs [%s] as allowed for user [%s].", apiNames, user)); } return apiNames; } @@ -100,8 +96,8 @@ public class ProjectRoleBasedApiAccessChecker extends AdapterBase implements AP if (projectAccount.getAccountRole() != ProjectAccount.Role.Admin) { apiNames.removeIf(apiName -> !isPermitted(project, projectAccount, apiName)); } - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Returning APIs [%s] as allowed for user [%s].", apiNames, user)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Returning APIs [%s] as allowed for user [%s].", apiNames, user)); } return apiNames; } @@ -114,16 +110,14 @@ public class ProjectRoleBasedApiAccessChecker extends AdapterBase implements AP Project project = CallContext.current().getProject(); if (project == null) { - LOGGER.warn(String.format("Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning API [%s] for user [%s] as allowed.", apiCommandName, + logger.warn(String.format("Project is null, ProjectRoleBasedApiAccessChecker only applies to projects, returning API [%s] for user [%s] as allowed.", apiCommandName, user)); return true; } Account userAccount = accountService.getAccount(user.getAccountId()); if (accountService.isRootAdmin(userAccount.getId()) || accountService.isDomainAdmin(userAccount.getAccountId())) { - if (LOGGER.isTraceEnabled()) { - LOGGER.trace(String.format("Account [%s] is Root Admin or Domain Admin, all APIs are allowed.", userAccount.getAccountName())); - } + logger.info(String.format("Account [%s] is Root Admin or Domain Admin, all APIs are allowed.", userAccount.getAccountName())); return true; } diff --git a/plugins/acl/project-role-based/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/acl/project-role-based/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/acl/project-role-based/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/acl/static-role-based/pom.xml b/plugins/acl/static-role-based/pom.xml index b6bb6339ba2..62fb60395e0 100644 --- a/plugins/acl/static-role-based/pom.xml +++ b/plugins/acl/static-role-based/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/acl/static-role-based/src/main/java/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java b/plugins/acl/static-role-based/src/main/java/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java index 7d12178f0f3..3444f967d78 100644 --- a/plugins/acl/static-role-based/src/main/java/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java +++ b/plugins/acl/static-role-based/src/main/java/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java @@ -26,7 +26,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import com.cloud.exception.UnavailableCommandException; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ import com.cloud.utils.component.PluggableService; @Deprecated public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIAclChecker { - protected static final Logger LOGGER = Logger.getLogger(StaticRoleBasedAPIAccessChecker.class); private Set commandPropertyFiles = new HashSet(); private Set commandNames = new HashSet(); @@ -74,7 +72,7 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIA @Override public boolean isEnabled() { if (roleService.isEnabled()) { - LOGGER.debug("RoleService is enabled. We will use it instead of StaticRoleBasedAPIAccessChecker."); + logger.debug("RoleService is enabled. We will use it instead of StaticRoleBasedAPIAccessChecker."); } return !roleService.isEnabled(); } @@ -180,7 +178,7 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIA commandsPropertiesRoleBasedApisMap.get(roleType).add(apiName); } } catch (NumberFormatException nfe) { - LOGGER.error(String.format("Malformed key=value pair for entry: [%s].", entry)); + logger.error(String.format("Malformed key=value pair for entry: [%s].", entry)); } } } diff --git a/plugins/affinity-group-processors/explicit-dedication/pom.xml b/plugins/affinity-group-processors/explicit-dedication/pom.xml index 870cb4058dd..d6827ee13b6 100644 --- a/plugins/affinity-group-processors/explicit-dedication/pom.xml +++ b/plugins/affinity-group-processors/explicit-dedication/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/affinity-group-processors/explicit-dedication/src/main/java/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java b/plugins/affinity-group-processors/explicit-dedication/src/main/java/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java index 95283028441..ec6674477b0 100644 --- a/plugins/affinity-group-processors/explicit-dedication/src/main/java/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java +++ b/plugins/affinity-group-processors/explicit-dedication/src/main/java/org/apache/cloudstack/affinity/ExplicitDedicationProcessor.java @@ -24,7 +24,6 @@ import javax.inject.Inject; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; -import org.apache.log4j.Logger; import com.cloud.dc.ClusterVO; import com.cloud.dc.DataCenter; @@ -56,7 +55,6 @@ import com.cloud.vm.dao.VMInstanceDao; public class ExplicitDedicationProcessor extends AffinityProcessorBase implements AffinityGroupProcessor { - private static final Logger s_logger = Logger.getLogger(ExplicitDedicationProcessor.class); @Inject protected UserVmDao _vmDao; @Inject @@ -96,8 +94,8 @@ public class ExplicitDedicationProcessor extends AffinityProcessorBase implement for (AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) { if (vmGroupMapping != null) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() + "of type 'ExplicitDedication' for VM Id: " + vm.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() + "of type 'ExplicitDedication' for VM Id: " + vm.getId()); } long affinityGroupId = vmGroupMapping.getAffinityGroupId(); @@ -234,13 +232,13 @@ public class ExplicitDedicationProcessor extends AffinityProcessorBase implement avoid = updateAvoidList(resourceList, avoid, dc); } else { avoid.addDataCenter(dc.getId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("No dedicated resources available for this domain or account under this group"); + if (logger.isDebugEnabled()) { + logger.debug("No dedicated resources available for this domain or account under this group"); } } - if (s_logger.isDebugEnabled()) { - s_logger.debug("ExplicitDedicationProcessor returns Avoid List as: Deploy avoids pods: " + avoid.getPodsToAvoid() + ", clusters: " + + if (logger.isDebugEnabled()) { + logger.debug("ExplicitDedicationProcessor returns Avoid List as: Deploy avoids pods: " + avoid.getPodsToAvoid() + ", clusters: " + avoid.getClustersToAvoid() + ", hosts: " + avoid.getHostsToAvoid()); } } @@ -305,8 +303,8 @@ public class ExplicitDedicationProcessor extends AffinityProcessorBase implement for (HostPodVO pod : podList) { DedicatedResourceVO dPod = _dedicatedDao.findByPodId(pod.getId()); if (dPod != null && !dedicatedResources.contains(dPod)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Avoiding POD %s [%s] because it is not dedicated.", pod.getName(), pod.getUuid())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Avoiding POD %s [%s] because it is not dedicated.", pod.getName(), pod.getUuid())); } avoidList.addPod(pod.getId()); } else { @@ -346,8 +344,8 @@ public class ExplicitDedicationProcessor extends AffinityProcessorBase implement for (HostPodVO pod : pods) { if (podsInIncludeList != null && !podsInIncludeList.contains(pod.getId())) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Avoiding POD %s [%s], as it is not in include list.", pod.getName(), pod.getUuid())); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Avoiding POD %s [%s], as it is not in include list.", pod.getName(), pod.getUuid())); } avoidList.addPod(pod.getId()); } @@ -413,8 +411,8 @@ public class ExplicitDedicationProcessor extends AffinityProcessorBase implement if (group != null) { List dedicatedResources = _dedicatedDao.listByAffinityGroupId(group.getId()); if (!dedicatedResources.isEmpty()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Releasing the dedicated resources under group: " + group); + if (logger.isDebugEnabled()) { + logger.debug("Releasing the dedicated resources under group: " + group); } Transaction.execute(new TransactionCallbackNoReturn() { @@ -431,8 +429,8 @@ public class ExplicitDedicationProcessor extends AffinityProcessorBase implement } }); } else { - if (s_logger.isDebugEnabled()) { - s_logger.debug("No dedicated resources to releease under group: " + group); + if (logger.isDebugEnabled()) { + logger.debug("No dedicated resources to releease under group: " + group); } } } diff --git a/plugins/affinity-group-processors/host-affinity/pom.xml b/plugins/affinity-group-processors/host-affinity/pom.xml index f30e8ba3d6e..bd999288717 100644 --- a/plugins/affinity-group-processors/host-affinity/pom.xml +++ b/plugins/affinity-group-processors/host-affinity/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/affinity-group-processors/host-affinity/src/main/java/org/apache/cloudstack/affinity/HostAffinityProcessor.java b/plugins/affinity-group-processors/host-affinity/src/main/java/org/apache/cloudstack/affinity/HostAffinityProcessor.java index 07c1dd5ff88..7f316fe7a91 100644 --- a/plugins/affinity-group-processors/host-affinity/src/main/java/org/apache/cloudstack/affinity/HostAffinityProcessor.java +++ b/plugins/affinity-group-processors/host-affinity/src/main/java/org/apache/cloudstack/affinity/HostAffinityProcessor.java @@ -27,7 +27,6 @@ import java.util.ArrayList; import javax.inject.Inject; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; @@ -42,7 +41,6 @@ import com.cloud.vm.dao.VMInstanceDao; public class HostAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor { - private static final Logger s_logger = Logger.getLogger(HostAffinityProcessor.class); @Inject protected VMInstanceDao _vmInstanceDao; @@ -68,7 +66,7 @@ public class HostAffinityProcessor extends AffinityProcessorBase implements Affi */ protected void processAffinityGroup(AffinityGroupVMMapVO vmGroupMapping, DeploymentPlan plan, VirtualMachine vm, List vmList) { AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId()); - s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId()); + logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId()); List groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId()); groupVMIds.remove(vm.getId()); diff --git a/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java b/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java index 66f3a37ae1b..3813c81b88f 100644 --- a/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java +++ b/plugins/affinity-group-processors/host-affinity/src/test/java/org/apache/cloudstack/affinity/HostAffinityProcessorTest.java @@ -25,6 +25,7 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.VMInstanceDao; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,8 +44,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -99,9 +100,11 @@ public class HostAffinityProcessorTest { @Mock VirtualMachineProfile profile; + private AutoCloseable closeable; + @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = MockitoAnnotations.openMocks(this); when(groupVM1.getHostId()).thenReturn(HOST_ID); when(groupVM2.getHostId()).thenReturn(HOST_ID); @@ -124,6 +127,11 @@ public class HostAffinityProcessorTest { when(affinityGroupVMMapDao.findByVmIdType(eq(VM_ID), any())).thenReturn(new ArrayList<>(Arrays.asList(mapVO))); } + @After + public void tearDown() throws Exception { + closeable.close(); + } + @Test public void testProcessAffinityGroupMultipleVMs() { processor.processAffinityGroup(mapVO, plan, vm); diff --git a/plugins/affinity-group-processors/host-anti-affinity/pom.xml b/plugins/affinity-group-processors/host-anti-affinity/pom.xml index 0e448688ca8..b224bbaf34a 100644 --- a/plugins/affinity-group-processors/host-anti-affinity/pom.xml +++ b/plugins/affinity-group-processors/host-anti-affinity/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/affinity-group-processors/host-anti-affinity/src/main/java/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java b/plugins/affinity-group-processors/host-anti-affinity/src/main/java/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java index 2a3c5796dda..9feeeed2b6d 100644 --- a/plugins/affinity-group-processors/host-anti-affinity/src/main/java/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java +++ b/plugins/affinity-group-processors/host-anti-affinity/src/main/java/org/apache/cloudstack/affinity/HostAntiAffinityProcessor.java @@ -23,7 +23,6 @@ import java.util.Map; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; @@ -46,7 +45,6 @@ import com.cloud.vm.dao.VMInstanceDao; public class HostAntiAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor { - private static final Logger s_logger = Logger.getLogger(HostAntiAffinityProcessor.class); @Inject protected UserVmDao _vmDao; @Inject @@ -71,8 +69,8 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements if (vmGroupMapping != null) { AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId()); } List groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId()); @@ -83,15 +81,15 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements if (groupVM != null && !groupVM.isRemoved()) { if (groupVM.getHostId() != null) { avoid.addHost(groupVM.getHostId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host"); + if (logger.isDebugEnabled()) { + logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host"); } } else if (Arrays.asList(VirtualMachine.State.Starting, VirtualMachine.State.Stopped).contains(groupVM.getState()) && groupVM.getLastHostId() != null) { long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - groupVM.getUpdateTime().getTime()) / 1000; if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) { avoid.addHost(groupVM.getLastHostId()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM " + groupVM.getId() + + if (logger.isDebugEnabled()) { + logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host, in Stopped state but has reserved capacity"); } } @@ -131,8 +129,8 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements for (Long groupVMId : groupVMIds) { VMReservationVO vmReservation = _reservationDao.findByVmId(groupVMId); if (vmReservation != null && vmReservation.getHostId() != null && vmReservation.getHostId().equals(plannedHostId)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + + if (logger.isDebugEnabled()) { + logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + " reserved on the same host " + plannedHostId); } return false; diff --git a/plugins/affinity-group-processors/non-strict-host-affinity/pom.xml b/plugins/affinity-group-processors/non-strict-host-affinity/pom.xml index f6fbb9e50be..bf751ca4141 100644 --- a/plugins/affinity-group-processors/non-strict-host-affinity/pom.xml +++ b/plugins/affinity-group-processors/non-strict-host-affinity/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/affinity-group-processors/non-strict-host-affinity/src/main/java/org/apache/cloudstack/affinity/NonStrictHostAffinityProcessor.java b/plugins/affinity-group-processors/non-strict-host-affinity/src/main/java/org/apache/cloudstack/affinity/NonStrictHostAffinityProcessor.java index cdb3447f5a5..f227a3ffc8d 100644 --- a/plugins/affinity-group-processors/non-strict-host-affinity/src/main/java/org/apache/cloudstack/affinity/NonStrictHostAffinityProcessor.java +++ b/plugins/affinity-group-processors/non-strict-host-affinity/src/main/java/org/apache/cloudstack/affinity/NonStrictHostAffinityProcessor.java @@ -23,7 +23,6 @@ import java.util.Map; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.dao.AffinityGroupDao; import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; @@ -45,7 +44,6 @@ import com.cloud.vm.dao.VMInstanceDao; public class NonStrictHostAffinityProcessor extends AffinityProcessorBase implements AffinityGroupProcessor { - private final Logger logger = Logger.getLogger(this.getClass().getName()); @Inject protected UserVmDao vmDao; @Inject diff --git a/plugins/affinity-group-processors/non-strict-host-anti-affinity/pom.xml b/plugins/affinity-group-processors/non-strict-host-anti-affinity/pom.xml index adb4de23673..445acfc11d6 100644 --- a/plugins/affinity-group-processors/non-strict-host-anti-affinity/pom.xml +++ b/plugins/affinity-group-processors/non-strict-host-anti-affinity/pom.xml @@ -25,14 +25,14 @@ org.apache.cloudstack cloud-plugin-non-strict-host-affinity - 4.19.0.0-SNAPSHOT + ${project.version} compile org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/alert-handlers/snmp-alerts/pom.xml b/plugins/alert-handlers/snmp-alerts/pom.xml index 04e5de2f5ee..fad47d426f2 100644 --- a/plugins/alert-handlers/snmp-alerts/pom.xml +++ b/plugins/alert-handlers/snmp-alerts/pom.xml @@ -24,7 +24,7 @@ cloudstack-plugins org.apache.cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -33,8 +33,12 @@ org.apache.servicemix.bundles.snmp4j - ch.qos.reload4j - reload4j + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api diff --git a/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayout.java b/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayout.java index 5761e7041e7..cf9e18bf9cf 100644 --- a/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayout.java +++ b/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayout.java @@ -17,42 +17,27 @@ package org.apache.cloudstack.alert.snmp; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.message.Message; + import java.util.Date; import java.util.StringTokenizer; -import org.apache.log4j.EnhancedPatternLayout; -import org.apache.log4j.spi.LoggingEvent; - -public class SnmpEnhancedPatternLayout extends EnhancedPatternLayout { +public class SnmpEnhancedPatternLayout { private String _pairDelimiter = "//"; private String _keyValueDelimiter = "::"; private static final int LENGTH_OF_STRING_MESSAGE_AND_KEY_VALUE_DELIMITER = 9; private static final int LENGTH_OF_STRING_MESSAGE = 8; - public String getKeyValueDelimeter() { - return _keyValueDelimiter; - } - - public void setKeyValueDelimiter(String keyValueDelimiter) { - this._keyValueDelimiter = keyValueDelimiter; - } - - public String getPairDelimiter() { - return _pairDelimiter; - } - - public void setPairDelimiter(String pairDelimiter) { - this._pairDelimiter = pairDelimiter; - } - - public SnmpTrapInfo parseEvent(LoggingEvent event) { + public SnmpTrapInfo parseEvent(LogEvent event) { SnmpTrapInfo snmpTrapInfo = null; - final String message = event.getRenderedMessage(); - if (message.contains("alertType") && message.contains("message")) { + Message message = event.getMessage(); + final String formattedMessage = message.getFormattedMessage(); + if (formattedMessage.contains("alertType") && formattedMessage.contains("message")) { snmpTrapInfo = new SnmpTrapInfo(); - final StringTokenizer messageSplitter = new StringTokenizer(message, _pairDelimiter); + final StringTokenizer messageSplitter = new StringTokenizer(formattedMessage, _pairDelimiter); while (messageSplitter.hasMoreTokens()) { final String pairToken = messageSplitter.nextToken(); final StringTokenizer pairSplitter = new StringTokenizer(pairToken, _keyValueDelimiter); @@ -80,11 +65,11 @@ public class SnmpEnhancedPatternLayout extends EnhancedPatternLayout { } else if (keyToken.equalsIgnoreCase("clusterId") && !valueToken.equalsIgnoreCase("null")) { snmpTrapInfo.setClusterId(Long.parseLong(valueToken)); } else if (keyToken.equalsIgnoreCase("message") && !valueToken.equalsIgnoreCase("null")) { - snmpTrapInfo.setMessage(getSnmpMessage(message)); + snmpTrapInfo.setMessage(getSnmpMessage(formattedMessage)); } } - snmpTrapInfo.setGenerationTime(new Date(event.getTimeStamp())); + snmpTrapInfo.setGenerationTime(new Date(event.getTimeMillis())); } return snmpTrapInfo; } diff --git a/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppender.java b/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppender.java index 5374e39916d..d91c60db31d 100644 --- a/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppender.java +++ b/plugins/alert-handlers/snmp-alerts/src/main/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppender.java @@ -17,21 +17,32 @@ package org.apache.cloudstack.alert.snmp; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.spi.ErrorCode; -import org.apache.log4j.spi.LoggingEvent; - import com.cloud.utils.net.NetUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.Property; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.layout.PatternLayout; -public class SnmpTrapAppender extends AppenderSkeleton { +@Plugin(name = "SnmpTrapAppender", category = "Core", elementType = "appender", printObject = true) +public class SnmpTrapAppender extends AbstractAppender { + protected static Logger LOGGER = LogManager.getLogger(SnmpTrapAppender.class); private String _delimiter = ","; - private String _snmpManagerIpAddresses; - private String _snmpManagerPorts; - private String _snmpManagerCommunities; + private String snmpManagerIpAddresses; + private String snmpManagerPorts; + private String snmpManagerCommunities; private String _oldSnmpManagerIpAddresses = null; private String _oldSnmpManagerPorts = null; @@ -41,27 +52,21 @@ public class SnmpTrapAppender extends AppenderSkeleton { private List _communities = null; private List _ports = null; - List _snmpHelpers = new ArrayList(); + private SnmpEnhancedPatternLayout snmpEnhancedPatternLayout; + + List _snmpHelpers = new ArrayList<>(); + + protected SnmpTrapAppender(String name, Filter filter, Layout layout, final boolean ignoreExceptions, final Property[] properties, + String snmpManagerIpAddresses, String snmpManagerPorts, String snmpManagerCommunities) { + super(name, filter, layout, ignoreExceptions, properties); + this.snmpEnhancedPatternLayout = new SnmpEnhancedPatternLayout(); + this.snmpManagerIpAddresses = snmpManagerIpAddresses; + this.snmpManagerPorts = snmpManagerPorts; + this.snmpManagerCommunities = snmpManagerCommunities; + } @Override - protected void append(LoggingEvent event) { - SnmpEnhancedPatternLayout snmpEnhancedPatternLayout; - - if (getLayout() == null) { - errorHandler.error("No layout set for the Appender named [" + getName() + ']', null, ErrorCode.MISSING_LAYOUT); - return; - } - - if (getLayout() instanceof SnmpEnhancedPatternLayout) { - snmpEnhancedPatternLayout = (SnmpEnhancedPatternLayout)getLayout(); - } else { - return; - } - - if (!isAsSevereAsThreshold(event.getLevel())) { - return; - } - + public void append(LogEvent event) { SnmpTrapInfo snmpTrapInfo = snmpEnhancedPatternLayout.parseEvent(event); if (snmpTrapInfo != null && !_snmpHelpers.isEmpty()) { @@ -69,41 +74,57 @@ public class SnmpTrapAppender extends AppenderSkeleton { try { helper.sendSnmpTrap(snmpTrapInfo); } catch (Exception e) { - errorHandler.error(e.getMessage()); + getHandler().error(e.getMessage()); } } } } + @PluginFactory + public static SnmpTrapAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout layout, + @PluginElement("Filter") final Filter filter, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, @PluginElement("properties") final Property[] properties, + @PluginAttribute("SnmpManagerIpAddresses") String snmpManagerIpAddresses, @PluginAttribute("SnmpManagerPorts") String snmpManagerPorts, + @PluginAttribute("SnmpManagerCommunities") String snmpManagerCommunities) { + + if (name == null) { + LOGGER.error("No name provided for SnmpTrapAppender"); + return null; + } + if (layout == null) { + layout = PatternLayout.createDefaultLayout(); + } + return new SnmpTrapAppender(name, filter, layout, ignoreExceptions, properties, snmpManagerIpAddresses, snmpManagerPorts, snmpManagerCommunities); + } + void setSnmpHelpers() { - if (_snmpManagerIpAddresses == null || _snmpManagerIpAddresses.trim().isEmpty() || _snmpManagerCommunities == null || _snmpManagerCommunities.trim().isEmpty() || - _snmpManagerPorts == null || _snmpManagerPorts.trim().isEmpty()) { + if (snmpManagerIpAddresses == null || snmpManagerIpAddresses.trim().isEmpty() || snmpManagerCommunities == null || snmpManagerCommunities.trim().isEmpty() || + snmpManagerPorts == null || snmpManagerPorts.trim().isEmpty()) { reset(); return; } - if (_oldSnmpManagerIpAddresses != null && _oldSnmpManagerIpAddresses.equals(_snmpManagerIpAddresses) && - _oldSnmpManagerCommunities.equals(_snmpManagerCommunities) && _oldSnmpManagerPorts.equals(_snmpManagerPorts)) { + if (_oldSnmpManagerIpAddresses != null && _oldSnmpManagerIpAddresses.equals(snmpManagerIpAddresses) && + _oldSnmpManagerCommunities.equals(snmpManagerCommunities) && _oldSnmpManagerPorts.equals(snmpManagerPorts)) { return; } - _oldSnmpManagerIpAddresses = _snmpManagerIpAddresses; - _oldSnmpManagerPorts = _snmpManagerPorts; - _oldSnmpManagerCommunities = _snmpManagerCommunities; + _oldSnmpManagerIpAddresses = snmpManagerIpAddresses; + _oldSnmpManagerPorts = snmpManagerPorts; + _oldSnmpManagerCommunities = snmpManagerCommunities; - _ipAddresses = parse(_snmpManagerIpAddresses); - _communities = parse(_snmpManagerCommunities); - _ports = parse(_snmpManagerPorts); + _ipAddresses = parse(snmpManagerIpAddresses); + _communities = parse(snmpManagerCommunities); + _ports = parse(snmpManagerPorts); if (!(_ipAddresses.size() == _communities.size() && _ipAddresses.size() == _ports.size())) { reset(); - errorHandler.error(" size of ip addresses , communities, " + "and ports list doesn't match, " + "setting all to null"); + getHandler().error(" size of ip addresses , communities, " + "and ports list doesn't match, " + "setting all to null"); return; } if (!validateIpAddresses() || !validatePorts()) { reset(); - errorHandler.error(" Invalid format for the IP Addresses or Ports parameter "); + getHandler().error(" Invalid format for the IP Addresses or Ports parameter "); return; } @@ -114,7 +135,7 @@ public class SnmpTrapAppender extends AppenderSkeleton { try { _snmpHelpers.add(new SnmpHelper(address, _communities.get(i))); } catch (Exception e) { - errorHandler.error(e.getMessage()); + getHandler().error(e.getMessage()); } } } @@ -126,17 +147,6 @@ public class SnmpTrapAppender extends AppenderSkeleton { _snmpHelpers.clear(); } - @Override - public void close() { - if (!closed) - closed = true; - } - - @Override - public boolean requiresLayout() { - return true; - } - private List parse(String str) { List result = new ArrayList(); @@ -168,38 +178,20 @@ public class SnmpTrapAppender extends AppenderSkeleton { return true; } - public String getSnmpManagerIpAddresses() { - return _snmpManagerIpAddresses; - } - public void setSnmpManagerIpAddresses(String snmpManagerIpAddresses) { - this._snmpManagerIpAddresses = snmpManagerIpAddresses; + this.snmpManagerIpAddresses = snmpManagerIpAddresses; setSnmpHelpers(); } - public String getSnmpManagerPorts() { - return _snmpManagerPorts; - } public void setSnmpManagerPorts(String snmpManagerPorts) { - this._snmpManagerPorts = snmpManagerPorts; + this.snmpManagerPorts = snmpManagerPorts; setSnmpHelpers(); } - public String getSnmpManagerCommunities() { - return _snmpManagerCommunities; - } - public void setSnmpManagerCommunities(String snmpManagerCommunities) { - this._snmpManagerCommunities = snmpManagerCommunities; + this.snmpManagerCommunities = snmpManagerCommunities; setSnmpHelpers(); } - public String getDelimiter() { - return _delimiter; - } - - public void setDelimiter(String delimiter) { - this._delimiter = delimiter; - } } diff --git a/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayoutTest.java b/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayoutTest.java index a04d36bede8..adfc0e27b0e 100644 --- a/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayoutTest.java +++ b/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpEnhancedPatternLayoutTest.java @@ -20,56 +20,57 @@ package org.apache.cloudstack.alert.snmp; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.message.Message; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; -import javax.naming.ConfigurationException; - -import org.apache.log4j.spi.LoggingEvent; -import org.junit.Before; import org.junit.Test; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class SnmpEnhancedPatternLayoutTest { - SnmpEnhancedPatternLayout _snmpEnhancedPatternLayout = new SnmpEnhancedPatternLayout(); - @Before - public void setUp() throws ConfigurationException { - _snmpEnhancedPatternLayout.setKeyValueDelimiter("::"); - _snmpEnhancedPatternLayout.setPairDelimiter("//"); - } + @Mock + Message messageMock; + @Mock + LogEvent eventMock; + + @Spy + @InjectMocks + SnmpEnhancedPatternLayout _snmpEnhancedPatternLayout = new SnmpEnhancedPatternLayout(); @Test public void parseAlertTest() { - LoggingEvent event = mock(LoggingEvent.class); setMessage(" alertType:: 14 // dataCenterId:: 1 // podId:: 1 // " + "clusterId:: null // message:: Management" - + " network CIDR is not configured originally. Set it default to 10.102.192.0/22", event); - SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(event); + + " network CIDR is not configured originally. Set it default to 10.102.192.0/22", eventMock); + SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(eventMock); commonAssertions(info, "Management network CIDR is not configured originally. Set it default to 10.102.192" + ".0/22"); } @Test public void ParseAlertWithPairDelimeterInMessageTest() { - LoggingEvent event = mock(LoggingEvent.class); setMessage(" alertType:: 14 // dataCenterId:: 1 // podId:: 1 // " + "clusterId:: null // message:: Management" - + " //network CIDR is not configured originally. Set it default to 10.102.192.0/22", event); - SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(event); + + " //network CIDR is not configured originally. Set it default to 10.102.192.0/22", eventMock); + SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(eventMock); commonAssertions(info, "Management //network CIDR is not configured originally. Set it default to 10.102.192" + ".0/22"); } @Test public void ParseAlertWithKeyValueDelimeterInMessageTest() { - LoggingEvent event = mock(LoggingEvent.class); setMessage(" alertType:: 14 // dataCenterId:: 1 // podId:: 1 // " + "clusterId:: null // message:: Management" - + " ::network CIDR is not configured originally. Set it default to 10.102.192.0/22", event); - SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(event); + + " ::network CIDR is not configured originally. Set it default to 10.102.192.0/22", eventMock); + SnmpTrapInfo info = _snmpEnhancedPatternLayout.parseEvent(eventMock); commonAssertions(info, "Management ::network CIDR is not configured originally. Set it default to 10.102.192" + ".0/22"); } @Test public void parseRandomTest() { - LoggingEvent event = mock(LoggingEvent.class); - when(event.getRenderedMessage()).thenReturn("Problem clearing email alert"); - assertNull(" Null value was expected ", _snmpEnhancedPatternLayout.parseEvent(event)); + setMessage("Problem clearing email alert", eventMock); + assertNull(" Null value was expected ", _snmpEnhancedPatternLayout.parseEvent(eventMock)); } private void commonAssertions(SnmpTrapInfo info, String message) { @@ -81,7 +82,8 @@ public class SnmpEnhancedPatternLayoutTest { assertEquals(" message is not as expected ", message, info.getMessage()); } - private void setMessage(String message, LoggingEvent event) { - when(event.getRenderedMessage()).thenReturn(message); + private void setMessage(String message, LogEvent eventMock) { + Mockito.doReturn(messageMock).when(eventMock).getMessage(); + Mockito.doReturn(message).when(messageMock).getFormattedMessage(); } } diff --git a/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppenderTest.java b/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppenderTest.java index 36fb0c9e5c2..ce207e08266 100644 --- a/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppenderTest.java +++ b/plugins/alert-handlers/snmp-alerts/src/test/java/org/apache/cloudstack/alert/snmp/SnmpTrapAppenderTest.java @@ -19,20 +19,11 @@ package org.apache.cloudstack.alert.snmp; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import java.util.List; - -import org.apache.log4j.spi.LoggingEvent; import org.junit.Test; -import org.mockito.Mock; public class SnmpTrapAppenderTest { - SnmpTrapAppender _appender = new SnmpTrapAppender(); - LoggingEvent _event = mock(LoggingEvent.class); - SnmpEnhancedPatternLayout _snmpEnhancedPatternLayout = mock(SnmpEnhancedPatternLayout.class); - @Mock - List snmpHelpers; + SnmpTrapAppender _appender = new SnmpTrapAppender("test", null, null, false, null, null, null, null); @Test public void appendTest() { diff --git a/plugins/alert-handlers/syslog-alerts/pom.xml b/plugins/alert-handlers/syslog-alerts/pom.xml index 48af97b7717..54641bd8a8a 100644 --- a/plugins/alert-handlers/syslog-alerts/pom.xml +++ b/plugins/alert-handlers/syslog-alerts/pom.xml @@ -24,13 +24,17 @@ cloudstack-plugins org.apache.cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml - ch.qos.reload4j - reload4j + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api diff --git a/plugins/alert-handlers/syslog-alerts/src/main/java/org/apache/cloudstack/syslog/AlertsSyslogAppender.java b/plugins/alert-handlers/syslog-alerts/src/main/java/org/apache/cloudstack/syslog/AlertsSyslogAppender.java index b73da2fd421..a6f511558dc 100644 --- a/plugins/alert-handlers/syslog-alerts/src/main/java/org/apache/cloudstack/syslog/AlertsSyslogAppender.java +++ b/plugins/alert-handlers/syslog-alerts/src/main/java/org/apache/cloudstack/syslog/AlertsSyslogAppender.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.syslog; +import java.io.Serializable; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; @@ -26,20 +27,31 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.net.SyslogAppender; -import org.apache.log4j.spi.LoggingEvent; import com.cloud.utils.net.NetUtils; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.appender.SyslogAppender; +import org.apache.logging.log4j.core.config.Property; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.impl.Log4jLogEvent; +import org.apache.logging.log4j.core.net.Facility; +import org.apache.logging.log4j.message.SimpleMessage; -public class AlertsSyslogAppender extends AppenderSkeleton { - String _syslogHosts = null; - String _delimiter = ","; - List _syslogHostsList = null; - List _syslogAppenders = null; - private String _facility; - private String _pairDelimiter = "//"; - private String _keyValueDelimiter = "::"; +@Plugin(name = "AlertSyslogAppender", category = "Core", elementType = "appender", printObject = true) +public class AlertsSyslogAppender extends AbstractAppender { + String syslogHosts; + String delimiter = ","; + List syslogHostsList = null; + List syslogAppenders = null; + private String facility; + private String pairDelimiter = "//"; + private String keyValueDelimiter = "::"; private int alertType = -1; private long dataCenterId = 0; private long podId = 0; @@ -53,7 +65,7 @@ public class AlertsSyslogAppender extends AppenderSkeleton { private static final Map alertsMap; static { - Map aMap = new HashMap(27); + Map aMap = new HashMap<>(27); aMap.put(0, "availableMemory"); aMap.put(1, "availableCpu"); aMap.put(2, "availableStorage"); @@ -86,70 +98,68 @@ public class AlertsSyslogAppender extends AppenderSkeleton { alertsMap = Collections.unmodifiableMap(aMap); } - @Override - protected void append(LoggingEvent event) { - if (!isAsSevereAsThreshold(event.getLevel())) { - return; - } + protected AlertsSyslogAppender(String name, Filter filter, Layout layout, final boolean ignoreExceptions, final Property[] properties, String facility, + String syslogHosts){ + super(name, filter, layout, ignoreExceptions, properties); + this.facility = facility; + this.syslogHosts = syslogHosts; + } - if (_syslogAppenders != null && !_syslogAppenders.isEmpty()) { + @Override + public void append(LogEvent event) { + if (syslogAppenders != null && !syslogAppenders.isEmpty()) { try { - String logMessage = event.getRenderedMessage(); + String logMessage = event.getMessage().getFormattedMessage(); if (logMessage.contains("alertType") && logMessage.contains("message")) { parseMessage(logMessage); String syslogMessage = createSyslogMessage(); - LoggingEvent syslogEvent = new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getLevel(), syslogMessage, null); + LogEvent syslogEvent = new Log4jLogEvent(event.getLoggerName(), event.getMarker(), event.getLoggerFqcn(), event.getLevel(), new SimpleMessage(syslogMessage), event.getThrown()); - for (SyslogAppender syslogAppender : _syslogAppenders) { + for (SyslogAppender syslogAppender : syslogAppenders) { syslogAppender.append(syslogEvent); } } } catch (Exception e) { - errorHandler.error(e.getMessage()); + getHandler().error(e.getMessage()); } } } - @Override - synchronized public void close() { - for (SyslogAppender syslogAppender : _syslogAppenders) { - syslogAppender.close(); - } - } - - @Override - public boolean requiresLayout() { - return true; + @PluginFactory + public static AlertsSyslogAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout layout, + @PluginElement("Filter") final Filter filter, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, @PluginElement("properties") final Property[] properties, + @PluginAttribute("facility") String facility, @PluginAttribute("syslogHosts") String syslogHosts) { + return new AlertsSyslogAppender(name, filter, layout, ignoreExceptions, properties, facility, syslogHosts); } void setSyslogAppenders() { - if (_syslogAppenders == null) { - _syslogAppenders = new ArrayList(); + if (syslogAppenders == null) { + syslogAppenders = new ArrayList(); } - if (_syslogHosts == null || _syslogHosts.trim().isEmpty()) { + if (syslogHosts == null || syslogHosts.trim().isEmpty()) { reset(); return; } - _syslogHostsList = parseSyslogHosts(_syslogHosts); + syslogHostsList = parseSyslogHosts(syslogHosts); if (!validateIpAddresses()) { reset(); - errorHandler.error(" Invalid format for the IP Addresses parameter "); + getHandler().error(" Invalid format for the IP Addresses parameter "); return; } - for (String syslogHost : _syslogHostsList) { - _syslogAppenders.add(new SyslogAppender(getLayout(), syslogHost, SyslogAppender.getFacility(_facility))); + for (String syslogHost : syslogHostsList) { + syslogAppenders.add(SyslogAppender.newSyslogAppenderBuilder().setFacility(Facility.toFacility(facility)).setHost(syslogHost).setLayout(getLayout()).build()); } } private List parseSyslogHosts(String syslogHosts) { List result = new ArrayList(); - final StringTokenizer tokenizer = new StringTokenizer(syslogHosts, _delimiter); + final StringTokenizer tokenizer = new StringTokenizer(syslogHosts, delimiter); while (tokenizer.hasMoreTokens()) { result.add(tokenizer.nextToken().trim()); } @@ -157,7 +167,7 @@ public class AlertsSyslogAppender extends AppenderSkeleton { } private boolean validateIpAddresses() { - for (String ipAddress : _syslogHostsList) { + for (String ipAddress : syslogHostsList) { String[] hostTokens = (ipAddress.trim()).split(":"); String ip = hostTokens[0]; @@ -181,10 +191,10 @@ public class AlertsSyslogAppender extends AppenderSkeleton { } void parseMessage(String logMessage) { - final StringTokenizer messageSplitter = new StringTokenizer(logMessage, _pairDelimiter); + final StringTokenizer messageSplitter = new StringTokenizer(logMessage, pairDelimiter); while (messageSplitter.hasMoreTokens()) { final String pairToken = messageSplitter.nextToken(); - final StringTokenizer pairSplitter = new StringTokenizer(pairToken, _keyValueDelimiter); + final StringTokenizer pairSplitter = new StringTokenizer(pairToken, keyValueDelimiter); String keyToken; String valueToken; @@ -231,60 +241,47 @@ public class AlertsSyslogAppender extends AppenderSkeleton { } if (alertType >= 0) { - message.append("alertType").append(_keyValueDelimiter).append(" ").append(alertsMap.containsKey(alertType) ? alertsMap.get(alertType) : "unknown") + message.append("alertType").append(keyValueDelimiter).append(" ").append(alertsMap.containsKey(alertType) ? alertsMap.get(alertType) : "unknown") .append(MESSAGE_DELIMITER_STRING); if (dataCenterId != 0) { - message.append("dataCenterId").append(_keyValueDelimiter).append(" ").append(dataCenterId).append(MESSAGE_DELIMITER_STRING); + message.append("dataCenterId").append(keyValueDelimiter).append(" ").append(dataCenterId).append(MESSAGE_DELIMITER_STRING); } if (podId != 0) { - message.append("podId").append(_keyValueDelimiter).append(" ").append(podId).append(MESSAGE_DELIMITER_STRING); + message.append("podId").append(keyValueDelimiter).append(" ").append(podId).append(MESSAGE_DELIMITER_STRING); } if (clusterId != 0) { - message.append("clusterId").append(_keyValueDelimiter).append(" ").append(clusterId).append(MESSAGE_DELIMITER_STRING); + message.append("clusterId").append(keyValueDelimiter).append(" ").append(clusterId).append(MESSAGE_DELIMITER_STRING); } if (sysMessage != null) { - message.append("message").append(_keyValueDelimiter).append(" ").append(sysMessage); + message.append("message").append(keyValueDelimiter).append(" ").append(sysMessage); } else { - errorHandler.error("What is the use of alert without message "); + getHandler().error("What is the use of alert without message "); } } else { - errorHandler.error("Invalid alert Type "); + getHandler().error("Invalid alert Type "); } return message.toString(); } private String getSyslogMessage(String message) { - int lastIndexOfKeyValueDelimiter = message.lastIndexOf(_keyValueDelimiter); + int lastIndexOfKeyValueDelimiter = message.lastIndexOf(keyValueDelimiter); int lastIndexOfMessageInString = message.lastIndexOf("message"); if (lastIndexOfKeyValueDelimiter - lastIndexOfMessageInString <= LENGTH_OF_STRING_MESSAGE_AND_KEY_VALUE_DELIMITER) { - return message.substring(lastIndexOfKeyValueDelimiter + _keyValueDelimiter.length()).trim(); + return message.substring(lastIndexOfKeyValueDelimiter + keyValueDelimiter.length()).trim(); } else if (lastIndexOfMessageInString < lastIndexOfKeyValueDelimiter) { - return message.substring(lastIndexOfMessageInString + _keyValueDelimiter.length() + LENGTH_OF_STRING_MESSAGE).trim(); + return message.substring(lastIndexOfMessageInString + keyValueDelimiter.length() + LENGTH_OF_STRING_MESSAGE).trim(); } - return message.substring(message.lastIndexOf("message" + _keyValueDelimiter) + LENGTH_OF_STRING_MESSAGE_AND_KEY_VALUE_DELIMITER).trim(); + return message.substring(message.lastIndexOf("message" + keyValueDelimiter) + LENGTH_OF_STRING_MESSAGE_AND_KEY_VALUE_DELIMITER).trim(); } private void reset() { - _syslogAppenders.clear(); - } - - public void setFacility(String facility) { - if (facility == null) { - return; - } - - _facility = facility; - if (_syslogAppenders != null && !_syslogAppenders.isEmpty()) { - for (SyslogAppender syslogAppender : _syslogAppenders) { - syslogAppender.setFacility(facility); - } - } + syslogAppenders.clear(); } private String severityOfAlert(int alertType) { @@ -304,40 +301,9 @@ public class AlertsSyslogAppender extends AppenderSkeleton { return false; } - public String getFacility() { - return _facility; - } - - public String getSyslogHosts() { - return _syslogHosts; - } - public void setSyslogHosts(String syslogHosts) { - _syslogHosts = syslogHosts; + this.syslogHosts = syslogHosts; setSyslogAppenders(); } - public String getDelimiter() { - return _delimiter; - } - - public void setDelimiter(String delimiter) { - _delimiter = delimiter; - } - - public String getPairDelimiter() { - return _pairDelimiter; - } - - public void setPairDelimiter(String pairDelimiter) { - _pairDelimiter = pairDelimiter; - } - - public String getKeyValueDelimiter() { - return _keyValueDelimiter; - } - - public void setKeyValueDelimiter(String keyValueDelimiter) { - _keyValueDelimiter = keyValueDelimiter; - } } diff --git a/plugins/alert-handlers/syslog-alerts/src/test/java/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java b/plugins/alert-handlers/syslog-alerts/src/test/java/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java index fe071a6c327..b76a259409c 100644 --- a/plugins/alert-handlers/syslog-alerts/src/test/java/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java +++ b/plugins/alert-handlers/syslog-alerts/src/test/java/org/apache/cloudstack/syslog/AlertsSyslogAppenderTest.java @@ -17,41 +17,32 @@ package org.apache.cloudstack.syslog; +import org.apache.logging.log4j.core.config.Property; +import org.apache.logging.log4j.core.layout.PatternLayout; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import javax.naming.ConfigurationException; - -import org.apache.log4j.PatternLayout; -import org.junit.Before; import org.junit.Test; public class AlertsSyslogAppenderTest { - AlertsSyslogAppender _appender = new AlertsSyslogAppender(); - - @Before - public void setUp() throws ConfigurationException { - _appender.setLayout(new PatternLayout("%-5p [%c{3}] (%t:%x) %m%n")); - _appender.setFacility("LOCAL6"); - } - + AlertsSyslogAppender _appender = new AlertsSyslogAppender("test", null, PatternLayout.createDefaultLayout(), true, Property.EMPTY_ARRAY, "LOCAL6", null); @Test public void setSyslogAppendersTest() { _appender.setSyslogHosts("10.1.1.1,10.1.1.2"); - assertEquals(" error Syslog Appenders list size not as expected ", 2, _appender._syslogAppenders.size()); + assertEquals(" error Syslog Appenders list size not as expected ", 2, _appender.syslogAppenders.size()); } @Test public void setSyslogAppendersWithPortTest() { _appender.setSyslogHosts("10.1.1.1:897,10.1.1.2"); - assertEquals(" error Syslog Appenders list size not as expected ", 2, _appender._syslogAppenders.size()); + assertEquals(" error Syslog Appenders list size not as expected ", 2, _appender.syslogAppenders.size()); } @Test public void setSyslogAppendersNegativeTest() { //setting invalid IP for Syslog Hosts _appender.setSyslogHosts("10.1.1."); - assertTrue(" list was expected to be empty", _appender._syslogAppenders.isEmpty()); + assertTrue(" list was expected to be empty", _appender.syslogAppenders.isEmpty()); } @Test diff --git a/plugins/api/discovery/pom.xml b/plugins/api/discovery/pom.xml index 0026c4f4d06..6426dcd70a5 100644 --- a/plugins/api/discovery/pom.xml +++ b/plugins/api/discovery/pom.xml @@ -25,7 +25,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/api/discovery/src/main/java/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java b/plugins/api/discovery/src/main/java/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java index 8cf643edb04..aa78a725a34 100644 --- a/plugins/api/discovery/src/main/java/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java +++ b/plugins/api/discovery/src/main/java/org/apache/cloudstack/api/command/user/discovery/ListApisCmd.java @@ -19,7 +19,6 @@ package org.apache.cloudstack.api.command.user.discovery; import javax.inject.Inject; import org.apache.cloudstack.acl.RoleType; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.user.User; responseHasSensitiveInfo = false, authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User}) public class ListApisCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(ListApisCmd.class.getName()); @Inject ApiDiscoveryService _apiDiscoveryService; diff --git a/plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java b/plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java index 3bdf2e9ce92..239bc49a65a 100644 --- a/plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java +++ b/plugins/api/discovery/src/main/java/org/apache/cloudstack/discovery/ApiDiscoveryServiceImpl.java @@ -44,7 +44,6 @@ import org.apache.cloudstack.api.response.ApiResponseResponse; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.reflections.ReflectionUtils; import org.springframework.stereotype.Component; @@ -60,7 +59,6 @@ import com.google.gson.annotations.SerializedName; @Component public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements ApiDiscoveryService { - private static final Logger s_logger = Logger.getLogger(ApiDiscoveryServiceImpl.class); List _apiAccessCheckers = null; List _services = null; @@ -83,13 +81,13 @@ public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements A s_apiNameDiscoveryResponseMap = new HashMap(); Set> cmdClasses = new LinkedHashSet>(); for (PluggableService service : _services) { - s_logger.debug(String.format("getting api commands of service: %s", service.getClass().getName())); + logger.debug(String.format("getting api commands of service: %s", service.getClass().getName())); cmdClasses.addAll(service.getCommands()); } cmdClasses.addAll(this.getCommands()); cacheResponseMap(cmdClasses); long endTime = System.nanoTime(); - s_logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms"); + logger.info("Api Discovery Service: Annotation, docstrings, api relation graph processed in " + (endTime - startTime) / 1000000.0 + " ms"); } return true; @@ -108,8 +106,8 @@ public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements A } String apiName = apiCmdAnnotation.name(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Found api: " + apiName); + if (logger.isTraceEnabled()) { + logger.trace("Found api: " + apiName); } ApiDiscoveryResponse response = getCmdRequestMap(cmdClass, apiCmdAnnotation); @@ -258,7 +256,7 @@ public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements A try { apiChecker.checkAccess(user, name); } catch (Exception ex) { - s_logger.error(String.format("API discovery access check failed for [%s] with error [%s].", name, ex.getMessage()), ex); + logger.error(String.format("API discovery access check failed for [%s] with error [%s].", name, ex.getMessage()), ex); return null; } } @@ -277,7 +275,7 @@ public class ApiDiscoveryServiceImpl extends ComponentLifecycleBase implements A } if (role.getRoleType() == RoleType.Admin && role.getId() == RoleType.Admin.getId()) { - s_logger.info(String.format("Account [%s] is Root Admin, all APIs are allowed.", + logger.info(String.format("Account [%s] is Root Admin, all APIs are allowed.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(account, "accountName", "uuid"))); } else { for (APIChecker apiChecker : _apiAccessCheckers) { diff --git a/plugins/api/rate-limit/pom.xml b/plugins/api/rate-limit/pom.xml index e951fe3b6f1..73bdd0697d1 100644 --- a/plugins/api/rate-limit/pom.xml +++ b/plugins/api/rate-limit/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java index 5be0dfcb678..8f5624f5b95 100644 --- a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java +++ b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/admin/ratelimit/ResetApiLimitCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.ratelimit; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ACL; import org.apache.cloudstack.api.APICommand; @@ -39,7 +38,6 @@ import com.cloud.user.Account; @APICommand(name = "resetApiLimit", responseObject = SuccessResponse.class, description = "Reset api count", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ResetApiLimitCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(ResetApiLimitCmd.class.getName()); @Inject diff --git a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java index 027d9bef459..eafe2782d33 100644 --- a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java +++ b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/api/command/user/ratelimit/GetApiLimitCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.user.ratelimit; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiErrorCode; @@ -35,7 +34,6 @@ import com.cloud.user.Account; @APICommand(name = "getApiLimit", responseObject = ApiLimitResponse.class, description = "Get API limit count for the caller", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetApiLimitCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(GetApiLimitCmd.class.getName()); @Inject diff --git a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java index 3192727fbeb..917cd7bb2b4 100644 --- a/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java +++ b/plugins/api/rate-limit/src/main/java/org/apache/cloudstack/ratelimit/ApiRateLimitServiceImpl.java @@ -28,7 +28,6 @@ import net.sf.ehcache.CacheManager; import org.apache.cloudstack.acl.Role; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import org.apache.cloudstack.acl.APIChecker; @@ -47,7 +46,6 @@ import com.cloud.utils.component.AdapterBase; @Component public class ApiRateLimitServiceImpl extends AdapterBase implements APIChecker, ApiRateLimitService { - private static final Logger s_logger = Logger.getLogger(ApiRateLimitServiceImpl.class); /** * True if api rate limiting is enabled @@ -100,7 +98,7 @@ public class ApiRateLimitServiceImpl extends AdapterBase implements APIChecker, CacheManager cm = CacheManager.create(); Cache cache = new Cache("api-limit-cache", maxElements, false, false, timeToLive, timeToLive); cm.addCache(cache); - s_logger.info("Limit Cache created with timeToLive=" + timeToLive + ", maxAllowed=" + maxAllowed + ", maxElements=" + maxElements); + logger.info("Limit Cache created with timeToLive=" + timeToLive + ", maxAllowed=" + maxAllowed + ", maxElements=" + maxElements); cacheStore.setCache(cache); _store = cacheStore; @@ -158,7 +156,7 @@ public class ApiRateLimitServiceImpl extends AdapterBase implements APIChecker, public void throwExceptionDueToApiRateLimitReached(Long accountId) throws RequestLimitException { long expireAfter = _store.get(accountId).getExpireDuration(); String msg = String.format("The given user has reached his/her account api limit, please retry after [%s] ms.", expireAfter); - s_logger.warn(msg); + logger.warn(msg); throw new RequestLimitException(msg); } @@ -176,7 +174,7 @@ public class ApiRateLimitServiceImpl extends AdapterBase implements APIChecker, public boolean checkAccess(Account account, String commandName) { Long accountId = account.getAccountId(); if (_accountService.isRootAdmin(accountId)) { - s_logger.info(String.format("Account [%s] is Root Admin, in this case, API limit does not apply.", + logger.info(String.format("Account [%s] is Root Admin, in this case, API limit does not apply.", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(account, "accountName", "uuid"))); return true; } @@ -203,7 +201,7 @@ public class ApiRateLimitServiceImpl extends AdapterBase implements APIChecker, int current = entry.incrementAndGet(); if (current <= maxAllowed) { - s_logger.trace(String.format("Account %s has current count [%s].", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(account, "uuid", "accountName"), current)); + logger.trace(String.format("Account %s has current count [%s].", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(account, "uuid", "accountName"), current)); return false; } return true; @@ -212,7 +210,7 @@ public class ApiRateLimitServiceImpl extends AdapterBase implements APIChecker, @Override public boolean isEnabled() { if (!enabled) { - s_logger.debug("API rate limiting is disabled. We will not use ApiRateLimitService."); + logger.debug("API rate limiting is disabled. We will not use ApiRateLimitService."); } return enabled; } diff --git a/plugins/api/solidfire-intg-test/pom.xml b/plugins/api/solidfire-intg-test/pom.xml index f33aa33c994..907c5f2968d 100644 --- a/plugins/api/solidfire-intg-test/pom.xml +++ b/plugins/api/solidfire-intg-test/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetPathForVolumeCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetPathForVolumeCmd.java index ff3c307a87b..5ff7f82a7b0 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetPathForVolumeCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetPathForVolumeCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.solidfire; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; @@ -29,7 +28,6 @@ import org.apache.cloudstack.util.solidfire.SolidFireIntegrationTestUtil; @APICommand(name = "getPathForVolume", responseObject = ApiPathForVolumeResponse.class, description = "Get the path associated with the provided volume UUID", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetPathForVolumeCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetPathForVolumeCmd.class.getName()); @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.STRING, description = "CloudStack Volume UUID", required = true) private String _volumeUuid; @@ -47,7 +45,7 @@ public class GetPathForVolumeCmd extends BaseCmd { @Override public void execute() { - LOGGER.info("'GetPathForVolumeIdCmd.execute' method invoked"); + logger.info("'GetPathForVolumeIdCmd.execute' method invoked"); String pathForVolume = _util.getPathForVolumeUuid(_volumeUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireAccountIdCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireAccountIdCmd.java index af6400ce1c5..baedb0389d5 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireAccountIdCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireAccountIdCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.solidfire; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; @@ -31,7 +30,6 @@ import org.apache.cloudstack.util.solidfire.SolidFireIntegrationTestUtil; @APICommand(name = "getSolidFireAccountId", responseObject = ApiSolidFireAccountIdResponse.class, description = "Get SolidFire Account ID", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetSolidFireAccountIdCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetSolidFireAccountIdCmd.class.getName()); @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.STRING, description = "CloudStack Account UUID", required = true) private String csAccountUuid; @@ -52,7 +50,7 @@ public class GetSolidFireAccountIdCmd extends BaseCmd { @Override public void execute() { - LOGGER.info("'GetSolidFireAccountIdCmd.execute' method invoked"); + logger.info("'GetSolidFireAccountIdCmd.execute' method invoked"); long sfAccountId = manager.getSolidFireAccountId(csAccountUuid, storagePoolUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeAccessGroupIdsCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeAccessGroupIdsCmd.java index 31330f066e5..c250c870f8d 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeAccessGroupIdsCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeAccessGroupIdsCmd.java @@ -20,7 +20,6 @@ import com.cloud.user.Account; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; @@ -34,7 +33,6 @@ import org.apache.cloudstack.util.solidfire.SolidFireIntegrationTestUtil; @APICommand(name = "getSolidFireVolumeAccessGroupIds", responseObject = ApiSolidFireVolumeAccessGroupIdsResponse.class, description = "Get the SF Volume Access Group IDs", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetSolidFireVolumeAccessGroupIdsCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetSolidFireVolumeAccessGroupIdsCmd.class.getName()); @Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.STRING, description = "Cluster UUID", required = true) private String clusterUuid; @@ -61,7 +59,7 @@ public class GetSolidFireVolumeAccessGroupIdsCmd extends BaseCmd { @Override public void execute() { - LOGGER.info("'GetSolidFireVolumeAccessGroupIdsCmd.execute' method invoked"); + logger.info("'GetSolidFireVolumeAccessGroupIdsCmd.execute' method invoked"); long[] sfVagIds = manager.getSolidFireVolumeAccessGroupIds(clusterUuid, storagePoolUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeSizeCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeSizeCmd.java index 9179ec26a8b..10af3be25b0 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeSizeCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetSolidFireVolumeSizeCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.solidfire; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; @@ -31,7 +30,6 @@ import org.apache.cloudstack.util.solidfire.SolidFireIntegrationTestUtil; @APICommand(name = "getSolidFireVolumeSize", responseObject = ApiSolidFireVolumeSizeResponse.class, description = "Get the SF volume size including Hypervisor Snapshot Reserve", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetSolidFireVolumeSizeCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetSolidFireVolumeSizeCmd.class.getName()); @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.STRING, description = "Volume UUID", required = true) private String volumeUuid; @@ -50,7 +48,7 @@ public class GetSolidFireVolumeSizeCmd extends BaseCmd { @Override public void execute() { - LOGGER.info("'GetSolidFireVolumeSizeCmd.execute' method invoked"); + logger.info("'GetSolidFireVolumeSizeCmd.execute' method invoked"); long sfVolumeSize = manager.getSolidFireVolumeSize(volumeUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeSnapshotDetailsCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeSnapshotDetailsCmd.java index 91fe6bba1cb..bbb86bec31e 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeSnapshotDetailsCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeSnapshotDetailsCmd.java @@ -20,7 +20,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; @@ -34,7 +33,6 @@ import org.apache.cloudstack.util.solidfire.SolidFireIntegrationTestUtil; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetVolumeSnapshotDetailsCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetVolumeSnapshotDetailsCmd.class.getName()); @Parameter(name = ApiConstants.SNAPSHOT_ID, type = CommandType.STRING, description = "CloudStack Snapshot UUID", required = true) private String snapshotUuid; @@ -52,7 +50,7 @@ public class GetVolumeSnapshotDetailsCmd extends BaseCmd { @Override public void execute() { - LOGGER.info("'" + GetVolumeSnapshotDetailsCmd.class.getSimpleName() + ".execute' method invoked"); + logger.info("'" + GetVolumeSnapshotDetailsCmd.class.getSimpleName() + ".execute' method invoked"); List responses = util.getSnapshotDetails(snapshotUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeiScsiNameCmd.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeiScsiNameCmd.java index 41ed1069418..e2063ce9d69 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeiScsiNameCmd.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/command/admin/solidfire/GetVolumeiScsiNameCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.solidfire; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; @@ -30,7 +29,6 @@ import org.apache.cloudstack.util.solidfire.SolidFireIntegrationTestUtil; requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class GetVolumeiScsiNameCmd extends BaseCmd { - private static final Logger LOGGER = Logger.getLogger(GetVolumeiScsiNameCmd.class.getName()); @Parameter(name = ApiConstants.VOLUME_ID, type = CommandType.STRING, description = "CloudStack Volume UUID", required = true) private String volumeUuid; @@ -48,7 +46,7 @@ public class GetVolumeiScsiNameCmd extends BaseCmd { @Override public void execute() { - LOGGER.info("'GetVolumeiScsiNameCmd.execute' method invoked"); + logger.info("'GetVolumeiScsiNameCmd.execute' method invoked"); String volume_iScsiName = _util.getVolume_iScsiName(volumeUuid); diff --git a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/solidfire/ApiSolidFireIntegrationTestServiceImpl.java b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/solidfire/ApiSolidFireIntegrationTestServiceImpl.java index 4adcbbe89d8..91868f4ef8f 100644 --- a/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/solidfire/ApiSolidFireIntegrationTestServiceImpl.java +++ b/plugins/api/solidfire-intg-test/src/main/java/org/apache/cloudstack/api/solidfire/ApiSolidFireIntegrationTestServiceImpl.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.ArrayList; import org.apache.cloudstack.api.command.admin.solidfire.GetPathForVolumeCmd; -// import org.apache.log4j.Logger; import org.apache.cloudstack.api.command.admin.solidfire.GetSolidFireAccountIdCmd; import org.apache.cloudstack.api.command.admin.solidfire.GetSolidFireVolumeAccessGroupIdsCmd; import org.apache.cloudstack.api.command.admin.solidfire.GetVolumeSnapshotDetailsCmd; diff --git a/plugins/api/vmware-sioc/pom.xml b/plugins/api/vmware-sioc/pom.xml index 8dd0cfc11e0..b3c04e603cb 100644 --- a/plugins/api/vmware-sioc/pom.xml +++ b/plugins/api/vmware-sioc/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/api/command/admin/sioc/UpdateSiocInfoCmd.java b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/api/command/admin/sioc/UpdateSiocInfoCmd.java index 84504d13e4c..b9dd659905b 100644 --- a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/api/command/admin/sioc/UpdateSiocInfoCmd.java +++ b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/api/command/admin/sioc/UpdateSiocInfoCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.command.admin.sioc; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -37,7 +36,6 @@ import com.cloud.user.Account; since = "4.11.0", authorized = {RoleType.Admin}) public class UpdateSiocInfoCmd extends BaseCmd { - private static final Logger s_logger = Logger.getLogger(UpdateSiocInfoCmd.class.getName()); ///////////////////////////////////////////////////// @@ -78,7 +76,7 @@ public class UpdateSiocInfoCmd extends BaseCmd { @Override public void execute() { - s_logger.info("'UpdateSiocInfoCmd.execute' method invoked"); + logger.info("'UpdateSiocInfoCmd.execute' method invoked"); String msg = "Success"; diff --git a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/sioc/SiocManagerImpl.java b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/sioc/SiocManagerImpl.java index f012dbfa972..c87ff3dfc82 100644 --- a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/sioc/SiocManagerImpl.java +++ b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/sioc/SiocManagerImpl.java @@ -30,7 +30,8 @@ import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.util.LoginInfo; import org.apache.cloudstack.util.vmware.VMwareUtil; import org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.dc.DataCenterVO; @@ -63,7 +64,7 @@ import com.vmware.vim25.VirtualMachineConfigSpec; @Component public class SiocManagerImpl implements SiocManager { - private static final Logger LOGGER = Logger.getLogger(SiocManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int LOCK_TIME_IN_SECONDS = 3; private static final int ONE_GB_IN_BYTES = 1000000000; private static final int LOWEST_SHARES_PER_VIRTUAL_DISK = 2000; // We want this to be greater than 1,000, which is the VMware default value. @@ -82,7 +83,7 @@ public class SiocManagerImpl implements SiocManager { @Override public void updateSiocInfo(long zoneId, long storagePoolId, int sharesPerGB, int limitIopsPerGB, int iopsNotifyThreshold) throws Exception { - LOGGER.info("'SiocManagerImpl.updateSiocInfo(long, long, int, int, int)' method invoked"); + logger.info("'SiocManagerImpl.updateSiocInfo(long, long, int, int, int)' method invoked"); DataCenterVO zone = zoneDao.findById(zoneId); @@ -250,7 +251,7 @@ public class SiocManagerImpl implements SiocManager { tasks.add(task); - LOGGER.info(getInfoMsg(volumeVO, newShares, newLimitIops)); + logger.info(getInfoMsg(volumeVO, newShares, newLimitIops)); } catch (Exception ex) { throw new Exception("Error: " + ex.getMessage()); } @@ -321,7 +322,7 @@ public class SiocManagerImpl implements SiocManager { tasks.add(task); - LOGGER.info(getInfoMsgForWorkerVm(newLimitIops)); + logger.info(getInfoMsgForWorkerVm(newLimitIops)); } catch (Exception ex) { throw new Exception("Error: " + ex.getMessage()); } diff --git a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/util/vmware/VMwareUtil.java b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/util/vmware/VMwareUtil.java index 209945fa471..ae93c3431fc 100644 --- a/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/util/vmware/VMwareUtil.java +++ b/plugins/api/vmware-sioc/src/main/java/org/apache/cloudstack/util/vmware/VMwareUtil.java @@ -35,7 +35,8 @@ import javax.xml.ws.BindingProvider; import javax.xml.ws.WebServiceException; import org.apache.cloudstack.util.LoginInfo; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.hypervisor.vmware.mo.VirtualMachineDiskInfoBuilder; import com.vmware.vim25.DynamicProperty; @@ -71,7 +72,7 @@ import com.vmware.vim25.VirtualMachineConfigSpec; import com.vmware.vim25.VirtualSCSIController; public class VMwareUtil { - private static final Logger s_logger = Logger.getLogger(VMwareUtil.class); + protected static Logger LOGGER = LogManager.getLogger(VMwareUtil.class); private VMwareUtil() {} @@ -315,7 +316,7 @@ public class VMwareUtil { throw new Exception(((LocalizedMethodFault)result[1]).getLocalizedMessage()); } } catch (WebServiceException we) { - s_logger.debug("Cancelling vCenter task because the task failed with the following error: " + we.getLocalizedMessage()); + LOGGER.debug("Cancelling vCenter task because the task failed with the following error: " + we.getLocalizedMessage()); connection.getVimPortType().cancelTask(task); diff --git a/plugins/backup/dummy/pom.xml b/plugins/backup/dummy/pom.xml index 3c3d5cfdd24..52fbd085eb2 100644 --- a/plugins/backup/dummy/pom.xml +++ b/plugins/backup/dummy/pom.xml @@ -23,7 +23,7 @@ cloudstack-plugins org.apache.cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java b/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java index fabc9821fd3..fa376f992ed 100644 --- a/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java +++ b/plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java @@ -25,7 +25,6 @@ import java.util.Map; import javax.inject.Inject; import org.apache.cloudstack.backup.dao.BackupDao; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; @@ -35,7 +34,6 @@ import com.cloud.vm.VirtualMachine; public class DummyBackupProvider extends AdapterBase implements BackupProvider { - private static final Logger s_logger = Logger.getLogger(DummyBackupProvider.class); @Inject private BackupDao backupDao; @@ -52,7 +50,7 @@ public class DummyBackupProvider extends AdapterBase implements BackupProvider { @Override public List listBackupOfferings(Long zoneId) { - s_logger.debug("Listing backup policies on Dummy B&R Plugin"); + logger.debug("Listing backup policies on Dummy B&R Plugin"); BackupOffering policy1 = new BackupOfferingVO(1, "gold-policy", "dummy", "Golden Policy", "Gold description", true); BackupOffering policy2 = new BackupOfferingVO(1, "silver-policy", "dummy", "Silver Policy", "Silver description", true); return Arrays.asList(policy1, policy2); @@ -60,26 +58,26 @@ public class DummyBackupProvider extends AdapterBase implements BackupProvider { @Override public boolean isValidProviderOffering(Long zoneId, String uuid) { - s_logger.debug("Checking if backup offering exists on the Dummy Backup Provider"); + logger.debug("Checking if backup offering exists on the Dummy Backup Provider"); return true; } @Override public boolean assignVMToBackupOffering(VirtualMachine vm, BackupOffering backupOffering) { - s_logger.debug("Creating VM backup for VM " + vm.getInstanceName() + " from backup offering " + backupOffering.getName()); + logger.debug("Creating VM backup for VM " + vm.getInstanceName() + " from backup offering " + backupOffering.getName()); ((VMInstanceVO) vm).setBackupExternalId("dummy-external-backup-id"); return true; } @Override public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) { - s_logger.debug("Restoring vm " + vm.getUuid() + "from backup " + backup.getUuid() + " on the Dummy Backup Provider"); + logger.debug("Restoring vm " + vm.getUuid() + "from backup " + backup.getUuid() + " on the Dummy Backup Provider"); return true; } @Override public Pair restoreBackedUpVolume(Backup backup, String volumeUuid, String hostIp, String dataStoreUuid) { - s_logger.debug("Restoring volume " + volumeUuid + "from backup " + backup.getUuid() + " on the Dummy Backup Provider"); + logger.debug("Restoring volume " + volumeUuid + "from backup " + backup.getUuid() + " on the Dummy Backup Provider"); throw new CloudRuntimeException("Dummy plugin does not support this feature"); } @@ -100,7 +98,7 @@ public class DummyBackupProvider extends AdapterBase implements BackupProvider { @Override public boolean removeVMFromBackupOffering(VirtualMachine vm) { - s_logger.debug("Removing VM ID " + vm.getUuid() + " from backup offering by the Dummy Backup Provider"); + logger.debug("Removing VM ID " + vm.getUuid() + " from backup offering by the Dummy Backup Provider"); return true; } @@ -111,7 +109,7 @@ public class DummyBackupProvider extends AdapterBase implements BackupProvider { @Override public boolean takeBackup(VirtualMachine vm) { - s_logger.debug("Starting backup for VM ID " + vm.getUuid() + " on Dummy provider"); + logger.debug("Starting backup for VM ID " + vm.getUuid() + " on Dummy provider"); BackupVO backup = new BackupVO(); backup.setVmId(vm.getId()); diff --git a/plugins/backup/networker/pom.xml b/plugins/backup/networker/pom.xml index 16724096444..1124d281d2e 100644 --- a/plugins/backup/networker/pom.xml +++ b/plugins/backup/networker/pom.xml @@ -25,7 +25,7 @@ cloudstack-plugins org.apache.cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java b/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java index 9703203108a..e375b42aeb5 100644 --- a/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java +++ b/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java @@ -44,7 +44,8 @@ import org.apache.cloudstack.backup.networker.NetworkerClient; import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; import org.apache.commons.collections.CollectionUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xml.utils.URI; import org.apache.cloudstack.backup.networker.api.NetworkerBackup; import javax.inject.Inject; @@ -68,7 +69,7 @@ import com.cloud.utils.script.Script; public class NetworkerBackupProvider extends AdapterBase implements BackupProvider, Configurable { public static final String BACKUP_IDENTIFIER = "-CSBKP-"; - private static final Logger LOG = Logger.getLogger(NetworkerBackupProvider.class); + private static final Logger LOG = LogManager.getLogger(NetworkerBackupProvider.class); public ConfigKey NetworkerUrl = new ConfigKey<>("Advanced", String.class, "backup.plugin.networker.url", "https://localhost:9090/nwrestapi/v3", diff --git a/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/networker/NetworkerClient.java b/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/networker/NetworkerClient.java index 8bb89b635e9..8aecaa26023 100644 --- a/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/networker/NetworkerClient.java +++ b/plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/networker/NetworkerClient.java @@ -42,7 +42,8 @@ import org.apache.http.conn.ConnectTimeoutException; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import javax.net.ssl.SSLContext; import javax.net.ssl.X509TrustManager; @@ -64,7 +65,7 @@ import java.util.List; import static org.apache.cloudstack.backup.NetworkerBackupProvider.BACKUP_IDENTIFIER; public class NetworkerClient { - private static final Logger LOG = Logger.getLogger(NetworkerClient.class); + private static final Logger LOG = LogManager.getLogger(NetworkerClient.class); private final URI apiURI; private final String apiName; private final String apiPassword; diff --git a/plugins/backup/veeam/pom.xml b/plugins/backup/veeam/pom.xml index ee59fa8ba74..a317f90388a 100644 --- a/plugins/backup/veeam/pom.xml +++ b/plugins/backup/veeam/pom.xml @@ -23,11 +23,26 @@ cloudstack-plugins org.apache.cloudstack - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml + + org.apache.cloudstack + cloud-core + ${project.version} + + + org.apache.cloudstack + cloud-engine-api + ${project.version} + + + org.apache.cloudstack + cloud-engine-components-api + ${project.version} + org.apache.cloudstack cloud-plugin-hypervisor-vmware diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java index c0091e47061..0e453739018 100644 --- a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/VeeamBackupProvider.java @@ -29,6 +29,7 @@ import java.util.stream.Collectors; import javax.inject.Inject; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.InternalIdentity; import org.apache.cloudstack.backup.Backup.Metric; import org.apache.cloudstack.backup.dao.BackupDao; @@ -38,13 +39,18 @@ import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.Configurable; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.BooleanUtils; -import org.apache.log4j.Logger; +import com.cloud.agent.AgentManager; +import com.cloud.agent.api.Answer; +import com.cloud.event.ActionEventUtils; +import com.cloud.event.EventTypes; +import com.cloud.event.EventVO; import com.cloud.hypervisor.Hypervisor; import com.cloud.dc.VmwareDatacenter; import com.cloud.hypervisor.vmware.VmwareDatacenterZoneMap; import com.cloud.dc.dao.VmwareDatacenterDao; import com.cloud.hypervisor.vmware.dao.VmwareDatacenterZoneMapDao; +import com.cloud.user.User; import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.db.Transaction; @@ -53,17 +59,21 @@ import com.cloud.utils.db.TransactionStatus; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineManager; import com.cloud.vm.dao.VMInstanceDao; public class VeeamBackupProvider extends AdapterBase implements BackupProvider, Configurable { - private static final Logger LOG = Logger.getLogger(VeeamBackupProvider.class); public static final String BACKUP_IDENTIFIER = "-CSBKP-"; public ConfigKey VeeamUrl = new ConfigKey<>("Advanced", String.class, "backup.plugin.veeam.url", "https://localhost:9398/api/", "The Veeam backup and recovery URL.", true, ConfigKey.Scope.Zone); + public ConfigKey VeeamVersion = new ConfigKey<>("Advanced", Integer.class, + "backup.plugin.veeam.version", "0", + "The version of Veeam backup and recovery. CloudStack will get Veeam server version via PowerShell commands if it is 0 or not set", true, ConfigKey.Scope.Zone); + private ConfigKey VeeamUsername = new ConfigKey<>("Advanced", String.class, "backup.plugin.veeam.username", "administrator", "The Veeam backup and recovery username.", true, ConfigKey.Scope.Zone); @@ -81,6 +91,12 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, private static ConfigKey VeeamRestoreTimeout = new ConfigKey<>("Advanced", Integer.class, "backup.plugin.veeam.restore.timeout", "600", "The Veeam B&R API restore backup timeout in seconds.", true, ConfigKey.Scope.Zone); + private static ConfigKey VeeamTaskPollInterval = new ConfigKey<>("Advanced", Integer.class, "backup.plugin.veeam.task.poll.interval", "5", + "The time interval in seconds when the management server polls for Veeam task status.", true, ConfigKey.Scope.Zone); + + private static ConfigKey VeeamTaskPollMaxRetry = new ConfigKey<>("Advanced", Integer.class, "backup.plugin.veeam.task.poll.max.retry", "120", + "The max number of retrying times when the management server polls for Veeam task status.", true, ConfigKey.Scope.Zone); + @Inject private VmwareDatacenterZoneMapDao vmwareDatacenterZoneMapDao; @Inject @@ -89,15 +105,20 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, private BackupDao backupDao; @Inject private VMInstanceDao vmInstanceDao; + @Inject + private AgentManager agentMgr; + @Inject + private VirtualMachineManager virtualMachineManager; protected VeeamClient getClient(final Long zoneId) { try { - return new VeeamClient(VeeamUrl.valueIn(zoneId), VeeamUsername.valueIn(zoneId), VeeamPassword.valueIn(zoneId), - VeeamValidateSSLSecurity.valueIn(zoneId), VeeamApiRequestTimeout.valueIn(zoneId), VeeamRestoreTimeout.valueIn(zoneId)); + return new VeeamClient(VeeamUrl.valueIn(zoneId), VeeamVersion.valueIn(zoneId), VeeamUsername.valueIn(zoneId), VeeamPassword.valueIn(zoneId), + VeeamValidateSSLSecurity.valueIn(zoneId), VeeamApiRequestTimeout.valueIn(zoneId), VeeamRestoreTimeout.valueIn(zoneId), + VeeamTaskPollInterval.valueIn(zoneId), VeeamTaskPollMaxRetry.valueIn(zoneId)); } catch (URISyntaxException e) { throw new CloudRuntimeException("Failed to parse Veeam API URL: " + e.getMessage()); } catch (NoSuchAlgorithmException | KeyManagementException e) { - LOG.error("Failed to build Veeam API client due to: ", e); + logger.error("Failed to build Veeam API client due to: ", e); } throw new CloudRuntimeException("Failed to build Veeam API client"); } @@ -152,7 +173,7 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, final String clonedJobName = getGuestBackupName(vm.getInstanceName(), vm.getUuid()); if (!client.cloneVeeamJob(parentJob, clonedJobName)) { - LOG.error("Failed to clone pre-defined Veeam job (backup offering) for backup offering ID: " + backupOffering.getExternalId() + " but will check the list of jobs again if it was eventually succeeded."); + logger.error("Failed to clone pre-defined Veeam job (backup offering) for backup offering ID: " + backupOffering.getExternalId() + " but will check the list of jobs again if it was eventually succeeded."); } for (final BackupOffering job : client.listJobs()) { @@ -161,7 +182,7 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, if (BooleanUtils.isTrue(clonedJob.getScheduleConfigured()) && !clonedJob.getScheduleEnabled()) { client.toggleJobSchedule(clonedJob.getId()); } - LOG.debug("Veeam job (backup offering) for backup offering ID: " + backupOffering.getExternalId() + " found, now trying to assign the VM to the job."); + logger.debug("Veeam job (backup offering) for backup offering ID: " + backupOffering.getExternalId() + " found, now trying to assign the VM to the job."); final VmwareDatacenter vmwareDC = findVmwareDatacenterForVM(vm); if (client.addVMToVeeamJob(job.getExternalId(), vm.getInstanceName(), vmwareDC.getVcenterHost())) { ((VMInstanceVO) vm).setBackupExternalId(job.getExternalId()); @@ -178,17 +199,18 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, final VmwareDatacenter vmwareDC = findVmwareDatacenterForVM(vm); try { if (!client.removeVMFromVeeamJob(vm.getBackupExternalId(), vm.getInstanceName(), vmwareDC.getVcenterHost())) { - LOG.warn("Failed to remove VM from Veeam Job id: " + vm.getBackupExternalId()); + logger.warn("Failed to remove VM from Veeam Job id: " + vm.getBackupExternalId()); } } catch (Exception e) { - LOG.debug("VM was removed from the job so could not remove again, trying to delete the veeam job now.", e); + logger.debug("VM was removed from the job so could not remove again, trying to delete the veeam job now.", e); } final String clonedJobName = getGuestBackupName(vm.getInstanceName(), vm.getUuid()); if (!client.deleteJobAndBackup(clonedJobName)) { - LOG.warn("Failed to remove Veeam job and backup for job: " + clonedJobName); + logger.warn("Failed to remove Veeam job and backup for job: " + clonedJobName); throw new CloudRuntimeException("Failed to delete Veeam B&R job and backup, an operation may be in progress. Please try again after some time."); } + client.syncBackupRepository(); return true; } @@ -210,7 +232,7 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, throw new CloudRuntimeException(String.format("Could not find any VM associated with the Backup [uuid: %s, externalId: %s].", backup.getUuid(), backup.getExternalId())); } if (!forced) { - LOG.debug(String.format("Veeam backup provider does not have a safe way to remove a single restore point, which results in all backup chain being removed. " + logger.debug(String.format("Veeam backup provider does not have a safe way to remove a single restore point, which results in all backup chain being removed. " + "More information about this limitation can be found in the links: [%s, %s].", "https://forums.veeam.com/powershell-f26/removing-a-single-restorepoint-t21061.html", "https://helpcenter.veeam.com/docs/backup/vsphere/retention_separate_vms.html?ver=110")); throw new CloudRuntimeException("Veeam backup provider does not have a safe way to remove a single restore point, which results in all backup chain being removed. " @@ -222,6 +244,8 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, return false; } + client.syncBackupRepository(); + List allBackups = backupDao.listByVmId(backup.getZoneId(), backup.getVmId()); for (Backup b : allBackups) { if (b.getId() != backup.getId()) { @@ -234,7 +258,36 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, @Override public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) { final String restorePointId = backup.getExternalId(); - return getClient(vm.getDataCenterId()).restoreFullVM(vm.getInstanceName(), restorePointId); + try { + return getClient(vm.getDataCenterId()).restoreFullVM(vm.getInstanceName(), restorePointId); + } catch (Exception ex) { + logger.error(String.format("Failed to restore Full VM due to: %s. Retrying after some preparation", ex.getMessage())); + prepareForBackupRestoration(vm); + return getClient(vm.getDataCenterId()).restoreFullVM(vm.getInstanceName(), restorePointId); + } + } + + private void prepareForBackupRestoration(VirtualMachine vm) { + if (!Hypervisor.HypervisorType.VMware.equals(vm.getHypervisorType())) { + return; + } + logger.info("Preparing for restoring VM " + vm); + PrepareForBackupRestorationCommand command = new PrepareForBackupRestorationCommand(vm.getInstanceName()); + Long hostId = virtualMachineManager.findClusterAndHostIdForVm(vm.getId()).second(); + if (hostId == null) { + throw new CloudRuntimeException("Cannot find a host to prepare for restoring VM " + vm); + } + try { + Answer answer = agentMgr.easySend(hostId, command); + if (answer != null && answer.getResult()) { + logger.info("Succeeded to prepare for restoring VM " + vm); + } else { + throw new CloudRuntimeException(String.format("Failed to prepare for restoring VM %s. details: %s", vm, + (answer != null ? answer.getDetails() : null))); + } + } catch (Exception e) { + throw new CloudRuntimeException(String.format("Failed to prepare for restoring VM %s due to exception %s", vm, e)); + } } @Override @@ -248,12 +301,12 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, public Map getBackupMetrics(final Long zoneId, final List vms) { final Map metrics = new HashMap<>(); if (CollectionUtils.isEmpty(vms)) { - LOG.warn("Unable to get VM Backup Metrics because the list of VMs is empty."); + logger.warn("Unable to get VM Backup Metrics because the list of VMs is empty."); return metrics; } List vmUuids = vms.stream().filter(Objects::nonNull).map(VirtualMachine::getUuid).collect(Collectors.toList()); - LOG.debug(String.format("Get Backup Metrics for VMs: [%s].", String.join(", ", vmUuids))); + logger.debug(String.format("Get Backup Metrics for VMs: [%s].", String.join(", ", vmUuids))); final Map backendMetrics = getClient(zoneId).getBackupMetrics(); for (final VirtualMachine vm : vms) { @@ -262,7 +315,7 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, } Metric metric = backendMetrics.get(vm.getUuid()); - LOG.debug(String.format("Metrics for VM [uuid: %s, name: %s] is [backup size: %s, data size: %s].", vm.getUuid(), + logger.debug(String.format("Metrics for VM [uuid: %s, name: %s] is [backup size: %s, data size: %s].", vm.getUuid(), vm.getInstanceName(), metric.getBackupSize(), metric.getDataSize())); metrics.put(vm, metric); } @@ -278,7 +331,7 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, for (final Backup backup : backupsInDb) { if (restorePoint.getId().equals(backup.getExternalId())) { if (metric != null) { - LOG.debug(String.format("Update backup with [uuid: %s, external id: %s] from [size: %s, protected size: %s] to [size: %s, protected size: %s].", + logger.debug(String.format("Update backup with [uuid: %s, external id: %s] from [size: %s, protected size: %s] to [size: %s, protected size: %s].", backup.getUuid(), backup.getExternalId(), backup.getSize(), backup.getProtectedSize(), metric.getBackupSize(), metric.getDataSize())); ((BackupVO) backup).setSize(metric.getBackupSize()); @@ -295,7 +348,7 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, public void syncBackups(VirtualMachine vm, Backup.Metric metric) { List restorePoints = listRestorePoints(vm); if (CollectionUtils.isEmpty(restorePoints)) { - LOG.debug(String.format("Can't find any restore point to VM: [uuid: %s, name: %s].", vm.getUuid(), vm.getInstanceName())); + logger.debug(String.format("Can't find any restore point to VM: [uuid: %s, name: %s].", vm.getUuid(), vm.getInstanceName())); return; } Transaction.execute(new TransactionCallbackNoReturn() { @@ -326,14 +379,18 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, backup.setDomainId(vm.getDomainId()); backup.setZoneId(vm.getDataCenterId()); - LOG.debug(String.format("Creating a new entry in backups: [uuid: %s, vm_id: %s, external_id: %s, type: %s, date: %s, backup_offering_id: %s, account_id: %s, " + logger.debug(String.format("Creating a new entry in backups: [uuid: %s, vm_id: %s, external_id: %s, type: %s, date: %s, backup_offering_id: %s, account_id: %s, " + "domain_id: %s, zone_id: %s].", backup.getUuid(), backup.getVmId(), backup.getExternalId(), backup.getType(), backup.getDate(), backup.getBackupOfferingId(), backup.getAccountId(), backup.getDomainId(), backup.getZoneId())); backupDao.persist(backup); + + ActionEventUtils.onCompletedActionEvent(User.UID_SYSTEM, vm.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_VM_BACKUP_CREATE, + String.format("Created backup %s for VM ID: %s", backup.getUuid(), vm.getUuid()), + vm.getId(), ApiCommandResourceType.VirtualMachine.toString(),0); } } for (final Long backupIdToRemove : removeList) { - LOG.warn(String.format("Removing backup with ID: [%s].", backupIdToRemove)); + logger.warn(String.format("Removing backup with ID: [%s].", backupIdToRemove)); backupDao.remove(backupIdToRemove); } } @@ -349,11 +406,14 @@ public class VeeamBackupProvider extends AdapterBase implements BackupProvider, public ConfigKey[] getConfigKeys() { return new ConfigKey[]{ VeeamUrl, + VeeamVersion, VeeamUsername, VeeamPassword, VeeamValidateSSLSecurity, VeeamApiRequestTimeout, - VeeamRestoreTimeout + VeeamRestoreTimeout, + VeeamTaskPollInterval, + VeeamTaskPollMaxRetry }; } diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java index 1438dca4838..8a193c1ce80 100644 --- a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java @@ -20,12 +20,15 @@ package org.apache.cloudstack.backup.veeam; import static org.apache.cloudstack.backup.VeeamBackupProvider.BACKUP_IDENTIFIER; import java.io.IOException; +import java.io.InputStream; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URISyntaxException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; @@ -44,6 +47,8 @@ import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.backup.Backup; import org.apache.cloudstack.backup.BackupOffering; +import org.apache.cloudstack.backup.veeam.api.BackupFile; +import org.apache.cloudstack.backup.veeam.api.BackupFiles; import org.apache.cloudstack.backup.veeam.api.BackupJobCloneInfo; import org.apache.cloudstack.backup.veeam.api.CreateObjectInJobSpec; import org.apache.cloudstack.backup.veeam.api.EntityReferences; @@ -57,7 +62,10 @@ import org.apache.cloudstack.backup.veeam.api.ObjectsInJob; import org.apache.cloudstack.backup.veeam.api.Ref; import org.apache.cloudstack.backup.veeam.api.RestoreSession; import org.apache.cloudstack.backup.veeam.api.Task; +import org.apache.cloudstack.backup.veeam.api.VmRestorePoint; +import org.apache.cloudstack.backup.veeam.api.VmRestorePoints; import org.apache.cloudstack.utils.security.SSLUtils; +import org.apache.commons.collections.CollectionUtils; import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -71,8 +79,10 @@ import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.nio.TrustAllManager; @@ -84,7 +94,7 @@ import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; import org.apache.commons.lang3.StringUtils; public class VeeamClient { - private static final Logger LOG = Logger.getLogger(VeeamClient.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String FAILED_TO_DELETE = "Failed to delete"; private final URI apiURI; @@ -92,18 +102,30 @@ public class VeeamClient { private final HttpClient httpClient; private static final String RESTORE_VM_SUFFIX = "CS-RSTR-"; private static final String SESSION_HEADER = "X-RestSvcSessionId"; + private static final String BACKUP_REFERENCE = "BackupReference"; + private static final String HIERARCHY_ROOT_REFERENCE = "HierarchyRootReference"; + private static final String REPOSITORY_REFERENCE = "RepositoryReference"; + private static final String RESTORE_POINT_REFERENCE = "RestorePointReference"; + private static final String BACKUP_FILE_REFERENCE = "BackupFileReference"; + private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); + private String veeamServerIp; + private final Integer veeamServerVersion; private String veeamServerUsername; private String veeamServerPassword; private String veeamSessionId = null; - private int restoreTimeout; + private final int restoreTimeout; private final int veeamServerPort = 22; + private final int taskPollInterval; + private final int taskPollMaxRetry; - public VeeamClient(final String url, final String username, final String password, final boolean validateCertificate, final int timeout, - final int restoreTimeout) throws URISyntaxException, NoSuchAlgorithmException, KeyManagementException { + public VeeamClient(final String url, final Integer version, final String username, final String password, final boolean validateCertificate, final int timeout, + final int restoreTimeout, final int taskPollInterval, final int taskPollMaxRetry) throws URISyntaxException, NoSuchAlgorithmException, KeyManagementException { this.apiURI = new URI(url); this.restoreTimeout = restoreTimeout; + this.taskPollInterval = taskPollInterval; + this.taskPollMaxRetry = taskPollMaxRetry; final RequestConfig config = RequestConfig.custom() .setConnectTimeout(timeout * 1000) @@ -127,6 +149,7 @@ public class VeeamClient { authenticate(username, password); setVeeamSshCredentials(this.apiURI.getHost(), username, password); + this.veeamServerVersion = (version != null && version != 0) ? version : getVeeamServerVersion(); } protected void setVeeamSshCredentials(String hostIp, String username, String password) { @@ -137,7 +160,7 @@ public class VeeamClient { private void authenticate(final String username, final String password) { // https://helpcenter.veeam.com/docs/backup/rest/http_authentication.html?ver=95u4 - final HttpPost request = new HttpPost(apiURI.toString() + "/sessionMngr/?v=v1_4"); + final HttpPost request = new HttpPost(apiURI.toString() + "/sessionMngr/?v=latest"); request.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes())); try { final HttpResponse response = httpClient.execute(request); @@ -160,15 +183,35 @@ public class VeeamClient { } } + protected Integer getVeeamServerVersion() { + final List cmds = Arrays.asList( + "$InstallPath = Get-ItemProperty -Path 'HKLM:\\Software\\Veeam\\Veeam Backup and Replication\\' ^| Select -ExpandProperty CorePath", + "Add-Type -LiteralPath \\\"$InstallPath\\Veeam.Backup.Configuration.dll\\\"", + "$ProductData = [Veeam.Backup.Configuration.BackupProduct]::Create()", + "$Version = $ProductData.ProductVersion.ToString()", + "if ($ProductData.MarketName -ne '') {$Version += \\\" $($ProductData.MarketName)\\\"}", + "$Version" + ); + Pair response = executePowerShellCommands(cmds); + if (response == null || !response.first() || response.second() == null || StringUtils.isBlank(response.second().trim())) { + logger.error("Failed to get veeam server version, using default version"); + return 0; + } else { + Integer majorVersion = NumbersUtil.parseInt(response.second().trim().split("\\.")[0], 0); + logger.info(String.format("Veeam server full version is %s, major version is %s", response.second().trim(), majorVersion)); + return majorVersion; + } + } + private void checkResponseOK(final HttpResponse response) { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT) { - LOG.debug("Requested Veeam resource does not exist"); + logger.debug("Requested Veeam resource does not exist"); return; } if (!(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK || response.getStatusLine().getStatusCode() == HttpStatus.SC_ACCEPTED) && response.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { - LOG.debug(String.format("HTTP request failed, status code is [%s], response is: [%s].", response.getStatusLine().getStatusCode(), response.toString())); + logger.debug(String.format("HTTP request failed, status code is [%s], response is: [%s].", response.getStatusLine().getStatusCode(), response.toString())); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Got invalid API status code returned by the Veeam server"); } } @@ -186,7 +229,7 @@ public class VeeamClient { final HttpResponse response = httpClient.execute(request); checkAuthFailure(response); - LOG.debug(String.format("Response received in GET request is: [%s] for URL: [%s].", response.toString(), url)); + logger.debug(String.format("Response received in GET request is: [%s] for URL: [%s].", response.toString(), url)); return response; } @@ -212,7 +255,7 @@ public class VeeamClient { final HttpResponse response = httpClient.execute(request); checkAuthFailure(response); - LOG.debug(String.format("Response received in POST request with body [%s] is: [%s] for URL [%s].", xml, response.toString(), url)); + logger.debug(String.format("Response received in POST request with body [%s] is: [%s] for URL [%s].", xml, response.toString(), url)); return response; } @@ -223,7 +266,7 @@ public class VeeamClient { final HttpResponse response = httpClient.execute(request); checkAuthFailure(response); - LOG.debug(String.format("Response received in DELETE request is: [%s] for URL [%s].", response.toString(), url)); + logger.debug(String.format("Response received in DELETE request is: [%s] for URL [%s].", response.toString(), url)); return response; } @@ -232,7 +275,7 @@ public class VeeamClient { /////////////////////////////////////////////////////////////////// private String findDCHierarchy(final String vmwareDcName) { - LOG.debug("Trying to find hierarchy ID for vmware datacenter: " + vmwareDcName); + logger.debug("Trying to find hierarchy ID for vmware datacenter: " + vmwareDcName); try { final HttpResponse response = get("/hierarchyRoots"); @@ -240,19 +283,19 @@ public class VeeamClient { final ObjectMapper objectMapper = new XmlMapper(); final EntityReferences references = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class); for (final Ref ref : references.getRefs()) { - if (ref.getName().equals(vmwareDcName) && ref.getType().equals("HierarchyRootReference")) { + if (ref.getName().equals(vmwareDcName) && ref.getType().equals(HIERARCHY_ROOT_REFERENCE)) { return ref.getUid(); } } } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } throw new CloudRuntimeException("Failed to find hierarchy reference for VMware datacenter " + vmwareDcName + " in Veeam, please ask administrator to check Veeam B&R manager configuration"); } private String lookupVM(final String hierarchyId, final String vmName) { - LOG.debug("Trying to lookup VM from veeam hierarchy:" + hierarchyId + " for vm name:" + vmName); + logger.debug("Trying to lookup VM from veeam hierarchy:" + hierarchyId + " for vm name:" + vmName); try { final HttpResponse response = get(String.format("/lookup?host=%s&type=Vm&name=%s", hierarchyId, vmName)); @@ -268,7 +311,7 @@ public class VeeamClient { } } } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } throw new CloudRuntimeException("Failed to lookup VM " + vmName + " in Veeam, please ask administrator to check Veeam B&R manager configuration"); @@ -288,13 +331,13 @@ public class VeeamClient { private boolean checkTaskStatus(final HttpResponse response) throws IOException { final Task task = parseTaskResponse(response); - for (int i = 0; i < 120; i++) { + for (int i = 0; i < this.taskPollMaxRetry; i++) { final HttpResponse taskResponse = get("/tasks/" + task.getTaskId()); final Task polledTask = parseTaskResponse(taskResponse); if (polledTask.getState().equals("Finished")) { final HttpResponse taskDeleteResponse = delete("/tasks/" + task.getTaskId()); if (taskDeleteResponse.getStatusLine().getStatusCode() != HttpStatus.SC_NO_CONTENT) { - LOG.warn("Operation failed for veeam task id=" + task.getTaskId()); + logger.warn("Operation failed for veeam task id=" + task.getTaskId()); } if (polledTask.getResult().getSuccess().equals("true")) { Pair pair = getRelatedLinkPair(polledTask.getLink()); @@ -311,9 +354,9 @@ public class VeeamClient { throw new CloudRuntimeException("Failed to assign VM to backup offering due to: " + polledTask.getResult().getMessage()); } try { - Thread.sleep(5000); + Thread.sleep(this.taskPollInterval * 1000); } catch (InterruptedException e) { - LOG.debug("Failed to sleep while polling for Veeam task status due to: ", e); + logger.debug("Failed to sleep while polling for Veeam task status due to: ", e); } } return false; @@ -326,10 +369,14 @@ public class VeeamClient { if (session.getResult().equals("Success")) { return true; } + if (session.getResult().equalsIgnoreCase("Failed")) { + String sessionUid = session.getUid(); + throw new CloudRuntimeException(String.format("Restore job [%s] failed.", sessionUid)); + } try { Thread.sleep(1000); } catch (InterruptedException ignored) { - LOG.trace(String.format("Ignoring InterruptedException [%s] when waiting for restore session finishes.", ignored.getMessage())); + logger.trace(String.format("Ignoring InterruptedException [%s] when waiting for restore session finishes.", ignored.getMessage())); } } throw new CloudRuntimeException("Related job type: " + type + " was not successful"); @@ -349,7 +396,7 @@ public class VeeamClient { //////////////////////////////////////////////////////// public Ref listBackupRepository(final String backupServerId, final String backupName) { - LOG.debug(String.format("Trying to list backup repository for backup job [name: %s] in server [id: %s].", backupName, backupServerId)); + logger.debug(String.format("Trying to list backup repository for backup job [name: %s] in server [id: %s].", backupName, backupServerId)); try { String repositoryName = getRepositoryNameFromJob(backupName); final HttpResponse response = get(String.format("/backupServers/%s/repositories", backupServerId)); @@ -357,12 +404,12 @@ public class VeeamClient { final ObjectMapper objectMapper = new XmlMapper(); final EntityReferences references = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class); for (final Ref ref : references.getRefs()) { - if (ref.getType().equals("RepositoryReference") && ref.getName().equals(repositoryName)) { + if (ref.getType().equals(REPOSITORY_REFERENCE) && ref.getName().equals(repositoryName)) { return ref; } } } catch (final IOException e) { - LOG.error(String.format("Failed to list Veeam backup repository used by backup job [name: %s] due to: [%s].", backupName, e.getMessage()), e); + logger.error(String.format("Failed to list Veeam backup repository used by backup job [name: %s] due to: [%s].", backupName, e.getMessage()), e); checkResponseTimeOut(e); } return null; @@ -370,7 +417,7 @@ public class VeeamClient { protected String getRepositoryNameFromJob(String backupName) { final List cmds = Arrays.asList( - String.format("$Job = Get-VBRJob -name \"%s\"", backupName), + String.format("$Job = Get-VBRJob -name '%s'", backupName), "$Job.GetBackupTargetRepository() ^| select Name ^| Format-List" ); Pair result = executePowerShellCommands(cmds); @@ -378,7 +425,7 @@ public class VeeamClient { throw new CloudRuntimeException(String.format("Failed to get Repository Name from Job [name: %s].", backupName)); } - for (String block : result.second().split("\n\n")) { + for (String block : result.second().split("\r\n")) { if (block.matches("Name(\\s)+:(.)*")) { return block.split(":")[1].trim(); } @@ -387,23 +434,23 @@ public class VeeamClient { } public void listAllBackups() { - LOG.debug("Trying to list Veeam backups"); + logger.debug("Trying to list Veeam backups"); try { final HttpResponse response = get("/backups"); checkResponseOK(response); final ObjectMapper objectMapper = new XmlMapper(); final EntityReferences entityReferences = objectMapper.readValue(response.getEntity().getContent(), EntityReferences.class); for (final Ref ref : entityReferences.getRefs()) { - LOG.debug("Veeam Backup found, name: " + ref.getName() + ", uid: " + ref.getUid() + ", type: " + ref.getType()); + logger.debug("Veeam Backup found, name: " + ref.getName() + ", uid: " + ref.getUid() + ", type: " + ref.getType()); } } catch (final IOException e) { - LOG.error("Failed to list Veeam backups due to:", e); + logger.error("Failed to list Veeam backups due to:", e); checkResponseTimeOut(e); } } public List listJobs() { - LOG.debug("Trying to list backup policies that are Veeam jobs"); + logger.debug("Trying to list backup policies that are Veeam jobs"); try { final HttpResponse response = get("/jobs"); checkResponseOK(response); @@ -418,14 +465,14 @@ public class VeeamClient { } return policies; } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } return new ArrayList<>(); } public Job listJob(final String jobId) { - LOG.debug("Trying to list veeam job id: " + jobId); + logger.debug("Trying to list veeam job id: " + jobId); try { final HttpResponse response = get(String.format("/jobs/%s?format=Entity", jobId.replace("urn:veeam:Job:", ""))); @@ -434,40 +481,40 @@ public class VeeamClient { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return objectMapper.readValue(response.getEntity().getContent(), Job.class); } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } catch (final ServerApiException e) { - LOG.error(e); + logger.error(e); } return null; } public boolean toggleJobSchedule(final String jobId) { - LOG.debug("Trying to toggle schedule for Veeam job: " + jobId); + logger.debug("Trying to toggle schedule for Veeam job: " + jobId); try { final HttpResponse response = post(String.format("/jobs/%s?action=toggleScheduleEnabled", jobId), null); return checkTaskStatus(response); } catch (final IOException e) { - LOG.error("Failed to toggle Veeam job schedule due to:", e); + logger.error("Failed to toggle Veeam job schedule due to:", e); checkResponseTimeOut(e); } return false; } public boolean startBackupJob(final String jobId) { - LOG.debug("Trying to start ad-hoc backup for Veeam job: " + jobId); + logger.debug("Trying to start ad-hoc backup for Veeam job: " + jobId); try { final HttpResponse response = post(String.format("/jobs/%s?action=start", jobId), null); return checkTaskStatus(response); } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } return false; } public boolean cloneVeeamJob(final Job parentJob, final String clonedJobName) { - LOG.debug("Trying to clone veeam job: " + parentJob.getUid() + " with backup uuid: " + clonedJobName); + logger.debug("Trying to clone veeam job: " + parentJob.getUid() + " with backup uuid: " + clonedJobName); try { final Ref repositoryRef = listBackupRepository(parentJob.getBackupServerId(), parentJob.getName()); if (repositoryRef == null) { @@ -483,13 +530,13 @@ public class VeeamClient { final HttpResponse response = post(String.format("/jobs/%s?action=clone", parentJob.getId()), cloneSpec); return checkTaskStatus(response); } catch (final Exception e) { - LOG.warn("Exception caught while trying to clone Veeam job:", e); + logger.warn("Exception caught while trying to clone Veeam job:", e); } return false; } public boolean addVMToVeeamJob(final String jobId, final String vmwareInstanceName, final String vmwareDcName) { - LOG.debug("Trying to add VM to backup offering that is Veeam job: " + jobId); + logger.debug("Trying to add VM to backup offering that is Veeam job: " + jobId); try { final String heirarchyId = findDCHierarchy(vmwareDcName); final String veeamVmRefId = lookupVM(heirarchyId, vmwareInstanceName); @@ -499,14 +546,14 @@ public class VeeamClient { final HttpResponse response = post(String.format("/jobs/%s/includes", jobId), vmToBackupJob); return checkTaskStatus(response); } catch (final IOException e) { - LOG.error("Failed to add VM to Veeam job due to:", e); + logger.error("Failed to add VM to Veeam job due to:", e); checkResponseTimeOut(e); } throw new CloudRuntimeException("Failed to add VM to backup offering likely due to timeout, please check Veeam tasks"); } public boolean removeVMFromVeeamJob(final String jobId, final String vmwareInstanceName, final String vmwareDcName) { - LOG.debug("Trying to remove VM from backup offering that is a Veeam job: " + jobId); + logger.debug("Trying to remove VM from backup offering that is a Veeam job: " + jobId); try { final String hierarchyId = findDCHierarchy(vmwareDcName); final String veeamVmRefId = lookupVM(hierarchyId, vmwareInstanceName); @@ -516,7 +563,7 @@ public class VeeamClient { objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); final ObjectsInJob jobObjects = objectMapper.readValue(response.getEntity().getContent(), ObjectsInJob.class); if (jobObjects == null || jobObjects.getObjects() == null) { - LOG.warn("No objects found in the Veeam job " + jobId); + logger.warn("No objects found in the Veeam job " + jobId); return false; } for (final ObjectInJob jobObject : jobObjects.getObjects()) { @@ -525,22 +572,22 @@ public class VeeamClient { return checkTaskStatus(deleteResponse); } } - LOG.warn(vmwareInstanceName + " VM was not found to be attached to Veaam job (backup offering): " + jobId); + logger.warn(vmwareInstanceName + " VM was not found to be attached to Veaam job (backup offering): " + jobId); return false; } catch (final IOException e) { - LOG.error("Failed to list Veeam jobs due to:", e); + logger.error("Failed to list Veeam jobs due to:", e); checkResponseTimeOut(e); } return false; } public boolean restoreFullVM(final String vmwareInstanceName, final String restorePointId) { - LOG.debug("Trying to restore full VM: " + vmwareInstanceName + " from backup"); + logger.debug("Trying to restore full VM: " + vmwareInstanceName + " from backup"); try { final HttpResponse response = post(String.format("/vmRestorePoints/%s?action=restore", restorePointId), null); return checkTaskStatus(response); } catch (final IOException e) { - LOG.error("Failed to restore full VM due to: ", e); + logger.error("Failed to restore full VM due to: ", e); checkResponseTimeOut(e); } throw new CloudRuntimeException("Failed to restore full VM from backup"); @@ -555,7 +602,12 @@ public class VeeamClient { */ protected String transformPowerShellCommandList(List cmds) { StringJoiner joiner = new StringJoiner(";"); - joiner.add("PowerShell Add-PSSnapin VeeamPSSnapin"); + if (isLegacyServer()) { + joiner.add("PowerShell Add-PSSnapin VeeamPSSnapin"); + } else { + joiner.add("PowerShell Import-Module Veeam.Backup.PowerShell -WarningAction SilentlyContinue"); + joiner.add("$ProgressPreference='SilentlyContinue'"); + } for (String cmd : cmds) { joiner.add(cmd); } @@ -573,9 +625,9 @@ public class VeeamClient { commands, 120000, 120000, 3600000); if (response == null || !response.first()) { - LOG.error(String.format("Veeam PowerShell commands [%s] failed due to: [%s].", commands, response != null ? response.second() : "no PowerShell output returned")); + logger.error(String.format("Veeam PowerShell commands [%s] failed due to: [%s].", commands, response != null ? response.second() : "no PowerShell output returned")); } else { - LOG.debug(String.format("Veeam response for PowerShell commands [%s] is: [%s].", commands, response.second())); + logger.debug(String.format("Veeam response for PowerShell commands [%s] is: [%s].", commands, response.second())); } return response; @@ -586,66 +638,156 @@ public class VeeamClient { public boolean setJobSchedule(final String jobName) { Pair result = executePowerShellCommands(Arrays.asList( - String.format("$job = Get-VBRJob -Name \"%s\"", jobName), + String.format("$job = Get-VBRJob -Name '%s'", jobName), "if ($job) { Set-VBRJobSchedule -Job $job -Daily -At \"11:00\" -DailyKind Weekdays }" )); - return result.first() && !result.second().isEmpty() && !result.second().contains(FAILED_TO_DELETE); + return result != null && result.first() && !result.second().isEmpty() && !result.second().contains(FAILED_TO_DELETE); } public boolean deleteJobAndBackup(final String jobName) { Pair result = executePowerShellCommands(Arrays.asList( - String.format("$job = Get-VBRJob -Name \"%s\"", jobName), + String.format("$job = Get-VBRJob -Name '%s'", jobName), "if ($job) { Remove-VBRJob -Job $job -Confirm:$false }", - String.format("$backup = Get-VBRBackup -Name \"%s\"", jobName), - "if ($backup) { Remove-VBRBackup -Backup $backup -FromDisk -Confirm:$false }", - "$repo = Get-VBRBackupRepository", - "Sync-VBRBackupRepository -Repository $repo" + String.format("$backup = Get-VBRBackup -Name '%s'", jobName), + "if ($backup) { Remove-VBRBackup -Backup $backup -FromDisk -Confirm:$false }" )); - return result.first() && !result.second().contains(FAILED_TO_DELETE); + return result != null && result.first() && !result.second().contains(FAILED_TO_DELETE); } public boolean deleteBackup(final String restorePointId) { - LOG.debug(String.format("Trying to delete restore point [name: %s].", restorePointId)); + logger.debug(String.format("Trying to delete restore point [name: %s].", restorePointId)); Pair result = executePowerShellCommands(Arrays.asList( String.format("$restorePoint = Get-VBRRestorePoint ^| Where-Object { $_.Id -eq '%s' }", restorePointId), "if ($restorePoint) { Remove-VBRRestorePoint -Oib $restorePoint -Confirm:$false", - "$repo = Get-VBRBackupRepository", - "Sync-VBRBackupRepository -Repository $repo", "} else { ", - " Write-Output \"Failed to delete\"", + " Write-Output 'Failed to delete'", " Exit 1", "}" )); - return result.first() && !result.second().contains(FAILED_TO_DELETE); + return result != null && result.first() && !result.second().contains(FAILED_TO_DELETE); + } + + public boolean syncBackupRepository() { + logger.debug("Trying to sync backup repository."); + Pair result = executePowerShellCommands(Arrays.asList( + "$repo = Get-VBRBackupRepository", + "$Syncs = Sync-VBRBackupRepository -Repository $repo", + "while ((Get-VBRSession -ID $Syncs.ID).Result -ne 'Success') { Start-Sleep -Seconds 10 }" + )); + logger.debug("Done syncing backup repository."); + return result != null && result.first(); } public Map getBackupMetrics() { + if (isLegacyServer()) { + return getBackupMetricsLegacy(); + } else { + return getBackupMetricsViaVeeamAPI(); + } + } + + public Map getBackupMetricsViaVeeamAPI() { + logger.debug("Trying to get backup metrics via Veeam B&R API"); + + try { + final HttpResponse response = get(String.format("/backupFiles?format=Entity")); + checkResponseOK(response); + return processHttpResponseForBackupMetrics(response.getEntity().getContent()); + } catch (final IOException e) { + logger.error("Failed to get backup metrics via Veeam B&R API due to:", e); + checkResponseTimeOut(e); + } + return new HashMap<>(); + } + + protected Map processHttpResponseForBackupMetrics(final InputStream content) { + Map metrics = new HashMap<>(); + try { + final ObjectMapper objectMapper = new XmlMapper(); + final BackupFiles backupFiles = objectMapper.readValue(content, BackupFiles.class); + if (backupFiles == null || CollectionUtils.isEmpty(backupFiles.getBackupFiles())) { + throw new CloudRuntimeException("Could not get backup metrics via Veeam B&R API"); + } + for (final BackupFile backupFile : backupFiles.getBackupFiles()) { + String vmUuid = null; + String backupName = null; + List links = backupFile.getLink(); + for (Link link : links) { + if (BACKUP_REFERENCE.equals(link.getType())) { + backupName = link.getName(); + break; + } + } + if (backupName != null && backupName.contains(BACKUP_IDENTIFIER)) { + final String[] names = backupName.split(BACKUP_IDENTIFIER); + if (names.length > 1) { + vmUuid = names[1]; + } + } + if (vmUuid == null) { + continue; + } + if (vmUuid.contains(" - ")) { + vmUuid = vmUuid.split(" - ")[0]; + } + Long usedSize = 0L; + Long dataSize = 0L; + if (metrics.containsKey(vmUuid)) { + usedSize = metrics.get(vmUuid).getBackupSize(); + dataSize = metrics.get(vmUuid).getDataSize(); + } + if (backupFile.getBackupSize() != null) { + usedSize += Long.valueOf(backupFile.getBackupSize()); + } + if (backupFile.getDataSize() != null) { + dataSize += Long.valueOf(backupFile.getDataSize()); + } + metrics.put(vmUuid, new Backup.Metric(usedSize, dataSize)); + } + } catch (final IOException e) { + logger.error("Failed to process response to get backup metrics via Veeam B&R API due to:", e); + checkResponseTimeOut(e); + } + return metrics; + } + + public Map getBackupMetricsLegacy() { final String separator = "====="; final List cmds = Arrays.asList( - "$backups = Get-VBRBackup", - "foreach ($backup in $backups) {" + - "$backup.JobName;" + - "$storageGroups = $backup.GetStorageGroups();" + - "foreach ($group in $storageGroups) {" + - "$usedSize = 0;" + - "$dataSize = 0;" + - "$sizePerStorage = $group.GetStorages().Stats.BackupSize;" + - "$dataPerStorage = $group.GetStorages().Stats.DataSize;" + - "foreach ($size in $sizePerStorage) {" + - "$usedSize += $size;" + - "}" + - "foreach ($size in $dataPerStorage) {" + - "$dataSize += $size;" + - "}" + - "$usedSize;" + - "$dataSize;" + - "}" + - "echo \"" + separator + "\"" + - "}" + "$backups = Get-VBRBackup", + "foreach ($backup in $backups) {" + + " $backup.JobName;" + + " $storageGroups = $backup.GetStorageGroups();" + + " foreach ($group in $storageGroups) {" + + " $usedSize = 0;" + + " $dataSize = 0;" + + " $sizePerStorage = $group.GetStorages().Stats.BackupSize;" + + " $dataPerStorage = $group.GetStorages().Stats.DataSize;" + + " foreach ($size in $sizePerStorage) {" + + " $usedSize += $size;" + + " }" + + " foreach ($size in $dataPerStorage) {" + + " $dataSize += $size;" + + " }" + + " $usedSize;" + + " $dataSize;" + + " }" + + " echo \"" + separator + "\"" + + "}" ); Pair response = executePowerShellCommands(cmds); + if (response == null || !response.first()) { + throw new CloudRuntimeException("Failed to get backup metrics via PowerShell command"); + } + return processPowerShellResultForBackupMetrics(response.second()); + } + + protected Map processPowerShellResultForBackupMetrics(final String result) { + logger.debug("Processing powershell result: " + result); + + final String separator = "====="; final Map sizes = new HashMap<>(); - for (final String block : response.second().split(separator + "\r\n")) { + for (final String block : result.split(separator + "\r\n")) { final String[] parts = block.split("\r\n"); if (parts.length != 3) { continue; @@ -660,7 +802,7 @@ public class VeeamClient { } private Backup.RestorePoint getRestorePointFromBlock(String[] parts) { - LOG.debug(String.format("Processing block of restore points: [%s].", StringUtils.join(parts, ", "))); + logger.debug(String.format("Processing block of restore points: [%s].", StringUtils.join(parts, ", "))); String id = null; Date created = null; String type = null; @@ -683,9 +825,9 @@ public class VeeamClient { return new Backup.RestorePoint(id, created, type); } - public List listRestorePoints(String backupName, String vmInternalName) { + public List listRestorePointsLegacy(String backupName, String vmInternalName) { final List cmds = Arrays.asList( - String.format("$backup = Get-VBRBackup -Name \"%s\"", backupName), + String.format("$backup = Get-VBRBackup -Name '%s'", backupName), String.format("if ($backup) { $restore = (Get-VBRRestorePoint -Backup:$backup -Name \"%s\" ^| Where-Object {$_.IsConsistent -eq $true})", vmInternalName), "if ($restore) { $restore ^| Format-List } }" ); @@ -699,13 +841,78 @@ public class VeeamClient { if (block.isEmpty()) { continue; } - LOG.debug(String.format("Found restore points from [backupName: %s, vmInternalName: %s] which is: [%s].", backupName, vmInternalName, block)); + logger.debug(String.format("Found restore points from [backupName: %s, vmInternalName: %s] which is: [%s].", backupName, vmInternalName, block)); final String[] parts = block.split("\r\n"); restorePoints.add(getRestorePointFromBlock(parts)); } return restorePoints; } + public List listRestorePoints(String backupName, String vmInternalName) { + if (isLegacyServer()) { + return listRestorePointsLegacy(backupName, vmInternalName); + } else { + return listVmRestorePointsViaVeeamAPI(vmInternalName); + } + } + + public List listVmRestorePointsViaVeeamAPI(String vmInternalName) { + logger.debug(String.format("Trying to list VM restore points via Veeam B&R API for VM %s: ", vmInternalName)); + + try { + final HttpResponse response = get(String.format("/vmRestorePoints?format=Entity")); + checkResponseOK(response); + return processHttpResponseForVmRestorePoints(response.getEntity().getContent(), vmInternalName); + } catch (final IOException e) { + logger.error("Failed to list VM restore points via Veeam B&R API due to:", e); + checkResponseTimeOut(e); + } + return new ArrayList<>(); + } + + public List processHttpResponseForVmRestorePoints(InputStream content, String vmInternalName) { + List vmRestorePointList = new ArrayList<>(); + try { + final ObjectMapper objectMapper = new XmlMapper(); + final VmRestorePoints vmRestorePoints = objectMapper.readValue(content, VmRestorePoints.class); + if (vmRestorePoints == null) { + throw new CloudRuntimeException("Could not get VM restore points via Veeam B&R API"); + } + for (final VmRestorePoint vmRestorePoint : vmRestorePoints.getVmRestorePoints()) { + logger.debug(String.format("Processing VM restore point Name=%s, VmDisplayName=%s for vm name=%s", + vmRestorePoint.getName(), vmRestorePoint.getVmDisplayName(), vmInternalName)); + if (!vmInternalName.equals(vmRestorePoint.getVmDisplayName())) { + continue; + } + boolean isReady = true; + List links = vmRestorePoint.getLink(); + for (Link link : links) { + if (Arrays.asList(BACKUP_FILE_REFERENCE, RESTORE_POINT_REFERENCE).contains(link.getType()) && !link.getRel().equals("Up")) { + logger.info(String.format("The VM restore point is not ready. Reference: %s, state: %s", link.getType(), link.getRel())); + isReady = false; + break; + } + } + if (!isReady) { + continue; + } + String vmRestorePointId = vmRestorePoint.getUid().substring(vmRestorePoint.getUid().lastIndexOf(':') + 1); + Date created = formatDate(vmRestorePoint.getCreationTimeUtc()); + String type = vmRestorePoint.getPointType(); + logger.debug(String.format("Adding restore point %s, %s, %s", vmRestorePointId, created, type)); + vmRestorePointList.add(new Backup.RestorePoint(vmRestorePointId, created, type)); + } + } catch (final IOException | ParseException e) { + logger.error("Failed to process response to get VM restore points via Veeam B&R API due to:", e); + checkResponseTimeOut(e); + } + return vmRestorePointList; + } + + private Date formatDate(String date) throws ParseException { + return dateFormat.parse(StringUtils.substring(date, 0, 19)); + } + public Pair restoreVMToDifferentLocation(String restorePointId, String hostIp, String dataStoreUuid) { final String restoreLocation = RESTORE_VM_SUFFIX + UUID.randomUUID().toString(); final String datastoreId = dataStoreUuid.replace("-",""); @@ -723,4 +930,8 @@ public class VeeamClient { } return new Pair<>(result.first(), restoreLocation); } + + private boolean isLegacyServer() { + return this.veeamServerVersion != null && (this.veeamServerVersion > 0 && this.veeamServerVersion < 11); + } } diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/BackupFile.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/BackupFile.java new file mode 100644 index 00000000000..2b28793b1fb --- /dev/null +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/BackupFile.java @@ -0,0 +1,160 @@ +// 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 org.apache.cloudstack.backup.veeam.api; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +import java.util.List; + +@JacksonXmlRootElement(localName = "BackupFile") +public class BackupFile { + @JacksonXmlProperty(localName = "Type", isAttribute = true) + private String type; + + @JacksonXmlProperty(localName = "Href", isAttribute = true) + private String href; + + @JacksonXmlProperty(localName = "Name", isAttribute = true) + private String name; + + @JacksonXmlProperty(localName = "UID", isAttribute = true) + private String uid; + + @JacksonXmlProperty(localName = "Link") + @JacksonXmlElementWrapper(localName = "Links") + private List link; + + @JacksonXmlProperty(localName = "FilePath") + private String filePath; + + @JacksonXmlProperty(localName = "BackupSize") + private String backupSize; + + @JacksonXmlProperty(localName = "DataSize") + private String dataSize; + + @JacksonXmlProperty(localName = "DeduplicationRatio") + private String deduplicationRatio; + + @JacksonXmlProperty(localName = "CompressRatio") + private String compressRatio; + + @JacksonXmlProperty(localName = "CreationTimeUtc") + private String creationTimeUtc; + + @JacksonXmlProperty(localName = "FileType") + private String fileType; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getHref() { + return href; + } + + public void setHref(String href) { + this.href = href; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUid() { + return uid; + } + + public void setUid(String uid) { + this.uid = uid; + } + + public List getLink() { + return link; + } + + public void setLink(List link) { + this.link = link; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public String getBackupSize() { + return backupSize; + } + + public void setBackupSize(String backupSize) { + this.backupSize = backupSize; + } + + public String getDataSize() { + return dataSize; + } + + public void setDataSize(String dataSize) { + this.dataSize = dataSize; + } + + public String getDeduplicationRatio() { + return deduplicationRatio; + } + + public void setDeduplicationRatio(String deduplicationRatio) { + this.deduplicationRatio = deduplicationRatio; + } + + public String getCompressRatio() { + return compressRatio; + } + + public void setCompressRatio(String compressRatio) { + this.compressRatio = compressRatio; + } + + public String getCreationTimeUtc() { + return creationTimeUtc; + } + + public void setCreationTimeUtc(String creationTimeUtc) { + this.creationTimeUtc = creationTimeUtc; + } + + public String getFileType() { + return fileType; + } + + public void setFileType(String fileType) { + this.fileType = fileType; + } +} diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/BackupFiles.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/BackupFiles.java new file mode 100644 index 00000000000..4ff7d0c088b --- /dev/null +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/BackupFiles.java @@ -0,0 +1,39 @@ +// 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 org.apache.cloudstack.backup.veeam.api; + +import java.util.List; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +@JacksonXmlRootElement(localName = "BackupFiles") +public class BackupFiles { + @JacksonXmlProperty(localName = "BackupFile") + @JacksonXmlElementWrapper(localName = "BackupFile", useWrapping = false) + private List backupFiles; + + public List getBackupFiles() { + return backupFiles; + } + + public void setBackupFiles(List backupFiles) { + this.backupFiles = backupFiles; + } +} diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/VmRestorePoint.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/VmRestorePoint.java new file mode 100644 index 00000000000..beaa11cd5d4 --- /dev/null +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/VmRestorePoint.java @@ -0,0 +1,149 @@ +// 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 org.apache.cloudstack.backup.veeam.api; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +import java.util.List; + +@JacksonXmlRootElement(localName = "VmRestorePoint") +public class VmRestorePoint { + @JacksonXmlProperty(localName = "Type", isAttribute = true) + private String type; + + @JacksonXmlProperty(localName = "Href", isAttribute = true) + private String href; + + @JacksonXmlProperty(localName = "Name", isAttribute = true) + private String name; + + @JacksonXmlProperty(localName = "UID", isAttribute = true) + private String uid; + + @JacksonXmlProperty(localName = "VmDisplayName", isAttribute = true) + private String vmDisplayName; + + @JacksonXmlProperty(localName = "Link") + @JacksonXmlElementWrapper(localName = "Links") + private List link; + + @JacksonXmlProperty(localName = "CreationTimeUTC") + private String creationTimeUtc; + + @JacksonXmlProperty(localName = "VmName") + private String vmName; + + @JacksonXmlProperty(localName = "Algorithm") + private String algorithm; + + @JacksonXmlProperty(localName = "PointType") + private String pointType; + + @JacksonXmlProperty(localName = "HierarchyObjRef") + private String hierarchyObjRef; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getHref() { + return href; + } + + public void setHref(String href) { + this.href = href; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUid() { + return uid; + } + + public void setUid(String uid) { + this.uid = uid; + } + + public String getVmDisplayName() { + return vmDisplayName; + } + + public void setVmDisplayName(String vmDisplayName) { + this.vmDisplayName = vmDisplayName; + } + + public List getLink() { + return link; + } + + public void setLink(List link) { + this.link = link; + } + + public String getCreationTimeUtc() { + return creationTimeUtc; + } + + public void setCreationTimeUtc(String creationTimeUtc) { + this.creationTimeUtc = creationTimeUtc; + } + + public String getVmName() { + return vmName; + } + + public void setVmName(String vmName) { + this.vmName = vmName; + } + + public String getAlgorithm() { + return algorithm; + } + + public void setAlgorithm(String algorithm) { + this.algorithm = algorithm; + } + + public String getPointType() { + return pointType; + } + + public void setPointType(String pointType) { + this.pointType = pointType; + } + + public String getHierarchyObjRef() { + return hierarchyObjRef; + } + + public void setHierarchyObjRef(String hierarchyObjRef) { + this.hierarchyObjRef = hierarchyObjRef; + } +} diff --git a/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/VmRestorePoints.java b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/VmRestorePoints.java new file mode 100644 index 00000000000..2b59a3ef23c --- /dev/null +++ b/plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/api/VmRestorePoints.java @@ -0,0 +1,39 @@ +// 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 org.apache.cloudstack.backup.veeam.api; + +import java.util.List; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +@JacksonXmlRootElement(localName = "VmRestorePoints") +public class VmRestorePoints { + @JacksonXmlProperty(localName = "VmRestorePoint") + @JacksonXmlElementWrapper(localName = "VmRestorePoint", useWrapping = false) + private List VmRestorePoints; + + public List getVmRestorePoints() { + return VmRestorePoints; + } + + public void setVmRestorePoints(List vmRestorePoints) { + VmRestorePoints = vmRestorePoints; + } +} diff --git a/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java b/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java index a155d351bc6..b00455968c6 100644 --- a/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java +++ b/plugins/backup/veeam/src/test/java/org/apache/cloudstack/backup/veeam/VeeamClientTest.java @@ -27,12 +27,18 @@ import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static org.junit.Assert.fail; import static org.mockito.Mockito.times; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; +import java.text.SimpleDateFormat; import java.util.List; +import java.util.Map; +import org.apache.cloudstack.backup.Backup; import org.apache.cloudstack.backup.BackupOffering; import org.apache.cloudstack.backup.veeam.api.RestoreSession; import org.apache.http.HttpResponse; +import org.apache.logging.log4j.core.Logger; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; @@ -51,6 +57,7 @@ public class VeeamClientTest { private String adminPassword = "password"; private VeeamClient client; private VeeamClient mockClient; + private static final SimpleDateFormat newDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @Rule public WireMockRule wireMockRule = new WireMockRule(9399); @@ -62,9 +69,11 @@ public class VeeamClientTest { .withStatus(201) .withHeader("X-RestSvcSessionId", "some-session-auth-id") .withBody(""))); - client = new VeeamClient("http://localhost:9399/api/", adminUsername, adminPassword, true, 60, 600); + client = new VeeamClient("http://localhost:9399/api/", 12, adminUsername, adminPassword, true, 60, 600, 5, 120); mockClient = Mockito.mock(VeeamClient.class); + mockClient.logger = Mockito.mock(Logger.class); Mockito.when(mockClient.getRepositoryNameFromJob(Mockito.anyString())).thenCallRealMethod(); + Mockito.when(mockClient.getVeeamServerVersion()).thenCallRealMethod(); } @Test @@ -139,7 +148,7 @@ public class VeeamClientTest { @Test public void getRepositoryNameFromJobTestSuccess() throws Exception { String backupName = "TEST-BACKUP3"; - Pair response = new Pair(Boolean.TRUE, "\n\nName : test"); + Pair response = new Pair(Boolean.TRUE, "\r\nName : test"); Mockito.doReturn(response).when(mockClient).executePowerShellCommands(Mockito.anyList()); String repositoryNameFromJob = mockClient.getRepositoryNameFromJob(backupName); Assert.assertEquals("test", repositoryNameFromJob); @@ -162,4 +171,324 @@ public class VeeamClientTest { } Mockito.verify(mockClient, times(10)).get(Mockito.anyString()); } + + private void verifyBackupMetrics(Map metrics) { + Assert.assertEquals(2, metrics.size()); + + Assert.assertTrue(metrics.containsKey("d1bd8abd-fc73-4b77-9047-7be98a2ecb72")); + Assert.assertEquals(537776128L, (long) metrics.get("d1bd8abd-fc73-4b77-9047-7be98a2ecb72").getBackupSize()); + Assert.assertEquals(2147506644L, (long) metrics.get("d1bd8abd-fc73-4b77-9047-7be98a2ecb72").getDataSize()); + + Assert.assertTrue(metrics.containsKey("0d752ca6-d628-4d85-a739-75275e4661e6")); + Assert.assertEquals(1268682752L, (long) metrics.get("0d752ca6-d628-4d85-a739-75275e4661e6").getBackupSize()); + Assert.assertEquals(15624049921L, (long) metrics.get("0d752ca6-d628-4d85-a739-75275e4661e6").getDataSize()); + } + + @Test + public void testProcessPowerShellResultForBackupMetrics() { + String result = "i-2-3-VM-CSBKP-d1bd8abd-fc73-4b77-9047-7be98a2ecb72\r\n" + + "537776128\r\n" + + "2147506644\r\n" + + "=====\r\n" + + "i-13-22-VM-CSBKP-b3b3cb75-cfbf-4496-9c63-a08a93347276\r\n" + + "=====\r\n" + + "backup-job-based-on-sla\r\n" + + "=====\r\n" + + "i-12-20-VM-CSBKP-9f292f11-00ec-4915-84f0-e3895828640e\r\n" + + "=====\r\n" + + "i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\r\n" + + "1268682752\r\n" + + "15624049921\r\n" + + "=====\r\n"; + + Map metrics = client.processPowerShellResultForBackupMetrics(result); + + verifyBackupMetrics(metrics); + } + + @Test + public void testProcessHttpResponseForBackupMetricsForV11() { + String xmlResponse = "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-10-28T000059_745D.vbk\n" + + " 579756032\n" + + " 7516219400\n" + + " 5.83\n" + + " 2.22\n" + + " 2023-10-27T23:00:13.74Z\n" + + " vbk\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-11-05T000022_7987.vib\n" + + " 12083200\n" + + " 69232800\n" + + " 1\n" + + " 6.67\n" + + " 2023-11-05T00:00:22.827Z\n" + + " vib\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-11-01T000035_BEBF.vib\n" + + " 12398592\n" + + " 71329948\n" + + " 1\n" + + " 6.67\n" + + " 2023-11-01T00:00:35.163Z\n" + + " vib\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-11-04T000109_2AC1.vbk\n" + + " 581083136\n" + + " 7516219404\n" + + " 5.82\n" + + " 2.22\n" + + " 2023-11-04T00:00:24.973Z\n" + + " vbk\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-10-29T000033_F468.vib\n" + + " 11870208\n" + + " 72378524\n" + + " 1\n" + + " 7.14\n" + + " 2023-10-28T23:00:33.233Z\n" + + " vib\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-10-30T000022_0CE3.vib\n" + + " 14409728\n" + + " 76572828\n" + + " 1\n" + + " 6.25\n" + + " 2023-10-30T00:00:22.7Z\n" + + " vib\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-11-06T000018_055B.vib\n" + + " 17883136\n" + + " 80767136\n" + + " 1\n" + + " 5\n" + + " 2023-11-06T00:00:18.253Z\n" + + " vib\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-11-02T000029_65BE.vib\n" + + " 12521472\n" + + " 72378525\n" + + " 1\n" + + " 6.67\n" + + " 2023-11-02T00:00:29.05Z\n" + + " vib\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-3-VM-CSBKP-d1bd8abd-fc73-4b77-9047-7be98a2ecb72\\i-2-3-VM-CSBKP-d1bd8abd-fc73-4b77-9047-7be98aD2023-10-25T145951_8062.vbk\n" + + " 537776128\n" + + " 2147506644\n" + + " 1.68\n" + + " 2.38\n" + + " 2023-10-25T13:59:51.76Z\n" + + " vbk\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-11-03T000024_7ACF.vib\n" + + " 14217216\n" + + " 76572832\n" + + " 1\n" + + " 6.25\n" + + " 2023-11-03T00:00:24.803Z\n" + + " vib\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275e4661e6\\i-2-5-VM-CSBKP-0d752ca6-d628-4d85-a739-75275eD2023-10-31T000015_4624.vib\n" + + " 12460032\n" + + " 72378524\n" + + " 1\n" + + " 6.67\n" + + " 2023-10-31T00:00:15.853Z\n" + + " vib\n" + + " \n" + + "\n"; + + InputStream inputStream = new ByteArrayInputStream(xmlResponse.getBytes()); + Map metrics = client.processHttpResponseForBackupMetrics(inputStream); + + verifyBackupMetrics(metrics); + } + + @Test + public void testGetBackupMetricsViaVeeamAPI() { + String xmlResponse = "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " V:\\Backup\\i-2-4-VM-CSBKP-506760dc-ed77-40d6-a91d-e0914e7a1ad8\\i-2-4-VM.vm-1036D2023-11-03T162535_89D6.vbk\n" + + " 535875584\n" + + " 2147507235\n" + + " 1.68\n" + + " 2.38\n" + + " 2023-11-03T16:25:35.920773Z\n" + + " vbk\n" + + " \n" + + ""; + + wireMockRule.stubFor(get(urlMatching(".*/backupFiles\\?format=Entity")) + .willReturn(aResponse() + .withHeader("content-type", "application/xml") + .withStatus(200) + .withBody(xmlResponse))); + Map metrics = client.getBackupMetricsViaVeeamAPI(); + + Assert.assertEquals(1, metrics.size()); + Assert.assertTrue(metrics.containsKey("506760dc-ed77-40d6-a91d-e0914e7a1ad8")); + Assert.assertEquals(535875584L, (long) metrics.get("506760dc-ed77-40d6-a91d-e0914e7a1ad8").getBackupSize()); + Assert.assertEquals(2147507235L, (long) metrics.get("506760dc-ed77-40d6-a91d-e0914e7a1ad8").getDataSize()); + } + + @Test + public void testListVmRestorePointsViaVeeamAPI() { + String xmlResponse = "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 2023-11-03T16:26:12.209913Z\n" + + " i-2-4-VM\n" + + " Full\n" + + " Full\n" + + " urn:VMware:Vm:adb5423b-b578-4c26-8ab8-cde9c1faec55.vm-1036\n" + + " \n" + + "\n"; + String vmName = "i-2-4-VM"; + + wireMockRule.stubFor(get(urlMatching(".*/vmRestorePoints\\?format=Entity")) + .willReturn(aResponse() + .withHeader("content-type", "application/xml") + .withStatus(200) + .withBody(xmlResponse))); + List vmRestorePointList = client.listVmRestorePointsViaVeeamAPI(vmName); + + Assert.assertEquals(1, vmRestorePointList.size()); + Assert.assertEquals("f6d504cf-eafe-4cd2-8dfc-e9cfe2f1e977", vmRestorePointList.get(0).getId()); + Assert.assertEquals("2023-11-03 16:26:12", newDateFormat.format(vmRestorePointList.get(0).getCreated())); + Assert.assertEquals("Full", vmRestorePointList.get(0).getType()); + } + + @Test + public void testGetVeeamServerVersionAllGood() { + Pair response = new Pair(Boolean.TRUE, "12.0.0.1"); + Mockito.doReturn(response).when(mockClient).executePowerShellCommands(Mockito.anyList()); + Assert.assertEquals(12, (int) mockClient.getVeeamServerVersion()); + } + + @Test + public void testGetVeeamServerVersionWithError() { + Pair response = new Pair(Boolean.FALSE, ""); + Mockito.doReturn(response).when(mockClient).executePowerShellCommands(Mockito.anyList()); + Assert.assertEquals(0, (int) mockClient.getVeeamServerVersion()); + } + + @Test + public void testGetVeeamServerVersionWithEmptyVersion() { + Pair response = new Pair(Boolean.TRUE, ""); + Mockito.doReturn(response).when(mockClient).executePowerShellCommands(Mockito.anyList()); + Assert.assertEquals(0, (int) mockClient.getVeeamServerVersion()); + } } diff --git a/plugins/ca/root-ca/pom.xml b/plugins/ca/root-ca/pom.xml index 824d423b17d..fe1fb006302 100644 --- a/plugins/ca/root-ca/pom.xml +++ b/plugins/ca/root-ca/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManager.java b/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManager.java index fb5da50ce16..5ff036fef12 100644 --- a/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManager.java +++ b/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManager.java @@ -27,13 +27,14 @@ import java.util.Map; import javax.net.ssl.X509TrustManager; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.certificate.dao.CrlDao; import org.apache.commons.lang3.StringUtils; public final class RootCACustomTrustManager implements X509TrustManager { - private static final Logger LOG = Logger.getLogger(RootCACustomTrustManager.class); + protected Logger logger = LogManager.getLogger(getClass()); private String clientAddress = "Unknown"; private boolean authStrictness = true; @@ -71,12 +72,12 @@ public final class RootCACustomTrustManager implements X509TrustManager { builder.append("\n Issuer DN:" + certificate.getIssuerDN()); builder.append("\n Alternative Names:" + certificate.getSubjectAlternativeNames()); } - LOG.debug(builder.toString()); + logger.debug(builder.toString()); } @Override public void checkClientTrusted(final X509Certificate[] certificates, final String s) throws CertificateException { - if (LOG.isDebugEnabled()) { + if (logger.isDebugEnabled()) { printCertificateChain(certificates, s); } @@ -86,7 +87,7 @@ public final class RootCACustomTrustManager implements X509TrustManager { if (authStrictness && primaryClientCertificate == null) { throw new CertificateException("In strict auth mode, certificate(s) are expected from client:" + clientAddress); } else if (primaryClientCertificate == null) { - LOG.info("No certificate was received from client, but continuing since strict auth mode is disabled"); + logger.info("No certificate was received from client, but continuing since strict auth mode is disabled"); return; } @@ -95,7 +96,7 @@ public final class RootCACustomTrustManager implements X509TrustManager { if (serialNumber == null || crlDao.findBySerial(serialNumber) != null) { final String errorMsg = String.format("Client is using revoked certificate of serial=%x, subject=%s from address=%s", primaryClientCertificate.getSerialNumber(), primaryClientCertificate.getSubjectDN(), clientAddress); - LOG.error(errorMsg); + logger.error(errorMsg); exceptionMsg = (StringUtils.isEmpty(exceptionMsg)) ? errorMsg : (exceptionMsg + ". " + errorMsg); } @@ -105,7 +106,7 @@ public final class RootCACustomTrustManager implements X509TrustManager { } catch (final CertificateExpiredException | CertificateNotYetValidException e) { final String errorMsg = String.format("Client certificate has expired with serial=%x, subject=%s from address=%s", primaryClientCertificate.getSerialNumber(), primaryClientCertificate.getSubjectDN(), clientAddress); - LOG.error(errorMsg); + logger.error(errorMsg); if (!allowExpiredCertificate) { throw new CertificateException(errorMsg); } @@ -125,17 +126,17 @@ public final class RootCACustomTrustManager implements X509TrustManager { } if (!certMatchesOwnership) { final String errorMsg = "Certificate ownership verification failed for client: " + clientAddress; - LOG.error(errorMsg); + logger.error(errorMsg); exceptionMsg = (StringUtils.isEmpty(exceptionMsg)) ? errorMsg : (exceptionMsg + ". " + errorMsg); } if (authStrictness && StringUtils.isNotEmpty(exceptionMsg)) { throw new CertificateException(exceptionMsg); } - if (LOG.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (authStrictness) { - LOG.debug("Client/agent connection from ip=" + clientAddress + " has been validated and trusted."); + logger.debug("Client/agent connection from ip=" + clientAddress + " has been validated and trusted."); } else { - LOG.debug("Client/agent connection from ip=" + clientAddress + " accepted without certificate validation."); + logger.debug("Client/agent connection from ip=" + clientAddress + " accepted without certificate validation."); } } diff --git a/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCAProvider.java b/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCAProvider.java index 69df700cf60..d7001ce941a 100644 --- a/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCAProvider.java +++ b/plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCAProvider.java @@ -62,7 +62,6 @@ import org.apache.cloudstack.framework.config.Configurable; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.utils.security.CertUtils; import org.apache.cloudstack.utils.security.KeyStoreUtils; -import org.apache.log4j.Logger; import org.bouncycastle.asn1.pkcs.Attribute; import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; import org.bouncycastle.asn1.x509.Extension; @@ -83,7 +82,6 @@ import com.cloud.utils.net.NetUtils; import org.apache.commons.lang3.StringUtils; public final class RootCAProvider extends AdapterBase implements CAProvider, Configurable { - private static final Logger LOG = Logger.getLogger(RootCAProvider.class); public static final Integer caValidityYears = 30; public static final String caAlias = "root"; @@ -168,7 +166,7 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con final PemReader pemReader = new PemReader(new StringReader(csr)); pemObject = pemReader.readPemObject(); } catch (IOException e) { - LOG.error("Failed to read provided CSR string as a PEM object", e); + logger.error("Failed to read provided CSR string as a PEM object", e); } if (pemObject == null) { @@ -224,7 +222,7 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con try { return generateCertificate(domainNames, ipAddresses, validityDays); } catch (final CertificateException | IOException | SignatureException | NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | OperatorCreationException e) { - LOG.error("Failed to create client certificate, due to: ", e); + logger.error("Failed to create client certificate, due to: ", e); throw new CloudRuntimeException("Failed to generate certificate due to:" + e.getMessage()); } } @@ -234,7 +232,7 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con try { return generateCertificateUsingCsr(csr, domainNames, ipAddresses, validityDays); } catch (final CertificateException | IOException | SignatureException | NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | OperatorCreationException e) { - LOG.error("Failed to generate certificate from CSR: ", e); + logger.error("Failed to generate certificate from CSR: ", e); throw new CloudRuntimeException("Failed to generate certificate using CSR due to:" + e.getMessage()); } } @@ -305,16 +303,16 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con private boolean saveNewRootCAKeypair() { try { - LOG.debug("Generating root CA public/private keys"); + logger.debug("Generating root CA public/private keys"); final KeyPair keyPair = CertUtils.generateRandomKeyPair(2 * CAManager.CertKeySize.value()); if (!configDao.update(rootCAPublicKey.key(), rootCAPublicKey.category(), CertUtils.publicKeyToPem(keyPair.getPublic()))) { - LOG.error("Failed to save RootCA public key"); + logger.error("Failed to save RootCA public key"); } if (!configDao.update(rootCAPrivateKey.key(), rootCAPrivateKey.category(), CertUtils.privateKeyToPem(keyPair.getPrivate()))) { - LOG.error("Failed to save RootCA private key"); + logger.error("Failed to save RootCA private key"); } } catch (final NoSuchProviderException | NoSuchAlgorithmException | IOException e) { - LOG.error("Failed to generate/save RootCA private/public keys due to exception:", e); + logger.error("Failed to generate/save RootCA private/public keys due to exception:", e); } return loadRootCAKeyPair(); } @@ -324,16 +322,16 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con throw new CloudRuntimeException("Cannot issue self-signed root CA certificate as CA keypair is not initialized"); } try { - LOG.debug("Generating root CA certificate"); + logger.debug("Generating root CA certificate"); final X509Certificate rootCaCertificate = CertUtils.generateV3Certificate( null, caKeyPair, caKeyPair.getPublic(), rootCAIssuerDN.value(), CAManager.CertSignatureAlgorithm.value(), getCaValidityDays(), null, null); if (!configDao.update(rootCACertificate.key(), rootCACertificate.category(), CertUtils.x509CertificateToPem(rootCaCertificate))) { - LOG.error("Failed to update RootCA public/x509 certificate"); + logger.error("Failed to update RootCA public/x509 certificate"); } } catch (final CertificateException | NoSuchAlgorithmException | NoSuchProviderException | SignatureException | InvalidKeyException | OperatorCreationException | IOException e) { - LOG.error("Failed to generate RootCA certificate from private/public keys due to exception:", e); + logger.error("Failed to generate RootCA certificate from private/public keys due to exception:", e); return false; } return loadRootCACertificate(); @@ -346,7 +344,7 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con try { caKeyPair = new KeyPair(CertUtils.pemToPublicKey(rootCAPublicKey.value()), CertUtils.pemToPrivateKey(rootCAPrivateKey.value())); } catch (InvalidKeySpecException | IOException e) { - LOG.error("Failed to load saved RootCA private/public keys due to exception:", e); + logger.error("Failed to load saved RootCA private/public keys due to exception:", e); return false; } return caKeyPair.getPrivate() != null && caKeyPair.getPublic() != null; @@ -360,7 +358,7 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con caCertificate = CertUtils.pemToX509Certificate(rootCACertificate.value()); caCertificate.verify(caKeyPair.getPublic()); } catch (final IOException | CertificateException | NoSuchAlgorithmException | InvalidKeyException | SignatureException | NoSuchProviderException e) { - LOG.error("Failed to load saved RootCA certificate due to exception:", e); + logger.error("Failed to load saved RootCA certificate due to exception:", e); return false; } return caCertificate != null; @@ -379,7 +377,7 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con if (serverCertificate == null || serverCertificate.getPrivateKey() == null) { throw new CloudRuntimeException("Failed to generate management server certificate and load management server keystore"); } - LOG.info("Creating new management server certificate and keystore"); + logger.info("Creating new management server certificate and keystore"); try { managementKeyStore = KeyStore.getInstance("JKS"); managementKeyStore.load(null, null); @@ -387,7 +385,7 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con managementKeyStore.setKeyEntry(managementAlias, serverCertificate.getPrivateKey(), getKeyStorePassphrase(), new X509Certificate[]{serverCertificate.getClientCertificate(), caCertificate}); } catch (final CertificateException | NoSuchAlgorithmException | KeyStoreException | IOException e) { - LOG.error("Failed to load root CA management-server keystore due to exception: ", e); + logger.error("Failed to load root CA management-server keystore due to exception: ", e); return false; } return managementKeyStore != null; @@ -396,20 +394,20 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con protected void addConfiguredManagementIp(List ipList) { String msNetworkCidr = configDao.getValue(Config.ManagementNetwork.key()); try { - LOG.debug(String.format("Trying to find management IP in CIDR range [%s].", msNetworkCidr)); + logger.debug(String.format("Trying to find management IP in CIDR range [%s].", msNetworkCidr)); Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.asIterator().forEachRemaining(networkInterface -> { networkInterface.getInetAddresses().asIterator().forEachRemaining(inetAddress -> { if (NetUtils.isIpWithInCidrRange(inetAddress.getHostAddress(), msNetworkCidr)) { ipList.add(inetAddress.getHostAddress()); - LOG.debug(String.format("Added IP [%s] to the list of IPs in the management server's certificate.", inetAddress.getHostAddress())); + logger.debug(String.format("Added IP [%s] to the list of IPs in the management server's certificate.", inetAddress.getHostAddress())); } }); }); } catch (SocketException e) { String msg = "Exception while trying to gather the management server's network interfaces."; - LOG.error(msg, e); + logger.error(msg, e); throw new CloudRuntimeException(msg, e); } } @@ -417,15 +415,15 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con private boolean setupCA() { if (!loadRootCAKeyPair() && !saveNewRootCAKeypair()) { - LOG.error("Failed to save and load root CA keypair"); + logger.error("Failed to save and load root CA keypair"); return false; } if (!loadRootCACertificate() && !saveNewRootCACertificate()) { - LOG.error("Failed to save and load root CA certificate"); + logger.error("Failed to save and load root CA certificate"); return false; } if (!loadManagementKeyStore()) { - LOG.error("Failed to check and configure management server keystore"); + logger.error("Failed to check and configure management server keystore"); return false; } return true; @@ -449,7 +447,7 @@ public final class RootCAProvider extends AdapterBase implements CAProvider, Con caLock.unlock(); } } else { - LOG.error("Failed to grab lock and setup CA, startup method will try to load the CA certificate and keypair."); + logger.error("Failed to grab lock and setup CA, startup method will try to load the CA certificate and keypair."); } } finally { caLock.releaseRef(); diff --git a/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java b/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java index f879f056372..d4ded302332 100644 --- a/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java +++ b/plugins/ca/root-ca/src/test/java/org/apache/cloudstack/ca/provider/RootCACustomTrustManagerTest.java @@ -34,7 +34,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import com.cloud.certificate.CrlVO; import com.cloud.certificate.dao.CrlDao; diff --git a/plugins/database/mysql-ha/pom.xml b/plugins/database/mysql-ha/pom.xml index 82806f5b6d6..37a07784341 100644 --- a/plugins/database/mysql-ha/pom.xml +++ b/plugins/database/mysql-ha/pom.xml @@ -24,13 +24,13 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml - mysql - mysql-connector-java + com.mysql + mysql-connector-j provided diff --git a/plugins/database/mysql-ha/src/main/java/com/cloud/utils/db/StaticStrategy.java b/plugins/database/mysql-ha/src/main/java/com/cloud/utils/db/StaticStrategy.java index 469e58be517..a72d6968f73 100644 --- a/plugins/database/mysql-ha/src/main/java/com/cloud/utils/db/StaticStrategy.java +++ b/plugins/database/mysql-ha/src/main/java/com/cloud/utils/db/StaticStrategy.java @@ -23,7 +23,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.mysql.cj.jdbc.ConnectionImpl; import com.mysql.cj.jdbc.JdbcConnection; @@ -32,7 +33,7 @@ import com.mysql.cj.jdbc.ha.BalanceStrategy; import com.mysql.cj.jdbc.ha.LoadBalancedConnectionProxy; public class StaticStrategy implements BalanceStrategy { - private static final Logger s_logger = Logger.getLogger(StaticStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); public StaticStrategy() { } @@ -84,7 +85,7 @@ public class StaticStrategy implements BalanceStrategy { try { Thread.sleep(250); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while fail over in progres."); + logger.debug("[ignored] interrupted while fail over in progres."); } // start fresh diff --git a/plugins/database/quota/pom.xml b/plugins/database/quota/pom.xml index 129f343e867..9dada4128a5 100644 --- a/plugins/database/quota/pom.xml +++ b/plugins/database/quota/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml @@ -49,8 +49,8 @@ ${project.version} - mysql - mysql-connector-java + com.mysql + mysql-connector-j provided diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java index f4e248855fd..53d82fae604 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaBalanceCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseCmd; @@ -36,7 +35,6 @@ import org.apache.cloudstack.api.response.QuotaStatementItemResponse; @APICommand(name = "quotaBalance", responseObject = QuotaStatementItemResponse.class, description = "Create a quota balance statement", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaBalanceCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaBalanceCmd.class); @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Account Id for which statement needs to be generated") diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaConfigureEmailCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaConfigureEmailCmd.java new file mode 100644 index 00000000000..01d9ffc1529 --- /dev/null +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaConfigureEmailCmd.java @@ -0,0 +1,79 @@ +//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 org.apache.cloudstack.api.command; + +import com.cloud.utils.Pair; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.QuotaConfigureEmailResponse; +import org.apache.cloudstack.api.response.QuotaResponseBuilder; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; + +import javax.inject.Inject; + +@APICommand(name = "quotaConfigureEmail", responseObject = QuotaConfigureEmailResponse.class, description = "Configure a quota email template", since = "4.20.0.0", + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class QuotaConfigureEmailCmd extends BaseCmd { + + @Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, required = true, + description = "Account ID for which to configure quota template email or min balance") + private long accountId; + + @Parameter(name = ApiConstants.TEMPLATE_NAME, type = CommandType.STRING, description = "Quota email template name which should be configured") + private String templateName; + + @Parameter(name = ApiConstants.ENABLE, type = CommandType.BOOLEAN, description = "If the quota email template should be enabled") + private Boolean enable; + + @Parameter(name = "minbalance", type = CommandType.DOUBLE, description = "New quota account min balance") + private Double minBalance; + + @Inject + private QuotaResponseBuilder responseBuilder; + + @Override + public void execute() { + Pair result = responseBuilder.configureQuotaEmail(this); + QuotaConfigureEmailResponse quotaConfigureEmailResponse = responseBuilder.createQuotaConfigureEmailResponse(result.first(), result.second(), accountId); + quotaConfigureEmailResponse.setResponseName(getCommandName()); + this.setResponseObject(quotaConfigureEmailResponse); + } + + @Override + public long getEntityOwnerId() { + return accountId; + } + + public long getAccountId() { + return accountId; + } + + public String getTemplateName() { + return templateName; + } + + public Boolean getEnable() { + return enable; + } + + public Double getMinBalance() { + return minBalance; + } +} diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaCreditsCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaCreditsCmd.java index c47c0ad2d76..8ca29f275dd 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaCreditsCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaCreditsCmd.java @@ -29,7 +29,6 @@ import org.apache.cloudstack.api.response.QuotaCreditsResponse; import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.quota.QuotaService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -42,7 +41,6 @@ public class QuotaCreditsCmd extends BaseCmd { @Inject QuotaService _quotaService; - public static final Logger s_logger = Logger.getLogger(QuotaStatementCmd.class); @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Account Id for which quota credits need to be added") diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java index 3cca09c909e..c7f39037934 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmd.java @@ -22,13 +22,11 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.QuotaEmailTemplateResponse; import org.apache.cloudstack.api.response.QuotaResponseBuilder; -import org.apache.log4j.Logger; import javax.inject.Inject; @APICommand(name = "quotaEmailTemplateList", responseObject = QuotaEmailTemplateResponse.class, description = "Lists all quota email templates", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaEmailTemplateListCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(QuotaEmailTemplateListCmd.class); @Inject QuotaResponseBuilder _quotaResponseBuilder; diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java index 36d09864e54..17e7c220d2e 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmd.java @@ -25,14 +25,12 @@ import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.quota.constant.QuotaConfig; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.Arrays; @APICommand(name = "quotaEmailTemplateUpdate", responseObject = SuccessResponse.class, description = "Updates existing email templates for quota alerts", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaEmailTemplateUpdateCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaEmailTemplateUpdateCmd.class); @Inject QuotaResponseBuilder _quotaResponseBuilder; diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEnabledCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEnabledCmd.java index ad6f12e9cc6..4035a5205e6 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEnabledCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaEnabledCmd.java @@ -22,7 +22,6 @@ import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.response.QuotaEnabledResponse; import org.apache.cloudstack.quota.QuotaService; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -30,7 +29,6 @@ import javax.inject.Inject; @APICommand(name = "quotaIsEnabled", responseObject = QuotaEnabledResponse.class, description = "Return true if the plugin is enabled", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaEnabledCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaEnabledCmd.class); @Inject diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaListEmailConfigurationCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaListEmailConfigurationCmd.java new file mode 100644 index 00000000000..8915158461f --- /dev/null +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaListEmailConfigurationCmd.java @@ -0,0 +1,54 @@ +//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 org.apache.cloudstack.api.command; + +import com.cloud.user.Account; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.AccountResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.QuotaConfigureEmailResponse; +import org.apache.cloudstack.api.response.QuotaResponseBuilder; + +import javax.inject.Inject; + +@APICommand(name = "quotaListEmailConfiguration", responseObject = QuotaConfigureEmailResponse.class, description = "List quota email template configurations", since = "4.20.0.0", + requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) +public class QuotaListEmailConfigurationCmd extends BaseCmd { + + @Parameter(name = ApiConstants.ACCOUNT_ID, type = BaseCmd.CommandType.UUID, entityType = AccountResponse.class, required = true, + description = "Account ID for which to list quota template email configurations") + private long accountId; + + @Inject + private QuotaResponseBuilder responseBuilder; + + @Override + public void execute() { + ListResponse response = new ListResponse<>(); + response.setResponses(responseBuilder.listEmailConfiguration(accountId)); + response.setResponseName(getCommandName()); + setResponseObject(response); + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } +} diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java index 4d1c233c37a..cc02ed31d2d 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java @@ -31,14 +31,12 @@ import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.QuotaStatementItemResponse; import org.apache.cloudstack.api.response.QuotaStatementResponse; import org.apache.cloudstack.quota.vo.QuotaUsageVO; -import org.apache.log4j.Logger; import com.cloud.user.Account; @APICommand(name = "quotaStatement", responseObject = QuotaStatementItemResponse.class, description = "Create a quota statement", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaStatementCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaStatementCmd.class); @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "Optional, Account Id for which statement needs to be generated") diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java index 9236be1e0f8..a1ef9b3746a 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaSummaryCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.QuotaSummaryResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import java.util.List; @@ -36,7 +35,6 @@ import javax.inject.Inject; @APICommand(name = "quotaSummary", responseObject = QuotaSummaryResponse.class, description = "Lists balance and quota usage for all accounts", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaSummaryCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(QuotaSummaryCmd.class); @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = false, description = "Optional, Account Id for which statement needs to be generated") private String accountName; diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffCreateCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffCreateCmd.java index 2bbdb57fa7e..ef9ffc23d13 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffCreateCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffCreateCmd.java @@ -20,6 +20,7 @@ import com.cloud.user.Account; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; @@ -27,8 +28,8 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.QuotaTariffResponse; +import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.quota.vo.QuotaTariffVO; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -37,7 +38,6 @@ import java.util.Date; @APICommand(name = "quotaTariffCreate", responseObject = QuotaTariffResponse.class, description = "Creates a quota tariff for a resource.", since = "4.18.0.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class QuotaTariffCreateCmd extends BaseCmd { - protected Logger logger = Logger.getLogger(getClass()); @Inject QuotaResponseBuilder responseBuilder; @@ -70,6 +70,7 @@ public class QuotaTariffCreateCmd extends BaseCmd { @Override public void execute() { + CallContext.current().setEventDetails(String.format("Tariff: %s, description: %s, value: %s", getName(), getDescription(), getValue())); QuotaTariffVO result = responseBuilder.createQuotaTariff(this); if (result == null) { @@ -134,4 +135,8 @@ public class QuotaTariffCreateCmd extends BaseCmd { this.endDate = endDate; } + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.QuotaTariff; + } } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffDeleteCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffDeleteCmd.java index 6fd46dc487e..7810760c56e 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffDeleteCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffDeleteCmd.java @@ -21,20 +21,20 @@ import com.cloud.user.Account; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiArgValidator; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseCmd; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.QuotaTariffResponse; import org.apache.cloudstack.api.response.SuccessResponse; -import org.apache.log4j.Logger; +import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; @APICommand(name = "quotaTariffDelete", description = "Marks a quota tariff as removed.", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0.0", authorized = {RoleType.Admin}) public class QuotaTariffDeleteCmd extends BaseCmd { - protected Logger logger = Logger.getLogger(getClass()); @Inject QuotaResponseBuilder responseBuilder; @@ -49,6 +49,7 @@ public class QuotaTariffDeleteCmd extends BaseCmd { @Override public void execute() { + CallContext.current().setEventDetails(String.format("Tariff id: %s", getId())); boolean result = responseBuilder.deleteQuotaTariff(getId()); SuccessResponse response = new SuccessResponse(getCommandName()); response.setSuccess(result); @@ -60,4 +61,8 @@ public class QuotaTariffDeleteCmd extends BaseCmd { return Account.ACCOUNT_ID_SYSTEM; } + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.QuotaTariff; + } } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffListCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffListCmd.java index b79fd3d9aa8..c47fdbfa1d8 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffListCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffListCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.QuotaTariffResponse; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -38,7 +37,6 @@ import java.util.List; @APICommand(name = "quotaTariffList", responseObject = QuotaTariffResponse.class, description = "Lists all quota tariff plans", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaTariffListCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(QuotaTariffListCmd.class); @Inject QuotaResponseBuilder _responseBuilder; @@ -71,7 +69,7 @@ public class QuotaTariffListCmd extends BaseListCmd { final List responses = new ArrayList<>(); - s_logger.trace(String.format("Adding quota tariffs [%s] to response of API quotaTariffList.", ReflectionToStringBuilderUtils.reflectCollection(responses))); + logger.trace(String.format("Adding quota tariffs [%s] to response of API quotaTariffList.", ReflectionToStringBuilderUtils.reflectCollection(responses))); for (final QuotaTariffVO resource : result.first()) { responses.add(_responseBuilder.createQuotaTariffResponse(resource)); diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java index e2aad3a86f3..175500604d6 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java @@ -20,6 +20,7 @@ import com.cloud.user.Account; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiCommandResourceType; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.BaseCmd; @@ -27,8 +28,8 @@ import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.response.QuotaResponseBuilder; import org.apache.cloudstack.api.response.QuotaTariffResponse; +import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.quota.vo.QuotaTariffVO; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -37,7 +38,6 @@ import java.util.Date; @APICommand(name = "quotaTariffUpdate", responseObject = QuotaTariffResponse.class, description = "Update the tariff plan for a resource", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class QuotaTariffUpdateCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaTariffUpdateCmd.class); @Inject QuotaResponseBuilder _responseBuilder; @@ -111,6 +111,7 @@ public class QuotaTariffUpdateCmd extends BaseCmd { @Override public void execute() { + CallContext.current().setEventDetails(String.format("Tariff: %s, description: %s, value: %s", getName(), getDescription(), getValue())); final QuotaTariffVO result = _responseBuilder.updateQuotaTariffPlan(this); if (result == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update quota tariff plan"); @@ -125,4 +126,8 @@ public class QuotaTariffUpdateCmd extends BaseCmd { return Account.ACCOUNT_ID_SYSTEM; } + @Override + public ApiCommandResourceType getApiResourceType() { + return ApiCommandResourceType.QuotaTariff; + } } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaUpdateCmd.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaUpdateCmd.java index 6f0e70c66e8..986b2d4ce98 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaUpdateCmd.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaUpdateCmd.java @@ -24,7 +24,6 @@ import org.apache.cloudstack.api.response.QuotaUpdateResponse; import org.apache.cloudstack.quota.QuotaAlertManager; import org.apache.cloudstack.quota.QuotaManager; import org.apache.cloudstack.quota.QuotaStatement; -import org.apache.log4j.Logger; import java.util.Calendar; @@ -33,7 +32,6 @@ import javax.inject.Inject; @APICommand(name = "quotaUpdate", responseObject = QuotaUpdateResponse.class, description = "Update quota calculations, alerts and statements", since = "4.7.0", requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class QuotaUpdateCmd extends BaseCmd { - public static final Logger s_logger = Logger.getLogger(QuotaUpdateCmd.class); @Inject diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaConfigureEmailResponse.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaConfigureEmailResponse.java new file mode 100644 index 00000000000..4f84a2c2828 --- /dev/null +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaConfigureEmailResponse.java @@ -0,0 +1,78 @@ +//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 org.apache.cloudstack.api.response; + +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; +import org.apache.cloudstack.api.BaseResponse; + + +public class QuotaConfigureEmailResponse extends BaseResponse { + + @SerializedName("account") + @Param(description = "The configured account's id.") + private String accountId; + + @SerializedName("templatename") + @Param(description = "The template's name.") + private String templateName; + + @SerializedName("enabled") + @Param(description = "Whether the template is enabled.") + private Boolean enabled; + + @SerializedName("minbalance") + @Param(description = "The configured account's min balance.") + private Double minBalance; + + public QuotaConfigureEmailResponse() { + super("quotaconfigureemail"); + setResponseName(""); + } + + public String getAccountId() { + return accountId; + } + + public void setAccountId(String accountId) { + this.accountId = accountId; + } + + public String getTemplateName() { + return templateName; + } + + public void setTemplateName(String templateName) { + this.templateName = templateName; + } + + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public Double getMinBalance() { + return minBalance; + } + + public void setMinBalance(Double minBalance) { + this.minBalance = minBalance; + } +} diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilder.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilder.java index 36033043bcf..57aa04e00fa 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilder.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilder.java @@ -17,6 +17,7 @@ package org.apache.cloudstack.api.response; import org.apache.cloudstack.api.command.QuotaBalanceCmd; +import org.apache.cloudstack.api.command.QuotaConfigureEmailCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd; import org.apache.cloudstack.api.command.QuotaStatementCmd; @@ -24,6 +25,7 @@ import org.apache.cloudstack.api.command.QuotaTariffCreateCmd; import org.apache.cloudstack.api.command.QuotaTariffListCmd; import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.apache.cloudstack.quota.vo.QuotaUsageVO; @@ -69,4 +71,10 @@ public interface QuotaResponseBuilder { QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd); boolean deleteQuotaTariff(String quotaTariffUuid); + + Pair configureQuotaEmail(QuotaConfigureEmailCmd cmd); + + QuotaConfigureEmailResponse createQuotaConfigureEmailResponse(QuotaEmailConfigurationVO quotaEmailConfigurationVO, Double minBalance, long accountId); + + List listEmailConfiguration(long accountId); } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java index 32b49a72ae4..94897b410f4 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java @@ -34,16 +34,20 @@ import java.util.function.Consumer; import javax.inject.Inject; +import com.cloud.utils.DateUtil; import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.command.QuotaBalanceCmd; +import org.apache.cloudstack.api.command.QuotaConfigureEmailCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd; import org.apache.cloudstack.api.command.QuotaStatementCmd; import org.apache.cloudstack.api.command.QuotaTariffCreateCmd; import org.apache.cloudstack.api.command.QuotaTariffListCmd; import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd; +import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.quota.QuotaManager; +import org.apache.cloudstack.quota.QuotaManagerImpl; import org.apache.cloudstack.quota.QuotaService; import org.apache.cloudstack.quota.QuotaStatement; import org.apache.cloudstack.quota.constant.QuotaConfig; @@ -51,17 +55,20 @@ import org.apache.cloudstack.quota.constant.QuotaTypes; import org.apache.cloudstack.quota.dao.QuotaAccountDao; import org.apache.cloudstack.quota.dao.QuotaBalanceDao; import org.apache.cloudstack.quota.dao.QuotaCreditsDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDao; import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.dao.QuotaTariffDao; -import org.apache.cloudstack.quota.dao.QuotaUsageDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; +import org.apache.cloudstack.quota.dao.QuotaUsageDao; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; import org.apache.cloudstack.quota.vo.QuotaCreditsVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.apache.cloudstack.quota.vo.QuotaUsageVO; import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.domain.DomainVO; @@ -75,10 +82,12 @@ import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.utils.Pair; import com.cloud.utils.db.Filter; +import com.cloud.event.ActionEvent; +import com.cloud.event.EventTypes; @Component public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { - private static final Logger s_logger = Logger.getLogger(QuotaResponseBuilderImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject private QuotaTariffDao _quotaTariffDao; @@ -98,7 +107,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { @Inject private AccountDao _accountDao; @Inject - private QuotaAccountDao _quotaAccountDao; + private QuotaAccountDao quotaAccountDao; @Inject private DomainDao _domainDao; @Inject @@ -107,6 +116,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { private QuotaStatement _statement; @Inject private QuotaManager _quotaManager; + @Inject + private QuotaEmailConfigurationDao quotaEmailConfigurationDao; @Override public QuotaTariffResponse createQuotaTariffResponse(QuotaTariffVO tariff) { @@ -159,7 +170,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { result.add(qr); } } else { - Pair, Integer> data = _quotaAccountDao.listAllQuotaAccount(startIndex, pageSize); + Pair, Integer> data = quotaAccountDao.listAllQuotaAccount(startIndex, pageSize); count = data.second(); for (final QuotaAccountVO quotaAccount : data.first()) { AccountVO account = _accountDao.findById(quotaAccount.getId()); @@ -230,8 +241,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { // Iterate in reverse. while (li.hasPrevious()) { QuotaBalanceVO entry = li.previous(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaBalanceResponse: Entry=" + entry); + if (logger.isDebugEnabled()) { + logger.debug("createQuotaBalanceResponse: Entry=" + entry); } if (entry.getCreditsId() > 0) { li.remove(); @@ -247,8 +258,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { boolean consecutive = true; for (Iterator it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaBalanceResponse: All Credit Entry=" + entry); + if (logger.isDebugEnabled()) { + logger.debug("createQuotaBalanceResponse: All Credit Entry=" + entry); } if (entry.getCreditsId() > 0) { if (consecutive) { @@ -268,9 +279,9 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { resp.setStartDate(startDate); resp.setStartQuota(startItem.getCreditBalance()); resp.setEndDate(endDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaBalanceResponse: Start Entry=" + startItem); - s_logger.debug("createQuotaBalanceResponse: End Entry=" + endItem); + if (logger.isDebugEnabled()) { + logger.debug("createQuotaBalanceResponse: Start Entry=" + startItem); + logger.debug("createQuotaBalanceResponse: End Entry=" + endItem); } resp.setEndQuota(endItem.getCreditBalance().add(lastCredits)); } else if (quota_activity > 0) { @@ -310,8 +321,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { quotaUsage.add(dummy); } - if (s_logger.isDebugEnabled()) { - s_logger.debug( + if (logger.isDebugEnabled()) { + logger.debug( "createQuotaStatementResponse Type=" + quotaUsage.get(0).getUsageType() + " usage=" + quotaUsage.get(0).getQuotaUsed().setScale(2, RoundingMode.HALF_EVEN) + " rec.id=" + quotaUsage.get(0).getUsageItemId() + " SD=" + quotaUsage.get(0).getStartDate() + " ED=" + quotaUsage.get(0).getEndDate()); } @@ -333,8 +344,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { BigDecimal totalUsage = new BigDecimal(0); quotaUsage.add(new QuotaUsageVO());// boundary QuotaUsageVO prev = quotaUsage.get(0); - if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaStatementResponse record count=" + quotaUsage.size()); + if (logger.isDebugEnabled()) { + logger.debug("createQuotaStatementResponse record count=" + quotaUsage.size()); } for (final QuotaUsageVO quotaRecord : quotaUsage) { if (type != quotaRecord.getUsageType()) { @@ -373,13 +384,14 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { Long startIndex = cmd.getStartIndex(); Long pageSize = cmd.getPageSizeVal(); - s_logger.debug(String.format("Listing quota tariffs for parameters [%s].", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(cmd, "effectiveDate", + logger.debug(String.format("Listing quota tariffs for parameters [%s].", ReflectionToStringBuilderUtils.reflectOnlySelectedFields(cmd, "effectiveDate", "endDate", "listAll", "name", "page", "pageSize", "usageType"))); return _quotaTariffDao.listQuotaTariffs(startDate, endDate, usageType, name, null, listAll, startIndex, pageSize); } @Override + @ActionEvent(eventType = EventTypes.EVENT_QUOTA_TARIFF_UPDATE, eventDescription = "updating Quota Tariff") public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) { String name = cmd.getName(); Double value = cmd.getValue(); @@ -403,6 +415,9 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { QuotaTariffVO newQuotaTariff = persistNewQuotaTariff(currentQuotaTariff, name, 0, currentQuotaTariffStartDate, cmd.getEntityOwnerId(), endDate, value, description, activationRule); _quotaTariffDao.updateQuotaTariff(currentQuotaTariff); + + CallContext.current().setEventResourceId(newQuotaTariff.getId()); + return newQuotaTariff; } @@ -410,11 +425,11 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { String warnMessage = "The parameter 's%s' for API 'quotaTariffUpdate' is no longer needed and it will be removed in future releases."; if (cmd.getStartDate() != null) { - s_logger.warn(String.format(warnMessage,"startdate")); + logger.warn(String.format(warnMessage,"startdate")); } if (cmd.getUsageType() != null) { - s_logger.warn(String.format(warnMessage,"usagetype")); + logger.warn(String.format(warnMessage,"usagetype")); } } @@ -469,12 +484,14 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { } if (endDate.compareTo(startDate) < 0) { - throw new InvalidParameterValueException(String.format("The quota tariff's end date [%s] cannot be less than the start date [%s]", endDate, startDate)); + throw new InvalidParameterValueException(String.format("The quota tariff's end date [%s] cannot be less than the start date [%s].", + endDate, startDate)); } Date now = _quotaService.computeAdjustedTime(new Date()); if (endDate.compareTo(now) < 0) { - throw new InvalidParameterValueException(String.format("The quota tariff's end date [%s] cannot be less than now [%s].", endDate, now)); + throw new InvalidParameterValueException(String.format("The quota tariff's end date [%s] cannot be less than now [%s].", + endDate, now)); } newQuotaTariff.setEndDate(endDate); @@ -486,7 +503,8 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { QuotaBalanceVO qb = _quotaBalanceDao.findLaterBalanceEntry(accountId, domainId, despositedOn); if (qb != null) { - throw new InvalidParameterValueException("Incorrect deposit date: " + despositedOn + " there are balance entries after this date"); + throw new InvalidParameterValueException(String.format("Incorrect deposit date [%s], as there are balance entries after this date.", + despositedOn)); } QuotaCreditsVO credits = new QuotaCreditsVO(accountId, domainId, new BigDecimal(amount), updatedBy); @@ -499,20 +517,19 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { } final boolean lockAccountEnforcement = "true".equalsIgnoreCase(QuotaConfig.QuotaEnableEnforcement.value()); final BigDecimal currentAccountBalance = _quotaBalanceDao.lastQuotaBalance(accountId, domainId, startOfNextDay(new Date(despositedOn.getTime()))); - if (s_logger.isDebugEnabled()) { - s_logger.debug("AddQuotaCredits: Depositing " + amount + " on adjusted date " + despositedOn + ", current balance " + currentAccountBalance); - } + logger.debug("Depositing [{}] credits on adjusted date [{}]; current balance is [{}].", amount, + DateUtil.displayDateInTimezone(QuotaManagerImpl.getUsageAggregationTimeZone(), despositedOn), currentAccountBalance); // update quota account with the balance _quotaService.saveQuotaAccount(account, currentAccountBalance, despositedOn); if (lockAccountEnforcement) { if (currentAccountBalance.compareTo(new BigDecimal(0)) >= 0) { if (account.getState() == Account.State.LOCKED) { - s_logger.info("UnLocking account " + account.getAccountName() + " , due to positive balance " + currentAccountBalance); + logger.info("UnLocking account " + account.getAccountName() + " , due to positive balance " + currentAccountBalance); _accountMgr.enableAccount(account.getAccountName(), domainId, accountId); } } else { // currentAccountBalance < 0 then lock the account if (_quotaManager.isLockable(account) && account.getState() == Account.State.ENABLED && enforce) { - s_logger.info("Locking account " + account.getAccountName() + " , due to negative balance " + currentAccountBalance); + logger.info("Locking account " + account.getAccountName() + " , due to negative balance " + currentAccountBalance); _accountMgr.lockAccount(account.getAccountName(), domainId, accountId); } } @@ -580,9 +597,10 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { QuotaBalanceResponse resp = new QuotaBalanceResponse(); BigDecimal lastCredits = new BigDecimal(0); for (QuotaBalanceVO entry : quotaBalance) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("createQuotaLastBalanceResponse Date=" + entry.getUpdatedOn() + " balance=" + entry.getCreditBalance() + " credit=" + entry.getCreditsId()); - } + logger.debug("createQuotaLastBalanceResponse Date={} balance={} credit={}", + DateUtil.displayDateInTimezone(QuotaManagerImpl.getUsageAggregationTimeZone(), entry.getUpdatedOn()), + entry.getCreditBalance(), entry.getCreditsId()); + lastCredits = lastCredits.add(entry.getCreditBalance()); } resp.setStartQuota(lastCredits); @@ -619,6 +637,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { } @Override + @ActionEvent(eventType = EventTypes.EVENT_QUOTA_TARIFF_CREATE, eventDescription = "creating Quota Tariff") public QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd) { String name = cmd.getName(); int usageType = cmd.getUsageType(); @@ -637,12 +656,18 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { } if (startDate.compareTo(now) < 0) { - throw new InvalidParameterValueException(String.format("The quota tariff's start date [%s] cannot be less than now [%s]", startDate, now)); + throw new InvalidParameterValueException(String.format("The value passed as Quota tariff's start date is in the past: [%s]. " + + "Please, inform a date in the future or do not pass the parameter to use the current date and time.", startDate)); } - return persistNewQuotaTariff(null, name, usageType, startDate, cmd.getEntityOwnerId(), endDate, value, description, activationRule); + QuotaTariffVO newQuotaTariff = persistNewQuotaTariff(null, name, usageType, startDate, cmd.getEntityOwnerId(), endDate, value, description, activationRule); + + CallContext.current().setEventResourceId(newQuotaTariff.getId()); + + return newQuotaTariff; } + @ActionEvent(eventType = EventTypes.EVENT_QUOTA_TARIFF_DELETE, eventDescription = "removing Quota Tariff") public boolean deleteQuotaTariff(String quotaTariffUuid) { QuotaTariffVO quotaTariff = _quotaTariffDao.findByUuid(quotaTariffUuid); @@ -651,6 +676,104 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { } quotaTariff.setRemoved(_quotaService.computeAdjustedTime(new Date())); + + CallContext.current().setEventResourceId(quotaTariff.getId()); + return _quotaTariffDao.updateQuotaTariff(quotaTariff); } + + @Override + public Pair configureQuotaEmail(QuotaConfigureEmailCmd cmd) { + validateQuotaConfigureEmailCmdParameters(cmd); + + Double minBalance = cmd.getMinBalance(); + + if (minBalance != null) { + _quotaService.setMinBalance(cmd.getAccountId(), cmd.getMinBalance()); + } + + QuotaEmailConfigurationVO configurationVO = getQuotaEmailConfigurationVo(cmd); + return new Pair<>(configurationVO, minBalance); + } + + protected QuotaEmailConfigurationVO getQuotaEmailConfigurationVo(QuotaConfigureEmailCmd cmd) { + if (cmd.getTemplateName() == null) { + return null; + } + + List templateVO = _quotaEmailTemplateDao.listAllQuotaEmailTemplates(cmd.getTemplateName()); + if (templateVO.isEmpty()) { + throw new InvalidParameterValueException(String.format("Could not find template with name [%s].", cmd.getTemplateName())); + } + long templateId = templateVO.get(0).getId(); + QuotaEmailConfigurationVO configurationVO = quotaEmailConfigurationDao.findByAccountIdAndEmailTemplateId(cmd.getAccountId(), templateId); + + if (configurationVO == null) { + configurationVO = new QuotaEmailConfigurationVO(cmd.getAccountId(), templateId, cmd.getEnable()); + quotaEmailConfigurationDao.persistQuotaEmailConfiguration(configurationVO); + return configurationVO; + } + + configurationVO.setEnabled(cmd.getEnable()); + return quotaEmailConfigurationDao.updateQuotaEmailConfiguration(configurationVO); + } + + protected void validateQuotaConfigureEmailCmdParameters(QuotaConfigureEmailCmd cmd) { + if (quotaAccountDao.findByIdQuotaAccount(cmd.getAccountId()) == null) { + throw new InvalidParameterValueException("You must have the quota enabled for this account to configure quota emails."); + } + + if (cmd.getTemplateName() == null && cmd.getMinBalance() == null) { + throw new InvalidParameterValueException("You should inform at least the 'minbalance' or both the 'templatename' and 'enable' parameters."); + } + + if ((cmd.getTemplateName() != null && cmd.getEnable() == null) || (cmd.getTemplateName() == null && cmd.getEnable() != null)) { + throw new InvalidParameterValueException("Parameter 'enable' must be informed along with 'templatename'."); + } + } + + public QuotaConfigureEmailResponse createQuotaConfigureEmailResponse(QuotaEmailConfigurationVO quotaEmailConfigurationVO, Double minBalance, long accountId) { + QuotaConfigureEmailResponse quotaConfigureEmailResponse = new QuotaConfigureEmailResponse(); + + Account account = _accountDao.findByIdIncludingRemoved(accountId); + if (quotaEmailConfigurationVO != null) { + QuotaEmailTemplatesVO templateVO = _quotaEmailTemplateDao.findById(quotaEmailConfigurationVO.getEmailTemplateId()); + + quotaConfigureEmailResponse.setAccountId(account.getUuid()); + quotaConfigureEmailResponse.setTemplateName(templateVO.getTemplateName()); + quotaConfigureEmailResponse.setEnabled(quotaEmailConfigurationVO.isEnabled()); + } + + quotaConfigureEmailResponse.setMinBalance(minBalance); + + return quotaConfigureEmailResponse; + } + + @Override + public List listEmailConfiguration(long accountId) { + List emailConfigurationVOList = quotaEmailConfigurationDao.listByAccount(accountId); + Account account = _accountDao.findById(accountId); + QuotaAccountVO quotaAccountVO = quotaAccountDao.findByIdQuotaAccount(accountId); + + List quotaConfigureEmailResponseList = new ArrayList<>(); + for (QuotaEmailConfigurationVO quotaEmailConfigurationVO : emailConfigurationVOList) { + quotaConfigureEmailResponseList.add(createQuotaConfigureEmailResponse(quotaEmailConfigurationVO, account, quotaAccountVO)); + } + + return quotaConfigureEmailResponseList; + } + + protected QuotaConfigureEmailResponse createQuotaConfigureEmailResponse(QuotaEmailConfigurationVO quotaEmailConfigurationVO, Account account, QuotaAccountVO quotaAccountVO) { + QuotaConfigureEmailResponse quotaConfigureEmailResponse = new QuotaConfigureEmailResponse(); + + QuotaEmailTemplatesVO templateVO = _quotaEmailTemplateDao.findById(quotaEmailConfigurationVO.getEmailTemplateId()); + + quotaConfigureEmailResponse.setAccountId(account.getUuid()); + quotaConfigureEmailResponse.setTemplateName(templateVO.getTemplateName()); + quotaConfigureEmailResponse.setEnabled(quotaEmailConfigurationVO.isEnabled()); + + quotaConfigureEmailResponse.setMinBalance(quotaAccountVO.getQuotaMinBalance().doubleValue()); + + return quotaConfigureEmailResponse; + } } diff --git a/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java b/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java index 9179691e973..da3f50b165a 100644 --- a/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java +++ b/plugins/database/quota/src/main/java/org/apache/cloudstack/quota/QuotaServiceImpl.java @@ -28,10 +28,12 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.cloudstack.api.command.QuotaBalanceCmd; +import org.apache.cloudstack.api.command.QuotaConfigureEmailCmd; import org.apache.cloudstack.api.command.QuotaCreditsCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd; import org.apache.cloudstack.api.command.QuotaEnabledCmd; +import org.apache.cloudstack.api.command.QuotaListEmailConfigurationCmd; import org.apache.cloudstack.api.command.QuotaStatementCmd; import org.apache.cloudstack.api.command.QuotaSummaryCmd; import org.apache.cloudstack.api.command.QuotaTariffCreateCmd; @@ -51,8 +53,7 @@ import org.apache.cloudstack.quota.dao.QuotaUsageDao; import org.apache.cloudstack.quota.vo.QuotaAccountVO; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; import org.apache.cloudstack.quota.vo.QuotaUsageVO; -import org.apache.cloudstack.utils.usage.UsageUtils; -import org.apache.log4j.Logger; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Component; import com.cloud.configuration.Config; @@ -67,7 +68,6 @@ import com.cloud.utils.db.Filter; @Component public class QuotaServiceImpl extends ManagerBase implements QuotaService, Configurable, QuotaConfig { - private static final Logger s_logger = Logger.getLogger(QuotaServiceImpl.class); @Inject private AccountDao _accountDao; @@ -85,7 +85,6 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi private QuotaResponseBuilder _respBldr; private TimeZone _usageTimezone; - private int _aggregationDuration = 0; public QuotaServiceImpl() { super(); @@ -94,21 +93,10 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi @Override public boolean configure(String name, Map params) throws ConfigurationException { super.configure(name, params); - String timeZoneStr = _configDao.getValue(Config.UsageAggregationTimezone.toString()); - String aggregationRange = _configDao.getValue(Config.UsageStatsJobAggregationRange.toString()); - if (timeZoneStr == null) { - timeZoneStr = "GMT"; - } + + String timeZoneStr = ObjectUtils.defaultIfNull(_configDao.getValue(Config.UsageAggregationTimezone.toString()), "GMT"); _usageTimezone = TimeZone.getTimeZone(timeZoneStr); - _aggregationDuration = Integer.parseInt(aggregationRange); - if (_aggregationDuration < UsageUtils.USAGE_AGGREGATION_RANGE_MIN) { - s_logger.warn("Usage stats job aggregation range is to small, using the minimum value of " + UsageUtils.USAGE_AGGREGATION_RANGE_MIN); - _aggregationDuration = UsageUtils.USAGE_AGGREGATION_RANGE_MIN; - } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Usage timezone = " + _usageTimezone + " AggregationDuration=" + _aggregationDuration); - } return true; } @@ -130,6 +118,8 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi cmdList.add(QuotaEmailTemplateUpdateCmd.class); cmdList.add(QuotaTariffCreateCmd.class); cmdList.add(QuotaTariffDeleteCmd.class); + cmdList.add(QuotaConfigureEmailCmd.class); + cmdList.add(QuotaListEmailConfigurationCmd.class); return cmdList; } @@ -142,7 +132,7 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi public ConfigKey[] getConfigKeys() { return new ConfigKey[] {QuotaPluginEnabled, QuotaEnableEnforcement, QuotaCurrencySymbol, QuotaCurrencyLocale, QuotaStatementPeriod, QuotaSmtpHost, QuotaSmtpPort, QuotaSmtpTimeout, QuotaSmtpUser, QuotaSmtpPassword, QuotaSmtpAuthType, QuotaSmtpSender, QuotaSmtpEnabledSecurityProtocols, QuotaSmtpUseStartTLS, QuotaActivationRuleTimeout, QuotaAccountEnabled, - QuotaEmailHeader, QuotaEmailFooter}; + QuotaEmailHeader, QuotaEmailFooter, QuotaEnableEmails}; } @Override @@ -176,15 +166,15 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi if (endDate == null) { // adjust start date to end of day as there is no end date Date adjustedStartDate = computeAdjustedTime(_respBldr.startOfNextDay(startDate)); - if (s_logger.isDebugEnabled()) { - s_logger.debug("getQuotaBalance1: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", on or before " + adjustedStartDate); + if (logger.isDebugEnabled()) { + logger.debug("getQuotaBalance1: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", on or before " + adjustedStartDate); } List qbrecords = _quotaBalanceDao.lastQuotaBalanceVO(accountId, domainId, adjustedStartDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found records size=" + qbrecords.size()); + if (logger.isDebugEnabled()) { + logger.debug("Found records size=" + qbrecords.size()); } if (qbrecords.isEmpty()) { - s_logger.info("Incorrect Date there are no quota records before this date " + adjustedStartDate); + logger.info("Incorrect Date there are no quota records before this date " + adjustedStartDate); return qbrecords; } else { return qbrecords; @@ -195,16 +185,16 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi throw new InvalidParameterValueException("Incorrect Date Range. End date:" + endDate + " should not be in future. "); } else if (startDate.before(endDate)) { Date adjustedEndDate = computeAdjustedTime(endDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("getQuotaBalance2: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate + if (logger.isDebugEnabled()) { + logger.debug("getQuotaBalance2: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate + " and " + adjustedEndDate); } List qbrecords = _quotaBalanceDao.findQuotaBalance(accountId, domainId, adjustedStartDate, adjustedEndDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("getQuotaBalance3: Found records size=" + qbrecords.size()); + if (logger.isDebugEnabled()) { + logger.debug("getQuotaBalance3: Found records size=" + qbrecords.size()); } if (qbrecords.isEmpty()) { - s_logger.info("There are no quota records between these dates start date " + adjustedStartDate + " and end date:" + endDate); + logger.info("There are no quota records between these dates start date " + adjustedStartDate + " and end date:" + endDate); return qbrecords; } else { return qbrecords; @@ -245,8 +235,8 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi } Date adjustedEndDate = computeAdjustedTime(endDate); Date adjustedStartDate = computeAdjustedTime(startDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Getting quota records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate + " and " + adjustedEndDate); + if (logger.isDebugEnabled()) { + logger.debug("Getting quota records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate + " and " + adjustedEndDate); } return _quotaUsageDao.findQuotaUsage(accountId, domainId, usageType, adjustedStartDate, adjustedEndDate); } @@ -302,16 +292,16 @@ public class QuotaServiceImpl extends ManagerBase implements QuotaService, Confi quota_account = new QuotaAccountVO(account.getAccountId()); quota_account.setQuotaBalance(aggrUsage); quota_account.setQuotaBalanceDate(endDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug(quota_account); + if (logger.isDebugEnabled()) { + logger.debug(quota_account); } _quotaAcc.persistQuotaAccount(quota_account); return true; } else { quota_account.setQuotaBalance(aggrUsage); quota_account.setQuotaBalanceDate(endDate); - if (s_logger.isDebugEnabled()) { - s_logger.debug(quota_account); + if (logger.isDebugEnabled()) { + logger.debug(quota_account); } return _quotaAcc.updateQuotaAccount(account.getAccountId(), quota_account); } diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java index 1fdb2956f30..adabc694f25 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaBalanceCmdTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import junit.framework.TestCase; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java index c66ac6b89c1..1a73fcd7506 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateListCmdTest.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.util.ArrayList; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java index a357a181c38..de0220edfa0 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaEmailTemplateUpdateCmdTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java index 0492ae84b8d..d6f9f747fa8 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaStatementCmdTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.util.ArrayList; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java index e57109c4761..f5ce92ae014 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffListCmdTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.math.BigDecimal; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java index 0cb1799ec10..22d78d6794e 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmdTest.java @@ -27,7 +27,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import java.lang.reflect.Field; import java.math.BigDecimal; diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java index b960a1be569..899ce649fce 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java @@ -30,6 +30,7 @@ import java.util.function.Consumer; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; import org.apache.cloudstack.api.ServerApiException; +import org.apache.cloudstack.api.command.QuotaConfigureEmailCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateListCmd; import org.apache.cloudstack.api.command.QuotaEmailTemplateUpdateCmd; import org.apache.cloudstack.framework.config.ConfigKey; @@ -37,13 +38,17 @@ import org.apache.cloudstack.quota.QuotaService; import org.apache.cloudstack.quota.QuotaStatement; import org.apache.cloudstack.quota.constant.QuotaConfig; import org.apache.cloudstack.quota.constant.QuotaTypes; +import org.apache.cloudstack.quota.dao.QuotaAccountDao; import org.apache.cloudstack.quota.dao.QuotaBalanceDao; import org.apache.cloudstack.quota.dao.QuotaCreditsDao; +import org.apache.cloudstack.quota.dao.QuotaEmailConfigurationDao; import org.apache.cloudstack.quota.dao.QuotaEmailTemplatesDao; import org.apache.cloudstack.quota.dao.QuotaTariffDao; import org.apache.cloudstack.quota.dao.QuotaUsageDao; +import org.apache.cloudstack.quota.vo.QuotaAccountVO; import org.apache.cloudstack.quota.vo.QuotaBalanceVO; import org.apache.cloudstack.quota.vo.QuotaCreditsVO; +import org.apache.cloudstack.quota.vo.QuotaEmailConfigurationVO; import org.apache.cloudstack.quota.vo.QuotaEmailTemplatesVO; import org.apache.cloudstack.quota.vo.QuotaTariffVO; import org.apache.commons.lang3.time.DateUtils; @@ -103,6 +108,12 @@ public class QuotaResponseBuilderImplTest extends TestCase { @Mock QuotaUsageDao quotaUsageDaoMock; + @Mock + QuotaAccountDao quotaAccountDaoMock; + + @Mock + QuotaEmailConfigurationDao quotaEmailConfigurationDaoMock; + @InjectMocks QuotaResponseBuilderImpl quotaResponseBuilderSpy = Mockito.spy(QuotaResponseBuilderImpl.class); @@ -114,6 +125,15 @@ public class QuotaResponseBuilderImplTest extends TestCase { @Mock DomainVO domainVOMock; + @Mock + QuotaConfigureEmailCmd quotaConfigureEmailCmdMock; + + @Mock + QuotaAccountVO quotaAccountVOMock; + + @Mock + QuotaEmailTemplatesVO quotaEmailTemplatesVoMock; + private void overrideDefaultQuotaEnabledConfigValue(final Object value) throws IllegalAccessException, NoSuchFieldException { Field f = ConfigKey.class.getDeclaredField("_defaultValue"); f.setAccessible(true); @@ -403,4 +423,96 @@ public class QuotaResponseBuilderImplTest extends TestCase { assertTrue(quotaSummaryResponse.getQuotaEnabled()); } + + + @Test (expected = InvalidParameterValueException.class) + public void validateQuotaConfigureEmailCmdParametersTestNullQuotaAccount() { + Mockito.doReturn(null).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + @Test (expected = InvalidParameterValueException.class) + public void validateQuotaConfigureEmailCmdParametersTestNullTemplateNameAndMinBalance() { + Mockito.doReturn(quotaAccountVOMock).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getMinBalance(); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + @Test (expected = InvalidParameterValueException.class) + public void validateQuotaConfigureEmailCmdParametersTestEnableNullAndTemplateNameNotNull() { + Mockito.doReturn(quotaAccountVOMock).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + Mockito.doReturn(QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW.toString()).when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getEnable(); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + + @Test + public void validateQuotaConfigureEmailCmdParametersTestNullTemplateName() { + Mockito.doReturn(quotaAccountVOMock).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getEnable(); + Mockito.doReturn(100D).when(quotaConfigureEmailCmdMock).getMinBalance(); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + @Test + public void validateQuotaConfigureEmailCmdParametersTestWithTemplateNameAndEnable() { + Mockito.doReturn(quotaAccountVOMock).when(quotaAccountDaoMock).findByIdQuotaAccount(Mockito.any()); + Mockito.doReturn(QuotaConfig.QuotaEmailTemplateTypes.QUOTA_LOW.toString()).when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(true).when(quotaConfigureEmailCmdMock).getEnable(); + quotaResponseBuilderSpy.validateQuotaConfigureEmailCmdParameters(quotaConfigureEmailCmdMock); + } + + @Test + public void getQuotaEmailConfigurationVoTestTemplateNameIsNull() { + Mockito.doReturn(null).when(quotaConfigureEmailCmdMock).getTemplateName(); + + QuotaEmailConfigurationVO result = quotaResponseBuilderSpy.getQuotaEmailConfigurationVo(quotaConfigureEmailCmdMock); + + Assert.assertNull(result); + } + + @Test (expected = InvalidParameterValueException.class) + public void getQuotaEmailConfigurationVoTestNoTemplateFound() { + Mockito.doReturn("name").when(quotaConfigureEmailCmdMock).getTemplateName(); + Mockito.doReturn(new ArrayList()).when(quotaEmailTemplateDaoMock).listAllQuotaEmailTemplates(Mockito.any()); + + quotaResponseBuilderSpy.getQuotaEmailConfigurationVo(quotaConfigureEmailCmdMock); + } + + @Test + public void getQuotaEmailConfigurationVoTestNewConfiguration() { + Mockito.doReturn("name").when(quotaConfigureEmailCmdMock).getTemplateName(); + List templatesVOArrayList = List.of(quotaEmailTemplatesVoMock); + Mockito.doReturn(templatesVOArrayList).when(quotaEmailTemplateDaoMock).listAllQuotaEmailTemplates(Mockito.any()); + Mockito.doReturn(null).when(quotaEmailConfigurationDaoMock).findByAccountIdAndEmailTemplateId(Mockito.anyLong(), Mockito.anyLong()); + + QuotaEmailConfigurationVO result = quotaResponseBuilderSpy.getQuotaEmailConfigurationVo(quotaConfigureEmailCmdMock); + + Mockito.verify(quotaEmailConfigurationDaoMock).persistQuotaEmailConfiguration(Mockito.any()); + assertEquals(0, result.getAccountId()); + assertEquals(0, result.getEmailTemplateId()); + assertFalse(result.isEnabled()); + } + + @Test + public void getQuotaEmailConfigurationVoTestExistingConfiguration() { + Mockito.doReturn("name").when(quotaConfigureEmailCmdMock).getTemplateName(); + List templatesVOArrayList = List.of(quotaEmailTemplatesVoMock); + Mockito.doReturn(templatesVOArrayList).when(quotaEmailTemplateDaoMock).listAllQuotaEmailTemplates(Mockito.any()); + + QuotaEmailConfigurationVO quotaEmailConfigurationVO = new QuotaEmailConfigurationVO(1, 2, true); + Mockito.doReturn(quotaEmailConfigurationVO).when(quotaEmailConfigurationDaoMock).findByAccountIdAndEmailTemplateId(Mockito.anyLong(), Mockito.anyLong()); + Mockito.doReturn(quotaEmailConfigurationVO).when(quotaEmailConfigurationDaoMock).updateQuotaEmailConfiguration(Mockito.any()); + + QuotaEmailConfigurationVO result = quotaResponseBuilderSpy.getQuotaEmailConfigurationVo(quotaConfigureEmailCmdMock); + + Mockito.verify(quotaEmailConfigurationDaoMock).updateQuotaEmailConfiguration(Mockito.any()); + + assertEquals(1, result.getAccountId()); + assertEquals(2, result.getEmailTemplateId()); + assertFalse(result.isEnabled()); + } } diff --git a/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java b/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java index 310e9ced72f..fa58c35ea5d 100644 --- a/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java +++ b/plugins/database/quota/src/test/java/org/apache/cloudstack/quota/QuotaServiceImplTest.java @@ -36,7 +36,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import javax.naming.ConfigurationException; import java.lang.reflect.Field; @@ -99,7 +99,6 @@ public class QuotaServiceImplTest extends TestCase { QuotaResponseBuilderField.set(quotaService, respBldr); Mockito.when(configDao.getValue(Mockito.eq(Config.UsageAggregationTimezone.toString()))).thenReturn("IST"); - Mockito.when(configDao.getValue(Mockito.eq(Config.UsageStatsJobAggregationRange.toString()))).thenReturn("1"); quotaService.configure("randomName", null); } diff --git a/plugins/database/quota/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/plugins/database/quota/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker deleted file mode 100644 index 1f0955d450f..00000000000 --- a/plugins/database/quota/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker +++ /dev/null @@ -1 +0,0 @@ -mock-maker-inline diff --git a/plugins/dedicated-resources/pom.xml b/plugins/dedicated-resources/pom.xml index 084e8fdf378..5aeecec818d 100644 --- a/plugins/dedicated-resources/pom.xml +++ b/plugins/dedicated-resources/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../pom.xml diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateClusterCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateClusterCmd.java index 06e0a42df85..5ab1ba73fce 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateClusterCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateClusterCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "dedicateCluster", description = "Dedicate an existing cluster", responseObject = DedicateClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicateClusterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DedicateClusterCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateHostCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateHostCmd.java index cf6c5872fdd..6fb379f4a87 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateHostCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateHostCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "dedicateHost", description = "Dedicates a host.", responseObject = DedicateHostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicateHostCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DedicateHostCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicatePodCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicatePodCmd.java index 819c4106af5..2b5e9afab88 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicatePodCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicatePodCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "dedicatePod", description = "Dedicates a Pod.", responseObject = DedicatePodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicatePodCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DedicatePodCmd.class.getName()); @Inject public DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateZoneCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateZoneCmd.java index c3ce1d3baec..ea91ea5a661 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateZoneCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/DedicateZoneCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -42,7 +41,6 @@ import com.cloud.user.Account; @APICommand(name = "dedicateZone", description = "Dedicates a zones.", responseObject = DedicateZoneResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class DedicateZoneCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DedicateZoneCmd.class.getName()); @Inject public DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedClustersCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedClustersCmd.java index c91e4470763..efdee15ff19 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedClustersCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedClustersCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listDedicatedClusters", description = "Lists dedicated clusters.", responseObject = DedicateClusterResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedClustersCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedClustersCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedHostsCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedHostsCmd.java index fd27662dded..b60509f6b66 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedHostsCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedHostsCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listDedicatedHosts", description = "Lists dedicated hosts.", responseObject = DedicateHostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedHostsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedHostsCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedPodsCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedPodsCmd.java index 742c5cc96ea..06eaefe3298 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedPodsCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedPodsCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listDedicatedPods", description = "Lists dedicated pods.", responseObject = DedicatePodResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedPodsCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedPodsCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedZonesCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedZonesCmd.java index b8874eab7cd..c5bc5456f79 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedZonesCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ListDedicatedZonesCmd.java @@ -21,7 +21,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.api.APICommand; @@ -43,7 +42,6 @@ import com.cloud.utils.Pair; @APICommand(name = "listDedicatedZones", description = "List dedicated zones.", responseObject = DedicateZoneResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListDedicatedZonesCmd extends BaseListCmd { - public static final Logger s_logger = Logger.getLogger(ListDedicatedZonesCmd.class.getName()); @Inject DedicatedService _dedicatedservice; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedClusterCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedClusterCmd.java index 9945ba29ca1..af153e499e9 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedClusterCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedClusterCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.commands; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "releaseDedicatedCluster", description = "Release the dedication for cluster", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedClusterCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedClusterCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedHostCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedHostCmd.java index 22563503061..81eff262fbc 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedHostCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedHostCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.commands; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "releaseDedicatedHost", description = "Release the dedication for host", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedHostCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedHostCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedPodCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedPodCmd.java index ec47a430340..5f7dadc993f 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedPodCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedPodCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.commands; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "releaseDedicatedPod", description = "Release the dedication for the pod", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedPodCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedPodCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedZoneCmd.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedZoneCmd.java index 4b15ddf951c..cc178d992f2 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedZoneCmd.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/api/commands/ReleaseDedicatedZoneCmd.java @@ -18,7 +18,6 @@ package org.apache.cloudstack.api.commands; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.ApiConstants; @@ -36,7 +35,6 @@ import com.cloud.user.Account; @APICommand(name = "releaseDedicatedZone", description = "Release dedication of zone", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ReleaseDedicatedZoneCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(ReleaseDedicatedZoneCmd.class.getName()); @Inject DedicatedService dedicatedService; diff --git a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java index cd6d8cf590d..9060eccb64a 100644 --- a/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java +++ b/plugins/dedicated-resources/src/main/java/org/apache/cloudstack/dedicated/DedicatedResourceManagerImpl.java @@ -44,7 +44,8 @@ import org.apache.cloudstack.api.response.DedicatePodResponse; import org.apache.cloudstack.api.response.DedicateZoneResponse; import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.configuration.Config; @@ -84,7 +85,7 @@ import com.cloud.vm.dao.UserVmDao; @Component public class DedicatedResourceManagerImpl implements DedicatedService { - private static final Logger s_logger = Logger.getLogger(DedicatedResourceManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject AccountDao _accountDao; @@ -140,7 +141,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { DedicatedResourceVO dedicatedZone = _dedicatedDao.findByZoneId(zoneId); //check if zone is dedicated if (dedicatedZone != null) { - s_logger.error("Zone " + dc.getName() + " is already dedicated"); + logger.error("Zone " + dc.getName() + " is already dedicated"); throw new CloudRuntimeException("Zone " + dc.getName() + " is already dedicated"); } @@ -159,7 +160,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dPod.getAccountId().equals(accountId)) { podsToRelease.add(dPod); } else { - s_logger.error("Pod " + pod.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); + logger.error("Pod " + pod.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Pod " + pod.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); } } else { @@ -185,7 +186,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dCluster.getAccountId().equals(accountId)) { clustersToRelease.add(dCluster); } else { - s_logger.error("Cluster " + cluster.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); + logger.error("Cluster " + cluster.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); } @@ -212,7 +213,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dHost.getAccountId().equals(accountId)) { hostsToRelease.add(dHost); } else { - s_logger.error("Host " + host.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); + logger.error("Host " + host.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Host " + host.getName() + " under this Zone " + dc.getName() + " is dedicated to different account/domain"); } } else { @@ -237,7 +238,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { // find or create the affinity group by name under this account/domain AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); if (group == null) { - s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); + logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); } @@ -256,7 +257,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { } } catch (Exception e) { - s_logger.error("Unable to dedicate zone due to " + e.getMessage(), e); + logger.error("Unable to dedicate zone due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); } @@ -290,7 +291,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { DedicatedResourceVO dedicatedZoneOfPod = _dedicatedDao.findByZoneId(pod.getDataCenterId()); //check if pod is dedicated if (dedicatedPod != null) { - s_logger.error("Pod " + pod.getName() + " is already dedicated"); + logger.error("Pod " + pod.getName() + " is already dedicated"); throw new CloudRuntimeException("Pod " + pod.getName() + " is already dedicated"); } @@ -300,7 +301,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dedicatedZoneOfPod.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfPod.getDomainId().equals(domainId) || domainIdInChildreanList))) { DataCenterVO zone = _zoneDao.findById(pod.getDataCenterId()); - s_logger.error("Cannot dedicate Pod. Its zone is already dedicated"); + logger.error("Cannot dedicate Pod. Its zone is already dedicated"); throw new CloudRuntimeException("Pod's Zone " + zone.getName() + " is already dedicated"); } } @@ -321,7 +322,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dCluster.getAccountId().equals(accountId)) { clustersToRelease.add(dCluster); } else { - s_logger.error("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); + logger.error("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Cluster " + cluster.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); } @@ -348,7 +349,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dHost.getAccountId().equals(accountId)) { hostsToRelease.add(dHost); } else { - s_logger.error("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); + logger.error("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); throw new CloudRuntimeException("Host " + host.getName() + " under this Pod " + pod.getName() + " is dedicated to different account/domain"); } } else { @@ -373,7 +374,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { // find or create the affinity group by name under this account/domain AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); if (group == null) { - s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); + logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); } DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, podId, null, null, null, null, group.getId()); @@ -384,7 +385,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { } dedicatedResource = _dedicatedDao.persist(dedicatedResource); } catch (Exception e) { - s_logger.error("Unable to dedicate pod due to " + e.getMessage(), e); + logger.error("Unable to dedicate pod due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate pod. Please contact Cloud Support."); } @@ -419,7 +420,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { //check if cluster is dedicated if (dedicatedCluster != null) { - s_logger.error("Cluster " + cluster.getName() + " is already dedicated"); + logger.error("Cluster " + cluster.getName() + " is already dedicated"); throw new CloudRuntimeException("Cluster " + cluster.getName() + " is already dedicated"); } @@ -428,7 +429,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { //can dedicate a cluster to an account/domain if pod is dedicated to parent-domain if (dedicatedPodOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) { - s_logger.error("Cannot dedicate Cluster. Its Pod is already dedicated"); + logger.error("Cannot dedicate Cluster. Its Pod is already dedicated"); HostPodVO pod = _podDao.findById(cluster.getPodId()); throw new CloudRuntimeException("Cluster's Pod " + pod.getName() + " is already dedicated"); } @@ -439,7 +440,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { //can dedicate a cluster to an account/domain if zone is dedicated to parent-domain if (dedicatedZoneOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) { - s_logger.error("Cannot dedicate Cluster. Its zone is already dedicated"); + logger.error("Cannot dedicate Cluster. Its zone is already dedicated"); DataCenterVO zone = _zoneDao.findById(cluster.getDataCenterId()); throw new CloudRuntimeException("Cluster's Zone " + zone.getName() + " is already dedicated"); } @@ -461,7 +462,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dHost.getAccountId().equals(accountId)) { hostsToRelease.add(dHost); } else { - s_logger.error("Cannot dedicate Cluster " + cluster.getName() + " to account" + accountName); + logger.error("Cannot dedicate Cluster " + cluster.getName() + " to account" + accountName); throw new CloudRuntimeException("Cannot dedicate Cluster " + cluster.getName() + " to account" + accountName); } } else { @@ -486,7 +487,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { // find or create the affinity group by name under this account/domain AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); if (group == null) { - s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); + logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); } DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, null, clusterId, null, null, null, group.getId()); @@ -497,7 +498,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { } dedicatedResource = _dedicatedDao.persist(dedicatedResource); } catch (Exception e) { - s_logger.error("Unable to dedicate cluster due to " + e.getMessage(), e); + logger.error("Unable to dedicate cluster due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate cluster. Please contact Cloud Support.", e); } @@ -534,7 +535,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { DedicatedResourceVO dedicatedZoneOfHost = _dedicatedDao.findByZoneId(host.getDataCenterId()); if (dedicatedHost != null) { - s_logger.error("Host " + host.getName() + " is already dedicated"); + logger.error("Host " + host.getName() + " is already dedicated"); throw new CloudRuntimeException("Host " + host.getName() + " is already dedicated"); } @@ -544,7 +545,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dedicatedClusterOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedClusterOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) { ClusterVO cluster = _clusterDao.findById(host.getClusterId()); - s_logger.error("Host's Cluster " + cluster.getName() + " is already dedicated"); + logger.error("Host's Cluster " + cluster.getName() + " is already dedicated"); throw new CloudRuntimeException("Host's Cluster " + cluster.getName() + " is already dedicated"); } } @@ -555,7 +556,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dedicatedPodOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) { HostPodVO pod = _podDao.findById(host.getPodId()); - s_logger.error("Host's Pod " + pod.getName() + " is already dedicated"); + logger.error("Host's Pod " + pod.getName() + " is already dedicated"); throw new CloudRuntimeException("Host's Pod " + pod.getName() + " is already dedicated"); } } @@ -566,7 +567,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (dedicatedZoneOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) { DataCenterVO zone = _zoneDao.findById(host.getDataCenterId()); - s_logger.error("Host's Data Center " + zone.getName() + " is already dedicated"); + logger.error("Host's Data Center " + zone.getName() + " is already dedicated"); throw new CloudRuntimeException("Host's Data Center " + zone.getName() + " is already dedicated"); } } @@ -583,7 +584,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { // find or create the affinity group by name under this account/domain AffinityGroup group = findOrCreateDedicatedAffinityGroup(domainId, accountIdFinal); if (group == null) { - s_logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); + logger.error("Unable to dedicate zone due to, failed to create dedication affinity group"); throw new CloudRuntimeException("Failed to dedicate zone. Please contact Cloud Support."); } DedicatedResourceVO dedicatedResource = new DedicatedResourceVO(null, null, null, hostId, null, null, group.getId()); @@ -594,7 +595,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { } dedicatedResource = _dedicatedDao.persist(dedicatedResource); } catch (Exception e) { - s_logger.error("Unable to dedicate host due to " + e.getMessage(), e); + logger.error("Unable to dedicate host due to " + e.getMessage(), e); throw new CloudRuntimeException("Failed to dedicate host. Please contact Cloud Support.", e); } @@ -665,7 +666,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { if (accountId != null) { for (UserVmVO vm : allVmsOnHost) { if (vm.getAccountId() != accountId) { - s_logger.info("Host " + vm.getHostId() + " found to be unsuitable for explicit dedication as it is " + "running instances of another account"); + logger.info("Host " + vm.getHostId() + " found to be unsuitable for explicit dedication as it is " + "running instances of another account"); throw new CloudRuntimeException("Host " + hostId + " found to be unsuitable for explicit dedication as it is " + "running instances of another account"); } @@ -673,7 +674,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService { } else { for (UserVmVO vm : allVmsOnHost) { if (!domainIds.contains(vm.getDomainId())) { - s_logger.info("Host " + vm.getHostId() + " found to be unsuitable for explicit dedication as it is " + "running instances of another domain"); + logger.info("Host " + vm.getHostId() + " found to be unsuitable for explicit dedication as it is " + "running instances of another domain"); throw new CloudRuntimeException("Host " + hostId + " found to be unsuitable for explicit dedication as it is " + "running instances of another domain"); } diff --git a/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java b/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java index cd1d5018529..c13b8b12d9d 100644 --- a/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java +++ b/plugins/dedicated-resources/src/test/java/org/apache/cloudstack/dedicated/manager/DedicatedApiUnitTest.java @@ -18,7 +18,7 @@ package org.apache.cloudstack.dedicated.manager; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.anyLong; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; import java.io.IOException; @@ -32,7 +32,6 @@ import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.dedicated.DedicatedResourceManagerImpl; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.test.utils.SpringUtils; -import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -74,7 +73,6 @@ import junit.framework.Assert; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class) public class DedicatedApiUnitTest { - public static final Logger s_logger = Logger.getLogger(DedicatedApiUnitTest.class); @Inject DedicatedResourceManagerImpl _dedicatedService = new DedicatedResourceManagerImpl(); @@ -162,7 +160,7 @@ public class DedicatedApiUnitTest { List result = _dedicatedService.dedicateZone(10L, domainId, accountName); Assert.assertNotNull(result); } catch (Exception e) { - s_logger.info("exception in testing dedication of zone " + logger.info("exception in testing dedication of zone " + e.toString()); } } @@ -176,7 +174,7 @@ public class DedicatedApiUnitTest { List result = _dedicatedService.dedicatePod(10L, domainId, accountName); Assert.assertNotNull(result); } catch (Exception e) { - s_logger.info("exception in testing dedication of pod " + logger.info("exception in testing dedication of pod " + e.toString()); } } @@ -189,7 +187,7 @@ public class DedicatedApiUnitTest { List result = _dedicatedService.dedicateCluster(10L, domainId, accountName); Assert.assertNotNull(result); } catch (Exception e) { - s_logger.info("exception in testing dedication of cluster " + logger.info("exception in testing dedication of cluster " + e.toString()); } } @@ -205,7 +203,7 @@ public class DedicatedApiUnitTest { List result = _dedicatedService.dedicateHost(10L, domainId, accountName); Assert.assertNotNull(result); } catch (Exception e) { - s_logger.info("exception in testing dedication of host " + logger.info("exception in testing dedication of host " + e.toString()); } } diff --git a/plugins/deployment-planners/implicit-dedication/pom.xml b/plugins/deployment-planners/implicit-dedication/pom.xml index 0d78434c674..b9f8be5d08a 100644 --- a/plugins/deployment-planners/implicit-dedication/pom.xml +++ b/plugins/deployment-planners/implicit-dedication/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/deployment-planners/implicit-dedication/src/main/java/com/cloud/deploy/ImplicitDedicationPlanner.java b/plugins/deployment-planners/implicit-dedication/src/main/java/com/cloud/deploy/ImplicitDedicationPlanner.java index 2c5a72498bc..bd1bcf06101 100644 --- a/plugins/deployment-planners/implicit-dedication/src/main/java/com/cloud/deploy/ImplicitDedicationPlanner.java +++ b/plugins/deployment-planners/implicit-dedication/src/main/java/com/cloud/deploy/ImplicitDedicationPlanner.java @@ -25,7 +25,6 @@ import java.util.Set; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.configuration.Config; import com.cloud.exception.InsufficientServerCapacityException; @@ -43,7 +42,6 @@ import org.springframework.util.CollectionUtils; public class ImplicitDedicationPlanner extends FirstFitPlanner implements DeploymentClusterPlanner { - private static final Logger s_logger = Logger.getLogger(ImplicitDedicationPlanner.class); @Inject private ServiceOfferingDao serviceOfferingDao; @@ -158,12 +156,12 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements Deploy for (VMInstanceVO vm : allVmsOnHost) { if (vm.getAccountId() != accountId) { - s_logger.info("Host " + vm.getHostId() + " found to be unsuitable for implicit dedication as it is " + "running instances of another account"); + logger.info("Host " + vm.getHostId() + " found to be unsuitable for implicit dedication as it is " + "running instances of another account"); suitable = false; break; } else { if (!isImplicitPlannerUsedByOffering(vm.getServiceOfferingId())) { - s_logger.info("Host " + vm.getHostId() + " found to be unsuitable for implicit dedication as it " + + logger.info("Host " + vm.getHostId() + " found to be unsuitable for implicit dedication as it " + "is running instances of this account which haven't been created using implicit dedication."); suitable = false; break; @@ -179,11 +177,11 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements Deploy return false; for (VMInstanceVO vm : allVmsOnHost) { if (!isImplicitPlannerUsedByOffering(vm.getServiceOfferingId())) { - s_logger.info("Host " + vm.getHostId() + " found to be running a vm created by a planner other" + " than implicit."); + logger.info("Host " + vm.getHostId() + " found to be running a vm created by a planner other" + " than implicit."); createdByImplicitStrict = false; break; } else if (isServiceOfferingUsingPlannerInPreferredMode(vm.getServiceOfferingId())) { - s_logger.info("Host " + vm.getHostId() + " found to be running a vm created by an implicit planner" + " in preferred mode."); + logger.info("Host " + vm.getHostId() + " found to be running a vm created by an implicit planner" + " in preferred mode."); createdByImplicitStrict = false; break; } @@ -195,7 +193,7 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements Deploy boolean implicitPlannerUsed = false; ServiceOfferingVO offering = serviceOfferingDao.findByIdIncludingRemoved(offeringId); if (offering == null) { - s_logger.error("Couldn't retrieve the offering by the given id : " + offeringId); + logger.error("Couldn't retrieve the offering by the given id : " + offeringId); } else { String plannerName = offering.getDeploymentPlanner(); if (plannerName == null) { diff --git a/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java b/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java index f1645611272..e174824cfdd 100644 --- a/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java +++ b/plugins/deployment-planners/implicit-dedication/src/test/java/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java @@ -21,7 +21,7 @@ import static org.junit.Assert.assertTrue; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.everyItem; import static org.hamcrest.Matchers.equalTo; -import static org.mockito.Matchers.anyString; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/plugins/deployment-planners/user-concentrated-pod/pom.xml b/plugins/deployment-planners/user-concentrated-pod/pom.xml index 2fe6404ffab..0dcbe3506c6 100644 --- a/plugins/deployment-planners/user-concentrated-pod/pom.xml +++ b/plugins/deployment-planners/user-concentrated-pod/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/deployment-planners/user-concentrated-pod/src/main/java/com/cloud/deploy/UserConcentratedPodPlanner.java b/plugins/deployment-planners/user-concentrated-pod/src/main/java/com/cloud/deploy/UserConcentratedPodPlanner.java index bc56740eec8..c8ec78dc8f9 100644 --- a/plugins/deployment-planners/user-concentrated-pod/src/main/java/com/cloud/deploy/UserConcentratedPodPlanner.java +++ b/plugins/deployment-planners/user-concentrated-pod/src/main/java/com/cloud/deploy/UserConcentratedPodPlanner.java @@ -21,14 +21,12 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; import com.cloud.utils.Pair; import com.cloud.vm.VirtualMachineProfile; public class UserConcentratedPodPlanner extends FirstFitPlanner implements DeploymentClusterPlanner { - private static final Logger s_logger = Logger.getLogger(UserConcentratedPodPlanner.class); /** * This method should reorder the given list of Cluster Ids by applying any necessary heuristic @@ -62,14 +60,14 @@ public class UserConcentratedPodPlanner extends FirstFitPlanner implements Deplo private List reorderClustersByPods(List clusterIds, List podIds) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Reordering cluster list as per pods ordered by user concentration"); + if (logger.isDebugEnabled()) { + logger.debug("Reordering cluster list as per pods ordered by user concentration"); } Map> podClusterMap = clusterDao.getPodClusterIdMap(clusterIds); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Pod To cluster Map is: " + podClusterMap); + if (logger.isTraceEnabled()) { + logger.trace("Pod To cluster Map is: " + podClusterMap); } List reorderedClusters = new ArrayList(); @@ -88,22 +86,22 @@ public class UserConcentratedPodPlanner extends FirstFitPlanner implements Deplo } reorderedClusters.addAll(clusterIds); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Reordered cluster list: " + reorderedClusters); + if (logger.isTraceEnabled()) { + logger.trace("Reordered cluster list: " + reorderedClusters); } return reorderedClusters; } protected List listPodsByUserConcentration(long zoneId, long accountId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Applying UserConcentratedPod heuristic for account: " + accountId); + if (logger.isDebugEnabled()) { + logger.debug("Applying UserConcentratedPod heuristic for account: " + accountId); } List prioritizedPods = vmDao.listPodIdsHavingVmsforAccount(zoneId, accountId); - if (s_logger.isTraceEnabled()) { - s_logger.trace("List of pods to be considered, after applying UserConcentratedPod heuristic: " + prioritizedPods); + if (logger.isTraceEnabled()) { + logger.trace("List of pods to be considered, after applying UserConcentratedPod heuristic: " + prioritizedPods); } return prioritizedPods; diff --git a/plugins/deployment-planners/user-dispersing/pom.xml b/plugins/deployment-planners/user-dispersing/pom.xml index 3d7682a0cea..bbd74bf1a7a 100644 --- a/plugins/deployment-planners/user-dispersing/pom.xml +++ b/plugins/deployment-planners/user-dispersing/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/deployment-planners/user-dispersing/src/main/java/com/cloud/deploy/UserDispersingPlanner.java b/plugins/deployment-planners/user-dispersing/src/main/java/com/cloud/deploy/UserDispersingPlanner.java index 24bc061b218..c5d81e9a51b 100644 --- a/plugins/deployment-planners/user-dispersing/src/main/java/com/cloud/deploy/UserDispersingPlanner.java +++ b/plugins/deployment-planners/user-dispersing/src/main/java/com/cloud/deploy/UserDispersingPlanner.java @@ -25,7 +25,6 @@ import java.util.TreeMap; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.configuration.Config; import com.cloud.utils.NumbersUtil; @@ -34,7 +33,6 @@ import com.cloud.vm.VirtualMachineProfile; public class UserDispersingPlanner extends FirstFitPlanner implements DeploymentClusterPlanner { - private static final Logger s_logger = Logger.getLogger(UserDispersingPlanner.class); /** * This method should reorder the given list of Cluster Ids by applying any necessary heuristic @@ -97,8 +95,8 @@ public class UserDispersingPlanner extends FirstFitPlanner implements Deployment } protected Pair, Map> listClustersByUserDispersion(long id, boolean isZone, long accountId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Applying Userdispersion heuristic to clusters for account: " + accountId); + if (logger.isDebugEnabled()) { + logger.debug("Applying Userdispersion heuristic to clusters for account: " + accountId); } Pair, Map> clusterIdsVmCountInfo; if (isZone) { @@ -106,19 +104,19 @@ public class UserDispersingPlanner extends FirstFitPlanner implements Deployment } else { clusterIdsVmCountInfo = vmInstanceDao.listClusterIdsInPodByVmCount(id, accountId); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("List of clusters in ascending order of number of VMs: " + clusterIdsVmCountInfo.first()); + if (logger.isTraceEnabled()) { + logger.trace("List of clusters in ascending order of number of VMs: " + clusterIdsVmCountInfo.first()); } return clusterIdsVmCountInfo; } protected Pair, Map> listPodsByUserDispersion(long dataCenterId, long accountId) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Applying Userdispersion heuristic to pods for account: " + accountId); + if (logger.isDebugEnabled()) { + logger.debug("Applying Userdispersion heuristic to pods for account: " + accountId); } Pair, Map> podIdsVmCountInfo = vmInstanceDao.listPodIdsInZoneByVmCount(dataCenterId, accountId); - if (s_logger.isTraceEnabled()) { - s_logger.trace("List of pods in ascending order of number of VMs: " + podIdsVmCountInfo.first()); + if (logger.isTraceEnabled()) { + logger.trace("List of pods in ascending order of number of VMs: " + podIdsVmCountInfo.first()); } return podIdsVmCountInfo; @@ -130,25 +128,25 @@ public class UserDispersingPlanner extends FirstFitPlanner implements Deployment Map capacityMap = capacityInfo.second(); Map vmCountMap = vmCountInfo.second(); - if (s_logger.isTraceEnabled()) { - s_logger.trace("Capacity Id list: " + capacityOrderedIds + " , capacityMap:" + capacityMap); + if (logger.isTraceEnabled()) { + logger.trace("Capacity Id list: " + capacityOrderedIds + " , capacityMap:" + capacityMap); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Vm Count Id list: " + vmCountOrderedIds + " , vmCountMap:" + vmCountMap); + if (logger.isTraceEnabled()) { + logger.trace("Vm Count Id list: " + vmCountOrderedIds + " , vmCountMap:" + vmCountMap); } List idsReorderedByWeights = new ArrayList(); float capacityWeight = (1.0f - _userDispersionWeight); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Applying userDispersionWeight: " + _userDispersionWeight); + if (logger.isDebugEnabled()) { + logger.debug("Applying userDispersionWeight: " + _userDispersionWeight); } //normalize the vmCountMap LinkedHashMap normalisedVmCountIdMap = new LinkedHashMap(); Long totalVmsOfAccount = vmInstanceDao.countRunningAndStartingByAccount(accountId); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Total VMs for account: " + totalVmsOfAccount); + if (logger.isDebugEnabled()) { + logger.debug("Total VMs for account: " + totalVmsOfAccount); } for (Long id : vmCountOrderedIds) { Double normalisedCount = vmCountMap.get(id) / totalVmsOfAccount; @@ -177,8 +175,8 @@ public class UserDispersingPlanner extends FirstFitPlanner implements Deployment idsReorderedByWeights.addAll(idList); } - if (s_logger.isTraceEnabled()) { - s_logger.trace("Reordered Id list: " + idsReorderedByWeights); + if (logger.isTraceEnabled()) { + logger.trace("Reordered Id list: " + idsReorderedByWeights); } return idsReorderedByWeights; diff --git a/plugins/drs/cluster/balanced/pom.xml b/plugins/drs/cluster/balanced/pom.xml index aaec36bbac6..743a5f2bc98 100644 --- a/plugins/drs/cluster/balanced/pom.xml +++ b/plugins/drs/cluster/balanced/pom.xml @@ -27,7 +27,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/drs/cluster/balanced/src/main/java/org/apache/cloudstack/cluster/Balanced.java b/plugins/drs/cluster/balanced/src/main/java/org/apache/cloudstack/cluster/Balanced.java index dc15a820560..c799ac872c0 100644 --- a/plugins/drs/cluster/balanced/src/main/java/org/apache/cloudstack/cluster/Balanced.java +++ b/plugins/drs/cluster/balanced/src/main/java/org/apache/cloudstack/cluster/Balanced.java @@ -21,10 +21,11 @@ package org.apache.cloudstack.cluster; import com.cloud.host.Host; import com.cloud.offering.ServiceOffering; -import com.cloud.utils.Pair; import com.cloud.utils.Ternary; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.VirtualMachine; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.naming.ConfigurationException; import java.util.ArrayList; @@ -32,68 +33,56 @@ import java.util.List; import java.util.Map; import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsImbalanceThreshold; -import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsMetric; public class Balanced extends AdapterBase implements ClusterDrsAlgorithm { + private static final Logger logger = LogManager.getLogger(Balanced.class); + + @Override + public boolean needsDrs(long clusterId, List> cpuList, + List> memoryList) throws ConfigurationException { + double threshold = getThreshold(clusterId); + Double imbalance = ClusterDrsAlgorithm.getClusterImbalance(clusterId, cpuList, memoryList, null); + String drsMetric = ClusterDrsAlgorithm.getClusterDrsMetric(clusterId); + String metricType = ClusterDrsAlgorithm.getDrsMetricType(clusterId); + Boolean useRatio = ClusterDrsAlgorithm.getDrsMetricUseRatio(clusterId); + if (imbalance > threshold) { + logger.debug(String.format("Cluster %d needs DRS. Imbalance: %s Threshold: %s Algorithm: %s DRS metric: %s Metric Type: %s Use ratio: %s", + clusterId, imbalance, threshold, getName(), drsMetric, metricType, useRatio)); + return true; + } else { + logger.debug(String.format("Cluster %d does not need DRS. Imbalance: %s Threshold: %s Algorithm: %s DRS metric: %s Metric Type: %s Use ratio: %s", + clusterId, imbalance, threshold, getName(), drsMetric, metricType, useRatio)); + return false; + } + } + + private double getThreshold(long clusterId) { + return 1.0 - ClusterDrsImbalanceThreshold.valueIn(clusterId); + } + @Override public String getName() { return "balanced"; } - @Override - public boolean needsDrs(long clusterId, List cpuList, List memoryList) throws ConfigurationException { - Double cpuImbalance = getClusterImbalance(cpuList); - Double memoryImbalance = getClusterImbalance(memoryList); - double threshold = getThreshold(clusterId); - String metric = ClusterDrsMetric.valueIn(clusterId); - switch (metric) { - case "cpu": - return cpuImbalance > threshold; - case "memory": - return memoryImbalance > threshold; - default: - throw new ConfigurationException( - String.format("Invalid metric: %s for cluster: %d", metric, clusterId)); - } - } - - private double getThreshold(long clusterId) throws ConfigurationException { - return 1.0 - ClusterDrsImbalanceThreshold.valueIn(clusterId); - } - @Override public Ternary getMetrics(long clusterId, VirtualMachine vm, - ServiceOffering serviceOffering, Host destHost, - Map hostCpuUsedMap, Map hostMemoryUsedMap, - Boolean requiresStorageMotion) { - Double preCpuImbalance = getClusterImbalance(new ArrayList<>(hostCpuUsedMap.values())); - Double preMemoryImbalance = getClusterImbalance(new ArrayList<>(hostMemoryUsedMap.values())); + ServiceOffering serviceOffering, Host destHost, + Map> hostCpuMap, Map> hostMemoryMap, + Boolean requiresStorageMotion) throws ConfigurationException { + Double preImbalance = ClusterDrsAlgorithm.getClusterImbalance(clusterId, new ArrayList<>(hostCpuMap.values()), new ArrayList<>(hostMemoryMap.values()), null); + Double postImbalance = getImbalancePostMigration(serviceOffering, vm, destHost, hostCpuMap, hostMemoryMap); - Pair imbalancePair = getImbalancePostMigration(serviceOffering, vm, destHost, hostCpuUsedMap, - hostMemoryUsedMap); - Double postCpuImbalance = imbalancePair.first(); - Double postMemoryImbalance = imbalancePair.second(); + logger.debug(String.format("Cluster %d pre-imbalance: %s post-imbalance: %s Algorithm: %s VM: %s srcHost: %d destHost: %s", + clusterId, preImbalance, postImbalance, getName(), vm.getUuid(), vm.getHostId(), destHost.getUuid())); // This needs more research to determine the cost and benefit of a migration // TODO: Cost should be a factor of the VM size and the host capacity // TODO: Benefit should be a factor of the VM size and the host capacity and the number of VMs on the host - double cost = 0.0; - double benefit = 1.0; - - String metric = ClusterDrsMetric.valueIn(clusterId); - final double improvement; - switch (metric) { - case "cpu": - improvement = preCpuImbalance - postCpuImbalance; - break; - case "memory": - improvement = preMemoryImbalance - postMemoryImbalance; - break; - default: - improvement = preCpuImbalance + preMemoryImbalance - postCpuImbalance - postMemoryImbalance; - } - + final double improvement = preImbalance - postImbalance; + final double cost = 0.0; + final double benefit = 1.0; return new Ternary<>(improvement, cost, benefit); } } diff --git a/plugins/drs/cluster/balanced/src/test/java/org/apache/cloudstack/cluster/BalancedTest.java b/plugins/drs/cluster/balanced/src/test/java/org/apache/cloudstack/cluster/BalancedTest.java index 4b84049e49a..a1562b52e38 100644 --- a/plugins/drs/cluster/balanced/src/test/java/org/apache/cloudstack/cluster/BalancedTest.java +++ b/plugins/drs/cluster/balanced/src/test/java/org/apache/cloudstack/cluster/BalancedTest.java @@ -21,7 +21,6 @@ package org.apache.cloudstack.cluster; import com.cloud.host.Host; import com.cloud.service.ServiceOfferingVO; -import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.utils.Ternary; import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.framework.config.ConfigKey; @@ -30,13 +29,13 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.junit.MockitoJUnitRunner; import javax.naming.ConfigurationException; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -66,14 +65,7 @@ public class BalancedTest { Map> hostVmMap; - List cpuList, memoryList; - - Map hostCpuUsedMap, hostMemoryUsedMap; - - - @Mock - private ServiceOfferingDao serviceOfferingDao; - + Map> hostCpuFreeMap, hostMemoryFreeMap; private AutoCloseable closeable; @@ -98,24 +90,21 @@ public class BalancedTest { Mockito.when(serviceOffering.getCpu()).thenReturn(1); Mockito.when(serviceOffering.getSpeed()).thenReturn(1000); - Mockito.when(serviceOffering.getRamSize()).thenReturn(512); + Mockito.when(serviceOffering.getRamSize()).thenReturn(1024); overrideDefaultConfigValue(ClusterDrsImbalanceThreshold, "_defaultValue", "0.5"); - cpuList = Arrays.asList(1L, 2L); - memoryList = Arrays.asList(512L, 2048L); + hostCpuFreeMap = new HashMap<>(); + hostCpuFreeMap.put(1L, new Ternary<>(1000L, 0L, 10000L)); + hostCpuFreeMap.put(2L, new Ternary<>(2000L, 0L, 10000L)); - hostCpuUsedMap = new HashMap<>(); - hostCpuUsedMap.put(1L, 1000L); - hostCpuUsedMap.put(2L, 2000L); - - hostMemoryUsedMap = new HashMap<>(); - hostMemoryUsedMap.put(1L, 512L * 1024L * 1024L); - hostMemoryUsedMap.put(2L, 2048L * 1024L * 1024L); + hostMemoryFreeMap = new HashMap<>(); + hostMemoryFreeMap.put(1L, new Ternary<>(512L * 1024L * 1024L, 0L, 8192L * 1024L * 1024L)); + hostMemoryFreeMap.put(2L, new Ternary<>(2048L * 1024L * 1024L, 0L, 8192L * 1024L * 1024L)); } private void overrideDefaultConfigValue(final ConfigKey configKey, final String name, - final Object o) throws IllegalAccessException, NoSuchFieldException { + final Object o) throws IllegalAccessException, NoSuchFieldException { Field f = ConfigKey.class.getDeclaredField(name); f.setAccessible(true); f.set(configKey, o); @@ -144,7 +133,7 @@ public class BalancedTest { @Test public void needsDrsWithCpu() throws ConfigurationException, NoSuchFieldException, IllegalAccessException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "cpu"); - assertFalse(balanced.needsDrs(clusterId, cpuList, memoryList)); + assertFalse(balanced.needsDrs(clusterId, new ArrayList<>(hostCpuFreeMap.values()), new ArrayList<>(hostMemoryFreeMap.values()))); } /* @@ -154,14 +143,14 @@ public class BalancedTest { @Test public void needsDrsWithMemory() throws ConfigurationException, NoSuchFieldException, IllegalAccessException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "memory"); - assertTrue(balanced.needsDrs(clusterId, cpuList, memoryList)); + assertTrue(balanced.needsDrs(clusterId, new ArrayList<>(hostCpuFreeMap.values()), new ArrayList<>(hostMemoryFreeMap.values()))); } /* 3. cluster with "unknown" metric */ @Test - public void needsDrsWithUnknown() throws ConfigurationException, NoSuchFieldException, IllegalAccessException { + public void needsDrsWithUnknown() throws NoSuchFieldException, IllegalAccessException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "unknown"); - assertThrows(ConfigurationException.class, () -> balanced.needsDrs(clusterId, cpuList, memoryList)); + assertThrows(ConfigurationException.class, () -> balanced.needsDrs(clusterId, new ArrayList<>(hostCpuFreeMap.values()), new ArrayList<>(hostMemoryFreeMap.values()))); } /** @@ -188,10 +177,10 @@ public class BalancedTest { improvement = 0.3333 - 0.3333 = 0.0 */ @Test - public void getMetricsWithCpu() throws NoSuchFieldException, IllegalAccessException { + public void getMetricsWithCpu() throws NoSuchFieldException, IllegalAccessException, ConfigurationException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "cpu"); Ternary result = balanced.getMetrics(clusterId, vm3, serviceOffering, destHost, - hostCpuUsedMap, hostMemoryUsedMap, false); + hostCpuFreeMap, hostMemoryFreeMap, false); assertEquals(0.0, result.first(), 0.01); assertEquals(0.0, result.second(), 0.0); assertEquals(1.0, result.third(), 0.0); @@ -202,24 +191,10 @@ public class BalancedTest { improvement = 0.6 - 0.2 = 0.4 */ @Test - public void getMetricsWithMemory() throws NoSuchFieldException, IllegalAccessException { + public void getMetricsWithMemory() throws NoSuchFieldException, IllegalAccessException, ConfigurationException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "memory"); Ternary result = balanced.getMetrics(clusterId, vm3, serviceOffering, destHost, - hostCpuUsedMap, hostMemoryUsedMap, false); - assertEquals(0.4, result.first(), 0.01); - assertEquals(0, result.second(), 0.0); - assertEquals(1, result.third(), 0.0); - } - - /* - 3. cluster with default metric - improvement = 0.3333 + 0.6 - 0.3333 - 0.2 = 0.4 - */ - @Test - public void getMetricsWithDefault() throws NoSuchFieldException, IllegalAccessException { - overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "both"); - Ternary result = balanced.getMetrics(clusterId, vm3, serviceOffering, destHost, - hostCpuUsedMap, hostMemoryUsedMap, false); + hostCpuFreeMap, hostMemoryFreeMap, false); assertEquals(0.4, result.first(), 0.01); assertEquals(0, result.second(), 0.0); assertEquals(1, result.third(), 0.0); diff --git a/plugins/drs/cluster/condensed/pom.xml b/plugins/drs/cluster/condensed/pom.xml index ea8acdc6d1b..60b472bccb5 100644 --- a/plugins/drs/cluster/condensed/pom.xml +++ b/plugins/drs/cluster/condensed/pom.xml @@ -27,7 +27,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../../pom.xml diff --git a/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java b/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java index aefd11905ef..3a8befa628b 100644 --- a/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java +++ b/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java @@ -21,78 +21,72 @@ package org.apache.cloudstack.cluster; import com.cloud.host.Host; import com.cloud.offering.ServiceOffering; -import com.cloud.utils.Pair; import com.cloud.utils.Ternary; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.VirtualMachine; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.naming.ConfigurationException; import java.util.ArrayList; import java.util.List; import java.util.Map; +import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsImbalanceSkipThreshold; import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsImbalanceThreshold; -import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsMetric; public class Condensed extends AdapterBase implements ClusterDrsAlgorithm { + private static final Logger logger = LogManager.getLogger(Condensed.class); + + @Override + public boolean needsDrs(long clusterId, List> cpuList, + List> memoryList) throws ConfigurationException { + double threshold = getThreshold(clusterId); + Float skipThreshold = ClusterDrsImbalanceSkipThreshold.valueIn(clusterId); + Double imbalance = ClusterDrsAlgorithm.getClusterImbalance(clusterId, cpuList, memoryList, skipThreshold); + String drsMetric = ClusterDrsAlgorithm.getClusterDrsMetric(clusterId); + String metricType = ClusterDrsAlgorithm.getDrsMetricType(clusterId); + Boolean useRatio = ClusterDrsAlgorithm.getDrsMetricUseRatio(clusterId); + if (imbalance < threshold) { + + logger.debug(String.format("Cluster %d needs DRS. Imbalance: %s Threshold: %s Algorithm: %s DRS metric: %s Metric Type: %s Use ratio: %s SkipThreshold: %s", + clusterId, imbalance, threshold, getName(), drsMetric, metricType, useRatio, skipThreshold)); + return true; + } else { + logger.debug(String.format("Cluster %d does not need DRS. Imbalance: %s Threshold: %s Algorithm: %s DRS metric: %s Metric Type: %s Use ratio: %s SkipThreshold: %s", + clusterId, imbalance, threshold, getName(), drsMetric, metricType, useRatio, skipThreshold)); + return false; + } + } + + private double getThreshold(long clusterId) { + return ClusterDrsImbalanceThreshold.valueIn(clusterId); + } + @Override public String getName() { return "condensed"; } - @Override - public boolean needsDrs(long clusterId, List cpuList, List memoryList) throws ConfigurationException { - Double cpuImbalance = getClusterImbalance(cpuList); - Double memoryImbalance = getClusterImbalance(memoryList); - double threshold = getThreshold(clusterId); - String metric = ClusterDrsMetric.valueIn(clusterId); - switch (metric) { - case "cpu": - return cpuImbalance < threshold; - case "memory": - return memoryImbalance < threshold; - default: - throw new ConfigurationException( - String.format("Invalid metric: %s for cluster: %d", metric, clusterId)); - } - } - - private double getThreshold(long clusterId) throws ConfigurationException { - return ClusterDrsImbalanceThreshold.valueIn(clusterId); - } - @Override public Ternary getMetrics(long clusterId, VirtualMachine vm, - ServiceOffering serviceOffering, Host destHost, - Map hostCpuUsedMap, Map hostMemoryUsedMap, - Boolean requiresStorageMotion) { - Double preCpuImbalance = getClusterImbalance(new ArrayList<>(hostCpuUsedMap.values())); - Double preMemoryImbalance = getClusterImbalance(new ArrayList<>(hostMemoryUsedMap.values())); + ServiceOffering serviceOffering, Host destHost, + Map> hostCpuMap, Map> hostMemoryMap, + Boolean requiresStorageMotion) throws ConfigurationException { + Double preImbalance = ClusterDrsAlgorithm.getClusterImbalance(clusterId, new ArrayList<>(hostCpuMap.values()), + new ArrayList<>(hostMemoryMap.values()), null); + Double postImbalance = getImbalancePostMigration(serviceOffering, vm, destHost, hostCpuMap, hostMemoryMap); - Pair imbalancePair = getImbalancePostMigration(serviceOffering, vm, destHost, hostCpuUsedMap, - hostMemoryUsedMap); - Double postCpuImbalance = imbalancePair.first(); - Double postMemoryImbalance = imbalancePair.second(); + logger.debug(String.format("Cluster %d pre-imbalance: %s post-imbalance: %s Algorithm: %s VM: %s srcHost: %d destHost: %s", + clusterId, preImbalance, postImbalance, getName(), vm.getUuid(), vm.getHostId(), destHost.getUuid())); // This needs more research to determine the cost and benefit of a migration // TODO: Cost should be a factor of the VM size and the host capacity // TODO: Benefit should be a factor of the VM size and the host capacity and the number of VMs on the host - double cost = 0; - double benefit = 1; - - String metric = ClusterDrsMetric.valueIn(clusterId); - double improvement; - switch (metric) { - case "cpu": - improvement = postCpuImbalance - preCpuImbalance; - break; - case "memory": - improvement = postMemoryImbalance - preMemoryImbalance; - break; - default: - improvement = postCpuImbalance + postMemoryImbalance - preCpuImbalance - preMemoryImbalance; - } + final double improvement = postImbalance - preImbalance; + final double cost = 0; + final double benefit = 1; return new Ternary<>(improvement, cost, benefit); } } diff --git a/plugins/drs/cluster/condensed/src/test/java/org/apache/cloudstack/cluster/CondensedTest.java b/plugins/drs/cluster/condensed/src/test/java/org/apache/cloudstack/cluster/CondensedTest.java index d8cf581768a..d5072774534 100644 --- a/plugins/drs/cluster/condensed/src/test/java/org/apache/cloudstack/cluster/CondensedTest.java +++ b/plugins/drs/cluster/condensed/src/test/java/org/apache/cloudstack/cluster/CondensedTest.java @@ -35,6 +35,7 @@ import org.mockito.junit.MockitoJUnitRunner; import javax.naming.ConfigurationException; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -64,9 +65,7 @@ public class CondensedTest { Map> hostVmMap; - List cpuList, memoryList; - - Map hostCpuUsedMap, hostMemoryUsedMap; + Map> hostCpuFreeMap, hostMemoryFreeMap; private AutoCloseable closeable; @@ -95,21 +94,18 @@ public class CondensedTest { overrideDefaultConfigValue(ClusterDrsImbalanceThreshold, "_defaultValue", "0.5"); - cpuList = Arrays.asList(1L, 2L); - memoryList = Arrays.asList(512L, 2048L); + hostCpuFreeMap = new HashMap<>(); + hostCpuFreeMap.put(1L, new Ternary<>(1000L, 0L, 10000L)); + hostCpuFreeMap.put(2L, new Ternary<>(2000L, 0L, 10000L)); - hostCpuUsedMap = new HashMap<>(); - hostCpuUsedMap.put(1L, 1000L); - hostCpuUsedMap.put(2L, 2000L); - - hostMemoryUsedMap = new HashMap<>(); - hostMemoryUsedMap.put(1L, 512L * 1024L * 1024L); - hostMemoryUsedMap.put(2L, 2048L * 1024L * 1024L); + hostMemoryFreeMap = new HashMap<>(); + hostMemoryFreeMap.put(1L, new Ternary<>(512L * 1024L * 1024L, 0L, 8192L * 1024L * 1024L)); + hostMemoryFreeMap.put(2L, new Ternary<>(2048L * 1024L * 1024L, 0L, 8192L * 1024L * 1024L)); } private void overrideDefaultConfigValue(final ConfigKey configKey, - final String name, - final Object o) throws IllegalAccessException, NoSuchFieldException { + final String name, + final Object o) throws IllegalAccessException, NoSuchFieldException { Field f = ConfigKey.class.getDeclaredField(name); f.setAccessible(true); f.set(configKey, o); @@ -138,7 +134,7 @@ public class CondensedTest { @Test public void needsDrsWithCpu() throws ConfigurationException, NoSuchFieldException, IllegalAccessException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "cpu"); - assertTrue(condensed.needsDrs(clusterId, cpuList, memoryList)); + assertTrue(condensed.needsDrs(clusterId, new ArrayList<>(hostCpuFreeMap.values()), new ArrayList<>(hostMemoryFreeMap.values()))); } /* @@ -148,14 +144,14 @@ public class CondensedTest { @Test public void needsDrsWithMemory() throws ConfigurationException, NoSuchFieldException, IllegalAccessException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "memory"); - assertFalse(condensed.needsDrs(clusterId, cpuList, memoryList)); + assertFalse(condensed.needsDrs(clusterId, new ArrayList<>(hostCpuFreeMap.values()), new ArrayList<>(hostMemoryFreeMap.values()))); } /* 3. cluster with "unknown" metric */ @Test - public void needsDrsWithUnknown() throws ConfigurationException, NoSuchFieldException, IllegalAccessException { + public void needsDrsWithUnknown() throws NoSuchFieldException, IllegalAccessException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "unknown"); - assertThrows(ConfigurationException.class, () -> condensed.needsDrs(clusterId, cpuList, memoryList)); + assertThrows(ConfigurationException.class, () -> condensed.needsDrs(clusterId, new ArrayList<>(hostCpuFreeMap.values()), new ArrayList<>(hostMemoryFreeMap.values()))); } /** @@ -182,10 +178,10 @@ public class CondensedTest { improvement = 0.3333 - 0.3333 = 0.0 */ @Test - public void getMetricsWithCpu() throws NoSuchFieldException, IllegalAccessException { + public void getMetricsWithCpu() throws NoSuchFieldException, IllegalAccessException, ConfigurationException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "cpu"); Ternary result = condensed.getMetrics(clusterId, vm3, serviceOffering, destHost, - hostCpuUsedMap, hostMemoryUsedMap, false); + hostCpuFreeMap, hostMemoryFreeMap, false); assertEquals(0.0, result.first(), 0.0); assertEquals(0, result.second(), 0.0); assertEquals(1, result.third(), 0.0); @@ -196,26 +192,12 @@ public class CondensedTest { improvement = 0.2 - 0.6 = -0.4 */ @Test - public void getMetricsWithMemory() throws NoSuchFieldException, IllegalAccessException { + public void getMetricsWithMemory() throws NoSuchFieldException, IllegalAccessException, ConfigurationException { overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "memory"); Ternary result = condensed.getMetrics(clusterId, vm3, serviceOffering, destHost, - hostCpuUsedMap, hostMemoryUsedMap, false); + hostCpuFreeMap, hostMemoryFreeMap, false); assertEquals(-0.4, result.first(), 0.01); assertEquals(0, result.second(), 0.0); assertEquals(1, result.third(), 0.0); } - - /* - 3. cluster with default metric - improvement = 0.3333 + 0.2 - 0.3333 - 0.6 = -0.4 - */ - @Test - public void getMetricsWithDefault() throws NoSuchFieldException, IllegalAccessException { - overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "both"); - Ternary result = condensed.getMetrics(clusterId, vm3, serviceOffering, destHost, - hostCpuUsedMap, hostMemoryUsedMap, false); - assertEquals(-0.4, result.first(), 0.0001); - assertEquals(0, result.second(), 0.0); - assertEquals(1, result.third(), 0.0); - } } diff --git a/plugins/event-bus/inmemory/pom.xml b/plugins/event-bus/inmemory/pom.xml index 2ed5a9132d0..be85e8afd8d 100644 --- a/plugins/event-bus/inmemory/pom.xml +++ b/plugins/event-bus/inmemory/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/event-bus/inmemory/src/main/java/org/apache/cloudstack/mom/inmemory/InMemoryEventBus.java b/plugins/event-bus/inmemory/src/main/java/org/apache/cloudstack/mom/inmemory/InMemoryEventBus.java index b7d74df980f..d5d36278192 100644 --- a/plugins/event-bus/inmemory/src/main/java/org/apache/cloudstack/mom/inmemory/InMemoryEventBus.java +++ b/plugins/event-bus/inmemory/src/main/java/org/apache/cloudstack/mom/inmemory/InMemoryEventBus.java @@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentHashMap; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.events.Event; import org.apache.cloudstack.framework.events.EventBus; @@ -38,7 +37,6 @@ import com.cloud.utils.component.ManagerBase; public class InMemoryEventBus extends ManagerBase implements EventBus { - private static final Logger s_logger = Logger.getLogger(InMemoryEventBus.class); private final static Map> subscribers; diff --git a/plugins/event-bus/kafka/pom.xml b/plugins/event-bus/kafka/pom.xml index 6756ea2d7f6..44014847548 100644 --- a/plugins/event-bus/kafka/pom.xml +++ b/plugins/event-bus/kafka/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/event-bus/kafka/src/main/java/org/apache/cloudstack/mom/kafka/KafkaEventBus.java b/plugins/event-bus/kafka/src/main/java/org/apache/cloudstack/mom/kafka/KafkaEventBus.java index 17a58a5d232..01888779fc6 100644 --- a/plugins/event-bus/kafka/src/main/java/org/apache/cloudstack/mom/kafka/KafkaEventBus.java +++ b/plugins/event-bus/kafka/src/main/java/org/apache/cloudstack/mom/kafka/KafkaEventBus.java @@ -27,7 +27,6 @@ import java.util.Properties; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.apache.cloudstack.framework.events.Event; import org.apache.cloudstack.framework.events.EventBus; @@ -50,7 +49,6 @@ public class KafkaEventBus extends ManagerBase implements EventBus { private String _topic = null; private Producer _producer; - private static final Logger s_logger = Logger.getLogger(KafkaEventBus.class); @Override public boolean configure(String name, Map params) throws ConfigurationException { diff --git a/plugins/event-bus/rabbitmq/pom.xml b/plugins/event-bus/rabbitmq/pom.xml index 6019fb9cb02..1e04caf026f 100644 --- a/plugins/event-bus/rabbitmq/pom.xml +++ b/plugins/event-bus/rabbitmq/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/event-bus/rabbitmq/src/main/java/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java b/plugins/event-bus/rabbitmq/src/main/java/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java index f54c769908d..8cd2289f9f3 100644 --- a/plugins/event-bus/rabbitmq/src/main/java/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java +++ b/plugins/event-bus/rabbitmq/src/main/java/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java @@ -34,7 +34,6 @@ import javax.naming.ConfigurationException; import com.cloud.utils.exception.CloudRuntimeException; import com.rabbitmq.client.BlockedListener; -import org.apache.log4j.Logger; import com.rabbitmq.client.AMQP; import com.rabbitmq.client.AlreadyClosedException; @@ -97,7 +96,6 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { private ExecutorService executorService; private static DisconnectHandler disconnectHandler; private static BlockedConnectionHandler blockedConnectionHandler; - private static final Logger s_logger = Logger.getLogger(RabbitMQEventBus.class); @Override public boolean configure(String name, Map params) throws ConfigurationException { @@ -240,9 +238,9 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { s_subscribers.put(queueName, queueDetails); } catch (AlreadyClosedException closedException) { - s_logger.warn("Connection to AMQP service is lost. Subscription:" + queueName + " will be active after reconnection", closedException); + logger.warn("Connection to AMQP service is lost. Subscription:" + queueName + " will be active after reconnection", closedException); } catch (ConnectException connectException) { - s_logger.warn("Connection to AMQP service is lost. Subscription:" + queueName + " will be active after reconnection", connectException); + logger.warn("Connection to AMQP service is lost. Subscription:" + queueName + " will be active after reconnection", connectException); } catch (Exception e) { throw new EventBusException("Failed to subscribe to event due to " + e.getMessage()); } @@ -362,7 +360,7 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { try { return createConnection(); } catch (KeyManagementException | NoSuchAlgorithmException | IOException | TimeoutException e) { - s_logger.error(String.format("Failed to create a connection to AMQP server [AMQP host:%s, port:%d] due to: %s", amqpHost, port, e)); + logger.error(String.format("Failed to create a connection to AMQP server [AMQP host:%s, port:%d] due to: %s", amqpHost, port, e)); throw e; } } else { @@ -399,7 +397,7 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { s_connection.close(); } } catch (Exception e) { - s_logger.warn("Failed to close connection to AMQP server due to " + e.getMessage()); + logger.warn("Failed to close connection to AMQP server due to " + e.getMessage()); } s_connection = null; } @@ -411,7 +409,7 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { try { s_connection.abort(); } catch (Exception e) { - s_logger.warn("Failed to abort connection due to " + e.getMessage()); + logger.warn("Failed to abort connection due to " + e.getMessage()); } s_connection = null; } @@ -428,7 +426,7 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { try { return connection.createChannel(); } catch (java.io.IOException exception) { - s_logger.warn("Failed to create a channel due to " + exception.getMessage()); + logger.warn("Failed to create a channel due to " + exception.getMessage()); throw exception; } } @@ -437,7 +435,7 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { try { channel.exchangeDeclare(exchangeName, "topic", true); } catch (java.io.IOException exception) { - s_logger.error("Failed to create exchange" + exchangeName + " on RabbitMQ server"); + logger.error("Failed to create exchange" + exchangeName + " on RabbitMQ server"); throw exception; } } @@ -447,7 +445,7 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { byte[] messageBodyBytes = eventDescription.getBytes(); channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes); } catch (Exception e) { - s_logger.error("Failed to publish event " + routingKey + " on exchange " + exchangeName + " of message broker due to " + e.getMessage()); + logger.error("Failed to publish event " + routingKey + " on exchange " + exchangeName + " of message broker due to " + e.getMessage()); throw e; } } @@ -500,7 +498,7 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { channel.queueDelete(queueName); channel.abort(); } catch (IOException ioe) { - s_logger.warn("Failed to delete queue: " + queueName + " on AMQP server due to " + ioe.getMessage()); + logger.warn("Failed to delete queue: " + queueName + " on AMQP server due to " + ioe.getMessage()); } } } @@ -514,14 +512,14 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { @Override public void handleBlocked(String reason) throws IOException { - s_logger.error("rabbitmq connection is blocked with reason: " + reason); + logger.error("rabbitmq connection is blocked with reason: " + reason); closeConnection(); throw new CloudRuntimeException("unblocking the parent thread as publishing to rabbitmq server is blocked with reason: " + reason); } @Override public void handleUnblocked() throws IOException { - s_logger.info("rabbitmq connection in unblocked"); + logger.info("rabbitmq connection in unblocked"); } } // logic to deal with loss of connection to AMQP server @@ -538,7 +536,7 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { } abortConnection(); // disconnected to AMQP server, so abort the connection and channels - s_logger.warn("Connection has been shutdown by AMQP server. Attempting to reconnect."); + logger.warn("Connection has been shutdown by AMQP server. Attempting to reconnect."); // initiate re-connect process ReconnectionTask reconnect = new ReconnectionTask(); @@ -616,7 +614,7 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { s_subscribers.put(subscriberId, subscriberDetails); } } catch (Exception e) { - s_logger.warn("Failed to recreate queues and binding for the subscribers due to " + e.getMessage()); + logger.warn("Failed to recreate queues and binding for the subscribers due to " + e.getMessage()); } } return; diff --git a/plugins/ha-planners/skip-heurestics/pom.xml b/plugins/ha-planners/skip-heurestics/pom.xml index 59a26006e03..3dc3989da2c 100644 --- a/plugins/ha-planners/skip-heurestics/pom.xml +++ b/plugins/ha-planners/skip-heurestics/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/ha-planners/skip-heurestics/src/main/java/com/cloud/deploy/SkipHeuresticsPlanner.java b/plugins/ha-planners/skip-heurestics/src/main/java/com/cloud/deploy/SkipHeuresticsPlanner.java index 6f9d696a171..c6e2ea4d99f 100644 --- a/plugins/ha-planners/skip-heurestics/src/main/java/com/cloud/deploy/SkipHeuresticsPlanner.java +++ b/plugins/ha-planners/skip-heurestics/src/main/java/com/cloud/deploy/SkipHeuresticsPlanner.java @@ -17,7 +17,6 @@ package com.cloud.deploy; import com.cloud.vm.VirtualMachineProfile; -import org.apache.log4j.Logger; import javax.naming.ConfigurationException; @@ -25,7 +24,6 @@ import java.util.List; import java.util.Map; public class SkipHeuresticsPlanner extends FirstFitPlanner implements HAPlanner { - private static final Logger s_logger = Logger.getLogger(SkipHeuresticsPlanner.class); /** @@ -37,8 +35,8 @@ public class SkipHeuresticsPlanner extends FirstFitPlanner implements HAPlanner @Override protected void removeClustersCrossingThreshold(List clusterListForVmAllocation, ExcludeList avoid, VirtualMachineProfile vmProfile, DeploymentPlan plan){ - if (s_logger.isDebugEnabled()) { - s_logger.debug("Deploying vm during HA process, so skipping disable threshold check"); + if (logger.isDebugEnabled()) { + logger.debug("Deploying vm during HA process, so skipping disable threshold check"); } return; } diff --git a/plugins/host-allocators/random/pom.xml b/plugins/host-allocators/random/pom.xml index 8c8bd99b195..f01494914ce 100644 --- a/plugins/host-allocators/random/pom.xml +++ b/plugins/host-allocators/random/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java b/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java index 70920df5eb5..f15f3f20001 100644 --- a/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java +++ b/plugins/host-allocators/random/src/main/java/com/cloud/agent/manager/allocator/impl/RandomAllocator.java @@ -22,10 +22,10 @@ import java.util.List; import javax.inject.Inject; -import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.ListUtils; -import org.apache.log4j.Logger; +import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import com.cloud.agent.manager.allocator.HostAllocator; @@ -40,14 +40,15 @@ import com.cloud.host.HostVO; import com.cloud.host.dao.HostDao; import com.cloud.offering.ServiceOffering; import com.cloud.resource.ResourceManager; +import com.cloud.storage.VMTemplateVO; import com.cloud.utils.Pair; import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; @Component public class RandomAllocator extends AdapterBase implements HostAllocator { - private static final Logger s_logger = Logger.getLogger(RandomAllocator.class); @Inject private HostDao _hostDao; @Inject @@ -59,6 +60,27 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { @Inject private CapacityManager capacityManager; + protected List listHostsByTags(Host.Type type, long dcId, Long podId, Long clusterId, String offeringHostTag, String templateTag) { + List taggedHosts = new ArrayList<>(); + if (offeringHostTag != null) { + taggedHosts.addAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, offeringHostTag)); + } + if (templateTag != null) { + List templateTaggedHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, templateTag); + if (taggedHosts.isEmpty()) { + taggedHosts = templateTaggedHosts; + } else { + taggedHosts.retainAll(templateTaggedHosts); + } + } + if (logger.isDebugEnabled()) { + logger.debug(String.format("Found %d hosts %s with type: %s, zone ID: %d, pod ID: %d, cluster ID: %s, offering host tag(s): %s, template tag: %s", + taggedHosts.size(), + (taggedHosts.isEmpty() ? "" : String.format("(%s)", StringUtils.join(taggedHosts.stream().map(HostVO::getId).toArray(), ","))), + type.name(), dcId, podId, clusterId, offeringHostTag, templateTag)); + } + return taggedHosts; + } private List findSuitableHosts(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { @@ -72,37 +94,41 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { if (type == Host.Type.Storage) { return suitableHosts; } - String hostTag = offering.getHostTag(); - if (hostTag != null) { - s_logger.debug(String.format("Looking for hosts in dc [%s], pod [%s], cluster [%s] and complying with host tag [%s].", dcId, podId, clusterId, hostTag)); + String offeringHostTag = offering.getHostTag(); + VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate(); + String templateTag = template.getTemplateTag(); + String hostTag = null; + if (ObjectUtils.anyNull(offeringHostTag, templateTag)) { + hostTag = offeringHostTag; + hostTag = hostTag == null ? templateTag : String.format("%s, %s", hostTag, templateTag); + logger.debug(String.format("Looking for hosts in dc [%s], pod [%s], cluster [%s] and complying with host tag(s): [%s]", dcId, podId, clusterId, hostTag)); } else { - s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId); + logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId); } if (hosts != null) { // retain all computing hosts, regardless of whether they support routing...it's random after all hostsCopy = new ArrayList(hosts); - if (hostTag != null) { - hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag)); + if (ObjectUtils.anyNotNull(offeringHostTag, templateTag)) { + hostsCopy.retainAll(listHostsByTags(type, dcId, podId, clusterId, offeringHostTag, templateTag)); } else { hostsCopy.retainAll(_hostDao.listAllHostsThatHaveNoRuleTag(type, clusterId, podId, dcId)); } } else { // list all computing hosts, regardless of whether they support routing...it's random after all - hostsCopy = new ArrayList(); - if (hostTag != null) { - hostsCopy = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag); + if (offeringHostTag != null) { + hostsCopy = listHostsByTags(type, dcId, podId, clusterId, offeringHostTag, templateTag); } else { hostsCopy = _hostDao.listAllHostsThatHaveNoRuleTag(type, clusterId, podId, dcId); } } - hostsCopy = ListUtils.union(hostsCopy, _hostDao.findHostsWithTagRuleThatMatchComputeOferringTags(hostTag)); + hostsCopy = ListUtils.union(hostsCopy, _hostDao.findHostsWithTagRuleThatMatchComputeOferringTags(offeringHostTag)); if (hostsCopy.isEmpty()) { - s_logger.error(String.format("No suitable host found for vm [%s] with tags [%s].", vmProfile, hostTag)); + logger.error(String.format("No suitable host found for vm [%s] with tags [%s].", vmProfile, hostTag)); throw new CloudRuntimeException(String.format("No suitable host found for vm [%s].", vmProfile)); } - s_logger.debug("Random Allocator found " + hostsCopy.size() + " hosts"); + logger.debug("Random Allocator found " + hostsCopy.size() + " hosts"); if (hostsCopy.size() == 0) { return suitableHosts; } @@ -112,25 +138,25 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { break; } if (avoid.shouldAvoid(host)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " is in avoid set, skipping this and trying other available hosts"); + if (logger.isDebugEnabled()) { + logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " is in avoid set, skipping this and trying other available hosts"); } continue; } Pair cpuCapabilityAndCapacity = capacityManager.checkIfHostHasCpuCapabilityAndCapacity(host, offering, considerReservedCapacity); if (!cpuCapabilityAndCapacity.first() || !cpuCapabilityAndCapacity.second()) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Not using host " + host.getId() + "; host has cpu capability? " + cpuCapabilityAndCapacity.first() + ", host has capacity?" + cpuCapabilityAndCapacity.second()); + if (logger.isDebugEnabled()) { + logger.debug("Not using host " + host.getId() + "; host has cpu capability? " + cpuCapabilityAndCapacity.first() + ", host has capacity?" + cpuCapabilityAndCapacity.second()); } continue; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Found a suitable host, adding to list: " + host.getId()); + if (logger.isDebugEnabled()) { + logger.debug("Found a suitable host, adding to list: " + host.getId()); } suitableHosts.add(host); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Random Host Allocator returning " + suitableHosts.size() + " suitable hosts"); + if (logger.isDebugEnabled()) { + logger.debug("Random Host Allocator returning " + suitableHosts.size() + " suitable hosts"); } return suitableHosts; } @@ -145,8 +171,8 @@ public class RandomAllocator extends AdapterBase implements HostAllocator { ExcludeList avoid, List hosts, int returnUpTo, boolean considerReservedCapacity) { if (CollectionUtils.isEmpty(hosts)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Random Allocator found 0 hosts as given host list is empty"); + if (logger.isDebugEnabled()) { + logger.debug("Random Allocator found 0 hosts as given host list is empty"); } return new ArrayList(); } diff --git a/plugins/host-allocators/random/src/test/java/com/cloud/agent/manager/allocator/impl/RandomAllocatorTest.java b/plugins/host-allocators/random/src/test/java/com/cloud/agent/manager/allocator/impl/RandomAllocatorTest.java new file mode 100644 index 00000000000..538d7157184 --- /dev/null +++ b/plugins/host-allocators/random/src/test/java/com/cloud/agent/manager/allocator/impl/RandomAllocatorTest.java @@ -0,0 +1,80 @@ +// 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.manager.allocator.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; + +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; + +@RunWith(MockitoJUnitRunner.class) +public class RandomAllocatorTest { + + @Mock + HostDao hostDao; + @InjectMocks + RandomAllocator randomAllocator; + + @Test + public void testListHostsByTags() { + Host.Type type = Host.Type.Routing; + Long id = 1L; + String templateTag = "tag1"; + String offeringTag = "tag2"; + HostVO host1 = Mockito.mock(HostVO.class); + HostVO host2 = Mockito.mock(HostVO.class); + Mockito.when(hostDao.listByHostTag(type, id, id, id, offeringTag)).thenReturn(List.of(host1, host2)); + + // No template tagged host + Mockito.when(hostDao.listByHostTag(type, id, id, id, templateTag)).thenReturn(new ArrayList<>()); + List result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, templateTag); + Assert.assertTrue(CollectionUtils.isEmpty(result)); + + // Different template tagged host + HostVO host3 = Mockito.mock(HostVO.class); + Mockito.when(hostDao.listByHostTag(type, id, id, id, templateTag)).thenReturn(List.of(host3)); + result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, templateTag); + Assert.assertTrue(CollectionUtils.isEmpty(result)); + + // Matching template tagged host + Mockito.when(hostDao.listByHostTag(type, id, id, id, templateTag)).thenReturn(List.of(host1)); + result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, templateTag); + Assert.assertFalse(CollectionUtils.isEmpty(result)); + Assert.assertEquals(1, result.size()); + + // No template tag + result = randomAllocator.listHostsByTags(type, id, id, id, offeringTag, null); + Assert.assertFalse(CollectionUtils.isEmpty(result)); + Assert.assertEquals(2, result.size()); + + // No offering tag + result = randomAllocator.listHostsByTags(type, id, id, id, null, templateTag); + Assert.assertFalse(CollectionUtils.isEmpty(result)); + Assert.assertEquals(1, result.size()); + } +} diff --git a/plugins/hypervisors/baremetal/pom.xml b/plugins/hypervisors/baremetal/pom.xml index 6150bedfb55..d866c9b47e2 100755 --- a/plugins/hypervisors/baremetal/pom.xml +++ b/plugins/hypervisors/baremetal/pom.xml @@ -22,7 +22,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml cloud-plugin-hypervisor-baremetal @@ -45,7 +45,7 @@ com.sun.xml.bind jaxb-impl - ${cs.jaxb.version} + ${cs.jaxb.impl.version} diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalDiscoverer.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalDiscoverer.java index 3bdd2e81fb5..321369b24b9 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalDiscoverer.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalDiscoverer.java @@ -33,7 +33,6 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; import org.apache.cloudstack.api.ApiConstants; -import org.apache.log4j.Logger; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; @@ -61,7 +60,6 @@ import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.VMInstanceDao; public class BareMetalDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter { - protected static final Logger s_logger = Logger.getLogger(BareMetalDiscoverer.class); @Inject protected VMInstanceDao _vmDao = null; @@ -92,25 +90,25 @@ public class BareMetalDiscoverer extends DiscovererBase implements Discoverer, R if (!url.getScheme().equals("http")) { String msg = "urlString is not http so we're not taking care of the discovery for this: " + url; - s_logger.debug(msg); + logger.debug(msg); return null; } if (clusterId == null) { String msg = "must specify cluster Id when add host"; - s_logger.debug(msg); + logger.debug(msg); throw new RuntimeException(msg); } if (podId == null) { String msg = "must specify pod Id when add host"; - s_logger.debug(msg); + logger.debug(msg); throw new RuntimeException(msg); } ClusterVO cluster = _clusterDao.findById(clusterId); if (cluster == null || (cluster.getHypervisorType() != HypervisorType.BareMetal)) { - if (s_logger.isInfoEnabled()) - s_logger.info("invalid cluster id or cluster is not for Bare Metal hosts"); + if (logger.isInfoEnabled()) + logger.info("invalid cluster id or cluster is not for Bare Metal hosts"); return null; } @@ -132,14 +130,14 @@ public class BareMetalDiscoverer extends DiscovererBase implements Discoverer, R + injectScript); } - final Script2 command = new Script2(scriptPath, s_logger); + final Script2 command = new Script2(scriptPath, logger); command.add("ping"); command.add("hostname="+ipmiIp); command.add("usrname="+username); command.add("password="+password, ParamType.PASSWORD); final String result = command.execute(); if (result != null) { - s_logger.warn(String.format("Can not set up ipmi connection(ip=%1$s, username=%2$s, password=%3$s, args) because %4$s", ipmiIp, username, "******", result)); + logger.warn(String.format("Can not set up ipmi connection(ip=%1$s, username=%2$s, password=%3$s, args) because %4$s", ipmiIp, username, "******", result)); return null; } @@ -205,11 +203,11 @@ public class BareMetalDiscoverer extends DiscovererBase implements Discoverer, R zone.setDhcpProvider(Network.Provider.ExternalDhcpServer.getName()); _dcDao.update(zone.getId(), zone); - s_logger.debug(String.format("Discover Bare Metal host successfully(ip=%1$s, username=%2$s, password=%3$s," + + logger.debug(String.format("Discover Bare Metal host successfully(ip=%1$s, username=%2$s, password=%3$s," + "cpuNum=%4$s, cpuCapacity-%5$s, memCapacity=%6$s)", ipmiIp, username, "******", cpuNum, cpuCapacity, memCapacity)); return resources; } catch (Exception e) { - s_logger.warn("Can not set up bare metal agent", e); + logger.warn("Can not set up bare metal agent", e); } return null; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalGuru.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalGuru.java index f82ad489b8d..a1b306b66c9 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalGuru.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalGuru.java @@ -27,7 +27,6 @@ import java.util.Map; import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -39,7 +38,6 @@ import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachineProfile; public class BareMetalGuru extends HypervisorGuruBase implements HypervisorGuru { - private static final Logger s_logger = Logger.getLogger(BareMetalGuru.class); @Inject GuestOSDao _guestOsDao; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalPlanner.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalPlanner.java index c37b51df5e9..318ac225c8c 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalPlanner.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalPlanner.java @@ -24,7 +24,6 @@ import javax.naming.ConfigurationException; import com.cloud.utils.NumbersUtil; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; import com.cloud.capacity.CapacityManager; import com.cloud.dc.ClusterDetailsDao; @@ -51,7 +50,6 @@ import com.cloud.vm.VirtualMachine; import com.cloud.vm.VirtualMachineProfile; public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { - private static final Logger s_logger = Logger.getLogger(BareMetalPlanner.class); @Inject protected DataCenterDao _dcDao; @Inject @@ -82,7 +80,7 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { DataCenter dc = _dcDao.findById(h.getDataCenterId()); Pod pod = _podDao.findById(h.getPodId()); Cluster c = _clusterDao.findById(h.getClusterId()); - s_logger.debug("Start baremetal vm " + vm.getId() + " on last stayed host " + h.getId()); + logger.debug("Start baremetal vm " + vm.getId() + " on last stayed host " + h.getId()); return new DeployDestination(dc, pod, c, h); } @@ -114,7 +112,7 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { } if (target == null) { - s_logger.warn("Cannot find host with tag " + hostTag + " use capacity from service offering"); + logger.warn("Cannot find host with tag " + hostTag + " use capacity from service offering"); cpu_requested = offering.getCpu() * offering.getSpeed(); ram_requested = offering.getRamSize() * 1024L * 1024L; } else { @@ -126,7 +124,7 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { if (haVmTag == null) { hosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); } else { - s_logger.warn("Cannot find HA host with tag " + haVmTag + " in cluster id=" + cluster.getId() + ", pod id=" + cluster.getPodId() + ", data center id=" + + logger.warn("Cannot find HA host with tag " + haVmTag + " in cluster id=" + cluster.getId() + ", pod id=" + cluster.getPodId() + ", data center id=" + cluster.getDataCenterId()); return null; } @@ -138,7 +136,7 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { Float memoryOvercommitRatio = Float.parseFloat(cluster_detail_ram.getValue()); if (_capacityMgr.checkIfHostHasCapacity(h.getId(), cpu_requested, ram_requested, false, cpuOvercommitRatio, memoryOvercommitRatio, true)) { - s_logger.debug("Find host " + h.getId() + " has enough capacity"); + logger.debug("Find host " + h.getId() + " has enough capacity"); DataCenter dc = _dcDao.findById(h.getDataCenterId()); Pod pod = _podDao.findById(h.getPodId()); return new DeployDestination(dc, pod, cluster, h); @@ -146,7 +144,7 @@ public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { } } - s_logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, NumbersUtil.toHumanReadableSize(ram_requested))); + logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, NumbersUtil.toHumanReadableSize(ram_requested))); return null; } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java index 8265f951f8a..940897de3c9 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java @@ -45,14 +45,12 @@ import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd; import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd; import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.Date; import java.util.List; public class BareMetalTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter { - private final static Logger s_logger = Logger.getLogger(BareMetalTemplateAdapter.class); @Inject HostDao _hostDao; @Inject @@ -141,7 +139,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem zoneName = "all zones"; } - s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); + logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId()); String eventType = EventTypes.EVENT_TEMPLATE_DELETE; List templateHostVOs = this._tmpltStoreDao.listByTemplate(templateId); @@ -151,7 +149,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem try { lock = _tmpltStoreDao.acquireInLockTable(vo.getId()); if (lock == null) { - s_logger.debug("Failed to acquire lock when deleting templateDataStoreVO with ID: " + vo.getId()); + logger.debug("Failed to acquire lock when deleting templateDataStoreVO with ID: " + vo.getId()); success = false; break; } @@ -184,7 +182,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem } } - s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); + logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName); // If there are no more non-destroyed template host entries for this template, delete it if (success && (_tmpltStoreDao.listByTemplate(templateId).size() == 0)) { @@ -194,7 +192,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem try { if (lock == null) { - s_logger.debug("Failed to acquire lock when deleting template with ID: " + templateId); + logger.debug("Failed to acquire lock when deleting template with ID: " + templateId); success = false; } else if (_tmpltDao.remove(templateId)) { // Decrement the number of templates and total secondary storage space used by the account. @@ -207,7 +205,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem _tmpltDao.releaseFromLockTable(lock.getId()); } } - s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed."); + logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed."); } return success; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BaremetalManagerImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BaremetalManagerImpl.java index b1aafc692ef..bf991b77e1c 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BaremetalManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/manager/BaremetalManagerImpl.java @@ -32,7 +32,6 @@ import com.cloud.utils.fsm.StateMachine2; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.dao.VMInstanceDao; import org.apache.cloudstack.api.BaremetalProvisionDoneNotificationCmd; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.AddBaremetalHostCmd; @@ -46,7 +45,6 @@ import com.cloud.vm.VirtualMachine.Event; import com.cloud.vm.VirtualMachine.State; public class BaremetalManagerImpl extends ManagerBase implements BaremetalManager, StateListener { - private static final Logger s_logger = Logger.getLogger(BaremetalManagerImpl.class); @Inject protected HostDao _hostDao; @@ -93,17 +91,17 @@ public class BaremetalManagerImpl extends ManagerBase implements BaremetalManage HostVO host = _hostDao.findById(vo.getHostId()); if (host == null) { - s_logger.debug("Skip oldState " + oldState + " to " + "newState " + newState + " transimtion"); + logger.debug("Skip oldState " + oldState + " to " + "newState " + newState + " transimtion"); return true; } _hostDao.loadDetails(host); if (newState == State.Starting) { host.setDetail("vmName", vo.getInstanceName()); - s_logger.debug("Add vmName " + host.getDetail("vmName") + " to host " + host.getId() + " details"); + logger.debug("Add vmName " + host.getDetail("vmName") + " to host " + host.getId() + " details"); } else { if (host.getDetail("vmName") != null && host.getDetail("vmName").equalsIgnoreCase(vo.getInstanceName())) { - s_logger.debug("Remove vmName " + host.getDetail("vmName") + " from host " + host.getId() + " details"); + logger.debug("Remove vmName " + host.getDetail("vmName") + " from host " + host.getId() + " details"); host.getDetails().remove("vmName"); } } @@ -150,7 +148,7 @@ public class BaremetalManagerImpl extends ManagerBase implements BaremetalManage vm.setState(State.Running); vm.setLastHostId(vm.getHostId()); vmDao.update(vm.getId(), vm); - s_logger.debug(String.format("received baremetal provision done notification for vm[id:%s name:%s] running on host[mac:%s, ip:%s]", + logger.debug(String.format("received baremetal provision done notification for vm[id:%s name:%s] running on host[mac:%s, ip:%s]", vm.getId(), vm.getInstanceName(), host.getPrivateMacAddress(), host.getPrivateIpAddress())); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java index fc7596a9dd6..509fd340dae 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalPingServiceImpl.java @@ -32,7 +32,6 @@ import javax.inject.Inject; import org.apache.cloudstack.api.AddBaremetalPxeCmd; import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd; import org.apache.cloudstack.api.ListBaremetalPxeServersCmd; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.baremetal.IpmISetBootDevCommand; @@ -68,7 +67,6 @@ import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachineProfile; public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements BaremetalPxeService { - private static final Logger s_logger = Logger.getLogger(BareMetalPingServiceImpl.class); @Inject ResourceManager _resourceMgr; @Inject @@ -107,19 +105,19 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements new PreparePxeServerCommand(ip, mac, mask, gateway, dns, tpl, profile.getVirtualMachine().getInstanceName(), dest.getHost().getName()); PreparePxeServerAnswer ans = (PreparePxeServerAnswer)_agentMgr.send(pxeServerId, cmd); if (!ans.getResult()) { - s_logger.warn("Unable tot program PXE server: " + pxeVo.getId() + " because " + ans.getDetails()); + logger.warn("Unable tot program PXE server: " + pxeVo.getId() + " because " + ans.getDetails()); return false; } IpmISetBootDevCommand bootCmd = new IpmISetBootDevCommand(BootDev.pxe); Answer anw = _agentMgr.send(dest.getHost().getId(), bootCmd); if (!anw.getResult()) { - s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + anw.getDetails()); + logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + anw.getDetails()); } return anw.getResult(); } catch (Exception e) { - s_logger.warn("Cannot prepare PXE server", e); + logger.warn("Cannot prepare PXE server", e); return false; } } @@ -150,7 +148,7 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements Answer ans = _agentMgr.send(pxeServerId, cmd); return ans.getResult(); } catch (Exception e) { - s_logger.debug("Prepare for creating baremetal template failed", e); + logger.debug("Prepare for creating baremetal template failed", e); return false; } } @@ -219,7 +217,7 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements try { uri = new URI(cmd.getUrl()); } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new IllegalArgumentException(e.getMessage()); } String ipAddress = uri.getHost(); @@ -244,7 +242,7 @@ public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements try { resource.configure("PING PXE resource", params); } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new CloudRuntimeException(e.getMessage()); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalResourceBase.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalResourceBase.java index 0cdd0f12822..007640e8aad 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalResourceBase.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BareMetalResourceBase.java @@ -31,7 +31,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -83,7 +82,6 @@ import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.dao.VMInstanceDao; public class BareMetalResourceBase extends ManagerBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(BareMetalResourceBase.class); protected String _uuid; protected String _zone; protected String _pod; @@ -176,20 +174,20 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource try { ipmiIface = configDao.getValue(Config.BaremetalIpmiLanInterface.key()); } catch (Exception e) { - s_logger.debug(e.getMessage(), e); + logger.debug(e.getMessage(), e); } try { ipmiRetryTimes = Integer.parseInt(configDao.getValue(Config.BaremetalIpmiRetryTimes.key())); } catch (Exception e) { - s_logger.debug(e.getMessage(), e); + logger.debug(e.getMessage(), e); } try { provisionDoneNotificationOn = Boolean.valueOf(configDao.getValue(Config.BaremetalProvisionDoneNotificationEnabled.key())); isProvisionDoneNotificationTimeout = Integer.parseInt(configDao.getValue(Config.BaremetalProvisionDoneNotificationTimeout.key())); } catch (Exception e) { - s_logger.debug(e.getMessage(), e); + logger.debug(e.getMessage(), e); } String injectScript = "scripts/util/ipmi.py"; @@ -198,7 +196,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource throw new ConfigurationException("Cannot find ping script " + scriptPath); } String pythonPath = "/usr/bin/python"; - _pingCommand = new Script2(pythonPath, s_logger); + _pingCommand = new Script2(pythonPath, logger); _pingCommand.add(scriptPath); _pingCommand.add("ping"); _pingCommand.add("interface=" + ipmiIface); @@ -206,7 +204,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource _pingCommand.add("usrname=" + _username); _pingCommand.add("password=" + _password, ParamType.PASSWORD); - _setPxeBootCommand = new Script2(pythonPath, s_logger); + _setPxeBootCommand = new Script2(pythonPath, logger); _setPxeBootCommand.add(scriptPath); _setPxeBootCommand.add("boot_dev"); _setPxeBootCommand.add("interface=" + ipmiIface); @@ -215,7 +213,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource _setPxeBootCommand.add("password=" + _password, ParamType.PASSWORD); _setPxeBootCommand.add("dev=pxe"); - _setDiskBootCommand = new Script2(pythonPath, s_logger); + _setDiskBootCommand = new Script2(pythonPath, logger); _setDiskBootCommand.add(scriptPath); _setDiskBootCommand.add("boot_dev"); _setDiskBootCommand.add("interface=" + ipmiIface); @@ -224,7 +222,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource _setDiskBootCommand.add("password=" + _password, ParamType.PASSWORD); _setDiskBootCommand.add("dev=disk"); - _rebootCommand = new Script2(pythonPath, s_logger); + _rebootCommand = new Script2(pythonPath, logger); _rebootCommand.add(scriptPath); _rebootCommand.add("reboot"); _rebootCommand.add("interface=" + ipmiIface); @@ -232,7 +230,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource _rebootCommand.add("usrname=" + _username); _rebootCommand.add("password=" + _password, ParamType.PASSWORD); - _getStatusCommand = new Script2(pythonPath, s_logger); + _getStatusCommand = new Script2(pythonPath, logger); _getStatusCommand.add(scriptPath); _getStatusCommand.add("ping"); _getStatusCommand.add("interface=" + ipmiIface); @@ -240,7 +238,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource _getStatusCommand.add("usrname=" + _username); _getStatusCommand.add("password=" + _password, ParamType.PASSWORD); - _powerOnCommand = new Script2(pythonPath, s_logger); + _powerOnCommand = new Script2(pythonPath, logger); _powerOnCommand.add(scriptPath); _powerOnCommand.add("power"); _powerOnCommand.add("interface=" + ipmiIface); @@ -249,7 +247,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource _powerOnCommand.add("password=" + _password, ParamType.PASSWORD); _powerOnCommand.add("action=on"); - _powerOffCommand = new Script2(pythonPath, s_logger); + _powerOffCommand = new Script2(pythonPath, logger); _powerOffCommand.add(scriptPath); _powerOffCommand.add("power"); _powerOffCommand.add("interface=" + ipmiIface); @@ -258,7 +256,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource _powerOffCommand.add("password=" + _password, ParamType.PASSWORD); _powerOffCommand.add("action=soft"); - _forcePowerOffCommand = new Script2(pythonPath, s_logger); + _forcePowerOffCommand = new Script2(pythonPath, logger); _forcePowerOffCommand.add(scriptPath); _forcePowerOffCommand.add("power"); _forcePowerOffCommand.add("interface=" + ipmiIface); @@ -267,7 +265,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource _forcePowerOffCommand.add("password=" + _password, ParamType.PASSWORD); _forcePowerOffCommand.add("action=off"); - _bootOrRebootCommand = new Script2(pythonPath, s_logger); + _bootOrRebootCommand = new Script2(pythonPath, logger); _bootOrRebootCommand.add(scriptPath); _bootOrRebootCommand.add("boot_or_reboot"); _bootOrRebootCommand.add("interface=" + ipmiIface); @@ -299,11 +297,11 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource res = cmd.execute(interpreter); } if (res != null && res.startsWith("Error: Unable to establish LAN")) { - s_logger.warn("IPMI script timeout(" + cmd.toString() + "), will retry " + retry + " times"); + logger.warn("IPMI script timeout(" + cmd.toString() + "), will retry " + retry + " times"); try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while waiting to retry running script."); + logger.debug("[ignored] interrupted while waiting to retry running script."); } continue; } else if (res == null) { @@ -313,7 +311,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource } } - s_logger.warn("IPMI Scirpt failed due to " + res + "(" + cmd.toString() + ")"); + logger.warn("IPMI Scirpt failed due to " + res + "(" + cmd.toString() + ")"); return false; } @@ -379,12 +377,12 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource if (!ipmiPing()) { Thread.sleep(1000); if (!ipmiPing()) { - s_logger.warn("Cannot ping ipmi nic " + _ip); + logger.warn("Cannot ping ipmi nic " + _ip); return null; } } } catch (Exception e) { - s_logger.debug("Cannot ping ipmi nic " + _ip, e); + logger.debug("Cannot ping ipmi nic " + _ip, e); return null; } @@ -419,11 +417,11 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource String bootDev = cmd.getBootDev().name(); if (!doScript(bootCmd)) { - s_logger.warn("Set " + _ip + " boot dev to " + bootDev + "failed"); + logger.warn("Set " + _ip + " boot dev to " + bootDev + "failed"); return new Answer(cmd, false, "Set " + _ip + " boot dev to " + bootDev + "failed"); } - s_logger.warn("Set " + _ip + " boot dev to " + bootDev + "Success"); + logger.warn("Set " + _ip + " boot dev to " + bootDev + "Success"); return new Answer(cmd, true, "Set " + _ip + " boot dev to " + bootDev + "Success"); } @@ -494,7 +492,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource return Answer.createUnsupportedCommandAnswer(cmd); } } catch (Throwable t) { - s_logger.debug(t.getMessage(), t); + logger.debug(t.getMessage(), t); return new Answer(cmd, false, t.getMessage()); } } @@ -545,7 +543,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource OutputInterpreter.AllLinesParser interpreter = new OutputInterpreter.AllLinesParser(); if (!doScript(_getStatusCommand, interpreter)) { success = true; - s_logger.warn("Cannot get power status of " + getName() + ", assume VM state changed successfully"); + logger.warn("Cannot get power status of " + getName() + ", assume VM state changed successfully"); break; } @@ -600,7 +598,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource try { TimeUnit.SECONDS.sleep(5); } catch (InterruptedException e) { - s_logger.warn(e.getMessage(), e); + logger.warn(e.getMessage(), e); } q = QueryBuilder.create(VMInstanceVO.class); @@ -614,21 +612,21 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource return new StartAnswer(cmd); } - s_logger.debug(String.format("still wait for baremetal provision done notification for vm[name:%s], current vm state is %s", vmvo.getInstanceName(), vmvo.getState())); + logger.debug(String.format("still wait for baremetal provision done notification for vm[name:%s], current vm state is %s", vmvo.getInstanceName(), vmvo.getState())); } return new StartAnswer(cmd, String.format("timeout after %s seconds, no baremetal provision done notification received. vm[name:%s] failed to start", isProvisionDoneNotificationTimeout, vm.getName())); } } - s_logger.debug("Start bare metal vm " + vm.getName() + "successfully"); + logger.debug("Start bare metal vm " + vm.getName() + "successfully"); _vmName = vm.getName(); return new StartAnswer(cmd); } protected ReadyAnswer execute(ReadyCommand cmd) { // derived resource should check if the PXE server is ready - s_logger.debug("Bare metal resource " + getName() + " is ready"); + logger.debug("Bare metal resource " + getName() + " is ready"); return new ReadyAnswer(cmd); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java index bf6932f05d4..79590f08ffa 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetaNetworkGuru.java @@ -22,7 +22,6 @@ import javax.inject.Inject; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; -import org.apache.log4j.Logger; import com.cloud.dc.DataCenter; import com.cloud.dc.Pod; @@ -59,7 +58,6 @@ import com.cloud.vm.ReservationContext; import com.cloud.vm.VirtualMachineProfile; public class BaremetaNetworkGuru extends DirectPodBasedNetworkGuru { - private static final Logger s_logger = Logger.getLogger(BaremetaNetworkGuru.class); @Inject private HostDao _hostDao; @Inject @@ -151,14 +149,14 @@ public class BaremetaNetworkGuru extends DirectPodBasedNetworkGuru { * nic.setBroadcastUri(null); nic.setIsolationUri(null); */ - s_logger.debug("Allocated a nic " + nic + " for " + vm); + logger.debug("Allocated a nic " + nic + " for " + vm); } private void getBaremetalIp(NicProfile nic, Pod pod, VirtualMachineProfile vm, Network network, String requiredIp) throws InsufficientAddressCapacityException, ConcurrentOperationException { DataCenter dc = _dcDao.findById(pod.getDataCenterId()); if (nic.getIPv4Address() == null) { - s_logger.debug(String.format("Requiring ip address: %s", nic.getIPv4Address())); + logger.debug(String.format("Requiring ip address: %s", nic.getIPv4Address())); PublicIp ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), requiredIp, false, false); nic.setIPv4Address(ip.getAddress().toString()); nic.setFormat(AddressFormat.Ip4); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java index 807babcb09f..e39b40cfc68 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpElement.java @@ -24,7 +24,6 @@ import java.util.Set; import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.baremetal.database.BaremetalDhcpVO; import com.cloud.dc.DataCenter.NetworkType; @@ -56,7 +55,6 @@ import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.NicDao; public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProvider { - private static final Logger s_logger = Logger.getLogger(BaremetalDhcpElement.class); private static final Map> capabilities; @Inject @@ -98,7 +96,7 @@ public class BaremetalDhcpElement extends AdapterBase implements DhcpServiceProv public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (offering.isSystemOnly() || !canHandle(dest, offering.getTrafficType(), network.getGuestType())) { - s_logger.debug("BaremetalDhcpElement can not handle networkoffering: " + offering.getName()); + logger.debug("BaremetalDhcpElement can not handle networkoffering: " + offering.getName()); return false; } return true; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java index f50681abe7b..99bedbff05e 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpManagerImpl.java @@ -33,7 +33,6 @@ import javax.naming.ConfigurationException; import org.apache.cloudstack.api.AddBaremetalDhcpCmd; import org.apache.cloudstack.api.ListBaremetalDhcpCmd; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -75,7 +74,6 @@ import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDhcpManager, ResourceStateAdapter { - private static final org.apache.log4j.Logger s_logger = Logger.getLogger(BaremetalDhcpManagerImpl.class); protected String _name; @Inject DataCenterDao _dcDao; @@ -155,15 +153,15 @@ public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDh try { Answer ans = _agentMgr.send(h.getId(), dhcpCommand); if (ans.getResult()) { - s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), + logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", h.getPrivateIpAddress(), nic.getIPv4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName())); return true; } else { - s_logger.debug(errMsg + " " + ans.getDetails()); + logger.debug(errMsg + " " + ans.getDetails()); throw new ResourceUnavailableException(errMsg, DataCenter.class, zoneId); } } catch (Exception e) { - s_logger.debug(errMsg, e); + logger.debug(errMsg, e); throw new ResourceUnavailableException(errMsg + e.getMessage(), DataCenter.class, zoneId); } } @@ -226,7 +224,7 @@ public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDh try { uri = new URI(cmd.getUrl()); } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new IllegalArgumentException(e.getMessage()); } @@ -260,7 +258,7 @@ public class BaremetalDhcpManagerImpl extends ManagerBase implements BaremetalDh throw new CloudRuntimeException("Unsupport DHCP server type: " + cmd.getDhcpType()); } } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new CloudRuntimeException(e.getMessage()); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java index 0d3cdce74e8..9fe3f6ad516 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java @@ -27,7 +27,6 @@ import java.util.Map; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -44,7 +43,6 @@ import com.cloud.resource.ServerResource; import com.cloud.utils.component.ManagerBase; public class BaremetalDhcpResourceBase extends ManagerBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(BaremetalDhcpResourceBase.class); String _name; String _guid; String _username; @@ -129,7 +127,7 @@ public class BaremetalDhcpResourceBase extends ManagerBase implements ServerReso } protected ReadyAnswer execute(ReadyCommand cmd) { - s_logger.debug("External DHCP resource " + _name + " is ready"); + logger.debug("External DHCP resource " + _name + " is ready"); return new ReadyAnswer(cmd); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java index 8fd2c35ced9..e92cbf2c204 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java @@ -27,7 +27,6 @@ import java.util.Map; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -41,14 +40,13 @@ import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; public class BaremetalDhcpdResource extends BaremetalDhcpResourceBase { - private static final Logger s_logger = Logger.getLogger(BaremetalDhcpdResource.class); @Override public boolean configure(String name, Map params) throws ConfigurationException { com.trilead.ssh2.Connection sshConnection = null; try { super.configure(name, params); - s_logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, "******")); + logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, "******")); sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password); if (sshConnection == null) { throw new ConfigurationException(String.format("Cannot connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); @@ -89,10 +87,10 @@ public class BaremetalDhcpdResource extends BaremetalDhcpResourceBase { throw new ConfigurationException("prepare Dhcpd at " + _ip + " failed, command:" + cmd); } - s_logger.debug("Dhcpd resource configure successfully"); + logger.debug("Dhcpd resource configure successfully"); return true; } catch (Exception e) { - s_logger.debug("Dhcpd resource configure failed", e); + logger.debug("Dhcpd resource configure failed", e); throw new ConfigurationException(e.getMessage()); } finally { SSHCmdHelper.releaseSshConnection(sshConnection); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java index 79f23cc46db..51acfe93d39 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java @@ -27,7 +27,6 @@ import java.util.Map; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -41,14 +40,13 @@ import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; public class BaremetalDnsmasqResource extends BaremetalDhcpResourceBase { - private static final Logger s_logger = Logger.getLogger(BaremetalDnsmasqResource.class); @Override public boolean configure(String name, Map params) throws ConfigurationException { com.trilead.ssh2.Connection sshConnection = null; try { super.configure(name, params); - s_logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, _password)); + logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, _password)); sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password); if (sshConnection == null) { throw new ConfigurationException(String.format("Cannot connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); @@ -81,10 +79,10 @@ public class BaremetalDnsmasqResource extends BaremetalDhcpResourceBase { } */ - s_logger.debug("Dnsmasq resource configure successfully"); + logger.debug("Dnsmasq resource configure successfully"); return true; } catch (Exception e) { - s_logger.debug("Dnsmasq resorce configure failed", e); + logger.debug("Dnsmasq resorce configure failed", e); throw new ConfigurationException(e.getMessage()); } finally { SSHCmdHelper.releaseSshConnection(sshConnection); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java index dbee3c4a91d..3775f4effc1 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java @@ -25,7 +25,6 @@ import java.util.Map; import javax.naming.ConfigurationException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -40,7 +39,6 @@ import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase { - private static final Logger s_logger = Logger.getLogger(BaremetalKickStartPxeResource.class); private static final String Name = "BaremetalKickStartPxeResource"; String _tftpDir; @@ -54,11 +52,11 @@ public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase { com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); - s_logger.debug(String.format("Trying to connect to kickstart PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); + logger.debug(String.format("Trying to connect to kickstart PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to kickstart PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } @@ -132,7 +130,7 @@ public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -143,7 +141,7 @@ public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase { return new Answer(cmd, true, "Success"); } catch (Exception e) { - s_logger.debug("Prepare for creating baremetal template failed", e); + logger.debug("Prepare for creating baremetal template failed", e); return new Answer(cmd, false, e.getMessage()); } finally { if (sshConnection != null) { @@ -168,7 +166,7 @@ public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase { try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -188,10 +186,10 @@ public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase { return new Answer(cmd, false, "prepare kickstart at pxe server " + _ip + " failed, command:" + script); } - s_logger.debug("Prepare kickstart PXE server successfully"); + logger.debug("Prepare kickstart PXE server successfully"); return new Answer(cmd, true, "Success"); } catch (Exception e) { - s_logger.debug("Prepare for kickstart server failed", e); + logger.debug("Prepare for kickstart server failed", e); return new Answer(cmd, false, e.getMessage()); } finally { if (sshConnection != null) { diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java index 8fe3d827ed4..169743881ed 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java @@ -33,7 +33,6 @@ import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd; import org.apache.cloudstack.api.AddBaremetalPxeCmd; import org.apache.cloudstack.api.ListBaremetalPxeServersCmd; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.baremetal.IpmISetBootDevCommand; @@ -80,7 +79,6 @@ import com.cloud.vm.dao.DomainRouterDao; import com.cloud.vm.dao.NicDao; public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase implements BaremetalPxeService { - private static final Logger s_logger = Logger.getLogger(BaremetalKickStartServiceImpl.class); @Inject ResourceManager _resourceMgr; @Inject @@ -170,7 +168,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple throw new CloudRuntimeException(String.format("cannot find id_rsa.cloud")); } if (!keyFile.exists()) { - s_logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); + logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); } return keyFile; } @@ -199,7 +197,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple cmd.setTemplateUuid(template.getUuid()); Answer aws = _agentMgr.send(pxeVo.getHostId(), cmd); if (!aws.getResult()) { - s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails()); + logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails()); return false; } @@ -234,7 +232,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple List tuple = parseKickstartUrl(profile); String cmd = String.format("/opt/cloud/bin/prepare_pxe.sh %s %s %s %s %s %s", tuple.get(1), tuple.get(2), profile.getTemplate().getUuid(), String.format("01-%s", nic.getMacAddress().replaceAll(":", "-")).toLowerCase(), tuple.get(0), nic.getMacAddress().toLowerCase()); - s_logger.debug(String.format("prepare pxe on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd)); + logger.debug(String.format("prepare pxe on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd)); ret = SshHelper.sshExecute(mgmtNic.getIPv4Address(), 3922, "root", getSystemVMKeyFile(), null, cmd); if (!ret.first()) { throw new CloudRuntimeException(String.format("failed preparing PXE in virtual router[id:%s], because %s", vr.getId(), ret.second())); @@ -242,7 +240,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple //String internalServerIp = "10.223.110.231"; cmd = String.format("/opt/cloud/bin/baremetal_snat.sh %s %s %s", mgmtNic.getIPv4Address(), internalServerIp, mgmtNic.getIPv4Gateway()); - s_logger.debug(String.format("prepare SNAT on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd)); + logger.debug(String.format("prepare SNAT on virtual router[ip:%s], cmd: %s", mgmtNic.getIPv4Address(), cmd)); ret = SshHelper.sshExecute(mgmtNic.getIPv4Address(), 3922, "root", getSystemVMKeyFile(), null, cmd); if (!ret.first()) { throw new CloudRuntimeException(String.format("failed preparing PXE in virtual router[id:%s], because %s", vr.getId(), ret.second())); @@ -267,12 +265,12 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple IpmISetBootDevCommand bootCmd = new IpmISetBootDevCommand(BootDev.pxe); Answer aws = _agentMgr.send(dest.getHost().getId(), bootCmd); if (!aws.getResult()) { - s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails()); + logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails()); } return aws.getResult(); } catch (Exception e) { - s_logger.warn("Cannot prepare PXE server", e); + logger.warn("Cannot prepare PXE server", e); return false; } } @@ -324,7 +322,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple try { uri = new URI(cmd.getUrl()); } catch (Exception e) { - s_logger.debug(e); + logger.debug(e); throw new IllegalArgumentException(e.getMessage()); } String ipAddress = uri.getHost(); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java index 416b3d0e3b3..96b2dbfeb93 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java @@ -29,7 +29,6 @@ import java.util.Map; import javax.naming.ConfigurationException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.trilead.ssh2.SCPClient; @@ -46,7 +45,6 @@ import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { - private static final Logger s_logger = Logger.getLogger(BaremetalPingPxeResource.class); private static final String Name = "BaremetalPingPxeResource"; String _storageServer; String _pingDir; @@ -98,11 +96,11 @@ public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); - s_logger.debug(String.format("Trying to connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); + logger.debug(String.format("Trying to connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); } @@ -152,7 +150,7 @@ public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -162,11 +160,11 @@ public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) { return new PreparePxeServerAnswer(cmd, "prepare PING at " + _ip + " failed, command:" + script); } - s_logger.debug("Prepare Ping PXE server successfully"); + logger.debug("Prepare Ping PXE server successfully"); return new PreparePxeServerAnswer(cmd); } catch (Exception e) { - s_logger.debug("Prepare PING pxe server failed", e); + logger.debug("Prepare PING pxe server failed", e); return new PreparePxeServerAnswer(cmd, e.getMessage()); } finally { if (sshConnection != null) { @@ -180,7 +178,7 @@ public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { try { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -190,11 +188,11 @@ public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) { return new Answer(cmd, false, "prepare for creating template failed, command:" + script); } - s_logger.debug("Prepare for creating template successfully"); + logger.debug("Prepare for creating template successfully"); return new Answer(cmd, true, "Success"); } catch (Exception e) { - s_logger.debug("Prepare for creating baremetal template failed", e); + logger.debug("Prepare for creating baremetal template failed", e); return new Answer(cmd, false, e.getMessage()); } finally { if (sshConnection != null) { @@ -238,7 +236,7 @@ public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { sshConnection.connect(null, 60000, 60000); if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); + logger.debug("SSH Failed to authenticate"); throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password)); } @@ -249,7 +247,7 @@ public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { return new Answer(cmd, true, "Success"); } catch (Exception e) { - s_logger.debug("Prepare for creating baremetal template failed", e); + logger.debug("Prepare for creating baremetal template failed", e); return new Answer(cmd, false, e.getMessage()); } finally { if (sshConnection != null) { diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeElement.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeElement.java index 17ec9021016..fa708e7be4c 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeElement.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeElement.java @@ -51,7 +51,6 @@ import com.cloud.vm.VirtualMachine.Type; import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.VMInstanceDao; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.HashMap; @@ -59,7 +58,6 @@ import java.util.Map; import java.util.Set; public class BaremetalPxeElement extends AdapterBase implements NetworkElement { - private static final Logger s_logger = Logger.getLogger(BaremetalPxeElement.class); private static final Map> capabilities; @Inject @@ -110,7 +108,7 @@ public class BaremetalPxeElement extends AdapterBase implements NetworkElement { } if (offering.isSystemOnly() || !canHandle(dest, offering.getTrafficType(), network.getGuestType())) { - s_logger.debug("BaremetalPxeElement can not handle network offering: " + offering.getName()); + logger.debug("BaremetalPxeElement can not handle network offering: " + offering.getName()); return false; } return true; diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java index 22f93959733..636ce360d03 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeManagerImpl.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.api.AddBaremetalPxeCmd; import org.apache.cloudstack.api.AddBaremetalPxePingServerCmd; import org.apache.cloudstack.api.ListBaremetalPxeServersCmd; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -71,7 +70,6 @@ import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; public class BaremetalPxeManagerImpl extends ManagerBase implements BaremetalPxeManager, ResourceStateAdapter { - private static final org.apache.log4j.Logger s_logger = Logger.getLogger(BaremetalPxeManagerImpl.class); @Inject DataCenterDao _dcDao; @Inject @@ -233,13 +231,13 @@ public class BaremetalPxeManagerImpl extends ManagerBase implements BaremetalPxe try { Answer ans = _agentMgr.send(pxeVo.getHostId(), cmd); if (!ans.getResult()) { - s_logger.debug(String.format("Add userdata to vm:%s failed because %s", vm.getInstanceName(), ans.getDetails())); + logger.debug(String.format("Add userdata to vm:%s failed because %s", vm.getInstanceName(), ans.getDetails())); return false; } else { return true; } } catch (Exception e) { - s_logger.debug(String.format("Add userdata to vm:%s failed", vm.getInstanceName()), e); + logger.debug(String.format("Add userdata to vm:%s failed", vm.getInstanceName()), e); return false; } } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeResourceBase.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeResourceBase.java index 5b5a959d597..01d1bf62717 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeResourceBase.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/BaremetalPxeResourceBase.java @@ -26,7 +26,6 @@ import java.util.Map; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; @@ -41,7 +40,6 @@ import com.cloud.resource.ServerResource; import com.cloud.utils.component.ManagerBase; public class BaremetalPxeResourceBase extends ManagerBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(BaremetalPxeResourceBase.class); String _name; String _guid; String _username; @@ -84,7 +82,7 @@ public class BaremetalPxeResourceBase extends ManagerBase implements ServerResou } protected ReadyAnswer execute(ReadyCommand cmd) { - s_logger.debug("Pxe resource " + _name + " is ready"); + logger.debug("Pxe resource " + _name + " is ready"); return new ReadyAnswer(cmd); } diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/Force10BaremetalSwitchBackend.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/Force10BaremetalSwitchBackend.java index e4dd5b1a5d8..3a013da7858 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/Force10BaremetalSwitchBackend.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/Force10BaremetalSwitchBackend.java @@ -27,7 +27,8 @@ import com.cloud.utils.xmlobject.XmlObject; import com.cloud.utils.xmlobject.XmlObjectParser; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -48,7 +49,7 @@ import java.util.List; * Created by frank on 9/2/14. */ public class Force10BaremetalSwitchBackend implements BaremetalSwitchBackend { - private Logger logger = Logger.getLogger(Force10BaremetalSwitchBackend.class); + private Logger logger = LogManager.getLogger(Force10BaremetalSwitchBackend.class); public static final String TYPE = "Force10"; private static List successHttpStatusCode = new ArrayList<>(); diff --git a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/SecurityGroupHttpClient.java b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/SecurityGroupHttpClient.java index b100929da96..b0053500464 100644 --- a/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/SecurityGroupHttpClient.java +++ b/plugins/hypervisors/baremetal/src/main/java/com/cloud/baremetal/networkservice/SecurityGroupHttpClient.java @@ -34,7 +34,8 @@ import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; @@ -46,7 +47,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; public class SecurityGroupHttpClient { - private static final Logger logger = Logger.getLogger(SecurityGroupHttpClient.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final String ARG_NAME = "args"; private static final String COMMAND = "command"; private JAXBContext context; diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalDhcpCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalDhcpCmd.java index 22a1c4eba90..379dee875f4 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalDhcpCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalDhcpCmd.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.api; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.cloudstack.context.CallContext; @@ -38,7 +37,6 @@ import com.cloud.exception.ResourceUnavailableException; @APICommand(name = "addBaremetalDhcp", description = "adds a baremetal dhcp server", responseObject = BaremetalDhcpResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class AddBaremetalDhcpCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddBaremetalDhcpCmd.class); @Inject BaremetalDhcpManager mgr; @@ -84,7 +82,7 @@ public class AddBaremetalDhcpCmd extends BaseAsyncCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (Exception e) { - s_logger.warn("Unable to add external dhcp server with url: " + getUrl(), e); + logger.warn("Unable to add external dhcp server with url: " + getUrl(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalPxeCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalPxeCmd.java index 19854a981b5..a11ae0bae36 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalPxeCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalPxeCmd.java @@ -20,7 +20,6 @@ package org.apache.cloudstack.api; import javax.inject.Inject; -import org.apache.log4j.Logger; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.cloudstack.api.response.PodResponse; @@ -38,7 +37,6 @@ import com.cloud.exception.ResourceUnavailableException; public class AddBaremetalPxeCmd extends BaseAsyncCmd { private static final String s_name = "addbaremetalpxeresponse"; - public static final Logger s_logger = Logger.getLogger(AddBaremetalPxeCmd.class); @Inject BaremetalPxeManager pxeMgr; @@ -86,7 +84,7 @@ public class AddBaremetalPxeCmd extends BaseAsyncCmd { rsp.setResponseName(getCommandName()); this.setResponseObject(rsp); } catch (Exception e) { - s_logger.warn("Unable to add external pxe server with url: " + getUrl(), e); + logger.warn("Unable to add external pxe server with url: " + getUrl(), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalRctCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalRctCmd.java index 3227cbd24ff..e7c77c3cd1c 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalRctCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/AddBaremetalRctCmd.java @@ -27,7 +27,6 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -37,7 +36,6 @@ import javax.inject.Inject; @APICommand(name = "addBaremetalRct", description = "adds baremetal rack configuration text", responseObject = BaremetalRctResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class AddBaremetalRctCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(AddBaremetalRctCmd.class); @Inject private BaremetalVlanManager vlanMgr; @@ -68,7 +66,7 @@ public class AddBaremetalRctCmd extends BaseAsyncCmd { BaremetalRctResponse rsp = vlanMgr.addRct(this); this.setResponseObject(rsp); } catch (Exception e) { - s_logger.warn(String.format("unable to add baremetal RCT[%s]", getRctUrl()), e); + logger.warn(String.format("unable to add baremetal RCT[%s]", getRctUrl()), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/BaremetalProvisionDoneNotificationCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/BaremetalProvisionDoneNotificationCmd.java index c712849a27a..75df9556ba4 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/BaremetalProvisionDoneNotificationCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/BaremetalProvisionDoneNotificationCmd.java @@ -28,7 +28,6 @@ import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; import javax.inject.Inject; -import org.apache.log4j.Logger; /** * Created by frank on 9/17/14. @@ -36,7 +35,6 @@ import org.apache.log4j.Logger; @APICommand(name = "notifyBaremetalProvisionDone", description = "Notify provision has been done on a host. This api is for baremetal virtual router service, not for end user", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class BaremetalProvisionDoneNotificationCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(BaremetalProvisionDoneNotificationCmd.class); private static final String s_name = "baremetalprovisiondone"; @Inject @@ -61,7 +59,7 @@ public class BaremetalProvisionDoneNotificationCmd extends BaseAsyncCmd { bmMgr.notifyProvisionDone(this); this.setResponseObject(new SuccessResponse(getCommandName())); } catch (Exception e) { - s_logger.warn(String.format("unable to notify baremetal provision done[mac:%s]", mac), e); + logger.warn(String.format("unable to notify baremetal provision done[mac:%s]", mac), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java index c2691d67ae0..8bb31403d9f 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/DeleteBaremetalRctCmd.java @@ -28,7 +28,6 @@ import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.context.CallContext; -import org.apache.log4j.Logger; import javax.inject.Inject; @@ -38,7 +37,6 @@ import javax.inject.Inject; @APICommand(name = "deleteBaremetalRct", description = "deletes baremetal rack configuration text", responseObject = SuccessResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class DeleteBaremetalRctCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeleteBaremetalRctCmd.class); @Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, description = "RCT id", required = true, entityType = BaremetalRctResponse.class) private Long id; @@ -63,7 +61,7 @@ public class DeleteBaremetalRctCmd extends BaseAsyncCmd { SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } catch (Exception e) { - s_logger.warn(String.format("unable to delete baremetal RCT[%s]", getId()), e); + logger.warn(String.format("unable to delete baremetal RCT[%s]", getId()), e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage(), e); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalDhcpCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalDhcpCmd.java index fdc64de25d7..8f4e2338be9 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalDhcpCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalDhcpCmd.java @@ -27,7 +27,6 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; @@ -35,7 +34,6 @@ import java.util.List; @APICommand(name = "listBaremetalDhcp", description = "list baremetal dhcp servers", responseObject = BaremetalDhcpResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListBaremetalDhcpCmd extends BaseListCmd { - private static final Logger s_logger = Logger.getLogger(ListBaremetalDhcpCmd.class); @Inject BaremetalDhcpManager _dhcpMgr; @@ -90,7 +88,7 @@ public class ListBaremetalDhcpCmd extends BaseListCmd { response.setObjectName("baremetaldhcps"); this.setResponseObject(response); } catch (Exception e) { - s_logger.debug("Exception happend while executing ListBaremetalDhcpCmd"); + logger.debug("Exception happend while executing ListBaremetalDhcpCmd"); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalPxeServersCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalPxeServersCmd.java index 5f856a5d638..bcf3f6f44db 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalPxeServersCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalPxeServersCmd.java @@ -27,7 +27,6 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.PhysicalNetworkResponse; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; @@ -35,7 +34,6 @@ import java.util.List; @APICommand(name = "listBaremetalPxeServers", description = "list baremetal pxe server", responseObject = BaremetalPxeResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false) public class ListBaremetalPxeServersCmd extends BaseListCmd { - private static final Logger s_logger = Logger.getLogger(ListBaremetalPxeServersCmd.class); @Inject BaremetalPxeManager _pxeMgr; @@ -76,7 +74,7 @@ public class ListBaremetalPxeServersCmd extends BaseListCmd { response.setObjectName("baremetalpxeservers"); this.setResponseObject(response); } catch (Exception e) { - s_logger.debug("Exception happened while executing ListPingPxeServersCmd", e); + logger.debug("Exception happened while executing ListPingPxeServersCmd", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalRctCmd.java b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalRctCmd.java index 379c8758bf1..d654fece0c7 100644 --- a/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalRctCmd.java +++ b/plugins/hypervisors/baremetal/src/main/java/org/apache/cloudstack/api/ListBaremetalRctCmd.java @@ -27,7 +27,6 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.api.response.ListResponse; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -36,7 +35,6 @@ import java.util.List; @APICommand(name = "listBaremetalRct", description = "list baremetal rack configuration", responseObject = BaremetalRctResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin}) public class ListBaremetalRctCmd extends BaseListCmd { - private static final Logger s_logger = Logger.getLogger(ListBaremetalRctCmd.class); @Inject BaremetalVlanManager vlanMgr; @@ -55,7 +53,7 @@ public class ListBaremetalRctCmd extends BaseListCmd { response.setObjectName("baremetalrcts"); this.setResponseObject(response); } catch (Exception e) { - s_logger.debug("Exception happened while executing ListBaremetalRctCmd", e); + logger.debug("Exception happened while executing ListBaremetalRctCmd", e); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } } diff --git a/plugins/hypervisors/hyperv/conf/log4j-cloud.xml.in b/plugins/hypervisors/hyperv/conf/log4j-cloud.xml.in index fdbba19e903..0292dffb3a9 100644 --- a/plugins/hypervisors/hyperv/conf/log4j-cloud.xml.in +++ b/plugins/hypervisors/hyperv/conf/log4j-cloud.xml.in @@ -17,77 +17,52 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - + + - + + + - - - + + + + + + + + - - - - - - - - - - - - - - - - + + + - - - + + + + - - - - + - - - + + - - - - - - - - - - - + - - - - + - - - - - - - + - - - + - - - - - + + + - + + + + + + + diff --git a/plugins/hypervisors/hyperv/pom.xml b/plugins/hypervisors/hyperv/pom.xml index 946e5f45873..b24c4c8a847 100644 --- a/plugins/hypervisors/hyperv/pom.xml +++ b/plugins/hypervisors/hyperv/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/hypervisors/hyperv/src/main/java/com/cloud/ha/HypervInvestigator.java b/plugins/hypervisors/hyperv/src/main/java/com/cloud/ha/HypervInvestigator.java index 774efc84b3a..d820fd5b6d3 100644 --- a/plugins/hypervisors/hyperv/src/main/java/com/cloud/ha/HypervInvestigator.java +++ b/plugins/hypervisors/hyperv/src/main/java/com/cloud/ha/HypervInvestigator.java @@ -22,7 +22,6 @@ import java.util.List; import javax.inject.Inject; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.api.Answer; @@ -36,7 +35,6 @@ import com.cloud.resource.ResourceManager; import com.cloud.utils.component.AdapterBase; public class HypervInvestigator extends AdapterBase implements Investigator { - private final static Logger s_logger = Logger.getLogger(HypervInvestigator.class); @Inject HostDao _hostDao; @Inject AgentManager _agentMgr; @Inject ResourceManager _resourceMgr; @@ -68,7 +66,7 @@ public class HypervInvestigator extends AdapterBase implements Investigator { return answer.getResult() ? Status.Down : Status.Up; } } catch (Exception e) { - s_logger.debug("Failed to send command to host: " + neighbor.getId(), e); + logger.debug("Failed to send command to host: " + neighbor.getId(), e); } } diff --git a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/discoverer/HypervServerDiscoverer.java b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/discoverer/HypervServerDiscoverer.java index 51b423052ea..283f4dc0c96 100644 --- a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/discoverer/HypervServerDiscoverer.java +++ b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/discoverer/HypervServerDiscoverer.java @@ -29,7 +29,6 @@ import java.util.UUID; import javax.inject.Inject; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.Listener; @@ -72,7 +71,6 @@ import com.cloud.storage.StorageLayer; * hypervisor and manages its lifecycle. */ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter { - private static final Logger s_logger = Logger.getLogger(HypervServerDiscoverer.class); Random _rand = new Random(System.currentTimeMillis()); Map _storageMounts = new HashMap(); @@ -121,7 +119,7 @@ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer // assert if (startup.getHypervisorType() != HypervisorType.Hyperv) { - s_logger.debug("Not Hyper-V hypervisor, so moving on."); + logger.debug("Not Hyper-V hypervisor, so moving on."); return; } @@ -137,8 +135,8 @@ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer _clusterDao.update(cluster.getId(), cluster); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Setting up host " + agentId); + if (logger.isDebugEnabled()) { + logger.debug("Setting up host " + agentId); } HostEnvironment env = new HostEnvironment(); @@ -163,14 +161,14 @@ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer if (reason == null) { reason = " details were null"; } - s_logger.warn("Unable to setup agent " + agentId + " due to " + reason); + logger.warn("Unable to setup agent " + agentId + " due to " + reason); } // Error handling borrowed from XcpServerDiscoverer, may need to be // updated. } catch (AgentUnavailableException e) { - s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e); + logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e); } catch (OperationTimedoutException e) { - s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e); + logger.warn("Unable to setup agent " + agentId + " because it timed out", e); } throw new ConnectionException(true, "Reinitialize agent after setup."); } @@ -213,14 +211,14 @@ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer public final Map> find(final long dcId, final Long podId, final Long clusterId, final URI uri, final String username, final String password, final List hostTags) throws DiscoveryException { - if (s_logger.isInfoEnabled()) { - s_logger.info("Discover host. dc(zone): " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + uri.getHost()); + if (logger.isInfoEnabled()) { + logger.info("Discover host. dc(zone): " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + uri.getHost()); } // Assertions if (podId == null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("No pod is assigned, skipping the discovery in" + " Hyperv discoverer"); + if (logger.isInfoEnabled()) { + logger.info("No pod is assigned, skipping the discovery in" + " Hyperv discoverer"); } return null; } @@ -228,20 +226,20 @@ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer // in the // database if (cluster == null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("No cluster in database for cluster id " + clusterId); + if (logger.isInfoEnabled()) { + logger.info("No cluster in database for cluster id " + clusterId); } return null; } if (cluster.getHypervisorType() != HypervisorType.Hyperv) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Cluster " + clusterId + "is not for Hyperv hypervisors"); + if (logger.isInfoEnabled()) { + logger.info("Cluster " + clusterId + "is not for Hyperv hypervisors"); } return null; } if (!uri.getScheme().equals("http")) { String msg = "urlString is not http so we're not taking care of" + " the discovery for this: " + uri; - s_logger.debug(msg); + logger.debug(msg); return null; } @@ -253,11 +251,11 @@ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer String guidWithTail = calcServerResourceGuid(uuidSeed) + "-HypervResource"; if (_resourceMgr.findHostByGuid(guidWithTail) != null) { - s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database."); + logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database."); return null; } - s_logger.info("Creating" + HypervDirectConnectResource.class.getName() + " HypervDirectConnectResource for zone/pod/cluster " + dcId + "/" + podId + "/" + + logger.info("Creating" + HypervDirectConnectResource.class.getName() + " HypervDirectConnectResource for zone/pod/cluster " + dcId + "/" + podId + "/" + clusterId); // Some Hypervisors organise themselves in pools. @@ -298,7 +296,7 @@ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer Answer pingAns = resource.executeRequest(ping); if (pingAns == null || !pingAns.getResult()) { String errMsg = "Agent not running, or no route to agent on at " + uri; - s_logger.debug(errMsg); + logger.debug(errMsg); throw new DiscoveryException(errMsg); } @@ -309,14 +307,14 @@ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer return resources; } catch (ConfigurationException e) { _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + uri.getHost(), "Error is " + e.getMessage()); - s_logger.warn("Unable to instantiate " + uri.getHost(), e); + logger.warn("Unable to instantiate " + uri.getHost(), e); } catch (UnknownHostException e) { _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + uri.getHost(), "Error is " + e.getMessage()); - s_logger.warn("Unable to instantiate " + uri.getHost(), e); + logger.warn("Unable to instantiate " + uri.getHost(), e); } catch (Exception e) { String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage(); - s_logger.warn(msg); + logger.warn(msg); } return null; } @@ -393,7 +391,7 @@ public class HypervServerDiscoverer extends DiscovererBase implements Discoverer return null; } - s_logger.info("Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.Hyperv + ". Checking CIDR..."); + logger.info("Host: " + host.getName() + " connected with hypervisor type: " + HypervisorType.Hyperv + ". Checking CIDR..."); HostPodVO pod = _podDao.findById(host.getPodId()); DataCenterVO dc = _dcDao.findById(host.getDataCenterId()); diff --git a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/manager/HypervManagerImpl.java b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/manager/HypervManagerImpl.java index 9490ae07b30..a31637b60de 100644 --- a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/manager/HypervManagerImpl.java +++ b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/manager/HypervManagerImpl.java @@ -33,7 +33,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.utils.identity.ManagementServerNode; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.configuration.Config; import com.cloud.storage.JavaStorageLayer; @@ -47,7 +48,7 @@ import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.VMInstanceDao; public class HypervManagerImpl implements HypervManager { - public static final Logger s_logger = Logger.getLogger(HypervManagerImpl.class); + protected Logger logger = LogManager.getLogger(getClass()); private String name; private int runLevel; @@ -127,7 +128,7 @@ public class HypervManagerImpl implements HypervManager { public String prepareSecondaryStorageStore(long zoneId) { String secondaryStorageUri = getSecondaryStorageStoreUrl(zoneId); if (secondaryStorageUri == null) { - s_logger.debug("Secondary storage uri for dc " + zoneId + " couldn't be obtained"); + logger.debug("Secondary storage uri for dc " + zoneId + " couldn't be obtained"); } else { prepareSecondaryStorageStore(secondaryStorageUri); } @@ -143,7 +144,7 @@ public class HypervManagerImpl implements HypervManager { } if (secUrl == null) { - s_logger.warn("Secondary storage uri couldn't be retrieved"); + logger.warn("Secondary storage uri couldn't be retrieved"); } return secUrl; @@ -160,7 +161,7 @@ public class HypervManagerImpl implements HypervManager { if (!patchFolder.exists()) { if (!patchFolder.mkdirs()) { String msg = "Unable to create systemvm folder on secondary storage. location: " + patchFolder.toString(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } @@ -168,20 +169,20 @@ public class HypervManagerImpl implements HypervManager { File srcIso = getSystemVMPatchIsoFile(); File destIso = new File(mountPoint + "/systemvm/" + getSystemVMIsoFileNameOnDatastore()); if (!destIso.exists()) { - s_logger.info("Copy System VM patch ISO file to secondary storage. source ISO: " + + logger.info("Copy System VM patch ISO file to secondary storage. source ISO: " + srcIso.getAbsolutePath() + ", destination: " + destIso.getAbsolutePath()); try { FileUtil.copyfile(srcIso, destIso); } catch (IOException e) { - s_logger.error("Unexpected exception ", e); + logger.error("Unexpected exception ", e); String msg = "Unable to copy systemvm ISO on secondary storage. src location: " + srcIso.toString() + ", dest location: " + destIso; - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } } else { - if (s_logger.isTraceEnabled()) { - s_logger.trace("SystemVM ISO file " + destIso.getPath() + " already exists"); + if (logger.isTraceEnabled()) { + logger.trace("SystemVM ISO file " + destIso.getPath() + " already exists"); } } } finally { @@ -205,14 +206,14 @@ public class HypervManagerImpl implements HypervManager { try { uri = new URI(storageUrl); } catch (URISyntaxException e) { - s_logger.error("Invalid storage URL format ", e); + logger.error("Invalid storage URL format ", e); throw new CloudRuntimeException("Unable to create mount point due to invalid storage URL format " + storageUrl); } mountPoint = mount(File.separator + File.separator + uri.getHost() + uri.getPath(), getMountParent(), uri.getScheme(), uri.getQuery()); if (mountPoint == null) { - s_logger.error("Unable to create mount point for " + storageUrl); + logger.error("Unable to create mount point for " + storageUrl); return "/mnt/sec"; } @@ -224,7 +225,7 @@ public class HypervManagerImpl implements HypervManager { protected String mount(String path, String parent, String scheme, String query) { String mountPoint = setupMountPoint(parent); if (mountPoint == null) { - s_logger.warn("Unable to create a mount point"); + logger.warn("Unable to create a mount point"); return null; } @@ -232,7 +233,7 @@ public class HypervManagerImpl implements HypervManager { String result = null; if (scheme.equals("cifs")) { String user = System.getProperty("user.name"); - Script command = new Script(true, "mount", _timeout, s_logger); + Script command = new Script(true, "mount", _timeout, logger); command.add("-t", "cifs"); command.add(path); command.add(mountPoint); @@ -250,7 +251,7 @@ public class HypervManagerImpl implements HypervManager { } if (result != null) { - s_logger.warn("Unable to mount " + path + " due to " + result); + logger.warn("Unable to mount " + path + " due to " + result); File file = new File(mountPoint); if (file.exists()) { file.delete(); @@ -259,11 +260,11 @@ public class HypervManagerImpl implements HypervManager { } // Change permissions for the mountpoint - script = new Script(true, "chmod", _timeout, s_logger); + script = new Script(true, "chmod", _timeout, logger); script.add("-R", "777", mountPoint); result = script.execute(); if (result != null) { - s_logger.warn("Unable to set permissions for " + mountPoint + " due to " + result); + logger.warn("Unable to set permissions for " + mountPoint + " due to " + result); } return mountPoint; } @@ -280,7 +281,7 @@ public class HypervManagerImpl implements HypervManager { break; } } - s_logger.error("Unable to create mount: " + mntPt); + logger.error("Unable to create mount: " + mntPt); } return mountPoint; @@ -306,7 +307,7 @@ public class HypervManagerImpl implements HypervManager { assert (isoFile != null); if (!isoFile.exists()) { - s_logger.error("Unable to locate systemvm.iso in your setup at " + isoFile.toString()); + logger.error("Unable to locate systemvm.iso in your setup at " + isoFile.toString()); } return isoFile; } @@ -330,7 +331,7 @@ public class HypervManagerImpl implements HypervManager { } private void startupCleanup(String parent) { - s_logger.info("Cleanup mounted mount points used in previous session"); + logger.info("Cleanup mounted mount points used in previous session"); long mshostId = ManagementServerNode.getManagementServerId(); @@ -338,14 +339,14 @@ public class HypervManagerImpl implements HypervManager { String[] mounts = _storage.listFiles(parent + File.separator + String.valueOf(mshostId) + ".*"); if (mounts != null && mounts.length > 0) { for (String mountPoint : mounts) { - s_logger.info("umount NFS mount from previous session: " + mountPoint); + logger.info("umount NFS mount from previous session: " + mountPoint); String result = null; - Script command = new Script(true, "umount", _timeout, s_logger); + Script command = new Script(true, "umount", _timeout, logger); command.add(mountPoint); result = command.execute(); if (result != null) { - s_logger.warn("Unable to umount " + mountPoint + " due to " + result); + logger.warn("Unable to umount " + mountPoint + " due to " + result); } File file = new File(mountPoint); if (file.exists()) { @@ -356,17 +357,17 @@ public class HypervManagerImpl implements HypervManager { } private void shutdownCleanup() { - s_logger.info("Cleanup mounted mount points used in current session"); + logger.info("Cleanup mounted mount points used in current session"); synchronized (_storageMounts) { for (String mountPoint : _storageMounts.values()) { - s_logger.info("umount NFS mount: " + mountPoint); + logger.info("umount NFS mount: " + mountPoint); String result = null; - Script command = new Script(true, "umount", _timeout, s_logger); + Script command = new Script(true, "umount", _timeout, logger); command.add(mountPoint); result = command.execute(); if (result != null) { - s_logger.warn("Unable to umount " + mountPoint + " due to " + result); + logger.warn("Unable to umount " + mountPoint + " due to " + result); } File file = new File(mountPoint); if (file.exists()) { diff --git a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java index 6bc1b98a688..37df91b2c89 100644 --- a/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java +++ b/plugins/hypervisors/hyperv/src/main/java/com/cloud/hypervisor/hyperv/resource/HypervDirectConnectResource.java @@ -60,7 +60,6 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.BasicClientConnectionManager; import org.apache.http.util.EntityUtils; -import org.apache.log4j.Logger; import org.joda.time.Duration; import com.cloud.agent.api.Answer; @@ -163,7 +162,6 @@ import com.google.gson.reflect.TypeToken; public class HypervDirectConnectResource extends ServerResourceBase implements ServerResource, VirtualRouterDeployer { public static final int DEFAULT_AGENT_PORT = 8250; public static final String HOST_VM_STATE_REPORT_COMMAND = "org.apache.cloudstack.HostVmStateReportCommand"; - private static final Logger s_logger = Logger.getLogger(HypervDirectConnectResource.class.getName()); private static final Gson s_gson = GsonHelper.getGson(); private String zoneId; @@ -206,7 +204,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S // assert if (!configureCalled) { final String errMsg = this.getClass().getName() + " requires configure() be called before" + " initialize()"; - s_logger.error(errMsg); + logger.error(errMsg); } // Create default StartupRoutingCommand, then customise @@ -224,7 +222,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S defaultStartRoutCmd.setStorageIpAddress(agentIp); defaultStartRoutCmd.setPool(clusterGuid); - s_logger.debug("Generated StartupRoutingCommand for agentIp \"" + agentIp + "\""); + logger.debug("Generated StartupRoutingCommand for agentIp \"" + agentIp + "\""); defaultStartRoutCmd.setVersion(this.getClass().getPackage().getImplementationVersion()); @@ -240,7 +238,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S // Assert that host identity is consistent with existing values. if (startCmd == null) { final String errMsg = String.format("Host %s (IP %s)" + "did not return a StartupRoutingCommand", name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } @@ -248,26 +246,26 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final String errMsg = String.format("Host %s (IP %s) changed zone/data center. Was " + defaultStartRoutCmd.getDataCenter() + " NOW its " + startCmd.getDataCenter(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } if (!startCmd.getPod().equals(defaultStartRoutCmd.getPod())) { final String errMsg = String.format("Host %s (IP %s) changed pod. Was " + defaultStartRoutCmd.getPod() + " NOW its " + startCmd.getPod(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } if (!startCmd.getCluster().equals(defaultStartRoutCmd.getCluster())) { final String errMsg = String.format("Host %s (IP %s) changed cluster. Was " + defaultStartRoutCmd.getCluster() + " NOW its " + startCmd.getCluster(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } if (!startCmd.getGuid().equals(defaultStartRoutCmd.getGuid())) { final String errMsg = String.format("Host %s (IP %s) changed guid. Was " + defaultStartRoutCmd.getGuid() + " NOW its " + startCmd.getGuid(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } @@ -275,13 +273,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final String errMsg = String.format("Host %s (IP %s) IP address. Was " + defaultStartRoutCmd.getPrivateIpAddress() + " NOW its " + startCmd.getPrivateIpAddress(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } if (!startCmd.getName().equals(defaultStartRoutCmd.getName())) { final String errMsg = String.format("Host %s (IP %s) name. Was " + startCmd.getName() + " NOW its " + defaultStartRoutCmd.getName(), name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } @@ -301,13 +299,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S if (storePoolCmd == null) { final String frmtStr = "Host %s (IP %s) sent incorrect Command, " + "second parameter should be a " + "StartupStorageCommand"; final String errMsg = String.format(frmtStr, name, agentIp); - s_logger.error(errMsg); + logger.error(errMsg); // TODO: valid to return null, or should we throw? return null; } - s_logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details " + s_gson.toJson(startCmds[1])); + logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details " + s_gson.toJson(startCmds[1])); } else { - s_logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details "); + logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details "); } return new StartupCommand[] {startCmd, storePoolCmd}; } @@ -316,14 +314,14 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S public final PingCommand getCurrentStatus(final long id) { final PingCommand pingCmd = new PingRoutingCommand(getType(), id, getHostVmStateReport()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping host " + name + " (IP " + agentIp + ")"); + if (logger.isDebugEnabled()) { + logger.debug("Ping host " + name + " (IP " + agentIp + ")"); } final Answer pingAns = executeRequest(pingCmd); if (pingAns == null || !pingAns.getResult()) { - s_logger.info("Cannot ping host " + name + " (IP " + agentIp + "), pingAns (blank means null) is:" + pingAns); + logger.info("Cannot ping host " + name + " (IP " + agentIp + "), pingAns (blank means null) is:" + pingAns); return null; } return pingCmd; @@ -335,7 +333,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S agentUri = new URI("https", null, agentIp, port, "/api/HypervResource/" + HOST_VM_STATE_REPORT_COMMAND, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return null; } final String incomingCmd = postHttpRequest("{}", agentUri); @@ -349,9 +347,9 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S }.getType()); } catch (final Exception ex) { final String errMsg = "Failed to deserialize Command[] " + incomingCmd; - s_logger.error(errMsg, ex); + logger.error(errMsg, ex); } - s_logger.debug("HostVmStateReportCommand received response " + logger.debug("HostVmStateReportCommand received response " + s_gson.toJson(result)); if (result != null) { if (!result.isEmpty()) { @@ -393,7 +391,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } catch (final URISyntaxException e) { // TODO add proper logging final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return null; } final String incomingCmd = postHttpRequest(s_gson.toJson(cmd), agentUri); @@ -406,9 +404,9 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S result = s_gson.fromJson(incomingCmd, Command[].class); } catch (final Exception ex) { final String errMsg = "Failed to deserialize Command[] " + incomingCmd; - s_logger.error(errMsg, ex); + logger.error(errMsg, ex); } - s_logger.debug("requestStartupCommand received response " + s_gson.toJson(result)); + logger.debug("requestStartupCommand received response " + s_gson.toJson(result)); if (result.length > 0) { return result; } @@ -432,7 +430,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } catch (final URISyntaxException e) { // TODO add proper logging final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return null; } if (cmd instanceof NetworkElementCommand) { @@ -460,7 +458,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S ((StartCommand)cmd).setSecondaryStorage(secondary); } } else { - s_logger.error("Hyperv manager isn't available. Couldn't check and copy the systemvm iso."); + logger.error("Hyperv manager isn't available. Couldn't check and copy the systemvm iso."); } } } @@ -474,7 +472,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S // E.g. see Response.getAnswers() final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); final String logResult = cleanPassword(s_gson.toJson(result)); - s_logger.debug("executeRequest received response " + logResult); + logger.debug("executeRequest received response " + logResult); if (result.length > 0) { return result[0]; } @@ -491,7 +489,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); return null; } cleanPassword(cmd.getSrcTO().getDataStore()); @@ -505,7 +503,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); final String logResult = cleanPassword(s_gson.toJson(result)); - s_logger.debug("executeRequest received response " + logResult); + logger.debug("executeRequest received response " + logResult); if (result.length > 0) { return result[0]; } @@ -524,8 +522,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } private PlugNicAnswer execute(final PlugNicCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource PlugNicCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource PlugNicCommand " + s_gson.toJson(cmd)); } try { @@ -544,19 +542,19 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S return new PlugNicAnswer(cmd, true, "success"); } final String msg = " Plug Nic failed for the vm as it has reached max limit of NICs to be added"; - s_logger.warn(msg); + logger.warn(msg); return new PlugNicAnswer(cmd, false, msg); } catch (final Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString()); } } private UnPlugNicAnswer execute(final UnPlugNicCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource UnPlugNicCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource UnPlugNicCommand " + s_gson.toJson(cmd)); } try { @@ -574,7 +572,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } return new UnPlugNicAnswer(cmd, true, "success"); } catch (final Exception e) { - s_logger.error("Unexpected exception: ", e); + logger.error("Unexpected exception: ", e); return new UnPlugNicAnswer(cmd, false, "Unable to execute unPlugNicCommand due to " + e.toString()); } } @@ -589,8 +587,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S Pair result; //TODO: Password should be masked, cannot output to log directly - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on VR: " + routerIP + ", script: " + script + " with args: " + args); + if (logger.isDebugEnabled()) { + logger.debug("Run command on VR: " + routerIP + ", script: " + script + " with args: " + args); } try { @@ -598,11 +596,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S VRScripts.CONNECTION_TIMEOUT, timeout); } catch (final Exception e) { final String msg = "Command failed due to " + e ; - s_logger.error(msg); + logger.error(msg); result = new Pair(false, msg); } - if (s_logger.isDebugEnabled()) { - s_logger.debug(script + " execution result: " + result.first().toString()); + if (logger.isDebugEnabled()) { + logger.debug(script + " execution result: " + result.first().toString()); } return new ExecutionResult(result.first(), result.second()); } @@ -613,7 +611,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S try { SshHelper.scpTo(routerIp, 3922, "root", keyFile, null, filePath, content.getBytes(Charset.forName("UTF-8")), fileName, null); } catch (final Exception e) { - s_logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e); + logger.warn("Fail to create file " + filePath + fileName + " in VR " + routerIp, e); return new ExecutionResult(false, e.getMessage()); } return new ExecutionResult(true, null); @@ -660,8 +658,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S boolean addVif = false; if (ip.isAdd() && publicNicInfo == -1) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp()); + if (logger.isDebugEnabled()) { + logger.debug("Plug new NIC to associate" + controlIp + " to " + ip.getPublicIp()); } addVif = true; } @@ -679,7 +677,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S else { // we didn't find any eth device available in VR to configure the ip range with new VLAN final String msg = "No Nic is available on DomR VIF to associate/disassociate IP with."; - s_logger.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } ip.setNicDevId(publicNicInfo); @@ -689,7 +687,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } } } catch (final Throwable e) { - s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); + logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); return new ExecutionResult(false, e.toString()); } return new ExecutionResult(true, null); @@ -711,7 +709,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } } catch (final Exception e) { final String msg = "Prepare SetupGuestNetwork failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); @@ -735,7 +733,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S if (ip.isAdd()) { throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with."); } else { - s_logger.debug("VIF to deassociate IP with does not exist, return success"); + logger.debug("VIF to deassociate IP with does not exist, return success"); continue; } } @@ -743,7 +741,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S ip.setNicDevId(publicNicInfo); } } catch (final Exception e) { - s_logger.error("Prepare Ip Assoc failure on applying one ip due to exception: ", e); + logger.error("Prepare Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.toString()); } @@ -765,7 +763,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } } catch (final Exception e) { final String msg = "Prepare Ip SNAT failure due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new ExecutionResult(false, e.toString()); } return new ExecutionResult(true, null); @@ -787,7 +785,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } } catch (final Exception e) { final String msg = "Prepare SetNetworkACL failed due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new ExecutionResult(false, msg); } return new ExecutionResult(true, null); @@ -814,29 +812,29 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S try { final String command = String.format("%s%s %s", "/opt/cloud/bin/", VRScripts.VPN_L2TP, argsBuf.toString()); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing " + command); + if (logger.isDebugEnabled()) { + logger.debug("Executing " + command); } final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("RemoteAccessVpnCfg command on domR failed, message: " + result.second()); + logger.error("RemoteAccessVpnCfg command on domR failed, message: " + result.second()); return new Answer(cmd, false, "RemoteAccessVpnCfg command failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("RemoteAccessVpnCfg command on domain router " + argsBuf.toString() + " completed"); + if (logger.isInfoEnabled()) { + logger.info("RemoteAccessVpnCfg command on domain router " + argsBuf.toString() + " completed"); } } catch (final Throwable e) { if (e instanceof RemoteException) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); } final String msg = "RemoteAccessVpnCfg command failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -856,24 +854,24 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S try { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh "); + if (logger.isDebugEnabled()) { + logger.debug("Executing /opt/cloud/bin/vpn_lt2p.sh "); } final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/opt/cloud/bin/vpn_l2tp.sh " + argsBuf.toString()); if (!result.first()) { - s_logger.error("VpnUserCfg command on domR failed, message: " + result.second()); + logger.error("VpnUserCfg command on domR failed, message: " + result.second()); return new Answer(cmd, false, "VpnUserCfg command failed due to " + result.second()); } } catch (final Throwable e) { if (e instanceof RemoteException) { - s_logger.warn(e.getMessage()); + logger.warn(e.getMessage()); } final String msg = "VpnUserCfg command failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } } @@ -881,8 +879,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S return new Answer(cmd); } private SetStaticRouteAnswer execute(final SetStaticRouteCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetStaticRouteCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetStaticRouteCommand: " + s_gson.toJson(cmd)); } boolean endResult = true; @@ -908,19 +906,19 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing script on domain router " + controlIp + ": /opt/cloud/bin/vpc_staticroute.sh " + args); + if (logger.isDebugEnabled()) { + logger.debug("Executing script on domain router " + controlIp + ": /opt/cloud/bin/vpc_staticroute.sh " + args); } if (!result.first()) { - s_logger.error("SetStaticRouteCommand failure on setting one rule. args: " + args); + logger.error("SetStaticRouteCommand failure on setting one rule. args: " + args); results[i++] = "Failed"; endResult = false; } else { results[i++] = null; } } catch (final Throwable e) { - s_logger.error("SetStaticRouteCommand(args: " + args + ") failed on setting one rule due to " + e); + logger.error("SetStaticRouteCommand(args: " + args + ") failed on setting one rule due to " + e); results[i++] = "Failed"; endResult = false; } @@ -933,9 +931,9 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S cmdline.append("/opt/cloud/bin/"); cmdline.append(VRScripts.S2SVPN_CHECK); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing resource CheckS2SVpnConnectionsCommand: " + s_gson.toJson(cmd)); - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + cmdline.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Executing resource CheckS2SVpnConnectionsCommand: " + s_gson.toJson(cmd)); + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + cmdline.toString()); } Pair result; @@ -949,26 +947,26 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, cmdline.toString()); if (!result.first()) { - s_logger.error("check site-to-site vpn connections command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + + logger.error("check site-to-site vpn connections command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); return new CheckS2SVpnConnectionsAnswer(cmd, false, result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("check site-to-site vpn connections command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("check site-to-site vpn connections command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); } } catch (final Throwable e) { final String msg = "CheckS2SVpnConnectionsCommand failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new CheckS2SVpnConnectionsAnswer(cmd, false, "CheckS2SVpnConneciontsCommand failed"); } return new CheckS2SVpnConnectionsAnswer(cmd, true, result.second()); } protected Answer execute(final Site2SiteVpnCfgCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource Site2SiteVpnCfgCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource Site2SiteVpnCfgCommand " + s_gson.toJson(cmd)); } final String routerIp = getRouterSshControlIp(cmd); @@ -1018,25 +1016,25 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("Setup site2site VPN " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); + logger.error("Setup site2site VPN " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); return new Answer(cmd, false, "Setup site2site VPN falied due to " + result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("setup site 2 site vpn on router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("setup site 2 site vpn on router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); } } catch (final Throwable e) { final String msg = "Setup site2site VPN falied due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, "Setup site2site VPN failed due to " + e.getMessage()); } return new Answer(cmd, true, result.second()); } protected SetSourceNatAnswer execute(final SetSourceNatCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetSourceNatCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetSourceNatCommand " + s_gson.toJson(cmd)); } final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME); @@ -1058,7 +1056,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S if (!result.first()) { final String msg = "SetupGuestNetworkCommand on domain router " + routerIp + " failed. message: " + result.second(); - s_logger.error(msg); + logger.error(msg); return new SetSourceNatAnswer(cmd, false, msg); } @@ -1066,14 +1064,14 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S return new SetSourceNatAnswer(cmd, true, "success"); } catch (final Exception e) { final String msg = "Ip SNAT failure due to " + e.toString(); - s_logger.error(msg, e); + logger.error(msg, e); return new SetSourceNatAnswer(cmd, false, msg); } } protected Answer execute(final SetPortForwardingRulesCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetPortForwardingRulesCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetPortForwardingRulesCommand: " + s_gson.toJson(cmd)); } final String controlIp = getRouterSshControlIp(cmd); @@ -1093,19 +1091,19 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S try { final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall.sh " + args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args); + if (logger.isDebugEnabled()) { + logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args); } if (!result.first()) { - s_logger.error("SetPortForwardingRulesCommand failure on setting one rule. args: " + args); + logger.error("SetPortForwardingRulesCommand failure on setting one rule. args: " + args); results[i++] = "Failed"; endResult = false; } else { results[i++] = null; } } catch (final Throwable e) { - s_logger.error("SetPortForwardingRulesCommand(args: " + args + ") failed on setting one rule due to " + e.getMessage()); + logger.error("SetPortForwardingRulesCommand(args: " + args + ") failed on setting one rule due to " + e.getMessage()); results[i++] = "Failed"; endResult = false; } @@ -1117,9 +1115,9 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S protected Answer execute(final CheckRouterCommand cmd) { final String command = String.format("%s%s", "/opt/cloud/bin/", VRScripts.RVR_CHECK); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing resource CheckRouterCommand: " + s_gson.toJson(cmd)); - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); + if (logger.isDebugEnabled()) { + logger.debug("Executing resource CheckRouterCommand: " + s_gson.toJson(cmd)); + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); } Pair result; @@ -1129,17 +1127,17 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("check router command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); + logger.error("check router command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); return new CheckRouterAnswer(cmd, "CheckRouter failed due to " + result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("check router command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("check router command on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); } } catch (final Throwable e) { final String msg = "CheckRouterCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new CheckRouterAnswer(cmd, msg); } return new CheckRouterAnswer(cmd, result.second(), true); @@ -1151,8 +1149,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S //return SetVPCStaticNatRules(cmd); } - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetFirewallRuleCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetFirewallRuleCommand: " + s_gson.toJson(cmd)); } String args = null; @@ -1177,19 +1175,19 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final String controlIp = getRouterSshControlIp(cmd); final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall.sh " + args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args); + if (logger.isDebugEnabled()) { + logger.debug("Executing script on domain router " + controlIp + ": /root/firewall.sh " + args); } if (!result.first()) { - s_logger.error("SetStaticNatRulesCommand failure on setting one rule. args: " + args); + logger.error("SetStaticNatRulesCommand failure on setting one rule. args: " + args); results[i++] = "Failed"; endResult = false; } else { results[i++] = null; } } catch (final Throwable e) { - s_logger.error("SetStaticNatRulesCommand (args: " + args + ") failed on setting one rule due to " + e.getMessage()); + logger.error("SetStaticNatRulesCommand (args: " + args + ") failed on setting one rule due to " + e.getMessage()); results[i++] = "Failed"; endResult = false; } @@ -1198,8 +1196,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } protected Answer execute(final PingTestCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource PingTestCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource PingTestCommand: " + s_gson.toJson(cmd)); } final String controlIp = cmd.getRouterIp(); final String args = " -c 1 -n -q " + cmd.getPrivateIp(); @@ -1209,7 +1207,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S return new Answer(cmd); } } catch (final Exception e) { - s_logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to " + e.getMessage()); + logger.error("Unable to execute ping command on DomR (" + controlIp + "), domR may not be ready yet. failure due to " + e.getMessage()); } return new Answer(cmd, false, "PingTestCommand failed"); } @@ -1218,8 +1216,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final List revokedIpAliasTOs = cmd.getDeleteIpAliasTos(); final List activeIpAliasTOs = cmd.getCreateIpAliasTos(); - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing deleteIpAlias command: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing deleteIpAlias command: " + s_gson.toJson(cmd)); } final StringBuilder args = new StringBuilder(); for (final IpAliasTO ipAliasTO : revokedIpAliasTOs) { @@ -1239,8 +1237,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S args.append(ipAliasTO.getNetmask()); args.append("-"); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/deleteIpAlias " + args); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/deleteIpAlias " + args); } try { @@ -1248,18 +1246,18 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/deleteIpAlias.sh " + args); if (!result.first()) { - s_logger.error("deleteIpAlias command on domr " + controlIp + " failed, message: " + result.second()); + logger.error("deleteIpAlias command on domr " + controlIp + " failed, message: " + result.second()); return new Answer(cmd, false, "deleteIpAlias failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("deleteIpAlias command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("deleteIpAlias command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "deleteIpAlias failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -1334,27 +1332,27 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "scp " + tmpCfgFilePath + " /etc/haproxy/haproxy.cfg.new"); if (!result.first()) { - s_logger.error("Unable to copy haproxy configuration file"); + logger.error("Unable to copy haproxy configuration file"); return new Answer(cmd, false, "LoadBalancerConfigCommand failed due to unable to copy haproxy configuration file"); } final String command = String.format("%s%s %s", "/root/", VRScripts.LB, args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domain router " + routerIp + command); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domain router " + routerIp + command); } result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { final String msg = "LoadBalancerConfigCommand on domain router " + routerIp + " failed. message: " + result.second(); - s_logger.error(msg); + logger.error(msg); return new Answer(cmd, false, msg); } - if (s_logger.isInfoEnabled()) { - s_logger.info("LoadBalancerConfigCommand on domain router " + routerIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("LoadBalancerConfigCommand on domain router " + routerIp + " completed"); } } finally { SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "rm " + tmpCfgFilePath); @@ -1362,15 +1360,15 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S return new Answer(cmd); } catch (final Throwable e) { - s_logger.error("Unexpected exception: " + e.toString(), e); + logger.error("Unexpected exception: " + e.toString(), e); return new Answer(cmd, false, "LoadBalancerConfigCommand failed due to " + e.getMessage()); } } protected Answer execute(final SavePasswordCommand cmd) { - if (s_logger.isInfoEnabled()) { + if (logger.isInfoEnabled()) { - s_logger.info("Executing resource SavePasswordCommand. vmName: " + cmd.getVmName() + ", vmIp: " + cmd.getVmIpAddress() + ", password: " + + logger.info("Executing resource SavePasswordCommand. vmName: " + cmd.getVmName() + ", vmIp: " + cmd.getVmIpAddress() + ", password: " + StringUtils.getMaskedPasswordForDisplay(cmd.getPassword())); } @@ -1381,9 +1379,9 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S // Run save_password_to_domr.sh final String command = String.format("%s%s %s %s %s %s", "/opt/cloud/bin/", VRScripts.PASSWORD, "-v", vmIpAddress, "-p", password); - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { final String debugCommand = String.format("%s%s %s %s %s %s", "/opt/cloud/bin/", VRScripts.PASSWORD, "-v", vmIpAddress, "-p", StringUtils.getMaskedPasswordForDisplay(cmd.getPassword())); - s_logger.debug("Run command on domain router " + controlIp + debugCommand); + logger.debug("Run command on domain router " + controlIp + debugCommand); } try { @@ -1391,18 +1389,18 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("savepassword command on domain router " + controlIp + " failed, message: " + result.second()); + logger.error("savepassword command on domain router " + controlIp + " failed, message: " + result.second()); return new Answer(cmd, false, "SavePassword failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("savepassword command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("savepassword command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "SavePasswordCommand failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } return new Answer(cmd); @@ -1447,16 +1445,16 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/firewall_rule.sh " + args); } - if (s_logger.isDebugEnabled()) { + if (logger.isDebugEnabled()) { if (trafficType == FirewallRule.TrafficType.Egress) { - s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewallRule_egress.sh " + args); + logger.debug("Executing script on domain router " + controlIp + ": /root/firewallRule_egress.sh " + args); } else { - s_logger.debug("Executing script on domain router " + controlIp + ": /root/firewall_rule.sh " + args); + logger.debug("Executing script on domain router " + controlIp + ": /root/firewall_rule.sh " + args); } } if (!result.first()) { - s_logger.error("SetFirewallRulesCommand failure on setting one rule. args: " + args); + logger.error("SetFirewallRulesCommand failure on setting one rule. args: " + args); //FIXME - in the future we have to process each rule separately; now we temporarily set every rule to be false if single rule fails for (int i = 0; i < results.length; i++) { results[i] = "Failed"; @@ -1465,7 +1463,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S return new SetFirewallRulesAnswer(cmd, false, results); } } catch (final Throwable e) { - s_logger.error("SetFirewallRulesCommand(args: " + args + ") failed on setting one rule due to ", e); + logger.error("SetFirewallRulesCommand(args: " + args + ") failed on setting one rule due to ", e); //FIXME - in the future we have to process each rule separately; now we temporarily set every rule to be false if single rule fails for (int i = 0; i < results.length; i++) { results[i] = "Failed"; @@ -1477,15 +1475,15 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } protected Answer execute(final VmDataCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource VmDataCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource VmDataCommand: " + s_gson.toJson(cmd)); } final String controlIp = getRouterSshControlIp(cmd); final Map> data = new HashMap>(); data.put(cmd.getVmIpAddress(), cmd.getVmData()); String json = new Gson().toJson(data); - s_logger.debug("VM data JSON IS:" + json); + logger.debug("VM data JSON IS:" + json); json = Base64.encodeBase64String(json.getBytes(Charset.forName("UTF-8"))); final String command = String.format("%s%s %s %s", "/opt/cloud/bin/", VRScripts.VMDATA, "-d", json); @@ -1493,24 +1491,24 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S try { final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("vm_data command on domain router " + controlIp + " failed. messge: " + result.second()); + logger.error("vm_data command on domain router " + controlIp + " failed. messge: " + result.second()); return new Answer(cmd, false, "VmDataCommand failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("vm_data command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("vm_data command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "VmDataCommand failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } return new Answer(cmd); } protected Answer execute(final DhcpEntryCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource DhcpEntryCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource DhcpEntryCommand: " + s_gson.toJson(cmd)); } // ssh -p 3922 -o StrictHostKeyChecking=no -i $cert root@$domr "/root/edithosts.sh $mac $ip $vm $dfltrt $ns $staticrt" >/dev/null @@ -1544,8 +1542,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final String command = String.format("%s%s %s", "/root/", VRScripts.DHCP, args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); } try { @@ -1553,18 +1551,18 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("dhcp_entry command on domR " + controlIp + " failed, message: " + result.second()); + logger.error("dhcp_entry command on domR " + controlIp + " failed, message: " + result.second()); return new Answer(cmd, false, "DhcpEntry failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("dhcp_entry command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("dhcp_entry command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "DhcpEntryCommand failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -1572,8 +1570,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } protected Answer execute(final CreateIpAliasCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing createIpAlias command: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing createIpAlias command: " + s_gson.toJson(cmd)); } cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final List ipAliasTOs = cmd.getIpAliasList(); @@ -1586,8 +1584,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S args.append(ipaliasto.getNetmask()); args.append("-"); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/createIpAlias " + args); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + ", /root/createIpAlias " + args); } try { @@ -1595,18 +1593,18 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, "/root/createIpAlias.sh " + args); if (!result.first()) { - s_logger.error("CreateIpAlias command on domr " + controlIp + " failed, message: " + result.second()); + logger.error("CreateIpAlias command on domr " + controlIp + " failed, message: " + result.second()); return new Answer(cmd, false, "createipAlias failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("createIpAlias command on domain router " + controlIp + " completed"); + if (logger.isInfoEnabled()) { + logger.info("createIpAlias command on domain router " + controlIp + " completed"); } } catch (final Throwable e) { final String msg = "createIpAlias failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -1614,8 +1612,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } protected Answer execute(final DnsMasqConfigCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing dnsmasqConfig command: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing dnsmasqConfig command: " + s_gson.toJson(cmd)); } final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final String controlIp = getRouterSshControlIp(cmd); @@ -1639,21 +1637,21 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final String command = String.format("%s%s %s", "/root/", VRScripts.DHCP, args); final Pair result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domain router " + routerIp + ", /root/dnsmasq.sh"); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domain router " + routerIp + ", /root/dnsmasq.sh"); } if (!result.first()) { - s_logger.error("Unable update dnsmasq config file"); + logger.error("Unable update dnsmasq config file"); return new Answer(cmd, false, "dnsmasq config update failed due to: " + result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("dnsmasq config command on domain router " + routerIp + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("dnsmasq config command on domain router " + routerIp + " completed"); } } catch (final Throwable e) { final String msg = "Dnsmasqconfig command failed due to " + e.getMessage(); - s_logger.error(msg, e); + logger.error(msg, e); return new Answer(cmd, false, msg); } @@ -1678,7 +1676,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S private int findRouterEthDeviceIndex(final String domrName, final String routerIp, final String mac) throws Exception { - s_logger.info("findRouterEthDeviceIndex. mac: " + mac); + logger.info("findRouterEthDeviceIndex. mac: " + mac); // TODO : this is a temporary very inefficient solution, will refactor it later final Pair result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, @@ -1694,14 +1692,14 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S if (!("all".equalsIgnoreCase(token) || "default".equalsIgnoreCase(token) || "lo".equalsIgnoreCase(token))) { final String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run domr script " + cmd); + if (logger.isDebugEnabled()) { + logger.debug("Run domr script " + cmd); } final Pair result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, // TODO need to find the dev index inside router based on IP address cmd); - if (s_logger.isDebugEnabled()) { - s_logger.debug("result: " + result2.first() + ", output: " + result2.second()); + if (logger.isDebugEnabled()) { + logger.debug("result: " + result2.first() + ", output: " + result2.second()); } if (result2.first() && result2.second().trim().equalsIgnoreCase(mac.trim())) { @@ -1711,7 +1709,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } } - s_logger.warn("can not find intereface associated with mac: " + mac + ", guest OS may still at loading state, retry..."); + logger.warn("can not find intereface associated with mac: " + mac + ", guest OS may still at loading state, retry..."); } @@ -1720,7 +1718,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S private Pair findRouterFreeEthDeviceIndex(final String routerIp) throws Exception { - s_logger.info("findRouterFreeEthDeviceIndex. mac: "); + logger.info("findRouterFreeEthDeviceIndex. mac: "); // TODO : this is a temporary very inefficient solution, will refactor it later final Pair result = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, @@ -1738,14 +1736,14 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S //TODO: don't check for eth0,1,2, as they will be empty by default. //String cmd = String.format("ip address show %s ", token); final String cmd = String.format("ip address show %s | grep link/ether | sed -e 's/^[ \t]*//' | cut -d' ' -f2", token); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run domr script " + cmd); + if (logger.isDebugEnabled()) { + logger.debug("Run domr script " + cmd); } final Pair result2 = SshHelper.sshExecute(routerIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, // TODO need to find the dev index inside router based on IP address cmd); - if (s_logger.isDebugEnabled()) { - s_logger.debug("result: " + result2.first() + ", output: " + result2.second()); + if (logger.isDebugEnabled()) { + logger.debug("result: " + result2.first() + ", output: " + result2.second()); } if (result2.first() && result2.second().trim().length() > 0) { @@ -1755,7 +1753,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } } - //s_logger.warn("can not find intereface associated with mac: , guest OS may still at loading state, retry..."); + //logger.warn("can not find intereface associated with mac: , guest OS may still at loading state, retry..."); } @@ -1763,8 +1761,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } protected Answer execute(final IpAssocCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource IPAssocCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource IPAssocCommand: " + s_gson.toJson(cmd)); } int i = 0; @@ -1785,7 +1783,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S results[i++] = IpAssocAnswer.errorResult; } } catch (final Throwable e) { - s_logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); + logger.error("Unexpected exception: " + e.toString() + " will shortcut rest of IPAssoc commands", e); for (; i < cmd.getIpAddresses().length; i++) { results[i++] = IpAssocAnswer.errorResult; @@ -1807,11 +1805,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } final String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri); final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); - s_logger.debug("GetVmConfigCommand response received " + logger.debug("GetVmConfigCommand response received " + s_gson.toJson(result)); if (result.length > 0) { final GetVmConfigAnswer ans = (GetVmConfigAnswer)result[0]; @@ -1840,11 +1838,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } final String ansStr = postHttpRequest(s_gson.toJson(vmConfig), agentUri); final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); - s_logger.debug("executeRequest received response " + logger.debug("executeRequest received response " + s_gson.toJson(result)); if (result.length > 0) { final GetVmConfigAnswer ans = (GetVmConfigAnswer)result[0]; @@ -1869,11 +1867,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } final String ansStr = postHttpRequest(s_gson.toJson(modifynic), agentUri); final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); - s_logger.debug("executeRequest received response " + logger.debug("executeRequest received response " + s_gson.toJson(result)); if (result.length > 0) { } @@ -1890,11 +1888,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S "/api/HypervResource/" + cmdName, null, null); } catch (final URISyntaxException e) { final String errMsg = "Could not generate URI for Hyper-V agent"; - s_logger.error(errMsg, e); + logger.error(errMsg, e); } final String ansStr = postHttpRequest(s_gson.toJson(modifyNic), agentUri); final Answer[] result = s_gson.fromJson(ansStr, Answer[].class); - s_logger.debug("executeRequest received response " + logger.debug("executeRequest received response " + s_gson.toJson(result)); if (result.length > 0) { } @@ -1914,13 +1912,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S boolean addVif = false; if (add && publicNicInfo == -1) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Plug new NIC to associate" + privateIpAddress + " to " + publicIpAddress); + if (logger.isDebugEnabled()) { + logger.debug("Plug new NIC to associate" + privateIpAddress + " to " + publicIpAddress); } addVif = true; } else if (!add && firstIP) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Unplug NIC " + publicNicInfo); + if (logger.isDebugEnabled()) { + logger.debug("Unplug NIC " + publicNicInfo); } } @@ -1937,7 +1935,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S else { // we didn't find any eth device available in VR to configure the ip range with new VLAN final String msg = "No Nic is available on DomR VIF to associate/disassociate IP with."; - s_logger.error(msg); + logger.error(msg); throw new InternalErrorException(msg); } } @@ -1972,29 +1970,29 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final String command = String.format("%s%s %s","/opt/cloud/bin/", VRScripts.IPASSOC ,args); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Run command on domain router " + privateIpAddress + command); + if (logger.isDebugEnabled()) { + logger.debug("Run command on domain router " + privateIpAddress + command); } final Pair result = SshHelper.sshExecute(privateIpAddress, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("ipassoc command on domain router " + privateIpAddress + " failed. message: " + result.second()); + logger.error("ipassoc command on domain router " + privateIpAddress + " failed. message: " + result.second()); throw new Exception("ipassoc failed due to " + result.second()); } - if (s_logger.isInfoEnabled()) { - s_logger.info("ipassoc command on domain router " + privateIpAddress + " completed"); + if (logger.isInfoEnabled()) { + logger.info("ipassoc command on domain router " + privateIpAddress + " completed"); } } protected Answer execute(final GetDomRVersionCmd cmd) { final String command = String.format("%s%s", "/opt/cloud/bin/", VRScripts.VERSION); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Executing resource GetDomRVersionCmd: " + s_gson.toJson(cmd)); - s_logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); + if (logger.isDebugEnabled()) { + logger.debug("Executing resource GetDomRVersionCmd: " + s_gson.toJson(cmd)); + logger.debug("Run command on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + command); } Pair result; @@ -2003,17 +2001,17 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S result = SshHelper.sshExecute(controlIp, DEFAULT_DOMR_SSHPORT, "root", getSystemVMKeyFile(), null, command); if (!result.first()) { - s_logger.error("GetDomRVersionCmd on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); + logger.error("GetDomRVersionCmd on domR " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " failed, message: " + result.second()); return new GetDomRVersionAnswer(cmd, "GetDomRVersionCmd failed due to " + result.second()); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("GetDomRVersionCmd on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); + if (logger.isDebugEnabled()) { + logger.debug("GetDomRVersionCmd on domain router " + cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP) + " completed"); } } catch (final Throwable e) { final String msg = "GetDomRVersionCmd failed due to " + e; - s_logger.error(msg, e); + logger.error(msg, e); return new GetDomRVersionAnswer(cmd, msg); } final String[] lines = result.second().split("&"); @@ -2023,21 +2021,21 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S return new GetDomRVersionAnswer(cmd, result.second(), lines[0], lines[1]); } - private static String getRouterSshControlIp(final NetworkElementCommand cmd) { + private String getRouterSshControlIp(final NetworkElementCommand cmd) { final String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP); final String routerGuestIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP); final String zoneNetworkType = cmd.getAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE); if (routerGuestIp != null && zoneNetworkType != null && NetworkType.valueOf(zoneNetworkType) == NetworkType.Basic) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("In Basic zone mode, use router's guest IP for SSH control. guest IP : " + routerGuestIp); + if (logger.isDebugEnabled()) { + logger.debug("In Basic zone mode, use router's guest IP for SSH control. guest IP : " + routerGuestIp); } return routerGuestIp; } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Use router's private IP for SSH control. IP : " + routerIp); + if (logger.isDebugEnabled()) { + logger.debug("Use router's private IP for SSH control. IP : " + routerIp); } return routerIp; } @@ -2046,8 +2044,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S if (cmd.isForVpc()) { //return VPCNetworkUsage(cmd); } - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource NetworkUsageCommand " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource NetworkUsageCommand " + s_gson.toJson(cmd)); } if (cmd.getOption() != null && cmd.getOption().equals("create")) { networkUsage(cmd.getPrivateIP(), "create", null); @@ -2072,21 +2070,21 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S stats[1] += Long.parseLong(splitResult[i++]); } } catch (final Throwable e) { - s_logger.warn("Unable to parse return from script return of network usage command: " + e.toString(), e); + logger.warn("Unable to parse return from script return of network usage command: " + e.toString(), e); } } return stats; } protected Answer execute(final SetMonitorServiceCommand cmd) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Executing resource SetMonitorServiceCommand: " + s_gson.toJson(cmd)); + if (logger.isInfoEnabled()) { + logger.info("Executing resource SetMonitorServiceCommand: " + s_gson.toJson(cmd)); } final String controlIp = getRouterSshControlIp(cmd); final String config = cmd.getConfiguration(); if (org.apache.commons.lang3.StringUtils.isBlank(config)) { - s_logger.error("SetMonitorServiceCommand should have config for this case"); + logger.error("SetMonitorServiceCommand should have config for this case"); return new Answer(cmd, false, "SetMonitorServiceCommand failed due to missing config"); } @@ -2099,14 +2097,14 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S if (!result.first()) { final String msg= "monitor_service.sh failed on domain router " + controlIp + " failed " + result.second(); - s_logger.error(msg); + logger.error(msg); return new Answer(cmd, false, msg); } return new Answer(cmd); } catch (final Throwable e) { - s_logger.error("Unexpected exception: " + e.toString(), e); + logger.error("Unexpected exception: " + e.toString(), e); return new Answer(cmd, false, "SetMonitorServiceCommand failed due to " + e); } } @@ -2116,28 +2114,28 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final String privateIp = cmd.getIp(); final int cmdPort = cmd.getPort(); - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port, " + privateIp + ":" + cmdPort); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port, " + privateIp + ":" + cmdPort); } try { final String result = connect(cmd.getName(), privateIp, cmdPort); if (result != null) { - s_logger.error("Can not ping System vm " + vmName + "due to:" + result); + logger.error("Can not ping System vm " + vmName + "due to:" + result); return new CheckSshAnswer(cmd, "Can not ping System vm " + vmName + "due to:" + result); } } catch (final Exception e) { - s_logger.error("Can not ping System vm " + vmName + "due to exception"); + logger.error("Can not ping System vm " + vmName + "due to exception"); return new CheckSshAnswer(cmd, e); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Ping command port succeeded for vm " + vmName); + if (logger.isDebugEnabled()) { + logger.debug("Ping command port succeeded for vm " + vmName); } if (VirtualMachineName.isValidRouterName(vmName)) { - if (s_logger.isDebugEnabled()) { - s_logger.debug("Execute network usage setup command on " + vmName); + if (logger.isDebugEnabled()) { + logger.debug("Execute network usage setup command on " + vmName); } networkUsage(privateIp, "create", null); } @@ -2162,8 +2160,8 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } try { - if (s_logger.isTraceEnabled()) { - s_logger.trace("Executing /opt/cloud/bin/netusage.sh " + args + " on DomR " + privateIpAddress); + if (logger.isTraceEnabled()) { + logger.trace("Executing /opt/cloud/bin/netusage.sh " + args + " on DomR " + privateIpAddress); } final Pair result = @@ -2175,7 +2173,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S return result.second(); } catch (final Throwable e) { - s_logger.error("Unable to execute NetworkUsage command on DomR (" + privateIpAddress + "), domR may not be ready yet. failure due to " + e); + logger.error("Unable to execute NetworkUsage command on DomR (" + privateIpAddress + "), domR may not be ready yet. failure due to " + e); } return null; @@ -2192,12 +2190,12 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S } assert keyFile != null; if (!keyFile.exists()) { - s_logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); + logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString()); } return keyFile; } - public static String postHttpRequest(final String jsonCmd, final URI agentUri) { + public String postHttpRequest(final String jsonCmd, final URI agentUri) { // Using Apache's HttpClient for HTTP POST // Java-only approach discussed at on StackOverflow concludes with // comment to use Apache HttpClient @@ -2205,7 +2203,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S // use Apache. String logMessage = StringEscapeUtils.unescapeJava(jsonCmd); logMessage = cleanPassword(logMessage); - s_logger.debug("POST request to " + agentUri.toString() + logger.debug("POST request to " + agentUri.toString() + " with contents " + logMessage); // Create request @@ -2225,13 +2223,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final ClientConnectionManager ccm = new BasicClientConnectionManager(registry); httpClient = new DefaultHttpClient(ccm); } catch (final KeyManagementException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (final UnrecoverableKeyException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (final NoSuchAlgorithmException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } catch (final KeyStoreException e) { - s_logger.error("failed to initialize http client " + e.getMessage()); + logger.error("failed to initialize http client " + e.getMessage()); } String result = null; @@ -2246,33 +2244,33 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S final StringEntity cmdJson = new StringEntity(jsonCmd); request.addHeader("content-type", "application/json"); request.setEntity(cmdJson); - s_logger.debug("Sending cmd to " + agentUri.toString() + logger.debug("Sending cmd to " + agentUri.toString() + " cmd data:" + logMessage); final HttpResponse response = httpClient.execute(request); // Unsupported commands will not route. if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) { final String errMsg = "Failed to send : HTTP error code : " + response.getStatusLine().getStatusCode(); - s_logger.error(errMsg); + logger.error(errMsg); final String unsupportMsg = "Unsupported command " + agentUri.getPath() + ". Are you sure you got the right type of" + " server?"; final Answer ans = new UnsupportedAnswer(null, unsupportMsg); - s_logger.error(ans); + logger.error(ans); result = s_gson.toJson(new Answer[] {ans}); } else if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { final String errMsg = "Failed send to " + agentUri.toString() + " : HTTP error code : " + response.getStatusLine().getStatusCode(); - s_logger.error(errMsg); + logger.error(errMsg); return null; } else { result = EntityUtils.toString(response.getEntity()); final String logResult = cleanPassword(StringEscapeUtils.unescapeJava(result)); - s_logger.debug("POST response is " + logResult); + logger.debug("POST response is " + logResult); } } catch (final ClientProtocolException protocolEx) { // Problem with HTTP message exchange - s_logger.error(protocolEx); + logger.error(protocolEx); } catch (final IOException connEx) { // Problem with underlying communications - s_logger.error(connEx); + logger.error(connEx); } finally { httpClient.getConnectionManager().shutdown(); } @@ -2354,7 +2352,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S // VM patching/rebooting time that may need int retry = this.retry; while (System.currentTimeMillis() - startTick <= opsTimeout || --retry > 0) { - s_logger.info("Trying to connect to " + ipAddress); + logger.info("Trying to connect to " + ipAddress); try (SocketChannel sch = SocketChannel.open();) { sch.configureBlocking(true); sch.socket().setSoTimeout(5000); @@ -2363,7 +2361,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S sch.connect(addr); return null; } catch (final IOException e) { - s_logger.info("Could] not connect to " + ipAddress + " due to " + e.toString()); + logger.info("Could] not connect to " + ipAddress + " due to " + e.toString()); if (e instanceof ConnectException) { // if connection is refused because of VM is being started, // we give it more sleep time @@ -2371,7 +2369,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S try { Thread.sleep(5000); } catch (final InterruptedException ex) { - s_logger.debug("[ignored] interrupted while waiting to retry connecting to vm after exception: "+e.getLocalizedMessage()); + logger.debug("[ignored] interrupted while waiting to retry connecting to vm after exception: "+e.getLocalizedMessage()); } } } @@ -2379,11 +2377,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S try { Thread.sleep(1000); } catch (final InterruptedException ex) { - s_logger.debug("[ignored] interrupted while connecting to vm."); + logger.debug("[ignored] interrupted while connecting to vm."); } } - s_logger.info("Unable to logon to " + ipAddress); + logger.info("Unable to logon to " + ipAddress); return "Unable to connect"; } diff --git a/plugins/hypervisors/hyperv/src/main/java/org/apache/cloudstack/storage/motion/HypervStorageMotionStrategy.java b/plugins/hypervisors/hyperv/src/main/java/org/apache/cloudstack/storage/motion/HypervStorageMotionStrategy.java index 19c655b8f21..0e189d05000 100644 --- a/plugins/hypervisors/hyperv/src/main/java/org/apache/cloudstack/storage/motion/HypervStorageMotionStrategy.java +++ b/plugins/hypervisors/hyperv/src/main/java/org/apache/cloudstack/storage/motion/HypervStorageMotionStrategy.java @@ -34,7 +34,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; @@ -59,7 +60,7 @@ import com.cloud.vm.dao.VMInstanceDao; @Component public class HypervStorageMotionStrategy implements DataMotionStrategy { - private static final Logger s_logger = Logger.getLogger(HypervStorageMotionStrategy.class); + protected Logger logger = LogManager.getLogger(getClass()); @Inject AgentManager agentMgr; @Inject VolumeDao volDao; @Inject VolumeDataFactory volFactory; @@ -99,7 +100,7 @@ public class HypervStorageMotionStrategy implements DataMotionStrategy { throw new CloudRuntimeException("Unsupported operation requested for moving data."); } } catch (Exception e) { - s_logger.error("copy failed", e); + logger.error("copy failed", e); errMsg = e.toString(); } @@ -124,10 +125,10 @@ public class HypervStorageMotionStrategy implements DataMotionStrategy { MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getPrivateIpAddress()); MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), command); if (answer == null) { - s_logger.error("Migration with storage of vm " + vm + " failed."); + logger.error("Migration with storage of vm " + vm + " failed."); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost); } else if (!answer.getResult()) { - s_logger.error("Migration with storage of vm " + vm+ " failed. Details: " + answer.getDetails()); + logger.error("Migration with storage of vm " + vm+ " failed. Details: " + answer.getDetails()); throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails()); } else { @@ -137,7 +138,7 @@ public class HypervStorageMotionStrategy implements DataMotionStrategy { return answer; } catch (OperationTimedoutException e) { - s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e); + logger.error("Error while migrating vm " + vm + " to host " + destHost, e); throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId()); } } @@ -170,7 +171,7 @@ public class HypervStorageMotionStrategy implements DataMotionStrategy { } if (!updated) { - s_logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated."); + logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated."); } } } diff --git a/plugins/hypervisors/hyperv/src/test/java/com/cloud/hypervisor/hyperv/test/HypervDirectConnectResourceTest.java b/plugins/hypervisors/hyperv/src/test/java/com/cloud/hypervisor/hyperv/test/HypervDirectConnectResourceTest.java index bf069183cd9..d2e92bd5a2b 100644 --- a/plugins/hypervisors/hyperv/src/test/java/com/cloud/hypervisor/hyperv/test/HypervDirectConnectResourceTest.java +++ b/plugins/hypervisors/hyperv/src/test/java/com/cloud/hypervisor/hyperv/test/HypervDirectConnectResourceTest.java @@ -35,7 +35,8 @@ import java.util.Properties; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -85,7 +86,7 @@ import com.cloud.utils.exception.CloudRuntimeException; **/ public class HypervDirectConnectResourceTest { - private static final Logger s_logger = Logger.getLogger(HypervDirectConnectResourceTest.class.getName()); + protected Logger logger = LogManager.getLogger(getClass()); // TODO: make this a config parameter private static final String sampleLegitDiskImageURL = "http://s3-eu-west-1.amazonaws.com/cshv3eu/SmallDisk.vhdx"; @@ -188,30 +189,30 @@ public class HypervDirectConnectResourceTest { continue; } Assert.assertTrue("Should have deleted file " + file.getPath(), file.delete()); - s_logger.info("Cleaned up by delete file " + file.getPath()); + logger.info("Cleaned up by delete file " + file.getPath()); } s_testSampleVolumeTempURIJSON = createTestDiskImageFromExistingImage(testVolWorks, s_testLocalStorePath, s_testSampleVolumeTempUUID); - s_logger.info("Created " + s_testSampleVolumeTempURIJSON); + logger.info("Created " + s_testSampleVolumeTempURIJSON); s_testSampleVolumeCorruptURIJSON = createTestDiskImageFromExistingImage(testVolWorks, s_testLocalStorePath, s_testSampleVolumeCorruptUUID); - s_logger.info("Created " + s_testSampleVolumeCorruptURIJSON); + logger.info("Created " + s_testSampleVolumeCorruptURIJSON); createTestDiskImageFromExistingImage(testVolWorks, s_testLocalStorePath, s_testSampleTemplateUUID); s_testSampleTemplateURLJSON = s_testSampleTemplateUUID; - s_logger.info("Created " + s_testSampleTemplateURLJSON + " in local storage."); + logger.info("Created " + s_testSampleTemplateURLJSON + " in local storage."); // Create secondary storage template: createTestDiskImageFromExistingImage(testVolWorks, testSecondarStoreDir.getAbsolutePath(), "af39aa7f-2b12-37e1-86d3-e23f2f005101.vhdx"); - s_logger.info("Created " + "af39aa7f-2b12-37e1-86d3-e23f2f005101.vhdx" + " in secondary (NFS) storage."); + logger.info("Created " + "af39aa7f-2b12-37e1-86d3-e23f2f005101.vhdx" + " in secondary (NFS) storage."); s_testLocalStorePathJSON = s_gson.toJson(s_testLocalStorePath); String agentIp = (String)params.get("ipaddress"); - s_logger.info("Test using agent IP address " + agentIp); + logger.info("Test using agent IP address " + agentIp); params.put("agentIp", agentIp); setTestJsonResult(params); s_hypervresource.configure("hypervresource", params); // Verify sample template is in place storage pool - s_logger.info("setUp complete, sample StoragePool at " + s_testLocalStorePathJSON + " sample template at " + s_testSampleTemplateURLJSON); + logger.info("setUp complete, sample StoragePool at " + s_testLocalStorePathJSON + " sample template at " + s_testSampleTemplateURLJSON); s_agentExecutable = (String)params.get("agent.executable"); s_testPrimaryDataStoreHost = (String)params.get("ipaddress"); @@ -269,11 +270,11 @@ public class HypervDirectConnectResourceTest { Command[] cmds = {scmd}; String cmdsStr = s_gson.toJson(cmds); - s_logger.debug("Commands[] toJson is " + cmdsStr); + logger.debug("Commands[] toJson is " + cmdsStr); Command[] result = s_gson.fromJson(cmdsStr, Command[].class); - s_logger.debug("Commands[] fromJson is " + s_gson.toJson(result)); - s_logger.debug("Commands[] first element has type" + result[0].toString()); + logger.debug("Commands[] fromJson is " + s_gson.toJson(result)); + logger.debug("Commands[] first element has type" + result[0].toString()); } // @Test @@ -286,7 +287,7 @@ public class HypervDirectConnectResourceTest { sscmd.setGuid(pi.getUuid()); sscmd.setDataCenter("foo"); sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL); - s_logger.debug("StartupStorageCommand fromJson is " + s_gson.toJson(sscmd)); + logger.debug("StartupStorageCommand fromJson is " + s_gson.toJson(sscmd)); } @Test @@ -305,7 +306,7 @@ public class HypervDirectConnectResourceTest { StoragePoolVO pool = createTestStoragePoolVO(folderName); CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool); - s_logger.debug("TestCreateStoragePoolCommand sending " + s_gson.toJson(cmd)); + logger.debug("TestCreateStoragePoolCommand sending " + s_gson.toJson(cmd)); Answer ans = s_hypervresource.executeRequest(cmd); Assert.assertTrue(ans.getResult()); @@ -340,7 +341,7 @@ public class HypervDirectConnectResourceTest { } // Use same spec for pool - s_logger.info("Createing pool at : " + folderName); + logger.info("Createing pool at : " + folderName); StoragePoolVO pool = new StoragePoolVO(StoragePoolType.Filesystem, "127.0.0.1", -1, folderName); pool.setUuid(s_testLocalStoreUUID); @@ -363,7 +364,7 @@ public class HypervDirectConnectResourceTest { } // Use same spec for pool - s_logger.info("Createing pool at : " + folderName); + logger.info("Createing pool at : " + folderName); StoragePoolVO pool = new StoragePoolVO(StoragePoolType.Filesystem, "127.0.0.1", -1, folderName); return pool; @@ -377,8 +378,8 @@ public class HypervDirectConnectResourceTest { if (result == null) { result = "NULL"; } - s_logger.debug("TestInitialize returned " + result); - s_logger.debug("TestInitialize expected " + _setTestJsonResultStr); + logger.debug("TestInitialize returned " + result); + logger.debug("TestInitialize expected " + _setTestJsonResultStr); Assert.assertTrue("StartupCommand[] not what we expected", _setTestJsonResultStr.equals(result)); return; } @@ -393,9 +394,9 @@ public class HypervDirectConnectResourceTest { private void corePrimaryStorageDownloadCommandTestCycle(final PrimaryStorageDownloadCommand cmd) { PrimaryStorageDownloadAnswer ans = (PrimaryStorageDownloadAnswer)s_hypervresource.executeRequest(cmd); if (!ans.getResult()) { - s_logger.error(ans.getDetails()); + logger.error(ans.getDetails()); } else { - s_logger.debug(ans.getDetails()); + logger.debug(ans.getDetails()); } Assert.assertTrue(ans.getDetails(), ans.getResult()); @@ -444,7 +445,7 @@ public class HypervDirectConnectResourceTest { testSampleTemplateURLFile.exists()); int fileCount = destDir.listFiles().length; - s_logger.debug(" test local store has " + fileCount + "files"); + logger.debug(" test local store has " + fileCount + "files"); // Test requires there to be a template at the tempalteUrl, which is its // location in the local file system. CreateCommand cmd = s_gson.fromJson(sample, CreateCommand.class); @@ -527,7 +528,7 @@ public class HypervDirectConnectResourceTest { private StartAnswer simpleVmStart(final String sample) { StartCommand cmd = s_gson.fromJson(sample, StartCommand.class); - s_logger.info("StartCommand sample " + s_gson.toJson(cmd)); + logger.info("StartCommand sample " + s_gson.toJson(cmd)); StartAnswer ans = (StartAnswer)s_hypervresource.executeRequest(cmd); return ans; } @@ -553,7 +554,7 @@ public class HypervDirectConnectResourceTest { String sample = "{\"id\":\"" + s_testLocalStoreUUID + "\",\"localPath\":" + s_testLocalStorePathJSON + "," + "\"pooltype\":\"Filesystem\"," + "\"contextMap\":{},\"wait\":0}"; - s_logger.info("Sample JSON: " + sample); + logger.info("Sample JSON: " + sample); GetStorageStatsCommand cmd = s_gson.fromJson(sample, GetStorageStatsCommand.class); s_hypervresource.executeRequest(cmd); @@ -573,7 +574,7 @@ public class HypervDirectConnectResourceTest { writer.flush(); writer.close(); } catch (IOException ex) { - s_logger.debug("Error closing agent at " + s_agentExecutable + " message " + ex.getMessage()); + logger.debug("Error closing agent at " + s_agentExecutable + " message " + ex.getMessage()); } } @@ -592,7 +593,7 @@ public class HypervDirectConnectResourceTest { s_agentProc = builder.start(); Thread.sleep(4000); } catch (Exception ex) { - s_logger.debug("Error calling starting aget at " + s_agentExecutable + " message " + ex.getMessage()); + logger.debug("Error calling starting aget at " + s_agentExecutable + " message " + ex.getMessage()); } } @@ -617,14 +618,14 @@ public class HypervDirectConnectResourceTest { Assert.assertTrue(ans.getDetails() == null); } - public static Properties loadProperties() throws ConfigurationException { + public Properties loadProperties() throws ConfigurationException { Properties properties = new Properties(); final File file = PropertiesUtil.findConfigFile("agent.properties"); if (file == null) { throw new ConfigurationException("Unable to find agent.properties."); } - s_logger.info("agent.properties found at " + file.getAbsolutePath()); + logger.info("agent.properties found at " + file.getAbsolutePath()); try { properties.load(new FileInputStream(file)); diff --git a/plugins/hypervisors/kvm/pom.xml b/plugins/hypervisors/kvm/pom.xml index 9265d66c79a..eec93d33da5 100644 --- a/plugins/hypervisors/kvm/pom.xml +++ b/plugins/hypervisors/kvm/pom.xml @@ -24,7 +24,7 @@ org.apache.cloudstack cloudstack-plugins - 4.19.0.0-SNAPSHOT + 4.20.0.0-SNAPSHOT ../../pom.xml diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/ha/KVMInvestigator.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/ha/KVMInvestigator.java index 022501524f7..8fc74826242 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/ha/KVMInvestigator.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/ha/KVMInvestigator.java @@ -36,13 +36,11 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver import org.apache.cloudstack.ha.HAManager; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.List; public class KVMInvestigator extends AdapterBase implements Investigator { - private final static Logger s_logger = Logger.getLogger(KVMInvestigator.class); @Inject private HostDao _hostDao; @Inject @@ -62,7 +60,7 @@ public class KVMInvestigator extends AdapterBase implements Investigator { return haManager.isVMAliveOnHost(host); } Status status = isAgentAlive(host); - s_logger.debug("HA: HOST is ineligible legacy state " + status + " for host " + host.getId()); + logger.debug("HA: HOST is ineligible legacy state " + status + " for host " + host.getId()); if (status == null) { throw new UnknownVM(); } @@ -90,7 +88,7 @@ public class KVMInvestigator extends AdapterBase implements Investigator { storageSupportHA = storageSupportHa(zonePools); } if (!storageSupportHA) { - s_logger.warn( + logger.warn( "Agent investigation was requested on host " + agent + ", but host does not support investigation because it has no NFS storage. Skipping investigation."); return Status.Disconnected; } @@ -106,7 +104,7 @@ public class KVMInvestigator extends AdapterBase implements Investigator { hostStatus = answer.getResult() ? Status.Down : Status.Up; } } catch (Exception e) { - s_logger.debug("Failed to send command to host: " + agent.getId()); + logger.debug("Failed to send command to host: " + agent.getId()); } if (hostStatus == null) { hostStatus = Status.Disconnected; @@ -118,18 +116,18 @@ public class KVMInvestigator extends AdapterBase implements Investigator { || (neighbor.getHypervisorType() != Hypervisor.HypervisorType.KVM && neighbor.getHypervisorType() != Hypervisor.HypervisorType.LXC)) { continue; } - s_logger.debug("Investigating host:" + agent.getId() + " via neighbouring host:" + neighbor.getId()); + logger.debug("Investigating host:" + agent.getId() + " via neighbouring host:" + neighbor.getId()); try { Answer answer = _agentMgr.easySend(neighbor.getId(), cmd); if (answer != null) { neighbourStatus = answer.getResult() ? Status.Down : Status.Up; - s_logger.debug("Neighbouring host:" + neighbor.getId() + " returned status:" + neighbourStatus + " for the investigated host:" + agent.getId()); + logger.debug("Neighbouring host:" + neighbor.getId() + " returned status:" + neighbourStatus + " for the investigated host:" + agent.getId()); if (neighbourStatus == Status.Up) { break; } } } catch (Exception e) { - s_logger.debug("Failed to send command to host: " + neighbor.getId()); + logger.debug("Failed to send command to host: " + neighbor.getId()); } } if (neighbourStatus == Status.Up && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) { @@ -138,7 +136,7 @@ public class KVMInvestigator extends AdapterBase implements Investigator { if (neighbourStatus == Status.Down && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) { hostStatus = Status.Down; } - s_logger.debug("HA: HOST is ineligible legacy state " + hostStatus + " for host " + agent.getId()); + logger.debug("HA: HOST is ineligible legacy state " + hostStatus + " for host " + agent.getId()); return hostStatus; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverImpl.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverImpl.java index 022eafaca8a..2a8d87af643 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverImpl.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverImpl.java @@ -21,7 +21,6 @@ package com.cloud.hypervisor.kvm.dpdk; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.util.Map; @@ -31,7 +30,6 @@ public class DpdkDriverImpl extends AdapterBase implements DpdkDriver { private final String dpdkPortVhostUserType = "dpdkvhostuser"; private final String dpdkPortVhostUserClientType = "dpdkvhostuserclient"; - private static final Logger s_logger = Logger.getLogger(DpdkDriver.class); public DpdkDriverImpl() { } @@ -48,7 +46,7 @@ public class DpdkDriverImpl extends AdapterBase implements DpdkDriver { * Get the latest DPDK port number created on a DPDK enabled host */ public int getDpdkLatestPortNumberUsed() { - s_logger.debug("Checking the last DPDK port created"); + logger.debug("Checking the last DPDK port created"); String cmd = "ovs-vsctl show | grep Port | grep " + DPDK_PORT_PREFIX + " | " + "awk '{ print $2 }' | sort -rV | head -1"; String port = Script.runSimpleBashScript(cmd); @@ -82,7 +80,7 @@ public class DpdkDriverImpl extends AdapterBase implements DpdkDriver { } String cmd = stringBuilder.toString(); - s_logger.debug("DPDK property enabled, executing: " + cmd); + logger.debug("DPDK property enabled, executing: " + cmd); Script.runSimpleBashScript(cmd); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java index 39ecc9182f0..26b8de53083 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java @@ -31,7 +31,6 @@ import javax.naming.ConfigurationException; import com.cloud.utils.net.NetUtils; import com.cloud.utils.script.OutputInterpreter; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.NicTO; @@ -44,7 +43,6 @@ import com.cloud.utils.script.Script; public class BridgeVifDriver extends VifDriverBase { - private static final Logger s_logger = Logger.getLogger(BridgeVifDriver.class); private int _timeout; private final Object _vnetBridgeMonitor = new Object(); @@ -92,9 +90,9 @@ public class BridgeVifDriver extends VifDriverBase { for (File netdev : netdevs) { final File isbridge = new File(netdev.getAbsolutePath() + "/bridge"); final String netdevName = netdev.getName(); - s_logger.debug("looking in file " + netdev.getAbsolutePath() + "/bridge"); + logger.debug("looking in file " + netdev.getAbsolutePath() + "/bridge"); if (isbridge.exists()) { - s_logger.debug("Found bridge " + netdevName); + logger.debug("Found bridge " + netdevName); bridges.add(netdevName); } } @@ -103,7 +101,7 @@ public class BridgeVifDriver extends VifDriverBase { String publicBridgeName = _libvirtComputingResource.getPublicBridgeName(); for (final String bridge : bridges) { - s_logger.debug("looking for pif for bridge " + bridge); + logger.debug("looking for pif for bridge " + bridge); final String pif = getPif(bridge); if (_libvirtComputingResource.isPublicBridge(bridge)) { _pifs.put("public", pif); @@ -117,10 +115,10 @@ public class BridgeVifDriver extends VifDriverBase { // guest(private) creates bridges on a pif, if private bridge not found try pif direct // This addresses the unnecessary requirement of someone to create an unused bridge just for traffic label if (_pifs.get("private") == null) { - s_logger.debug("guest(private) traffic label '" + guestBridgeName + "' not found as bridge, looking for physical interface"); + logger.debug("guest(private) traffic label '" + guestBridgeName + "' not found as bridge, looking for physical interface"); final File dev = new File("/sys/class/net/" + guestBridgeName); if (dev.exists()) { - s_logger.debug("guest(private) traffic label '" + guestBridgeName + "' found as a physical device"); + logger.debug("guest(private) traffic label '" + guestBridgeName + "' found as a physical device"); _pifs.put("private", guestBridgeName); } } @@ -128,15 +126,15 @@ public class BridgeVifDriver extends VifDriverBase { // public creates bridges on a pif, if private bridge not found try pif direct // This addresses the unnecessary requirement of someone to create an unused bridge just for traffic label if (_pifs.get("public") == null) { - s_logger.debug("public traffic label '" + publicBridgeName+ "' not found as bridge, looking for physical interface"); + logger.debug("public traffic label '" + publicBridgeName+ "' not found as bridge, looking for physical interface"); final File dev = new File("/sys/class/net/" + publicBridgeName); if (dev.exists()) { - s_logger.debug("public traffic label '" + publicBridgeName + "' found as a physical device"); + logger.debug("public traffic label '" + publicBridgeName + "' found as a physical device"); _pifs.put("public", publicBridgeName); } } - s_logger.debug("done looking for pifs, no more bridges"); + logger.debug("done looking for pifs, no more bridges"); } private String getPif(final String bridge) { @@ -159,7 +157,7 @@ public class BridgeVifDriver extends VifDriverBase { // if bridgeName already refers to a pif, return it as-is return bridgeName; } - s_logger.debug("failing to get physical interface from bridge " + bridgeName + ", does " + brif.getAbsolutePath() + "exist?"); + logger.debug("failing to get physical interface from bridge " + bridgeName + ", does " + brif.getAbsolutePath() + "exist?"); return ""; } @@ -167,13 +165,13 @@ public class BridgeVifDriver extends VifDriverBase { for (File anInterface : interfaces) { final String fname = anInterface.getName(); - s_logger.debug("matchPifFileInDirectory: file name '" + fname + "'"); + logger.debug("matchPifFileInDirectory: file name '" + fname + "'"); if (LibvirtComputingResource.isInterface(fname)) { return fname; } } - s_logger.debug("failing to get physical interface from bridge " + bridgeName + ", did not find an eth*, bond*, team*, vlan*, em*, p*p*, ens*, eno*, enp*, or enx* in " + brif.getAbsolutePath()); + logger.debug("failing to get physical interface from bridge " + bridgeName + ", did not find an eth*, bond*, team*, vlan*, em*, p*p*, ens*, eno*, enp*, or enx* in " + brif.getAbsolutePath()); return ""; } @@ -189,10 +187,10 @@ public class BridgeVifDriver extends VifDriverBase { @Override public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType, String nicAdapter, Map extraConfig) throws InternalErrorException, LibvirtException { - if (s_logger.isDebugEnabled()) { - s_logger.debug("nic=" + nic); + if (logger.isDebugEnabled()) { + logger.debug("nic=" + nic); if (nicAdapter != null && !nicAdapter.isEmpty()) { - s_logger.debug("custom nic adapter=" + nicAdapter); + logger.debug("custom nic adapter=" + nicAdapter); } } @@ -215,7 +213,7 @@ public class BridgeVifDriver extends VifDriverBase { if (nic.getType() == Networks.TrafficType.Guest) { if (isBroadcastTypeVlanOrVxlan(nic) && isValidProtocolAndVnetId(vNetId, protocol)) { if (trafficLabel != null && !trafficLabel.isEmpty()) { - s_logger.debug("creating a vNet dev and bridge for guest traffic per traffic label " + trafficLabel); + logger.debug("creating a vNet dev and bridge for guest traffic per traffic label " + trafficLabel); String brName = createVnetBr(vNetId, trafficLabel, protocol); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else { @@ -238,7 +236,7 @@ public class BridgeVifDriver extends VifDriverBase { } else if (nic.getType() == Networks.TrafficType.Public) { if (isBroadcastTypeVlanOrVxlan(nic) && isValidProtocolAndVnetId(vNetId, protocol)) { if (trafficLabel != null && !trafficLabel.isEmpty()) { - s_logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel); + logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel); String brName = createVnetBr(vNetId, trafficLabel, protocol); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else { @@ -309,7 +307,7 @@ public class BridgeVifDriver extends VifDriverBase { if (protocol.equals(Networks.BroadcastDomainType.Vxlan.scheme())) { script = _modifyVxlanPath; } - final Script command = new Script(script, _timeout, s_logger); + final Script command = new Script(script, _timeout, logger); command.add("-v", vnetId); command.add("-p", pif); command.add("-b", brName); @@ -355,7 +353,7 @@ public class BridgeVifDriver extends VifDriverBase { } if (vNetId == null || vNetId.isEmpty()) { - s_logger.debug("unable to get a vNet ID from name " + brName); + logger.debug("unable to get a vNet ID from name " + brName); return; } @@ -366,7 +364,7 @@ public class BridgeVifDriver extends VifDriverBase { scriptPath = _modifyVlanPath; } - final Script command = new Script(scriptPath, _timeout, s_logger); + final Script command = new Script(scriptPath, _timeout, logger); command.add("-o", "delete"); command.add("-v", vNetId); command.add("-p", pName); @@ -377,7 +375,7 @@ public class BridgeVifDriver extends VifDriverBase { final String result = command.execute(); if (result != null) { - s_logger.debug("Delete bridge " + brName + " failed: " + result); + logger.debug("Delete bridge " + brName + " failed: " + result); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/DirectVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/DirectVifDriver.java index 5037ad1aec7..71afc940932 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/DirectVifDriver.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/DirectVifDriver.java @@ -20,7 +20,6 @@ package com.cloud.hypervisor.kvm.resource; import org.apache.commons.compress.utils.Sets; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.NicTO; @@ -31,7 +30,6 @@ import java.util.Map; public class DirectVifDriver extends VifDriverBase { - private static final Logger s_logger = Logger.getLogger(DirectVifDriver.class); /** * Experimental driver to configure direct networking in libvirt. This should only diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java index 178728b7f96..2386e7d2d59 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java @@ -26,7 +26,6 @@ import java.util.regex.Pattern; import javax.naming.ConfigurationException; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.NicTO; @@ -41,7 +40,6 @@ import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; public class IvsVifDriver extends VifDriverBase { - private static final Logger s_logger = Logger.getLogger(IvsVifDriver.class); private int _timeout; private final Object _vnetBridgeMonitor = new Object(); @@ -100,7 +98,7 @@ public class IvsVifDriver extends VifDriverBase { if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan || nic.getBroadcastType() == Networks.BroadcastDomainType.Pvlan) && !vlanId.equalsIgnoreCase("untagged")) { if (trafficLabel != null && !trafficLabel.isEmpty()) { - s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); + logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); intf.defEthernet("ivsnet-" + nic.getUuid().substring(0, 5), nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), _ivsIfUpPath, networkRateKBps); } else { throw new InternalErrorException("no traffic label "); @@ -114,7 +112,7 @@ public class IvsVifDriver extends VifDriverBase { if ((nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan) && (vNetId != null) && (protocol != null) && (!vNetId.equalsIgnoreCase("untagged")) || (nic.getBroadcastType() == Networks.BroadcastDomainType.Vxlan)) { if (trafficLabel != null && !trafficLabel.isEmpty()) { - s_logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel); + logger.debug("creating a vNet dev and bridge for public traffic per traffic label " + trafficLabel); String brName = createVnetBr(vNetId, trafficLabel, protocol); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else { @@ -180,7 +178,7 @@ public class IvsVifDriver extends VifDriverBase { if (protocol.equals(Networks.BroadcastDomainType.Vxlan.scheme())) { script = _modifyVxlanPath; } - final Script command = new Script(script, _timeout, s_logger); + final Script command = new Script(script, _timeout, logger); command.add("-v", vnetId); command.add("-p", pif); command.add("-b", brName); @@ -226,7 +224,7 @@ public class IvsVifDriver extends VifDriverBase { } if (vNetId == null || vNetId.isEmpty()) { - s_logger.debug("unable to get a vNet ID from name " + brName); + logger.debug("unable to get a vNet ID from name " + brName); return; } @@ -237,7 +235,7 @@ public class IvsVifDriver extends VifDriverBase { scriptPath = _modifyVlanPath; } - final Script command = new Script(scriptPath, _timeout, s_logger); + final Script command = new Script(scriptPath, _timeout, logger); command.add("-o", "delete"); command.add("-v", vNetId); command.add("-p", pName); @@ -245,7 +243,7 @@ public class IvsVifDriver extends VifDriverBase { final String result = command.execute(); if (result != null) { - s_logger.debug("Delete bridge " + brName + " failed: " + result); + logger.debug("Delete bridge " + brName + " failed: " + result); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMGuestOsMapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMGuestOsMapper.java index 1cf74501770..20cd9bb5ac2 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMGuestOsMapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMGuestOsMapper.java @@ -19,10 +19,11 @@ package com.cloud.hypervisor.kvm.resource; import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class KVMGuestOsMapper { - private static final Logger s_logger = Logger.getLogger(KVMGuestOsMapper.class); + protected Logger logger = LogManager.getLogger(getClass()); private static Map s_mapper = new HashMap(); static { s_mapper.put("CentOS 4.5 (32-bit)", "CentOS 4.5"); @@ -133,10 +134,10 @@ public class KVMGuestOsMapper { } - public static String getGuestOsName(String guestOsName) { + public String getGuestOsName(String guestOsName) { String guestOS = s_mapper.get(guestOsName); if (guestOS == null) { - s_logger.debug("Can't find the mapping of guest os: " + guestOsName); + logger.debug("Can't find the mapping of guest os: " + guestOsName); return "Other"; } else { return guestOS; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHABase.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHABase.java index b9abea4f0bc..896426addca 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHABase.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHABase.java @@ -18,7 +18,8 @@ package com.cloud.hypervisor.kvm.resource; import java.io.File; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.LibvirtException; import org.libvirt.StoragePool; import org.libvirt.StoragePoolInfo; @@ -32,7 +33,7 @@ import com.cloud.agent.properties.AgentProperties; import com.cloud.agent.properties.AgentPropertiesFileHandler; public class KVMHABase { - private static final Logger s_logger = Logger.getLogger(KVMHABase.class); + protected Logger logger = LogManager.getLogger(getClass()); private long _timeout = 60000; /* 1 minutes */ protected static String s_heartBeatPath; protected long _heartBeatUpdateTimeout = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HEARTBEAT_UPDATE_TIMEOUT); @@ -173,14 +174,14 @@ public class KVMHABase { } } catch (LibvirtException e) { - s_logger.debug("Ignoring libvirt error.", e); + logger.debug("Ignoring libvirt error.", e); } finally { try { if (pool != null) { pool.free(); } } catch (LibvirtException e) { - s_logger.debug("Ignoring libvirt error.", e); + logger.debug("Ignoring libvirt error.", e); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAChecker.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAChecker.java index 2df70375107..db6190fa8f2 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAChecker.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAChecker.java @@ -20,12 +20,10 @@ import java.util.List; import java.util.concurrent.Callable; import java.util.stream.Collectors; -import org.apache.log4j.Logger; import com.cloud.agent.api.to.HostTO; public class KVMHAChecker extends KVMHABase implements Callable { - private static final Logger s_logger = Logger.getLogger(KVMHAChecker.class); private List storagePools; private HostTO host; private boolean reportFailureIfOneStorageIsDown; @@ -46,7 +44,7 @@ public class KVMHAChecker extends KVMHABase implements Callable { String hostAndPools = String.format("host IP [%s] in pools [%s]", host.getPrivateNetwork().getIp(), storagePools.stream().map(pool -> pool.getPoolUUID()).collect(Collectors.joining(", "))); - s_logger.debug(String.format("Checking heart beat with KVMHAChecker for %s", hostAndPools)); + logger.debug(String.format("Checking heart beat with KVMHAChecker for %s", hostAndPools)); for (HAStoragePool pool : storagePools) { validResult = pool.getPool().checkingHeartBeat(pool, host); @@ -56,7 +54,7 @@ public class KVMHAChecker extends KVMHABase implements Callable { } if (!validResult) { - s_logger.warn(String.format("All checks with KVMHAChecker for %s considered it as dead. It may cause a shutdown of the host.", hostAndPools)); + logger.warn(String.format("All checks with KVMHAChecker for %s considered it as dead. It may cause a shutdown of the host.", hostAndPools)); } return validResult; @@ -64,7 +62,7 @@ public class KVMHAChecker extends KVMHABase implements Callable { @Override public Boolean call() throws Exception { - // s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new + // logger.addAppender(new org.apache.log4j.ConsoleAppender(new // org.apache.log4j.PatternLayout(), "System.out")); return checkingHeartBeat(); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java index eb09408c14e..cf407bfc08a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/KVMHAMonitor.java @@ -20,7 +20,6 @@ import com.cloud.agent.properties.AgentProperties; import com.cloud.agent.properties.AgentPropertiesFileHandler; import com.cloud.storage.Storage.StoragePoolType; import com.cloud.utils.script.Script; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; import org.libvirt.StoragePool; @@ -35,7 +34,6 @@ import java.util.concurrent.ConcurrentHashMap; public class KVMHAMonitor extends KVMHABase implements Runnable { - private static final Logger s_logger = Logger.getLogger(KVMHAMonitor.class); private final Map storagePool = new ConcurrentHashMap<>(); private final boolean rebootHostAndAlertManagementOnHeartbeatTimeout; @@ -98,7 +96,7 @@ public class KVMHAMonitor extends KVMHABase implements Runnable { result = executePoolHeartBeatCommand(uuid, primaryStoragePool, result); if (result != null && rebootHostAndAlertManagementOnHeartbeatTimeout) { - s_logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; stopping cloudstack-agent.", uuid, result)); + logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; stopping cloudstack-agent.", uuid, result)); primaryStoragePool.getPool().createHeartBeatCommand(primaryStoragePool, null, false);; } } @@ -115,11 +113,11 @@ public class KVMHAMonitor extends KVMHABase implements Runnable { result = primaryStoragePool.getPool().createHeartBeatCommand(primaryStoragePool, hostPrivateIp, true); if (result != null) { - s_logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; try: %s of %s.", uuid, result, i, _heartBeatUpdateMaxTries)); + logger.warn(String.format("Write heartbeat for pool [%s] failed: %s; try: %s of %s.", uuid, result, i, _heartBeatUpdateMaxTries)); try { Thread.sleep(_heartBeatUpdateRetrySleep); } catch (InterruptedException e) { - s_logger.debug("[IGNORED] Interrupted between heartbeat retries.", e); + logger.debug("[IGNORED] Interrupted between heartbeat retries.", e); } } else { break; @@ -135,21 +133,21 @@ public class KVMHAMonitor extends KVMHABase implements Runnable { StoragePool storage = conn.storagePoolLookupByUUIDString(uuid); if (storage == null || storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) { if (storage == null) { - s_logger.debug(String.format("Libvirt storage pool [%s] not found, removing from HA list.", uuid)); + logger.debug(String.format("Libvirt storage pool [%s] not found, removing from HA list.", uuid)); } else { - s_logger.debug(String.format("Libvirt storage pool [%s] found, but not running, removing from HA list.", uuid)); + logger.debug(String.format("Libvirt storage pool [%s] found, but not running, removing from HA list.", uuid)); } removedPools.add(uuid); } - s_logger.debug(String.format("Found NFS storage pool [%s] in libvirt, continuing.", uuid)); + logger.debug(String.format("Found NFS storage pool [%s] in libvirt, continuing.", uuid)); } catch (LibvirtException e) { - s_logger.debug(String.format("Failed to lookup libvirt storage pool [%s].", uuid), e); + logger.debug(String.format("Failed to lookup libvirt storage pool [%s].", uuid), e); if (e.toString().contains("pool not found")) { - s_logger.debug(String.format("Removing pool [%s] from HA monitor since it was deleted.", uuid)); + logger.debug(String.format("Removing pool [%s] from HA monitor since it was deleted.", uuid)); removedPools.add(uuid); } } @@ -164,7 +162,7 @@ public class KVMHAMonitor extends KVMHABase implements Runnable { try { Thread.sleep(_heartBeatUpdateFreq); } catch (InterruptedException e) { - s_logger.debug("[IGNORED] Interrupted between heartbeats.", e); + logger.debug("[IGNORED] Interrupted between heartbeats.", e); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtCapXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtCapXMLParser.java index 358fafae4b5..a2b422b8bfb 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtCapXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtCapXMLParser.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; -import org.apache.log4j.Logger; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -34,7 +33,6 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser { private boolean _archTypex8664 = false; private final StringBuffer _emulator = new StringBuffer(); private final StringBuffer _capXML = new StringBuffer(); - private static final Logger s_logger = Logger.getLogger(LibvirtCapXMLParser.class); private final ArrayList guestOsTypes = new ArrayList(); @Override @@ -63,7 +61,7 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser { } else if (_osType) { guestOsTypes.add(new String(ch, start, length)); } else if (_emulatorFlag) { - s_logger.debug("Found " + new String(ch, start, length) + " as a suiteable emulator"); + logger.debug("Found " + new String(ch, start, length) + " as a suiteable emulator"); _emulator.append(ch, start, length); } } @@ -112,9 +110,9 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser { _sp.parse(new InputSource(new StringReader(capXML)), this); return _capXML.toString(); } catch (SAXException se) { - s_logger.warn(se.getMessage()); + logger.warn(se.getMessage()); } catch (IOException ie) { - s_logger.error(ie.getMessage()); + logger.error(ie.getMessage()); } return null; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 60e6bcffeb6..b30f2b6a6f0 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -75,7 +75,8 @@ import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.xerces.impl.xpath.regex.Match; import org.joda.time.Duration; import org.libvirt.Connect; @@ -85,7 +86,6 @@ import org.libvirt.DomainInfo; import org.libvirt.DomainInfo.DomainState; import org.libvirt.DomainInterfaceStats; import org.libvirt.DomainSnapshot; -import org.libvirt.Library; import org.libvirt.LibvirtException; import org.libvirt.MemoryStatistic; import org.libvirt.Network; @@ -93,9 +93,6 @@ import org.libvirt.SchedParameter; import org.libvirt.SchedUlongParameter; import org.libvirt.Secret; import org.libvirt.VcpuInfo; -import org.libvirt.event.DomainEvent; -import org.libvirt.event.DomainEventDetail; -import org.libvirt.event.StoppedDetail; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -234,8 +231,8 @@ import com.google.gson.Gson; * pool | the parent of the storage pool hierarchy * } **/ public class LibvirtComputingResource extends ServerResourceBase implements ServerResource, VirtualRouterDeployer, ResourceStatusUpdater { - protected static Logger s_logger = Logger.getLogger(LibvirtComputingResource.class); + protected static Logger LOGGER = LogManager.getLogger(LibvirtComputingResource.class); private static final String CONFIG_VALUES_SEPARATOR = ","; @@ -469,7 +466,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected CPUStat cpuStat = new CPUStat(); protected MemStat memStat = new MemStat(dom0MinMem, dom0OvercommitMem); private final LibvirtUtilitiesHelper libvirtUtilitiesHelper = new LibvirtUtilitiesHelper(); - private AgentStatusUpdater _agentStatusUpdater; + private LibvirtDomainListener libvirtDomainListener; protected Boolean enableManuallySettingCpuTopologyOnKvmVm = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.ENABLE_MANUALLY_SETTING_CPU_TOPOLOGY_ON_KVM_VM); @@ -503,8 +500,23 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } @Override - public void registerStatusUpdater(AgentStatusUpdater updater) { - _agentStatusUpdater = updater; + public synchronized void registerStatusUpdater(AgentStatusUpdater updater) { + if (AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_EVENTS_ENABLED)) { + try { + Connect conn = LibvirtConnection.getConnection(); + if (libvirtDomainListener != null) { + LOGGER.debug("Clearing old domain listener"); + conn.removeLifecycleListener(libvirtDomainListener); + } + libvirtDomainListener = new LibvirtDomainListener(updater); + conn.addLifecycleListener(libvirtDomainListener); + LOGGER.debug("Set up the libvirt domain event lifecycle listener"); + } catch (LibvirtException e) { + LOGGER.error("Failed to get libvirt connection for domain event lifecycle", e); + } + } else { + LOGGER.debug("Libvirt event listening is disabled, not registering status updater"); + } } @Override @@ -514,7 +526,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv @Override public ExecutionResult executeInVR(final String routerIp, final String script, final String args, final Duration timeout) { - final Script command = new Script(routerProxyPath, timeout, s_logger); + final Script command = new Script(routerProxyPath, timeout, LOGGER); final AllLinesParser parser = new AllLinesParser(); command.add(script); command.add(routerIp); @@ -526,7 +538,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv details = parser.getLines(); } - s_logger.debug("Executing script in VR: " + script); + LOGGER.debug("Executing script in VR: " + script); return new ExecutionResult(command.getExitValue() == 0, details); } @@ -536,12 +548,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final File permKey = new File("/root/.ssh/id_rsa.cloud"); boolean success = true; String details = "Creating file in VR, with ip: " + routerIp + ", file: " + filename; - s_logger.debug(details); + LOGGER.debug(details); try { SshHelper.scpTo(routerIp, 3922, "root", permKey, null, path, content.getBytes(), filename, null); } catch (final Exception e) { - s_logger.warn("Failed to create file " + path + filename + " in VR " + routerIp, e); + LOGGER.warn("Failed to create file " + path + filename + " in VR " + routerIp, e); details = e.getMessage(); success = false; } @@ -728,14 +740,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv while ((line = reader.readLine()) != null) { final String[] toks = line.trim().split("="); if (toks.length < 2) { - s_logger.warn("Failed to parse Script output: " + line); + LOGGER.warn("Failed to parse Script output: " + line); } else { map.put(toks[0].trim(), toks[1].trim()); } numLines++; } if (numLines == 0) { - s_logger.warn("KeyValueInterpreter: no output lines?"); + LOGGER.warn("KeyValueInterpreter: no output lines?"); } return null; } @@ -789,7 +801,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv throw new ConfigurationException("Unable to find developer.properties."); } - s_logger.info("developer.properties found at " + file.getAbsolutePath()); + LOGGER.info("developer.properties found at " + file.getAbsolutePath()); try { final Properties properties = PropertiesUtil.loadFromFile(file); @@ -862,7 +874,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { loadUefiProperties(); } catch (FileNotFoundException e) { - s_logger.error("uefi properties file not found due to: " + e.getLocalizedMessage()); + LOGGER.error("uefi properties file not found due to: " + e.getLocalizedMessage()); } storageLayer = new JavaStorageLayer(); @@ -993,7 +1005,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv hostHealthCheckScriptPath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HEALTH_CHECK_SCRIPT_PATH); if (StringUtils.isNotBlank(hostHealthCheckScriptPath) && !new File(hostHealthCheckScriptPath).exists()) { - s_logger.info(String.format("Unable to find the host health check script at: %s, " + + logger.info(String.format("Unable to find the host health check script at: %s, " + "discarding it", hostHealthCheckScriptPath)); } @@ -1134,7 +1146,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv // destroy default network, see https://libvirt.org/sources/java/javadoc/org/libvirt/Network.html try { Network network = conn.networkLookupByName("default"); - s_logger.debug("Found libvirt default network, destroying it and setting autostart to false"); + LOGGER.debug("Found libvirt default network, destroying it and setting autostart to false"); if (network.isActive() == 1) { network.destroy(); } @@ -1142,7 +1154,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv network.setAutostart(false); } } catch (final LibvirtException e) { - s_logger.warn("Ignoring libvirt error.", e); + LOGGER.warn("Ignoring libvirt error.", e); } if (HypervisorType.KVM == hypervisorType) { @@ -1160,17 +1172,17 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv hypervisorLibvirtVersion = conn.getLibVirVersion(); hypervisorQemuVersion = conn.getVersion(); } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } // Enable/disable IO driver for Qemu (in case it is not set CloudStack can also detect if its supported by qemu) enableIoUring = isIoUringEnabled(); - s_logger.info("IO uring driver for Qemu: " + (enableIoUring ? "enabled" : "disabled")); + LOGGER.info("IO uring driver for Qemu: " + (enableIoUring ? "enabled" : "disabled")); final String cpuArchOverride = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_ARCH); if (StringUtils.isNotEmpty(cpuArchOverride)) { guestCpuArch = cpuArchOverride; - s_logger.info("Using guest CPU architecture: " + guestCpuArch); + LOGGER.info("Using guest CPU architecture: " + guestCpuArch); } guestCpuMode = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_MODE); @@ -1178,7 +1190,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv guestCpuModel = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_MODEL); if (hypervisorLibvirtVersion < 9 * 1000 + 10) { - s_logger.warn("Libvirt version 0.9.10 required for guest cpu mode, but version " + prettyVersion(hypervisorLibvirtVersion) + + LOGGER.warn("Libvirt version 0.9.10 required for guest cpu mode, but version " + prettyVersion(hypervisorLibvirtVersion) + " detected, so it will be disabled"); guestCpuMode = ""; guestCpuModel = ""; @@ -1229,21 +1241,21 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv */ if (pifs.get("private") == null) { - s_logger.error("Failed to get private nic name"); + LOGGER.error("Failed to get private nic name"); throw new ConfigurationException("Failed to get private nic name"); } if (pifs.get("public") == null) { - s_logger.error("Failed to get public nic name"); + LOGGER.error("Failed to get public nic name"); throw new ConfigurationException("Failed to get public nic name"); } - s_logger.debug("Found pif: " + pifs.get("private") + " on " + privBridgeName + ", pif: " + pifs.get("public") + " on " + publicBridgeName); + LOGGER.debug("Found pif: " + pifs.get("private") + " on " + privBridgeName + ", pif: " + pifs.get("public") + " on " + publicBridgeName); canBridgeFirewall = canBridgeFirewall(pifs.get("public")); localGateway = Script.runSimpleBashScript("ip route show default 0.0.0.0/0|head -1|awk '{print $3}'"); if (localGateway == null) { - s_logger.warn("No default IPv4 gateway found"); + LOGGER.warn("No default IPv4 gateway found"); } migrateDowntime = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_DOWNTIME); @@ -1265,9 +1277,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { migrateSpeed = Integer.parseInt(tokens[0]); } catch (final NumberFormatException e) { - s_logger.trace("Ignoring migrateSpeed extraction error.", e); + LOGGER.trace("Ignoring migrateSpeed extraction error.", e); } - s_logger.debug("device " + pifs.get("public") + " has speed: " + String.valueOf(migrateSpeed)); + LOGGER.debug("device " + pifs.get("public") + " has speed: " + String.valueOf(migrateSpeed)); } } params.put("vm.migrate.speed", String.valueOf(migrateSpeed)); @@ -1293,7 +1305,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final Thread cleanupMonitor = new Thread(isciCleanupMonitor); cleanupMonitor.start(); } else { - s_logger.info("iscsi session clean up is disabled"); + LOGGER.info("iscsi session clean up is disabled"); } setupMemoryBalloonStatsPeriod(conn); @@ -1312,14 +1324,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { vmIds = ArrayUtils.toObject(conn.listDomains()); } catch (final LibvirtException e) { - s_logger.error("Unable to get the list of Libvirt domains on this host.", e); + LOGGER.error("Unable to get the list of Libvirt domains on this host.", e); return vmIdList; } vmIdList.addAll(Arrays.asList(vmIds)); - s_logger.debug(String.format("We have found a total of [%s] VMs (Libvirt domains) on this host: [%s].", vmIdList.size(), vmIdList.toString())); + LOGGER.debug(String.format("We have found a total of [%s] VMs (Libvirt domains) on this host: [%s].", vmIdList.size(), vmIdList.toString())); if (vmIdList.isEmpty()) { - s_logger.info("Skipping the memory balloon stats period setting, since there are no VMs (active Libvirt domains) on this host."); + LOGGER.info("Skipping the memory balloon stats period setting, since there are no VMs (active Libvirt domains) on this host."); } return vmIdList; } @@ -1330,13 +1342,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv */ protected Integer getCurrentVmBalloonStatsPeriod() { if (Boolean.TRUE.equals(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MEMBALLOON_DISABLE))) { - s_logger.info(String.format("The [%s] property is set to 'true', so the memory balloon stats period will be set to 0 for all VMs.", + LOGGER.info(String.format("The [%s] property is set to 'true', so the memory balloon stats period will be set to 0 for all VMs.", AgentProperties.VM_MEMBALLOON_DISABLE.getName())); return 0; } Integer vmBalloonStatsPeriod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MEMBALLOON_STATS_PERIOD); if (vmBalloonStatsPeriod == 0) { - s_logger.info(String.format("The [%s] property is set to '0', this prevents memory statistics from being displayed correctly. " + LOGGER.info(String.format("The [%s] property is set to '0', this prevents memory statistics from being displayed correctly. " + "Adjust (increase) the value of this parameter to correct this.", AgentProperties.VM_MEMBALLOON_STATS_PERIOD.getName())); } return vmBalloonStatsPeriod; @@ -1356,20 +1368,20 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv parser.parseDomainXML(dm.getXMLDesc(0)); MemBalloonDef memBalloon = parser.getMemBalloon(); if (!MemBalloonDef.MemBalloonModel.VIRTIO.equals(memBalloon.getMemBalloonModel())) { - s_logger.debug(String.format("Skipping the memory balloon stats period setting for the VM (Libvirt Domain) with ID [%s] and name [%s] because this VM has no memory" + LOGGER.debug(String.format("Skipping the memory balloon stats period setting for the VM (Libvirt Domain) with ID [%s] and name [%s] because this VM has no memory" + " balloon.", vmId, dm.getName())); } String setMemBalloonStatsPeriodCommand = String.format(COMMAND_SET_MEM_BALLOON_STATS_PERIOD, vmId, currentVmBalloonStatsPeriod); String setMemBalloonStatsPeriodResult = Script.runSimpleBashScript(setMemBalloonStatsPeriodCommand); if (StringUtils.isNotBlank(setMemBalloonStatsPeriodResult)) { - s_logger.error(String.format("Unable to set up memory balloon stats period for VM (Libvirt Domain) with ID [%s] due to an error when running the [%s] " + LOGGER.error(String.format("Unable to set up memory balloon stats period for VM (Libvirt Domain) with ID [%s] due to an error when running the [%s] " + "command. Output: [%s].", vmId, setMemBalloonStatsPeriodCommand, setMemBalloonStatsPeriodResult)); continue; } - s_logger.debug(String.format("The memory balloon stats period [%s] has been set successfully for the VM (Libvirt Domain) with ID [%s] and name [%s].", + LOGGER.debug(String.format("The memory balloon stats period [%s] has been set successfully for the VM (Libvirt Domain) with ID [%s] and name [%s].", currentVmBalloonStatsPeriod, vmId, dm.getName())); } catch (final Exception e) { - s_logger.warn(String.format("Failed to set up memory balloon stats period for the VM %s with exception %s", parser.getName(), e.getMessage())); + LOGGER.warn(String.format("Failed to set up memory balloon stats period for the VM %s with exception %s", parser.getName(), e.getMessage())); } } } @@ -1377,12 +1389,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv private void enableSSLForKvmAgent() { final File keyStoreFile = PropertiesUtil.findConfigFile(KeyStoreUtils.KS_FILENAME); if (keyStoreFile == null) { - s_logger.info("Failed to find keystore file: " + KeyStoreUtils.KS_FILENAME); + LOGGER.info("Failed to find keystore file: " + KeyStoreUtils.KS_FILENAME); return; } String keystorePass = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.KEYSTORE_PASSPHRASE); if (StringUtils.isBlank(keystorePass)) { - s_logger.info("Failed to find passphrase for keystore: " + KeyStoreUtils.KS_FILENAME); + LOGGER.info("Failed to find passphrase for keystore: " + KeyStoreUtils.KS_FILENAME); return; } if (keyStoreFile.exists() && !keyStoreFile.isDirectory()) { @@ -1393,20 +1405,20 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected void configureLocalStorage() throws ConfigurationException { String localStoragePath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_PATH); - s_logger.debug(String.format("Local Storage Path set: [%s].", localStoragePath)); + LOGGER.debug(String.format("Local Storage Path set: [%s].", localStoragePath)); String localStorageUUIDString = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_UUID); if (localStorageUUIDString == null) { localStorageUUIDString = UUID.randomUUID().toString(); } - s_logger.debug(String.format("Local Storage UUID set: [%s].", localStorageUUIDString)); + LOGGER.debug(String.format("Local Storage UUID set: [%s].", localStorageUUIDString)); String[] localStorageRelativePaths = localStoragePath.split(CONFIG_VALUES_SEPARATOR); String[] localStorageUUIDStrings = localStorageUUIDString.split(CONFIG_VALUES_SEPARATOR); if (localStorageRelativePaths.length != localStorageUUIDStrings.length) { String errorMessage = String.format("The path and UUID of the local storage pools have different length. Path: [%s], UUID: [%s].", localStoragePath, localStorageUUIDString); - s_logger.error(errorMessage); + LOGGER.error(errorMessage); throw new ConfigurationException(errorMessage); } for (String localStorageRelativePath : localStorageRelativePaths) { @@ -1434,7 +1446,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public boolean configureHostParams(final Map params) { final File file = PropertiesUtil.findConfigFile("agent.properties"); if (file == null) { - s_logger.error("Unable to find the file agent.properties"); + LOGGER.error("Unable to find the file agent.properties"); return false; } // Save configurations in agent.properties @@ -1461,25 +1473,25 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv private void configureAgentHooks() { agentHooksBasedir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_BASEDIR); - s_logger.debug("agent.hooks.basedir is " + agentHooksBasedir); + LOGGER.debug("agent.hooks.basedir is " + agentHooksBasedir); agentHooksLibvirtXmlScript = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_SCRIPT); - s_logger.debug("agent.hooks.libvirt_vm_xml_transformer.script is " + agentHooksLibvirtXmlScript); + LOGGER.debug("agent.hooks.libvirt_vm_xml_transformer.script is " + agentHooksLibvirtXmlScript); agentHooksLibvirtXmlMethod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_METHOD); - s_logger.debug("agent.hooks.libvirt_vm_xml_transformer.method is " + agentHooksLibvirtXmlMethod); + LOGGER.debug("agent.hooks.libvirt_vm_xml_transformer.method is " + agentHooksLibvirtXmlMethod); agentHooksVmOnStartScript = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_START_SCRIPT); - s_logger.debug("agent.hooks.libvirt_vm_on_start.script is " + agentHooksVmOnStartScript); + LOGGER.debug("agent.hooks.libvirt_vm_on_start.script is " + agentHooksVmOnStartScript); agentHooksVmOnStartMethod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_START_METHOD); - s_logger.debug("agent.hooks.libvirt_vm_on_start.method is " + agentHooksVmOnStartMethod); + LOGGER.debug("agent.hooks.libvirt_vm_on_start.method is " + agentHooksVmOnStartMethod); agentHooksVmOnStopScript = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_STOP_SCRIPT); - s_logger.debug("agent.hooks.libvirt_vm_on_stop.script is " + agentHooksVmOnStopScript); + LOGGER.debug("agent.hooks.libvirt_vm_on_stop.script is " + agentHooksVmOnStopScript); agentHooksVmOnStopMethod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_STOP_METHOD); - s_logger.debug("agent.hooks.libvirt_vm_on_stop.method is " + agentHooksVmOnStopMethod); + LOGGER.debug("agent.hooks.libvirt_vm_on_stop.method is " + agentHooksVmOnStopMethod); } public boolean isUefiPropertiesFileLoaded() { @@ -1496,14 +1508,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv throw new FileNotFoundException("Unable to find file uefi.properties."); } - s_logger.info("uefi.properties file found at " + file.getAbsolutePath()); + LOGGER.info("uefi.properties file found at " + file.getAbsolutePath()); try { PropertiesUtil.loadFromFile(uefiProperties, file); - s_logger.info("guest.nvram.template.legacy = " + uefiProperties.getProperty("guest.nvram.template.legacy")); - s_logger.info("guest.loader.legacy = " + uefiProperties.getProperty("guest.loader.legacy")); - s_logger.info("guest.nvram.template.secure = " + uefiProperties.getProperty("guest.nvram.template.secure")); - s_logger.info("guest.loader.secure =" + uefiProperties.getProperty("guest.loader.secure")); - s_logger.info("guest.nvram.path = " + uefiProperties.getProperty("guest.nvram.path")); + LOGGER.info("guest.nvram.template.legacy = " + uefiProperties.getProperty("guest.nvram.template.legacy")); + LOGGER.info("guest.loader.legacy = " + uefiProperties.getProperty("guest.loader.legacy")); + LOGGER.info("guest.nvram.template.secure = " + uefiProperties.getProperty("guest.nvram.template.secure")); + LOGGER.info("guest.loader.secure =" + uefiProperties.getProperty("guest.loader.secure")); + LOGGER.info("guest.nvram.path = " + uefiProperties.getProperty("guest.nvram.path")); } catch (final FileNotFoundException ex) { throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex); } catch (final IOException ex) { @@ -1534,10 +1546,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv String defaultVifDriverName = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_VIF_DRIVER); if (defaultVifDriverName == null) { if (bridgeType == BridgeType.OPENVSWITCH) { - s_logger.info("No libvirt.vif.driver specified. Defaults to OvsVifDriver."); + LOGGER.info("No libvirt.vif.driver specified. Defaults to OvsVifDriver."); defaultVifDriverName = DEFAULT_OVS_VIF_DRIVER_CLASS_NAME; } else { - s_logger.info("No libvirt.vif.driver specified. Defaults to BridgeVifDriver."); + LOGGER.info("No libvirt.vif.driver specified. Defaults to BridgeVifDriver."); defaultVifDriverName = DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME; } } @@ -1633,15 +1645,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv for (int i = 0; i < netdevs.length; i++) { final File isbridge = new File(netdevs[i].getAbsolutePath() + "/bridge"); final String netdevName = netdevs[i].getName(); - s_logger.debug("looking in file " + netdevs[i].getAbsolutePath() + "/bridge"); + LOGGER.debug("looking in file " + netdevs[i].getAbsolutePath() + "/bridge"); if (isbridge.exists()) { - s_logger.debug("Found bridge " + netdevName); + LOGGER.debug("Found bridge " + netdevName); bridges.add(netdevName); } } for (final String bridge : bridges) { - s_logger.debug("looking for pif for bridge " + bridge); + LOGGER.debug("looking for pif for bridge " + bridge); final String pif = getPif(bridge); if (isPublicBridge(bridge)) { pifs.put("public", pif); @@ -1655,10 +1667,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv // guest(private) creates bridges on a pif, if private bridge not found try pif direct // This addresses the unnecessary requirement of someone to create an unused bridge just for traffic label if (pifs.get("private") == null) { - s_logger.debug("guest(private) traffic label '" + guestBridgeName + "' not found as bridge, looking for physical interface"); + LOGGER.debug("guest(private) traffic label '" + guestBridgeName + "' not found as bridge, looking for physical interface"); final File dev = new File("/sys/class/net/" + guestBridgeName); if (dev.exists()) { - s_logger.debug("guest(private) traffic label '" + guestBridgeName + "' found as a physical device"); + LOGGER.debug("guest(private) traffic label '" + guestBridgeName + "' found as a physical device"); pifs.put("private", guestBridgeName); } } @@ -1666,15 +1678,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv // public creates bridges on a pif, if private bridge not found try pif direct // This addresses the unnecessary requirement of someone to create an unused bridge just for traffic label if (pifs.get("public") == null) { - s_logger.debug("public traffic label '" + publicBridgeName + "' not found as bridge, looking for physical interface"); + LOGGER.debug("public traffic label '" + publicBridgeName + "' not found as bridge, looking for physical interface"); final File dev = new File("/sys/class/net/" + publicBridgeName); if (dev.exists()) { - s_logger.debug("public traffic label '" + publicBridgeName + "' found as a physical device"); + LOGGER.debug("public traffic label '" + publicBridgeName + "' found as a physical device"); pifs.put("public", publicBridgeName); } } - s_logger.debug("done looking for pifs, no more bridges"); + LOGGER.debug("done looking for pifs, no more bridges"); } boolean isGuestBridge(String bridge) { @@ -1683,10 +1695,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv private void getOvsPifs() { final String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'"); - s_logger.debug("cmdout was " + cmdout); + LOGGER.debug("cmdout was " + cmdout); final List bridges = Arrays.asList(cmdout.split("%")); for (final String bridge : bridges) { - s_logger.debug("looking for pif for bridge " + bridge); + LOGGER.debug("looking for pif for bridge " + bridge); // String pif = getOvsPif(bridge); // Not really interested in the pif name at this point for ovs // bridges @@ -1699,7 +1711,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } pifs.put(bridge, pif); } - s_logger.debug("done looking for pifs, no more bridges"); + LOGGER.debug("done looking for pifs, no more bridges"); } public boolean isPublicBridge(String bridge) { @@ -1726,7 +1738,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv // if bridgeName already refers to a pif, return it as-is return bridgeName; } - s_logger.debug("failing to get physical interface from bridge " + bridgeName + ", does " + brif.getAbsolutePath() + "exist?"); + LOGGER.debug("failing to get physical interface from bridge " + bridgeName + ", does " + brif.getAbsolutePath() + "exist?"); return ""; } @@ -1734,13 +1746,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv for (int i = 0; i < interfaces.length; i++) { final String fname = interfaces[i].getName(); - s_logger.debug("matchPifFileInDirectory: file name '" + fname + "'"); + LOGGER.debug("matchPifFileInDirectory: file name '" + fname + "'"); if (isInterface(fname)) { return fname; } } - s_logger.debug("failing to get physical interface from bridge " + bridgeName + ", did not find an eth*, bond*, team*, vlan*, em*, p*p*, ens*, eno*, enp*, or enx* in " + brif.getAbsolutePath()); + LOGGER.debug("failing to get physical interface from bridge " + bridgeName + ", did not find an eth*, bond*, team*, vlan*, em*, p*p*, ens*, eno*, enp*, or enx* in " + brif.getAbsolutePath()); return ""; } @@ -1803,7 +1815,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } private boolean checkOvsNetwork(final String networkName) { - s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge"); + LOGGER.debug("Checking if network " + networkName + " exists as openvswitch bridge"); if (networkName == null) { return true; } @@ -1815,13 +1827,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } public boolean passCmdLine(final String vmName, final String cmdLine) throws InternalErrorException { - final Script command = new Script(patchScriptPath, 300000, s_logger); + final Script command = new Script(patchScriptPath, 300000, LOGGER); String result; command.add("-n", vmName); command.add("-c", cmdLine); result = command.execute(); if (result != null) { - s_logger.error("Passing cmdline failed:" + result); + LOGGER.error("Passing cmdline failed:" + result); return false; } return true; @@ -1879,9 +1891,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public boolean stop() { try { final Connect conn = LibvirtConnection.getConnection(); + if (AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_EVENTS_ENABLED) && libvirtDomainListener != null) { + LOGGER.debug("Clearing old domain listener"); + conn.removeLifecycleListener(libvirtDomainListener); + } conn.close(); } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } return true; @@ -1909,14 +1925,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public synchronized boolean destroyTunnelNetwork(final String bridge) { findOrCreateTunnelNetwork(bridge); - final Script cmd = new Script(ovsTunnelPath, timeout, s_logger); + final Script cmd = new Script(ovsTunnelPath, timeout, LOGGER); cmd.add("destroy_ovs_bridge"); cmd.add("--bridge", bridge); final String result = cmd.execute(); if (result != null) { - s_logger.debug("OVS Bridge could not be destroyed due to error ==> " + result); + LOGGER.debug("OVS Bridge could not be destroyed due to error ==> " + result); return false; } return true; @@ -1933,9 +1949,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv Script.runSimpleBashScript("ovs-vsctl -- --may-exist add-br " + nwName + " -- set bridge " + nwName + " other_config:ovs-host-setup='-1'"); - s_logger.debug("### KVM network for tunnels created:" + nwName); + LOGGER.debug("### KVM network for tunnels created:" + nwName); } catch (final Exception e) { - s_logger.warn("createTunnelNetwork failed", e); + LOGGER.warn("createTunnelNetwork failed", e); return false; } return true; @@ -1946,7 +1962,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { final boolean findResult = findOrCreateTunnelNetwork(nwName); if (!findResult) { - s_logger.warn("LibvirtComputingResource.findOrCreateTunnelNetwork() failed! Cannot proceed creating the tunnel."); + LOGGER.warn("LibvirtComputingResource.findOrCreateTunnelNetwork() failed! Cannot proceed creating the tunnel."); return false; } final String configuredHosts = Script @@ -1963,7 +1979,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } if (!configured) { - final Script cmd = new Script(ovsTunnelPath, timeout, s_logger); + final Script cmd = new Script(ovsTunnelPath, timeout, LOGGER); cmd.add("setup_ovs_bridge"); cmd.add("--key", nwName); cmd.add("--cs_host_id", ((Long)hostId).toString()); @@ -1976,7 +1992,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } } catch (final Exception e) { - s_logger.warn("createandConfigureTunnelNetwork failed", e); + LOGGER.warn("createandConfigureTunnelNetwork failed", e); return false; } return true; @@ -2004,7 +2020,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv secondaryPool.refresh(); final List disks = secondaryPool.listPhysicalDisks(); if (disks == null || disks.isEmpty()) { - s_logger.error("Failed to get volumes from pool: " + secondaryPool.getUuid()); + LOGGER.error("Failed to get volumes from pool: " + secondaryPool.getUuid()); return null; } for (final KVMPhysicalDisk disk : disks) { @@ -2014,7 +2030,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } if (templateVol == null) { - s_logger.error("Failed to get template from pool: " + secondaryPool.getUuid()); + LOGGER.error("Failed to get template from pool: " + secondaryPool.getUuid()); return null; } } else { @@ -2026,7 +2042,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final KVMPhysicalDisk primaryVol = storagePoolManager.copyPhysicalDisk(templateVol, volUuid, primaryPool, 0); return primaryVol; } catch (final CloudRuntimeException e) { - s_logger.error("Failed to download template to primary storage", e); + LOGGER.error("Failed to download template to primary storage", e); return null; } finally { if (secondaryPool != null) { @@ -2057,7 +2073,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final String pif = matchPifFileInDirectory(brName); final Pattern pattern = Pattern.compile("(\\D+)(\\d+)(\\D*)(\\d*)(\\D*)(\\d*)"); final Matcher matcher = pattern.matcher(pif); - s_logger.debug("getting broadcast uri for pif " + pif + " and bridge " + brName); + LOGGER.debug("getting broadcast uri for pif " + pif + " and bridge " + brName); if(matcher.find()) { if (brName.startsWith("brvx")){ return BroadcastDomainType.Vxlan.toUri(matcher.group(2)).toString(); @@ -2069,13 +2085,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return BroadcastDomainType.Vlan.toUri(matcher.group(4)).toString(); } else { //untagged or not matching (eth|bond|team)#.# - s_logger.debug("failed to get vNet id from bridge " + brName + LOGGER.debug("failed to get vNet id from bridge " + brName + "attached to physical interface" + pif + ", perhaps untagged interface"); return ""; } } } else { - s_logger.debug("failed to get vNet id from bridge " + brName + "attached to physical interface" + pif); + LOGGER.debug("failed to get vNet id from bridge " + brName + "attached to physical interface" + pif); return ""; } } @@ -2138,7 +2154,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return new ExecutionResult(true, null); } catch (final LibvirtException e) { final String msg = "Creating guest network failed due to " + e.toString(); - s_logger.warn(msg, e); + LOGGER.warn(msg, e); return new ExecutionResult(false, msg); } } @@ -2177,7 +2193,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return new ExecutionResult(true, "success"); } catch (final LibvirtException e) { final String msg = "Ip SNAT failure due to " + e.toString(); - s_logger.error(msg, e); + LOGGER.error(msg, e); return new ExecutionResult(false, msg); } } @@ -2199,7 +2215,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return new ExecutionResult(true, null); } catch (final LibvirtException e) { - s_logger.error("Ip Assoc failure on applying one ip due to exception: ", e); + LOGGER.error("Ip Assoc failure on applying one ip due to exception: ", e); return new ExecutionResult(false, e.getMessage()); } } @@ -2232,10 +2248,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } return new ExecutionResult(true, null); } catch (final LibvirtException e) { - s_logger.error("ipassoccmd failed", e); + LOGGER.error("ipassoccmd failed", e); return new ExecutionResult(false, e.getMessage()); } catch (final InternalErrorException e) { - s_logger.error("ipassoccmd failed", e); + LOGGER.error("ipassoccmd failed", e); return new ExecutionResult(false, e.getMessage()); } } @@ -2272,10 +2288,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } catch (final LibvirtException e) { - s_logger.error("ipassoccmd failed", e); + LOGGER.error("ipassoccmd failed", e); return new ExecutionResult(false, e.getMessage()); } catch (final InternalErrorException e) { - s_logger.error("ipassoccmd failed", e); + LOGGER.error("ipassoccmd failed", e); return new ExecutionResult(false, e.getMessage()); } @@ -2309,14 +2325,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final PowerState s = convertToPowerState(vms.getInfo().state); return s; } catch (final LibvirtException e) { - s_logger.warn("Can't get vm state " + vmName + e.getMessage() + "retry:" + retry); + LOGGER.warn("Can't get vm state " + vmName + e.getMessage() + "retry:" + retry); } finally { try { if (vms != null) { vms.free(); } } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } } @@ -2328,7 +2344,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } public String networkUsage(final String privateIpAddress, final String option, final String vif, String publicIp) { - final Script getUsage = new Script(routerProxyPath, s_logger); + final Script getUsage = new Script(routerProxyPath, LOGGER); getUsage.add("netusage.sh"); getUsage.add(privateIpAddress); if (option.equals("get")) { @@ -2349,7 +2365,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final OutputInterpreter.OneLineParser usageParser = new OutputInterpreter.OneLineParser(); final String result = getUsage.execute(usageParser); if (result != null) { - s_logger.debug("Failed to execute networkUsage:" + result); + LOGGER.debug("Failed to execute networkUsage:" + result); return null; } return usageParser.getLine(); @@ -2374,7 +2390,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } public String getHaproxyStats(final String privateIP, final String publicIp, final Integer port) { - final Script getHaproxyStatsScript = new Script(routerProxyPath, s_logger); + final Script getHaproxyStatsScript = new Script(routerProxyPath, LOGGER); getHaproxyStatsScript.add("get_haproxy_stats.sh"); getHaproxyStatsScript.add(privateIP); getHaproxyStatsScript.add(publicIp); @@ -2383,7 +2399,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final OutputInterpreter.OneLineParser statsParser = new OutputInterpreter.OneLineParser(); final String result = getHaproxyStatsScript.execute(statsParser); if (result != null) { - s_logger.debug("Failed to execute haproxy stats:" + result); + LOGGER.debug("Failed to execute haproxy stats:" + result); return null; } return statsParser.getLine(); @@ -2400,7 +2416,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } public String configureVPCNetworkUsage(final String privateIpAddress, final String publicIp, final String option, final String vpcCIDR) { - final Script getUsage = new Script(routerProxyPath, s_logger); + final Script getUsage = new Script(routerProxyPath, LOGGER); getUsage.add("vpc_netusage.sh"); getUsage.add(privateIpAddress); getUsage.add("-l", publicIp); @@ -2421,7 +2437,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final OutputInterpreter.OneLineParser usageParser = new OutputInterpreter.OneLineParser(); final String result = getUsage.execute(usageParser); if (result != null) { - s_logger.debug("Failed to execute VPCNetworkUsage:" + result); + LOGGER.debug("Failed to execute VPCNetworkUsage:" + result); return null; } return usageParser.getLine(); @@ -2473,19 +2489,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv int period = CpuTuneDef.DEFAULT_PERIOD; int quota = (int) (period * cpuQuotaPercentage); if (quota < CpuTuneDef.MIN_QUOTA) { - s_logger.info("Calculated quota (" + quota + ") below the minimum (" + CpuTuneDef.MIN_QUOTA + ") for VM domain " + vmTO.getUuid() + ", setting it to minimum " + + LOGGER.info("Calculated quota (" + quota + ") below the minimum (" + CpuTuneDef.MIN_QUOTA + ") for VM domain " + vmTO.getUuid() + ", setting it to minimum " + "and calculating period instead of using the default"); quota = CpuTuneDef.MIN_QUOTA; period = (int) ((double) quota / cpuQuotaPercentage); if (period > CpuTuneDef.MAX_PERIOD) { - s_logger.info("Calculated period (" + period + ") exceeds the maximum (" + CpuTuneDef.MAX_PERIOD + + LOGGER.info("Calculated period (" + period + ") exceeds the maximum (" + CpuTuneDef.MAX_PERIOD + "), setting it to the maximum"); period = CpuTuneDef.MAX_PERIOD; } } ctd.setQuota(quota); ctd.setPeriod(period); - s_logger.info("Setting quota=" + quota + ", period=" + period + " to VM domain " + vmTO.getUuid()); + LOGGER.info("Setting quota=" + quota + ", period=" + period + " to VM domain " + vmTO.getUuid()); } } @@ -2498,7 +2514,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv hyv.setFeature("spinlocks", true); hyv.setRetries(8096); features.addHyperVFeature(hyv); - s_logger.info("Enabling KVM Enlightment Features to VM domain " + vmTO.getUuid()); + LOGGER.info("Enabling KVM Enlightment Features to VM domain " + vmTO.getUuid()); } } @@ -2506,7 +2522,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv * Creates VM KVM definitions from virtual machine transfer object specifications. */ public LibvirtVMDef createVMFromSpec(final VirtualMachineTO vmTO) { - s_logger.debug(String.format("Creating VM from specifications [%s]", vmTO.toString())); + LOGGER.debug(String.format("Creating VM from specifications [%s]", vmTO.toString())); LibvirtVMDef vm = new LibvirtVMDef(); vm.setDomainName(vmTO.getName()); @@ -2523,10 +2539,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv if (MapUtils.isNotEmpty(customParams) && customParams.containsKey(GuestDef.BootType.UEFI.toString())) { isUefiEnabled = true; - s_logger.debug(String.format("Enabled UEFI for VM UUID [%s].", uuid)); + LOGGER.debug(String.format("Enabled UEFI for VM UUID [%s].", uuid)); if (isSecureMode(customParams.get(GuestDef.BootType.UEFI.toString()))) { - s_logger.debug(String.format("Enabled Secure Boot for VM UUID [%s].", uuid)); + LOGGER.debug(String.format("Enabled Secure Boot for VM UUID [%s].", uuid)); isSecureBoot = true; } @@ -2535,7 +2551,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv Map extraConfig = vmTO.getExtraConfig(); if (dpdkSupport && (!extraConfig.containsKey(DpdkHelper.DPDK_NUMA) || !extraConfig.containsKey(DpdkHelper.DPDK_HUGE_PAGES))) { - s_logger.info(String.format("DPDK is enabled for VM [%s], but it needs extra configurations for CPU NUMA and Huge Pages for VM deployment.", vmTO.toString())); + LOGGER.info(String.format("DPDK is enabled for VM [%s], but it needs extra configurations for CPU NUMA and Huge Pages for VM deployment.", vmTO.toString())); } configureVM(vmTO, vm, customParams, isUefiEnabled, isSecureBoot, bootMode, extraConfig, uuid); return vm; @@ -2546,7 +2562,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv */ private void configureVM(VirtualMachineTO vmTO, LibvirtVMDef vm, Map customParams, boolean isUefiEnabled, boolean isSecureBoot, String bootMode, Map extraConfig, String uuid) { - s_logger.debug(String.format("Configuring VM with UUID [%s].", uuid)); + LOGGER.debug(String.format("Configuring VM with UUID [%s].", uuid)); GuestDef guest = createGuestFromSpec(vmTO, vm, uuid, customParams); if (isUefiEnabled) { @@ -2581,7 +2597,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv */ private void addExtraConfigsToVM(VirtualMachineTO vmTO, LibvirtVMDef vm, Map extraConfig) { if (MapUtils.isNotEmpty(extraConfig) && VirtualMachine.Type.User.equals(vmTO.getType())) { - s_logger.debug(String.format("Appending extra configuration data [%s] to guest VM [%s] domain XML.", extraConfig, vmTO.toString())); + LOGGER.debug(String.format("Appending extra configuration data [%s] to guest VM [%s] domain XML.", extraConfig, vmTO.toString())); addExtraConfigComponent(extraConfig, vm); } } @@ -2754,11 +2770,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv if (hostCpuMaxCapacity > 0) { int updatedCpuShares = (int) Math.ceil((requestedCpuShares * CGROUP_V2_UPPER_LIMIT) / (double) hostCpuMaxCapacity); - s_logger.debug(String.format("This host utilizes cgroupv2 (as the max shares value is [%s]), thus, the VM requested shares of [%s] will be converted to " + + logger.debug(String.format("This host utilizes cgroupv2 (as the max shares value is [%s]), thus, the VM requested shares of [%s] will be converted to " + "consider the host limits; the new CPU shares value is [%s].", hostCpuMaxCapacity, requestedCpuShares, updatedCpuShares)); return updatedCpuShares; } - s_logger.debug(String.format("This host does not have a maximum CPU shares set; therefore, this host utilizes cgroupv1 and the VM requested CPU shares [%s] will not be " + + logger.debug(String.format("This host does not have a maximum CPU shares set; therefore, this host utilizes cgroupv1 and the VM requested CPU shares [%s] will not be " + "converted.", requestedCpuShares)); return requestedCpuShares; } @@ -2882,12 +2898,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected long getCurrentMemAccordingToMemBallooning(VirtualMachineTO vmTO, long maxRam) { long retVal = maxRam; if (noMemBalloon) { - s_logger.warn(String.format("Setting VM's [%s] current memory as max memory [%s] due to memory ballooning is disabled. If you are using a custom service offering, verify if memory ballooning really should be disabled.", vmTO.toString(), maxRam)); + LOGGER.warn(String.format("Setting VM's [%s] current memory as max memory [%s] due to memory ballooning is disabled. If you are using a custom service offering, verify if memory ballooning really should be disabled.", vmTO.toString(), maxRam)); } else if (vmTO != null && vmTO.getType() != VirtualMachine.Type.User) { - s_logger.warn(String.format("Setting System VM's [%s] current memory as max memory [%s].", vmTO.toString(), maxRam)); + LOGGER.warn(String.format("Setting System VM's [%s] current memory as max memory [%s].", vmTO.toString(), maxRam)); } else { long minRam = ByteScaleUtils.bytesToKibibytes(vmTO.getMinRam()); - s_logger.debug(String.format("Setting VM's [%s] current memory as min memory [%s] due to memory ballooning is enabled.", vmTO.toString(), minRam)); + logger.debug(String.format("Setting VM's [%s] current memory as min memory [%s] due to memory ballooning is enabled.", vmTO.toString(), minRam)); retVal = minRam; } return retVal; @@ -3028,13 +3044,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv // check for disk activity, if detected we should exit because vm is running elsewhere if (diskActivityCheckEnabled && physicalDisk != null && physicalDisk.getFormat() == PhysicalDiskFormat.QCOW2) { - s_logger.debug("Checking physical disk file at path " + volPath + " for disk activity to ensure vm is not running elsewhere"); + LOGGER.debug("Checking physical disk file at path " + volPath + " for disk activity to ensure vm is not running elsewhere"); try { HypervisorUtils.checkVolumeFileForActivity(volPath, diskActivityCheckTimeoutSeconds, diskActivityInactiveThresholdMilliseconds, diskActivityCheckFileSizeMin); } catch (final IOException ex) { throw new CloudRuntimeException("Unable to check physical disk file for activity", ex); } - s_logger.debug("Disk activity check cleared"); + LOGGER.debug("Disk activity check cleared"); } // if params contains a rootDiskController key, use its value (this is what other HVs are doing) @@ -3058,6 +3074,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv disk.setBusType(DiskDef.DiskBus.SCSI); } } else { + if (pool == null) { + throw new CloudRuntimeException(String.format("Found null pool for volume %s", volume)); + } + + disk.setLogicalBlockIOSize(pool.getSupportedLogicalBlockSize()); + disk.setPhysicalBlockIOSize(pool.getSupportedPhysicalBlockSize()); + if (diskBusType == DiskDef.DiskBus.SCSI ) { disk.setQemuDriver(true); disk.setDiscard(DiscardType.UNMAP); @@ -3133,7 +3156,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } if (vm.getDevices() == null) { - s_logger.error("There is no devices for" + vm); + LOGGER.error("There is no devices for" + vm); throw new RuntimeException("There is no devices for" + vm); } vm.getDevices().addDevice(disk); @@ -3164,7 +3187,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final int devId = volume.getDiskSeq().intValue(); final String device = mapRbdDevice(physicalDisk); if (device != null) { - s_logger.debug("RBD device on host is: " + device); + LOGGER.debug("RBD device on host is: " + device); final DiskDef diskdef = new DiskDef(); diskdef.defBlockBasedDisk(device, devId, DiskDef.DiskBus.VIRTIO); diskdef.setQemuDriver(false); @@ -3187,10 +3210,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv * Check if IO_URING is supported by qemu */ protected boolean isIoUringSupportedByQemu() { - s_logger.debug("Checking if iouring is supported"); + LOGGER.debug("Checking if iouring is supported"); String command = getIoUringCheckCommand(); if (org.apache.commons.lang3.StringUtils.isBlank(command)) { - s_logger.debug("Could not check iouring support, disabling it"); + LOGGER.debug("Could not check iouring support, disabling it"); return false; } int exitValue = executeBashScriptAndRetrieveExitValue(command); @@ -3203,7 +3226,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv File file = new File(qemuPath); if (file.exists()) { String cmd = String.format("ldd %s | grep -Eqe '[[:space:]]liburing\\.so'", qemuPath); - s_logger.debug("Using the check command: " + cmd); + LOGGER.debug("Using the check command: " + cmd); return cmd; } } @@ -3217,7 +3240,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv * (ii) Libvirt >= 6.3.0 */ public void setDiskIoDriver(DiskDef disk, IoDriverPolicy ioDriver) { - s_logger.debug(String.format("Disk IO driver policy [%s]. The host supports the io_uring policy [%s]", ioDriver, enableIoUring)); + logger.debug(String.format("Disk IO driver policy [%s]. The host supports the io_uring policy [%s]", ioDriver, enableIoUring)); if (ioDriver != null) { if (IoDriverPolicy.IO_URING != ioDriver) { disk.setIoDriver(ioDriver); @@ -3305,7 +3328,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv private void createVif(final LibvirtVMDef vm, final VirtualMachineTO vmSpec, final NicTO nic, final String nicAdapter, Map extraConfig) throws InternalErrorException, LibvirtException { if (vm.getDevices() == null) { - s_logger.error("LibvirtVMDef object get devices with null result"); + LOGGER.error("LibvirtVMDef object get devices with null result"); throw new InternalErrorException("LibvirtVMDef object get devices with null result"); } final InterfaceDef interfaceDef = getVifDriver(nic.getType(), nic.getName()).plug(nic, vm.getPlatformEmulator(), nicAdapter, extraConfig); @@ -3323,7 +3346,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final String path = disk.getDiskPath(); if (StringUtils.isBlank(path)) { - s_logger.debug("Unable to clean up disk with null path (perhaps empty cdrom drive):" + disk); + LOGGER.debug("Unable to clean up disk with null path (perhaps empty cdrom drive):" + disk); return false; } @@ -3352,15 +3375,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { String result = attachOrDetachISO(conn, vmName, configdrive.getDiskPath(), false, CONFIG_DRIVE_ISO_DEVICE_ID); if (result != null) { - s_logger.warn("Detach ConfigDrive ISO with result: " + result); + LOGGER.warn("Detach ConfigDrive ISO with result: " + result); } result = attachOrDetachISO(conn, vmName, configdrive.getDiskPath(), true, CONFIG_DRIVE_ISO_DEVICE_ID); if (result != null) { - s_logger.warn("Attach ConfigDrive ISO with result: " + result); + LOGGER.warn("Attach ConfigDrive ISO with result: " + result); } } catch (final LibvirtException | InternalErrorException | URISyntaxException e) { final String msg = "Detach and attach ConfigDrive ISO failed due to " + e.toString(); - s_logger.warn(msg, e); + LOGGER.warn(msg, e); } } } @@ -3486,6 +3509,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv if (cacheMode != null) { diskdef.setCacheMode(DiskDef.DiskCacheMode.valueOf(cacheMode.toUpperCase())); } + + diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize()); + diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize()); } final String xml = diskdef.toString(); @@ -3502,17 +3528,17 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { dm = conn.domainLookupByName(vmName); if (attach) { - s_logger.debug("Attaching device: " + xml); + LOGGER.debug("Attaching device: " + xml); dm.attachDevice(xml); } else { - s_logger.debug("Detaching device: " + xml); + LOGGER.debug("Detaching device: " + xml); dm.detachDevice(xml); } } catch (final LibvirtException e) { if (attach) { - s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); + LOGGER.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); } else { - s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); + LOGGER.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); } throw e; } finally { @@ -3520,7 +3546,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { dm.free(); } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } } @@ -3556,19 +3582,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv */ private HealthCheckResult getHostHealthCheckResult() { if (StringUtils.isBlank(hostHealthCheckScriptPath)) { - s_logger.debug("Host health check script path is not specified"); + logger.debug("Host health check script path is not specified"); return HealthCheckResult.IGNORE; } File script = new File(hostHealthCheckScriptPath); if (!script.exists() || !script.isFile() || !script.canExecute()) { - s_logger.warn(String.format("The host health check script file set at: %s cannot be executed, " + + logger.warn(String.format("The host health check script file set at: %s cannot be executed, " + "reason: %s", hostHealthCheckScriptPath, !script.exists() ? "file does not exist" : "please check file permissions to execute this file")); return HealthCheckResult.IGNORE; } int exitCode = executeBashScriptAndRetrieveExitValue(hostHealthCheckScriptPath); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Host health check script exit code: %s", exitCode)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Host health check script exit code: %s", exitCode)); } return retrieveHealthCheckResultFromExitCode(exitCode); } @@ -3586,7 +3612,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } private Map getVersionStrings() { - final Script command = new Script(versionStringPath, timeout, s_logger); + final Script command = new Script(versionStringPath, timeout, LOGGER); final KeyValueInterpreter kvi = new KeyValueInterpreter(); final String result = command.execute(kvi); if (result == null) { @@ -3660,17 +3686,17 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv */ protected void calculateHostCpuMaxCapacity(int cpuCores, Long cpuSpeed) { String output = Script.runSimpleBashScript(COMMAND_GET_CGROUP_HOST_VERSION); - s_logger.info(String.format("Host uses control group [%s].", output)); + logger.info(String.format("Host uses control group [%s].", output)); if (!CGROUP_V2.equals(output)) { - s_logger.info(String.format("Setting host CPU max capacity to 0, as it uses cgroup v1.", getHostCpuMaxCapacity())); + logger.info(String.format("Setting host CPU max capacity to 0, as it uses cgroup v1.", getHostCpuMaxCapacity())); setHostCpuMaxCapacity(0); return; } - s_logger.info(String.format("Calculating the max shares of the host.")); + logger.info(String.format("Calculating the max shares of the host.")); setHostCpuMaxCapacity(cpuCores * cpuSpeed.intValue()); - s_logger.info(String.format("The max shares of the host is [%d].", getHostCpuMaxCapacity())); + logger.info(String.format("The max shares of the host is [%d].", getHostCpuMaxCapacity())); } private StartupStorageCommand createLocalStoragePool(String localStoragePath, String localStorageUUID, StartupRoutingCommand cmd) { @@ -3687,65 +3713,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv sscmd.setDataCenter(dcId); sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL); } catch (final CloudRuntimeException e) { - s_logger.debug("Unable to initialize local storage pool: " + e); + LOGGER.debug("Unable to initialize local storage pool: " + e); } - setupLibvirtEventListener(); return sscmd; } - private void setupLibvirtEventListener() { - final Thread libvirtListenerThread = new Thread(() -> { - try { - Library.runEventLoop(); - } catch (LibvirtException e) { - s_logger.error("LibvirtException was thrown in event loop: ", e); - } catch (InterruptedException e) { - s_logger.error("Libvirt event loop was interrupted: ", e); - } - }); - - try { - libvirtListenerThread.setDaemon(true); - libvirtListenerThread.start(); - - Connect conn = LibvirtConnection.getConnection(); - conn.addLifecycleListener(this::onDomainLifecycleChange); - - s_logger.debug("Set up the libvirt domain event lifecycle listener"); - } catch (LibvirtException e) { - s_logger.error("Failed to get libvirt connection for domain event lifecycle", e); - } - } - - private int onDomainLifecycleChange(Domain domain, DomainEvent domainEvent) { - try { - s_logger.debug(String.format("Got event lifecycle change on Domain %s, event %s", domain.getName(), domainEvent)); - if (domainEvent != null) { - switch (domainEvent.getType()) { - case STOPPED: - /* libvirt-destroyed VMs have detail StoppedDetail.DESTROYED, self shutdown guests are StoppedDetail.SHUTDOWN - * Checking for this helps us differentiate between events where cloudstack or admin stopped the VM vs guest - * initiated, and avoid pushing extra updates for actions we are initiating without a need for extra tracking */ - DomainEventDetail detail = domainEvent.getDetail(); - if (StoppedDetail.SHUTDOWN.equals(detail) || StoppedDetail.CRASHED.equals(detail)) { - s_logger.info("Triggering out of band status update due to completed self-shutdown or crash of VM"); - _agentStatusUpdater.triggerUpdate(); - } else { - s_logger.debug("Event detail: " + detail); - } - break; - default: - s_logger.debug(String.format("No handling for event %s", domainEvent)); - } - } - } catch (LibvirtException e) { - s_logger.error("Libvirt exception while processing lifecycle event", e); - } catch (Throwable e) { - s_logger.error("Error during lifecycle", e); - } - return 0; - } - public String diskUuidToSerial(String uuid) { String uuidWithoutHyphen = uuid.replace("-",""); return uuidWithoutHyphen.substring(0, Math.min(uuidWithoutHyphen.length(), 20)); @@ -3755,7 +3727,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { final String textToFind = "InitiatorName="; - final Script iScsiAdmCmd = new Script(true, "grep", 0, s_logger); + final Script iScsiAdmCmd = new Script(true, "grep", 0, LOGGER); iScsiAdmCmd.add(textToFind); iScsiAdmCmd.add("/etc/iscsi/initiatorname.iscsi"); @@ -3787,7 +3759,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv String sourcePath = null; try { String mountResult = Script.runSimpleBashScript("mount | grep \"" + diskPath + "\""); - s_logger.debug("Got mount result for " + diskPath + "\n\n" + mountResult); + logger.debug("Got mount result for " + diskPath + "\n\n" + mountResult); if (StringUtils.isNotEmpty(mountResult)) { String[] res = mountResult.strip().split(" "); if (res[0].contains(":")) { @@ -3804,7 +3776,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return new Pair<>(sourceHostIp, sourcePath); } } catch (Exception ex) { - s_logger.warn("Failed to list source host and IP for " + diskPath + ex.toString()); + logger.warn("Failed to list source host and IP for " + diskPath + ex.toString()); } return null; } @@ -3817,14 +3789,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv la.add(names[i]); } } catch (final LibvirtException e) { - s_logger.warn("Failed to list Defined domains", e); + LOGGER.warn("Failed to list Defined domains", e); } int[] ids = null; try { ids = conn.listDomains(); } catch (final LibvirtException e) { - s_logger.warn("Failed to list domains", e); + LOGGER.warn("Failed to list domains", e); return la; } @@ -3834,14 +3806,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv dm = conn.domainLookupByID(ids[i]); la.add(dm.getName()); } catch (final LibvirtException e) { - s_logger.warn("Unable to get vms", e); + LOGGER.warn("Unable to get vms", e); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -3860,7 +3832,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv conn = LibvirtConnection.getConnectionByType(HypervisorType.KVM.toString()); vmStates.putAll(getHostVmStateReport(conn)); } catch (final LibvirtException e) { - s_logger.debug("Failed to get connection: " + e.getMessage()); + LOGGER.debug("Failed to get connection: " + e.getMessage()); } } @@ -3869,7 +3841,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv conn = LibvirtConnection.getConnectionByType(HypervisorType.KVM.toString()); vmStates.putAll(getHostVmStateReport(conn)); } catch (final LibvirtException e) { - s_logger.debug("Failed to get connection: " + e.getMessage()); + LOGGER.debug("Failed to get connection: " + e.getMessage()); } } @@ -3885,13 +3857,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { ids = conn.listDomains(); } catch (final LibvirtException e) { - s_logger.warn("Unable to listDomains", e); + LOGGER.warn("Unable to listDomains", e); return null; } try { vms = conn.listDefinedDomains(); } catch (final LibvirtException e) { - s_logger.warn("Unable to listDomains", e); + LOGGER.warn("Unable to listDomains", e); return null; } @@ -3904,7 +3876,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final PowerState state = convertToPowerState(ps); - s_logger.trace("VM " + dm.getName() + ": powerstate = " + ps + "; vm state=" + state.toString()); + LOGGER.trace("VM " + dm.getName() + ": powerstate = " + ps + "; vm state=" + state.toString()); final String vmName = dm.getName(); // TODO : for XS/KVM (host-based resource), we require to remove @@ -3915,14 +3887,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv vmStates.put(vmName, new HostVmStateReportEntry(state, conn.getHostName())); } } catch (final LibvirtException e) { - s_logger.warn("Unable to get vms", e); + LOGGER.warn("Unable to get vms", e); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -3935,7 +3907,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final DomainState ps = dm.getInfo().state; final PowerState state = convertToPowerState(ps); final String vmName = dm.getName(); - s_logger.trace("VM " + vmName + ": powerstate = " + ps + "; vm state=" + state.toString()); + LOGGER.trace("VM " + vmName + ": powerstate = " + ps + "; vm state=" + state.toString()); // TODO : for XS/KVM (host-based resource), we require to remove // VM completely from host, for some reason, KVM seems to still keep @@ -3945,14 +3917,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv vmStates.put(vmName, new HostVmStateReportEntry(state, conn.getHostName())); } } catch (final LibvirtException e) { - s_logger.warn("Unable to get vms", e); + LOGGER.warn("Unable to get vms", e); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -3972,7 +3944,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv dm.reboot(0x1); return null; } catch (final LibvirtException e) { - s_logger.warn("Failed to create vm", e); + LOGGER.warn("Failed to create vm", e); msg = e.getMessage(); } finally { try { @@ -3980,7 +3952,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } @@ -3996,18 +3968,18 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv dm = conn.domainLookupByName(vmName); cleanVMSnapshotMetadata(dm); } catch (LibvirtException e) { - s_logger.debug("Failed to get vm :" + e.getMessage()); + LOGGER.debug("Failed to get vm :" + e.getMessage()); } finally { try { if (dm != null) { dm.free(); } } catch (LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } - s_logger.debug("Try to stop the vm at first"); + LOGGER.debug("Try to stop the vm at first"); if (forceStop) { return stopVMInternal(conn, vmName, true); } @@ -4027,25 +3999,25 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv state = dm.getInfo().state; break; } catch (final LibvirtException e) { - s_logger.debug("Failed to get vm status:" + e.getMessage()); + LOGGER.debug("Failed to get vm status:" + e.getMessage()); } finally { try { if (dm != null) { dm.free(); } } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } } if (state == null) { - s_logger.debug("Can't get vm's status, assume it's dead already"); + LOGGER.debug("Can't get vm's status, assume it's dead already"); return null; } if (state != DomainState.VIR_DOMAIN_SHUTOFF) { - s_logger.debug("Try to destroy the vm"); + LOGGER.debug("Try to destroy the vm"); ret = stopVMInternal(conn, vmName, true); if (ret != null) { return ret; @@ -4084,13 +4056,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } catch (final LibvirtException e) { final String error = e.toString(); if (error.contains("Domain not found")) { - s_logger.debug("successfully shut down vm " + vmName); + LOGGER.debug("successfully shut down vm " + vmName); } else { - s_logger.debug("Error in waiting for vm shutdown:" + error); + LOGGER.debug("Error in waiting for vm shutdown:" + error); } } if (retry < 0) { - s_logger.warn("Timed out waiting for domain " + vmName + " to shutdown gracefully"); + LOGGER.warn("Timed out waiting for domain " + vmName + " to shutdown gracefully"); return Script.ERR_TIMEOUT; } else { if (persist == 1) { @@ -4100,13 +4072,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } catch (final LibvirtException e) { if (e.getMessage().contains("Domain not found")) { - s_logger.debug("VM " + vmName + " doesn't exist, no need to stop it"); + LOGGER.debug("VM " + vmName + " doesn't exist, no need to stop it"); return null; } - s_logger.debug("Failed to stop VM :" + vmName + " :", e); + LOGGER.debug("Failed to stop VM :" + vmName + " :", e); return e.getMessage(); } catch (final InterruptedException ie) { - s_logger.debug("Interrupted sleep"); + LOGGER.debug("Interrupted sleep"); return ie.getMessage(); } finally { try { @@ -4114,7 +4086,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } @@ -4135,7 +4107,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv dm.free(); } } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + LOGGER.trace("Ignoring libvirt error.", l); } } } @@ -4151,7 +4123,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } return false; } @@ -4161,7 +4133,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { parser.parseCapabilitiesXML(conn.getCapabilities()); } catch (final LibvirtException e) { - s_logger.debug(e.getMessage()); + LOGGER.debug(e.getMessage()); } return parser.getEmulator(); } @@ -4187,10 +4159,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv String rootDiskController = details.get(VmDetailConstants.ROOT_DISK_CONTROLLER); if (StringUtils.isNotBlank(rootDiskController)) { - s_logger.debug("Passed custom disk controller for ROOT disk " + rootDiskController); + LOGGER.debug("Passed custom disk controller for ROOT disk " + rootDiskController); for (DiskDef.DiskBus bus : DiskDef.DiskBus.values()) { if (bus.toString().equalsIgnoreCase(rootDiskController)) { - s_logger.debug("Found matching enum for disk controller for ROOT disk " + rootDiskController); + LOGGER.debug("Found matching enum for disk controller for ROOT disk " + rootDiskController); return bus; } } @@ -4206,10 +4178,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv String dataDiskController = details.get(VmDetailConstants.DATA_DISK_CONTROLLER); if (StringUtils.isNotBlank(dataDiskController)) { - s_logger.debug("Passed custom disk controller for DATA disk " + dataDiskController); + LOGGER.debug("Passed custom disk controller for DATA disk " + dataDiskController); for (DiskDef.DiskBus bus : DiskDef.DiskBus.values()) { if (bus.toString().equalsIgnoreCase(dataDiskController)) { - s_logger.debug("Found matching enum for disk controller for DATA disk " + dataDiskController); + LOGGER.debug("Found matching enum for disk controller for DATA disk " + dataDiskController); return bus; } } @@ -4259,7 +4231,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return parser.getInterfaces(); } catch (final LibvirtException e) { - s_logger.debug("Failed to get dom xml: " + e.toString()); + LOGGER.debug("Failed to get dom xml: " + e.toString()); return new ArrayList(); } finally { try { @@ -4267,7 +4239,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -4281,7 +4253,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return parser.getDisks(); } catch (final LibvirtException e) { - s_logger.debug("Failed to get dom xml: " + e.toString()); + LOGGER.debug("Failed to get dom xml: " + e.toString()); return new ArrayList(); } finally { try { @@ -4289,7 +4261,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv dm.free(); } } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + LOGGER.trace("Ignoring libvirt error.", e); } } } @@ -4299,7 +4271,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } private Script createScript(final String script) { - final Script command = new Script("/bin/bash", timeout, s_logger); + final Script command = new Script("/bin/bash", timeout, LOGGER); command.add("-c"); command.add(script); return command; @@ -4534,8 +4506,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected long getMemoryFreeInKBs(Domain dm) throws LibvirtException { MemoryStatistic[] memoryStats = dm.memoryStats(NUMMEMSTATS); - if(s_logger.isTraceEnabled()){ - s_logger.trace(String.format("Retrieved memory statistics (information about tags can be found on the libvirt documentation):", ArrayUtils.toString(memoryStats))); + if(LOGGER.isTraceEnabled()){ + LOGGER.trace(String.format("Retrieved memory statistics (information about tags can be found on the libvirt documentation):", ArrayUtils.toString(memoryStats))); } long freeMemory = NumberUtils.LONG_MINUS_ONE; @@ -4552,13 +4524,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } if (freeMemory == NumberUtils.LONG_MINUS_ONE){ - s_logger.warn("Couldn't retrieve free memory, returning -1."); + LOGGER.warn("Couldn't retrieve free memory, returning -1."); } return freeMemory; } private boolean canBridgeFirewall(final String prvNic) { - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("can_bridge_firewall"); cmd.add("--privnic", prvNic); final String result = cmd.execute(); @@ -4578,7 +4550,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final InterfaceDef intf = intfs.get(0); vif = intf.getDevName(); } - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("destroy_network_rules_for_vm"); cmd.add("--vmname", vmName); if (vif != null) { @@ -4624,7 +4596,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final String brname = intf.getBrName(); final String vif = intf.getDevName(); - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("destroy_network_rules_for_vm"); cmd.add("--vmname", vmName); if (nic.getIp() != null) { @@ -4651,7 +4623,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public boolean applyDefaultNetworkRules(final Connect conn, final VirtualMachineTO vm, final boolean checkBeforeApply) { NicTO[] nicTOs = new NicTO[] {}; if (vm != null && vm.getNics() != null) { - s_logger.debug("Checking default network rules for vm " + vm.getName()); + LOGGER.debug("Checking default network rules for vm " + vm.getName()); nicTOs = vm.getNics(); } for (NicTO nic : nicTOs) { @@ -4667,7 +4639,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv break; } if (!applyDefaultNetworkRulesOnNic(conn, vm.getName(), vm.getId(), nic, isFirstNic, checkBeforeApply)) { - s_logger.error("Unable to apply default network rule for nic " + nic.getName() + " for VM " + vm.getName()); + LOGGER.error("Unable to apply default network rule for nic " + nic.getName() + " for VM " + vm.getName()); return false; } isFirstNic = false; @@ -4715,7 +4687,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final String brname = intf.getBrName(); final String vif = intf.getDevName(); - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("default_network_rules"); cmd.add("--vmname", vmName); cmd.add("--vmid", vmId.toString()); @@ -4756,7 +4728,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final String brname = intf.getBrName(); final String vif = intf.getDevName(); - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("post_default_network_rules"); cmd.add("--vmname", vmName); cmd.add("--vmid", vmId.toString()); @@ -4782,7 +4754,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return false; } - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("default_network_rules_systemvm"); cmd.add("--vmname", vmName); cmd.add("--localbrname", linkLocalBridgeName); @@ -4806,7 +4778,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } final String newRules = rules.replace(" ", ";"); - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("add_network_rules"); cmd.add("--vmname", vmName); cmd.add("--vmid", vmId); @@ -4836,7 +4808,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return false; } - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("network_rules_vmSecondaryIp"); cmd.add("--vmname", vmName); cmd.add("--vmmac", vmMac); @@ -4852,7 +4824,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public boolean setupTungstenVRouter(final String oper, final String inf, final String subnet, final String route, final String vrf) { - final Script cmd = new Script(setupTungstenVrouterPath, timeout, s_logger); + final Script cmd = new Script(setupTungstenVrouterPath, timeout, logger); cmd.add(oper); cmd.add(inf); cmd.add(subnet); @@ -4865,7 +4837,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public boolean updateTungstenLoadbalancerStats(final String lbUuid, final String lbStatsPort, final String lbStatsUri, final String lbStatsAuth) { - final Script cmd = new Script(updateTungstenLoadbalancerStatsPath, timeout, s_logger); + final Script cmd = new Script(updateTungstenLoadbalancerStatsPath, timeout, logger); cmd.add(lbUuid); cmd.add(lbStatsPort); cmd.add(lbStatsUri); @@ -4877,7 +4849,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv public boolean updateTungstenLoadbalancerSsl(final String lbUuid, final String sslCertName, final String certificateKey, final String privateKey, final String privateIp, final String port) { - final Script cmd = new Script(updateTungstenLoadbalancerSslPath, timeout, s_logger); + final Script cmd = new Script(updateTungstenLoadbalancerSslPath, timeout, logger); cmd.add(lbUuid); cmd.add(sslCertName); cmd.add(certificateKey); @@ -4890,7 +4862,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } public boolean setupTfRoute(final String privateIpAddress, final String fromNetwork, final String toNetwork) { - final Script setupTfRouteScript = new Script(routerProxyPath, timeout, s_logger); + final Script setupTfRouteScript = new Script(routerProxyPath, timeout, logger); setupTfRouteScript.add("setup_tf_route.py"); setupTfRouteScript.add(privateIpAddress); setupTfRouteScript.add(fromNetwork); @@ -4899,7 +4871,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final OutputInterpreter.OneLineParser setupTfRouteParser = new OutputInterpreter.OneLineParser(); final String result = setupTfRouteScript.execute(setupTfRouteParser); if (result != null) { - s_logger.debug("Failed to execute setup TF Route:" + result); + logger.debug("Failed to execute setup TF Route:" + result); return false; } return true; @@ -4909,7 +4881,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv if (!canBridgeFirewall) { return false; } - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("cleanup_rules"); final String result = cmd.execute(); if (result != null) { @@ -4919,7 +4891,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } public String getRuleLogsForVms() { - final Script cmd = new Script(securityGroupPath, timeout, s_logger); + final Script cmd = new Script(securityGroupPath, timeout, LOGGER); cmd.add("get_rule_logs_for_vms"); final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); final String result = cmd.execute(parser); @@ -4933,7 +4905,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv final HashMap> states = new HashMap>(); final String result = getRuleLogsForVms(); - s_logger.trace("syncNetworkGroups: id=" + id + " got: " + result); + LOGGER.trace("syncNetworkGroups: id=" + id + " got: " + result); final String[] rulelogs = result != null ? result.split(";") : new String[0]; for (final String rulesforvm : rulelogs) { final String[] log = rulesforvm.split(","); @@ -4963,12 +4935,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return new Pair(readDouble(nicName, "rx_bytes"), readDouble(nicName, "tx_bytes")); } - static double readDouble(final String nicName, final String fileName) { + double readDouble(final String nicName, final String fileName) { final String path = "/sys/class/net/" + nicName + "/statistics/" + fileName; try { return Double.parseDouble(FileUtils.readFileToString(new File(path))); } catch (final IOException ioe) { - s_logger.warn("Failed to read the " + fileName + " for " + nicName + " from " + path, ioe); + LOGGER.warn("Failed to read the " + fileName + " for " + nicName + " from " + path, ioe); return 0.0; } } @@ -5025,11 +4997,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } public List> cleanVMSnapshotMetadata(Domain dm) throws LibvirtException { - s_logger.debug("Cleaning the metadata of vm snapshots of vm " + dm.getName()); + LOGGER.debug("Cleaning the metadata of vm snapshots of vm " + dm.getName()); List> vmsnapshots = new ArrayList>(); if (dm.snapshotNum() == 0) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("VM [%s] does not have any snapshots. Skipping cleanup of snapshots for this VM.", dm.getName())); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("VM [%s] does not have any snapshots. Skipping cleanup of snapshots for this VM.", dm.getName())); } return vmsnapshots; } @@ -5037,8 +5009,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { DomainSnapshot snapshotCurrent = dm.snapshotCurrent(); String snapshotXML = snapshotCurrent.getXMLDesc(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Current snapshot of VM [%s] has the following XML: [%s].", dm.getName(), snapshotXML)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("Current snapshot of VM [%s] has the following XML: [%s].", dm.getName(), snapshotXML)); } snapshotCurrent.free(); @@ -5053,23 +5025,23 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv currentSnapshotName = getTagValue("name", rootElement); } catch (ParserConfigurationException | SAXException | IOException e) { - s_logger.error(String.format("Failed to parse snapshot configuration [%s] of VM [%s] due to: [%s].", snapshotXML, dm.getName(), e.getMessage()), e); + LOGGER.error(String.format("Failed to parse snapshot configuration [%s] of VM [%s] due to: [%s].", snapshotXML, dm.getName(), e.getMessage()), e); } } catch (LibvirtException e) { - s_logger.error(String.format("Failed to get the current snapshot of VM [%s] due to: [%s]. Continuing the migration process.", dm.getName(), e.getMessage()), e); + LOGGER.error(String.format("Failed to get the current snapshot of VM [%s] due to: [%s]. Continuing the migration process.", dm.getName(), e.getMessage()), e); } int flags = 2; // VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY = 2 String[] snapshotNames = dm.snapshotListNames(); Arrays.sort(snapshotNames); - s_logger.debug(String.format("Found [%s] snapshots in VM [%s] to clean.", snapshotNames.length, dm.getName())); + LOGGER.debug(String.format("Found [%s] snapshots in VM [%s] to clean.", snapshotNames.length, dm.getName())); for (String snapshotName: snapshotNames) { DomainSnapshot snapshot = dm.snapshotLookupByName(snapshotName); Boolean isCurrent = (currentSnapshotName != null && currentSnapshotName.equals(snapshotName)) ? true: false; vmsnapshots.add(new Ternary(snapshotName, isCurrent, snapshot.getXMLDesc())); } for (String snapshotName: snapshotNames) { - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Cleaning snapshot [%s] of VM [%s] metadata.", snapshotNames, dm.getName())); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("Cleaning snapshot [%s] of VM [%s] metadata.", snapshotNames, dm.getName())); } DomainSnapshot snapshot = dm.snapshotLookupByName(snapshotName); snapshot.delete(flags); // clean metadata of vm snapshot @@ -5103,12 +5075,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } public void restoreVMSnapshotMetadata(Domain dm, String vmName, List> vmsnapshots) { - s_logger.debug("Restoring the metadata of vm snapshots of vm " + vmName); + LOGGER.debug("Restoring the metadata of vm snapshots of vm " + vmName); for (Ternary vmsnapshot: vmsnapshots) { String snapshotName = vmsnapshot.first(); Boolean isCurrent = vmsnapshot.second(); String snapshotXML = vmsnapshot.third(); - s_logger.debug("Restoring vm snapshot " + snapshotName + " on " + vmName + " with XML:\n " + snapshotXML); + LOGGER.debug("Restoring vm snapshot " + snapshotName + " on " + vmName + " with XML:\n " + snapshotXML); try { int flags = 1; // VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = 1 if (isCurrent) { @@ -5116,7 +5088,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv } dm.snapshotCreateXML(snapshotXML, flags); } catch (LibvirtException e) { - s_logger.debug("Failed to restore vm snapshot " + snapshotName + ", continue"); + LOGGER.debug("Failed to restore vm snapshot " + snapshotName + ", continue"); continue; } } @@ -5154,14 +5126,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return false; } } catch (QemuImgException | LibvirtException ex) { - s_logger.info("Host's qemu install doesn't support encryption", ex); + LOGGER.info("Host's qemu install doesn't support encryption", ex); return false; } // test cryptsetup CryptSetup crypt = new CryptSetup(); if (!crypt.isSupported()) { - s_logger.info("Host can't run cryptsetup"); + LOGGER.info("Host can't run cryptsetup"); return false; } @@ -5178,7 +5150,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv private void setCpuTopology(CpuModeDef cmd, int vCpusInDef, Map details) { if (!enableManuallySettingCpuTopologyOnKvmVm) { - s_logger.debug(String.format("Skipping manually setting CPU topology on VM's XML due to it is disabled in agent.properties {\"property\": \"%s\", \"value\": %s}.", + LOGGER.debug(String.format("Skipping manually setting CPU topology on VM's XML due to it is disabled in agent.properties {\"property\": \"%s\", \"value\": %s}.", AgentProperties.ENABLE_MANUALLY_SETTING_CPU_TOPOLOGY_ON_KVM_VM.getName(), enableManuallySettingCpuTopologyOnKvmVm)); return; } @@ -5216,14 +5188,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv // VMs which are created in CloudStack 4.14 and before cannot be started or migrated // in latest Linux distributions due to missing backing file format // Please refer to https://libvirt.org/kbase/backing_chains.html#vm-refuses-to-start-due-to-misconfigured-backing-store-format - s_logger.info("Setting backing file format of " + volPath); + LOGGER.info("Setting backing file format of " + volPath); QemuImgFile backingFile = new QemuImgFile(backingFilePath); Map backingFileinfo = qemu.info(backingFile); String backingFileFmt = backingFileinfo.get(QemuImg.FILE_FORMAT); qemu.rebase(file, backingFile, backingFileFmt, false); } } catch (QemuImgException | LibvirtException e) { - s_logger.error("Failed to set backing file format of " + volPath + " due to : " + e.getMessage(), e); + LOGGER.error("Failed to set backing file format of " + volPath + " due to : " + e.getMessage(), e); } } @@ -5261,7 +5233,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv return Integer.parseInt(c.getValueAsString()); } } - s_logger.warn(String.format("Could not get cpu_shares of domain: [%s]. Returning default value of 0. ", dm.getName())); + LOGGER.warn(String.format("Could not get cpu_shares of domain: [%s]. Returning default value of 0. ", dm.getName())); return 0; } @@ -5307,7 +5279,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv Match match = new Match(); if (UuidUtils.getUuidRegex().matches(ex.getMessage(), match)) { secretUuid = match.getCapturedText(0); - s_logger.info(String.format("Reusing previously defined secret '%s' for volume '%s'", secretUuid, consumer)); + LOGGER.info(String.format("Reusing previously defined secret '%s' for volume '%s'", secretUuid, consumer)); } else { throw ex; } @@ -5325,12 +5297,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv secret.undefine(); } catch (LibvirtException ex) { if (ex.getMessage().contains("Secret not found")) { - s_logger.debug(String.format("Secret uuid %s doesn't exist", secretUuid)); + LOGGER.debug(String.format("Secret uuid %s doesn't exist", secretUuid)); return; } throw ex; } - s_logger.debug(String.format("Undefined secret %s", secretUuid)); + LOGGER.debug(String.format("Undefined secret %s", secretUuid)); } public void cleanOldSecretsByDiskDef(Connect conn, List disks) throws LibvirtException { @@ -5359,7 +5331,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv interfaceDef.setMultiQueueNumber(nicMultiqueueNumberInteger); } } catch (NumberFormatException ex) { - s_logger.warn(String.format("VM details %s is not a valid integer value %s", VmDetailConstants.NIC_MULTIQUEUE_NUMBER, nicMultiqueueNumber)); + logger.warn(String.format("VM details %s is not a valid integer value %s", VmDetailConstants.NIC_MULTIQUEUE_NUMBER, nicMultiqueueNumber)); } } String nicPackedEnabled = details.get(VmDetailConstants.NIC_PACKED_VIRTQUEUES_ENABLED); @@ -5367,7 +5339,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv try { interfaceDef.setPackedVirtQueues(Boolean.valueOf(nicPackedEnabled)); } catch (NumberFormatException ex) { - s_logger.warn(String.format("VM details %s is not a valid Boolean value %s", VmDetailConstants.NIC_PACKED_VIRTQUEUES_ENABLED, nicPackedEnabled)); + logger.warn(String.format("VM details %s is not a valid Boolean value %s", VmDetailConstants.NIC_PACKED_VIRTQUEUES_ENABLED, nicPackedEnabled)); } } } @@ -5382,11 +5354,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv command.append(remoteFile); command.append(" "+tmpPath); command.append(outputFile); - s_logger.debug("Converting remoteFile: "+remoteFile); + logger.debug("Converting remoteFile: "+remoteFile); SshHelper.sshExecute(srcIp, 22, username, null, password, command.toString()); - s_logger.debug("Copying remoteFile to: "+localDir); + logger.debug("Copying remoteFile to: "+localDir); SshHelper.scpFrom(srcIp, 22, username, null, password, localDir, tmpPath+outputFile); - s_logger.debug("Successfully copyied remoteFile to: "+localDir+"/"+outputFile); + logger.debug("Successfully copyied remoteFile to: "+localDir+"/"+outputFile); return outputFile; } catch (Exception e) { throw new RuntimeException(e); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java index 7563f964759..cbb5d85b712 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtConnection.java @@ -21,39 +21,52 @@ import java.util.Map; import com.cloud.agent.properties.AgentProperties; import com.cloud.agent.properties.AgentPropertiesFileHandler; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; +import org.libvirt.Library; import org.libvirt.LibvirtException; import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor.HypervisorType; public class LibvirtConnection { - private static final Logger s_logger = Logger.getLogger(LibvirtConnection.class); + protected static Logger LOGGER = LogManager.getLogger(LibvirtConnection.class); static private Map s_connections = new HashMap(); static private Connect s_connection; static private String s_hypervisorURI; + static private Thread libvirtEventThread; static public Connect getConnection() throws LibvirtException { return getConnection(s_hypervisorURI); } - static public Connect getConnection(String hypervisorURI) throws LibvirtException { - s_logger.debug("Looking for libvirtd connection at: " + hypervisorURI); + static synchronized public Connect getConnection(String hypervisorURI) throws LibvirtException { + LOGGER.debug("Looking for libvirtd connection at: " + hypervisorURI); Connect conn = s_connections.get(hypervisorURI); if (conn == null) { - s_logger.info("No existing libvirtd connection found. Opening a new one"); + LOGGER.info("No existing libvirtd connection found. Opening a new one"); + + setupEventListener(); conn = new Connect(hypervisorURI, false); - s_logger.debug("Successfully connected to libvirt at: " + hypervisorURI); + LOGGER.debug("Successfully connected to libvirt at: " + hypervisorURI); s_connections.put(hypervisorURI, conn); } else { try { conn.getVersion(); } catch (LibvirtException e) { - s_logger.error("Connection with libvirtd is broken: " + e.getMessage()); - s_logger.debug("Opening a new libvirtd connection to: " + hypervisorURI); + LOGGER.error("Connection with libvirtd is broken: " + e.getMessage()); + + try { + conn.close(); + } catch (LibvirtException closeEx) { + LOGGER.debug("Ignoring error while trying to close broken connection:" + closeEx.getMessage()); + } + + LOGGER.debug("Opening a new libvirtd connection to: " + hypervisorURI); + setupEventListener(); conn = new Connect(hypervisorURI, false); s_connections.put(hypervisorURI, conn); } @@ -72,11 +85,11 @@ public class LibvirtConnection { return conn; } } catch (Exception e) { - s_logger.debug("Can not find " + hypervisor.toString() + " connection for Instance: " + vmName + ", continuing."); + LOGGER.debug("Can not find " + hypervisor.toString() + " connection for Instance: " + vmName + ", continuing."); } } - s_logger.warn("Can not find a connection for Instance " + vmName + ". Assuming the default connection."); + LOGGER.warn("Can not find a connection for Instance " + vmName + ". Assuming the default connection."); // return the default connection return getConnection(); } @@ -101,4 +114,38 @@ public class LibvirtConnection { return "qemu:///system"; } + + /** + * Set up Libvirt event handling and polling. This is not specific to a connection object instance, but needs + * to be done prior to creating connections. See the Libvirt documentation for virEventRegisterDefaultImpl and + * virEventRunDefaultImpl or the libvirt-java Library Javadoc for more information. + * @throws LibvirtException + */ + private static synchronized void setupEventListener() throws LibvirtException { + if (!AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_EVENTS_ENABLED)) { + LOGGER.debug("Libvirt event listening is disabled, not setting up event loop"); + return; + } + + if (libvirtEventThread == null || !libvirtEventThread.isAlive()) { + // Registers a default event loop, must be called before connecting to hypervisor + Library.initEventLoop(); + libvirtEventThread = new Thread(() -> { + while (true) { + try { + // This blocking call contains a loop of its own that will process events until the event loop is stopped or exception is thrown. + Library.runEventLoop(); + } catch (LibvirtException e) { + LOGGER.error("LibvirtException was thrown in event loop: ", e); + } catch (InterruptedException e) { + LOGGER.error("Libvirt event loop was interrupted: ", e); + } + } + }); + + // Process events in separate thread. Failure to run event loop regularly will cause connections to close due to keepalive timeout. + libvirtEventThread.setDaemon(true); + libvirtEventThread.start(); + } + } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainListener.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainListener.java new file mode 100644 index 00000000000..5adb383c6cd --- /dev/null +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainListener.java @@ -0,0 +1,66 @@ +/* + * + * Licensed 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.hypervisor.kvm.resource; + +import com.cloud.resource.AgentStatusUpdater; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.libvirt.Domain; +import org.libvirt.LibvirtException; +import org.libvirt.event.DomainEvent; +import org.libvirt.event.DomainEventDetail; +import org.libvirt.event.LifecycleListener; +import org.libvirt.event.StoppedDetail; + +public class LibvirtDomainListener implements LifecycleListener { + private static final Logger LOGGER = LogManager.getLogger(LibvirtDomainListener.class); + + private final AgentStatusUpdater agentStatusUpdater; + + public LibvirtDomainListener(AgentStatusUpdater updater) { + agentStatusUpdater = updater; + } + + public int onLifecycleChange(Domain domain, DomainEvent domainEvent) { + try { + LOGGER.debug(String.format("Got event lifecycle change on Domain %s, event %s", domain.getName(), domainEvent)); + if (domainEvent != null) { + switch (domainEvent.getType()) { + case STOPPED: + /* libvirt-destroyed VMs have detail StoppedDetail.DESTROYED, self shutdown guests are StoppedDetail.SHUTDOWN + * Checking for this helps us differentiate between events where cloudstack or admin stopped the VM vs guest + * initiated, and avoid pushing extra updates for actions we are initiating without a need for extra tracking */ + DomainEventDetail detail = domainEvent.getDetail(); + if (StoppedDetail.SHUTDOWN.equals(detail) || StoppedDetail.CRASHED.equals(detail) || StoppedDetail.FAILED.equals(detail)) { + if (agentStatusUpdater != null) { + LOGGER.info("Triggering out of band status update due to completed self-shutdown or crash of VM"); + agentStatusUpdater.triggerUpdate(); + } + } else { + LOGGER.debug("Event detail: " + detail); + } + break; + default: + LOGGER.debug(String.format("No handling for event %s", domainEvent)); + } + } + } catch (LibvirtException e) { + LOGGER.error("Libvirt exception while processing lifecycle event", e); + } catch (Throwable e) { + LOGGER.error("Error during lifecycle", e); + } + return 0; + } +} diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java index f165796adef..5465e289a2c 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java @@ -29,7 +29,8 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.lang3.StringUtils; import org.apache.cloudstack.utils.qemu.QemuObject; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -49,7 +50,7 @@ import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.WatchDogDef.WatchDogAction import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.WatchDogDef.WatchDogModel; public class LibvirtDomainXMLParser { - private static final Logger s_logger = Logger.getLogger(LibvirtDomainXMLParser.class); + protected Logger logger = LogManager.getLogger(getClass()); private final List interfaces = new ArrayList(); private MemBalloonDef memBalloonDef = new MemBalloonDef(); private final List diskDefs = new ArrayList(); @@ -332,7 +333,7 @@ public class LibvirtDomainXMLParser { String bytes = getAttrValue("rate", "bytes", rng); String period = getAttrValue("rate", "period", rng); if (StringUtils.isAnyEmpty(bytes, period)) { - s_logger.debug(String.format("Bytes and period in the rng section should not be null, please check the VM %s", name)); + logger.debug(String.format("Bytes and period in the rng section should not be null, please check the VM %s", name)); } if (bytes == null) { @@ -390,11 +391,11 @@ public class LibvirtDomainXMLParser { extractCpuModeDef(rootElement); return true; } catch (ParserConfigurationException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (SAXException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (IOException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } return false; } @@ -419,6 +420,9 @@ public class LibvirtDomainXMLParser { } private static String getTagValue(String tag, Element eElement) { + if (eElement == null) { + return null; + } NodeList tagNodeList = eElement.getElementsByTagName(tag); if (tagNodeList == null || tagNodeList.getLength() == 0) { return null; @@ -426,14 +430,20 @@ public class LibvirtDomainXMLParser { NodeList nlList = tagNodeList.item(0).getChildNodes(); + if (nlList == null || nlList.getLength() == 0) { + return null; + } Node nValue = nlList.item(0); return nValue.getNodeValue(); } private static String getAttrValue(String tag, String attr, Element eElement) { + if (eElement == null) { + return null; + } NodeList tagNode = eElement.getElementsByTagName(tag); - if (tagNode.getLength() == 0) { + if (tag == null || tagNode.getLength() == 0) { return null; } Element node = (Element)tagNode.item(0); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtKvmAgentHook.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtKvmAgentHook.java index 2ef65293de2..edcc5a05326 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtKvmAgentHook.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtKvmAgentHook.java @@ -22,7 +22,8 @@ import groovy.lang.GroovyObject; import groovy.util.GroovyScriptEngine; import groovy.util.ResourceException; import groovy.util.ScriptException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack; import java.io.File; @@ -34,14 +35,14 @@ public class LibvirtKvmAgentHook { private final GroovyScriptEngine gse; private final Binding binding = new Binding(); - private static final Logger s_logger = Logger.getLogger(LibvirtKvmAgentHook.class); + protected Logger logger = LogManager.getLogger(getClass()); public LibvirtKvmAgentHook(String path, String script, String method) throws IOException { this.script = script; this.method = method; File full_path = new File(path, script); if (!full_path.canRead()) { - s_logger.warn("Groovy script '" + full_path.toString() + "' is not available. Transformations will not be applied."); + logger.warn("Groovy script '" + full_path.toString() + "' is not available. Transformations will not be applied."); this.gse = null; } else { this.gse = new GroovyScriptEngine(path); @@ -54,21 +55,21 @@ public class LibvirtKvmAgentHook { public Object handle(Object arg) throws ResourceException, ScriptException { if (!isInitialized()) { - s_logger.warn("Groovy scripting engine is not initialized. Data transformation skipped."); + logger.warn("Groovy scripting engine is not initialized. Data transformation skipped."); return arg; } GroovyObject cls = (GroovyObject) this.gse.run(this.script, binding); if (null == cls) { - s_logger.warn("Groovy object is not received from script '" + this.script + "'."); + logger.warn("Groovy object is not received from script '" + this.script + "'."); return arg; } else { - Object[] params = {s_logger, arg}; + Object[] params = {logger, arg}; try { Object res = cls.invokeMethod(this.method, params); return res; } catch (MissingMethodExceptionNoStack e) { - s_logger.error("Error occurred when calling method from groovy script, {}", e); + logger.error("Error occurred when calling method from groovy script, {}", e); return arg; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolDef.java index f0ec29f41f6..ff44c8df2fa 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolDef.java @@ -18,7 +18,7 @@ package com.cloud.hypervisor.kvm.resource; public class LibvirtStoragePoolDef { public enum PoolType { - ISCSI("iscsi"), NETFS("netfs"), LOGICAL("logical"), DIR("dir"), RBD("rbd"), GLUSTERFS("glusterfs"), POWERFLEX("powerflex"); + ISCSI("iscsi"), NETFS("netfs"), loggerICAL("logical"), DIR("dir"), RBD("rbd"), GLUSTERFS("glusterfs"), POWERFLEX("powerflex"); String _poolType; PoolType(String poolType) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java index d19c851d7dc..30616e04798 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStoragePoolXMLParser.java @@ -26,7 +26,8 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -35,7 +36,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class LibvirtStoragePoolXMLParser { - private static final Logger s_logger = Logger.getLogger(LibvirtStoragePoolXMLParser.class); + protected Logger logger = LogManager.getLogger(getClass()); public LibvirtStoragePoolDef parseStoragePoolXML(String poolXML) { DocumentBuilder builder; @@ -101,11 +102,11 @@ public class LibvirtStoragePoolXMLParser { return new LibvirtStoragePoolDef(LibvirtStoragePoolDef.PoolType.valueOf(type.toUpperCase()), poolName, uuid, host, path, targetPath); } } catch (ParserConfigurationException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (SAXException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (IOException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } return null; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java index c4132ca1ba3..1b6f73039ca 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtStorageVolumeXMLParser.java @@ -23,7 +23,8 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.ParserConfigurationException; import org.apache.cloudstack.utils.security.ParserUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -32,7 +33,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class LibvirtStorageVolumeXMLParser { - private static final Logger s_logger = Logger.getLogger(LibvirtStorageVolumeXMLParser.class); + protected Logger logger = LogManager.getLogger(getClass()); public LibvirtStorageVolumeDef parseStorageVolumeXML(String volXML) { DocumentBuilder builder; @@ -51,11 +52,11 @@ public class LibvirtStorageVolumeXMLParser { Long capacity = Long.parseLong(getTagValue("capacity", rootElement)); return new LibvirtStorageVolumeDef(VolName, capacity, LibvirtStorageVolumeDef.VolumeFormat.getFormat(format), null, null); } catch (ParserConfigurationException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (SAXException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } catch (IOException e) { - s_logger.debug(e.toString()); + logger.debug(e.toString()); } return null; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index 6b5fac0e942..5e0c9044228 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -26,13 +26,14 @@ import org.apache.cloudstack.api.ApiConstants.IoDriverPolicy; import org.apache.cloudstack.utils.qemu.QemuObject; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import com.cloud.agent.properties.AgentProperties; import com.cloud.agent.properties.AgentPropertiesFileHandler; public class LibvirtVMDef { - private static final Logger s_logger = Logger.getLogger(LibvirtVMDef.class); + protected static Logger LOGGER = LogManager.getLogger(LibvirtVMDef.class); private String _hvsType; private static long s_libvirtVersion; @@ -699,6 +700,18 @@ public class LibvirtVMDef { } + public enum BlockIOSize { + SIZE_512("512"), SIZE_4K("4096"); + final String blockSize; + + BlockIOSize(String size) { this.blockSize = size; } + + @Override + public String toString() { + return blockSize; + } + } + private DeviceType _deviceType; /* floppy, disk, cdrom */ private DiskType _diskType; private DiskProtocol _diskProtocol; @@ -732,6 +745,8 @@ public class LibvirtVMDef { private IoDriverPolicy ioDriver; private LibvirtDiskEncryptDetails encryptDetails; private boolean isIothreadsEnabled; + private BlockIOSize logicalBlockIOSize = null; + private BlockIOSize physicalBlockIOSize = null; public DiscardType getDiscard() { return _discard; @@ -757,6 +772,10 @@ public class LibvirtVMDef { this.isIothreadsEnabled = isIothreadsEnabled; } + public void setPhysicalBlockIOSize(BlockIOSize size) { this.physicalBlockIOSize = size; } + + public void setLogicalBlockIOSize(BlockIOSize size) { this.logicalBlockIOSize = size; } + public void defFileBasedDisk(String filePath, String diskLabel, DiskBus bus, DiskFmtType diskFmtType) { _diskType = DiskType.FILE; _deviceType = DeviceType.DISK; @@ -861,7 +880,7 @@ public class LibvirtVMDef { public void defISODisk(String volPath, Integer devId, String diskLabel) { if (devId == null && StringUtils.isBlank(diskLabel)) { - s_logger.debug(String.format("No ID or label informed for volume [%s].", volPath)); + LOGGER.debug(String.format("No ID or label informed for volume [%s].", volPath)); defISODisk(volPath); return; } @@ -871,11 +890,11 @@ public class LibvirtVMDef { _sourcePath = volPath; if (StringUtils.isNotBlank(diskLabel)) { - s_logger.debug(String.format("Using informed label [%s] for volume [%s].", diskLabel, volPath)); + LOGGER.debug(String.format("Using informed label [%s] for volume [%s].", diskLabel, volPath)); _diskLabel = diskLabel; } else { _diskLabel = getDevLabel(devId, DiskBus.IDE, true); - s_logger.debug(String.format("Using device ID [%s] to define the label [%s] for volume [%s].", devId, _diskLabel, volPath)); + LOGGER.debug(String.format("Using device ID [%s] to define the label [%s] for volume [%s].", devId, _diskLabel, volPath)); } _diskFmtType = DiskFmtType.RAW; @@ -1155,6 +1174,17 @@ public class LibvirtVMDef { } diskBuilder.append("/>\n"); + if (logicalBlockIOSize != null || physicalBlockIOSize != null) { + diskBuilder.append("\n"); + } + if (_serial != null && !_serial.isEmpty() && _deviceType != DeviceType.LUN) { diskBuilder.append("" + _serial + "\n"); } @@ -2069,7 +2099,7 @@ public class LibvirtVMDef { } } - public static class MetadataDef { + public class MetadataDef { Map customNodes = new HashMap<>(); public T getMetadataNode(Class fieldClass) { @@ -2079,7 +2109,7 @@ public class LibvirtVMDef { field = fieldClass.newInstance(); customNodes.put(field.getClass().getName(), field); } catch (InstantiationException | IllegalAccessException e) { - s_logger.debug("No default constructor available in class " + fieldClass.getName() + ", ignoring exception", e); + LOGGER.debug("No default constructor available in class " + fieldClass.getName() + ", ignoring exception", e); } } return field; @@ -2200,7 +2230,7 @@ public class LibvirtVMDef { public static class WatchDogDef { enum WatchDogModel { - I6300ESB("i6300esb"), IB700("ib700"), DIAG288("diag288"); + I6300ESB("i6300esb"), IB700("ib700"), DIAG288("diag288"), ITCO("itco"); String model; WatchDogModel(String model) { @@ -2214,7 +2244,7 @@ public class LibvirtVMDef { } enum WatchDogAction { - RESET("reset"), SHUTDOWN("shutdown"), POWEROFF("poweroff"), PAUSE("pause"), NONE("none"), DUMP("dump"); + RESET("reset"), SHUTDOWN("shutdown"), POWEROFF("poweroff"), PAUSE("pause"), NONE("none"), DUMP("dump"), INJECT_NMI("inject-nmi"); String action; WatchDogAction(String action) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtXMLParser.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtXMLParser.java index 48a379c278f..f5de9b75412 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtXMLParser.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtXMLParser.java @@ -24,13 +24,14 @@ import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.apache.cloudstack.utils.security.ParserUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class LibvirtXMLParser extends DefaultHandler { - private static final Logger s_logger = Logger.getLogger(LibvirtXMLParser.class); + protected Logger logger = LogManager.getLogger(getClass()); protected static final SAXParserFactory s_spf; static { s_spf = ParserUtils.getSaferSAXParserFactory(); @@ -43,9 +44,9 @@ public class LibvirtXMLParser extends DefaultHandler { _sp = s_spf.newSAXParser(); _initialized = true; } catch (ParserConfigurationException e) { - s_logger.trace("Ignoring xml parser error.", e); + logger.trace("Ignoring xml parser error.", e); } catch (SAXException e) { - s_logger.trace("Ignoring xml parser error.", e); + logger.trace("Ignoring xml parser error.", e); } } @@ -57,9 +58,9 @@ public class LibvirtXMLParser extends DefaultHandler { _sp.parse(new InputSource(new StringReader(domXML)), this); return true; } catch (SAXException se) { - s_logger.warn(se.getMessage()); + logger.warn(se.getMessage()); } catch (IOException ie) { - s_logger.error(ie.getMessage()); + logger.error(ie.getMessage()); } return false; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java index 3c4c9d48c9d..e3ce9f4b8a6 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java @@ -30,7 +30,6 @@ import com.cloud.hypervisor.kvm.dpdk.DpdkHelper; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.NicTO; @@ -45,7 +44,6 @@ import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; public class OvsVifDriver extends VifDriverBase { - private static final Logger s_logger = Logger.getLogger(OvsVifDriver.class); private int _timeout; private String _controlCidr = NetUtils.getLinkLocalCIDR(); private DpdkDriver dpdkDriver; @@ -68,10 +66,10 @@ public class OvsVifDriver extends VifDriverBase { public void getPifs() { final String cmdout = Script.runSimpleBashScript("ovs-vsctl list-br | sed '{:q;N;s/\\n/%/g;t q}'"); - s_logger.debug("cmdout was " + cmdout); + logger.debug("cmdout was " + cmdout); final List bridges = Arrays.asList(cmdout.split("%")); for (final String bridge : bridges) { - s_logger.debug("looking for pif for bridge " + bridge); + logger.debug("looking for pif for bridge " + bridge); // String pif = getOvsPif(bridge); // Not really interested in the pif name at this point for ovs // bridges @@ -84,7 +82,7 @@ public class OvsVifDriver extends VifDriverBase { } _pifs.put(bridge, pif); } - s_logger.debug("done looking for pifs, no more bridges"); + logger.debug("done looking for pifs, no more bridges"); } /** @@ -94,7 +92,7 @@ public class OvsVifDriver extends VifDriverBase { */ protected void plugDPDKInterface(InterfaceDef intf, String trafficLabel, Map extraConfig, String vlanId, String guestOsType, NicTO nic, String nicAdapter) { - s_logger.debug("DPDK support enabled: configuring per traffic label " + trafficLabel); + logger.debug("DPDK support enabled: configuring per traffic label " + trafficLabel); String dpdkOvsPath = _libvirtComputingResource.dpdkOvsPath; if (StringUtils.isBlank(dpdkOvsPath)) { throw new CloudRuntimeException("DPDK is enabled on the host but no OVS path has been provided"); @@ -111,7 +109,7 @@ public class OvsVifDriver extends VifDriverBase { @Override public InterfaceDef plug(NicTO nic, String guestOsType, String nicAdapter, Map extraConfig) throws InternalErrorException, LibvirtException { - s_logger.debug("plugging nic=" + nic); + logger.debug("plugging nic=" + nic); LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef(); if (!_libvirtComputingResource.dpdkSupport || !nic.isDpdkEnabled()) { @@ -139,7 +137,7 @@ public class OvsVifDriver extends VifDriverBase { if (_libvirtComputingResource.dpdkSupport && nic.isDpdkEnabled()) { plugDPDKInterface(intf, trafficLabel, extraConfig, vlanId, guestOsType, nic, nicAdapter); } else { - s_logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); + logger.debug("creating a vlan dev and bridge for guest traffic per traffic label " + trafficLabel); intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); intf.setVlanTag(Integer.parseInt(vlanId)); } @@ -148,13 +146,13 @@ public class OvsVifDriver extends VifDriverBase { intf.setVlanTag(Integer.parseInt(vlanId)); } } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Lswitch || nic.getBroadcastType() == Networks.BroadcastDomainType.OpenDaylight) { - s_logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid); + logger.debug("nic " + nic + " needs to be connected to LogicalSwitch " + logicalSwitchUuid); intf.setVirtualPortInterfaceId(nic.getUuid()); String brName = (trafficLabel != null && !trafficLabel.isEmpty()) ? _pifs.get(trafficLabel) : _pifs.get("private"); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vswitch) { String brName = getOvsTunnelNetworkName(nic.getBroadcastUri().getAuthority()); - s_logger.debug("nic " + nic + " needs to be connected to Open vSwitch bridge " + brName); + logger.debug("nic " + nic + " needs to be connected to Open vSwitch bridge " + brName); intf.defBridgeNet(brName, null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); } else { intf.defBridgeNet(_bridges.get("guest"), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); @@ -167,7 +165,7 @@ public class OvsVifDriver extends VifDriverBase { Integer networkRateKBps = (nic.getNetworkRateMbps() != null && nic.getNetworkRateMbps().intValue() != -1) ? nic.getNetworkRateMbps().intValue() * 128 : 0; if (nic.getBroadcastType() == Networks.BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) { if (trafficLabel != null && !trafficLabel.isEmpty()) { - s_logger.debug("creating a vlan dev and bridge for public traffic per traffic label " + trafficLabel); + logger.debug("creating a vlan dev and bridge for public traffic per traffic label " + trafficLabel); intf.defBridgeNet(_pifs.get(trafficLabel), null, nic.getMac(), getGuestNicModel(guestOsType, nicAdapter), networkRateKBps); intf.setVlanTag(Integer.parseInt(vlanId)); } else { @@ -206,7 +204,7 @@ public class OvsVifDriver extends VifDriverBase { // If DPDK is enabled, we'll need to cleanup the port as libvirt won't String dpdkPort = iface.getDpdkSourcePort(); String cmd = String.format("ovs-vsctl del-port %s", dpdkPort); - s_logger.debug("Removing DPDK port: " + dpdkPort); + logger.debug("Removing DPDK port: " + dpdkPort); Script.runSimpleBashScript(cmd); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/VRouterVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/VRouterVifDriver.java index e6d9801e22c..edfe18bdd05 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/VRouterVifDriver.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/VRouterVifDriver.java @@ -20,7 +20,8 @@ import com.cloud.agent.api.to.NicTO; import com.cloud.exception.InternalErrorException; import com.cloud.utils.TungstenUtils; import com.cloud.utils.script.Script; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.joda.time.Duration; import org.libvirt.LibvirtException; @@ -30,7 +31,7 @@ import java.util.Map; import javax.naming.ConfigurationException; public class VRouterVifDriver extends VifDriverBase { - private static final Logger s_logger = Logger.getLogger(VRouterVifDriver.class); + protected Logger logger = LogManager.getLogger(getClass()); private String createTapDeviceScript; private String deleteTapDeviceScript; @@ -61,7 +62,7 @@ public class VRouterVifDriver extends VifDriverBase { final String tapDeviceName = TungstenUtils.getTapName(nic.getMac()); final String script = createTapDeviceScript; - final Script command = new Script(script, Duration.standardSeconds(300), s_logger); + final Script command = new Script(script, Duration.standardSeconds(300), logger); command.add(tapDeviceName); final String result = command.execute(); @@ -80,12 +81,12 @@ public class VRouterVifDriver extends VifDriverBase { final String tapDeviceName = TungstenUtils.getTapName(iface.getMacAddress()); final String script = deleteTapDeviceScript; - final Script command = new Script(script, Duration.standardSeconds(300), s_logger); + final Script command = new Script(script, Duration.standardSeconds(300), logger); command.add(tapDeviceName); final String result = command.execute(); if (result != null) { - s_logger.error("Failed to delete tap device " + tapDeviceName + ": " + result); + logger.error("Failed to delete tap device " + tapDeviceName + ": " + result); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/VifDriverBase.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/VifDriverBase.java index b3ae4c1d704..c227ca69453 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/VifDriverBase.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/VifDriverBase.java @@ -25,6 +25,8 @@ import javax.naming.ConfigurationException; import com.cloud.agent.properties.AgentProperties; import com.cloud.agent.properties.AgentPropertiesFileHandler; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.NicTO; @@ -32,6 +34,8 @@ import com.cloud.exception.InternalErrorException; public abstract class VifDriverBase implements VifDriver { + protected Logger logger = LogManager.getLogger(getClass()); + protected LibvirtComputingResource _libvirtComputingResource; protected Map _pifs; protected Map _bridges; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceAgentExecutor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceAgentExecutor.java index 7635b81b918..6ba3d510dd8 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceAgentExecutor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceAgentExecutor.java @@ -21,14 +21,12 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import org.joda.time.Duration; import java.io.File; public class RollingMaintenanceAgentExecutor extends RollingMaintenanceExecutorBase implements RollingMaintenanceExecutor { - private static final Logger s_logger = Logger.getLogger(RollingMaintenanceAgentExecutor.class); private String output; private boolean success; @@ -41,17 +39,17 @@ public class RollingMaintenanceAgentExecutor extends RollingMaintenanceExecutorB public Pair startStageExecution(String stage, File scriptFile, int timeout, String payload) { checkHooksDirectory(); Duration duration = Duration.standardSeconds(timeout); - final Script script = new Script(scriptFile.getAbsolutePath(), duration, s_logger); + final Script script = new Script(scriptFile.getAbsolutePath(), duration, logger); final OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); if (StringUtils.isNotEmpty(payload)) { script.add(payload); } - s_logger.info("Executing stage: " + stage + " script: " + script); + logger.info("Executing stage: " + stage + " script: " + script); output = script.execute(parser) + " " + parser.getLines(); if (script.isTimeout()) { String msg = "Script " + scriptFile + " timed out"; - s_logger.error(msg); + logger.error(msg); success = false; return new Pair<>(false, msg); } @@ -62,10 +60,10 @@ public class RollingMaintenanceAgentExecutor extends RollingMaintenanceExecutorB } success = exitValue == 0 || exitValue == exitValueAvoidMaintenance; setAvoidMaintenance(exitValue == exitValueAvoidMaintenance); - s_logger.info("Execution finished for stage: " + stage + " script: " + script + ": " + exitValue); - if (s_logger.isDebugEnabled()) { - s_logger.debug(output); - s_logger.debug("Stage " + stage + " execution finished: " + exitValue); + logger.info("Execution finished for stage: " + stage + " script: " + script + ": " + exitValue); + if (logger.isDebugEnabled()) { + logger.debug(output); + logger.debug("Stage " + stage + " execution finished: " + exitValue); } return new Pair<>(true, "Stage " + stage + " finished"); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceExecutorBase.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceExecutorBase.java index 70c8e1983d6..b74faca0ecf 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceExecutorBase.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceExecutorBase.java @@ -18,7 +18,8 @@ package com.cloud.hypervisor.kvm.resource.rolling.maintenance; import com.cloud.utils.exception.CloudRuntimeException; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import java.io.File; @@ -30,7 +31,7 @@ public abstract class RollingMaintenanceExecutorBase implements RollingMaintenan static final int exitValueAvoidMaintenance = 70; static final int exitValueTerminatedSignal = 143; - private static final Logger s_logger = Logger.getLogger(RollingMaintenanceExecutor.class); + protected Logger logger = LogManager.getLogger(getClass()); void setTimeout(int timeout) { this.timeout = timeout; @@ -66,7 +67,7 @@ public abstract class RollingMaintenanceExecutorBase implements RollingMaintenan return new File(scriptPath + ".py"); } else { String msg = "Unable to locate script for stage: " + stage + " in directory: " + hooksDir; - s_logger.warn(msg); + logger.warn(msg); return null; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceServiceExecutor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceServiceExecutor.java index bf8147ac853..c9edcc104b7 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceServiceExecutor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/rolling/maintenance/RollingMaintenanceServiceExecutor.java @@ -21,7 +21,6 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.File; import java.io.IOException; @@ -36,7 +35,6 @@ public class RollingMaintenanceServiceExecutor extends RollingMaintenanceExecuto private static final String resultsFileSuffix = "rolling-maintenance-results"; private static final String outputFileSuffix = "rolling-maintenance-output"; - private static final Logger s_logger = Logger.getLogger(RollingMaintenanceServiceExecutor.class); public RollingMaintenanceServiceExecutor(String hooksDir) { super(hooksDir); @@ -55,15 +53,15 @@ public class RollingMaintenanceServiceExecutor extends RollingMaintenanceExecuto } private String invokeService(String action, String stage, String file, String payload) { - s_logger.debug("Invoking rolling maintenance service for stage: " + stage + " and file " + file + " with action: " + action); + logger.debug("Invoking rolling maintenance service for stage: " + stage + " and file " + file + " with action: " + action); final OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); - Script command = new Script("/bin/systemctl", s_logger); + Script command = new Script("/bin/systemctl", logger); command.add(action); String service = servicePrefix + "@" + generateInstanceName(stage, file, payload); command.add(service); String result = command.execute(parser); int exitValue = command.getExitValue(); - s_logger.trace("Execution: " + command.toString() + " - exit code: " + exitValue + + logger.trace("Execution: " + command.toString() + " - exit code: " + exitValue + ": " + result + (StringUtils.isNotBlank(parser.getLines()) ? parser.getLines() : "")); return StringUtils.isBlank(result) ? parser.getLines().replace("\n", " ") : result; } @@ -76,7 +74,7 @@ public class RollingMaintenanceServiceExecutor extends RollingMaintenanceExecuto if (StringUtils.isNotBlank(result)) { throw new CloudRuntimeException("Error starting stage: " + stage + " execution: " + result); } - s_logger.trace("Stage " + stage + "execution started"); + logger.trace("Stage " + stage + "execution started"); return new Pair<>(true, "OK"); } @@ -111,7 +109,7 @@ public class RollingMaintenanceServiceExecutor extends RollingMaintenanceExecuto if (StringUtils.isNotBlank(result) && result.equals("failed")) { String status = invokeService("status", stage, scriptFile.getAbsolutePath(), payload); String errorMsg = "Stage " + stage + " execution failed, status: " + status; - s_logger.error(errorMsg); + logger.error(errorMsg); throw new CloudRuntimeException(errorMsg); } return StringUtils.isNotBlank(result) && result.equals("active"); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtBackupSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtBackupSnapshotCommandWrapper.java index 780fc35b563..656a63d3db0 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtBackupSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtBackupSnapshotCommandWrapper.java @@ -25,7 +25,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.text.MessageFormat; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; @@ -56,7 +55,6 @@ import static com.cloud.utils.NumbersUtil.toHumanReadableSize; @ResourceWrapper(handles = BackupSnapshotCommand.class) public final class LibvirtBackupSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtBackupSnapshotCommandWrapper.class); @Override public Answer execute(final BackupSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -104,7 +102,7 @@ public final class LibvirtBackupSnapshotCommandWrapper extends CommandWrapper { + + @Override + public Answer execute(CheckAndRepairVolumeCommand command, LibvirtComputingResource serverResource) { + final String volumeId = command.getPath(); + final String repair = command.getRepair(); + final StorageFilerTO spool = command.getPool(); + + final KVMStoragePoolManager storagePoolMgr = serverResource.getStoragePoolMgr(); + KVMStoragePool pool = storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid()); + final KVMPhysicalDisk vol = pool.getPhysicalDisk(volumeId); + byte[] passphrase = command.getPassphrase(); + + try { + CheckAndRepairVolumeAnswer answer = null; + String checkVolumeResult = null; + if (QemuImg.PhysicalDiskFormat.RAW.equals(vol.getFormat())) { + checkVolumeResult = "Volume format RAW is not supported to check and repair"; + String jsonStringFormat = String.format("{ \"message\": \"%s\" }", checkVolumeResult); + answer = new CheckAndRepairVolumeAnswer(command, true, checkVolumeResult); + answer.setVolumeCheckExecutionResult(jsonStringFormat); + + return answer; + } else { + answer = checkVolume(vol, command, serverResource); + checkVolumeResult = answer.getVolumeCheckExecutionResult(); + } + + CheckAndRepairVolumeAnswer resultAnswer = checkIfRepairLeaksIsRequired(command, checkVolumeResult, vol.getName()); + // resultAnswer is not null when repair is not required, so return from here + if (resultAnswer != null) { + return resultAnswer; + } + + if (StringUtils.isNotEmpty(repair)) { + answer = repairVolume(vol, command, serverResource, checkVolumeResult); + } + + return answer; + } catch (Exception e) { + return new CheckAndRepairVolumeAnswer(command, false, e.toString()); + } finally { + if (passphrase != null) { + Arrays.fill(passphrase, (byte) 0); + } + } + } + + private CheckAndRepairVolumeAnswer checkVolume(KVMPhysicalDisk vol, CheckAndRepairVolumeCommand command, LibvirtComputingResource serverResource) { + EncryptFormat encryptFormat = EncryptFormat.enumValue(command.getEncryptFormat()); + byte[] passphrase = command.getPassphrase(); + String checkVolumeResult = checkAndRepairVolume(vol, null, encryptFormat, passphrase, serverResource); + logger.info(String.format("Check Volume result for the volume %s is %s", vol.getName(), checkVolumeResult)); + CheckAndRepairVolumeAnswer answer = new CheckAndRepairVolumeAnswer(command, true, checkVolumeResult); + answer.setVolumeCheckExecutionResult(checkVolumeResult); + + return answer; + } + + private CheckAndRepairVolumeAnswer repairVolume(KVMPhysicalDisk vol, CheckAndRepairVolumeCommand command, LibvirtComputingResource serverResource, String checkVolumeResult) { + EncryptFormat encryptFormat = EncryptFormat.enumValue(command.getEncryptFormat()); + byte[] passphrase = command.getPassphrase(); + final String repair = command.getRepair(); + + String repairVolumeResult = checkAndRepairVolume(vol, repair, encryptFormat, passphrase, serverResource); + String finalResult = (checkVolumeResult != null ? checkVolumeResult.concat(",") : "") + repairVolumeResult; + logger.info(String.format("Repair Volume result for the volume %s is %s", vol.getName(), repairVolumeResult)); + + CheckAndRepairVolumeAnswer answer = new CheckAndRepairVolumeAnswer(command, true, finalResult); + answer.setVolumeRepairExecutionResult(repairVolumeResult); + answer.setVolumeCheckExecutionResult(checkVolumeResult); + + return answer; + } + + private CheckAndRepairVolumeAnswer checkIfRepairLeaksIsRequired(CheckAndRepairVolumeCommand command, String checkVolumeResult, String volumeName) { + final String repair = command.getRepair(); + int leaks = 0; + if (StringUtils.isNotEmpty(checkVolumeResult) && StringUtils.isNotEmpty(repair) && repair.equals("leaks")) { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = null; + try { + jsonNode = objectMapper.readTree(checkVolumeResult); + } catch (JsonProcessingException e) { + String msg = String.format("Error processing response %s during check volume %s", checkVolumeResult, e.getMessage()); + logger.info(msg); + + return skipRepairVolumeCommand(command, checkVolumeResult, msg); + } + JsonNode leaksNode = jsonNode.get("leaks"); + if (leaksNode != null) { + leaks = leaksNode.asInt(); + } + + if (leaks == 0) { + String msg = String.format("No leaks found while checking for the volume %s, so skipping repair", volumeName); + return skipRepairVolumeCommand(command, checkVolumeResult, msg); + } + } + + return null; + } + + private CheckAndRepairVolumeAnswer skipRepairVolumeCommand(CheckAndRepairVolumeCommand command, String checkVolumeResult, String msg) { + logger.info(msg); + String jsonStringFormat = String.format("{ \"message\": \"%s\" }", msg); + String finalResult = (checkVolumeResult != null ? checkVolumeResult.concat(",") : "") + jsonStringFormat; + CheckAndRepairVolumeAnswer answer = new CheckAndRepairVolumeAnswer(command, true, finalResult); + answer.setVolumeRepairExecutionResult(jsonStringFormat); + answer.setVolumeCheckExecutionResult(checkVolumeResult); + + return answer; + } + + protected String checkAndRepairVolume(final KVMPhysicalDisk vol, final String repair, final EncryptFormat encryptFormat, byte[] passphrase, final LibvirtComputingResource libvirtComputingResource) throws CloudRuntimeException { + List passphraseObjects = new ArrayList<>(); + QemuImageOptions imgOptions = null; + if (ArrayUtils.isEmpty(passphrase)) { + passphrase = null; + } + try (KeyFile keyFile = new KeyFile(passphrase)) { + if (passphrase != null) { + passphraseObjects.add( + QemuObject.prepareSecretForQemuImg(vol.getFormat(), encryptFormat, keyFile.toString(), "sec0", null) + ); + imgOptions = new QemuImageOptions(vol.getFormat(), vol.getPath(),"sec0"); + } + QemuImg q = new QemuImg(libvirtComputingResource.getCmdsTimeout()); + QemuImgFile file = new QemuImgFile(vol.getPath()); + return q.checkAndRepair(file, imgOptions, passphraseObjects, repair); + } catch (QemuImgException | LibvirtException ex) { + throw new CloudRuntimeException("Failed to run qemu-img for check volume", ex); + } catch (IOException ex) { + throw new CloudRuntimeException("Failed to create keyfile for encrypted volume for check volume operation", ex); + } + } +} diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckSshCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckSshCommandWrapper.java index a04ddecd250..d41cd63fa4e 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckSshCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCheckSshCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.check.CheckSshAnswer; @@ -32,7 +31,6 @@ import com.cloud.resource.ResourceWrapper; @ResourceWrapper(handles = CheckSshCommand.class) public final class LibvirtCheckSshCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.class); @Override public Answer execute(final CheckSshCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -40,8 +38,8 @@ public final class LibvirtCheckSshCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCheckStorageAvailabilityWrapper.class); @Override public Answer execute(CheckStorageAvailabilityCommand command, LibvirtComputingResource resource) { @@ -44,15 +42,15 @@ public class LibvirtCheckStorageAvailabilityWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCheckUrlCommand.class); @Override public CheckUrlAnswer execute(CheckUrlCommand cmd, LibvirtComputingResource serverResource) { @@ -39,14 +37,14 @@ public class LibvirtCheckUrlCommand extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCheckVolumeCommandWrapper.class); - @Override public Answer execute(final CheckVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { String result = null; @@ -64,7 +61,7 @@ public final class LibvirtCheckVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCleanupPersistentNetworkResourceCommandWrapper.class); @Override public Answer execute(CleanupPersistentNetworkResourceCommand command, LibvirtComputingResource serverResource) { NicTO nic = command.getNicTO(); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConsoleProxyLoadCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConsoleProxyLoadCommandWrapper.java index 1a2f7cb20b6..ecfa062ed88 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConsoleProxyLoadCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConsoleProxyLoadCommandWrapper.java @@ -26,7 +26,6 @@ import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; @@ -36,7 +35,6 @@ import com.cloud.resource.ServerResource; public abstract class LibvirtConsoleProxyLoadCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtConsoleProxyLoadCommandWrapper.class); public Answer executeProxyLoadScan(final Command cmd, final long proxyVmId, final String proxyVmName, final String proxyManagementIp, final int cmdPort) { String result = null; @@ -64,12 +62,12 @@ public abstract class LibvirtConsoleProxyLoadCommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtConvertInstanceCommandWrapper.class); - private static final List supportedInstanceConvertSourceHypervisors = List.of(Hypervisor.HypervisorType.VMware); @@ -80,7 +77,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper getTemporaryDisksWithPrefixFromTemporaryPool(KVMStoragePool pool, String path, String prefix) { String msg = String.format("Could not parse correctly the converted XML domain, checking for disks on %s with prefix %s", path, prefix); - s_logger.info(msg); + logger.info(msg); pool.refresh(); List disksWithPrefix = pool.listPhysicalDisks() .stream() @@ -190,7 +187,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper %s", password, passwordFile)); return passwordFile; } @@ -377,7 +374,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCopyRemoteVolumeCommandWrapper.class); - @Override public Answer execute(final CopyRemoteVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { String result = null; @@ -61,7 +58,7 @@ public final class LibvirtCopyRemoteVolumeCommandWrapper extends CommandWrapper< if (storageFilerTO.getType() == Storage.StoragePoolType.Filesystem || storageFilerTO.getType() == Storage.StoragePoolType.NetworkFilesystem) { String filename = libvirtComputingResource.copyVolume(srcIp, username, password, dstPath, srcFile, tmpPath); - s_logger.debug("Volume Copy Successful"); + logger.debug("Volume Copy Successful"); final KVMPhysicalDisk vol = pool.getPhysicalDisk(filename); final String path = vol.getPath(); long size = getVirtualSizeFromFile(path); @@ -71,7 +68,7 @@ public final class LibvirtCopyRemoteVolumeCommandWrapper extends CommandWrapper< } } catch (final Exception e) { - s_logger.error("Error while copying file from remote host: "+ e.getMessage()); + logger.error("Error while copying file from remote host: "+ e.getMessage()); return new Answer(command, false, result); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyToSecondaryStorageWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyToSecondaryStorageWrapper.java index a6baa1c1785..a8ea0d2ce81 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyToSecondaryStorageWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCopyToSecondaryStorageWrapper.java @@ -25,7 +25,6 @@ import java.nio.file.Paths; import org.apache.cloudstack.diagnostics.CopyToSecondaryStorageAnswer; import org.apache.cloudstack.diagnostics.CopyToSecondaryStorageCommand; import org.apache.cloudstack.diagnostics.DiagnosticsService; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; @@ -37,7 +36,6 @@ import com.cloud.utils.ssh.SshHelper; @ResourceWrapper(handles = CopyToSecondaryStorageCommand.class) public class LibvirtCopyToSecondaryStorageWrapper extends CommandWrapper { - public static final Logger LOGGER = Logger.getLogger(LibvirtCopyToSecondaryStorageWrapper.class); @Override public Answer execute(CopyToSecondaryStorageCommand command, LibvirtComputingResource libvirtResource) { @@ -64,7 +62,7 @@ public class LibvirtCopyToSecondaryStorageWrapper extends CommandWrapper { - private static final Logger LOGGER = Logger.getLogger(LibvirtCopyVolumeCommandWrapper.class); @Override public Answer execute(final CopyVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -164,7 +162,7 @@ public final class LibvirtCopyVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCreateCommandWrapper.class); @Override public Answer execute(final CreateCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -80,7 +78,7 @@ public final class LibvirtCreateCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper.class); @Override public Answer execute(final CreatePrivateTemplateFromSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -80,7 +78,7 @@ public final class LibvirtCreatePrivateTemplateFromSnapshotCommandWrapper extend final String createTmplPath = libvirtComputingResource.createTmplPath(); final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout(); - final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, s_logger); + final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, logger); scriptCommand.add("-t", templatePath); scriptCommand.add("-n", tmplFileName); scriptCommand.add("-f", snapshot.getPath()); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.java index 4a7aae51202..de35a1251bb 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.utils.qemu.QemuImg; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand; @@ -60,7 +59,6 @@ import org.libvirt.LibvirtException; @ResourceWrapper(handles = CreatePrivateTemplateFromVolumeCommand.class) public final class LibvirtCreatePrivateTemplateFromVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCreatePrivateTemplateFromVolumeCommandWrapper.class); @Override public Answer execute(final CreatePrivateTemplateFromVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -96,7 +94,7 @@ public final class LibvirtCreatePrivateTemplateFromVolumeCommandWrapper extends final String createTmplPath = libvirtComputingResource.createTmplPath(); final int cmdsTimeout = libvirtComputingResource.getCmdsTimeout(); - final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, s_logger); + final Script scriptCommand = new Script(createTmplPath, cmdsTimeout, logger); scriptCommand.add("-f", disk.getPath()); scriptCommand.add("-t", tmpltPath); scriptCommand.add("-n", command.getUniqueName() + ".qcow2"); @@ -104,11 +102,11 @@ public final class LibvirtCreatePrivateTemplateFromVolumeCommandWrapper extends final String result = scriptCommand.execute(); if (result != null) { - s_logger.debug("failed to create template: " + result); + logger.debug("failed to create template: " + result); return new CreatePrivateTemplateAnswer(command, false, result); } } else { - s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + command.getUniqueName()); + logger.debug("Converting RBD disk " + disk.getPath() + " into template " + command.getUniqueName()); final QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(), primary.getSourcePort(), primary.getAuthUserName(), @@ -122,7 +120,7 @@ public final class LibvirtCreatePrivateTemplateFromVolumeCommandWrapper extends final QemuImg q = new QemuImg(0); q.convert(srcFile, destFile); } catch (final QemuImgException | LibvirtException e) { - s_logger.error("Failed to create new template while converting " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + + logger.error("Failed to create new template while converting " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); } @@ -142,7 +140,7 @@ public final class LibvirtCreatePrivateTemplateFromVolumeCommandWrapper extends templFo.flush(); }catch(final IOException ex) { - s_logger.error("CreatePrivateTemplateAnswer:Exception:"+ex.getMessage()); + logger.error("CreatePrivateTemplateAnswer:Exception:"+ex.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateVMSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateVMSnapshotCommandWrapper.java index c7941e7fc89..7cada635a04 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCreateVMSnapshotCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; @@ -35,7 +34,6 @@ import com.cloud.resource.ResourceWrapper; @ResourceWrapper(handles = CreateVMSnapshotCommand.class) public final class LibvirtCreateVMSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtCreateVMSnapshotCommandWrapper.class); @Override public Answer execute(final CreateVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -67,14 +65,14 @@ public final class LibvirtCreateVMSnapshotCommandWrapper extends CommandWrapper< return new CreateVMSnapshotAnswer(cmd, cmd.getTarget(), cmd.getVolumeTOs()); } catch (LibvirtException e) { String msg = " Create VM snapshot failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new CreateVMSnapshotAnswer(cmd, false, msg); } finally { if (dm != null) { try { dm.free(); } catch (LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); }; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java index 5b55db24f4d..45b0c179938 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDeleteVMSnapshotCommandWrapper.java @@ -21,7 +21,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo; @@ -43,7 +42,6 @@ import com.cloud.utils.script.Script; @ResourceWrapper(handles = DeleteVMSnapshotCommand.class) public final class LibvirtDeleteVMSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtDeleteVMSnapshotCommandWrapper.class); @Override public Answer execute(final DeleteVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -64,7 +62,7 @@ public final class LibvirtDeleteVMSnapshotCommandWrapper extends CommandWrapper< oldState = dm.getInfo().state; if (oldState == DomainInfo.DomainState.VIR_DOMAIN_RUNNING) { - s_logger.debug("Suspending domain " + vmName); + logger.debug("Suspending domain " + vmName); dm.suspend(); // suspend the vm to avoid image corruption } @@ -84,7 +82,7 @@ public final class LibvirtDeleteVMSnapshotCommandWrapper extends CommandWrapper< String msg = " Delete VM snapshot failed due to " + e.toString(); if (dm == null) { - s_logger.debug("Can not find running vm: " + vmName + ", now we are trying to delete the vm snapshot using qemu-img if the format of root volume is QCOW2"); + logger.debug("Can not find running vm: " + vmName + ", now we are trying to delete the vm snapshot using qemu-img if the format of root volume is QCOW2"); VolumeObjectTO rootVolume = null; for (VolumeObjectTO volume: cmd.getVolumeTOs()) { if (volume.getVolumeType() == Volume.Type.ROOT) { @@ -98,7 +96,7 @@ public final class LibvirtDeleteVMSnapshotCommandWrapper extends CommandWrapper< primaryStore.getUuid(), rootVolume.getPath()); String qemu_img_snapshot = Script.runSimpleBashScript("qemu-img snapshot -l " + rootDisk.getPath() + " | tail -n +3 | awk -F ' ' '{print $2}' | grep ^" + cmd.getTarget().getSnapshotName() + "$"); if (qemu_img_snapshot == null) { - s_logger.info("Cannot find snapshot " + cmd.getTarget().getSnapshotName() + " in file " + rootDisk.getPath() + ", return true"); + logger.info("Cannot find snapshot " + cmd.getTarget().getSnapshotName() + " in file " + rootDisk.getPath() + ", return true"); return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs()); } int result = Script.runSimpleBashScriptForExitValue("qemu-img snapshot -d " + cmd.getTarget().getSnapshotName() + " " + rootDisk.getPath()); @@ -110,14 +108,14 @@ public final class LibvirtDeleteVMSnapshotCommandWrapper extends CommandWrapper< } } } else if (snapshot == null) { - s_logger.debug("Can not find vm snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + ", return true"); + logger.debug("Can not find vm snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + ", return true"); return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs()); } else if (tryingResume) { - s_logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e); + logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e); return new DeleteVMSnapshotAnswer(cmd, cmd.getVolumeTOs()); } - s_logger.warn(msg, e); + logger.warn(msg, e); return new DeleteVMSnapshotAnswer(cmd, false, msg); } finally { if (dm != null) { @@ -125,12 +123,12 @@ public final class LibvirtDeleteVMSnapshotCommandWrapper extends CommandWrapper< try { dm = libvirtComputingResource.getDomain(conn, vmName); if (oldState == DomainInfo.DomainState.VIR_DOMAIN_RUNNING && dm.getInfo().state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) { - s_logger.debug("Resuming domain " + vmName); + logger.debug("Resuming domain " + vmName); dm.resume(); } dm.free(); } catch (LibvirtException e) { - s_logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e); + logger.error("Failed to resume vm after delete snapshot " + cmd.getTarget().getSnapshotName() + " on vm: " + vmName + " return true : " + e); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDestroyCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDestroyCommandWrapper.java index 361d194189e..b9106cec42f 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDestroyCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtDestroyCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.storage.DestroyCommand; @@ -34,7 +33,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @ResourceWrapper(handles = DestroyCommand.class) public final class LibvirtDestroyCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtDestroyCommandWrapper.class); @Override public Answer execute(final DestroyCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -45,7 +43,7 @@ public final class LibvirtDestroyCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtFenceCommandWrapper.class); @Override public Answer execute(final FenceCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -56,7 +54,7 @@ public final class LibvirtFenceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtFreezeThawVMCommandWrapper.class); @Override public Answer execute(FreezeThawVMCommand command, LibvirtComputingResource serverResource) { @@ -60,13 +58,13 @@ public class LibvirtFreezeThawVMCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetHostStatsCommandWrapper.class); @Override public Answer execute(final GetHostStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetRemoteVmsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetRemoteVmsCommandWrapper.java index 700f058b59b..ead294ad05f 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetRemoteVmsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetRemoteVmsCommandWrapper.java @@ -32,7 +32,6 @@ import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine; import org.apache.cloudstack.vm.UnmanagedInstanceTO; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainBlockInfo; @@ -46,8 +45,6 @@ import java.util.List; @ResourceWrapper(handles = GetRemoteVmsCommand.class) public final class LibvirtGetRemoteVmsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetRemoteVmsCommandWrapper.class); - @Override public Answer execute(final GetRemoteVmsCommand command, final LibvirtComputingResource libvirtComputingResource) { String result = null; @@ -64,22 +61,22 @@ public final class LibvirtGetRemoteVmsCommandWrapper extends CommandWrapper { - private static final Logger LOGGER = Logger.getLogger(LibvirtGetUnmanagedInstancesCommandWrapper.class); + + private static final int requiredVncPasswordLength = 22; @Override public GetUnmanagedInstancesAnswer execute(GetUnmanagedInstancesCommand command, LibvirtComputingResource libvirtComputingResource) { - LOGGER.info("Fetching unmanaged instance on host"); + logger.info("Fetching unmanaged instance on host"); HashMap unmanagedInstances = new HashMap<>(); try { @@ -65,7 +63,7 @@ public final class LibvirtGetUnmanagedInstancesCommandWrapper extends CommandWra } } catch (Exception e) { String err = String.format("Error listing unmanaged instances: %s", e.getMessage()); - LOGGER.error(err, e); + logger.error(err, e); return new GetUnmanagedInstancesAnswer(command, err); } @@ -81,7 +79,7 @@ public final class LibvirtGetUnmanagedInstancesCommandWrapper extends CommandWra final Domain domain = libvirtComputingResource.getDomain(conn, vmNameCmd); if (domain == null) { String msg = String.format("VM %s not found", vmNameCmd); - LOGGER.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } @@ -104,14 +102,14 @@ public final class LibvirtGetUnmanagedInstancesCommandWrapper extends CommandWra private void checkIfVmExists(String vmNameCmd,final Domain domain) throws LibvirtException { if (StringUtils.isNotEmpty(vmNameCmd) && !vmNameCmd.equals(domain.getName())) { - LOGGER.error("GetUnmanagedInstancesCommand: exact vm name not found " + vmNameCmd); + logger.error("GetUnmanagedInstancesCommand: exact vm name not found " + vmNameCmd); throw new CloudRuntimeException("GetUnmanagedInstancesCommand: exact vm name not found " + vmNameCmd); } } private void checkIfVmIsManaged(GetUnmanagedInstancesCommand command,String vmNameCmd,final Domain domain) throws LibvirtException { if (command.hasManagedInstance(domain.getName())) { - LOGGER.error("GetUnmanagedInstancesCommand: vm already managed " + vmNameCmd); + logger.error("GetUnmanagedInstancesCommand: vm already managed " + vmNameCmd); throw new CloudRuntimeException("GetUnmanagedInstancesCommand: vm already managed " + vmNameCmd); } } @@ -132,16 +130,24 @@ public final class LibvirtGetUnmanagedInstancesCommandWrapper extends CommandWra instance.setPowerState(getPowerState(libvirtComputingResource.getVmState(conn,domain.getName()))); instance.setMemory((int) LibvirtComputingResource.getDomainMemory(domain) / 1024); instance.setNics(getUnmanagedInstanceNics(parser.getInterfaces())); - instance.setDisks(getUnmanagedInstanceDisks(parser.getDisks(),libvirtComputingResource)); - instance.setVncPassword(parser.getVncPasswd() + "aaaaaaaaaaaaaa"); // Suffix back extra characters for DB compatibility + instance.setDisks(getUnmanagedInstanceDisks(parser.getDisks(),libvirtComputingResource, conn, domain.getName())); + instance.setVncPassword(getFormattedVncPassword(parser.getVncPasswd())); return instance; } catch (Exception e) { - LOGGER.info("Unable to retrieve unmanaged instance info. " + e.getMessage(), e); + logger.info("Unable to retrieve unmanaged instance info. " + e.getMessage(), e); return null; } } + protected String getFormattedVncPassword(String vncPasswd) { + if (StringUtils.isBlank(vncPasswd)) { + return null; + } + String randomChars = RandomStringUtils.random(requiredVncPasswordLength - vncPasswd.length(), true, false); + return String.format("%s%s", vncPasswd, randomChars); + } + private UnmanagedInstanceTO.PowerState getPowerState(VirtualMachine.PowerState vmPowerState) { switch (vmPowerState) { case PowerOn: @@ -170,7 +176,7 @@ public final class LibvirtGetUnmanagedInstancesCommandWrapper extends CommandWra return nics; } - private List getUnmanagedInstanceDisks(List disksInfo, LibvirtComputingResource libvirtComputingResource){ + private List getUnmanagedInstanceDisks(List disksInfo, LibvirtComputingResource libvirtComputingResource, Connect conn, String domainName) { final ArrayList disks = new ArrayList<>(disksInfo.size()); int counter = 0; for (LibvirtVMDef.DiskDef diskDef : disksInfo) { @@ -180,14 +186,11 @@ public final class LibvirtGetUnmanagedInstancesCommandWrapper extends CommandWra final UnmanagedInstanceTO.Disk disk = new UnmanagedInstanceTO.Disk(); Long size = null; - String imagePath = null; try { - QemuImgFile file = new QemuImgFile(diskDef.getSourcePath()); - QemuImg qemu = new QemuImg(0); - Map info = qemu.info(file); - size = Long.parseLong(info.getOrDefault("virtual_size", "0")); - imagePath = info.getOrDefault("image", null); - } catch (QemuImgException | LibvirtException e) { + Domain dm = conn.domainLookupByName(domainName); + DomainBlockInfo blockInfo = dm.blockInfo(diskDef.getDiskLabel()); + size = blockInfo.getCapacity(); + } catch (LibvirtException e) { throw new RuntimeException(e); } @@ -197,25 +200,44 @@ public final class LibvirtGetUnmanagedInstancesCommandWrapper extends CommandWra disk.setLabel(diskDef.getDiskLabel()); disk.setController(diskDef.getBusType().toString()); - Pair sourceHostPath = getSourceHostPath(libvirtComputingResource, diskDef.getSourcePath()); if (sourceHostPath != null) { disk.setDatastoreHost(sourceHostPath.first()); disk.setDatastorePath(sourceHostPath.second()); } else { - disk.setDatastorePath(diskDef.getSourcePath()); + int pathEnd = diskDef.getSourcePath().lastIndexOf("/"); + if (pathEnd >= 0) { + disk.setDatastorePath(diskDef.getSourcePath().substring(0, pathEnd)); + } else { + disk.setDatastorePath(diskDef.getSourcePath()); + } disk.setDatastoreHost(diskDef.getSourceHost()); } disk.setDatastoreType(diskDef.getDiskType().toString()); disk.setDatastorePort(diskDef.getSourceHostPort()); - disk.setImagePath(imagePath); - disk.setDatastoreName(imagePath.substring(imagePath.lastIndexOf("/"))); + disk.setImagePath(diskDef.getSourcePath()); + disk.setDatastoreName(disk.getDatastorePath()); + disk.setFileBaseName(getDiskRelativePath(diskDef)); disks.add(disk); } return disks; } + protected String getDiskRelativePath(LibvirtVMDef.DiskDef diskDef) { + if (diskDef == null || diskDef.getDiskType() == null || diskDef.getDiskType() == LibvirtVMDef.DiskDef.DiskType.BLOCK) { + return null; + } + String sourcePath = diskDef.getSourcePath(); + if (StringUtils.isBlank(sourcePath)) { + return null; + } + if (!sourcePath.contains("/")) { + return sourcePath; + } + return sourcePath.substring(sourcePath.lastIndexOf("/") + 1); + } + private Pair getSourceHostPath(LibvirtComputingResource libvirtComputingResource, String diskPath) { int pathEnd = diskPath.lastIndexOf("/"); if (pathEnd >= 0) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmDiskStatsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmDiskStatsCommandWrapper.java index 6316be9fbf3..6edd667ddcc 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmDiskStatsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmDiskStatsCommandWrapper.java @@ -22,7 +22,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -37,7 +36,6 @@ import com.cloud.resource.ResourceWrapper; @ResourceWrapper(handles = GetVmDiskStatsCommand.class) public final class LibvirtGetVmDiskStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmDiskStatsCommandWrapper.class); @Override public Answer execute(final GetVmDiskStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -56,12 +54,12 @@ public final class LibvirtGetVmDiskStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmIpAddressCommandWrapper.class); @Override public Answer execute(final GetVmIpAddressCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -53,7 +51,7 @@ public final class LibvirtGetVmIpAddressCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmNetworkStatsCommandWrapper.class); @Override public Answer execute(final GetVmNetworkStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -56,12 +54,12 @@ public final class LibvirtGetVmNetworkStatsCommandWrapper extends CommandWrapper vmNetworkStatsNameMap.put(vmName, statEntry); } catch (LibvirtException e) { - s_logger.warn("Can't get vm network stats: " + e.toString() + ", continue"); + logger.warn("Can't get vm network stats: " + e.toString() + ", continue"); } } return new GetVmNetworkStatsAnswer(command, "", command.getHostName(), vmNetworkStatsNameMap); } catch (final LibvirtException e) { - s_logger.debug("Can't get vm network stats: " + e.toString()); + logger.debug("Can't get vm network stats: " + e.toString()); return new GetVmNetworkStatsAnswer(command, null, null, null); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmStatsCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmStatsCommandWrapper.java index 24853d0a2e8..834b0e834df 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmStatsCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtGetVmStatsCommandWrapper.java @@ -22,7 +22,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; import java.util.HashMap; import java.util.List; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -37,7 +36,6 @@ import com.cloud.resource.ResourceWrapper; @ResourceWrapper(handles = GetVmStatsCommand.class) public final class LibvirtGetVmStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmStatsCommandWrapper.class); @Override public Answer execute(final GetVmStatsCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -57,12 +55,12 @@ public final class LibvirtGetVmStatsCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtGetVmDiskStatsCommandWrapper.class); @Override public Answer execute(final GetVolumeStatsCommand cmd, final LibvirtComputingResource libvirtComputingResource) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java index 3d2f7282b06..135d447fbb2 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java @@ -25,7 +25,6 @@ import java.nio.file.Paths; import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder; import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.HandleConfigDriveIsoAnswer; @@ -42,7 +41,6 @@ import com.cloud.utils.exception.CloudRuntimeException; @ResourceWrapper(handles = HandleConfigDriveIsoCommand.class) public final class LibvirtHandleConfigDriveCommandWrapper extends CommandWrapper { - private static final Logger LOG = Logger.getLogger(LibvirtHandleConfigDriveCommandWrapper.class); @Override public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -50,11 +48,11 @@ public final class LibvirtHandleConfigDriveCommandWrapper extends CommandWrapper try { if (command.isCreate()) { - LOG.debug("Creating config drive: " + command.getIsoFile()); + logger.debug("Creating config drive: " + command.getIsoFile()); NetworkElement.Location location = NetworkElement.Location.PRIMARY; if (command.isHostCachePreferred()) { - LOG.debug("Using the KVM host for config drive"); + logger.debug("Using the KVM host for config drive"); mountPoint = libvirtComputingResource.getConfigPath(); location = NetworkElement.Location.HOST; } else { @@ -79,14 +77,14 @@ public final class LibvirtHandleConfigDriveCommandWrapper extends CommandWrapper } if (pool.supportsConfigDriveIso()) { - LOG.debug("Using the pool: " + poolUuid + " for config drive"); + logger.debug("Using the pool: " + poolUuid + " for config drive"); mountPoint = pool.getLocalPath(); } else if (command.getUseHostCacheOnUnsupportedPool()) { - LOG.debug("Config drive for KVM is not supported for pool type: " + poolType.toString() + ", using the KVM host"); + logger.debug("Config drive for KVM is not supported for pool type: " + poolType.toString() + ", using the KVM host"); mountPoint = libvirtComputingResource.getConfigPath(); location = NetworkElement.Location.HOST; } else { - LOG.debug("Config drive for KVM is not supported for pool type: " + poolType.toString()); + logger.debug("Config drive for KVM is not supported for pool type: " + poolType.toString()); return new HandleConfigDriveIsoAnswer(command, "Config drive for KVM is not supported for pool type: " + poolType.toString()); } } @@ -98,7 +96,7 @@ public final class LibvirtHandleConfigDriveCommandWrapper extends CommandWrapper return new HandleConfigDriveIsoAnswer(command, "Invalid config drive ISO data received"); } if (isoFile.exists()) { - LOG.debug("An old config drive iso already exists"); + logger.debug("An old config drive iso already exists"); } Files.createDirectories(isoPath.getParent()); @@ -106,7 +104,7 @@ public final class LibvirtHandleConfigDriveCommandWrapper extends CommandWrapper return new HandleConfigDriveIsoAnswer(command, location); } else { - LOG.debug("Deleting config drive: " + command.getIsoFile()); + logger.debug("Deleting config drive: " + command.getIsoFile()); Path configDrivePath = null; if (command.isHostCachePreferred()) { @@ -138,10 +136,10 @@ public final class LibvirtHandleConfigDriveCommandWrapper extends CommandWrapper return new HandleConfigDriveIsoAnswer(command); } } catch (final IOException e) { - LOG.debug("Failed to handle config drive due to " + e.getMessage(), e); + logger.debug("Failed to handle config drive due to " + e.getMessage(), e); return new HandleConfigDriveIsoAnswer(command, "Failed due to exception: " + e.getMessage()); } catch (final CloudRuntimeException e) { - LOG.debug("Failed to handle config drive due to " + e.getMessage(), e); + logger.debug("Failed to handle config drive due to " + e.getMessage(), e); return new HandleConfigDriveIsoAnswer(command, "Failed due to exception: " + e.toString()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtManageSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtManageSnapshotCommandWrapper.java index 0e2492c146f..ec900e9981e 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtManageSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtManageSnapshotCommandWrapper.java @@ -22,7 +22,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; import java.io.File; import java.text.MessageFormat; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo.DomainState; @@ -49,7 +48,6 @@ import com.cloud.utils.script.Script; @ResourceWrapper(handles = ManageSnapshotCommand.class) public final class LibvirtManageSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtManageSnapshotCommandWrapper.class); @Override public Answer execute(final ManageSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -66,7 +64,7 @@ public final class LibvirtManageSnapshotCommandWrapper extends CommandWrapper vlanToPersistenceMap = command.getVlanToPersistenceMap(); final String destinationUri = createMigrationURI(command.getDestinationIp(), libvirtComputingResource); final List migrateDiskInfoList = command.getMigrateDiskInfoList(); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Trying to migrate VM [%s] to destination host: [%s].", vmName, destinationUri)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Trying to migrate VM [%s] to destination host: [%s].", vmName, destinationUri)); } String result = null; @@ -127,8 +125,8 @@ public final class LibvirtMigrateCommandWrapper extends CommandWrapper dpdkPortsMapping = command.getDpdkInterfaceMapping(); if (MapUtils.isNotEmpty(dpdkPortsMapping)) { - if (s_logger.isTraceEnabled()) { - s_logger.trace(String.format("Changing VM [%s] DPDK interfaces during migration to host: [%s].", vmName, target)); + if (logger.isTraceEnabled()) { + logger.trace(String.format("Changing VM [%s] DPDK interfaces during migration to host: [%s].", vmName, target)); } xmlDesc = replaceDpdkInterfaces(xmlDesc, dpdkPortsMapping); - if (s_logger.isDebugEnabled()) { - s_logger.debug(String.format("Changed VM [%s] XML configuration of DPDK interfaces. New XML configuration is [%s].", vmName, xmlDesc)); + if (logger.isDebugEnabled()) { + logger.debug(String.format("Changed VM [%s] XML configuration of DPDK interfaces. New XML configuration is [%s].", vmName, xmlDesc)); } } @@ -221,7 +219,7 @@ public final class LibvirtMigrateCommandWrapper extends CommandWrapper { - private static final Logger LOGGER = Logger.getLogger(LibvirtMigrateVolumeCommandWrapper.class); @Override public Answer execute(final MigrateVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -139,18 +137,18 @@ public class LibvirtMigrateVolumeCommandWrapper extends CommandWrapper 0) { DomainBlockJobInfo blockJobInfo = dm.getBlockJobInfo(diskLabel, 0); if (blockJobInfo != null) { - LOGGER.debug(String.format("Volume %s : %s block copy progress: %s%% current value:%s end value:%s", diskLabel, srcPath, (blockJobInfo.end == 0)? 0 : 100*(blockJobInfo.cur / (double) blockJobInfo.end), blockJobInfo.cur, blockJobInfo.end)); + logger.debug(String.format("Volume %s : %s block copy progress: %s%% current value:%s end value:%s", diskLabel, srcPath, (blockJobInfo.end == 0)? 0 : 100*(blockJobInfo.cur / (double) blockJobInfo.end), blockJobInfo.cur, blockJobInfo.end)); if (blockJobInfo.cur == blockJobInfo.end) { - LOGGER.info(String.format("Block copy completed for the volume %s : %s", diskLabel, srcPath)); + logger.info(String.format("Block copy completed for the volume %s : %s", diskLabel, srcPath)); dm.blockJobAbort(diskLabel, Domain.BlockJobAbortFlags.PIVOT); if (StringUtils.isNotEmpty(srcSecretUUID)) { libvirtComputingResource.removeLibvirtVolumeSecret(conn, srcSecretUUID); @@ -181,7 +179,7 @@ public class LibvirtMigrateVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtModifySshKeysCommandWrapper.class); @Override public Answer execute(final ModifySshKeysCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -52,13 +50,13 @@ public final class LibvirtModifySshKeysCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtModifyTargetsCommandWrapper.class); @Override public Answer execute(final ModifyTargetsCommand command, final LibvirtComputingResource libvirtComputingResource) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesSystemVmCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesSystemVmCommandWrapper.java index 65169a3f23d..b5ee13920a6 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesSystemVmCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesSystemVmCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -32,7 +31,6 @@ import com.cloud.resource.ResourceWrapper; @ResourceWrapper(handles = NetworkRulesSystemVmCommand.class) public final class LibvirtNetworkRulesSystemVmCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.class); @Override public Answer execute(final NetworkRulesSystemVmCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -43,7 +41,7 @@ public final class LibvirtNetworkRulesSystemVmCommandWrapper extends CommandWrap final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName()); success = libvirtComputingResource.configureDefaultNetworkRulesForSystemVm(conn, command.getVmName()); } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + logger.trace("Ignoring libvirt error.", e); } return new Answer(command, success, ""); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java index 07c091ee0ee..890558ca365 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtNetworkRulesVmSecondaryIpCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -32,7 +31,6 @@ import com.cloud.resource.ResourceWrapper; @ResourceWrapper(handles = NetworkRulesVmSecondaryIpCommand.class) public final class LibvirtNetworkRulesVmSecondaryIpCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.class); @Override public Answer execute(final NetworkRulesVmSecondaryIpCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -43,7 +41,7 @@ public final class LibvirtNetworkRulesVmSecondaryIpCommandWrapper extends Comman final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName()); result = libvirtComputingResource.configureNetworkRulesVMSecondaryIP(conn, command.getVmName(), command.getVmMac(), command.getVmSecIp(), command.getAction()); } catch (final LibvirtException e) { - s_logger.debug("Could not configure VM secondary IP! => " + e.getLocalizedMessage()); + logger.debug("Could not configure VM secondary IP! => " + e.getLocalizedMessage()); } return new Answer(command, result, ""); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java index fc683958303..14aaf234c16 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsCreateTunnelCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsCreateTunnelAnswer; @@ -32,19 +31,18 @@ import com.cloud.utils.script.Script; @ResourceWrapper(handles = OvsCreateTunnelCommand.class) public final class LibvirtOvsCreateTunnelCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsCreateTunnelCommandWrapper.class); @Override public Answer execute(final OvsCreateTunnelCommand command, final LibvirtComputingResource libvirtComputingResource) { final String bridge = command.getNetworkName(); try { if (!libvirtComputingResource.findOrCreateTunnelNetwork(bridge)) { - s_logger.debug("Error during bridge setup"); + logger.debug("Error during bridge setup"); return new OvsCreateTunnelAnswer(command, false, "Cannot create network", bridge); } libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(), command.getNetworkName()); - final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), s_logger); + final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), logger); scriptCommand.add("create_tunnel"); scriptCommand.add("--bridge", bridge); scriptCommand.add("--remote_ip", command.getRemoteIp()); @@ -59,7 +57,7 @@ public final class LibvirtOvsCreateTunnelCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsDestroyBridgeCommandWrapper.class); @Override public Answer execute(final OvsDestroyBridgeCommand command, final LibvirtComputingResource libvirtComputingResource) { final boolean result = libvirtComputingResource.destroyTunnelNetwork(command.getBridgeName()); if (!result) { - s_logger.debug("Error trying to destroy OVS Bridge!"); + logger.debug("Error trying to destroy OVS Bridge!"); } return new Answer(command, result, null); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyTunnelCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyTunnelCommandWrapper.java index a1a9851e78f..83fc26bf0ff 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyTunnelCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsDestroyTunnelCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsDestroyTunnelCommand; @@ -31,18 +30,17 @@ import com.cloud.utils.script.Script; @ResourceWrapper(handles = OvsDestroyTunnelCommand.class) public final class LibvirtOvsDestroyTunnelCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsDestroyTunnelCommandWrapper.class); @Override public Answer execute(final OvsDestroyTunnelCommand command, final LibvirtComputingResource libvirtComputingResource) { try { if (!libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())) { - s_logger.warn("Unable to find tunnel network for GRE key:" + logger.warn("Unable to find tunnel network for GRE key:" + command.getBridgeName()); return new Answer(command, false, "No network found"); } - final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), s_logger); + final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), logger); scriptCommand.add("destroy_tunnel"); scriptCommand.add("--bridge", command.getBridgeName()); scriptCommand.add("--iface_name", command.getInPortName()); @@ -53,7 +51,7 @@ public final class LibvirtOvsDestroyTunnelCommandWrapper extends CommandWrapper< return new Answer(command, false, result); } } catch (final Exception e) { - s_logger.warn("caught execption when destroy ovs tunnel", e); + logger.warn("caught execption when destroy ovs tunnel", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java index 5c79de5f4bf..db07cc5291a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java @@ -20,7 +20,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsFetchInterfaceAnswer; @@ -33,13 +32,12 @@ import com.cloud.utils.script.Script; @ResourceWrapper(handles = OvsFetchInterfaceCommand.class) public final class LibvirtOvsFetchInterfaceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsFetchInterfaceCommandWrapper.class); @Override public Answer execute(final OvsFetchInterfaceCommand command, final LibvirtComputingResource libvirtComputingResource) { final String label = command.getLabel(); - s_logger.debug("Will look for network with name-label:" + label); + logger.debug("Will look for network with name-label:" + label); try { String ipadd = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'"); if (StringUtils.isEmpty(ipadd)) { @@ -57,7 +55,7 @@ public final class LibvirtOvsFetchInterfaceCommandWrapper extends CommandWrapper + " retrieved successfully", ipadd, mask, mac); } catch (final Exception e) { - s_logger.warn("Caught execption when fetching interface", e); + logger.warn("Caught execption when fetching interface", e); return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage()); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsSetupBridgeCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsSetupBridgeCommandWrapper.java index 2eb0d082c49..98649500429 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsSetupBridgeCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsSetupBridgeCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsSetupBridgeCommand; @@ -30,7 +29,6 @@ import com.cloud.resource.ResourceWrapper; @ResourceWrapper(handles = OvsSetupBridgeCommand.class) public final class LibvirtOvsSetupBridgeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsSetupBridgeCommandWrapper.class); @Override public Answer execute(final OvsSetupBridgeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -41,7 +39,7 @@ public final class LibvirtOvsSetupBridgeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper.class); @Override public Answer execute(final OvsVpcPhysicalTopologyConfigCommand command, final LibvirtComputingResource libvirtComputingResource) { try { - final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), s_logger); + final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), logger); scriptCommand.add("configure_ovs_bridge_for_network_topology"); scriptCommand.add("--bridge", command.getBridgeName()); scriptCommand.add("--config", command.getVpcConfigInJson()); @@ -48,7 +46,7 @@ public final class LibvirtOvsVpcPhysicalTopologyConfigCommandWrapper extends Com return new Answer(command, false, result); } } catch (final Exception e) { - s_logger.warn("caught exception while updating host with latest routing polcies", e); + logger.warn("caught exception while updating host with latest routing polcies", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.java index e8280199546..b481cecde23 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import com.cloud.agent.api.Answer; import com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand; @@ -31,12 +30,11 @@ import com.cloud.utils.script.Script; @ResourceWrapper(handles = OvsVpcRoutingPolicyConfigCommand.class) public final class LibvirtOvsVpcRoutingPolicyConfigCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtOvsVpcRoutingPolicyConfigCommandWrapper.class); @Override public Answer execute(final OvsVpcRoutingPolicyConfigCommand command, final LibvirtComputingResource libvirtComputingResource) { try { - final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), s_logger); + final Script scriptCommand = new Script(libvirtComputingResource.getOvsTunnelPath(), libvirtComputingResource.getTimeout(), logger); scriptCommand.add("configure_ovs_bridge_for_routing_policies"); scriptCommand.add("--bridge", command.getBridgeName()); scriptCommand.add("--config", command.getVpcConfigInJson()); @@ -48,7 +46,7 @@ public final class LibvirtOvsVpcRoutingPolicyConfigCommandWrapper extends Comman return new Answer(command, false, result); } } catch (final Exception e) { - s_logger.warn("caught exception while updating host with latest VPC topology", e); + logger.warn("caught exception while updating host with latest VPC topology", e); return new Answer(command, false, e.getMessage()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPatchSystemVmCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPatchSystemVmCommandWrapper.java index 7800e95c39b..2c8918e620d 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPatchSystemVmCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPatchSystemVmCommandWrapper.java @@ -31,13 +31,11 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.ssh.SshHelper; import com.cloud.utils.validation.ChecksumUtil; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.File; @ResourceWrapper(handles = PatchSystemVmCommand.class) public class LibvirtPatchSystemVmCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPatchSystemVmCommandWrapper.class); private static int sshPort = Integer.parseInt(LibvirtComputingResource.DEFAULTDOMRSSHPORT); private static File pemFile = new File(LibvirtComputingResource.SSHPRVKEYPATH); @@ -63,7 +61,7 @@ public class LibvirtPatchSystemVmCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPingTestCommandWrapper.class); @Override public Answer execute(final PingTestCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -53,13 +51,13 @@ public final class LibvirtPingTestCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPlugNicCommandWrapper.class); @Override public Answer execute(final PlugNicCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -57,7 +55,7 @@ public final class LibvirtPlugNicCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPostCertificateRenewalCommandWrapper.class); @Override public Answer execute(final PostCertificateRenewalCommand command, final LibvirtComputingResource serverResource) { - s_logger.info("Restarting libvirt after certificate provisioning/renewal"); + logger.info("Restarting libvirt after certificate provisioning/renewal"); if (command != null) { final int timeout = 30000; - Script script = new Script(true, "service", timeout, s_logger); + Script script = new Script(true, "service", timeout, logger); script.add("libvirtd"); script.add("restart"); script.execute(); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareForMigrationCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareForMigrationCommandWrapper.java index 6292ca71c2e..c8b20511346 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareForMigrationCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareForMigrationCommandWrapper.java @@ -26,7 +26,6 @@ import java.util.Map; import org.apache.cloudstack.storage.configdrive.ConfigDrive; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.LibvirtException; @@ -52,7 +51,6 @@ import com.cloud.utils.script.Script; @ResourceWrapper(handles = PrepareForMigrationCommand.class) public final class LibvirtPrepareForMigrationCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPrepareForMigrationCommandWrapper.class); @Override public Answer execute(final PrepareForMigrationCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -62,8 +60,8 @@ public final class LibvirtPrepareForMigrationCommandWrapper extends CommandWrapp return handleRollback(command, libvirtComputingResource); } - if (s_logger.isDebugEnabled()) { - s_logger.debug("Preparing host for migrating " + vm); + if (logger.isDebugEnabled()) { + logger.debug("Preparing host for migrating " + vm); } final NicTO[] nics = vm.getNics(); @@ -111,10 +109,10 @@ public final class LibvirtPrepareForMigrationCommandWrapper extends CommandWrapp secretConsumer = volume.getDetails().get(DiskTO.SECRET_CONSUMER_DETAIL); } String secretUuid = libvirtComputingResource.createLibvirtVolumeSecret(conn, secretConsumer, volumeObjectTO.getPassphrase()); - s_logger.debug(String.format("Created libvirt secret %s for disk %s", secretUuid, volumeObjectTO.getPath())); + logger.debug(String.format("Created libvirt secret %s for disk %s", secretUuid, volumeObjectTO.getPath())); volumeObjectTO.clearPassphrase(); } else { - s_logger.debug(String.format("disk %s has no passphrase or encryption", volumeObjectTO)); + logger.debug(String.format("disk %s has no passphrase or encryption", volumeObjectTO)); } } } @@ -130,7 +128,7 @@ public final class LibvirtPrepareForMigrationCommandWrapper extends CommandWrapp if (MapUtils.isNotEmpty(dpdkInterfaceMapping)) { for (DpdkTO to : dpdkInterfaceMapping.values()) { String cmd = String.format("ovs-vsctl del-port %s", to.getPort()); - s_logger.debug("Removing DPDK port: " + to.getPort()); + logger.debug("Removing DPDK port: " + to.getPort()); Script.runSimpleBashScript(cmd); } } @@ -147,12 +145,12 @@ public final class LibvirtPrepareForMigrationCommandWrapper extends CommandWrapp PrepareForMigrationAnswer answer = new PrepareForMigrationAnswer(command); if (MapUtils.isNotEmpty(dpdkInterfaceMapping)) { - s_logger.debug(String.format("Setting DPDK interface for the migration of VM [%s].", vm)); + logger.debug(String.format("Setting DPDK interface for the migration of VM [%s].", vm)); answer.setDpdkInterfaceMapping(dpdkInterfaceMapping); } int newCpuShares = libvirtComputingResource.calculateCpuShares(vm); - s_logger.debug(String.format("Setting CPU shares to [%s] for the migration of VM [%s].", newCpuShares, vm)); + logger.debug(String.format("Setting CPU shares to [%s] for the migration of VM [%s].", newCpuShares, vm)); answer.setNewVmCpuShares(newCpuShares); return answer; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareUnmanageVMInstanceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareUnmanageVMInstanceCommandWrapper.java index 68373089038..601a3da8642 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareUnmanageVMInstanceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPrepareUnmanageVMInstanceCommandWrapper.java @@ -22,27 +22,25 @@ import com.cloud.agent.api.PrepareUnmanageVMInstanceCommand; import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.Domain; @ResourceWrapper(handles=PrepareUnmanageVMInstanceCommand.class) public final class LibvirtPrepareUnmanageVMInstanceCommandWrapper extends CommandWrapper { - private static final Logger LOGGER = Logger.getLogger(LibvirtPrepareUnmanageVMInstanceCommandWrapper.class); @Override public PrepareUnmanageVMInstanceAnswer execute(PrepareUnmanageVMInstanceCommand command, LibvirtComputingResource libvirtComputingResource) { final String vmName = command.getInstanceName(); final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); - LOGGER.debug(String.format("Verify if KVM instance: [%s] is available before Unmanaging VM.", vmName)); + logger.debug(String.format("Verify if KVM instance: [%s] is available before Unmanaging VM.", vmName)); try { final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(vmName); final Domain domain = libvirtComputingResource.getDomain(conn, vmName); if (domain == null) { - LOGGER.error("Prepare Unmanage VMInstanceCommand: vm not found " + vmName); + logger.error("Prepare Unmanage VMInstanceCommand: vm not found " + vmName); new PrepareUnmanageVMInstanceAnswer(command, false, String.format("Cannot find VM with name [%s] in KVM host.", vmName)); } } catch (Exception e){ - LOGGER.error("PrepareUnmanagedInstancesCommand failed due to " + e.getMessage()); + logger.error("PrepareUnmanagedInstancesCommand failed due to " + e.getMessage()); return new PrepareUnmanageVMInstanceAnswer(command, false, "Error: " + e.getMessage()); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java index 91fb9242fb9..3e4baa9ae3f 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtPvlanSetupCommandWrapper.java @@ -19,7 +19,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.joda.time.Duration; import com.cloud.agent.api.Answer; @@ -32,7 +31,6 @@ import com.cloud.utils.script.Script; @ResourceWrapper(handles = PvlanSetupCommand.class) public final class LibvirtPvlanSetupCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtPvlanSetupCommandWrapper.class); @Override public Answer execute(final PvlanSetupCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -56,30 +54,30 @@ public final class LibvirtPvlanSetupCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtReadyCommandWrapper.class); @Override public Answer execute(final ReadyCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -51,12 +51,13 @@ public final class LibvirtReadyCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRebootCommandWrapper.class); @Override public Answer execute(final RebootCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -49,7 +47,7 @@ public final class LibvirtRebootCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtReplugNicCommandWrapper.class); public enum DomainAffect { CURRENT(0), LIVE(1), CONFIG(2), BOTH(3); @@ -78,15 +76,15 @@ public final class LibvirtReplugNicCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtResizeVolumeCommandWrapper.class); @Override public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -77,7 +75,7 @@ public final class LibvirtResizeVolumeCommandWrapper extends CommandWrapper 0 ) { - s_logger.debug("Invoking qemu-img to resize an offline, encrypted volume"); + logger.debug("Invoking qemu-img to resize an offline, encrypted volume"); QemuObject.EncryptFormat encryptFormat = QemuObject.EncryptFormat.enumValue(command.getEncryptFormat()); resizeEncryptedQcowFile(vol, encryptFormat,newSize, command.getPassphrase(), libvirtComputingResource); } else { - s_logger.debug("Invoking resize script to handle type " + type); - final Script resizecmd = new Script(libvirtComputingResource.getResizeVolumePath(), libvirtComputingResource.getCmdsTimeout(), s_logger); + logger.debug("Invoking resize script to handle type " + type); + final Script resizecmd = new Script(libvirtComputingResource.getResizeVolumePath(), libvirtComputingResource.getCmdsTimeout(), logger); resizecmd.add("-s", String.valueOf(newSize)); resizecmd.add("-c", String.valueOf(currentSize)); resizecmd.add("-p", path); @@ -174,11 +172,11 @@ public final class LibvirtResizeVolumeCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRestoreVMSnapshotCommandWrapper.class); @Override public Answer execute(final RestoreVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -65,7 +63,7 @@ public final class LibvirtRestoreVMSnapshotCommandWrapper extends CommandWrapper for (VMSnapshotTO snapshot: snapshots) { VMSnapshotTO parent = snapshotAndParents.get(snapshot.getId()); String vmSnapshotXML = libvirtUtilitiesHelper.generateVMSnapshotXML(snapshot, parent, xmlDesc); - s_logger.debug("Restoring vm snapshot " + snapshot.getSnapshotName() + " on " + vmName + " with XML:\n " + vmSnapshotXML); + logger.debug("Restoring vm snapshot " + snapshot.getSnapshotName() + " on " + vmName + " with XML:\n " + vmSnapshotXML); try { int flags = 1; // VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE = 1 if (snapshot.getCurrent()) { @@ -73,7 +71,7 @@ public final class LibvirtRestoreVMSnapshotCommandWrapper extends CommandWrapper } dm.snapshotCreateXML(vmSnapshotXML, flags); } catch (LibvirtException e) { - s_logger.debug("Failed to restore vm snapshot " + snapshot.getSnapshotName() + " on " + vmName); + logger.debug("Failed to restore vm snapshot " + snapshot.getSnapshotName() + " on " + vmName); return new RestoreVMSnapshotAnswer(cmd, false, e.toString()); } } @@ -81,14 +79,14 @@ public final class LibvirtRestoreVMSnapshotCommandWrapper extends CommandWrapper return new RestoreVMSnapshotAnswer(cmd, listVolumeTo, vmState); } catch (LibvirtException e) { String msg = " Restore snapshot failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new RestoreVMSnapshotAnswer(cmd, false, msg); } finally { if (dm != null) { try { dm.free(); } catch (LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); }; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertSnapshotCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertSnapshotCommandWrapper.java index 4071c1bcb45..d2f1ef827a1 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertSnapshotCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertSnapshotCommandWrapper.java @@ -32,7 +32,6 @@ import org.apache.cloudstack.storage.command.RevertSnapshotCommand; import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; import com.ceph.rados.IoCTX; import com.ceph.rados.Rados; @@ -58,7 +57,6 @@ import com.cloud.utils.script.Script; @ResourceWrapper(handles = RevertSnapshotCommand.class) public class LibvirtRevertSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRevertSnapshotCommandWrapper.class); private static final String MON_HOST = "mon_host"; private static final String KEY = "key"; private static final String CLIENT_MOUNT_TIMEOUT = "client_mount_timeout"; @@ -103,7 +101,7 @@ public class LibvirtRevertSnapshotCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRevertToVMSnapshotCommandWrapper.class); @Override public Answer execute(final RevertToVMSnapshotCommand cmd, final LibvirtComputingResource libvirtComputingResource) { @@ -80,14 +78,14 @@ public final class LibvirtRevertToVMSnapshotCommandWrapper extends CommandWrappe return new RevertToVMSnapshotAnswer(cmd, listVolumeTo, vmState); } catch (LibvirtException e) { String msg = " Revert to VM snapshot failed due to " + e.toString(); - s_logger.warn(msg, e); + logger.warn(msg, e); return new RevertToVMSnapshotAnswer(cmd, false, msg); } finally { if (dm != null) { try { dm.free(); } catch (LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); }; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevokeDirectDownloadCertificateWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevokeDirectDownloadCertificateWrapper.java index 6c83c4d9f06..34815155711 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevokeDirectDownloadCertificateWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevokeDirectDownloadCertificateWrapper.java @@ -29,7 +29,6 @@ import com.cloud.utils.script.Script; import org.apache.cloudstack.agent.directdownload.RevokeDirectDownloadCertificateCommand; import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.File; import java.io.FileNotFoundException; @@ -38,7 +37,6 @@ import java.io.IOException; @ResourceWrapper(handles = RevokeDirectDownloadCertificateCommand.class) public class LibvirtRevokeDirectDownloadCertificateWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRevokeDirectDownloadCertificateWrapper.class); /** * Retrieve agent.properties file @@ -60,7 +58,7 @@ public class LibvirtRevokeDirectDownloadCertificateWrapper extends CommandWrappe try { pass = PropertiesUtil.loadFromFile(agentFile).getProperty(KeyStoreUtils.KS_PASSPHRASE_PROPERTY); } catch (IOException e) { - s_logger.error("Could not get 'keystore.passphrase' property value due to: " + e.getMessage()); + logger.error("Could not get 'keystore.passphrase' property value due to: " + e.getMessage()); } } return pass; @@ -89,15 +87,15 @@ public class LibvirtRevokeDirectDownloadCertificateWrapper extends CommandWrappe certificateAlias, keyStoreFile, privatePassword); int existsCmdResult = Script.runSimpleBashScriptForExitValue(checkCmd); if (existsCmdResult == 1) { - s_logger.error("Certificate alias " + certificateAlias + " does not exist, no need to revoke it"); + logger.error("Certificate alias " + certificateAlias + " does not exist, no need to revoke it"); } else { String revokeCmd = String.format("keytool -delete -alias %s -keystore %s -storepass %s", certificateAlias, keyStoreFile, privatePassword); - s_logger.debug("Revoking certificate alias " + certificateAlias + " from keystore " + keyStoreFile); + logger.debug("Revoking certificate alias " + certificateAlias + " from keystore " + keyStoreFile); Script.runSimpleBashScriptForExitValue(revokeCmd); } } catch (FileNotFoundException | CloudRuntimeException e) { - s_logger.error("Error while setting up certificate " + certificateAlias, e); + logger.error("Error while setting up certificate " + certificateAlias, e); return new Answer(command, false, e.getMessage()); } return new Answer(command); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRollingMaintenanceCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRollingMaintenanceCommandWrapper.java index a1b1af60c9f..e56386ad3ad 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRollingMaintenanceCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRollingMaintenanceCommandWrapper.java @@ -28,14 +28,12 @@ import com.cloud.resource.CommandWrapper; import com.cloud.resource.ResourceWrapper; import com.cloud.resource.RollingMaintenanceManager; import com.cloud.utils.exception.CloudRuntimeException; -import org.apache.log4j.Logger; import java.io.File; @ResourceWrapper(handles = RollingMaintenanceCommand.class) public class LibvirtRollingMaintenanceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtRollingMaintenanceCommandWrapper.class); @Override public RollingMaintenanceAnswer execute(RollingMaintenanceCommand command, LibvirtComputingResource resource) { @@ -49,16 +47,16 @@ public class LibvirtRollingMaintenanceCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtSecurityGroupRulesCommandWrapper.class); @Override public Answer execute(final SecurityGroupRulesCmd command, final LibvirtComputingResource libvirtComputingResource) { @@ -54,7 +52,7 @@ public final class LibvirtSecurityGroupRulesCommandWrapper extends CommandWrappe final VirtualMachineTO vm = command.getVmTO(); if (!libvirtComputingResource.applyDefaultNetworkRules(conn, vm, true)) { - s_logger.warn("Failed to program default network rules for vm " + command.getVmName()); + logger.warn("Failed to program default network rules for vm " + command.getVmName()); return new SecurityGroupRuleAnswer(command, false, "programming default network rules failed"); } } catch (final LibvirtException e) { @@ -65,10 +63,10 @@ public final class LibvirtSecurityGroupRulesCommandWrapper extends CommandWrappe Long.toString(command.getSeqNum()), command.getGuestMac(), command.stringifyRules(), vif, brname, command.getSecIpsString()); if (!result) { - s_logger.warn("Failed to program network rules for vm " + command.getVmName()); + logger.warn("Failed to program network rules for vm " + command.getVmName()); return new SecurityGroupRuleAnswer(command, false, "programming network rules failed"); } else { - s_logger.debug("Programmed network rules for vm " + command.getVmName() + " guestIp=" + command.getGuestIp() + ",ingress numrules=" + logger.debug("Programmed network rules for vm " + command.getVmName() + " guestIp=" + command.getGuestIp() + ",ingress numrules=" + command.getIngressRuleSet().size() + ",egress numrules=" + command.getEgressRuleSet().size()); return new SecurityGroupRuleAnswer(command); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java index fff8da7c4ea..eb4e6be7609 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupDirectDownloadCertificateCommandWrapper.java @@ -28,7 +28,6 @@ import com.cloud.utils.script.Script; import org.apache.cloudstack.agent.directdownload.SetupDirectDownloadCertificateCommand; import org.apache.cloudstack.utils.security.KeyStoreUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; import java.io.File; import java.io.FileNotFoundException; @@ -39,7 +38,6 @@ public class LibvirtSetupDirectDownloadCertificateCommandWrapper extends Command private static final String temporaryCertFilePrefix = "CSCERTIFICATE"; - private static final Logger s_logger = Logger.getLogger(LibvirtSetupDirectDownloadCertificateCommandWrapper.class); /** * Retrieve agent.properties file @@ -61,7 +59,7 @@ public class LibvirtSetupDirectDownloadCertificateCommandWrapper extends Command try { pass = PropertiesUtil.loadFromFile(agentFile).getProperty(KeyStoreUtils.KS_PASSPHRASE_PROPERTY); } catch (IOException e) { - s_logger.error("Could not get 'keystore.passphrase' property value due to: " + e.getMessage()); + logger.error("Could not get 'keystore.passphrase' property value due to: " + e.getMessage()); } } return pass; @@ -78,12 +76,12 @@ public class LibvirtSetupDirectDownloadCertificateCommandWrapper extends Command * Import certificate from temporary file into keystore */ private void importCertificate(String tempCerFilePath, String keyStoreFile, String certificateName, String privatePassword) { - s_logger.debug("Importing certificate from temporary file to keystore"); + logger.debug("Importing certificate from temporary file to keystore"); String importCommandFormat = "keytool -importcert -file %s -keystore %s -alias '%s' -storepass '%s' -noprompt"; String importCmd = String.format(importCommandFormat, tempCerFilePath, keyStoreFile, certificateName, privatePassword); int result = Script.runSimpleBashScriptForExitValue(importCmd); if (result != 0) { - s_logger.debug("Certificate " + certificateName + " not imported as it already exist on keystore"); + logger.debug("Certificate " + certificateName + " not imported as it already exist on keystore"); } } @@ -93,7 +91,7 @@ public class LibvirtSetupDirectDownloadCertificateCommandWrapper extends Command private String createTemporaryFile(File agentFile, String certificateName, String certificate) { String tempCerFilePath = String.format("%s/%s-%s", agentFile.getParent(), temporaryCertFilePrefix, certificateName); - s_logger.debug("Creating temporary certificate file into: " + tempCerFilePath); + logger.debug("Creating temporary certificate file into: " + tempCerFilePath); int result = Script.runSimpleBashScriptForExitValue(String.format("echo '%s' > %s", certificate, tempCerFilePath)); if (result != 0) { throw new CloudRuntimeException("Could not create the certificate file on path: " + tempCerFilePath); @@ -105,7 +103,7 @@ public class LibvirtSetupDirectDownloadCertificateCommandWrapper extends Command * Remove temporary file */ private void cleanupTemporaryFile(String temporaryFile) { - s_logger.debug("Cleaning up temporary certificate file"); + logger.debug("Cleaning up temporary certificate file"); Script.runSimpleBashScript("rm -f " + temporaryFile); } @@ -126,7 +124,7 @@ public class LibvirtSetupDirectDownloadCertificateCommandWrapper extends Command importCertificate(temporaryFile, keyStoreFile, certificateName, privatePassword); cleanupTemporaryFile(temporaryFile); } catch (FileNotFoundException | CloudRuntimeException e) { - s_logger.error("Error while setting up certificate " + certificateName, e); + logger.error("Error while setting up certificate " + certificateName, e); return new Answer(cmd, false, e.getMessage()); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupPersistentNetworkCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupPersistentNetworkCommandWrapper.java index a2ec64451a7..66be619777d 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupPersistentNetworkCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtSetupPersistentNetworkCommandWrapper.java @@ -17,7 +17,6 @@ package com.cloud.hypervisor.kvm.resource.wrapper; -import org.apache.log4j.Logger; import org.libvirt.LibvirtException; import com.cloud.agent.api.Answer; @@ -33,7 +32,6 @@ import com.cloud.resource.ResourceWrapper; @ResourceWrapper(handles = SetupPersistentNetworkCommand.class) public class LibvirtSetupPersistentNetworkCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtSetupPersistentNetworkCommandWrapper.class); @Override public Answer execute(SetupPersistentNetworkCommand command, LibvirtComputingResource serverResource) { diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java index 7b69993f2e5..32d687ff98c 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtStartCommandWrapper.java @@ -24,7 +24,6 @@ import java.net.URISyntaxException; import com.cloud.agent.resource.virtualnetwork.VRScripts; import com.cloud.utils.FileUtil; -import org.apache.log4j.Logger; import org.libvirt.Connect; import org.libvirt.DomainInfo.DomainState; import org.libvirt.LibvirtException; @@ -49,7 +48,6 @@ import com.cloud.vm.VirtualMachine; @ResourceWrapper(handles = StartCommand.class) public final class LibvirtStartCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtStartCommandWrapper.class); @Override public Answer execute(final StartCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -83,7 +81,7 @@ public final class LibvirtStartCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtStopCommandWrapper.class); private static final String CMDLINE_PATH = "/var/cache/cloud/cmdline"; private static final String CMDLINE_BACKUP_PATH = "/var/cache/cloud/cmdline.backup"; @@ -67,21 +65,21 @@ public final class LibvirtStopCommandWrapper extends CommandWrapper ret = SshHelper.sshExecute(command.getControlIp(), 3922, "root", pemFile, null,"cp -f "+CMDLINE_PATH+" "+CMDLINE_BACKUP_PATH); if(!ret.first()){ - s_logger.debug("Failed to backup cmdline file due to "+ret.second()); + logger.debug("Failed to backup cmdline file due to "+ret.second()); } } catch (Exception e){ - s_logger.debug("Failed to backup cmdline file due to "+e.getMessage()); + logger.debug("Failed to backup cmdline file due to "+e.getMessage()); } } @@ -123,7 +121,7 @@ public final class LibvirtStopCommandWrapper extends CommandWrapper ret = SshHelper.sshExecute(command.getControlIp(), 3922, "root", pemFile, null, "mv "+CMDLINE_BACKUP_PATH+" "+CMDLINE_PATH); if(!ret.first()){ - s_logger.debug("unable to restore cmdline due to "+ret.second()); + logger.debug("unable to restore cmdline due to "+ret.second()); } }catch (final Exception ex){ - s_logger.debug("unable to restore cmdline due to:"+ex.getMessage()); + logger.debug("unable to restore cmdline due to:"+ex.getMessage()); } return new StopAnswer(command, e.getMessage(), false); } @@ -161,7 +159,7 @@ public final class LibvirtStopCommandWrapper extends CommandWrapper { - private static final Logger s_logger = Logger.getLogger(LibvirtUnPlugNicCommandWrapper.class); @Override public Answer execute(final UnPlugNicCommand command, final LibvirtComputingResource libvirtComputingResource) { @@ -73,14 +71,14 @@ public final class LibvirtUnPlugNicCommandWrapper extends CommandWrapper(String.valueOf(currentLibvirtVersion), currentLibvirtVersion >= version); } catch (LibvirtException ex) { String exceptionMessage = ex.getMessage(); - s_logger.error(String.format("Unable to validate if the Libvirt's version is equal or higher than [%s] due to [%s]. Returning 'false' as default'.", version, + LOGGER.error(String.format("Unable to validate if the Libvirt's version is equal or higher than [%s] due to [%s]. Returning 'false' as default'.", version, exceptionMessage), ex); return new Pair<>(String.format("Unknown due to [%s]", exceptionMessage), false); } @@ -140,7 +141,7 @@ public class LibvirtUtilitiesHelper { */ public static boolean isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit(Connect conn) { Pair result = isLibvirtVersionEqualOrHigherThanVersionInParameter(conn, LIBVIRT_VERSION_THAT_SUPPORTS_FLAG_DELETE_ON_COMMAND_VIRSH_BLOCKCOMMIT); - s_logger.debug(String.format("The current Libvirt's version [%s]%s supports the flag '--delete' on command 'virsh blockcommit'.", result.first(), + LOGGER.debug(String.format("The current Libvirt's version [%s]%s supports the flag '--delete' on command 'virsh blockcommit'.", result.first(), result.second() ? "" : " does not")); return result.second(); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/FiberChannelAdapter.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/FiberChannelAdapter.java index be7cb727ad7..83636b9a9c3 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/FiberChannelAdapter.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/FiberChannelAdapter.java @@ -19,12 +19,16 @@ package com.cloud.hypervisor.kvm.storage; import com.cloud.storage.Storage; import com.cloud.utils.exception.CloudRuntimeException; -@StorageAdaptorInfo(storagePoolType=Storage.StoragePoolType.FiberChannel) public class FiberChannelAdapter extends MultipathSCSIAdapterBase { public FiberChannelAdapter() { LOGGER.info("Loaded FiberChannelAdapter for StorageLayer"); } + @Override + public Storage.StoragePoolType getStoragePoolType() { + return Storage.StoragePoolType.FiberChannel; + } + @Override public KVMStoragePool getStoragePool(String uuid) { KVMStoragePool pool = MapStorageUuidToStoragePool.get(uuid); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java index f980cd295bd..f023457461e 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiAdmStorageAdaptor.java @@ -25,7 +25,8 @@ import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.LibvirtException; import com.cloud.agent.api.to.DiskTO; @@ -36,9 +37,8 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; -@StorageAdaptorInfo(storagePoolType=StoragePoolType.Iscsi) public class IscsiAdmStorageAdaptor implements StorageAdaptor { - private static final Logger s_logger = Logger.getLogger(IscsiAdmStorageAdaptor.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final Map MapStorageUuidToStoragePool = new HashMap<>(); @@ -51,6 +51,11 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { return storagePool; } + @Override + public StoragePoolType getStoragePoolType() { + return StoragePoolType.Iscsi; + } + @Override public KVMStoragePool getStoragePool(String uuid) { return MapStorageUuidToStoragePool.get(uuid); @@ -81,7 +86,7 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { @Override public boolean connectPhysicalDisk(String volumeUuid, KVMStoragePool pool, Map details) { // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 -o new - Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger); + Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, logger); iScsiAdmCmd.add("-m", "node"); iScsiAdmCmd.add("-T", getIqn(volumeUuid)); @@ -91,12 +96,12 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { String result = iScsiAdmCmd.execute(); if (result != null) { - s_logger.debug("Failed to add iSCSI target " + volumeUuid); + logger.debug("Failed to add iSCSI target " + volumeUuid); System.out.println("Failed to add iSCSI target " + volumeUuid); return false; } else { - s_logger.debug("Successfully added iSCSI target " + volumeUuid); + logger.debug("Successfully added iSCSI target " + volumeUuid); System.out.println("Successfully added to iSCSI target " + volumeUuid); } @@ -119,7 +124,7 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { } // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 --login - iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger); + iScsiAdmCmd = new Script(true, "iscsiadm", 0, logger); iScsiAdmCmd.add("-m", "node"); iScsiAdmCmd.add("-T", getIqn(volumeUuid)); @@ -129,12 +134,12 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { result = iScsiAdmCmd.execute(); if (result != null) { - s_logger.debug("Failed to log in to iSCSI target " + volumeUuid); + logger.debug("Failed to log in to iSCSI target " + volumeUuid); System.out.println("Failed to log in to iSCSI target " + volumeUuid); return false; } else { - s_logger.debug("Successfully logged in to iSCSI target " + volumeUuid); + logger.debug("Successfully logged in to iSCSI target " + volumeUuid); System.out.println("Successfully logged in to iSCSI target " + volumeUuid); } @@ -186,7 +191,7 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { } private void executeChapCommand(String path, KVMStoragePool pool, String nParameter, String vParameter, String detail) throws Exception { - Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger); + Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, logger); iScsiAdmCmd.add("-m", "node"); iScsiAdmCmd.add("-T", getIqn(path)); @@ -202,18 +207,18 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { detail = useDetail ? detail.trim() + " " : detail; if (result != null) { - s_logger.debug("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result); + logger.debug("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result); System.out.println("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result); throw new Exception("Failed to execute CHAP " + (useDetail ? detail : "") + "command for iSCSI target " + path + " : message = " + result); } else { - s_logger.debug("CHAP " + (useDetail ? detail : "") + "command executed successfully for iSCSI target " + path); + logger.debug("CHAP " + (useDetail ? detail : "") + "command executed successfully for iSCSI target " + path); System.out.println("CHAP " + (useDetail ? detail : "") + "command executed successfully for iSCSI target " + path); } } // example by-path: /dev/disk/by-path/ip-192.168.233.10:3260-iscsi-iqn.2012-03.com.solidfire:storagepool2-lun-0 - private static String getByPath(String host, int port, String path) { + private String getByPath(String host, int port, String path) { return "/dev/disk/by-path/ip-" + host + ":" + port + "-iscsi-" + getIqn(path) + "-lun-" + getLun(path); } @@ -233,7 +238,7 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { } private long getDeviceSize(String deviceByPath) { - Script iScsiAdmCmd = new Script(true, "blockdev", 0, s_logger); + Script iScsiAdmCmd = new Script(true, "blockdev", 0, logger); iScsiAdmCmd.add("--getsize64", deviceByPath); @@ -242,32 +247,32 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { String result = iScsiAdmCmd.execute(parser); if (result != null) { - s_logger.warn("Unable to retrieve the size of device (resource may have moved to a different host)" + deviceByPath); + logger.warn("Unable to retrieve the size of device (resource may have moved to a different host)" + deviceByPath); return 0; } else { - s_logger.info("Successfully retrieved the size of device " + deviceByPath); + logger.info("Successfully retrieved the size of device " + deviceByPath); } return Long.parseLong(parser.getLine()); } - private static String getIqn(String path) { + private String getIqn(String path) { return getComponent(path, 1); } - private static String getLun(String path) { + private String getLun(String path) { return getComponent(path, 2); } - private static String getComponent(String path, int index) { + private String getComponent(String path, int index) { String[] tmp = path.split("/"); if (tmp.length != 3) { String msg = "Wrong format for iScsi path: " + path + ". It should be formatted as '/targetIQN/LUN'."; - s_logger.warn(msg); + logger.warn(msg); throw new CloudRuntimeException(msg); } @@ -279,7 +284,7 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { // use iscsiadm to log out of the iSCSI target and un-discover it // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 --logout - Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger); + Script iScsiAdmCmd = new Script(true, "iscsiadm", 0, logger); iScsiAdmCmd.add("-m", "node"); iScsiAdmCmd.add("-T", iqn); @@ -289,17 +294,17 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { String result = iScsiAdmCmd.execute(); if (result != null) { - s_logger.debug("Failed to log out of iSCSI target /" + iqn + "/" + lun + " : message = " + result); + logger.debug("Failed to log out of iSCSI target /" + iqn + "/" + lun + " : message = " + result); System.out.println("Failed to log out of iSCSI target /" + iqn + "/" + lun + " : message = " + result); return false; } else { - s_logger.debug("Successfully logged out of iSCSI target /" + iqn + "/" + lun); + logger.debug("Successfully logged out of iSCSI target /" + iqn + "/" + lun); System.out.println("Successfully logged out of iSCSI target /" + iqn + "/" + lun); } // ex. sudo iscsiadm -m node -T iqn.2012-03.com.test:volume1 -p 192.168.233.10:3260 -o delete - iScsiAdmCmd = new Script(true, "iscsiadm", 0, s_logger); + iScsiAdmCmd = new Script(true, "iscsiadm", 0, logger); iScsiAdmCmd.add("-m", "node"); iScsiAdmCmd.add("-T", iqn); @@ -309,12 +314,12 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { result = iScsiAdmCmd.execute(); if (result != null) { - s_logger.debug("Failed to remove iSCSI target /" + iqn + "/" + lun + " : message = " + result); + logger.debug("Failed to remove iSCSI target /" + iqn + "/" + lun + " : message = " + result); System.out.println("Failed to remove iSCSI target /" + iqn + "/" + lun + " : message = " + result); return false; } else { - s_logger.debug("Removed iSCSI target /" + iqn + "/" + lun); + logger.debug("Removed iSCSI target /" + iqn + "/" + lun); System.out.println("Removed iSCSI target /" + iqn + "/" + lun); } @@ -423,7 +428,7 @@ public class IscsiAdmStorageAdaptor implements StorageAdaptor { String msg = "Failed to copy data from " + srcDisk.getPath() + " to " + destDisk.getPath() + ". The error was the following: " + ex.getMessage(); - s_logger.error(msg); + logger.error(msg); throw new CloudRuntimeException(msg); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitor.java index da2be68d0b7..f37ae3d2a3c 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/IscsiStorageCleanupMonitor.java @@ -20,7 +20,8 @@ import com.cloud.hypervisor.kvm.resource.LibvirtConnection; import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef; import org.apache.cloudstack.managed.context.ManagedContextRunnable; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.LibvirtException; @@ -33,7 +34,7 @@ import java.util.List; import java.util.Map; public class IscsiStorageCleanupMonitor implements Runnable{ - private static final Logger s_logger = Logger.getLogger(IscsiStorageCleanupMonitor.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final int CLEANUP_INTERVAL_SEC = 60; // check every X seconds private static final String ISCSI_PATH_PREFIX = "/dev/disk/by-path"; private static final String KEYWORD_ISCSI = "iscsi"; @@ -46,7 +47,7 @@ public class IscsiStorageCleanupMonitor implements Runnable{ public IscsiStorageCleanupMonitor() { diskStatusMap = new HashMap<>(); - s_logger.debug("Initialize cleanup thread"); + logger.debug("Initialize cleanup thread"); iscsiStorageAdaptor = new IscsiAdmStorageAdaptor(); } @@ -62,7 +63,7 @@ public class IscsiStorageCleanupMonitor implements Runnable{ //populate all the iscsi disks currently attached to this host File[] iscsiVolumes = new File(ISCSI_PATH_PREFIX).listFiles(); if (iscsiVolumes == null || iscsiVolumes.length == 0) { - s_logger.debug("No iscsi sessions found for cleanup"); + logger.debug("No iscsi sessions found for cleanup"); return; } @@ -76,7 +77,7 @@ public class IscsiStorageCleanupMonitor implements Runnable{ disconnectInactiveSessions(); } catch (LibvirtException e) { - s_logger.warn("[ignored] Error trying to cleanup ", e); + logger.warn("[ignored] Error trying to cleanup ", e); } } @@ -92,7 +93,7 @@ public class IscsiStorageCleanupMonitor implements Runnable{ diskStatusMap.clear(); for( File v : iscsiVolumes) { if (isIscsiDisk(v.getAbsolutePath())) { - s_logger.debug("found iscsi disk by cleanup thread, marking inactive: " + v.getAbsolutePath()); + logger.debug("found iscsi disk by cleanup thread, marking inactive: " + v.getAbsolutePath()); diskStatusMap.put(v.getAbsolutePath(), false); } } @@ -105,7 +106,7 @@ public class IscsiStorageCleanupMonitor implements Runnable{ private void updateDiskStatusMapWithInactiveIscsiSessions(Connect conn){ try { int[] domains = conn.listDomains(); - s_logger.debug(String.format("found %d domains", domains.length)); + logger.debug(String.format("found %d domains", domains.length)); for (int domId : domains) { Domain dm = conn.domainLookupByID(domId); final String domXml = dm.getXMLDesc(0); @@ -117,12 +118,12 @@ public class IscsiStorageCleanupMonitor implements Runnable{ for (final LibvirtVMDef.DiskDef disk : disks) { if (diskStatusMap.containsKey(disk.getDiskPath())&&!disk.getDiskPath().matches(REGEX_PART)) { diskStatusMap.put(disk.getDiskPath(), true); - s_logger.debug("active disk found by cleanup thread" + disk.getDiskPath()); + logger.debug("active disk found by cleanup thread" + disk.getDiskPath()); } } } } catch (LibvirtException e) { - s_logger.warn("[ignored] Error trying to cleanup ", e); + logger.warn("[ignored] Error trying to cleanup ", e); } } @@ -141,10 +142,10 @@ public class IscsiStorageCleanupMonitor implements Runnable{ if (!diskStatusMap.get(diskPath)) { if (Files.exists(Paths.get(diskPath))) { try { - s_logger.info("Cleaning up disk " + diskPath); + logger.info("Cleaning up disk " + diskPath); iscsiStorageAdaptor.disconnectPhysicalDiskByPath(diskPath); } catch (Exception e) { - s_logger.warn("[ignored] Error cleaning up " + diskPath, e); + logger.warn("[ignored] Error cleaning up " + diskPath, e); } } } @@ -159,7 +160,7 @@ public class IscsiStorageCleanupMonitor implements Runnable{ try { Thread.sleep(CLEANUP_INTERVAL_SEC * 1000); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted between heartbeats."); + logger.debug("[ignored] interrupted between heartbeats."); } Thread monitorThread = new Thread(new Monitor()); @@ -167,7 +168,7 @@ public class IscsiStorageCleanupMonitor implements Runnable{ try { monitorThread.join(); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted joining monitor."); + logger.debug("[ignored] interrupted joining monitor."); } } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePool.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePool.java index 43a09ccf2bf..43547e7c7d1 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePool.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePool.java @@ -21,6 +21,7 @@ import java.util.Map; import com.cloud.agent.properties.AgentProperties; import com.cloud.agent.properties.AgentPropertiesFileHandler; +import com.cloud.hypervisor.kvm.resource.LibvirtVMDef; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.joda.time.Duration; @@ -99,4 +100,12 @@ public interface KVMStoragePool { public Boolean checkingHeartBeat(HAStoragePool pool, HostTO host); public Boolean vmActivityCheck(HAStoragePool pool, HostTO host, Duration activityScriptTimeout, String volumeUUIDListString, String vmActivityCheckPath, long duration); + + default LibvirtVMDef.DiskDef.BlockIOSize getSupportedLogicalBlockSize() { + return null; + } + + default LibvirtVMDef.DiskDef.BlockIOSize getSupportedPhysicalBlockSize() { + return null; + } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java index b1842f38da2..27f70b71ab4 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java @@ -16,6 +16,8 @@ // under the License. package com.cloud.hypervisor.kvm.storage; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; import java.net.URI; import java.net.URISyntaxException; import java.util.Arrays; @@ -30,7 +32,8 @@ import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.commons.collections.MapUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.reflections.Reflections; import com.cloud.agent.api.to.DiskTO; @@ -46,7 +49,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.VirtualMachine; public class KVMStoragePoolManager { - private static final Logger s_logger = Logger.getLogger(KVMStoragePoolManager.class); + protected Logger logger = LogManager.getLogger(getClass()); private class StoragePoolInformation { String name; @@ -98,35 +101,60 @@ public class KVMStoragePoolManager { public KVMStoragePoolManager(StorageLayer storagelayer, KVMHAMonitor monitor) { this._haMonitor = monitor; this._storageMapper.put("libvirt", new LibvirtStorageAdaptor(storagelayer)); - // add other storage adaptors here - // this._storageMapper.put("newadaptor", new NewStorageAdaptor(storagelayer)); - this._storageMapper.put(StoragePoolType.ManagedNFS.toString(), new ManagedNfsStorageAdaptor(storagelayer)); - this._storageMapper.put(StoragePoolType.PowerFlex.toString(), new ScaleIOStorageAdaptor(storagelayer)); + // add other storage adaptors manually here - // add any adaptors that wish to register themselves via annotation + // add any adaptors that wish to register themselves via call to adaptor.getStoragePoolType() Reflections reflections = new Reflections("com.cloud.hypervisor.kvm.storage"); - Set> storageAdaptors = reflections.getSubTypesOf(StorageAdaptor.class); - for (Class storageAdaptor : storageAdaptors) { - StorageAdaptorInfo info = storageAdaptor.getAnnotation(StorageAdaptorInfo.class); - if (info != null && info.storagePoolType() != null) { - if (this._storageMapper.containsKey(info.storagePoolType().toString())) { - s_logger.warn(String.format("Duplicate StorageAdaptor type %s, not loading %s", info.storagePoolType().toString(), storageAdaptor.getName())); + Set> storageAdaptorClasses = reflections.getSubTypesOf(StorageAdaptor.class); + for (Class storageAdaptorClass : storageAdaptorClasses) { + logger.debug("Checking pool type for adaptor " + storageAdaptorClass.getName()); + if (Modifier.isAbstract(storageAdaptorClass.getModifiers()) || storageAdaptorClass.isInterface()) { + logger.debug("Skipping registration of abstract class / interface " + storageAdaptorClass.getName()); + continue; + } + if (storageAdaptorClass.isAssignableFrom(LibvirtStorageAdaptor.class)) { + logger.debug("Skipping re-registration of LibvirtStorageAdaptor"); + continue; + } + try { + Constructor storageLayerConstructor = Arrays.stream(storageAdaptorClass.getConstructors()) + .filter(c -> c.getParameterCount() == 1) + .filter(c -> c.getParameterTypes()[0].isAssignableFrom(StorageLayer.class)) + .findFirst().orElse(null); + StorageAdaptor adaptor; + + if (storageLayerConstructor == null) { + adaptor = storageAdaptorClass.getDeclaredConstructor().newInstance(); } else { - try { - s_logger.info(String.format("adding storage adaptor for %s", storageAdaptor.getName())); - this._storageMapper.put(info.storagePoolType().toString(), storageAdaptor.getDeclaredConstructor().newInstance()); - } catch (Exception ex) { - throw new CloudRuntimeException(ex.toString()); + adaptor = (StorageAdaptor) storageLayerConstructor.newInstance(storagelayer); + } + + StoragePoolType storagePoolType = adaptor.getStoragePoolType(); + if (storagePoolType != null) { + if (this._storageMapper.containsKey(storagePoolType.toString())) { + logger.warn(String.format("Duplicate StorageAdaptor type %s, not loading %s", storagePoolType, storageAdaptorClass.getName())); + } else { + logger.info(String.format("Adding storage adaptor for %s", storageAdaptorClass.getName())); + this._storageMapper.put(storagePoolType.toString(), adaptor); } } + } catch (Exception ex) { + throw new CloudRuntimeException("Failed to set up storage adaptors", ex); } } for (Map.Entry adaptors : this._storageMapper.entrySet()) { - s_logger.debug("Registered a StorageAdaptor for " + adaptors.getKey()); + logger.debug("Registered a StorageAdaptor for " + adaptors.getKey()); } } + /** + * Returns true if physical disk copy functionality supported. + */ + public boolean supportsPhysicalDiskCopy(StoragePoolType type) { + return getStorageAdaptor(type).supportsPhysicalDiskCopy(type); + } + public boolean connectPhysicalDisk(StoragePoolType type, String poolUuid, String volPath, Map details) { StorageAdaptor adaptor = getStorageAdaptor(type); KVMStoragePool pool = adaptor.getStoragePool(poolUuid); @@ -160,7 +188,7 @@ public class KVMStoragePoolManager { result = adaptor.connectPhysicalDisk(vol.getPath(), pool, disk.getDetails()); if (!result) { - s_logger.error("Failed to connect disks via vm spec for vm: " + vmName + " volume:" + vol.toString()); + logger.error("Failed to connect disks via vm spec for vm: " + vmName + " volume:" + vol.toString()); return result; } } @@ -169,7 +197,7 @@ public class KVMStoragePoolManager { } public boolean disconnectPhysicalDisk(Map volumeToDisconnect) { - s_logger.debug(String.format("Disconnect physical disks using volume map: %s", volumeToDisconnect.toString())); + logger.debug(String.format("Disconnect physical disks using volume map: %s", volumeToDisconnect.toString())); if (MapUtils.isEmpty(volumeToDisconnect)) { return false; } @@ -178,18 +206,18 @@ public class KVMStoragePoolManager { String poolType = volumeToDisconnect.get(DiskTO.PROTOCOL_TYPE); StorageAdaptor adaptor = _storageMapper.get(poolType); if (adaptor != null) { - s_logger.info(String.format("Disconnecting physical disk using the storage adaptor found for pool type: %s", poolType)); + logger.info(String.format("Disconnecting physical disk using the storage adaptor found for pool type: %s", poolType)); return adaptor.disconnectPhysicalDisk(volumeToDisconnect); } - s_logger.debug(String.format("Couldn't find the storage adaptor for pool type: %s to disconnect the physical disk, trying with others", poolType)); + logger.debug(String.format("Couldn't find the storage adaptor for pool type: %s to disconnect the physical disk, trying with others", poolType)); } for (Map.Entry set : _storageMapper.entrySet()) { StorageAdaptor adaptor = set.getValue(); if (adaptor.disconnectPhysicalDisk(volumeToDisconnect)) { - s_logger.debug(String.format("Disconnected physical disk using the storage adaptor for pool type: %s", set.getKey())); + logger.debug(String.format("Disconnected physical disk using the storage adaptor for pool type: %s", set.getKey())); return true; } } @@ -198,12 +226,12 @@ public class KVMStoragePoolManager { } public boolean disconnectPhysicalDiskByPath(String path) { - s_logger.debug(String.format("Disconnect physical disk by path: %s", path)); + logger.debug(String.format("Disconnect physical disk by path: %s", path)); for (Map.Entry set : _storageMapper.entrySet()) { StorageAdaptor adaptor = set.getValue(); if (adaptor.disconnectPhysicalDiskByPath(path)) { - s_logger.debug(String.format("Disconnected physical disk by local path: %s, using the storage adaptor for pool type: %s", path, set.getKey())); + logger.debug(String.format("Disconnected physical disk by local path: %s, using the storage adaptor for pool type: %s", path, set.getKey())); return true; } } @@ -218,7 +246,7 @@ public class KVMStoragePoolManager { We may not know about these yet. This might mean that we can't use the vmspec map, because when we restart the agent we lose all of the info about running VMs. */ - s_logger.debug("disconnectPhysicalDiskViaVmSpec: Attempted to stop a VM that is not yet in our hash map"); + logger.debug("disconnectPhysicalDiskViaVmSpec: Attempted to stop a VM that is not yet in our hash map"); return true; } @@ -231,7 +259,7 @@ public class KVMStoragePoolManager { for (DiskTO disk : disks) { if (disk.getType() != Volume.Type.ISO) { - s_logger.debug("Disconnecting disk " + disk.getPath()); + logger.debug("Disconnecting disk " + disk.getPath()); VolumeObjectTO vol = (VolumeObjectTO)disk.getData(); PrimaryDataStoreTO store = (PrimaryDataStoreTO)vol.getDataStore(); @@ -239,7 +267,7 @@ public class KVMStoragePoolManager { KVMStoragePool pool = getStoragePool(store.getPoolType(), store.getUuid()); if (pool == null) { - s_logger.error("Pool " + store.getUuid() + " of type " + store.getPoolType() + " was not found, skipping disconnect logic"); + logger.error("Pool " + store.getUuid() + " of type " + store.getPoolType() + " was not found, skipping disconnect logic"); continue; } @@ -250,7 +278,7 @@ public class KVMStoragePoolManager { boolean subResult = adaptor.disconnectPhysicalDisk(vol.getPath(), pool); if (!subResult) { - s_logger.error("Failed to disconnect disks via vm spec for vm: " + vmName + " volume:" + vol.toString()); + logger.error("Failed to disconnect disks via vm spec for vm: " + vmName + " volume:" + vol.toString()); result = false; } @@ -323,14 +351,14 @@ public class KVMStoragePoolManager { return vol; } } catch (Exception e) { - s_logger.debug("Failed to find volume:" + volName + " due to " + e.toString() + ", retry:" + cnt); + logger.debug("Failed to find volume:" + volName + " due to " + e.toString() + ", retry:" + cnt); errMsg = e.toString(); } try { Thread.sleep(3000); } catch (InterruptedException e) { - s_logger.debug("[ignored] interrupted while trying to get storage pool."); + logger.debug("[ignored] interrupted while trying to get storage pool."); } cnt++; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java index 1be4a8b6185..0a9cc80a339 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java @@ -78,7 +78,8 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; import org.libvirt.Domain; import org.libvirt.DomainInfo; @@ -135,7 +136,7 @@ import com.cloud.utils.storage.S3.S3Utils; import com.cloud.vm.VmDetailConstants; public class KVMStorageProcessor implements StorageProcessor { - private static final Logger s_logger = Logger.getLogger(KVMStorageProcessor.class); + protected Logger logger = LogManager.getLogger(getClass()); private final KVMStoragePoolManager storagePoolMgr; private final LibvirtComputingResource resource; private StorageLayer storageLayer; @@ -185,14 +186,14 @@ public class KVMStorageProcessor implements StorageProcessor { @Override public SnapshotAndCopyAnswer snapshotAndCopy(final SnapshotAndCopyCommand cmd) { - s_logger.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for KVMStorageProcessor"); + logger.info("'SnapshotAndCopyAnswer snapshotAndCopy(SnapshotAndCopyCommand)' not currently used for KVMStorageProcessor"); return new SnapshotAndCopyAnswer(); } @Override public ResignatureAnswer resignature(final ResignatureCommand cmd) { - s_logger.info("'ResignatureAnswer resignature(ResignatureCommand)' not currently used for KVMStorageProcessor"); + logger.info("'ResignatureAnswer resignature(ResignatureCommand)' not currently used for KVMStorageProcessor"); return new ResignatureAnswer(); } @@ -246,7 +247,7 @@ public class KVMStorageProcessor implements StorageProcessor { /* Copy volume to primary storage */ tmplVol.setUseAsTemplate(); - s_logger.debug("Copying template to primary storage, template format is " + tmplVol.getFormat() ); + logger.debug("Copying template to primary storage, template format is " + tmplVol.getFormat() ); final KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(primaryStore.getPoolType(), primaryStore.getUuid()); KVMPhysicalDisk primaryVol = null; @@ -254,11 +255,11 @@ public class KVMStorageProcessor implements StorageProcessor { final VolumeObjectTO volume = (VolumeObjectTO)destData; // pass along volume's target size if it's bigger than template's size, for storage types that copy template rather than cloning on deploy if (volume.getSize() != null && volume.getSize() > tmplVol.getVirtualSize()) { - s_logger.debug("Using configured size of " + toHumanReadableSize(volume.getSize())); + logger.debug("Using configured size of " + toHumanReadableSize(volume.getSize())); tmplVol.setSize(volume.getSize()); tmplVol.setVirtualSize(volume.getSize()); } else { - s_logger.debug("Using template's size of " + toHumanReadableSize(tmplVol.getVirtualSize())); + logger.debug("Using template's size of " + toHumanReadableSize(tmplVol.getVirtualSize())); } primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, volume.getUuid(), primaryPool, cmd.getWaitInMillSeconds()); } else if (destData instanceof TemplateObjectTO) { @@ -269,13 +270,13 @@ public class KVMStorageProcessor implements StorageProcessor { String path = details != null ? details.get("managedStoreTarget") : null; if (!storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path, details)) { - s_logger.warn("Failed to connect physical disk at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); + logger.warn("Failed to connect physical disk at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); } primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, path != null ? path : destTempl.getUuid(), primaryPool, cmd.getWaitInMillSeconds()); if (!storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path)) { - s_logger.warn("Failed to disconnect physical disk at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); + logger.warn("Failed to disconnect physical disk at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); } } else { primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, cmd.getWaitInMillSeconds()); @@ -321,7 +322,7 @@ public class KVMStorageProcessor implements StorageProcessor { secondaryPool.delete(); } } catch(final Exception e) { - s_logger.debug("Failed to clean up secondary storage", e); + logger.debug("Failed to clean up secondary storage", e); } } } @@ -344,7 +345,7 @@ public class KVMStorageProcessor implements StorageProcessor { secondaryPool.refresh(); final List disks = secondaryPool.listPhysicalDisks(); if (disks == null || disks.isEmpty()) { - s_logger.error("Failed to get volumes from pool: " + secondaryPool.getUuid()); + logger.error("Failed to get volumes from pool: " + secondaryPool.getUuid()); return null; } for (final KVMPhysicalDisk disk : disks) { @@ -354,7 +355,7 @@ public class KVMStorageProcessor implements StorageProcessor { } } if (templateVol == null) { - s_logger.error("Failed to get template from pool: " + secondaryPool.getUuid()); + logger.error("Failed to get template from pool: " + secondaryPool.getUuid()); return null; } } else { @@ -364,17 +365,17 @@ public class KVMStorageProcessor implements StorageProcessor { /* Copy volume to primary storage */ if (size > templateVol.getSize()) { - s_logger.debug("Overriding provided template's size with new size " + toHumanReadableSize(size)); + logger.debug("Overriding provided template's size with new size " + toHumanReadableSize(size)); templateVol.setSize(size); templateVol.setVirtualSize(size); } else { - s_logger.debug("Using templates disk size of " + toHumanReadableSize(templateVol.getVirtualSize()) + "since size passed was " + toHumanReadableSize(size)); + logger.debug("Using templates disk size of " + toHumanReadableSize(templateVol.getVirtualSize()) + "since size passed was " + toHumanReadableSize(size)); } final KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(templateVol, volUuid, primaryPool, timeout); return primaryVol; } catch (final CloudRuntimeException e) { - s_logger.error("Failed to download template to primary storage", e); + logger.error("Failed to download template to primary storage", e); return null; } finally { if (secondaryPool != null) { @@ -403,22 +404,22 @@ public class KVMStorageProcessor implements StorageProcessor { if (primaryPool.getType() == StoragePoolType.CLVM) { templatePath = ((NfsTO)imageStore).getUrl() + File.separator + templatePath; vol = templateToPrimaryDownload(templatePath, primaryPool, volume.getUuid(), volume.getSize(), cmd.getWaitInMillSeconds()); - } if (primaryPool.getType() == StoragePoolType.PowerFlex) { + } if (storagePoolMgr.supportsPhysicalDiskCopy(primaryPool.getType())) { Map details = primaryStore.getDetails(); String path = details != null ? details.get("managedStoreTarget") : null; if (!storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath, details)) { - s_logger.warn("Failed to connect base template volume at path: " + templatePath + ", in storage pool id: " + primaryStore.getUuid()); + logger.warn("Failed to connect base template volume at path: " + templatePath + ", in storage pool id: " + primaryStore.getUuid()); } BaseVol = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath); if (BaseVol == null) { - s_logger.debug("Failed to get the physical disk for base template volume at path: " + templatePath); + logger.debug("Failed to get the physical disk for base template volume at path: " + templatePath); throw new CloudRuntimeException("Failed to get the physical disk for base template volume at path: " + templatePath); } if (!storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path, details)) { - s_logger.warn("Failed to connect new volume at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); + logger.warn("Failed to connect new volume at path: " + path + ", in storage pool id: " + primaryStore.getUuid()); } vol = storagePoolMgr.copyPhysicalDisk(BaseVol, path != null ? path : volume.getUuid(), primaryPool, cmd.getWaitInMillSeconds(), null, volume.getPassphrase(), volume.getProvisioningType()); @@ -454,7 +455,7 @@ public class KVMStorageProcessor implements StorageProcessor { return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to create volume: ", e); + logger.debug("Failed to create volume: ", e); return new CopyCmdAnswer(e.toString()); } finally { volume.clearPassphrase(); @@ -524,7 +525,7 @@ public class KVMStorageProcessor implements StorageProcessor { return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to copyVolumeFromImageCacheToPrimary: ", e); + logger.debug("Failed to copyVolumeFromImageCacheToPrimary: ", e); return new CopyCmdAnswer(e.toString()); } finally { @@ -572,7 +573,7 @@ public class KVMStorageProcessor implements StorageProcessor { newVol.setFormat(destFormat); return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to copyVolumeFromPrimaryToSecondary: ", e); + logger.debug("Failed to copyVolumeFromPrimaryToSecondary: ", e); return new CopyCmdAnswer(e.toString()); } finally { srcVol.clearPassphrase(); @@ -623,7 +624,7 @@ public class KVMStorageProcessor implements StorageProcessor { final String templateName = UUID.randomUUID().toString(); if (primary.getType() != StoragePoolType.RBD) { - final Script command = new Script(_createTmplPath, wait, s_logger); + final Script command = new Script(_createTmplPath, wait, logger); command.add("-f", disk.getPath()); command.add("-t", tmpltPath); command.add(NAME_OPTION, templateName + ".qcow2"); @@ -631,11 +632,11 @@ public class KVMStorageProcessor implements StorageProcessor { final String result = command.execute(); if (result != null) { - s_logger.debug("failed to create template: " + result); + logger.debug("failed to create template: " + result); return new CopyCmdAnswer(result); } } else { - s_logger.debug("Converting RBD disk " + disk.getPath() + " into template " + templateName); + logger.debug("Converting RBD disk " + disk.getPath() + " into template " + templateName); final QemuImgFile srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(), primary.getSourcePort(), primary.getAuthUserName(), @@ -697,13 +698,13 @@ public class KVMStorageProcessor implements StorageProcessor { return new CopyCmdAnswer(newTemplate); } catch (final QemuImgException e) { - s_logger.error(e.getMessage()); + logger.error(e.getMessage()); return new CopyCmdAnswer(e.toString()); } catch (final IOException e) { - s_logger.debug("Failed to createTemplateFromVolume: ", e); + logger.debug("Failed to createTemplateFromVolume: ", e); return new CopyCmdAnswer(e.toString()); } catch (final Exception e) { - s_logger.debug("Failed to createTemplateFromVolume: ", e); + logger.debug("Failed to createTemplateFromVolume: ", e); return new CopyCmdAnswer(e.toString()); } finally { volume.clearPassphrase(); @@ -779,7 +780,7 @@ public class KVMStorageProcessor implements StorageProcessor { String templateName = UUID.randomUUID().toString(); - s_logger.debug("Converting " + srcDisk.getFormat().toString() + " disk " + srcDisk.getPath() + " into template " + templateName); + logger.debug("Converting " + srcDisk.getFormat().toString() + " disk " + srcDisk.getPath() + " into template " + templateName); String destName = templateFolder + "/" + templateName + ".qcow2"; @@ -838,10 +839,10 @@ public class KVMStorageProcessor implements StorageProcessor { return new CopyCmdAnswer(newTemplate); } catch (Exception ex) { if (isVolume) { - s_logger.debug("Failed to create template from volume: ", ex); + logger.debug("Failed to create template from volume: ", ex); } else { - s_logger.debug("Failed to create template from snapshot: ", ex); + logger.debug("Failed to create template from snapshot: ", ex); } return new CopyCmdAnswer(ex.toString()); @@ -890,7 +891,7 @@ public class KVMStorageProcessor implements StorageProcessor { newSnapshot.setPath(destPath); return new CopyCmdAnswer(newSnapshot); } catch (final Exception e) { - s_logger.error("failed to upload" + srcPath, e); + logger.error("failed to upload" + srcPath, e); return new CopyCmdAnswer("failed to upload" + srcPath + e.toString()); } finally { try { @@ -901,7 +902,7 @@ public class KVMStorageProcessor implements StorageProcessor { srcStorePool.delete(); } } catch (final Exception e) { - s_logger.debug("Failed to clean up:", e); + logger.debug("Failed to clean up:", e); } } } @@ -980,10 +981,10 @@ public class KVMStorageProcessor implements StorageProcessor { final String rbdSnapshot = snapshotDisk.getPath() + "@" + snapshotName; final String snapshotFile = snapshotDestPath + "/" + snapshotName; try { - s_logger.debug("Attempting to backup RBD snapshot " + rbdSnapshot); + logger.debug("Attempting to backup RBD snapshot " + rbdSnapshot); final File snapDir = new File(snapshotDestPath); - s_logger.debug("Attempting to create " + snapDir.getAbsolutePath() + " recursively for snapshot storage"); + logger.debug("Attempting to create " + snapDir.getAbsolutePath() + " recursively for snapshot storage"); FileUtils.forceMkdir(snapDir); final QemuImgFile srcFile = @@ -994,7 +995,7 @@ public class KVMStorageProcessor implements StorageProcessor { final QemuImgFile destFile = new QemuImgFile(snapshotFile); destFile.setFormat(PhysicalDiskFormat.QCOW2); - s_logger.debug("Backing up RBD snapshot " + rbdSnapshot + " to " + snapshotFile); + logger.debug("Backing up RBD snapshot " + rbdSnapshot + " to " + snapshotFile); final QemuImg q = new QemuImg(cmd.getWaitInMillSeconds()); q.convert(srcFile, destFile); @@ -1003,20 +1004,20 @@ public class KVMStorageProcessor implements StorageProcessor { size = snapFile.length(); } - s_logger.debug("Finished backing up RBD snapshot " + rbdSnapshot + " to " + snapshotFile + " Snapshot size: " + toHumanReadableSize(size)); + logger.debug("Finished backing up RBD snapshot " + rbdSnapshot + " to " + snapshotFile + " Snapshot size: " + toHumanReadableSize(size)); } catch (final FileNotFoundException e) { - s_logger.error("Failed to open " + snapshotDestPath + ". The error was: " + e.getMessage()); + logger.error("Failed to open " + snapshotDestPath + ". The error was: " + e.getMessage()); return new CopyCmdAnswer(e.toString()); } catch (final IOException e) { - s_logger.error("Failed to create " + snapshotDestPath + ". The error was: " + e.getMessage()); + logger.error("Failed to create " + snapshotDestPath + ". The error was: " + e.getMessage()); return new CopyCmdAnswer(e.toString()); } catch (final QemuImgException | LibvirtException e) { - s_logger.error("Failed to backup the RBD snapshot from " + rbdSnapshot + + logger.error("Failed to backup the RBD snapshot from " + rbdSnapshot + " to " + snapshotFile + " the error was: " + e.getMessage()); return new CopyCmdAnswer(e.toString()); } } else { - final Script command = new Script(_manageSnapshotPath, cmd.getWaitInMillSeconds(), s_logger); + final Script command = new Script(_manageSnapshotPath, cmd.getWaitInMillSeconds(), logger); command.add("-b", isCreatedFromVmSnapshot ? snapshotDisk.getPath() : snapshot.getPath()); command.add(NAME_OPTION, snapshotName); command.add("-p", snapshotDestPath); @@ -1026,7 +1027,7 @@ public class KVMStorageProcessor implements StorageProcessor { command.add("-t", descName); final String result = command.execute(); if (result != null) { - s_logger.debug("Failed to backup snaptshot: " + result); + logger.debug("Failed to backup snaptshot: " + result); return new CopyCmdAnswer(result); } final File snapFile = new File(snapshotDestPath + "/" + descName); @@ -1040,12 +1041,12 @@ public class KVMStorageProcessor implements StorageProcessor { newSnapshot.setPhysicalSize(size); return new CopyCmdAnswer(newSnapshot); } catch (final LibvirtException | CloudRuntimeException e) { - s_logger.debug("Failed to backup snapshot: ", e); + logger.debug("Failed to backup snapshot: ", e); return new CopyCmdAnswer(e.toString()); } finally { srcVolume.clearPassphrase(); if (isCreatedFromVmSnapshot) { - s_logger.debug("Ignoring removal of vm snapshot on primary as this snapshot is created from vm snapshot"); + logger.debug("Ignoring removal of vm snapshot on primary as this snapshot is created from vm snapshot"); } else if (primaryPool.getType() != StoragePoolType.RBD) { deleteSnapshotOnPrimary(cmd, snapshot, primaryPool); } @@ -1055,7 +1056,7 @@ public class KVMStorageProcessor implements StorageProcessor { secondaryStoragePool.delete(); } } catch (final Exception ex) { - s_logger.debug("Failed to delete secondary storage", ex); + logger.debug("Failed to delete secondary storage", ex); } } } @@ -1074,10 +1075,10 @@ public class KVMStorageProcessor implements StorageProcessor { try { Files.deleteIfExists(Paths.get(snapshotPath)); } catch (IOException ex) { - s_logger.error(String.format("Failed to delete snapshot [%s] on primary storage [%s].", snapshotPath, primaryPool.getUuid()), ex); + logger.error(String.format("Failed to delete snapshot [%s] on primary storage [%s].", snapshotPath, primaryPool.getUuid()), ex); } } else { - s_logger.debug(String.format("This backup is temporary, not deleting snapshot [%s] on primary storage [%s]", snapshotPath, primaryPool.getUuid())); + logger.debug(String.format("This backup is temporary, not deleting snapshot [%s] on primary storage [%s]", snapshotPath, primaryPool.getUuid())); } } @@ -1164,7 +1165,7 @@ public class KVMStorageProcessor implements StorageProcessor { private String getDataStoreUrlFromStore(DataStoreTO store) { List supportedPoolType = List.of(StoragePoolType.NetworkFilesystem, StoragePoolType.Filesystem); if (!(store instanceof NfsTO) && (!(store instanceof PrimaryDataStoreTO) || !supportedPoolType.contains(((PrimaryDataStoreTO) store).getPoolType()))) { - s_logger.error(String.format("Unsupported protocol, store: %s", store.getUuid())); + logger.error(String.format("Unsupported protocol, store: %s", store.getUuid())); throw new InvalidParameterValueException("unsupported protocol"); } @@ -1208,11 +1209,11 @@ public class KVMStorageProcessor implements StorageProcessor { dm = conn.domainLookupByName(vmName); if (attach) { - s_logger.debug("Attaching device: " + diskXml); + logger.debug("Attaching device: " + diskXml); dm.attachDevice(diskXml); return; } - s_logger.debug(String.format("Detaching device: [%s].", diskXml)); + logger.debug(String.format("Detaching device: [%s].", diskXml)); dm.detachDevice(diskXml); long wait = waitDetachDevice; while (!checkDetachSuccess(diskPath, dm) && wait > 0) { @@ -1223,13 +1224,13 @@ public class KVMStorageProcessor implements StorageProcessor { "not support the sent detach command or the device is busy at the moment. Try again in a couple of minutes.", waitDetachDevice)); } - s_logger.debug(String.format("The detach command was executed successfully. The device [%s] was removed from the VM instance with UUID [%s].", + logger.debug(String.format("The detach command was executed successfully. The device [%s] was removed from the VM instance with UUID [%s].", diskPath, dm.getUUIDString())); } catch (final LibvirtException e) { if (attach) { - s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); + logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage()); } else { - s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); + logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage()); } throw e; } finally { @@ -1237,7 +1238,7 @@ public class KVMStorageProcessor implements StorageProcessor { try { dm.free(); } catch (final LibvirtException l) { - s_logger.trace("Ignoring libvirt error.", l); + logger.trace("Ignoring libvirt error.", l); } } } @@ -1252,7 +1253,7 @@ public class KVMStorageProcessor implements StorageProcessor { try { wait -= waitDelayForVirshCommands; Thread.sleep(waitDelayForVirshCommands); - s_logger.trace(String.format("Trying to detach device [%s] from VM instance with UUID [%s]. " + + logger.trace(String.format("Trying to detach device [%s] from VM instance with UUID [%s]. " + "Waiting [%s] milliseconds before assuming the VM was unable to detach the volume.", diskPath, dm.getUUIDString(), wait)); } catch (InterruptedException e) { throw new CloudRuntimeException(e); @@ -1272,7 +1273,7 @@ public class KVMStorageProcessor implements StorageProcessor { List disks = parser.getDisks(); for (DiskDef diskDef : disks) { if (StringUtils.equals(diskPath, diskDef.getDiskPath())) { - s_logger.debug(String.format("The hypervisor sent the detach command, but it is still possible to identify the device [%s] in the instance with UUID [%s].", + logger.debug(String.format("The hypervisor sent the detach command, but it is still possible to identify the device [%s] in the instance with UUID [%s].", diskPath, dm.getUUIDString())); return false; } @@ -1366,7 +1367,7 @@ public class KVMStorageProcessor implements StorageProcessor { if (resource.getHypervisorType() == Hypervisor.HypervisorType.LXC) { final String device = resource.mapRbdDevice(attachingDisk); if (device != null) { - s_logger.debug("RBD device on host is: "+device); + logger.debug("RBD device on host is: "+device); attachingDisk.setPath(device); } } @@ -1380,7 +1381,7 @@ public class KVMStorageProcessor implements StorageProcessor { } } if (diskdef == null) { - s_logger.warn(String.format("Could not find disk [%s] attached to VM instance with UUID [%s]. We will set it as detached in the database to ensure consistency.", + logger.warn(String.format("Could not find disk [%s] attached to VM instance with UUID [%s]. We will set it as detached in the database to ensure consistency.", attachingDisk.getPath(), dm.getUUIDString())); return; } @@ -1405,7 +1406,7 @@ public class KVMStorageProcessor implements StorageProcessor { // For LXC, map image to host and then attach to Vm final String device = resource.mapRbdDevice(attachingDisk); if (device != null) { - s_logger.debug("RBD device on host is: "+device); + logger.debug("RBD device on host is: "+device); diskdef.defBlockBasedDisk(device, devId, busT); } else { throw new InternalErrorException("Error while mapping disk "+attachingDisk.getPath()+" on host"); @@ -1481,6 +1482,8 @@ public class KVMStorageProcessor implements StorageProcessor { if (ioDriver != null) { resource.setDiskIoDriver(diskdef, resource.getIoDriverForTheStorage(ioDriver.toUpperCase())); } + diskdef.setPhysicalBlockIOSize(attachingPool.getSupportedPhysicalBlockSize()); + diskdef.setLogicalBlockIOSize(attachingPool.getSupportedLogicalBlockSize()); } attachOrDetachDevice(conn, attach, vmName, diskdef, waitDetachDevice); @@ -1512,7 +1515,7 @@ public class KVMStorageProcessor implements StorageProcessor { final KVMPhysicalDisk phyDisk = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath()); final String volCacheMode = vol.getCacheMode() == null ? null : vol.getCacheMode().toString(); - s_logger.debug(String.format("Attaching physical disk %s with format %s", phyDisk.getPath(), phyDisk.getFormat())); + logger.debug(String.format("Attaching physical disk %s with format %s", phyDisk.getPath(), phyDisk.getFormat())); attachOrDetachDisk(conn, true, vmName, phyDisk, disk.getDiskSeq().intValue(), serial, vol.getBytesReadRate(), vol.getBytesReadRateMax(), vol.getBytesReadRateMaxLength(), @@ -1522,14 +1525,14 @@ public class KVMStorageProcessor implements StorageProcessor { return new AttachAnswer(disk); } catch (final LibvirtException e) { - s_logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); storagePoolMgr.disconnectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), vol.getPath()); return new AttachAnswer(e.toString()); } catch (final InternalErrorException e) { - s_logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); return new AttachAnswer(e.toString()); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to attach volume: " + vol.getPath() + ", due to ", e); return new AttachAnswer(e.toString()); } finally { vol.clearPassphrase(); @@ -1560,13 +1563,13 @@ public class KVMStorageProcessor implements StorageProcessor { return new DettachAnswer(disk); } catch (final LibvirtException e) { - s_logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); return new DettachAnswer(e.toString()); } catch (final InternalErrorException e) { - s_logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); return new DettachAnswer(e.toString()); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); + logger.debug("Failed to detach volume: " + vol.getPath() + ", due to ", e); return new DettachAnswer(e.toString()); } finally { vol.clearPassphrase(); @@ -1595,7 +1598,7 @@ public class KVMStorageProcessor implements StorageProcessor { * Create full clone volume from VM snapshot */ protected KVMPhysicalDisk createFullCloneVolume(MigrationOptions migrationOptions, VolumeObjectTO volume, KVMStoragePool primaryPool, PhysicalDiskFormat format) { - s_logger.debug("For VM migration with full-clone volume: Creating empty stub disk for source disk " + migrationOptions.getSrcVolumeUuid() + " and size: " + toHumanReadableSize(volume.getSize()) + " and format: " + format); + logger.debug("For VM migration with full-clone volume: Creating empty stub disk for source disk " + migrationOptions.getSrcVolumeUuid() + " and size: " + toHumanReadableSize(volume.getSize()) + " and format: " + format); return primaryPool.createPhysicalDisk(volume.getUuid(), format, volume.getProvisioningType(), volume.getSize(), volume.getPassphrase()); } @@ -1647,7 +1650,7 @@ public class KVMStorageProcessor implements StorageProcessor { return new CreateObjectAnswer(newVol); } catch (final Exception e) { - s_logger.debug("Failed to create volume: ", e); + logger.debug("Failed to create volume: ", e); return new CreateObjectAnswer(e.toString()); } finally { volume.clearPassphrase(); @@ -1722,7 +1725,7 @@ public class KVMStorageProcessor implements StorageProcessor { vm = resource.getDomain(conn, vmName); state = vm.getInfo().state; } catch (final LibvirtException e) { - s_logger.trace("Ignoring libvirt error.", e); + logger.trace("Ignoring libvirt error.", e); } } @@ -1754,7 +1757,7 @@ public class KVMStorageProcessor implements StorageProcessor { throw e; } - s_logger.info(String.format("It was not possible to take live disk snapshot for volume [%s], in VM [%s], due to [%s]. We will take full snapshot of the VM" + logger.info(String.format("It was not possible to take live disk snapshot for volume [%s], in VM [%s], due to [%s]. We will take full snapshot of the VM" + " and extract the disk instead. Consider upgrading your QEMU binary.", volume, vmName, e.getMessage())); takeFullVmSnapshotForBinariesThatDoesNotSupportLiveDiskSnapshot(vm, snapshotName, vmName); @@ -1793,22 +1796,22 @@ public class KVMStorageProcessor implements StorageProcessor { final Rbd rbd = new Rbd(io); final RbdImage image = rbd.open(disk.getName()); - s_logger.debug("Attempting to create RBD snapshot " + disk.getName() + "@" + snapshotName); + logger.debug("Attempting to create RBD snapshot " + disk.getName() + "@" + snapshotName); image.snapCreate(snapshotName); rbd.close(image); r.ioCtxDestroy(io); } catch (final Exception e) { - s_logger.error("A RBD snapshot operation on " + disk.getName() + " failed. The error was: " + e.getMessage()); + logger.error("A RBD snapshot operation on " + disk.getName() + " failed. The error was: " + e.getMessage()); } } else if (primaryPool.getType() == StoragePoolType.CLVM) { /* VM is not running, create a snapshot by ourself */ - final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, s_logger); + final Script command = new Script(_manageSnapshotPath, _cmdsTimeout, logger); command.add(MANAGE_SNAPSTHOT_CREATE_OPTION, disk.getPath()); command.add(NAME_OPTION, snapshotName); final String result = command.execute(); if (result != null) { - s_logger.debug("Failed to manage snapshot: " + result); + logger.debug("Failed to manage snapshot: " + result); return new CreateObjectAnswer("Failed to manage snapshot: " + result); } } else { @@ -1824,7 +1827,7 @@ public class KVMStorageProcessor implements StorageProcessor { return new CreateObjectAnswer(newSnapshot); } catch (CloudRuntimeException | LibvirtException | IOException ex) { String errorMsg = String.format("Failed take snapshot for volume [%s], in VM [%s], due to [%s].", volume, vmName, ex.getMessage()); - s_logger.error(errorMsg, ex); + logger.error(errorMsg, ex); return new CreateObjectAnswer(errorMsg); } finally { volume.clearPassphrase(); @@ -1832,7 +1835,7 @@ public class KVMStorageProcessor implements StorageProcessor { } protected void deleteFullVmSnapshotAfterConvertingItToExternalDiskSnapshot(Domain vm, String snapshotName, VolumeObjectTO volume, String vmName) throws LibvirtException { - s_logger.debug(String.format("Deleting full VM snapshot [%s] of VM [%s] as we already converted it to an external disk snapshot of the volume [%s].", snapshotName, vmName, + logger.debug(String.format("Deleting full VM snapshot [%s] of VM [%s] as we already converted it to an external disk snapshot of the volume [%s].", snapshotName, vmName, volume)); DomainSnapshot domainSnapshot = vm.snapshotLookupByName(snapshotName); @@ -1846,13 +1849,13 @@ public class KVMStorageProcessor implements StorageProcessor { try { QemuImg qemuImg = new QemuImg(_cmdsTimeout); - s_logger.debug(String.format("Converting full VM snapshot [%s] of VM [%s] to external disk snapshot of the volume [%s].", snapshotName, vmName, volume)); + logger.debug(String.format("Converting full VM snapshot [%s] of VM [%s] to external disk snapshot of the volume [%s].", snapshotName, vmName, volume)); qemuImg.convert(srcFile, destFile, null, snapshotName, true); } catch (QemuImgException qemuException) { String message = String.format("Could not convert full VM snapshot [%s] of VM [%s] to external disk snapshot of volume [%s] due to [%s].", snapshotName, vmName, volume, qemuException.getMessage()); - s_logger.error(message, qemuException); + logger.error(message, qemuException); throw new CloudRuntimeException(message, qemuException); } finally { deleteFullVmSnapshotAfterConvertingItToExternalDiskSnapshot(vm, snapshotName, volume, vmName); @@ -1864,7 +1867,7 @@ public class KVMStorageProcessor implements StorageProcessor { long start = System.currentTimeMillis(); vm.snapshotCreateXML(String.format(XML_CREATE_FULL_VM_SNAPSHOT, snapshotName, vmUuid)); - s_logger.debug(String.format("Full VM Snapshot [%s] of VM [%s] took [%s] seconds to finish.", snapshotName, vmName, (System.currentTimeMillis() - start)/1000)); + logger.debug(String.format("Full VM Snapshot [%s] of VM [%s] took [%s] seconds to finish.", snapshotName, vmName, (System.currentTimeMillis() - start)/1000)); } protected void validateConvertResult(String convertResult, String snapshotPath) throws CloudRuntimeException, IOException { @@ -1892,7 +1895,7 @@ public class KVMStorageProcessor implements StorageProcessor { String mergeResult = Script.runSimpleBashScript(mergeCommand); if (mergeResult == null) { - s_logger.debug(String.format("Successfully merged snapshot [%s] into VM [%s] %s base file.", snapshotName, vmName, volume)); + logger.debug(String.format("Successfully merged snapshot [%s] into VM [%s] %s base file.", snapshotName, vmName, volume)); manuallyDeleteUnusedSnapshotFile(isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit, getSnapshotTemporaryPath(baseFilePath, snapshotName)); return; } @@ -1901,7 +1904,7 @@ public class KVMStorageProcessor implements StorageProcessor { + " will start to write in the base file again. All changes made between the snapshot and the VM stop will be in the snapshot. If the VM is stopped, the snapshot must be" + " merged into the base file manually.", snapshotName, vmName, volume, mergeCommand, mergeResult); - s_logger.warn(String.format("%s VM XML: [%s].", errorMsg, vm.getXMLDesc(0))); + logger.warn(String.format("%s VM XML: [%s].", errorMsg, vm.getXMLDesc(0))); throw new CloudRuntimeException(errorMsg); } @@ -1913,17 +1916,17 @@ public class KVMStorageProcessor implements StorageProcessor { */ protected void manuallyDeleteUnusedSnapshotFile(boolean isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit, String snapshotPath) { if (isLibvirtSupportingFlagDeleteOnCommandVirshBlockcommit) { - s_logger.debug(String.format("The current Libvirt's version supports the flag '--delete' on command 'virsh blockcommit', we will skip the manually deletion of the" + logger.debug(String.format("The current Libvirt's version supports the flag '--delete' on command 'virsh blockcommit', we will skip the manually deletion of the" + " unused snapshot file [%s] as it already was automatically deleted.", snapshotPath)); return; } - s_logger.debug(String.format("The current Libvirt's version does not supports the flag '--delete' on command 'virsh blockcommit', therefore we will manually delete the" + logger.debug(String.format("The current Libvirt's version does not supports the flag '--delete' on command 'virsh blockcommit', therefore we will manually delete the" + " unused snapshot file [%s].", snapshotPath)); try { Files.deleteIfExists(Paths.get(snapshotPath)); - s_logger.debug(String.format("Manually deleted unused snapshot file [%s].", snapshotPath)); + logger.debug(String.format("Manually deleted unused snapshot file [%s].", snapshotPath)); } catch (IOException ex) { throw new CloudRuntimeException(String.format("Unable to manually delete unused snapshot file [%s] due to [%s].", snapshotPath, ex.getMessage())); } @@ -1938,7 +1941,7 @@ public class KVMStorageProcessor implements StorageProcessor { */ protected String convertBaseFileToSnapshotFileInPrimaryStorageDir(KVMStoragePool primaryPool, String baseFile, String snapshotPath, VolumeObjectTO volume, int wait) { try { - s_logger.debug(String.format("Trying to convert volume [%s] (%s) to snapshot [%s].", volume, baseFile, snapshotPath)); + logger.debug(String.format("Trying to convert volume [%s] (%s) to snapshot [%s].", volume, baseFile, snapshotPath)); primaryPool.createFolder(TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR); @@ -1951,7 +1954,7 @@ public class KVMStorageProcessor implements StorageProcessor { QemuImg q = new QemuImg(wait); q.convert(srcFile, destFile); - s_logger.debug(String.format("Converted volume [%s] (from path \"%s\") to snapshot [%s].", volume, baseFile, snapshotPath)); + logger.debug(String.format("Converted volume [%s] (from path \"%s\") to snapshot [%s].", volume, baseFile, snapshotPath)); return null; } catch (QemuImgException | LibvirtException ex) { return String.format("Failed to convert %s snapshot of volume [%s] to [%s] due to [%s].", volume, baseFile, snapshotPath, ex.getMessage()); @@ -1988,7 +1991,7 @@ public class KVMStorageProcessor implements StorageProcessor { long start = System.currentTimeMillis(); vm.snapshotCreateXML(createSnapshotXmlFormated, VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY); - s_logger.debug(String.format("Snapshot [%s] took [%s] seconds to finish.", snapshotName, (System.currentTimeMillis() - start)/1000)); + logger.debug(String.format("Snapshot [%s] took [%s] seconds to finish.", snapshotName, (System.currentTimeMillis() - start)/1000)); return diskLabelToSnapshot; } @@ -2062,7 +2065,7 @@ public class KVMStorageProcessor implements StorageProcessor { diskDescription)); } - s_logger.debug(String.format("Pool [%s] has enough available size [%s] to take volume [%s] snapshot.", poolDescription, availablePoolSize, diskDescription)); + logger.debug(String.format("Pool [%s] has enough available size [%s] to take volume [%s] snapshot.", poolDescription, availablePoolSize, diskDescription)); } protected boolean isAvailablePoolSizeDividedByDiskSizeLesserThanMinRate(long availablePoolSize, long diskSize) { @@ -2075,7 +2078,7 @@ public class KVMStorageProcessor implements StorageProcessor { r.confSet(CEPH_AUTH_KEY, primaryPool.getAuthSecret()); r.confSet(CEPH_CLIENT_MOUNT_TIMEOUT, CEPH_DEFAULT_MOUNT_TIMEOUT); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet(CEPH_MON_HOST)); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet(CEPH_MON_HOST)); return r; } @@ -2088,13 +2091,13 @@ public class KVMStorageProcessor implements StorageProcessor { try { pool.getPhysicalDisk(vol.getPath()); } catch (final Exception e) { - s_logger.debug("can't find volume: " + vol.getPath() + ", return true"); + logger.debug("can't find volume: " + vol.getPath() + ", return true"); return new Answer(null); } pool.deletePhysicalDisk(vol.getPath(), vol.getFormat()); return new Answer(null); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to delete volume: ", e); + logger.debug("Failed to delete volume: ", e); return new Answer(null, false, e.toString()); } finally { vol.clearPassphrase(); @@ -2136,7 +2139,7 @@ public class KVMStorageProcessor implements StorageProcessor { return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to createVolumeFromSnapshot: ", e); + logger.debug("Failed to createVolumeFromSnapshot: ", e); return new CopyCmdAnswer(e.toString()); } finally { volume.clearPassphrase(); @@ -2155,11 +2158,11 @@ public class KVMStorageProcessor implements StorageProcessor { VolumeObjectTO newVol = (VolumeObjectTO) destData; if (StoragePoolType.RBD.equals(primaryStore.getPoolType())) { - s_logger.debug(String.format("Attempting to create volume from RBD snapshot %s", snapshotName)); + logger.debug(String.format("Attempting to create volume from RBD snapshot %s", snapshotName)); if (StoragePoolType.RBD.equals(pool.getPoolType())) { disk = createRBDvolumeFromRBDSnapshot(snapshotDisk, snapshotName, newVol.getUuid(), PhysicalDiskFormat.RAW, newVol.getSize(), destPool, cmd.getWaitInMillSeconds()); - s_logger.debug(String.format("Created RBD volume %s from snapshot %s", disk, snapshotDisk)); + logger.debug(String.format("Created RBD volume %s from snapshot %s", disk, snapshotDisk)); } else { Map details = cmd.getOptions2(); @@ -2172,7 +2175,7 @@ public class KVMStorageProcessor implements StorageProcessor { destPool, cmd.getWaitInMillSeconds()); storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), path); - s_logger.debug(String.format("Created RBD volume %s from snapshot %s", disk, snapshotDisk)); + logger.debug(String.format("Created RBD volume %s from snapshot %s", disk, snapshotDisk)); } } @@ -2249,12 +2252,12 @@ public class KVMStorageProcessor implements StorageProcessor { } if (!snapFound) { - s_logger.debug(String.format("Could not find snapshot %s on RBD", snapshotName)); + logger.debug(String.format("Could not find snapshot %s on RBD", snapshotName)); return null; } srcImage.snapProtect(snapshotName); - s_logger.debug(String.format("Try to clone snapshot %s on RBD", snapshotName)); + logger.debug(String.format("Try to clone snapshot %s on RBD", snapshotName)); rbd.clone(volume.getName(), snapshotName, io, disk.getName(), LibvirtStorageAdaptor.RBD_FEATURES, 0); RbdImage diskImage = rbd.open(disk.getName()); if (disk.getVirtualSize() > volume.getVirtualSize()) { @@ -2268,7 +2271,7 @@ public class KVMStorageProcessor implements StorageProcessor { rbd.close(srcImage); r.ioCtxDestroy(io); } catch (RadosException | RbdException e) { - s_logger.error(String.format("Failed due to %s", e.getMessage()), e); + logger.error(String.format("Failed due to %s", e.getMessage()), e); disk = null; } @@ -2294,16 +2297,16 @@ public class KVMStorageProcessor implements StorageProcessor { Rbd rbd = new Rbd(io); RbdImage image = rbd.open(disk.getName()); try { - s_logger.info("Attempting to remove RBD snapshot " + snapshotFullName); + logger.info("Attempting to remove RBD snapshot " + snapshotFullName); if (image.snapIsProtected(snapshotName)) { - s_logger.debug("Unprotecting RBD snapshot " + snapshotFullName); + logger.debug("Unprotecting RBD snapshot " + snapshotFullName); image.snapUnprotect(snapshotName); } image.snapRemove(snapshotName); - s_logger.info("Snapshot " + snapshotFullName + " successfully removed from " + + logger.info("Snapshot " + snapshotFullName + " successfully removed from " + primaryPool.getType().toString() + " pool."); } catch (RbdException e) { - s_logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + + logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); } finally { rbd.close(image); @@ -2311,24 +2314,24 @@ public class KVMStorageProcessor implements StorageProcessor { } } else if (storagePoolTypesToDeleteSnapshotFile.contains(primaryPool.getType())) { - s_logger.info(String.format("Deleting snapshot (id=%s, name=%s, path=%s, storage type=%s) on primary storage", snapshotTO.getId(), snapshotTO.getName(), + logger.info(String.format("Deleting snapshot (id=%s, name=%s, path=%s, storage type=%s) on primary storage", snapshotTO.getId(), snapshotTO.getName(), snapshotTO.getPath(), primaryPool.getType())); deleteSnapshotFile(snapshotTO); } else { - s_logger.warn("Operation not implemented for storage pool type of " + primaryPool.getType().toString()); + logger.warn("Operation not implemented for storage pool type of " + primaryPool.getType().toString()); throw new InternalErrorException("Operation not implemented for storage pool type of " + primaryPool.getType().toString()); } return new Answer(cmd, true, "Snapshot " + snapshotFullName + " removed successfully."); } catch (RadosException e) { - s_logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + + logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); return new Answer(cmd, false, "Failed to remove snapshot " + snapshotFullName); } catch (RbdException e) { - s_logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + + logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); return new Answer(cmd, false, "Failed to remove snapshot " + snapshotFullName); } catch (Exception e) { - s_logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString()); + logger.error("Failed to remove snapshot " + snapshotFullName + ", with exception: " + e.toString()); return new Answer(cmd, false, "Failed to remove snapshot " + snapshotFullName); } finally { volume.clearPassphrase(); @@ -2342,7 +2345,7 @@ public class KVMStorageProcessor implements StorageProcessor { protected void deleteSnapshotFile(SnapshotObjectTO snapshotObjectTo) throws CloudRuntimeException { try { Files.deleteIfExists(Paths.get(snapshotObjectTo.getPath())); - s_logger.debug(String.format("Deleted snapshot [%s].", snapshotObjectTo)); + logger.debug(String.format("Deleted snapshot [%s].", snapshotObjectTo)); } catch (IOException ex) { throw new CloudRuntimeException(String.format("Unable to delete snapshot [%s] due to [%s].", snapshotObjectTo, ex.getMessage())); } @@ -2366,39 +2369,39 @@ public class KVMStorageProcessor implements StorageProcessor { KVMStoragePool destPool = null; try { - s_logger.debug("Verifying temporary location for downloading the template exists on the host"); + logger.debug("Verifying temporary location for downloading the template exists on the host"); String temporaryDownloadPath = resource.getDirectDownloadTemporaryDownloadPath(); if (!isLocationAccessible(temporaryDownloadPath)) { String msg = "The temporary location path for downloading templates does not exist: " + temporaryDownloadPath + " on this host"; - s_logger.error(msg); + logger.error(msg); return new DirectDownloadAnswer(false, msg, true); } Long templateSize = null; if (StringUtils.isNotBlank(cmd.getUrl())) { String url = cmd.getUrl(); - templateSize = UriUtils.getRemoteSize(url); + templateSize = UriUtils.getRemoteSize(url, cmd.isFollowRedirects()); } - s_logger.debug("Checking for free space on the host for downloading the template with physical size: " + templateSize + " and virtual size: " + cmd.getTemplateSize()); + logger.debug("Checking for free space on the host for downloading the template with physical size: " + templateSize + " and virtual size: " + cmd.getTemplateSize()); if (!isEnoughSpaceForDownloadTemplateOnTemporaryLocation(templateSize)) { String msg = "Not enough space on the defined temporary location to download the template " + cmd.getTemplateId(); - s_logger.error(msg); + logger.error(msg); return new DirectDownloadAnswer(false, msg, true); } destPool = storagePoolMgr.getStoragePool(pool.getPoolType(), pool.getUuid()); downloader = DirectDownloadHelper.getDirectTemplateDownloaderFromCommand(cmd, destPool.getLocalPath(), temporaryDownloadPath); - s_logger.debug("Trying to download template"); + logger.debug("Trying to download template"); Pair result = downloader.downloadTemplate(); if (!result.first()) { - s_logger.warn("Couldn't download template"); + logger.warn("Couldn't download template"); return new DirectDownloadAnswer(false, "Unable to download template", true); } String tempFilePath = result.second(); if (!downloader.validateChecksum()) { - s_logger.warn("Couldn't validate template checksum"); + logger.warn("Couldn't validate template checksum"); return new DirectDownloadAnswer(false, "Checksum validation failed", false); } @@ -2406,16 +2409,16 @@ public class KVMStorageProcessor implements StorageProcessor { String destTemplatePath = (destTemplate != null) ? destTemplate.getPath() : null; if (!storagePoolMgr.connectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath, null)) { - s_logger.warn("Unable to connect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); + logger.warn("Unable to connect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); } template = storagePoolMgr.createPhysicalDiskFromDirectDownloadTemplate(tempFilePath, destTemplatePath, destPool, cmd.getFormat(), cmd.getWaitInMillSeconds()); if (!storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), destTemplatePath)) { - s_logger.warn("Unable to disconnect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); + logger.warn("Unable to disconnect physical disk at path: " + destTemplatePath + ", in storage pool id: " + pool.getUuid()); } } catch (CloudRuntimeException e) { - s_logger.warn("Error downloading template " + cmd.getTemplateId() + " due to: " + e.getMessage()); + logger.warn("Error downloading template " + cmd.getTemplateId() + " due to: " + e.getMessage()); return new DirectDownloadAnswer(false, "Unable to download template: " + e.getMessage(), true); } catch (IllegalArgumentException e) { return new DirectDownloadAnswer(false, "Unable to create direct downloader: " + e.getMessage(), true); @@ -2441,18 +2444,18 @@ public class KVMStorageProcessor implements StorageProcessor { KVMStoragePool destPool = null; try { - s_logger.debug("Copying src volume (id: " + srcVol.getId() + ", format: " + srcFormat + ", path: " + srcVolumePath + ", primary storage: [id: " + srcPrimaryStore.getId() + ", type: " + srcPrimaryStore.getPoolType() + "]) to dest volume (id: " + + logger.debug("Copying src volume (id: " + srcVol.getId() + ", format: " + srcFormat + ", path: " + srcVolumePath + ", primary storage: [id: " + srcPrimaryStore.getId() + ", type: " + srcPrimaryStore.getPoolType() + "]) to dest volume (id: " + destVol.getId() + ", format: " + destFormat + ", path: " + destVolumePath + ", primary storage: [id: " + destPrimaryStore.getId() + ", type: " + destPrimaryStore.getPoolType() + "])."); if (srcPrimaryStore.isManaged()) { if (!storagePoolMgr.connectPhysicalDisk(srcPrimaryStore.getPoolType(), srcPrimaryStore.getUuid(), srcVolumePath, srcPrimaryStore.getDetails())) { - s_logger.warn("Failed to connect src volume at path: " + srcVolumePath + ", in storage pool id: " + srcPrimaryStore.getUuid()); + logger.warn("Failed to connect src volume at path: " + srcVolumePath + ", in storage pool id: " + srcPrimaryStore.getUuid()); } } final KVMPhysicalDisk volume = storagePoolMgr.getPhysicalDisk(srcPrimaryStore.getPoolType(), srcPrimaryStore.getUuid(), srcVolumePath); if (volume == null) { - s_logger.debug("Failed to get physical disk for volume: " + srcVolumePath); + logger.debug("Failed to get physical disk for volume: " + srcVolumePath); throw new CloudRuntimeException("Failed to get physical disk for volume at path: " + srcVolumePath); } @@ -2461,7 +2464,7 @@ public class KVMStorageProcessor implements StorageProcessor { String destVolumeName = null; if (destPrimaryStore.isManaged()) { if (!storagePoolMgr.connectPhysicalDisk(destPrimaryStore.getPoolType(), destPrimaryStore.getUuid(), destVolumePath, destPrimaryStore.getDetails())) { - s_logger.warn("Failed to connect dest volume at path: " + destVolumePath + ", in storage pool id: " + destPrimaryStore.getUuid()); + logger.warn("Failed to connect dest volume at path: " + destVolumePath + ", in storage pool id: " + destPrimaryStore.getUuid()); } String managedStoreTarget = destPrimaryStore.getDetails() != null ? destPrimaryStore.getDetails().get("managedStoreTarget") : null; destVolumeName = managedStoreTarget != null ? managedStoreTarget : destVolumePath; @@ -2480,7 +2483,7 @@ public class KVMStorageProcessor implements StorageProcessor { } } catch (Exception e) { // Any exceptions while copying the disk, should send failed answer with the error message String errMsg = String.format("Failed to copy volume: %s to dest storage: %s, due to %s", srcVol.getName(), destPrimaryStore.getName(), e.toString()); - s_logger.debug(errMsg, e); + logger.debug(errMsg, e); throw new CloudRuntimeException(errMsg); } finally { if (srcPrimaryStore.isManaged()) { @@ -2499,7 +2502,7 @@ public class KVMStorageProcessor implements StorageProcessor { newVol.setEncryptFormat(destVol.getEncryptFormat()); return new CopyCmdAnswer(newVol); } catch (final CloudRuntimeException e) { - s_logger.debug("Failed to copyVolumeFromPrimaryToPrimary: ", e); + logger.debug("Failed to copyVolumeFromPrimaryToPrimary: ", e); return new CopyCmdAnswer(e.toString()); } finally { srcVol.clearPassphrase(); @@ -2521,7 +2524,7 @@ public class KVMStorageProcessor implements StorageProcessor { */ protected boolean isEnoughSpaceForDownloadTemplateOnTemporaryLocation(Long templateSize) { if (templateSize == null || templateSize == 0L) { - s_logger.info("The server did not provide the template size, assuming there is enough space to download it"); + logger.info("The server did not provide the template size, assuming there is enough space to download it"); return true; } String cmd = String.format("df --output=avail %s -B 1 | tail -1", resource.getDirectDownloadTemporaryDownloadPath()); @@ -2531,7 +2534,7 @@ public class KVMStorageProcessor implements StorageProcessor { availableBytes = Long.parseLong(resultInBytes); } catch (NumberFormatException e) { String msg = "Could not parse the output " + resultInBytes + " as a number, therefore not able to check for free space"; - s_logger.error(msg, e); + logger.error(msg, e); return false; } return availableBytes >= templateSize; @@ -2539,13 +2542,13 @@ public class KVMStorageProcessor implements StorageProcessor { @Override public Answer checkDataStoreStoragePolicyCompliance(CheckDataStoreStoragePolicyComplainceCommand cmd) { - s_logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not currently applicable for KVMStorageProcessor"); + logger.info("'CheckDataStoreStoragePolicyComplainceCommand' not currently applicable for KVMStorageProcessor"); return new Answer(cmd,false,"Not currently applicable for KVMStorageProcessor"); } @Override public Answer syncVolumePath(SyncVolumePathCommand cmd) { - s_logger.info("SyncVolumePathCommand not currently applicable for KVMStorageProcessor"); + logger.info("SyncVolumePathCommand not currently applicable for KVMStorageProcessor"); return new Answer(cmd, false, "Not currently applicable for KVMStorageProcessor"); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index bdaa419c698..3002fea41d3 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -32,7 +32,8 @@ import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.cloudstack.utils.qemu.QemuObject; import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; import org.libvirt.LibvirtException; import org.libvirt.Secret; @@ -74,7 +75,7 @@ import java.util.stream.Collectors; public class LibvirtStorageAdaptor implements StorageAdaptor { - private static final Logger s_logger = Logger.getLogger(LibvirtStorageAdaptor.class); + protected Logger logger = LogManager.getLogger(getClass()); private StorageLayer _storageLayer; private String _mountPoint = "/mnt"; private String _manageSnapshotPath; @@ -106,7 +107,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { String mountPoint = _mountPoint + File.separator + uuid; if (localPath != null) { - s_logger.debug(String.format("Pool [%s] is of type local or shared mount point; therefore, we will use the local path [%s] to create the folder [%s] (if it does not" + logger.debug(String.format("Pool [%s] is of type local or shared mount point; therefore, we will use the local path [%s] to create the folder [%s] (if it does not" + " exist).", uuid, localPath, path)); mountPoint = localPath; @@ -126,18 +127,18 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { destPool.getType(), size, passphrase != null && passphrase.length > 0); if (!poolTypesThatEnableCreateDiskFromTemplateBacking.contains(destPool.getType())) { - s_logger.info(String.format("Skipping creation of %s due to pool type is none of the following types %s.", volumeDesc, poolTypesThatEnableCreateDiskFromTemplateBacking.stream() + logger.info(String.format("Skipping creation of %s due to pool type is none of the following types %s.", volumeDesc, poolTypesThatEnableCreateDiskFromTemplateBacking.stream() .map(type -> type.toString()).collect(Collectors.joining(", ")))); return null; } if (format != PhysicalDiskFormat.QCOW2) { - s_logger.info(String.format("Skipping creation of %s due to format [%s] is not [%s].", volumeDesc, format, PhysicalDiskFormat.QCOW2)); + logger.info(String.format("Skipping creation of %s due to format [%s] is not [%s].", volumeDesc, format, PhysicalDiskFormat.QCOW2)); return null; } - s_logger.info(String.format("Creating %s.", volumeDesc)); + logger.info(String.format("Creating %s.", volumeDesc)); String destPoolLocalPath = destPool.getLocalPath(); String destPath = String.format("%s%s%s", destPoolLocalPath, destPoolLocalPath.endsWith("/") ? "" : "/", name); @@ -152,13 +153,13 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { if (keyFile.isSet()) { passphraseObjects.add(QemuObject.prepareSecretForQemuImg(format, QemuObject.EncryptFormat.LUKS, keyFile.toString(), "sec0", options)); } - s_logger.debug(String.format("Passphrase is staged to keyFile: %s", keyFile.isSet())); + logger.debug(String.format("Passphrase is staged to keyFile: %s", keyFile.isSet())); QemuImg qemu = new QemuImg(timeout); qemu.create(destFile, backingFile, options, passphraseObjects); } catch (QemuImgException | LibvirtException | IOException e) { // why don't we throw an exception here? I guess we fail to find the volume later and that results in a failure returned? - s_logger.error(String.format("Failed to create %s in [%s] due to [%s].", volumeDesc, destPath, e.getMessage()), e); + logger.error(String.format("Failed to create %s in [%s] due to [%s].", volumeDesc, destPath, e.getMessage()), e); } return null; @@ -228,7 +229,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { try { vol = pool.storageVolLookupByName(volName); } catch (LibvirtException e) { - s_logger.debug("Could not find volume " + volName + ": " + e.getMessage()); + logger.debug("Could not find volume " + volName + ": " + e.getMessage()); } /** @@ -238,15 +239,15 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { */ if (vol == null) { try { - s_logger.debug("Refreshing storage pool " + pool.getName()); + logger.debug("Refreshing storage pool " + pool.getName()); refreshPool(pool); } catch (LibvirtException e) { - s_logger.debug("Failed to refresh storage pool: " + e.getMessage()); + logger.debug("Failed to refresh storage pool: " + e.getMessage()); } try { vol = pool.storageVolLookupByName(volName); - s_logger.debug("Found volume " + volName + " in storage pool " + pool.getName() + " after refreshing the pool"); + logger.debug("Found volume " + volName + " in storage pool " + pool.getName() + " after refreshing the pool"); } catch (LibvirtException e) { throw new CloudRuntimeException("Could not find volume " + volName + ": " + e.getMessage()); } @@ -257,7 +258,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { public StorageVol createVolume(Connect conn, StoragePool pool, String uuid, long size, VolumeFormat format) throws LibvirtException { LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), size, format, null, null); - s_logger.debug(volDef.toString()); + logger.debug(volDef.toString()); return pool.storageVolCreateXML(volDef.toString(), 0); } @@ -268,7 +269,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { refreshPool(pool); } } catch (LibvirtException e) { - s_logger.debug("refresh storage pool failed: " + e.toString()); + logger.debug("refresh storage pool failed: " + e.toString()); } } @@ -278,24 +279,24 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { _storageLayer.mkdir(targetPath); StoragePool sp = null; try { - s_logger.debug(spd.toString()); + logger.debug(spd.toString()); // check whether the pool is already mounted int mountpointResult = Script.runSimpleBashScriptForExitValue("mountpoint -q " + targetPath); // if the pool is mounted, try to unmount it if(mountpointResult == 0) { - s_logger.info("Attempting to unmount old mount at " + targetPath); + logger.info("Attempting to unmount old mount at " + targetPath); String result = Script.runSimpleBashScript("umount -l " + targetPath); if (result == null) { - s_logger.info("Succeeded in unmounting " + targetPath); + logger.info("Succeeded in unmounting " + targetPath); } else { - s_logger.error("Failed in unmounting storage"); + logger.error("Failed in unmounting storage"); } } sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { - s_logger.error(e.toString()); + logger.error(e.toString()); throw e; } } @@ -303,17 +304,17 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { private StoragePool createSharedStoragePool(Connect conn, String uuid, String host, String path) { String mountPoint = path; if (!_storageLayer.exists(mountPoint)) { - s_logger.error(mountPoint + " does not exists. Check local.storage.path in agent.properties."); + logger.error(mountPoint + " does not exists. Check local.storage.path in agent.properties."); return null; } LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.DIR, uuid, uuid, host, path, path); StoragePool sp = null; try { - s_logger.debug(spd.toString()); + logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { - s_logger.error(e.toString()); + logger.error(e.toString()); if (sp != null) { try { if (sp.isPersistent() == 1) { @@ -324,7 +325,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } sp.free(); } catch (LibvirtException l) { - s_logger.debug("Failed to define shared mount point storage pool with: " + l.toString()); + logger.debug("Failed to define shared mount point storage pool with: " + l.toString()); } } return null; @@ -337,14 +338,14 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { String volgroupName = path; volgroupName = volgroupName.replaceFirst("/", ""); - LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.LOGICAL, volgroupName, uuid, host, volgroupPath, volgroupPath); + LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(PoolType.loggerICAL, volgroupName, uuid, host, volgroupPath, volgroupPath); StoragePool sp = null; try { - s_logger.debug(spd.toString()); + logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { - s_logger.error(e.toString()); + logger.error(e.toString()); if (sp != null) { try { if (sp.isPersistent() == 1) { @@ -355,7 +356,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } sp.free(); } catch (LibvirtException l) { - s_logger.debug("Failed to define clvm storage pool with: " + l.toString()); + logger.debug("Failed to define clvm storage pool with: " + l.toString()); } } return null; @@ -376,17 +377,17 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { sd.setCephName(userInfoTemp[0] + "@" + host + ":" + port + "/" + path); try { - s_logger.debug(sd.toString()); + logger.debug(sd.toString()); s = conn.secretDefineXML(sd.toString()); s.setValue(Base64.decodeBase64(userInfoTemp[1])); } catch (LibvirtException e) { - s_logger.error("Failed to define the libvirt secret: " + e.toString()); + logger.error("Failed to define the libvirt secret: " + e.toString()); if (s != null) { try { s.undefine(); s.free(); } catch (LibvirtException l) { - s_logger.error("Failed to undefine the libvirt secret: " + l.toString()); + logger.error("Failed to undefine the libvirt secret: " + l.toString()); } } return null; @@ -397,11 +398,11 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } try { - s_logger.debug(spd.toString()); + logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); return sp; } catch (LibvirtException e) { - s_logger.error("Failed to create RBD storage pool: " + e.toString()); + logger.error("Failed to create RBD storage pool: " + e.toString()); if (sp != null) { try { if (sp.isPersistent() == 1) { @@ -412,17 +413,17 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } sp.free(); } catch (LibvirtException l) { - s_logger.error("Failed to undefine RBD storage pool: " + l.toString()); + logger.error("Failed to undefine RBD storage pool: " + l.toString()); } } if (s != null) { try { - s_logger.error("Failed to create the RBD storage pool, cleaning up the libvirt secret"); + logger.error("Failed to create the RBD storage pool, cleaning up the libvirt secret"); s.undefine(); s.free(); } catch (LibvirtException se) { - s_logger.error("Failed to remove the libvirt secret: " + se.toString()); + logger.error("Failed to remove the libvirt secret: " + se.toString()); } } @@ -459,6 +460,12 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { return parser.parseStorageVolumeXML(volDefXML); } + @Override + public StoragePoolType getStoragePoolType() { + // This is mapped manually in KVMStoragePoolManager + return null; + } + @Override public KVMStoragePool getStoragePool(String uuid) { return this.getStoragePool(uuid, false); @@ -466,14 +473,14 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { @Override public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) { - s_logger.info("Trying to fetch storage pool " + uuid + " from libvirt"); + logger.info("Trying to fetch storage pool " + uuid + " from libvirt"); StoragePool storage = null; try { Connect conn = LibvirtConnection.getConnection(); storage = conn.storagePoolLookupByUUIDString(uuid); if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) { - s_logger.warn("Storage pool " + uuid + " is not in running state. Attempting to start it."); + logger.warn("Storage pool " + uuid + " is not in running state. Attempting to start it."); storage.create(0); } LibvirtStoragePoolDef spd = getStoragePoolDef(conn, storage); @@ -487,7 +494,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { type = StoragePoolType.Filesystem; } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.RBD) { type = StoragePoolType.RBD; - } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.LOGICAL) { + } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.loggerICAL) { type = StoragePoolType.CLVM; } else if (spd.getPoolType() == LibvirtStoragePoolDef.PoolType.GLUSTERFS) { type = StoragePoolType.Gluster; @@ -529,21 +536,21 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { * refresh the pool */ if (refreshInfo) { - s_logger.info("Asking libvirt to refresh storage pool " + uuid); + logger.info("Asking libvirt to refresh storage pool " + uuid); pool.refresh(); } pool.setCapacity(storage.getInfo().capacity); pool.setUsed(storage.getInfo().allocation); pool.setAvailable(storage.getInfo().available); - s_logger.debug("Successfully refreshed pool " + uuid + + logger.debug("Successfully refreshed pool " + uuid + " Capacity: " + toHumanReadableSize(storage.getInfo().capacity) + " Used: " + toHumanReadableSize(storage.getInfo().allocation) + " Available: " + toHumanReadableSize(storage.getInfo().available)); return pool; } catch (LibvirtException e) { - s_logger.debug("Could not find storage pool " + uuid + " in libvirt"); + logger.debug("Could not find storage pool " + uuid + " in libvirt"); throw new CloudRuntimeException(e.toString(), e); } } @@ -584,14 +591,14 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } return disk; } catch (LibvirtException e) { - s_logger.debug("Failed to get physical disk:", e); + logger.debug("Failed to get physical disk:", e); throw new CloudRuntimeException(e.toString()); } } @Override public KVMStoragePool createStoragePool(String name, String host, int port, String path, String userInfo, StoragePoolType type, Map details) { - s_logger.info("Attempting to create storage pool " + name + " (" + type.toString() + ") in libvirt"); + logger.info("Attempting to create storage pool " + name + " (" + type.toString() + ") in libvirt"); StoragePool sp = null; Connect conn = null; @@ -606,14 +613,14 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { if (sp != null && sp.isActive() == 0) { sp.undefine(); sp = null; - s_logger.info("Found existing defined storage pool " + name + ". It wasn't running, so we undefined it."); + logger.info("Found existing defined storage pool " + name + ". It wasn't running, so we undefined it."); } if (sp != null) { - s_logger.info("Found existing defined storage pool " + name + ", using it."); + logger.info("Found existing defined storage pool " + name + ", using it."); } } catch (LibvirtException e) { sp = null; - s_logger.warn("Storage pool " + name + " was not found running in libvirt. Need to create it."); + logger.warn("Storage pool " + name + " was not found running in libvirt. Need to create it."); } // libvirt strips trailing slashes off of path, we will too in order to match @@ -627,12 +634,12 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { // if anyone is, undefine the pool so we can define it as requested. // This should be safe since a pool in use can't be removed, and no // volumes are affected by unregistering the pool with libvirt. - s_logger.info("Didn't find an existing storage pool " + name + " by UUID, checking for pools with duplicate paths"); + logger.info("Didn't find an existing storage pool " + name + " by UUID, checking for pools with duplicate paths"); try { String[] poolnames = conn.listStoragePools(); for (String poolname : poolnames) { - s_logger.debug("Checking path of existing pool " + poolname + " against pool we want to create"); + logger.debug("Checking path of existing pool " + poolname + " against pool we want to create"); StoragePool p = conn.storagePoolLookupByName(poolname); LibvirtStoragePoolDef pdef = getStoragePoolDef(conn, p); if (pdef == null) { @@ -641,7 +648,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { String targetPath = pdef.getTargetPath(); if (targetPath != null && targetPath.equals(path)) { - s_logger.debug("Storage pool utilizing path '" + path + "' already exists as pool " + poolname + + logger.debug("Storage pool utilizing path '" + path + "' already exists as pool " + poolname + ", undefining so we can re-define with correct name " + name); if (p.isPersistent() == 1) { p.destroy(); @@ -652,25 +659,25 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } } } catch (LibvirtException e) { - s_logger.error("Failure in attempting to see if an existing storage pool might be using the path of the pool to be created:" + e); + logger.error("Failure in attempting to see if an existing storage pool might be using the path of the pool to be created:" + e); } - s_logger.debug("Attempting to create storage pool " + name); + logger.debug("Attempting to create storage pool " + name); if (type == StoragePoolType.NetworkFilesystem) { try { sp = createNetfsStoragePool(PoolType.NETFS, conn, name, host, path); } catch (LibvirtException e) { - s_logger.error("Failed to create netfs mount: " + host + ":" + path , e); - s_logger.error(e.getStackTrace()); + logger.error("Failed to create netfs mount: " + host + ":" + path , e); + logger.error(e.getStackTrace()); throw new CloudRuntimeException(e.toString()); } } else if (type == StoragePoolType.Gluster) { try { sp = createNetfsStoragePool(PoolType.GLUSTERFS, conn, name, host, path); } catch (LibvirtException e) { - s_logger.error("Failed to create glusterfs mount: " + host + ":" + path , e); - s_logger.error(e.getStackTrace()); + logger.error("Failed to create glusterfs mount: " + host + ":" + path , e); + logger.error(e.getStackTrace()); throw new CloudRuntimeException(e.toString()); } } else if (type == StoragePoolType.SharedMountPoint || type == StoragePoolType.Filesystem) { @@ -688,7 +695,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { try { if (sp.isActive() == 0) { - s_logger.debug("Attempting to activate pool " + name); + logger.debug("Attempting to activate pool " + name); sp.create(0); } @@ -707,7 +714,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { @Override public boolean deleteStoragePool(String uuid) { - s_logger.info("Attempting to remove storage pool " + uuid + " from libvirt"); + logger.info("Attempting to remove storage pool " + uuid + " from libvirt"); Connect conn = null; try { conn = LibvirtConnection.getConnection(); @@ -721,7 +728,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { try { sp = conn.storagePoolLookupByUUIDString(uuid); } catch (LibvirtException e) { - s_logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed"); + logger.warn("Storage pool " + uuid + " doesn't exist in libvirt. Assuming it is already removed"); return true; } @@ -732,7 +739,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { try { s = conn.secretLookupByUUIDString(uuid); } catch (LibvirtException e) { - s_logger.info("Storage pool " + uuid + " has no corresponding secret. Not removing any secret."); + logger.info("Storage pool " + uuid + " has no corresponding secret. Not removing any secret."); } try { @@ -748,21 +755,21 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { s.free(); } - s_logger.info("Storage pool " + uuid + " was successfully removed from libvirt."); + logger.info("Storage pool " + uuid + " was successfully removed from libvirt."); return true; } catch (LibvirtException e) { // handle ebusy error when pool is quickly destroyed if (e.toString().contains("exit status 16")) { String targetPath = _mountPoint + File.separator + uuid; - s_logger.error("deleteStoragePool removed pool from libvirt, but libvirt had trouble unmounting the pool. Trying umount location " + targetPath + + logger.error("deleteStoragePool removed pool from libvirt, but libvirt had trouble unmounting the pool. Trying umount location " + targetPath + "again in a few seconds"); String result = Script.runSimpleBashScript("sleep 5 && umount " + targetPath); if (result == null) { - s_logger.error("Succeeded in unmounting " + targetPath); + logger.error("Succeeded in unmounting " + targetPath); return true; } - s_logger.error("Failed to unmount " + targetPath); + logger.error("Failed to unmount " + targetPath); } throw new CloudRuntimeException(e.toString(), e); } @@ -772,26 +779,25 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool, PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, byte[] passphrase) { - s_logger.info("Attempting to create volume " + name + " (" + pool.getType().toString() + ") in pool " + logger.info("Attempting to create volume " + name + " (" + pool.getType().toString() + ") in pool " + pool.getUuid() + " with size " + toHumanReadableSize(size)); - switch (pool.getType()) { - case RBD: - return createPhysicalDiskByLibVirt(name, pool, PhysicalDiskFormat.RAW, provisioningType, size); - case NetworkFilesystem: - case Filesystem: - switch (format) { - case QCOW2: - case RAW: - return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size, passphrase); - case DIR: - case TAR: - return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); - default: - throw new CloudRuntimeException("Unexpected disk format is specified."); - } - default: - return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); + StoragePoolType poolType = pool.getType(); + if (poolType.equals(StoragePoolType.RBD)) { + return createPhysicalDiskByLibVirt(name, pool, PhysicalDiskFormat.RAW, provisioningType, size); + } else if (poolType.equals(StoragePoolType.NetworkFilesystem) || poolType.equals(StoragePoolType.Filesystem)) { + switch (format) { + case QCOW2: + case RAW: + return createPhysicalDiskByQemuImg(name, pool, format, provisioningType, size, passphrase); + case DIR: + case TAR: + return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); + default: + throw new CloudRuntimeException("Unexpected disk format is specified."); + } + } else { + return createPhysicalDiskByLibVirt(name, pool, format, provisioningType, size); } } @@ -808,7 +814,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(name, size, libvirtformat, null, null); - s_logger.debug(volDef.toString()); + logger.debug(volDef.toString()); try { StorageVol vol = virtPool.storageVolCreateXML(volDef.toString(), 0); volPath = vol.getPath(); @@ -929,7 +935,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { @Override public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool, Storage.ImageFormat format) { - s_logger.info("Attempting to remove volume " + uuid + " from pool " + pool.getUuid()); + logger.info("Attempting to remove volume " + uuid + " from pool " + pool.getUuid()); /** * RBD volume can have snapshots and while they exist libvirt @@ -939,48 +945,48 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { */ if (pool.getType() == StoragePoolType.RBD) { try { - s_logger.info("Unprotecting and Removing RBD snapshots of image " + pool.getSourceDir() + "/" + uuid + " prior to removing the image"); + logger.info("Unprotecting and Removing RBD snapshots of image " + pool.getSourceDir() + "/" + uuid + " prior to removing the image"); Rados r = new Rados(pool.getAuthUserName()); r.confSet("mon_host", pool.getSourceHost() + ":" + pool.getSourcePort()); r.confSet("key", pool.getAuthSecret()); r.confSet("client_mount_timeout", "30"); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); IoCTX io = r.ioCtxCreate(pool.getSourceDir()); Rbd rbd = new Rbd(io); RbdImage image = rbd.open(uuid); - s_logger.debug("Fetching list of snapshots of RBD image " + pool.getSourceDir() + "/" + uuid); + logger.debug("Fetching list of snapshots of RBD image " + pool.getSourceDir() + "/" + uuid); List snaps = image.snapList(); try { for (RbdSnapInfo snap : snaps) { if (image.snapIsProtected(snap.name)) { - s_logger.debug("Unprotecting snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name); + logger.debug("Unprotecting snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name); image.snapUnprotect(snap.name); } else { - s_logger.debug("Snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name + " is not protected."); + logger.debug("Snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name + " is not protected."); } - s_logger.debug("Removing snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name); + logger.debug("Removing snapshot " + pool.getSourceDir() + "/" + uuid + "@" + snap.name); image.snapRemove(snap.name); } - s_logger.info("Successfully unprotected and removed any remaining snapshots (" + snaps.size() + ") of " + logger.info("Successfully unprotected and removed any remaining snapshots (" + snaps.size() + ") of " + pool.getSourceDir() + "/" + uuid + " Continuing to remove the RBD image"); } catch (RbdException e) { - s_logger.error("Failed to remove snapshot with exception: " + e.toString() + + logger.error("Failed to remove snapshot with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); throw new CloudRuntimeException(e.toString() + " - " + ErrorCode.getErrorMessage(e.getReturnValue())); } finally { - s_logger.debug("Closing image and destroying context"); + logger.debug("Closing image and destroying context"); rbd.close(image); r.ioCtxDestroy(io); } } catch (RadosException e) { - s_logger.error("Failed to remove snapshot with exception: " + e.toString() + + logger.error("Failed to remove snapshot with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); throw new CloudRuntimeException(e.toString() + " - " + ErrorCode.getErrorMessage(e.getReturnValue())); } catch (RbdException e) { - s_logger.error("Failed to remove snapshot with exception: " + e.toString() + + logger.error("Failed to remove snapshot with exception: " + e.toString() + ", RBD error: " + ErrorCode.getErrorMessage(e.getReturnValue())); throw new CloudRuntimeException(e.toString() + " - " + ErrorCode.getErrorMessage(e.getReturnValue())); } @@ -989,7 +995,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool; try { StorageVol vol = getVolume(libvirtPool.getPool(), uuid); - s_logger.debug("Instructing libvirt to remove volume " + uuid + " from pool " + pool.getUuid()); + logger.debug("Instructing libvirt to remove volume " + uuid + " from pool " + pool.getUuid()); if(Storage.ImageFormat.DIR.equals(format)){ deleteDirVol(libvirtPool, vol); } else { @@ -1015,7 +1021,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, String name, PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size, KVMStoragePool destPool, int timeout, byte[] passphrase) { - s_logger.info("Creating volume " + name + " from template " + template.getName() + " in pool " + destPool.getUuid() + + logger.info("Creating volume " + name + " from template " + template.getName() + " in pool " + destPool.getUuid() + " (" + destPool.getType().toString() + ") with size " + toHumanReadableSize(size)); KVMPhysicalDisk disk = null; @@ -1134,7 +1140,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { QemuImg qemu = new QemuImg(timeout); qemu.convert(srcFile, destFile); } catch (QemuImgException | LibvirtException e) { - s_logger.error("Failed to create " + disk.getPath() + + logger.error("Failed to create " + disk.getPath() + " due to a failed executing of qemu-img: " + e.getMessage()); } } else { @@ -1150,14 +1156,14 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { try { if ((srcPool.getSourceHost().equals(destPool.getSourceHost())) && (srcPool.getSourceDir().equals(destPool.getSourceDir()))) { /* We are on the same Ceph cluster, but we require RBD format 2 on the source image */ - s_logger.debug("Trying to perform a RBD clone (layering) since we are operating in the same storage pool"); + logger.debug("Trying to perform a RBD clone (layering) since we are operating in the same storage pool"); Rados r = new Rados(srcPool.getAuthUserName()); r.confSet("mon_host", srcPool.getSourceHost() + ":" + srcPool.getSourcePort()); r.confSet("key", srcPool.getAuthSecret()); r.confSet("client_mount_timeout", "30"); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); IoCTX io = r.ioCtxCreate(srcPool.getSourceDir()); Rbd rbd = new Rbd(io); @@ -1165,33 +1171,33 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { if (srcImage.isOldFormat()) { /* The source image is RBD format 1, we have to do a regular copy */ - s_logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName() + + logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName() + " is RBD format 1. We have to perform a regular copy (" + toHumanReadableSize(disk.getVirtualSize()) + " bytes)"); rbd.create(disk.getName(), disk.getVirtualSize(), RBD_FEATURES, rbdOrder); RbdImage destImage = rbd.open(disk.getName()); - s_logger.debug("Starting to copy " + srcImage.getName() + " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir()); + logger.debug("Starting to copy " + srcImage.getName() + " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir()); rbd.copy(srcImage, destImage); - s_logger.debug("Finished copying " + srcImage.getName() + " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir()); + logger.debug("Finished copying " + srcImage.getName() + " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir()); rbd.close(destImage); } else { - s_logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName() + logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName() + " is RBD format 2. We will perform a RBD clone using snapshot " + rbdTemplateSnapName); /* The source image is format 2, we can do a RBD snapshot+clone (layering) */ - s_logger.debug("Checking if RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName() + logger.debug("Checking if RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName() + "@" + rbdTemplateSnapName + " exists prior to attempting a clone operation."); List snaps = srcImage.snapList(); - s_logger.debug("Found " + snaps.size() + " snapshots on RBD image " + srcPool.getSourceDir() + "/" + template.getName()); + logger.debug("Found " + snaps.size() + " snapshots on RBD image " + srcPool.getSourceDir() + "/" + template.getName()); boolean snapFound = false; for (RbdSnapInfo snap : snaps) { if (rbdTemplateSnapName.equals(snap.name)) { - s_logger.debug("RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName() + logger.debug("RBD snapshot " + srcPool.getSourceDir() + "/" + template.getName() + "@" + rbdTemplateSnapName + " already exists."); snapFound = true; break; @@ -1199,20 +1205,20 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { } if (!snapFound) { - s_logger.debug("Creating RBD snapshot " + rbdTemplateSnapName + " on image " + name); + logger.debug("Creating RBD snapshot " + rbdTemplateSnapName + " on image " + name); srcImage.snapCreate(rbdTemplateSnapName); - s_logger.debug("Protecting RBD snapshot " + rbdTemplateSnapName + " on image " + name); + logger.debug("Protecting RBD snapshot " + rbdTemplateSnapName + " on image " + name); srcImage.snapProtect(rbdTemplateSnapName); } rbd.clone(template.getName(), rbdTemplateSnapName, io, disk.getName(), RBD_FEATURES, rbdOrder); - s_logger.debug("Successfully cloned " + template.getName() + "@" + rbdTemplateSnapName + " to " + disk.getName()); + logger.debug("Successfully cloned " + template.getName() + "@" + rbdTemplateSnapName + " to " + disk.getName()); /* We also need to resize the image if the VM was deployed with a larger root disk size */ if (disk.getVirtualSize() > template.getVirtualSize()) { RbdImage diskImage = rbd.open(disk.getName()); diskImage.resize(disk.getVirtualSize()); rbd.close(diskImage); - s_logger.debug("Resized " + disk.getName() + " to " + toHumanReadableSize(disk.getVirtualSize())); + logger.debug("Resized " + disk.getName() + " to " + toHumanReadableSize(disk.getVirtualSize())); } } @@ -1221,21 +1227,21 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { r.ioCtxDestroy(io); } else { /* The source pool or host is not the same Ceph cluster, we do a simple copy with Qemu-Img */ - s_logger.debug("Both the source and destination are RBD, but not the same Ceph cluster. Performing a copy"); + logger.debug("Both the source and destination are RBD, but not the same Ceph cluster. Performing a copy"); Rados rSrc = new Rados(srcPool.getAuthUserName()); rSrc.confSet("mon_host", srcPool.getSourceHost() + ":" + srcPool.getSourcePort()); rSrc.confSet("key", srcPool.getAuthSecret()); rSrc.confSet("client_mount_timeout", "30"); rSrc.connect(); - s_logger.debug("Successfully connected to source Ceph cluster at " + rSrc.confGet("mon_host")); + logger.debug("Successfully connected to source Ceph cluster at " + rSrc.confGet("mon_host")); Rados rDest = new Rados(destPool.getAuthUserName()); rDest.confSet("mon_host", destPool.getSourceHost() + ":" + destPool.getSourcePort()); rDest.confSet("key", destPool.getAuthSecret()); rDest.confSet("client_mount_timeout", "30"); rDest.connect(); - s_logger.debug("Successfully connected to source Ceph cluster at " + rDest.confGet("mon_host")); + logger.debug("Successfully connected to source Ceph cluster at " + rDest.confGet("mon_host")); IoCTX sIO = rSrc.ioCtxCreate(srcPool.getSourceDir()); Rbd sRbd = new Rbd(sIO); @@ -1243,14 +1249,14 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { IoCTX dIO = rDest.ioCtxCreate(destPool.getSourceDir()); Rbd dRbd = new Rbd(dIO); - s_logger.debug("Creating " + disk.getName() + " on the destination cluster " + rDest.confGet("mon_host") + " in pool " + + logger.debug("Creating " + disk.getName() + " on the destination cluster " + rDest.confGet("mon_host") + " in pool " + destPool.getSourceDir()); dRbd.create(disk.getName(), disk.getVirtualSize(), RBD_FEATURES, rbdOrder); RbdImage srcImage = sRbd.open(template.getName()); RbdImage destImage = dRbd.open(disk.getName()); - s_logger.debug("Copying " + template.getName() + " from Ceph cluster " + rSrc.confGet("mon_host") + " to " + disk.getName() + logger.debug("Copying " + template.getName() + " from Ceph cluster " + rSrc.confGet("mon_host") + " to " + disk.getName() + " on cluster " + rDest.confGet("mon_host")); sRbd.copy(srcImage, destImage); @@ -1261,10 +1267,10 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { rDest.ioCtxDestroy(dIO); } } catch (RadosException e) { - s_logger.error("Failed to perform a RADOS action on the Ceph cluster, the error was: " + e.getMessage()); + logger.error("Failed to perform a RADOS action on the Ceph cluster, the error was: " + e.getMessage()); disk = null; } catch (RbdException e) { - s_logger.error("Failed to perform a RBD action on the Ceph cluster, the error was: " + e.getMessage()); + logger.error("Failed to perform a RBD action on the Ceph cluster, the error was: " + e.getMessage()); disk = null; } } @@ -1323,7 +1329,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { String sourcePath = disk.getPath(); KVMPhysicalDisk newDisk; - s_logger.debug("copyPhysicalDisk: disk size:" + toHumanReadableSize(disk.getSize()) + ", virtualsize:" + toHumanReadableSize(disk.getVirtualSize())+" format:"+disk.getFormat()); + logger.debug("copyPhysicalDisk: disk size:" + toHumanReadableSize(disk.getSize()) + ", virtualsize:" + toHumanReadableSize(disk.getVirtualSize())+" format:"+disk.getFormat()); if (destPool.getType() != StoragePoolType.RBD) { if (disk.getFormat() == PhysicalDiskFormat.TAR) { newDisk = destPool.createPhysicalDisk(name, PhysicalDiskFormat.DIR, Storage.ProvisioningType.THIN, disk.getVirtualSize(), null); @@ -1379,12 +1385,12 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { newDisk.setVirtualSize(virtualSize); newDisk.setSize(virtualSize); } catch (QemuImgException | LibvirtException e) { - s_logger.error("Failed to convert " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); + logger.error("Failed to convert " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); newDisk = null; } } } catch (QemuImgException e) { - s_logger.error("Failed to fetch the information of file " + srcFile.getFileName() + " the error was: " + e.getMessage()); + logger.error("Failed to fetch the information of file " + srcFile.getFileName() + " the error was: " + e.getMessage()); newDisk = null; } } @@ -1393,7 +1399,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { * Using qemu-img we copy the QCOW2 disk to RAW (on RBD) directly. * To do so it's mandatory that librbd on the system is at least 0.67.7 (Ceph Dumpling) */ - s_logger.debug("The source image is not RBD, but the destination is. We will convert into RBD format 2"); + logger.debug("The source image is not RBD, but the destination is. We will convert into RBD format 2"); try { srcFile = new QemuImgFile(sourcePath, sourceFormat); String rbdDestPath = destPool.getSourceDir() + "/" + name; @@ -1404,9 +1410,9 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { rbdDestPath); destFile = new QemuImgFile(rbdDestFile, destFormat); - s_logger.debug("Starting copy from source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath); + logger.debug("Starting copy from source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath); qemu.convert(srcFile, destFile); - s_logger.debug("Successfully converted source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath); + logger.debug("Successfully converted source image " + srcFile.getFileName() + " to RBD image " + rbdDestPath); /* We have to stat the RBD image to see how big it became afterwards */ Rados r = new Rados(destPool.getAuthUserName()); @@ -1414,7 +1420,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { r.confSet("key", destPool.getAuthSecret()); r.confSet("client_mount_timeout", "30"); r.connect(); - s_logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); + logger.debug("Successfully connected to Ceph cluster at " + r.confGet("mon_host")); IoCTX io = r.ioCtxCreate(destPool.getSourceDir()); Rbd rbd = new Rbd(io); @@ -1423,20 +1429,20 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { RbdImageInfo rbdInfo = image.stat(); newDisk.setSize(rbdInfo.size); newDisk.setVirtualSize(rbdInfo.size); - s_logger.debug("After copy the resulting RBD image " + rbdDestPath + " is " + toHumanReadableSize(rbdInfo.size) + " bytes long"); + logger.debug("After copy the resulting RBD image " + rbdDestPath + " is " + toHumanReadableSize(rbdInfo.size) + " bytes long"); rbd.close(image); r.ioCtxDestroy(io); } catch (QemuImgException | LibvirtException e) { String srcFilename = srcFile != null ? srcFile.getFileName() : null; String destFilename = destFile != null ? destFile.getFileName() : null; - s_logger.error(String.format("Failed to convert from %s to %s the error was: %s", srcFilename, destFilename, e.getMessage())); + logger.error(String.format("Failed to convert from %s to %s the error was: %s", srcFilename, destFilename, e.getMessage())); newDisk = null; } catch (RadosException e) { - s_logger.error("A Ceph RADOS operation failed (" + e.getReturnValue() + "). The error was: " + e.getMessage()); + logger.error("A Ceph RADOS operation failed (" + e.getReturnValue() + "). The error was: " + e.getMessage()); newDisk = null; } catch (RbdException e) { - s_logger.error("A Ceph RBD operation failed (" + e.getReturnValue() + "). The error was: " + e.getMessage()); + logger.error("A Ceph RBD operation failed (" + e.getReturnValue() + "). The error was: " + e.getMessage()); newDisk = null; } } else { @@ -1454,7 +1460,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { try { qemu.convert(srcFile, destFile); } catch (QemuImgException | LibvirtException e) { - s_logger.error("Failed to convert " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); + logger.error("Failed to convert " + srcFile.getFileName() + " to " + destFile.getFileName() + " the error was: " + e.getMessage()); newDisk = null; } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java index d81b40391d0..52adc59cbe7 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStoragePool.java @@ -20,7 +20,8 @@ import java.io.File; import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.joda.time.Duration; import org.libvirt.StoragePool; @@ -39,7 +40,7 @@ import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; public class LibvirtStoragePool implements KVMStoragePool { - private static final Logger s_logger = Logger.getLogger(LibvirtStoragePool.class); + protected Logger logger = LogManager.getLogger(getClass()); protected String uuid; protected long capacity; protected long used; @@ -149,19 +150,19 @@ public class LibvirtStoragePool implements KVMStoragePool { if (disk != null) { return disk; } - s_logger.debug("find volume bypass libvirt volumeUid " + volumeUid); + logger.debug("find volume bypass libvirt volumeUid " + volumeUid); //For network file system or file system, try to use java file to find the volume, instead of through libvirt. BUG:CLOUDSTACK-4459 String localPoolPath = this.getLocalPath(); File f = new File(localPoolPath + File.separator + volumeUuid); if (!f.exists()) { - s_logger.debug("volume: " + volumeUuid + " not exist on storage pool"); + logger.debug("volume: " + volumeUuid + " not exist on storage pool"); throw new CloudRuntimeException("Can't find volume:" + volumeUuid); } disk = new KVMPhysicalDisk(f.getPath(), volumeUuid, this); disk.setFormat(PhysicalDiskFormat.QCOW2); disk.setSize(f.length()); disk.setVirtualSize(f.length()); - s_logger.debug("find volume bypass libvirt disk " + disk.toString()); + logger.debug("find volume bypass libvirt disk " + disk.toString()); return disk; } @@ -271,7 +272,7 @@ public class LibvirtStoragePool implements KVMStoragePool { try { return this._storageAdaptor.deleteStoragePool(this); } catch (Exception e) { - s_logger.debug("Failed to delete storage pool", e); + logger.debug("Failed to delete storage pool", e); } return false; } @@ -309,7 +310,7 @@ public class LibvirtStoragePool implements KVMStoragePool { public String createHeartBeatCommand(HAStoragePool primaryStoragePool, String hostPrivateIp, boolean hostValidation) { - Script cmd = new Script(primaryStoragePool.getPool().getHearthBeatPath(), HeartBeatUpdateTimeout, s_logger); + Script cmd = new Script(primaryStoragePool.getPool().getHearthBeatPath(), HeartBeatUpdateTimeout, logger); cmd.add("-i", primaryStoragePool.getPoolIp()); cmd.add("-p", primaryStoragePool.getPoolMountSourcePath()); cmd.add("-m", primaryStoragePool.getMountDestPath()); @@ -339,7 +340,7 @@ public class LibvirtStoragePool implements KVMStoragePool { public Boolean checkingHeartBeat(HAStoragePool pool, HostTO host) { boolean validResult = false; String hostIp = host.getPrivateNetwork().getIp(); - Script cmd = new Script(getHearthBeatPath(), HeartBeatCheckerTimeout, s_logger); + Script cmd = new Script(getHearthBeatPath(), HeartBeatCheckerTimeout, logger); cmd.add("-i", pool.getPoolIp()); cmd.add("-p", pool.getPoolMountSourcePath()); cmd.add("-m", pool.getMountDestPath()); @@ -350,11 +351,11 @@ public class LibvirtStoragePool implements KVMStoragePool { String result = cmd.execute(parser); String parsedLine = parser.getLine(); - s_logger.debug(String.format("Checking heart beat with KVMHAChecker [{command=\"%s\", result: \"%s\", log: \"%s\", pool: \"%s\"}].", cmd.toString(), result, parsedLine, + logger.debug(String.format("Checking heart beat with KVMHAChecker [{command=\"%s\", result: \"%s\", log: \"%s\", pool: \"%s\"}].", cmd.toString(), result, parsedLine, pool.getPoolIp())); if (result == null && parsedLine.contains("DEAD")) { - s_logger.warn(String.format("Checking heart beat with KVMHAChecker command [%s] returned [%s]. [%s]. It may cause a shutdown of host IP [%s].", cmd.toString(), + logger.warn(String.format("Checking heart beat with KVMHAChecker command [%s] returned [%s]. [%s]. It may cause a shutdown of host IP [%s].", cmd.toString(), result, parsedLine, hostIp)); } else { validResult = true; @@ -364,7 +365,7 @@ public class LibvirtStoragePool implements KVMStoragePool { @Override public Boolean vmActivityCheck(HAStoragePool pool, HostTO host, Duration activityScriptTimeout, String volumeUUIDListString, String vmActivityCheckPath, long duration) { - Script cmd = new Script(vmActivityCheckPath, activityScriptTimeout.getStandardSeconds(), s_logger); + Script cmd = new Script(vmActivityCheckPath, activityScriptTimeout.getStandardSeconds(), logger); cmd.add("-i", pool.getPoolIp()); cmd.add("-p", pool.getPoolMountSourcePath()); cmd.add("-m", pool.getMountDestPath()); @@ -377,10 +378,10 @@ public class LibvirtStoragePool implements KVMStoragePool { String result = cmd.execute(parser); String parsedLine = parser.getLine(); - s_logger.debug(String.format("Checking heart beat with KVMHAVMActivityChecker [{command=\"%s\", result: \"%s\", log: \"%s\", pool: \"%s\"}].", cmd.toString(), result, parsedLine, pool.getPoolIp())); + logger.debug(String.format("Checking heart beat with KVMHAVMActivityChecker [{command=\"%s\", result: \"%s\", log: \"%s\", pool: \"%s\"}].", cmd.toString(), result, parsedLine, pool.getPoolIp())); if (result == null && parsedLine.contains("DEAD")) { - s_logger.warn(String.format("Checking heart beat with KVMHAVMActivityChecker command [%s] returned [%s]. It is [%s]. It may cause a shutdown of host IP [%s].", cmd.toString(), result, parsedLine, host.getPrivateNetwork().getIp())); + logger.warn(String.format("Checking heart beat with KVMHAVMActivityChecker command [%s] returned [%s]. It is [%s]. It may cause a shutdown of host IP [%s].", cmd.toString(), result, parsedLine, host.getPrivateNetwork().getIp())); return false; } else { return true; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java index b23dd9a1790..8ec56b885f2 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ManagedNfsStorageAdaptor.java @@ -22,7 +22,8 @@ import java.util.List; import java.util.Map; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; import org.libvirt.LibvirtException; import org.libvirt.StoragePool; @@ -44,7 +45,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; public class ManagedNfsStorageAdaptor implements StorageAdaptor { - private static final Logger s_logger = Logger.getLogger(ManagedNfsStorageAdaptor.class); + protected Logger logger = LogManager.getLogger(getClass()); private String _mountPoint = "/mnt"; private StorageLayer _storageLayer; @@ -65,6 +66,9 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { return storagePool; } + @Override + public StoragePoolType getStoragePoolType() { return StoragePoolType.ManagedNFS; } + @Override public KVMStoragePool getStoragePool(String uuid) { return getStoragePool(uuid, false); @@ -109,7 +113,7 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { spd = new LibvirtStoragePoolDef(PoolType.NETFS, volumeUuid, details.get(DiskTO.UUID), pool.getSourceHost(), details.get(DiskTO.MOUNT_POINT), targetPath); _storageLayer.mkdir(targetPath); - s_logger.debug(spd.toString()); + logger.debug(spd.toString()); sp = conn.storagePoolCreateXML(spd.toString(), 0); if (sp == null) { @@ -118,7 +122,7 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { try { if (sp.isActive() == 0) { - // s_logger.debug("attempting to activate pool " + name); + // logger.debug("attempting to activate pool " + name); sp.create(0); } // now add the storage pool @@ -136,25 +140,25 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { } } } catch (LibvirtException e) { - s_logger.error(e.toString()); + logger.error(e.toString()); // if error is that pool is mounted, try to handle it if (e.toString().contains("already mounted")) { - s_logger.error("Attempting to unmount old mount libvirt is unaware of at " + targetPath); + logger.error("Attempting to unmount old mount libvirt is unaware of at " + targetPath); String result = Script.runSimpleBashScript("umount -l " + targetPath); if (result == null) { - s_logger.error("Succeeded in unmounting " + targetPath); + logger.error("Succeeded in unmounting " + targetPath); try { conn.storagePoolCreateXML(spd.toString(), 0); - s_logger.error("Succeeded in redefining storage"); + logger.error("Succeeded in redefining storage"); return true; } catch (LibvirtException l) { - s_logger.error("Target was already mounted, unmounted it but failed to redefine storage:" + l); + logger.error("Target was already mounted, unmounted it but failed to redefine storage:" + l); } } else { - s_logger.error("Failed in unmounting and redefining storage"); + logger.error("Failed in unmounting and redefining storage"); } } else { - s_logger.error("Internal error occurred when attempting to mount:" + e.getMessage()); + logger.error("Internal error occurred when attempting to mount:" + e.getMessage()); // stacktrace for agent.log e.printStackTrace(); throw new CloudRuntimeException(e.toString()); @@ -192,7 +196,7 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { volCapacity = poolinfo.available; LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(volumeUuid, volCapacity, libvirtformat, null, null); - s_logger.debug(volDef.toString()); + logger.debug(volDef.toString()); vol = virtPool.storageVolCreateXML(volDef.toString(), 0); @@ -221,15 +225,15 @@ public class ManagedNfsStorageAdaptor implements StorageAdaptor { try { vol = pool.storageVolLookupByName(volName); } catch (LibvirtException e) { - s_logger.debug("Can't find volume: " + e.toString()); + logger.debug("Can't find volume: " + e.toString()); } if (vol == null) { try { refreshPool(pool); } catch (LibvirtException e) { - s_logger.debug("failed to refresh pool: " + e.toString()); + logger.debug("failed to refresh pool: " + e.toString()); } - s_logger.debug("no volume is present on the pool, creating a new one"); + logger.debug("no volume is present on the pool, creating a new one"); } return vol; } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/MultipathSCSIAdapterBase.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/MultipathSCSIAdapterBase.java index 06dea46a98d..1625ecc171a 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/MultipathSCSIAdapterBase.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/MultipathSCSIAdapterBase.java @@ -34,7 +34,6 @@ import org.apache.cloudstack.utils.qemu.QemuImg; import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; -import org.apache.log4j.Logger; import com.cloud.storage.Storage; import com.cloud.storage.StorageManager; @@ -43,11 +42,13 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.libvirt.LibvirtException; import org.joda.time.Duration; public abstract class MultipathSCSIAdapterBase implements StorageAdaptor { - static final Logger LOGGER = Logger.getLogger(MultipathSCSIAdapterBase.class); + protected static Logger LOGGER = LogManager.getLogger(MultipathSCSIAdapterBase.class); static final Map MapStorageUuidToStoragePool = new HashMap<>(); /** @@ -651,7 +652,7 @@ public abstract class MultipathSCSIAdapterBase implements StorageAdaptor { synchronized(CLEANUP_LOCK) { long start = System.currentTimeMillis(); ScriptResult result = runScript(cleanupScript, cleanupTimeoutSecs * 1000); - LOGGER.debug("Multipath Cleanup Job elapsed time (ms): "+ (System.currentTimeMillis() - start) + "; result: " + result.getExitCode(), null); + LOGGER.debug("Multipath Cleanup Job elapsed time (ms): "+ (System.currentTimeMillis() - start) + "; result: " + result.getExitCode()); } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java index b85be041e48..9190510c7a7 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java @@ -37,39 +37,42 @@ import org.apache.cloudstack.utils.qemu.QemuImgException; import org.apache.cloudstack.utils.qemu.QemuImgFile; import org.apache.cloudstack.utils.qemu.QemuObject; import org.apache.commons.io.filefilter.WildcardFileFilter; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.LibvirtException; import com.cloud.storage.Storage; -import com.cloud.storage.StorageLayer; import com.cloud.storage.StorageManager; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; import org.apache.commons.lang3.StringUtils; -@StorageAdaptorInfo(storagePoolType= Storage.StoragePoolType.PowerFlex) public class ScaleIOStorageAdaptor implements StorageAdaptor { - private static final Logger LOGGER = Logger.getLogger(ScaleIOStorageAdaptor.class); + protected Logger logger = LogManager.getLogger(getClass()); private static final Map MapStorageUuidToStoragePool = new HashMap<>(); private static final int DEFAULT_DISK_WAIT_TIME_IN_SECS = 60; - private StorageLayer storageLayer; - public ScaleIOStorageAdaptor(StorageLayer storagelayer) { - storageLayer = storagelayer; + public ScaleIOStorageAdaptor() { + } @Override public KVMStoragePool getStoragePool(String uuid) { KVMStoragePool pool = MapStorageUuidToStoragePool.get(uuid); if (pool == null) { - LOGGER.error("Pool: " + uuid + " not found, probably sdc not connected on agent start"); + logger.error("Pool: " + uuid + " not found, probably sdc not connected on agent start"); throw new CloudRuntimeException("Pool: " + uuid + " not found, reconnect sdc and restart agent if sdc not connected on agent start"); } return pool; } + @Override + public Storage.StoragePoolType getStoragePoolType() { + return Storage.StoragePoolType.PowerFlex; + } + @Override public KVMStoragePool getStoragePool(String uuid, boolean refreshInfo) { return getStoragePool(uuid); @@ -78,7 +81,7 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { @Override public KVMPhysicalDisk getPhysicalDisk(String volumePath, KVMStoragePool pool) { if (StringUtils.isEmpty(volumePath) || pool == null) { - LOGGER.error("Unable to get physical disk, volume path or pool not specified"); + logger.error("Unable to get physical disk, volume path or pool not specified"); return null; } @@ -93,18 +96,18 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { diskFilePath = ScaleIOUtil.DISK_PATH + File.separator + diskFileName; final File diskFile = new File(diskFilePath); if (!diskFile.exists()) { - LOGGER.debug("Physical disk file: " + diskFilePath + " doesn't exists on the storage pool: " + pool.getUuid()); + logger.debug("Physical disk file: " + diskFilePath + " doesn't exists on the storage pool: " + pool.getUuid()); return null; } } else { - LOGGER.debug("Try with wildcard filter to get the physical disk: " + volumeId + " on the storage pool: " + pool.getUuid()); + logger.debug("Try with wildcard filter to get the physical disk: " + volumeId + " on the storage pool: " + pool.getUuid()); final File dir = new File(ScaleIOUtil.DISK_PATH); final FileFilter fileFilter = new WildcardFileFilter(ScaleIOUtil.DISK_NAME_PREFIX_FILTER + volumeId); final File[] files = dir.listFiles(fileFilter); if (files != null && files.length == 1) { diskFilePath = files[0].getAbsolutePath(); } else { - LOGGER.debug("Unable to find the physical disk: " + volumeId + " on the storage pool: " + pool.getUuid()); + logger.debug("Unable to find the physical disk: " + volumeId + " on the storage pool: " + pool.getUuid()); return null; } } @@ -134,7 +137,7 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { return disk; } catch (Exception e) { - LOGGER.error("Failed to get the physical disk: " + volumePath + " on the storage pool: " + pool.getUuid() + " due to " + e.getMessage()); + logger.error("Failed to get the physical disk: " + volumePath + " on the storage pool: " + pool.getUuid() + " due to " + e.getMessage()); throw new CloudRuntimeException("Failed to get the physical disk: " + volumePath + " on the storage pool: " + pool.getUuid()); } } @@ -188,7 +191,7 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { qemuObjects.add(QemuObject.prepareSecretForQemuImg(disk.getFormat(), disk.getQemuEncryptFormat(), keyFile.toString(), "sec0", options)); QemuImgFile file = new QemuImgFile(disk.getPath(), formattedSize, disk.getFormat()); qemuImg.create(file, null, options, qemuObjects); - LOGGER.debug(String.format("Successfully formatted %s as encrypted QCOW2", file.getFileName())); + logger.debug(String.format("Successfully formatted %s as encrypted QCOW2", file.getFileName())); } catch (QemuImgException | LibvirtException | IOException ex) { throw new CloudRuntimeException("Failed to set up encrypted QCOW on block device " + disk.getPath(), ex); } @@ -209,7 +212,7 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { @Override public boolean connectPhysicalDisk(String volumePath, KVMStoragePool pool, Map details) { if (StringUtils.isEmpty(volumePath) || pool == null) { - LOGGER.error("Unable to connect physical disk due to insufficient data"); + logger.error("Unable to connect physical disk due to insufficient data"); throw new CloudRuntimeException("Unable to connect physical disk due to insufficient data"); } @@ -226,7 +229,7 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { } private boolean waitForDiskToBecomeAvailable(String volumePath, KVMStoragePool pool, int waitTimeInSec) { - LOGGER.debug("Waiting for the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid() + " to become available for " + waitTimeInSec + " secs"); + logger.debug("Waiting for the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid() + " to become available for " + waitTimeInSec + " secs"); int timeBetweenTries = 1000; // Try more frequently (every sec) and return early if disk is found KVMPhysicalDisk physicalDisk = null; @@ -236,7 +239,7 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { while (waitTimeInSec > 0) { physicalDisk = getPhysicalDisk(volumePath, pool); if (physicalDisk != null && physicalDisk.getSize() > 0) { - LOGGER.debug("Found the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid()); + logger.debug("Found the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid()); return true; } @@ -251,11 +254,11 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { physicalDisk = getPhysicalDisk(volumePath, pool); if (physicalDisk != null && physicalDisk.getSize() > 0) { - LOGGER.debug("Found the volume using id: " + volumePath + " of the storage pool: " + pool.getUuid()); + logger.debug("Found the volume using id: " + volumePath + " of the storage pool: " + pool.getUuid()); return true; } - LOGGER.debug("Unable to find the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid()); + logger.debug("Unable to find the volume with id: " + volumePath + " of the storage pool: " + pool.getUuid()); return false; } @@ -264,17 +267,17 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { return 0; } - Script diskCmd = new Script("blockdev", LOGGER); + Script diskCmd = new Script("blockdev", logger); diskCmd.add("--getsize64", diskPath); OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); String result = diskCmd.execute(parser); if (result != null) { - LOGGER.warn("Unable to get the disk size at path: " + diskPath); + logger.warn("Unable to get the disk size at path: " + diskPath); return 0; } else { - LOGGER.info("Able to retrieve the disk size at path:" + diskPath); + logger.info("Able to retrieve the disk size at path:" + diskPath); } return Long.parseLong(parser.getLine()); @@ -323,7 +326,7 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { @Override public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMStoragePool destPool, int timeout, byte[] srcPassphrase, byte[]dstPassphrase, Storage.ProvisioningType provisioningType) { if (StringUtils.isEmpty(name) || disk == null || destPool == null) { - LOGGER.error("Unable to copy physical disk due to insufficient data"); + logger.error("Unable to copy physical disk due to insufficient data"); throw new CloudRuntimeException("Unable to copy physical disk due to insufficient data"); } @@ -331,11 +334,11 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { provisioningType = Storage.ProvisioningType.THIN; } - LOGGER.debug("Copy physical disk with size: " + disk.getSize() + ", virtualsize: " + disk.getVirtualSize()+ ", format: " + disk.getFormat()); + logger.debug("Copy physical disk with size: " + disk.getSize() + ", virtualsize: " + disk.getVirtualSize()+ ", format: " + disk.getFormat()); KVMPhysicalDisk destDisk = destPool.getPhysicalDisk(name); if (destDisk == null) { - LOGGER.error("Failed to find the disk: " + name + " of the storage pool: " + destPool.getUuid()); + logger.error("Failed to find the disk: " + name + " of the storage pool: " + destPool.getUuid()); throw new CloudRuntimeException("Failed to find the disk: " + name + " of the storage pool: " + destPool.getUuid()); } @@ -386,33 +389,33 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { } boolean forceSourceFormat = srcQemuFile.getFormat() == QemuImg.PhysicalDiskFormat.RAW; - LOGGER.debug(String.format("Starting copy from source disk %s(%s) to PowerFlex volume %s(%s), forcing source format is %b", srcQemuFile.getFileName(), srcQemuFile.getFormat(), destQemuFile.getFileName(), destQemuFile.getFormat(), forceSourceFormat)); + logger.debug(String.format("Starting copy from source disk %s(%s) to PowerFlex volume %s(%s), forcing source format is %b", srcQemuFile.getFileName(), srcQemuFile.getFormat(), destQemuFile.getFileName(), destQemuFile.getFormat(), forceSourceFormat)); qemuImageOpts.setImageOptsFlag(true); qemu.convert(srcQemuFile, destQemuFile, options, qemuObjects, qemuImageOpts,null, forceSourceFormat); - LOGGER.debug("Successfully converted source disk image " + srcQemuFile.getFileName() + " to PowerFlex volume: " + destDisk.getPath()); + logger.debug("Successfully converted source disk image " + srcQemuFile.getFileName() + " to PowerFlex volume: " + destDisk.getPath()); if (destQemuFile.getFormat() == QemuImg.PhysicalDiskFormat.QCOW2 && !disk.useAsTemplate()) { QemuImageOptions resizeOptions = new QemuImageOptions(destQemuFile.getFormat(), destPath, destKeyName); resizeQcow2ToVolume(destPath, resizeOptions, qemuObjects, timeout); - LOGGER.debug("Resized volume at " + destPath); + logger.debug("Resized volume at " + destPath); } } catch (QemuImgException | LibvirtException | IOException e) { try { Map srcInfo = qemu.info(srcQemuFile); - LOGGER.debug("Source disk info: " + Arrays.asList(srcInfo)); + logger.debug("Source disk info: " + Arrays.asList(srcInfo)); } catch (Exception ignored) { - LOGGER.warn("Unable to get info from source disk: " + disk.getName()); + logger.warn("Unable to get info from source disk: " + disk.getName()); } String errMsg = String.format("Unable to convert/copy from %s to %s, due to: %s", disk.getName(), name, ((StringUtils.isEmpty(e.getMessage())) ? "an unknown error" : e.getMessage())); - LOGGER.error(errMsg); + logger.error(errMsg); throw new CloudRuntimeException(errMsg, e); } finally { if (cryptSetup != null) { try { cryptSetup.close(name); } catch (CryptSetupException ex) { - LOGGER.warn("Failed to clean up LUKS disk after copying disk", ex); + logger.warn("Failed to clean up LUKS disk after copying disk", ex); } } } @@ -450,11 +453,11 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { @Override public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFilePath, String destTemplatePath, KVMStoragePool destPool, Storage.ImageFormat format, int timeout) { if (StringUtils.isAnyEmpty(templateFilePath, destTemplatePath) || destPool == null) { - LOGGER.error("Unable to create template from direct download template file due to insufficient data"); + logger.error("Unable to create template from direct download template file due to insufficient data"); throw new CloudRuntimeException("Unable to create template from direct download template file due to insufficient data"); } - LOGGER.debug("Create template from direct download template - file path: " + templateFilePath + ", dest path: " + destTemplatePath + ", format: " + format.toString()); + logger.debug("Create template from direct download template - file path: " + templateFilePath + ", dest path: " + destTemplatePath + ", format: " + format.toString()); File sourceFile = new File(templateFilePath); if (!sourceFile.exists()) { @@ -462,7 +465,7 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { } if (destTemplatePath == null || destTemplatePath.isEmpty()) { - LOGGER.error("Failed to create template, target template disk path not provided"); + logger.error("Failed to create template, target template disk path not provided"); throw new CloudRuntimeException("Target template disk path not provided"); } @@ -471,7 +474,7 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { } if (Storage.ImageFormat.RAW.equals(format) && Storage.ImageFormat.QCOW2.equals(format)) { - LOGGER.error("Failed to create template, unsupported template format: " + format.toString()); + logger.error("Failed to create template, unsupported template format: " + format.toString()); throw new CloudRuntimeException("Unsupported template format: " + format.toString()); } @@ -483,13 +486,13 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { QemuImg qemu = new QemuImg(timeout, true, false); destDisk = destPool.getPhysicalDisk(destTemplatePath); if (destDisk == null) { - LOGGER.error("Failed to find the disk: " + destTemplatePath + " of the storage pool: " + destPool.getUuid()); + logger.error("Failed to find the disk: " + destTemplatePath + " of the storage pool: " + destPool.getUuid()); throw new CloudRuntimeException("Failed to find the disk: " + destTemplatePath + " of the storage pool: " + destPool.getUuid()); } if (isTemplateExtractable(templateFilePath)) { srcTemplateFilePath = sourceFile.getParent() + "/" + UUID.randomUUID().toString(); - LOGGER.debug("Extract the downloaded template " + templateFilePath + " to " + srcTemplateFilePath); + logger.debug("Extract the downloaded template " + templateFilePath + " to " + srcTemplateFilePath); String extractCommand = getExtractCommandForDownloadedFile(templateFilePath, srcTemplateFilePath); Script.runSimpleBashScript(extractCommand); Script.runSimpleBashScript("rm -f " + templateFilePath); @@ -512,12 +515,12 @@ public class ScaleIOStorageAdaptor implements StorageAdaptor { destFile = new QemuImgFile(destDisk.getPath(), QemuImg.PhysicalDiskFormat.QCOW2); destFile.setSize(srcFile.getSize()); - LOGGER.debug("Starting copy from source downloaded template " + srcFile.getFileName() + " to PowerFlex template volume: " + destDisk.getPath()); + logger.debug("Starting copy from source downloaded template " + srcFile.getFileName() + " to PowerFlex template volume: " + destDisk.getPath()); qemu.create(destFile); qemu.convert(srcFile, destFile); - LOGGER.debug("Successfully converted source downloaded template " + srcFile.getFileName() + " to PowerFlex template volume: " + destDisk.getPath()); + logger.debug("Successfully converted source downloaded template " + srcFile.getFileName() + " to PowerFlex template volume: " + destDisk.getPath()); } catch (QemuImgException | LibvirtException e) { - LOGGER.error("Failed to convert. The error was: " + e.getMessage(), e); + logger.error("Failed to convert. The error was: " + e.getMessage(), e); destDisk = null; } finally { Script.runSimpleBashScript("rm -f " + srcTemplateFilePath); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java index ecf8691c6ed..34bf08f4496 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java @@ -26,6 +26,8 @@ import com.cloud.storage.Storage.StoragePoolType; public interface StorageAdaptor { + StoragePoolType getStoragePoolType(); + public KVMStoragePool getStoragePool(String uuid); // Get the storage pool from libvirt, but control if libvirt should refresh the pool (can take a long time) @@ -91,4 +93,11 @@ public interface StorageAdaptor { * @param timeout */ KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFilePath, String destTemplatePath, KVMStoragePool destPool, Storage.ImageFormat format, int timeout); + + /** + * Returns true if storage adaptor supports physical disk copy functionality. + */ + default boolean supportsPhysicalDiskCopy(StoragePoolType type) { + return StoragePoolType.PowerFlex == type; + } } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptorInfo.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptorInfo.java index fce976535f6..8d4b0c60a86 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptorInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/StorageAdaptorInfo.java @@ -22,10 +22,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import com.cloud.storage.Storage.StoragePoolType; - @Retention(RetentionPolicy.RUNTIME) @Target({ TYPE }) public @interface StorageAdaptorInfo { - StoragePoolType storagePoolType(); } diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java index 14922727d34..e061f1e8952 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java @@ -33,14 +33,12 @@ import org.apache.cloudstack.ha.provider.HARecoveryException; import org.apache.cloudstack.ha.provider.host.HAAbstractHostProvider; import org.apache.cloudstack.outofbandmanagement.OutOfBandManagement.PowerOperation; import org.apache.cloudstack.outofbandmanagement.OutOfBandManagementService; -import org.apache.log4j.Logger; import org.joda.time.DateTime; import javax.inject.Inject; import java.security.InvalidParameterException; public final class KVMHAProvider extends HAAbstractHostProvider implements HAProvider, Configurable { - private final static Logger LOG = Logger.getLogger(KVMHAProvider.class); @Inject protected KVMHostActivityChecker hostActivityChecker; @@ -75,11 +73,11 @@ public final class KVMHAProvider extends HAAbstractHostProvider implements HAPro final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.RESET, null); return resp.getSuccess(); } else { - LOG.warn("OOBM recover operation failed for the host " + r.getName()); + logger.warn("OOBM recover operation failed for the host " + r.getName()); return false; } } catch (Exception e){ - LOG.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); + logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); throw new HARecoveryException(" OOBM service is not configured or enabled for this host " + r.getName(), e); } } @@ -92,11 +90,11 @@ public final class KVMHAProvider extends HAAbstractHostProvider implements HAPro final OutOfBandManagementResponse resp = outOfBandManagementService.executePowerOperation(r, PowerOperation.OFF, null); return resp.getSuccess(); } else { - LOG.warn("OOBM fence operation failed for this host " + r.getName()); + logger.warn("OOBM fence operation failed for this host " + r.getName()); return false; } } catch (Exception e){ - LOG.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); + logger.warn("OOBM service is not configured or enabled for this host " + r.getName() + " error is " + e.getMessage()); throw new HAFenceException("OBM service is not configured or enabled for this host " + r.getName() , e); } } diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHostActivityChecker.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHostActivityChecker.java index 0866d668a43..10d684bbdd3 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHostActivityChecker.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHostActivityChecker.java @@ -42,7 +42,6 @@ import org.apache.cloudstack.ha.provider.HACheckerException; import org.apache.cloudstack.ha.provider.HealthCheckerInterface; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.commons.lang.ArrayUtils; -import org.apache.log4j.Logger; import javax.inject.Inject; import java.util.ArrayList; @@ -51,7 +50,6 @@ import java.util.HashMap; import java.util.List; public class KVMHostActivityChecker extends AdapterBase implements ActivityCheckerInterface, HealthCheckerInterface { - private final static Logger LOG = Logger.getLogger(KVMHostActivityChecker.class); @Inject private VolumeDao volumeDao; @@ -75,7 +73,7 @@ public class KVMHostActivityChecker extends AdapterBase implements ActivityCheck throw e; } catch (Exception e){ String message = String.format("Operation timed out, probably the %s is not reachable.", r.toString()); - LOG.warn(message, e); + logger.warn(message, e); throw new HACheckerException(message, e); } } @@ -93,22 +91,22 @@ public class KVMHostActivityChecker extends AdapterBase implements ActivityCheck Status neighbourStatus = Status.Unknown; final CheckOnHostCommand cmd = new CheckOnHostCommand(agent, HighAvailabilityManager.KvmHAFenceHostIfHeartbeatFailsOnStorage.value()); try { - LOG.debug(String.format("Checking %s status...", agent.toString())); + logger.debug(String.format("Checking %s status...", agent.toString())); Answer answer = agentMgr.easySend(agent.getId(), cmd); if (answer != null) { hostStatus = answer.getResult() ? Status.Down : Status.Up; - LOG.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus)); + logger.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus)); if ( hostStatus == Status.Up ){ return true; } } else { - LOG.debug(String.format("Setting %s to \"Disconnected\" status.", agent.toString())); + logger.debug(String.format("Setting %s to \"Disconnected\" status.", agent.toString())); hostStatus = Status.Disconnected; } } catch (Exception e) { - LOG.warn(String.format("Failed to send command CheckOnHostCommand to %s.", agent.toString()), e); + logger.warn(String.format("Failed to send command CheckOnHostCommand to %s.", agent.toString()), e); } List neighbors = resourceManager.listHostsInClusterByStatus(agent.getClusterId(), Status.Up); @@ -118,22 +116,22 @@ public class KVMHostActivityChecker extends AdapterBase implements ActivityCheck } try { - LOG.debug(String.format("Investigating %s via neighbouring %s.", agent.toString(), neighbor.toString())); + logger.debug(String.format("Investigating %s via neighbouring %s.", agent.toString(), neighbor.toString())); Answer answer = agentMgr.easySend(neighbor.getId(), cmd); if (answer != null) { neighbourStatus = answer.getResult() ? Status.Down : Status.Up; - LOG.debug(String.format("Neighbouring %s returned status [%s] for the investigated %s.", neighbor.toString(), neighbourStatus, agent.toString())); + logger.debug(String.format("Neighbouring %s returned status [%s] for the investigated %s.", neighbor.toString(), neighbourStatus, agent.toString())); if (neighbourStatus == Status.Up) { break; } } else { - LOG.debug(String.format("Neighbouring %s is Disconnected.", neighbor.toString())); + logger.debug(String.format("Neighbouring %s is Disconnected.", neighbor.toString())); } } catch (Exception e) { - LOG.warn(String.format("Failed to send command CheckOnHostCommand to %s.", neighbor.toString()), e); + logger.warn(String.format("Failed to send command CheckOnHostCommand to %s.", neighbor.toString()), e); } } if (neighbourStatus == Status.Up && (hostStatus == Status.Disconnected || hostStatus == Status.Down)) { @@ -143,7 +141,7 @@ public class KVMHostActivityChecker extends AdapterBase implements ActivityCheck hostStatus = Status.Down; } - LOG.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus)); + logger.debug(String.format("%s has the status [%s].", agent.toString(), hostStatus)); return hostStatus == Status.Up; } @@ -157,7 +155,7 @@ public class KVMHostActivityChecker extends AdapterBase implements ActivityCheck for (StoragePool pool : poolVolMap.keySet()) { activityStatus = verifyActivityOfStorageOnHost(poolVolMap, pool, agent, suspectTime, activityStatus); if (!activityStatus) { - LOG.warn(String.format("It seems that the storage pool [%s] does not have activity on %s.", pool.getId(), agent.toString())); + logger.warn(String.format("It seems that the storage pool [%s] does not have activity on %s.", pool.getId(), agent.toString())); break; } } @@ -169,21 +167,21 @@ public class KVMHostActivityChecker extends AdapterBase implements ActivityCheck List volume_list = poolVolMap.get(pool); final CheckVMActivityOnStoragePoolCommand cmd = new CheckVMActivityOnStoragePoolCommand(agent, pool, volume_list, suspectTime); - LOG.debug(String.format("Checking VM activity for %s on storage pool [%s].", agent.toString(), pool.getId())); + logger.debug(String.format("Checking VM activity for %s on storage pool [%s].", agent.toString(), pool.getId())); try { Answer answer = storageManager.sendToPool(pool, getNeighbors(agent), cmd); if (answer != null) { activityStatus = !answer.getResult(); - LOG.debug(String.format("%s %s activity on storage pool [%s]", agent.toString(), activityStatus ? "has" : "does not have", pool.getId())); + logger.debug(String.format("%s %s activity on storage pool [%s]", agent.toString(), activityStatus ? "has" : "does not have", pool.getId())); } else { String message = String.format("Did not get a valid response for VM activity check for %s on storage pool [%s].", agent.toString(), pool.getId()); - LOG.debug(message); + logger.debug(message); throw new IllegalStateException(message); } } catch (StorageUnavailableException e){ String message = String.format("Storage [%s] is unavailable to do the check, probably the %s is not reachable.", pool.getId(), agent.toString()); - LOG.warn(message, e); + logger.warn(message, e); throw new HACheckerException(message, e); } return activityStatus; @@ -193,14 +191,14 @@ public class KVMHostActivityChecker extends AdapterBase implements ActivityCheck List vm_list = vmInstanceDao.listByHostId(agent.getId()); List volume_list = new ArrayList(); for (VirtualMachine vm : vm_list) { - LOG.debug(String.format("Retrieving volumes of VM [%s]...", vm.getId())); + logger.debug(String.format("Retrieving volumes of VM [%s]...", vm.getId())); List vm_volume_list = volumeDao.findByInstance(vm.getId()); volume_list.addAll(vm_volume_list); } HashMap> poolVolMap = new HashMap>(); for (Volume vol : volume_list) { - LOG.debug(String.format("Retrieving storage pool [%s] of volume [%s]...", vol.getPoolId(), vol.getId())); + logger.debug(String.format("Retrieving storage pool [%s] of volume [%s]...", vol.getPoolId(), vol.getId())); StoragePool sp = storagePool.findById(vol.getPoolId()); if (!poolVolMap.containsKey(sp)) { List list = new ArrayList(); @@ -217,7 +215,7 @@ public class KVMHostActivityChecker extends AdapterBase implements ActivityCheck public long[] getNeighbors(Host agent) { List neighbors = new ArrayList(); List cluster_hosts = resourceManager.listHostsInClusterByStatus(agent.getClusterId(), Status.Up); - LOG.debug(String.format("Retrieving all \"Up\" hosts from cluster [%s]...", agent.getClusterId())); + logger.debug(String.format("Retrieving all \"Up\" hosts from cluster [%s]...", agent.getClusterId())); for (HostVO host : cluster_hosts) { if (host.getId() == agent.getId() || (host.getHypervisorType() != Hypervisor.HypervisorType.KVM && host.getHypervisorType() != Hypervisor.HypervisorType.LXC)) { continue; diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/cryptsetup/CryptSetup.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/cryptsetup/CryptSetup.java index 82c4ebe6d8f..bcdb9acb7b6 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/cryptsetup/CryptSetup.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/cryptsetup/CryptSetup.java @@ -108,7 +108,7 @@ public class CryptSetup { public boolean isSupported() { final Script script = new Script(commandPath); - script.add("--usage"); + script.add("--version"); final String result = script.execute(); return result == null; } diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/CPUStat.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/CPUStat.java index d180d013a24..9dd14b1b510 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/CPUStat.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/CPUStat.java @@ -21,10 +21,11 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; public class CPUStat { - private static final Logger s_logger = Logger.getLogger(CPUStat.class); + protected Logger logger = LogManager.getLogger(getClass()); private Integer _cores; private UptimeStats _lastStats; @@ -58,7 +59,7 @@ public class CPUStat { String[] stats = scanner.useDelimiter("\\Z").next().split("\\s+"); uptime = new UptimeStats(Double.parseDouble(stats[0]), Double.parseDouble(stats[1])); } catch (FileNotFoundException ex) { - s_logger.warn("File " + _uptimeFile + " not found:" + ex.toString()); + logger.warn("File " + _uptimeFile + " not found:" + ex.toString()); } return uptime; } @@ -87,7 +88,7 @@ public class CPUStat { try (Scanner scanner = new Scanner(f,"UTF-8");) { load = scanner.useDelimiter("\\Z").next().split("\\s+"); } catch (FileNotFoundException ex) { - s_logger.warn("File " + _uptimeFile + " not found:" + ex.toString()); + logger.warn("File " + _uptimeFile + " not found:" + ex.toString()); } return Double.parseDouble(load[0]); } diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java index d160cbfac3b..4293ee75f7e 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java @@ -29,7 +29,8 @@ import javax.xml.parsers.DocumentBuilderFactory; import org.apache.cloudstack.utils.security.ParserUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.libvirt.Connect; import org.libvirt.LibvirtException; import org.libvirt.NodeInfo; @@ -46,7 +47,7 @@ import com.cloud.utils.script.Script; public class KVMHostInfo { - private static final Logger LOGGER = Logger.getLogger(KVMHostInfo.class); + protected static Logger LOGGER = LogManager.getLogger(KVMHostInfo.class); private int totalCpus; private int allocatableCpus; @@ -222,7 +223,6 @@ public class KVMHostInfo { We used to check if this was supported, but that is no longer required */ this.capabilities.add("snapshot"); - conn.close(); } catch (final LibvirtException e) { LOGGER.error("Caught libvirt exception while fetching host information", e); } diff --git a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java index 1cd63b9b566..1ddc16c8945 100644 --- a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java +++ b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java @@ -32,12 +32,13 @@ import com.cloud.hypervisor.kvm.resource.LibvirtConnection; import com.cloud.storage.Storage; import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.LogManager; import static java.util.regex.Pattern.CASE_INSENSITIVE; public class QemuImg { - private Logger logger = Logger.getLogger(this.getClass()); + private Logger logger = LogManager.getLogger(this.getClass()); public static final String BACKING_FILE = "backing_file"; public static final String BACKING_FILE_FORMAT = "backing_file_format"; @@ -812,4 +813,45 @@ public class QemuImg { Pattern pattern = Pattern.compile("Supported\\sformats:[a-zA-Z0-9-_\\s]*?\\b" + format + "\\b", CASE_INSENSITIVE); return pattern.matcher(text).find(); } + + /** + * check for any leaks for an image and repair. + * + * @param imageOptions + * Qemu style image options to be used in the checking process. + * @param qemuObjects + * Qemu style options (e.g. for passing secrets). + * @param repair + * Boolean option whether to repair any leaks + */ + public String checkAndRepair(final QemuImgFile file, final QemuImageOptions imageOptions, final List qemuObjects, final String repair) throws QemuImgException { + final Script script = new Script(_qemuImgPath); + script.add("check"); + if (imageOptions == null) { + script.add(file.getFileName()); + } + + for (QemuObject o : qemuObjects) { + script.add(o.toCommandFlag()); + } + + if (imageOptions != null) { + script.add(imageOptions.toCommandFlag()); + } + + if (StringUtils.isNotEmpty(repair)) { + script.add("-r"); + script.add(repair); + } + + script.add("--output=json"); + script.add("2>/dev/null"); + + final String result = Script.runBashScriptIgnoreExitValue(script.toString(), 3); + if (result != null) { + logger.debug(String.format("Check volume execution result %s", result)); + } + + return result; + } } diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java index 3e18638361c..2c3a3126f6d 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/dpdk/DpdkDriverTest.java @@ -24,7 +24,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Matchers; +import org.mockito.ArgumentMatchers; import org.mockito.MockedStatic; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -51,7 +51,7 @@ public class DpdkDriverTest { public void initMocks() { closeable = MockitoAnnotations.openMocks(this); scriptMockedStatic = Mockito.mockStatic(Script.class); - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())).thenReturn(null); + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())).thenReturn(null); extraConfig = new HashMap<>(); } @@ -68,14 +68,14 @@ public class DpdkDriverTest { @Test public void testGetDpdkLatestPortNumberUsedExistingDpdkPorts() { - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())). + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())). thenReturn(DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(dpdkPortNumber)); Assert.assertEquals(dpdkPortNumber, driver.getDpdkLatestPortNumberUsed()); } @Test public void testGetNextDpdkPortNoDpdkPorts() { - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())). + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())). thenReturn(null); String expectedPortName = DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(1); Assert.assertEquals(expectedPortName, driver.getNextDpdkPort()); @@ -83,7 +83,7 @@ public class DpdkDriverTest { @Test public void testGetNextDpdkPortExistingDpdkPorts() { - Mockito.when(Script.runSimpleBashScript(Matchers.anyString())). + Mockito.when(Script.runSimpleBashScript(ArgumentMatchers.anyString())). thenReturn(DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(dpdkPortNumber)); String expectedPortName = DpdkDriverImpl.DPDK_PORT_PREFIX + String.valueOf(dpdkPortNumber + 1); Assert.assertEquals(expectedPortName, driver.getNextDpdkPort()); diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java index aac7f7343af..19515ac8361 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java @@ -68,7 +68,7 @@ import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.SystemUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Logger; import org.joda.time.Duration; import org.junit.Assert; import org.junit.Before; @@ -271,7 +271,7 @@ public class LibvirtComputingResourceTest { public void setup() throws Exception { libvirtComputingResourceSpy.qemuSocketsPath = new File("/var/run/qemu"); libvirtComputingResourceSpy.parser = parserMock; - LibvirtComputingResource.s_logger = loggerMock; + LibvirtComputingResource.LOGGER = loggerMock; } /** @@ -6050,7 +6050,7 @@ public class LibvirtComputingResourceTest { List result = libvirtComputingResourceSpy.getVmsToSetMemoryBalloonStatsPeriod(connMock); - Mockito.verify(loggerMock).error(Mockito.anyString(), Mockito.any()); + Mockito.verify(loggerMock).error(Mockito.anyString(), (Throwable) Mockito.any()); Assert.assertTrue(result.isEmpty()); } diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java index 53a745134cf..3813cb39f3c 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParserTest.java @@ -259,4 +259,126 @@ public class LibvirtDomainXMLParserTest extends TestCase { assertEquals(WatchDogDef.WatchDogModel.I6300ESB, watchDogs.get(0).getModel()); assertEquals(WatchDogDef.WatchDogAction.RESET, watchDogs.get(0).getAction()); } + + @Test + public void testDomainXMLParserWithoutModelName() { + String xml = "\n" + + " testkiran\n" + + " aafaaabc-8657-4efc-9c52-3422d4e04088\n" + + " 2097152\n" + + " 2097152\n" + + " 2\n" + + " \n" + + " hvm\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " destroy\n" + + " restart\n" + + " destroy\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " /usr/libexec/qemu-kvm\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + "