From dac008fc4b669bdc7291592fb3c71e72e7383e62 Mon Sep 17 00:00:00 2001 From: kishan Date: Mon, 20 Dec 2010 14:32:59 +0530 Subject: [PATCH 01/23] bug 7504: Added started event when API command execute is called --- server/src/com/cloud/api/ApiDispatcher.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index b18558b194f..d554cc547b1 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -29,6 +29,7 @@ import org.apache.log4j.Logger; import com.cloud.api.BaseCmd.CommandType; import com.cloud.async.AsyncCommandQueued; +import com.cloud.event.EventUtils; import com.cloud.exception.AccountLimitException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; @@ -37,6 +38,7 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.server.ManagementServer; import com.cloud.user.Account; +import com.cloud.user.User; import com.cloud.user.UserContext; import com.cloud.utils.DateUtil; import com.cloud.utils.component.ComponentLocator; @@ -103,6 +105,14 @@ public class ApiDispatcher { public void dispatch(BaseCmd cmd, Map params) { setupParameters(cmd, params); try { + if(cmd instanceof BaseAsyncCmd){ + // save the started event + Long userId = new Long(params.get("ctxUserId")); + BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmd; + Long startId = new Long(params.get("starteventid")); + EventUtils.saveStartedEvent((userId == null) ? User.UID_SYSTEM : userId, asyncCmd.getEntityOwnerId(), + asyncCmd.getEventType(), "Starting async job for "+asyncCmd.getEventDescription(), startId); + } cmd.execute(); } catch (Throwable t) { if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { From fc8138bcfadf4b6463e5513fe6044c9128fea008 Mon Sep 17 00:00:00 2001 From: kishan Date: Mon, 20 Dec 2010 23:40:13 +0530 Subject: [PATCH 02/23] bug 7504: Added new usage event table --- setup/db/create-schema.sql | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 25c52b499d1..63caeb79eef 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -91,6 +91,7 @@ DROP TABLE IF EXISTS `cloud`.`load_balancing_ip_map`; DROP TABLE IF EXISTS `cloud`.`load_balancing_rules`; DROP TABLE IF EXISTS `cloud`.`port_forwarding_rules`; DROP TABLE IF EXISTS `cloud`.`firewall_rules`; +DROP TABLE IF EXISTS `cloud`.`usage_event`; CREATE TABLE `cloud`.`op_it_work` ( `id` char(40) COMMENT 'id', @@ -1252,4 +1253,19 @@ CREATE TABLE `cloud`.`instance_group_vm_map` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `cloud`.`usage_event` ( + `id` bigint unsigned NOT NULL auto_increment, + `type` varchar(32) NOT NULL, + `account_id` bigint unsigned NOT NULL, + `domain_id` bigint unsigned NOT NULL, + `created` datetime NOT NULL, + `zone_id` bigint unsigned NOT NULL, + `resource_id` bigint unsigned, + `resource_name` varchar(255), + `offering_id` bigint unsigned, + `template_id` bigint unsigned, + `size` bigint unsigned, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + SET foreign_key_checks = 1; From a7626fc991ccb31cf85ed547a1dc011c5c6dad54 Mon Sep 17 00:00:00 2001 From: kishan Date: Wed, 22 Dec 2010 12:09:53 +0530 Subject: [PATCH 03/23] bug 7504: Added usage events --- client/tomcatconf/components.xml.in | 2 +- server/src/com/cloud/api/ApiDispatcher.java | 10 ---------- .../configuration/DefaultComponentLibrary.java | 6 ++++-- .../src/com/cloud/network/NetworkManagerImpl.java | 13 ++++++++++++- .../src/com/cloud/storage/StorageManagerImpl.java | 12 ++++++++++++ .../cloud/storage/download/DownloadMonitorImpl.java | 7 +++++++ .../src/com/cloud/template/TemplateManagerImpl.java | 3 +++ server/src/com/cloud/vm/UserVmManagerImpl.java | 10 +++++++++- .../src/com/cloud/vm/VirtualMachineManagerImpl.java | 8 ++++++++ setup/db/create-schema.sql | 1 - 10 files changed, 56 insertions(+), 16 deletions(-) diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index 371c8239472..7dfdbbb2e67 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -96,6 +96,6 @@ - + diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index d554cc547b1..b18558b194f 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -29,7 +29,6 @@ import org.apache.log4j.Logger; import com.cloud.api.BaseCmd.CommandType; import com.cloud.async.AsyncCommandQueued; -import com.cloud.event.EventUtils; import com.cloud.exception.AccountLimitException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; @@ -38,7 +37,6 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.server.ManagementServer; import com.cloud.user.Account; -import com.cloud.user.User; import com.cloud.user.UserContext; import com.cloud.utils.DateUtil; import com.cloud.utils.component.ComponentLocator; @@ -105,14 +103,6 @@ public class ApiDispatcher { public void dispatch(BaseCmd cmd, Map params) { setupParameters(cmd, params); try { - if(cmd instanceof BaseAsyncCmd){ - // save the started event - Long userId = new Long(params.get("ctxUserId")); - BaseAsyncCmd asyncCmd = (BaseAsyncCmd)cmd; - Long startId = new Long(params.get("starteventid")); - EventUtils.saveStartedEvent((userId == null) ? User.UID_SYSTEM : userId, asyncCmd.getEntityOwnerId(), - asyncCmd.getEventType(), "Starting async job for "+asyncCmd.getEventDescription(), startId); - } cmd.execute(); } catch (Throwable t) { if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { diff --git a/server/src/com/cloud/configuration/DefaultComponentLibrary.java b/server/src/com/cloud/configuration/DefaultComponentLibrary.java index ec72d6cab7c..e43391a1248 100644 --- a/server/src/com/cloud/configuration/DefaultComponentLibrary.java +++ b/server/src/com/cloud/configuration/DefaultComponentLibrary.java @@ -52,6 +52,7 @@ import com.cloud.dc.dao.PodVlanMapDaoImpl; import com.cloud.dc.dao.VlanDaoImpl; import com.cloud.domain.dao.DomainDaoImpl; import com.cloud.event.dao.EventDaoImpl; +import com.cloud.event.dao.UsageEventDaoImpl; import com.cloud.ha.HighAvailabilityManagerImpl; import com.cloud.ha.dao.HighAvailabilityDaoImpl; import com.cloud.host.dao.DetailsDaoImpl; @@ -113,12 +114,12 @@ import com.cloud.user.dao.UserStatisticsDaoImpl; import com.cloud.utils.Pair; import com.cloud.utils.component.Adapter; import com.cloud.utils.component.ComponentLibrary; -import com.cloud.utils.component.ComponentLocator.ComponentInfo; import com.cloud.utils.component.Manager; +import com.cloud.utils.component.ComponentLocator.ComponentInfo; import com.cloud.utils.db.GenericDao; import com.cloud.vm.ItWorkDaoImpl; -import com.cloud.vm.VirtualMachineManagerImpl; import com.cloud.vm.UserVmManagerImpl; +import com.cloud.vm.VirtualMachineManagerImpl; import com.cloud.vm.dao.ConsoleProxyDaoImpl; import com.cloud.vm.dao.DomainRouterDaoImpl; import com.cloud.vm.dao.InstanceGroupDaoImpl; @@ -231,6 +232,7 @@ public class DefaultComponentLibrary implements ComponentLibrary { addDao("ItWorkDao", ItWorkDaoImpl.class); addDao("FirewallRulesDao", FirewallRulesDaoImpl.class); addDao("PortForwardingRulesDao", PortForwardingRulesDaoImpl.class); + addDao("UsageEventDao", UsageEventDaoImpl.class); } Map> _managers = new HashMap>(); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 96eab58ca5b..f9d2811a5d9 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -74,7 +74,9 @@ import com.cloud.domain.dao.DomainDao; import com.cloud.event.EventTypes; import com.cloud.event.EventUtils; import com.cloud.event.EventVO; +import com.cloud.event.UsageEventVO; import com.cloud.event.dao.EventDao; +import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.AccountLimitException; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; @@ -188,6 +190,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Inject FirewallRulesDao _firewallRulesDao; @Inject LoadBalancerDao _lbDao; @Inject PortForwardingRulesDao _pfRulesDao; + @Inject UsageEventDao _usageEventDao; @Inject(adapter=NetworkGuru.class) Adapters _networkGurus; @@ -251,6 +254,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!_ipAddressDao.update(addr.getAddress(), addr)) { throw new CloudRuntimeException("Found address to allocate but unable to update: " + addr); } + if(!sourceNat){ + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getAccountId(), dcId, -1, addr.getAddress()); + _usageEventDao.persist(usageEvent); + } txn.commit(); long macAddress = NetUtils.createSequenceBasedMacAddress(addr.getMacAddress()); @@ -664,7 +671,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (success) { _ipAddressDao.unassignIpAddress(ipAddress); - s_logger.debug("released a public ip: " + ipAddress); + s_logger.debug("released a public ip: " + ipAddress); + if(!ip.isSourceNat()){ + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ownerId, ip.getDataCenterId(), -1, ipAddress); + _usageEventDao.persist(usageEvent); + } } final EventVO event = new EventVO(); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 9f4b9de9bb1..e7785b3aab5 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -92,7 +92,9 @@ import com.cloud.domain.dao.DomainDao; import com.cloud.event.Event; import com.cloud.event.EventTypes; import com.cloud.event.EventVO; +import com.cloud.event.UsageEventVO; import com.cloud.event.dao.EventDao; +import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.DiscoveryException; @@ -211,6 +213,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag @Inject protected UserDao _userDao; @Inject protected ClusterDao _clusterDao; @Inject protected VirtualNetworkApplianceManager _routerMgr; + @Inject protected UsageEventDao _usageEventDao; + @Inject(adapter=StoragePoolAllocator.class) protected Adapters _storagePoolAllocators; @@ -830,6 +834,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag volume.setPodId(pod.getId()); volume.setState(Volume.State.Ready); _volsDao.persist(volume); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOffering.getId(), null , dskCh.getSize()); + _usageEventDao.persist(usageEvent); + } txn.commit(); return volume; @@ -1906,6 +1913,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag event.setParameters(eventParams); event.setState(Event.State.Completed); _eventDao.persist(event); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOffering.getId(), null , sizeMB); + _usageEventDao.persist(usageEvent); /* } else { event.setDescription("Unable to create a volume for " + volume); @@ -1943,6 +1952,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag event.setDescription("Volume " +volume.getName()+ " deleted"); event.setLevel(EventVO.LEVEL_INFO); _eventDao.persist(event); + + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), null, null , null); + _usageEventDao.persist(usageEvent); // Delete the recurring snapshot policies for this volume. _snapshotMgr.deletePoliciesForVolume(volumeId); diff --git a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java index fc83018b079..fd599f3a523 100755 --- a/server/src/com/cloud/storage/download/DownloadMonitorImpl.java +++ b/server/src/com/cloud/storage/download/DownloadMonitorImpl.java @@ -43,7 +43,9 @@ import com.cloud.dc.DataCenterVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.event.EventTypes; import com.cloud.event.EventVO; +import com.cloud.event.UsageEventVO; import com.cloud.event.dao.EventDao; +import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.StorageUnavailableException; import com.cloud.host.Host; @@ -103,6 +105,9 @@ public class DownloadMonitorImpl implements DownloadMonitor { private AgentManager _agentMgr; @Inject ConfigurationDao _configDao; + + @Inject + private UsageEventDao _usageEventDao; private String _name; private Boolean _sslCopy = new Boolean(false); @@ -374,6 +379,8 @@ public class DownloadMonitorImpl implements DownloadMonitor { event.setParameters(eventParams); event.setLevel(EventVO.LEVEL_INFO); _eventDao.persist(event); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_TEMPLATE_CREATE, template.getAccountId(), host.getDataCenterId(), template.getId(), template.getName(), null, null , size); + _usageEventDao.persist(usageEvent); } if (vmTemplateHost != null) { diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 70aa180e279..168f81d1f9f 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -61,7 +61,9 @@ import com.cloud.event.Event; import com.cloud.event.EventTypes; import com.cloud.event.EventUtils; import com.cloud.event.EventVO; +import com.cloud.event.UsageEventVO; import com.cloud.event.dao.EventDao; +import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; @@ -158,6 +160,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe @Inject AsyncJobManager _asyncMgr; @Inject UserVmManager _vmMgr; @Inject ConfigurationDao _configDao; + @Inject UsageEventDao _usageEventDao; protected SearchBuilder HostTemplateStatesSearch; @Override diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index f00bc38d255..f952c5276dd 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -103,7 +103,9 @@ import com.cloud.event.Event; import com.cloud.event.EventTypes; import com.cloud.event.EventUtils; import com.cloud.event.EventVO; +import com.cloud.event.UsageEventVO; import com.cloud.event.dao.EventDao; +import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -252,6 +254,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager @Inject VirtualNetworkApplianceManager _routerMgr; @Inject NicDao _nicDao; @Inject RulesManager _rulesMgr; + @Inject UsageEventDao _usageEventDao; private IpAddrAllocator _IpAllocator; ScheduledExecutorService _executor = null; @@ -1106,7 +1109,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (!destroy(vm)) { return false; } - cleanNetworkRules(userId, vmId); // Mark the VM's disks as destroyed @@ -1234,6 +1236,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } _eventDao.persist(event); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); + _usageEventDao.persist(usageEvent); txn.commit(); return _vmDao.findById(vmId); @@ -2527,6 +2531,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (s_logger.isDebugEnabled()) { s_logger.debug("Successfully allocated DB entry for " + vm); } + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE, accountId, dc.getId(), vm.getId(), vm.getName(), offering.getId(), template.getId(), null); + _usageEventDao.persist(usageEvent); return vm; } @@ -2718,6 +2724,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (status) { EventUtils.saveEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Successfully destroyed vm with id:"+vmId); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); + _usageEventDao.persist(usageEvent); return _vmDao.findById(vmId); } else { EventUtils.saveEvent(userId, vm.getAccountId(), EventTypes.EVENT_VM_DESTROY, "Failed to destroy vm with id:"+vmId); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 559ad108b10..2e0aadc9130 100644 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -51,6 +51,8 @@ import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.domain.dao.DomainDao; import com.cloud.event.EventTypes; import com.cloud.event.EventVO; +import com.cloud.event.UsageEventVO; +import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.AgentUnavailableException; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -113,6 +115,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster @Inject private DomainRouterDao _routerDao; @Inject private ConsoleProxyDao _consoleDao; @Inject private SecondaryStorageVmDao _secondaryDao; + @Inject private UsageEventDao _usageEventDao; @Inject(adapter=DeploymentPlanner.class) private Adapters _planners; @@ -431,6 +434,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster if (!stateTransitTo(vm, Event.OperationSucceeded, dest.getHost().getId())) { throw new CloudRuntimeException("Unable to transition to a new state."); } + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_START, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); + _usageEventDao.persist(usageEvent); return vm; } s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + answers[0].getDetails()); @@ -504,6 +509,9 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster stopped = answer.getResult(); if (!stopped) { throw new CloudRuntimeException("Unable to stop the virtual machine due to " + answer.getDetails()); + } else { + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_STOP, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); + _usageEventDao.persist(usageEvent); } } finally { if (!stopped) { diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 63caeb79eef..7282e3b603a 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -1257,7 +1257,6 @@ CREATE TABLE `cloud`.`usage_event` ( `id` bigint unsigned NOT NULL auto_increment, `type` varchar(32) NOT NULL, `account_id` bigint unsigned NOT NULL, - `domain_id` bigint unsigned NOT NULL, `created` datetime NOT NULL, `zone_id` bigint unsigned NOT NULL, `resource_id` bigint unsigned, From b12cd70216eba14f122e3f71cc6e4e731008a4e0 Mon Sep 17 00:00:00 2001 From: kishan Date: Wed, 22 Dec 2010 18:03:24 +0530 Subject: [PATCH 04/23] bug 7504: Added usage events and made corresponding changes in usage server --- .../production/premium/conf/usage-components.xml | 3 ++- .../src/com/cloud/network/NetworkManagerImpl.java | 4 ++-- .../network/lb/LoadBalancingRulesManagerImpl.java | 7 +++++++ .../src/com/cloud/storage/StorageManagerImpl.java | 12 ++++++++++++ .../cloud/storage/snapshot/SnapshotManagerImpl.java | 13 +++++++++++++ .../src/com/cloud/template/TemplateManagerImpl.java | 7 ++++++- .../src/com/cloud/vm/VirtualMachineManagerImpl.java | 7 +++++-- 7 files changed, 47 insertions(+), 6 deletions(-) diff --git a/build/deploy/production/premium/conf/usage-components.xml b/build/deploy/production/premium/conf/usage-components.xml index 5e178302819..37d66abe715 100644 --- a/build/deploy/production/premium/conf/usage-components.xml +++ b/build/deploy/production/premium/conf/usage-components.xml @@ -29,7 +29,6 @@ 50 -1 - @@ -41,6 +40,8 @@ + + DAILY diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index f9d2811a5d9..fdec1d7c600 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -255,7 +255,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag throw new CloudRuntimeException("Found address to allocate but unable to update: " + addr); } if(!sourceNat){ - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getAccountId(), dcId, -1, addr.getAddress()); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getAccountId(), dcId, 0, addr.getAddress()); _usageEventDao.persist(usageEvent); } @@ -673,7 +673,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag _ipAddressDao.unassignIpAddress(ipAddress); s_logger.debug("released a public ip: " + ipAddress); if(!ip.isSourceNat()){ - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ownerId, ip.getDataCenterId(), -1, ipAddress); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ownerId, ip.getDataCenterId(), 0, ipAddress); _usageEventDao.persist(usageEvent); } } diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java index 3bd44c1119c..82a46fff76d 100644 --- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java +++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java @@ -36,7 +36,9 @@ import com.cloud.dc.dao.VlanDao; import com.cloud.domain.dao.DomainDao; import com.cloud.event.EventTypes; import com.cloud.event.EventVO; +import com.cloud.event.UsageEventVO; import com.cloud.event.dao.EventDao; +import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.PermissionDeniedException; @@ -105,6 +107,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager, @Inject AccountDao _accountDao; @Inject DomainDao _domainDao; @Inject NicDao _nicDao; + @Inject UsageEventDao _usageEventDao; @Override @DB public boolean assignToLoadBalancer(long loadBalancerId, List instanceIds) { @@ -241,6 +244,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager, } _rulesDao.remove(lb.getId()); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_LOAD_BALANCER_DELETE, lb.getAccountId(), 0 , lb.getId(), null); + _usageEventDao.persist(usageEvent); s_logger.debug("Load balancer with id " + lb.getId() + " is removed successfully"); return true; } @@ -327,6 +332,8 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager, String params = "id=" + newRule.getId() + "\ndcId=" + ipAddr.getDataCenterId(); event.setParameters(params); event.setLevel(EventVO.LEVEL_INFO); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_LOAD_BALANCER_CREATE, ipAddr.getAllocatedToAccountId(), ipAddr.getDataCenterId(), newRule.getId(), null); + _usageEventDao.persist(usageEvent); } _eventDao.persist(event); } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index e7785b3aab5..a1b099906de 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -700,6 +700,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag if (createdVolume.getPath() != null) { event.setDescription("Created volume: "+ createdVolume.getName() + " with size: " + sizeMB + " MB in pool: " + poolName + " from snapshot id: " + snapshotId); event.setLevel(EventVO.LEVEL_INFO); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOfferingId, templateId , sizeMB); + _usageEventDao.persist(usageEvent); } else { details = "CreateVolume From Snapshot for snapshotId: " + snapshotId + " failed at the backend, reason " + details; @@ -2684,6 +2686,11 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag vol = _volsDao.persist(vol); + if(vm instanceof UserVm){ + long sizeMB = size / (1024 * 1024); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), null , sizeMB); + _usageEventDao.persist(usageEvent); + } return toDiskProfile(vol, offering); } @@ -2716,6 +2723,11 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag vol = _volsDao.persist(vol); + if(vm instanceof UserVm){ + long sizeMB = vol.getSize() / (1024 * 1024); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), template.getId() , sizeMB); + _usageEventDao.persist(usageEvent); + } return toDiskProfile(vol, offering); } diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index a789192c28e..f6bbdff9f02 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -59,7 +59,9 @@ import com.cloud.domain.dao.DomainDao; import com.cloud.event.EventTypes; import com.cloud.event.EventUtils; import com.cloud.event.EventVO; +import com.cloud.event.UsageEventVO; import com.cloud.event.dao.EventDao; +import com.cloud.event.dao.UsageEventDao; import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; @@ -138,6 +140,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma @Inject protected AsyncJobManager _asyncMgr; @Inject protected AccountManager _accountMgr; @Inject protected ClusterDao _clusterDao; + @Inject private UsageEventDao _usageEventDao; String _name; private int _totalRetries; private int _pauseInterval; @@ -524,6 +527,8 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma event.setDescription("Backed up snapshot id: " + snapshotId + " to secondary for volume:" + volumeId); event.setLevel(EventVO.LEVEL_INFO); event.setParameters(eventParams); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), volume.getDataCenterId(), snapshotId, snapshotName, null, null, volume.getSize()); + _usageEventDao.persist(usageEvent); } else { @@ -769,6 +774,12 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma event.setLevel(success ? EventVO.LEVEL_INFO : EventVO.LEVEL_ERROR); _eventDao.persist(event); + if(success){ + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, snapshot.getAccountId(), volume.getDataCenterId(), snapshotId, snapshot.getName(), null, null, volume.getSize()); + _usageEventDao.persist(usageEvent); + } + + return success; } @@ -955,6 +966,8 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma event.setParameters(eventParams); event.setLevel(EventVO.LEVEL_INFO); _eventDao.persist(event); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, snapshot.getAccountId(), volume.getDataCenterId(), snapshot.getId(), snapshot.getName(), null, null, volume.getSize()); + _usageEventDao.persist(usageEvent); } } } diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 168f81d1f9f..4fac3ba883b 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -129,6 +129,7 @@ import com.cloud.vm.VMInstanceVO; import com.cloud.vm.dao.UserVmDao; import com.cloud.vm.dao.VMInstanceDao; + @Local(value={TemplateManager.class, TemplateService.class}) public class TemplateManagerImpl implements TemplateManager, Manager, TemplateService { private final static Logger s_logger = Logger.getLogger(TemplateManagerImpl.class); @@ -160,7 +161,7 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe @Inject AsyncJobManager _asyncMgr; @Inject UserVmManager _vmMgr; @Inject ConfigurationDao _configDao; - @Inject UsageEventDao _usageEventDao; + @Inject UsageEventDao _usageEventDao; protected SearchBuilder HostTemplateStatesSearch; @Override @@ -817,6 +818,8 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe _downloadMonitor.copyTemplate(vmTemplate, srcSecHost, dstSecHost); + UsageEventVO usageEvent = new UsageEventVO(copyEventType, account.getId(), destZoneId, templateId, null, null, null, srcTmpltHost.getSize()); + _usageEventDao.persist(usageEvent); saveEvent(userId, account.getId(), account.getDomainId(), copyEventType, copyEventDescription, EventVO.LEVEL_INFO, params, startEventId); return true; } @@ -963,6 +966,8 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe String zoneParams = params + "\ndcId=" + sZoneId; saveEvent(userId, account.getId(), account.getDomainId(), eventType, description + template.getName() + " succesfully deleted.", EventVO.LEVEL_INFO, zoneParams, 0); + UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), sZoneId, templateId, null, null, null, null); + _usageEventDao.persist(usageEvent); } finally { if (lock != null) { _tmpltHostDao.releaseFromLockTable(lock.getId()); diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 2e0aadc9130..dcbee11b561 100644 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -76,6 +76,7 @@ import com.cloud.user.Account; import com.cloud.user.User; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; +import com.cloud.uservm.UserVm; import com.cloud.utils.Journal; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; @@ -434,8 +435,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Cluster if (!stateTransitTo(vm, Event.OperationSucceeded, dest.getHost().getId())) { throw new CloudRuntimeException("Unable to transition to a new state."); } - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_START, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); - _usageEventDao.persist(usageEvent); + if(vm instanceof UserVm){ + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_START, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); + _usageEventDao.persist(usageEvent); + } return vm; } s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + answers[0].getDetails()); From 2d7979ec88aa6cbd02f50b4b81aa7652b0b6b121 Mon Sep 17 00:00:00 2001 From: kishan Date: Wed, 22 Dec 2010 18:11:40 +0530 Subject: [PATCH 05/23] bug 7504: UsageEvent dao and related objects --- core/src/com/cloud/event/UsageEvent.java | 33 ++++ core/src/com/cloud/event/UsageEventVO.java | 169 ++++++++++++++++++ .../com/cloud/event/dao/UsageEventDao.java | 42 +++++ .../cloud/event/dao/UsageEventDaoImpl.java | 163 +++++++++++++++++ 4 files changed, 407 insertions(+) create mode 100644 core/src/com/cloud/event/UsageEvent.java create mode 100644 core/src/com/cloud/event/UsageEventVO.java create mode 100644 core/src/com/cloud/event/dao/UsageEventDao.java create mode 100644 core/src/com/cloud/event/dao/UsageEventDaoImpl.java diff --git a/core/src/com/cloud/event/UsageEvent.java b/core/src/com/cloud/event/UsageEvent.java new file mode 100644 index 00000000000..c90840afce2 --- /dev/null +++ b/core/src/com/cloud/event/UsageEvent.java @@ -0,0 +1,33 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.event; + +import java.util.Date; + +public interface UsageEvent { + long getId(); + String getType(); + + Date getCreateDate(); + long getAccountId(); + Long getSize(); + Long getTemplateId(); + Long getOfferingId(); + long getResourceId(); + long getZoneId(); +} diff --git a/core/src/com/cloud/event/UsageEventVO.java b/core/src/com/cloud/event/UsageEventVO.java new file mode 100644 index 00000000000..4390978b8bf --- /dev/null +++ b/core/src/com/cloud/event/UsageEventVO.java @@ -0,0 +1,169 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.event; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.PrimaryKeyJoinColumn; +import javax.persistence.SecondaryTable; +import javax.persistence.Table; + +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name="usage_event") +@SecondaryTable(name="account", + pkJoinColumns={@PrimaryKeyJoinColumn(name="account_id", referencedColumnName="id")}) +public class UsageEventVO implements UsageEvent { + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + @Column(name="id") + private long id = -1; + + @Column(name="type") + private String type; + + @Column(name=GenericDao.CREATED_COLUMN) + private Date createDate; + + @Column(name="account_id") + private long accountId; + + @Column(name="zone_id") + private long zoneId; + + @Column(name="resource_id") + private long resourceId; + + @Column(name="resource_name") + private String resourceName; + + @Column(name="offering_id") + private Long offeringId; + + @Column(name="template_id") + private Long templateId; + + @Column(name="size") + private Long size; + + + public UsageEventVO() { + } + + public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, Long size) { + this.type = usageType; + this.accountId = accountId; + this.zoneId = zoneId; + this.resourceId = resourceId; + this.resourceName = resourceName; + this.offeringId = offeringId; + this.templateId = templateId; + this.size = size; + } + + public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName) { + this.type = usageType; + this.accountId = accountId; + this.zoneId = zoneId; + this.resourceId = resourceId; + this.resourceName = resourceName; + } + + public long getId() { + return id; + } + @Override + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + @Override + public Date getCreateDate() { + return createDate; + } + public void setCreatedDate(Date createdDate) { + createDate = createdDate; + } + + @Override + public long getAccountId() { + return accountId; + } + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + public void setZoneId(long zoneId) { + this.zoneId = zoneId; + } + @Override + public long getZoneId() { + return zoneId; + } + + public void setResourceId(long resourceId) { + this.resourceId = resourceId; + } + @Override + public long getResourceId() { + return resourceId; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getResourceName() { + return resourceName; + } + + public void setOfferingId(long offeringId) { + this.offeringId = offeringId; + } + @Override + public Long getOfferingId() { + return offeringId; + } + + public void setTemplateId(long templateId) { + this.templateId = templateId; + } + @Override + public Long getTemplateId() { + return templateId; + } + + public void setSize(long size) { + this.size = size; + } + @Override + public Long getSize() { + return size; + } + +} diff --git a/core/src/com/cloud/event/dao/UsageEventDao.java b/core/src/com/cloud/event/dao/UsageEventDao.java new file mode 100644 index 00000000000..271856b2f5d --- /dev/null +++ b/core/src/com/cloud/event/dao/UsageEventDao.java @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.event.dao; + +import java.util.Date; +import java.util.List; + +import com.cloud.event.UsageEventVO; +import com.cloud.exception.UsageServerException; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDao; +import com.cloud.utils.db.SearchCriteria; + +public interface UsageEventDao extends GenericDao { + + public List searchAllUsageEvents(SearchCriteria sc, Filter filter); + + public List listLatestEvents(Date recentEventDate, Date endDate); + + public List listAllEvents(Date endDate); + + public List getLatestEventDate(); + + List getRecentEvents(Date endDate) throws UsageServerException; + +} \ No newline at end of file diff --git a/core/src/com/cloud/event/dao/UsageEventDaoImpl.java b/core/src/com/cloud/event/dao/UsageEventDaoImpl.java new file mode 100644 index 00000000000..170892dd95e --- /dev/null +++ b/core/src/com/cloud/event/dao/UsageEventDaoImpl.java @@ -0,0 +1,163 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.event.dao; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Date; +import java.util.List; +import java.util.TimeZone; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +import com.cloud.event.UsageEventVO; +import com.cloud.exception.UsageServerException; +import com.cloud.utils.DateUtil; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; + +@Local(value={UsageEventDao.class}) +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 allEventsSearch; + private static final String GET_LATEST_EVENT_DATE = "SELECT created FROM usage_event ORDER BY created DESC LIMIT 1"; + private static final String COPY_EVENTS = "INSERT INTO cloud_usage.usage_event SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size FROM cloud.usage_event vmevt WHERE vmevt.created > ? and vmevt.created <= ? "; + private static final String COPY_ALL_EVENTS = "INSERT INTO cloud_usage.usage_event SELECT id, type, account_id, created, zone_id, resource_id, resource_name, offering_id, template_id, size FROM cloud.usage_event where created <= ? "; + + + public UsageEventDaoImpl () { + latestEventsSearch = createSearchBuilder(); + latestEventsSearch.and("recentEventDate", latestEventsSearch.entity().getCreateDate(), SearchCriteria.Op.GT); + latestEventsSearch.and("enddate", latestEventsSearch.entity().getCreateDate(), SearchCriteria.Op.LTEQ); + latestEventsSearch.done(); + + allEventsSearch = createSearchBuilder(); + allEventsSearch.and("enddate", allEventsSearch.entity().getCreateDate(), SearchCriteria.Op.LTEQ); + allEventsSearch.done(); + + } + + @Override + public List listLatestEvents(Date recentEventDate, Date endDate) { + Filter filter = new Filter(UsageEventVO.class, "createDate", Boolean.TRUE, null, null); + SearchCriteria sc = latestEventsSearch.create(); + sc.setParameters("recentEventDate", recentEventDate); + sc.setParameters("enddate", endDate); + return listBy(sc, filter); + } + + @Override + public List listAllEvents(Date endDate) { + Filter filter = new Filter(UsageEventVO.class, "createDate", Boolean.TRUE, null, null); + SearchCriteria sc = latestEventsSearch.create(); + sc.setParameters("enddate", endDate); + return listBy(sc, filter); + } + + @Override + public List getLatestEventDate() { + Filter filter = new Filter(UsageEventVO.class, "createDate", Boolean.FALSE, null, 1L); + return listAll(filter); + } + + @Override + public List searchAllUsageEvents(SearchCriteria sc, Filter filter) { + return listIncludingRemovedBy(sc, filter); + } + + + public synchronized List getRecentEvents(Date endDate) throws UsageServerException { + Transaction txn = Transaction.open(Transaction.USAGE_DB); + Date recentEventDate = getMostRecentEventDate(); + String sql = COPY_EVENTS; + if (recentEventDate == null) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("no recent event date, copying all events"); + } + sql = COPY_ALL_EVENTS; + } + + PreparedStatement pstmt = null; + try { + txn.start(); + pstmt = txn.prepareAutoCloseStatement(sql); + int i = 1; + if (recentEventDate != null) { + pstmt.setString(i++, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), recentEventDate)); + } + pstmt.setString(i, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), endDate)); + pstmt.executeUpdate(); + txn.commit(); + return findRecentEvents(recentEventDate, endDate); + } catch (Exception ex) { + txn.rollback(); + s_logger.error("error copying events from cloud db to usage db", ex); + throw new UsageServerException(ex.getMessage()); + } finally { + txn.close(); + } + } + + private Date getMostRecentEventDate() throws UsageServerException { + Transaction txn = Transaction.open(Transaction.USAGE_DB); + PreparedStatement pstmt = null; + String sql = GET_LATEST_EVENT_DATE; + try { + pstmt = txn.prepareAutoCloseStatement(sql); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) { + String mostRecentTimestampStr = rs.getString(1); + if (mostRecentTimestampStr != null) { + return DateUtil.parseDateString(s_gmtTimeZone, mostRecentTimestampStr); + } + } + } catch (Exception ex) { + s_logger.error("error getting most recent event date", ex); + throw new UsageServerException(ex.getMessage()); + } finally { + txn.close(); + } + return null; + } + + private List findRecentEvents(Date recentEventDate, Date endDate) throws UsageServerException { + Transaction txn = Transaction.open(Transaction.USAGE_DB); + try { + int i = 1; + if (recentEventDate == null) { + return listAllEvents(endDate); + } else { + return listLatestEvents(recentEventDate, endDate); + } + } catch (Exception ex) { + s_logger.error("error getting most recent event date", ex); + throw new UsageServerException(ex.getMessage()); + } finally { + txn.close(); + } + } + +} From 9837cba9f1d84920fab856ec215886e615e70d2d Mon Sep 17 00:00:00 2001 From: kishan Date: Wed, 22 Dec 2010 20:26:34 +0530 Subject: [PATCH 06/23] bug 7504: Add usage events for VM destroy and stop during account delete --- server/src/com/cloud/vm/UserVmManagerImpl.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index f952c5276dd..c520f4dd438 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1109,6 +1109,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (!destroy(vm)) { return false; } + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); + _usageEventDao.persist(usageEvent); cleanNetworkRules(userId, vmId); // Mark the VM's disks as destroyed @@ -1388,6 +1390,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } _eventDao.persist(event); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_STOP, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName(), vm.getServiceOfferingId(), vm.getTemplateId(), null); + _usageEventDao.persist(usageEvent); + if (_storageMgr.unshare(vm, null) == null) { s_logger.warn("Unable to set share to false for " + vm.toString()); } From fe6824a66b621ff1d5a3e9e760dd7a46acb45649 Mon Sep 17 00:00:00 2001 From: edison Date: Tue, 21 Dec 2010 22:04:42 -0800 Subject: [PATCH 07/23] fix upload ova template --- server/src/com/cloud/template/TemplateManagerImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 4fac3ba883b..d28cf33a099 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -342,9 +342,11 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe } if((!url.toLowerCase().endsWith("vhd"))&&(!url.toLowerCase().endsWith("vhd.zip")) - &&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz") + &&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz")) &&(!url.toLowerCase().endsWith("qcow2"))&&(!url.toLowerCase().endsWith("qcow2.zip")) - &&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz")))){ + &&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz")) + &&(!url.toLowerCase().endsWith("ova"))&&(!url.toLowerCase().endsWith("ova.zip")) + &&(!url.toLowerCase().endsWith("ova.bz2"))&&(!url.toLowerCase().endsWith("ova.gz"))){ throw new ServerApiException(BaseCmd.PARAM_ERROR, "Please specify a valid "+format.toLowerCase()); } From 9fd24869fabffbf1c8c249b83aba49ab02c25b45 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Wed, 22 Dec 2010 10:42:36 -0800 Subject: [PATCH 08/23] bug 7641: resource page - Add Pod dialog, Add Host dialog - zone dropdown field might be empty (e.g. before first zone is created). Skip API call if zone field is empty. --- ui/scripts/cloud.core.resource.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/scripts/cloud.core.resource.js b/ui/scripts/cloud.core.resource.js index 03a55a5e6ea..5c93053e7e7 100644 --- a/ui/scripts/cloud.core.resource.js +++ b/ui/scripts/cloud.core.resource.js @@ -324,6 +324,8 @@ function initAddPodShortcut() { $zoneDropdown.bind("change", function(event) { var zoneId = $(this).val(); + if(zoneId == null) + return; $.ajax({ data: createURL("command=listZones&id="+zoneId), dataType: "json", @@ -484,6 +486,8 @@ function initAddHostShortcut() { $dialogAddHost.find("#zone_dropdown").bind("change", function(event) { var zoneId = $(this).val(); + if(zoneId == null) + return; $.ajax({ data: createURL("command=listPods&zoneId="+zoneId), dataType: "json", From ec9260ce62fcb58c7646102e233567ac47856a64 Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 21 Dec 2010 18:23:13 -0800 Subject: [PATCH 09/23] bug 7619: Added list of Capabilities parameter for Network status 7619: resolved fixed --- .../response/CapabilityResponse.java} | 33 +++++++-- .../cloud/api/response/NetworkResponse.java | 15 +++- .../cloud/api/response/ServiceResponse.java | 49 +++++++++++++ .../cloud/api/response/UserVmResponse.java | 6 +- api/src/com/cloud/network/Network.java | 68 +++++++++++++++++++ api/src/com/cloud/network/NetworkService.java | 1 + .../cloud/network/element/NetworkElement.java | 9 +++ server/src/com/cloud/api/ApiDBUtils.java | 7 ++ .../src/com/cloud/api/ApiResponseHelper.java | 35 +++++++++- server/src/com/cloud/dc/DataCenterVO.java | 22 +++--- .../src/com/cloud/network/NetworkManager.java | 5 ++ .../com/cloud/network/NetworkManagerImpl.java | 49 ++++++++++++- server/src/com/cloud/network/NetworkVO.java | 2 +- .../cloud/network/element/DhcpElement.java | 42 ++++++++++-- .../network/element/VirtualRouterElement.java | 55 ++++++++++++++- 15 files changed, 363 insertions(+), 35 deletions(-) rename api/src/com/cloud/{network/service/Providers.java => api/response/CapabilityResponse.java} (52%) create mode 100644 api/src/com/cloud/api/response/ServiceResponse.java diff --git a/api/src/com/cloud/network/service/Providers.java b/api/src/com/cloud/api/response/CapabilityResponse.java similarity index 52% rename from api/src/com/cloud/network/service/Providers.java rename to api/src/com/cloud/api/response/CapabilityResponse.java index 5556fd94394..079a5e6af51 100644 --- a/api/src/com/cloud/network/service/Providers.java +++ b/api/src/com/cloud/api/response/CapabilityResponse.java @@ -15,10 +15,33 @@ * along with this program. If not, see . * */ -package com.cloud.network.service; +package com.cloud.api.response; -public class Providers { - public final static String VirtualRouter = "VirtualRouter"; - public final static String ExternalFirewall = "ExternalFirewall"; - public final static String ExternalLoadBalancer = "ExternalLoadBalancer"; +import com.cloud.api.ApiConstants; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class CapabilityResponse extends BaseResponse { + + @SerializedName(ApiConstants.NAME) @Param(description="the capability name") + private String name; + + @SerializedName(ApiConstants.VALUE) @Param(description="the capability value") + private String value; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } } diff --git a/api/src/com/cloud/api/response/NetworkResponse.java b/api/src/com/cloud/api/response/NetworkResponse.java index b83852a3fb2..0c1df19f4e9 100644 --- a/api/src/com/cloud/api/response/NetworkResponse.java +++ b/api/src/com/cloud/api/response/NetworkResponse.java @@ -1,5 +1,7 @@ package com.cloud.api.response; +import java.util.List; + import com.cloud.api.ApiConstants; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @@ -102,6 +104,9 @@ public class NetworkResponse extends BaseResponse{ @SerializedName(ApiConstants.DOMAIN) @Param(description="the domain associated with the network") private String domain; + + @SerializedName("service") @Param(description="the list of services") + private List services; public Long getId() { return id; @@ -310,6 +315,12 @@ public class NetworkResponse extends BaseResponse{ public void setNetworkOfferingAvailability(String networkOfferingAvailability) { this.networkOfferingAvailability = networkOfferingAvailability; } - - + + public List getServices() { + return services; + } + + public void setServices(List services) { + this.services = services; + } } diff --git a/api/src/com/cloud/api/response/ServiceResponse.java b/api/src/com/cloud/api/response/ServiceResponse.java new file mode 100644 index 00000000000..d28c9f496ec --- /dev/null +++ b/api/src/com/cloud/api/response/ServiceResponse.java @@ -0,0 +1,49 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package com.cloud.api.response; + +import java.util.List; + +import com.cloud.api.ApiConstants; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class ServiceResponse extends BaseResponse { + + @SerializedName(ApiConstants.NAME) @Param(description="the service name") + private String name; + + @SerializedName("capability") @Param(description="the list of capabilities") + private List capabilities; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getCapabilities() { + return capabilities; + } + + public void setCapabilities(List capabilities) { + this.capabilities = capabilities; + } +} \ No newline at end of file diff --git a/api/src/com/cloud/api/response/UserVmResponse.java b/api/src/com/cloud/api/response/UserVmResponse.java index 3e34772a68b..40625421b9c 100644 --- a/api/src/com/cloud/api/response/UserVmResponse.java +++ b/api/src/com/cloud/api/response/UserVmResponse.java @@ -142,12 +142,12 @@ public class UserVmResponse extends BaseResponse { @SerializedName("jobstatus") @Param(description="shows the current pending asynchronous job status") private Integer jobStatus; + @SerializedName("nic") @Param(description="the list of nics associated with vm") + private List nics; + public Long getObjectId() { return getId(); } - - @SerializedName("nic") @Param(description="the list of nics associated with vm") - private List nics; public Long getId() { return id; diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index 5d2053163f8..b7ea407758b 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -20,6 +20,73 @@ import com.cloud.utils.fsm.StateMachine; * owned by an account. */ public interface Network extends ControlledEntity { + + public static class Service { + + public static final Service Vpn = new Service("Vpn"); + public static final Service Dhcp = new Service("Dhcp"); + public static final Service Dns = new Service("Dns"); + public static final Service Gateway = new Service("Gateway"); + public static final Service Firewall = new Service("Firewall", Capability.PortForwarding, Capability.StaticNat); + public static final Service Lb = new Service("Lb"); + public static final Service UserData = new Service("UserData"); + + private String name; + private Capability[] caps; + + public Service(String name, Capability... caps) { + this.name = name; + } + + public String getName() { + return name; + } + + public Capability[] getCapabilities() { + return caps; + } + } + + public static class Provider { + + public static final Provider VirtualRouter = new Provider("VirtualRouter"); + public static final Provider DhcpServer = new Provider("DhcpServer"); + public static final Provider ExternalFirewall = new Provider("ExternalFirewall"); + public static final Provider ExternalLoadBalancer = new Provider("ExternalLoadBalancer"); + + private String name; + + public Provider(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + public static class Capability { + + public static final Capability PortForwarding = new Capability("PortForwarding"); + public static final Capability StaticNat = new Capability("StaticNat"); + public static final Capability SupportedProtocols = new Capability("SupportedProtocols"); + public static final Capability SupportedLBAlgorithms = new Capability("SupportedLBAlgorithms"); + public static final Capability Vpn = new Capability("VPN"); + public static final Capability MultipleIps = new Capability("MultipleIps"); + public static final Capability SupportedSourceNatTypes = new Capability("SupportedSourceNatTypes"); + public static final Capability SupportedVpnTypes = new Capability("SupportedVpnTypes"); + + private String name; + + public Capability(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + enum Event { ImplementNetwork, DestroyNetwork, @@ -114,4 +181,5 @@ public interface Network extends ControlledEntity { boolean isShared(); String getReservationId(); + } diff --git a/api/src/com/cloud/network/NetworkService.java b/api/src/com/cloud/network/NetworkService.java index 2471ff5f3e9..d71f6e712ca 100644 --- a/api/src/com/cloud/network/NetworkService.java +++ b/api/src/com/cloud/network/NetworkService.java @@ -90,4 +90,5 @@ public interface NetworkService { boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException; int getActiveNicsInNetwork(long networkId); + } diff --git a/api/src/com/cloud/network/element/NetworkElement.java b/api/src/com/cloud/network/element/NetworkElement.java index 4854a391ec0..9586e7ae59e 100644 --- a/api/src/com/cloud/network/element/NetworkElement.java +++ b/api/src/com/cloud/network/element/NetworkElement.java @@ -4,6 +4,7 @@ package com.cloud.network.element; import java.util.List; +import java.util.Map; import com.cloud.deploy.DeployDestination; import com.cloud.exception.ConcurrentOperationException; @@ -11,6 +12,9 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientNetworkCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; import com.cloud.network.PublicIpAddress; import com.cloud.network.rules.FirewallRule; import com.cloud.offering.NetworkOffering; @@ -24,6 +28,11 @@ import com.cloud.vm.VirtualMachineProfile; * Represents one network element that exists in a network. */ public interface NetworkElement extends Adapter { + + Map> getCapabilities(); + + Provider getProvider(); + /** * Implement the network configuration as specified. * @param config fully specified network configuration. diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 1aed0885da8..7f1b25b7b46 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -2,6 +2,7 @@ package com.cloud.api; import java.util.ArrayList; import java.util.List; +import java.util.Map; import com.cloud.agent.AgentManager; import com.cloud.async.AsyncJobManager; @@ -32,6 +33,8 @@ import com.cloud.network.Network; import com.cloud.network.NetworkManager; import com.cloud.network.NetworkRuleConfigVO; import com.cloud.network.NetworkVO; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Service; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.NetworkDao; @@ -508,4 +511,8 @@ public class ApiDBUtils { return _networkDao.findById(id); } + public static Map> getZoneCapabilities(long zoneId) { + return _networkMgr.getZoneCapabilities(zoneId); + } + } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 0cb29aa5434..ccef3e0d8f7 100644 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -34,6 +34,7 @@ import com.cloud.api.commands.QueryAsyncJobResultCmd; import com.cloud.api.response.AccountResponse; import com.cloud.api.response.ApiResponseSerializer; import com.cloud.api.response.AsyncJobResponse; +import com.cloud.api.response.CapabilityResponse; import com.cloud.api.response.CapacityResponse; import com.cloud.api.response.ClusterResponse; import com.cloud.api.response.ConfigurationResponse; @@ -60,6 +61,7 @@ import com.cloud.api.response.RemoteAccessVpnResponse; import com.cloud.api.response.ResourceLimitResponse; import com.cloud.api.response.SecurityGroupResponse; import com.cloud.api.response.ServiceOfferingResponse; +import com.cloud.api.response.ServiceResponse; import com.cloud.api.response.SnapshotPolicyResponse; import com.cloud.api.response.SnapshotResponse; import com.cloud.api.response.StoragePoolResponse; @@ -97,6 +99,8 @@ import com.cloud.host.HostStats; import com.cloud.host.HostVO; import com.cloud.network.IpAddress; import com.cloud.network.Network; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Service; import com.cloud.network.Networks.TrafficType; import com.cloud.network.RemoteAccessVpn; import com.cloud.network.VpnUser; @@ -2209,7 +2213,36 @@ public class ApiResponseHelper implements ResponseGenerator { response.setRelated(network.getRelated()); response.setDns1(network.getDns1()); response.setDns2(network.getDns2()); - + + //populate capability + Map> serviceCapabilitiesMap = ApiDBUtils.getZoneCapabilities(network.getDataCenterId()); + List serviceResponses = new ArrayList(); + if (serviceCapabilitiesMap != null) { + for (Service service : serviceCapabilitiesMap.keySet()) { + ServiceResponse serviceResponse = new ServiceResponse(); + serviceResponse.setName(service.getName()); + + //set list of capabilities for the service + List capabilityResponses = new ArrayList(); + Map serviceCapabilities = serviceCapabilitiesMap.get(service); + if (serviceCapabilities != null) { + for (Capability capability : serviceCapabilities.keySet()) { + CapabilityResponse capabilityResponse = new CapabilityResponse(); + String capabilityValue = serviceCapabilities.get(capability); + capabilityResponse.setName(capability.getName()); + capabilityResponse.setValue(capabilityValue); + capabilityResponse.setObjectName("capability"); + capabilityResponses.add(capabilityResponse); + } + serviceResponse.setCapabilities(capabilityResponses); + } + + serviceResponse.setObjectName("service"); + serviceResponses.add(serviceResponse); + } + } + response.setServices(serviceResponses); + Account account = ApiDBUtils.findAccountById(network.getAccountId()); if (account != null) { response.setAccountName(account.getAccountName()); diff --git a/server/src/com/cloud/dc/DataCenterVO.java b/server/src/com/cloud/dc/DataCenterVO.java index e31cd079301..8ef823c5c23 100644 --- a/server/src/com/cloud/dc/DataCenterVO.java +++ b/server/src/com/cloud/dc/DataCenterVO.java @@ -28,7 +28,7 @@ import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.TableGenerator; -import com.cloud.network.service.Providers; +import com.cloud.network.Network.Provider; @Entity @Table(name="data_center") @@ -77,13 +77,13 @@ public class DataCenterVO implements DataCenter { NetworkType networkType; @Column(name="dns_provider") - private String dnsProvider = "VirtualRouter"; + private String dnsProvider = Provider.VirtualRouter.getName(); @Column(name="dhcp_provider") - private String dhcpProvider = "VirtualRouter"; + private String dhcpProvider = Provider.VirtualRouter.getName(); @Column(name="gateway_provider") - private String gatewayProvider = "VirtualRouter"; + private String gatewayProvider = Provider.VirtualRouter.getName(); @Column(name="vpn_provider") private String vpnProvider; @@ -163,13 +163,13 @@ public class DataCenterVO implements DataCenter { this.domain = domain; this.domainId = domainId; this.networkType = zoneType; - loadBalancerProvider = Providers.VirtualRouter; - firewallProvider = Providers.VirtualRouter; - dhcpProvider = Providers.VirtualRouter; - dnsProvider = Providers.VirtualRouter; - gatewayProvider = Providers.VirtualRouter; - vpnProvider = Providers.VirtualRouter; - userDataProvider = Providers.VirtualRouter; + loadBalancerProvider = Provider.VirtualRouter.getName(); + firewallProvider = Provider.VirtualRouter.getName(); + dhcpProvider = Provider.VirtualRouter.getName(); + dnsProvider = Provider.VirtualRouter.getName(); + gatewayProvider = Provider.VirtualRouter.getName(); + vpnProvider = Provider.VirtualRouter.getName(); + userDataProvider = Provider.VirtualRouter.getName(); } @Override diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 6a302bdb42d..884288bdca9 100644 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -18,6 +18,7 @@ package com.cloud.network; import java.util.List; +import java.util.Map; import com.cloud.dc.Vlan.VlanType; import com.cloud.deploy.DeployDestination; @@ -26,6 +27,8 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientAddressCapacityException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Service; import com.cloud.network.addr.PublicIp; import com.cloud.network.rules.FirewallRule; import com.cloud.offerings.NetworkOfferingVO; @@ -123,4 +126,6 @@ public interface NetworkManager extends NetworkService { String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException; boolean applyRules(List rules, boolean continueOnError) throws ResourceUnavailableException; + + Map> getZoneCapabilities(long zoneId); } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index fdec1d7c600..1e9f9b637a9 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.concurrent.Executors; @@ -87,6 +88,8 @@ import com.cloud.exception.OperationTimedoutException; import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Service; import com.cloud.network.Networks.AddressFormat; import com.cloud.network.Networks.Availability; import com.cloud.network.Networks.BroadcastDomainType; @@ -1781,7 +1784,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag throw new CloudRuntimeException("Failed to create a vlan"); } } - txn.commit(); + txn.commit(); + return networks.get(0); } catch (Exception ex) { s_logger.warn("Unexpected exception while creating network ", ex); @@ -1878,7 +1882,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } sc.addAnd("accountId", SearchCriteria.Op.SC, ssc); - return _networksDao.search(sc, searchFilter); + List networks = _networksDao.search(sc, searchFilter); + + return networks; } @Override @DB @@ -2131,4 +2137,43 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag public int getActiveNicsInNetwork(long networkId) { return _networksDao.getActiveNicsIn(networkId); } + + @Override + public Map> getZoneCapabilities(long zoneId) { + DataCenterVO dc = _dcDao.findById(zoneId); + if (dc == null) { + throw new InvalidParameterValueException("Zone id=" + dc.getId() + " doesn't exist in the system."); + } + + //Get all service providers from the datacenter + Map providers = new HashMap(); + providers.put(Service.Firewall, dc.getFirewallProvider()); + providers.put(Service.Lb, dc.getLoadBalancerProvider()); + providers.put(Service.Vpn, dc.getVpnProvider()); + providers.put(Service.Dns, dc.getDnsProvider()); + providers.put(Service.Gateway, dc.getGatewayProvider()); + providers.put(Service.UserData, dc.getUserDataProvider()); + providers.put(Service.Dhcp, dc.getDhcpProvider()); + + Map> networkCapabilities = new HashMap>(); + + for (NetworkElement element : _networkElements) { + if (providers.isEmpty()) { + break; + } + Map> elementCapabilities = element.getCapabilities(); + if (elementCapabilities != null) { + Iterator it = providers.keySet().iterator(); + while (it.hasNext()) { + Service service = it.next(); + if (providers.get(service).equals(element.getProvider().getName())) { + networkCapabilities.put(service, elementCapabilities.get(service)); + it.remove(); + } + } + } + } + return networkCapabilities; + } + } diff --git a/server/src/com/cloud/network/NetworkVO.java b/server/src/com/cloud/network/NetworkVO.java index 8dcbd0d39cd..e62655ceca8 100644 --- a/server/src/com/cloud/network/NetworkVO.java +++ b/server/src/com/cloud/network/NetworkVO.java @@ -130,7 +130,7 @@ public class NetworkVO implements Network { Date created; @Column(name="reservation_id") - String reservationId; + String reservationId; public NetworkVO() { } diff --git a/server/src/com/cloud/network/element/DhcpElement.java b/server/src/com/cloud/network/element/DhcpElement.java index 6b8bc98fc88..30f5805a663 100644 --- a/server/src/com/cloud/network/element/DhcpElement.java +++ b/server/src/com/cloud/network/element/DhcpElement.java @@ -17,7 +17,9 @@ */ package com.cloud.network.element; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.ejb.Local; @@ -29,12 +31,14 @@ import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.Network; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; import com.cloud.network.PublicIpAddress; import com.cloud.network.dao.NetworkDao; import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.rules.FirewallRule; -import com.cloud.network.service.Providers; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.uservm.UserVm; @@ -51,9 +55,11 @@ import com.cloud.vm.dao.UserVmDao; @Local(value=NetworkElement.class) -public class DhcpElement extends AdapterBase implements NetworkElement { +public class DhcpElement extends AdapterBase implements NetworkElement{ private static final Logger s_logger = Logger.getLogger(DhcpElement.class); + private static final Map> capabilities = setCapabilities(); + @Inject NetworkDao _networkConfigDao; @Inject NetworkManager _networkMgr; @Inject VirtualNetworkApplianceManager _routerMgr; @@ -64,10 +70,10 @@ public class DhcpElement extends AdapterBase implements NetworkElement { private boolean canHandle(GuestIpType ipType, DeployDestination dest) { DataCenter dc = dest.getDataCenter(); String provider = dc.getGatewayProvider(); - if (!dc.getDhcpProvider().equals(Providers.VirtualRouter)) { + if (!dc.getDhcpProvider().equals(Provider.VirtualRouter.getName())) { return false; } - return ((ipType == GuestIpType.Virtual && !provider.equals(Providers.VirtualRouter)) || (ipType == GuestIpType.Direct || ipType == GuestIpType.DirectPodBased)); + return ((ipType == GuestIpType.Virtual && !provider.equals(Provider.VirtualRouter.getName())) || (ipType == GuestIpType.Direct || ipType == GuestIpType.DirectPodBased)); } @Override @@ -100,7 +106,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement { public boolean release(Network config, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) { return true; } - + @Override public boolean shutdown(Network config, ReservationContext context) throws ConcurrentOperationException { DomainRouterVO router = _routerDao.findByNetworkConfiguration(config.getId()); @@ -112,11 +118,33 @@ public class DhcpElement extends AdapterBase implements NetworkElement { @Override public boolean applyRules(Network config, List rules) throws ResourceUnavailableException { - return true; + return false; } @Override public boolean applyIps(Network network, List ipAddress) throws ResourceUnavailableException { - return true; + return false; + } + + + @Override + public Provider getProvider() { + return Provider.DhcpServer; + } + + @Override + public Map> getCapabilities() { + return capabilities; + } + + private static Map> setCapabilities() { + Map> capabilities = new HashMap>(); + + capabilities.put(Service.Dns, null); + capabilities.put(Service.UserData, null); + capabilities.put(Service.Dhcp, null); + capabilities.put(Service.Gateway, null); + + return capabilities; } } diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index 4b816b34b56..7c7819b2acc 100644 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -18,7 +18,9 @@ package com.cloud.network.element; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.ejb.Local; @@ -32,6 +34,9 @@ import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.LoadBalancerVO; import com.cloud.network.Network; +import com.cloud.network.Network.Capability; +import com.cloud.network.Network.Provider; +import com.cloud.network.Network.Service; import com.cloud.network.NetworkManager; import com.cloud.network.PublicIpAddress; import com.cloud.network.dao.LoadBalancerDao; @@ -42,7 +47,6 @@ import com.cloud.network.lb.LoadBalancingRulesManager; import com.cloud.network.router.VirtualNetworkApplianceManager; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule.Purpose; -import com.cloud.network.service.Providers; import com.cloud.offering.NetworkOffering; import com.cloud.offering.NetworkOffering.GuestIpType; import com.cloud.offerings.dao.NetworkOfferingDao; @@ -65,6 +69,8 @@ import com.cloud.vm.dao.UserVmDao; public class VirtualRouterElement extends AdapterBase implements NetworkElement { private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class); + private static final Map> capabilities = setCapabilities(); + @Inject NetworkDao _networkConfigDao; @Inject NetworkManager _networkMgr; @Inject LoadBalancingRulesManager _lbMgr; @@ -76,10 +82,9 @@ public class VirtualRouterElement extends AdapterBase implements NetworkElement @Inject DataCenterDao _dataCenterDao; @Inject LoadBalancerDao _lbDao; - private boolean canHandle(GuestIpType ipType, DataCenter dc) { String provider = dc.getGatewayProvider(); - return (ipType == GuestIpType.Virtual && provider.equals(Providers.VirtualRouter)); + return (ipType == GuestIpType.Virtual && provider.equals(Provider.VirtualRouter.getName())); } @Override @@ -174,5 +179,49 @@ public class VirtualRouterElement extends AdapterBase implements NetworkElement return false; } } + + + @Override + public Provider getProvider() { + return Provider.VirtualRouter; + } + + @Override + public Map> getCapabilities() { + return capabilities; + } + + private static Map> setCapabilities() { + Map> capabilities = new HashMap>(); + + //Set capabilities for LB service + Map lbCapabilities = new HashMap(); + lbCapabilities.put(Capability.SupportedLBAlgorithms, "roundrobin,leastconn,sourceip"); + lbCapabilities.put(Capability.SupportedProtocols, "tcp, udp"); + + capabilities.put(Service.Lb, lbCapabilities); + + //Set capabilities for Firewall service + Map firewallCapabilities = new HashMap(); + firewallCapabilities.put(Capability.PortForwarding, "true"); + firewallCapabilities.put(Capability.StaticNat, "true"); + firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp"); + firewallCapabilities.put(Capability.MultipleIps, "true"); + firewallCapabilities.put(Capability.SupportedSourceNatTypes, "per account"); + + capabilities.put(Service.Firewall, firewallCapabilities); + + //Set capabilities for vpn + Map vpnCapabilities = new HashMap(); + vpnCapabilities.put(Capability.SupportedVpnTypes, "pptp,l2tp,ipsec"); + + capabilities.put(Service.Vpn, vpnCapabilities); + capabilities.put(Service.Dns, null); + capabilities.put(Service.UserData, null); + capabilities.put(Service.Dhcp, null); + capabilities.put(Service.Gateway, null); + + return capabilities; + } } From 882fe2e213415f9ae47a715a2bf2e87907996792 Mon Sep 17 00:00:00 2001 From: edison Date: Wed, 22 Dec 2010 11:04:22 -0800 Subject: [PATCH 10/23] fix vmware template url --- setup/db/templates.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/db/templates.sql b/setup/db/templates.sql index fc6c439cb36..85c30039da6 100644 --- a/setup/db/templates.sql +++ b/setup/db/templates.sql @@ -13,7 +13,7 @@ INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, created, type, VALUES (7, 'centos53-x64', 'centos53-x64', 1, now(), 'builtin', 0, 64, 1, 'http://download.cloud.com/releases/2.2.0/CentOS5.3-x86_64.ova', 'f6f881b7f2292948d8494db837fe0f47', 0, 'centos53-x64', 'OVA', 12, 1, 1, 'VMware'); INSERT INTO `cloud`.`vm_template` (id, unique_name, name, public, created, type, hvm, bits, account_id, url, checksum, enable_password, display_text, format, guest_os_id, featured, cross_zones, hypervisor_type) - VALUES (8, 'routing-8', 'SystemVM Template (VMWare)', 0, now(), 'system', 0, 32, 1, 'http://download.cloud.com/releases/2.2.0/systemvm.vmdk.bz2', '7ebe04f68583f30064d187069faf7b0f', 0, 'SystemVM Template VMWare', 'OVA', 15, 0, 1, 'VMware'); + VALUES (8, 'routing-8', 'SystemVM Template (VMWare)', 0, now(), 'system', 0, 32, 1, 'http://download.cloud.com/releases/2.2.0/systemvm.ova', 'ee3dc55e94e23a0490310bb78cf8cc76', 0, 'SystemVM Template VMWare', 'OVA', 15, 0, 1, 'VMware'); INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (1, 'CentOS'); INSERT INTO `cloud`.`guest_os_category` (id, name) VALUES (2, 'Debian'); From 572f4bb44f250d8b1e488ffeff5ba85490c81c29 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Wed, 22 Dec 2010 11:19:00 -0800 Subject: [PATCH 11/23] new Advanced Search - remove watermark when a field with matermark (e.g. "By Account", "By Startdate", "By Enddate") is mouse-clicked. --- ui/scripts/cloud.core.init.js | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/ui/scripts/cloud.core.init.js b/ui/scripts/cloud.core.init.js index 87bfff45806..b8c873c1f9a 100644 --- a/ui/scripts/cloud.core.init.js +++ b/ui/scripts/cloud.core.init.js @@ -278,24 +278,11 @@ $(document).ready(function() { $advancedSearchPopup.unbind("click").bind("click", function(event) { var $target = $(event.target); - var targetId = $target.attr("id"); - /* - if(targetId == "advanced_search_close") { - $(this).hide(); - return false; - } - else if(targetId == "adv_search_button") { - var params = $("#middle_menu_pagination").data("params"); - if(params == null) - return; - lastSearchType = "advanced_search"; - //$("#basic_search").find("#search_input").val(""); - listMidMenuItems2(params.commandString, params.getSearchParamsFn, params.jsonResponse1, params.jsonResponse2, params.toMidmenuFn, params.toRightPanelFn, params.getMidmenuIdFn, params.isMultipleSelectionInMidMenu, 1); - $("#advanced_search_icon").removeClass("up"); - $(this).hide(); - return false; - } - */ + var targetId = $target.attr("id"); + if($target.hasClass("textwatermark")) { + $target.val(""); + $target.removeClass("textwatermark"); + } return true; }); From 34db735ffa765150741fea94c5b385c5ef2fa077 Mon Sep 17 00:00:00 2001 From: will Date: Wed, 22 Dec 2010 11:25:10 -0800 Subject: [PATCH 12/23] Hiding Security Groups for beta2 for now. --- ui/index.jsp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ui/index.jsp b/ui/index.jsp index ddd949d87ea..9180d44bdc0 100644 --- a/ui/index.jsp +++ b/ui/index.jsp @@ -374,7 +374,8 @@ - + +
From a3ad3e041a0164bc20f495c3e4ecc758cfd2cf64 Mon Sep 17 00:00:00 2001 From: NIKITA Date: Wed, 22 Dec 2010 11:30:34 -0800 Subject: [PATCH 13/23] Color changed for Grid Actions dropdown --- ui/css/main.css | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui/css/main.css b/ui/css/main.css index 62298f2301c..d087d4e97f6 100644 --- a/ui/css/main.css +++ b/ui/css/main.css @@ -3494,8 +3494,9 @@ a:hover.search_button { height:auto; float:left; position:absolute; - background:#414141 repeat top left; - border:1px solid #CCC; + background:#444444 repeat top left; + border-bottom:1px solid #666; + border-left:1px solid #666; top:17px; right:0; margin:0; @@ -3517,7 +3518,7 @@ a:hover.search_button { height:auto; float:left; text-align:left; - background:#414141 repeat-x top left; + background:#444444 repeat-x top left; color:#CCC; font-size:11px; font-weight:normal; From 461563625b94f810c151b3f8b458170ad2376f04 Mon Sep 17 00:00:00 2001 From: Jessica Wang Date: Wed, 22 Dec 2010 11:31:36 -0800 Subject: [PATCH 14/23] new advanced search - slide down/up (500 milliseconds) when showing/hiding advanced search. --- ui/scripts/cloud.core.init.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ui/scripts/cloud.core.init.js b/ui/scripts/cloud.core.init.js index b8c873c1f9a..5f66583baf4 100644 --- a/ui/scripts/cloud.core.init.js +++ b/ui/scripts/cloud.core.init.js @@ -263,15 +263,15 @@ $(document).ready(function() { //advanced search $("#advanced_search_icon").unbind("click").bind("click", function(event) { - if($(this).hasClass("up")) { - $(this).removeClass("up"); - $("#advanced_search_container").find("#advanced_search_popup").hide(); + if($(this).hasClass("up")) { //clicking up-arrow + $("#advanced_search_container").find("#advanced_search_popup").slideUp("500"); + $(this).removeClass("up"); //change arrow from up to down } - else { - $(this).addClass("up"); + else { //clicking down-arrow + $(this).addClass("up"); //change arrow from down to up if($("#advanced_search_container").find("#advanced_search_popup").length > 0) { - $("#advanced_search_container").find("#advanced_search_popup").show(); + $("#advanced_search_container").find("#advanced_search_popup").slideDown("500"); } else { var $advancedSearchPopup = $("#advanced_search_popup"); @@ -391,7 +391,7 @@ $(document).ready(function() { $advancedSearchPopup.find("#adv_search_startdate, #adv_search_enddate").datepicker({dateFormat: 'yy-mm-dd'}); - $("#advanced_search_container").empty().append($advancedSearchPopup.show()); + $("#advanced_search_container").empty().append($advancedSearchPopup.slideDown("500")); } } From 04f39a7da724b65ade0a3ae36ce5aec8228b0dae Mon Sep 17 00:00:00 2001 From: NIKITA Date: Wed, 22 Dec 2010 11:36:52 -0800 Subject: [PATCH 15/23] Revised Advance Search UI for Network --- ui/jsp/network.jsp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ui/jsp/network.jsp b/ui/jsp/network.jsp index 494921f77f5..fbd63801b0e 100644 --- a/ui/jsp/network.jsp +++ b/ui/jsp/network.jsp @@ -46,7 +46,7 @@
Title
-