Updated Branches: refs/heads/vmsync 58112a9e1 -> 56bc25535
Separate usage monitor from HA manager Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/56bc2553 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/56bc2553 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/56bc2553 Branch: refs/heads/vmsync Commit: 56bc255355cc10e0273e6f124bc1659b8c1b6712 Parents: 58112a9 Author: Kelven Yang <kelv...@gmail.com> Authored: Wed Apr 17 14:14:17 2013 -0700 Committer: Kelven Yang <kelv...@gmail.com> Committed: Wed Apr 17 14:14:17 2013 -0700 ---------------------------------------------------------------------- client/tomcatconf/applicationContext.xml.in | 3 +- .../cloud/ha/HighAvailabilityManagerExtImpl.java | 107 ------------- server/src/com/cloud/usage/UsageServerMonitor.java | 118 +++++++++++++++ setup/db/db/schema-410to420.sql | 2 +- 4 files changed, 121 insertions(+), 109 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/56bc2553/client/tomcatconf/applicationContext.xml.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/applicationContext.xml.in b/client/tomcatconf/applicationContext.xml.in index b2c7eda..e12ded8 100644 --- a/client/tomcatconf/applicationContext.xml.in +++ b/client/tomcatconf/applicationContext.xml.in @@ -622,7 +622,7 @@ <property name="Discoverers" value="#{resourceDiscoverers.Adapters}" /> </bean> - <bean id="highAvailabilityManagerExtImpl" class="com.cloud.ha.HighAvailabilityManagerExtImpl" > + <bean id="highAvailabilityManagerImpl" class="com.cloud.ha.HighAvailabilityManagerImpl" > <property name="Investigators" value="#{haInvestigators.Adapters}" /> <property name="FenceBuilders" value="#{haFenceBuilders.Adapters}" /> </bean> @@ -698,6 +698,7 @@ <bean id="virtualNetworkApplianceManagerImpl" class="com.cloud.network.router.VirtualNetworkApplianceManagerImpl" /> <bean id="vpcManagerImpl" class="com.cloud.network.vpc.VpcManagerImpl" /> <bean id="vpcVirtualNetworkApplianceManagerImpl" class="com.cloud.network.router.VpcVirtualNetworkApplianceManagerImpl" /> + <bean id="usageServerMonitor" class="com.cloud.usage.UsageServerMonitor" /> <!-- Misc components http://git-wip-us.apache.org/repos/asf/cloudstack/blob/56bc2553/server/src/com/cloud/ha/HighAvailabilityManagerExtImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/ha/HighAvailabilityManagerExtImpl.java b/server/src/com/cloud/ha/HighAvailabilityManagerExtImpl.java deleted file mode 100644 index ae6fe4e..0000000 --- a/server/src/com/cloud/ha/HighAvailabilityManagerExtImpl.java +++ /dev/null @@ -1,107 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.ha; - -import java.util.Date; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; - -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - -import com.cloud.alert.AlertManager; -import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.usage.dao.UsageJobDao; -import com.cloud.utils.db.Transaction; - -@Local(value={HighAvailabilityManager.class}) -public class HighAvailabilityManagerExtImpl extends HighAvailabilityManagerImpl { - - @Inject - UsageJobDao _usageJobDao; - - @Inject ConfigurationDao configDao; - - @Override - public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException { - super.configure(name, xmlParams); - return true; - } - - @Override - public boolean start() - { - super.start(); - - - boolean enableUsage = new Boolean(configDao.getValue("enable.usage.server")); - - //By default, usage is enabled for production - //Devs might override this value to disable usage in their setup - if(enableUsage) - { - _executor.scheduleAtFixedRate(new UsageServerMonitorTask(), 60*60, 10*60, TimeUnit.SECONDS); // schedule starting in one hour to execute every 10 minutes - } - - return true; - } - - protected class UsageServerMonitorTask implements Runnable { - @Override - public void run() { - if (s_logger.isInfoEnabled()) { - s_logger.info("checking health of usage server"); - } - - try { - boolean isRunning = false; - Transaction txn = Transaction.open(Transaction.USAGE_DB); - try { - Date lastHeartbeat = _usageJobDao.getLastHeartbeat(); - if (lastHeartbeat != null) { - long sinceLastHeartbeat = System.currentTimeMillis() - lastHeartbeat.getTime(); - if (sinceLastHeartbeat <= (10 * 60 * 1000)) { - // if it's been less than 10 minutes since the last heartbeat, then it appears to be running, otherwise send an alert - isRunning = true; - } - } - if (s_logger.isDebugEnabled()) { - s_logger.debug("usage server running? " + isRunning + ", heartbeat: " + lastHeartbeat); - } - } finally { - txn.close(); - - // switch back to VMOPS db - Transaction swap = Transaction.open(Transaction.CLOUD_DB); - swap.close(); - } - - if (!isRunning) { - _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USAGE_SERVER, 0, new Long(0), "No usage server process running", "No usage server process has been detected, some attention is required"); - } else { - _alertMgr.clearAlert(AlertManager.ALERT_TYPE_USAGE_SERVER, 0, 0); - } - } catch (Exception ex) { - s_logger.warn("Error while monitoring usage job", ex); - } - } - } -} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/56bc2553/server/src/com/cloud/usage/UsageServerMonitor.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/usage/UsageServerMonitor.java b/server/src/com/cloud/usage/UsageServerMonitor.java new file mode 100644 index 0000000..edea8bb --- /dev/null +++ b/server/src/com/cloud/usage/UsageServerMonitor.java @@ -0,0 +1,118 @@ +// 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.usage; + +import java.util.Date; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; + +import com.cloud.alert.AlertManager; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.usage.dao.UsageJobDao; +import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.concurrency.NamedThreadFactory; +import com.cloud.utils.db.Transaction; + +/** + * This class is detached from HighAvailabilityManagerImpl, I see no reason for it to inherit from + * HighAvailabilityManagerImpl. + * + */ +public class UsageServerMonitor extends ManagerBase { + protected static final Logger s_logger = Logger.getLogger(UsageServerMonitor.class); + + @Inject UsageJobDao _usageJobDao; + + @Inject ConfigurationDao configDao; + @Inject AlertManager _alertMgr; + + ScheduledExecutorService _executor; + + @Override + public boolean configure(final String name, final Map<String, Object> xmlParams) throws ConfigurationException { + super.configure(name, xmlParams); + _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("UsageServer-Monitor")); + + return true; + } + + @Override + public boolean start() + { + super.start(); + + + boolean enableUsage = new Boolean(configDao.getValue("enable.usage.server")); + + //By default, usage is enabled for production + //Devs might override this value to disable usage in their setup + if(enableUsage) + { + _executor.scheduleAtFixedRate(new UsageServerMonitorTask(), 60*60, 10*60, TimeUnit.SECONDS); // schedule starting in one hour to execute every 10 minutes + } + + return true; + } + + protected class UsageServerMonitorTask implements Runnable { + @Override + public void run() { + if (s_logger.isInfoEnabled()) { + s_logger.info("checking health of usage server"); + } + + try { + boolean isRunning = false; + Transaction txn = Transaction.open(Transaction.USAGE_DB); + try { + Date lastHeartbeat = _usageJobDao.getLastHeartbeat(); + if (lastHeartbeat != null) { + long sinceLastHeartbeat = System.currentTimeMillis() - lastHeartbeat.getTime(); + if (sinceLastHeartbeat <= (10 * 60 * 1000)) { + // if it's been less than 10 minutes since the last heartbeat, then it appears to be running, otherwise send an alert + isRunning = true; + } + } + if (s_logger.isDebugEnabled()) { + s_logger.debug("usage server running? " + isRunning + ", heartbeat: " + lastHeartbeat); + } + } finally { + txn.close(); + + // switch back to VMOPS db + Transaction swap = Transaction.open(Transaction.CLOUD_DB); + swap.close(); + } + + if (!isRunning) { + _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USAGE_SERVER, 0, new Long(0), "No usage server process running", "No usage server process has been detected, some attention is required"); + } else { + _alertMgr.clearAlert(AlertManager.ALERT_TYPE_USAGE_SERVER, 0, 0); + } + } catch (Exception ex) { + s_logger.warn("Error while monitoring usage job", ex); + } + } + } +} http://git-wip-us.apache.org/repos/asf/cloudstack/blob/56bc2553/setup/db/db/schema-410to420.sql ---------------------------------------------------------------------- diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index a570747..c4e91eb 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -413,5 +413,5 @@ ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_dispatcher` VARCHAR(64); ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `last_event` VARCHAR(64) DEFAULT 'OperationNop'; ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `last_event_args` VARCHAR(256); ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state` VARCHAR(74) DEFAULT 'PowerUnknown'; -ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_time` DATETIME DEFAULT NOW(); +ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_time` DATETIME;