You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ke...@apache.org on 2013/02/01 20:38:11 UTC
[38/50] [abbrv] Merging events framework branch into master. This
commit will bring following changes
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/alert/AlertManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java
index a4c0fac..1a93f97 100755
--- a/server/src/com/cloud/alert/AlertManagerImpl.java
+++ b/server/src/com/cloud/alert/AlertManagerImpl.java
@@ -59,6 +59,7 @@ import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.DataCenterIpAddressDao;
import com.cloud.dc.dao.HostPodDao;
+import com.cloud.event.AlertGenerator;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
@@ -260,6 +261,10 @@ public class AlertManagerImpl implements AlertManager {
@Override
public void sendAlert(short alertType, long dataCenterId, Long podId, String subject, String body) {
+
+ // publish alert
+ AlertGenerator.publishAlertOnEventBus(getAlertType(alertType), dataCenterId, podId, subject, body);
+
// TODO: queue up these messages and send them as one set of issues once a certain number of issues is reached? If that's the case,
// shouldn't we have a type/severity as part of the API so that severe errors get sent right away?
try {
@@ -271,6 +276,65 @@ public class AlertManagerImpl implements AlertManager {
}
}
+ private String getAlertType(short alertType) {
+ if (alertType == ALERT_TYPE_MEMORY) {
+ return "ALERT.MEMORY";
+ } else if (alertType == ALERT_TYPE_CPU) {
+ return "ALERT.MEMORY";
+ } else if (alertType == ALERT_TYPE_STORAGE) {
+ return "ALERT.STORAGE";
+ } else if (alertType == ALERT_TYPE_STORAGE_ALLOCATED) {
+ return "ALERT.STORAGE.ALLOCATED";
+ } else if (alertType == ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP) {
+ return "ALERT.NETWORK.PUBLICIP";
+ } else if (alertType == ALERT_TYPE_PRIVATE_IP) {
+ return "ALERT.NETWORK.PRIVATEIP";
+ } else if (alertType == ALERT_TYPE_SECONDARY_STORAGE) {
+ return "ALERT.STORAGE.SECONDARY";
+ } else if (alertType == ALERT_TYPE_HOST) {
+ return "ALERT.COMPUTE.HOST";
+ } else if (alertType == ALERT_TYPE_USERVM) {
+ return "ALERT.USERVM";
+ } else if (alertType == ALERT_TYPE_DOMAIN_ROUTER) {
+ return "ALERT.SERVICE.DOMAINROUTER";
+ } else if (alertType == ALERT_TYPE_CONSOLE_PROXY) {
+ return "ALERT.SERVICE.CONSOLEPROXY";
+ } else if (alertType == ALERT_TYPE_ROUTING) {
+ return "ALERT.NETWORK.ROUTING";
+ } else if (alertType == ALERT_TYPE_STORAGE_MISC) {
+ return "ALERT.STORAGE.MISC";
+ } else if (alertType == ALERT_TYPE_USAGE_SERVER) {
+ return "ALERT.USAGE";
+ } else if (alertType == ALERT_TYPE_MANAGMENT_NODE) {
+ return "ALERT.MANAGEMENT";
+ } else if (alertType == ALERT_TYPE_DOMAIN_ROUTER_MIGRATE) {
+ return "ALERT.NETWORK.DOMAINROUTERMIGRATE";
+ } else if (alertType == ALERT_TYPE_CONSOLE_PROXY_MIGRATE) {
+ return "ALERT.SERVICE.CONSOLEPROXYMIGRATE";
+ } else if (alertType == ALERT_TYPE_USERVM_MIGRATE) {
+ return "ALERT.USERVM.MIGRATE";
+ } else if (alertType == ALERT_TYPE_VLAN) {
+ return "ALERT.NETWORK.VLAN";
+ } else if (alertType == ALERT_TYPE_SSVM) {
+ return "ALERT.SERVICE.SSVM";
+ } else if (alertType == ALERT_TYPE_USAGE_SERVER_RESULT) {
+ return "ALERT.USAGE.RESULT";
+ } else if (alertType == ALERT_TYPE_STORAGE_DELETE) {
+ return "ALERT.STORAGE.DELETE";
+ } else if (alertType == ALERT_TYPE_UPDATE_RESOURCE_COUNT) {
+ return "ALERT.RESOURCE.COUNT";
+ } else if (alertType == ALERT_TYPE_USAGE_SANITY_RESULT) {
+ return "ALERT.USAGE.SANITY";
+ } else if (alertType == ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP) {
+ return "ALERT.NETWORK.DIRECTPUBLICIP";
+ } else if (alertType == ALERT_TYPE_LOCAL_STORAGE) {
+ return "ALERT.STORAGE.LOCAL";
+ } else if (alertType == ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED) {
+ return "ALERT.RESOURCE.EXCEED";
+ }
+ return "UNKNOWN";
+ }
+
@Override @DB
public void recalculateCapacity() {
// FIXME: the right way to do this is to register a listener (see RouterStatsListener, VMSyncListener)
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index 0b08b26..143e280 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -16,68 +16,8 @@
// under the License.
package com.cloud.api;
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.cloudstack.api.ApiConstants.HostDetails;
-import org.apache.cloudstack.api.ApiConstants.VMDetails;
-import org.apache.cloudstack.api.response.AccountResponse;
-import org.apache.cloudstack.api.response.AsyncJobResponse;
-import org.apache.cloudstack.api.response.DiskOfferingResponse;
-import org.apache.cloudstack.api.response.DomainRouterResponse;
-import org.apache.cloudstack.api.response.EventResponse;
-import org.apache.cloudstack.api.response.HostResponse;
-import org.apache.cloudstack.api.response.InstanceGroupResponse;
-import org.apache.cloudstack.api.response.ProjectAccountResponse;
-import org.apache.cloudstack.api.response.ProjectInvitationResponse;
-import org.apache.cloudstack.api.response.ProjectResponse;
-import org.apache.cloudstack.api.response.ResourceTagResponse;
-import org.apache.cloudstack.api.response.SecurityGroupResponse;
-import org.apache.cloudstack.api.response.ServiceOfferingResponse;
-import org.apache.cloudstack.api.response.StoragePoolResponse;
-import org.apache.cloudstack.api.response.UserResponse;
-import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.api.response.VolumeResponse;
-import org.apache.cloudstack.api.response.ZoneResponse;
-
-import com.cloud.api.query.dao.AccountJoinDao;
-import com.cloud.api.query.dao.AsyncJobJoinDao;
-import com.cloud.api.query.dao.DataCenterJoinDao;
-import com.cloud.api.query.dao.DiskOfferingJoinDao;
-import com.cloud.api.query.dao.DomainRouterJoinDao;
-import com.cloud.api.query.dao.HostJoinDao;
-import com.cloud.api.query.dao.InstanceGroupJoinDao;
-import com.cloud.api.query.dao.ProjectAccountJoinDao;
-import com.cloud.api.query.dao.ProjectInvitationJoinDao;
-import com.cloud.api.query.dao.ProjectJoinDao;
-import com.cloud.api.query.dao.ResourceTagJoinDao;
-import com.cloud.api.query.dao.SecurityGroupJoinDao;
-import com.cloud.api.query.dao.ServiceOfferingJoinDao;
-import com.cloud.api.query.dao.StoragePoolJoinDao;
-import com.cloud.api.query.dao.UserAccountJoinDao;
-import com.cloud.api.query.dao.UserVmJoinDao;
-import com.cloud.api.query.dao.VolumeJoinDao;
-import com.cloud.api.query.vo.AccountJoinVO;
-import com.cloud.api.query.vo.AsyncJobJoinVO;
-import com.cloud.api.query.vo.DataCenterJoinVO;
-import com.cloud.api.query.vo.DiskOfferingJoinVO;
-import com.cloud.api.query.vo.DomainRouterJoinVO;
-import com.cloud.api.query.vo.EventJoinVO;
-import com.cloud.api.query.vo.HostJoinVO;
-import com.cloud.api.query.vo.InstanceGroupJoinVO;
-import com.cloud.api.query.vo.ProjectAccountJoinVO;
-import com.cloud.api.query.vo.ProjectInvitationJoinVO;
-import com.cloud.api.query.vo.ProjectJoinVO;
-import com.cloud.api.query.vo.ResourceTagJoinVO;
-import com.cloud.api.query.vo.SecurityGroupJoinVO;
-import com.cloud.api.query.vo.ServiceOfferingJoinVO;
-import com.cloud.api.query.vo.StoragePoolJoinVO;
-import com.cloud.api.query.vo.UserAccountJoinVO;
-import com.cloud.api.query.vo.UserVmJoinVO;
-import com.cloud.api.query.vo.VolumeJoinVO;
+import com.cloud.api.query.dao.*;
+import com.cloud.api.query.vo.*;
import com.cloud.async.AsyncJob;
import com.cloud.async.AsyncJobManager;
import com.cloud.async.AsyncJobVO;
@@ -89,18 +29,8 @@ import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationService;
import com.cloud.configuration.Resource.ResourceType;
import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.AccountVlanMapVO;
-import com.cloud.dc.ClusterVO;
-import com.cloud.dc.DataCenter;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.HostPodVO;
-import com.cloud.dc.Vlan;
-import com.cloud.dc.VlanVO;
-import com.cloud.dc.dao.AccountVlanMapDao;
-import com.cloud.dc.dao.ClusterDao;
-import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.dc.dao.HostPodDao;
-import com.cloud.dc.dao.VlanDao;
+import com.cloud.dc.*;
+import com.cloud.dc.dao.*;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.Event;
@@ -112,65 +42,23 @@ import com.cloud.host.HostStats;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.network.IPAddressVO;
-import com.cloud.network.IpAddress;
-import com.cloud.network.LoadBalancerVO;
-import com.cloud.network.Network;
+import com.cloud.network.*;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
-import com.cloud.network.NetworkDomainVO;
-import com.cloud.network.NetworkManager;
-import com.cloud.network.NetworkModel;
-import com.cloud.network.NetworkProfile;
-import com.cloud.network.NetworkRuleConfigVO;
-import com.cloud.network.NetworkVO;
-import com.cloud.network.PhysicalNetworkServiceProvider;
-import com.cloud.network.PhysicalNetworkVO;
-import com.cloud.network.Site2SiteVpnGatewayVO;
-import com.cloud.network.Site2SiteCustomerGatewayVO;
import com.cloud.network.Networks.TrafficType;
-import com.cloud.network.as.AutoScalePolicy;
-import com.cloud.network.as.AutoScalePolicyConditionMapVO;
-import com.cloud.network.as.AutoScalePolicyVO;
-import com.cloud.network.as.AutoScaleVmGroupPolicyMapVO;
-import com.cloud.network.as.AutoScaleVmGroupVO;
-import com.cloud.network.as.AutoScaleVmProfileVO;
-import com.cloud.network.as.ConditionVO;
-import com.cloud.network.as.CounterVO;
-import com.cloud.network.as.dao.AutoScalePolicyConditionMapDao;
-import com.cloud.network.as.dao.AutoScalePolicyDao;
-import com.cloud.network.as.dao.AutoScaleVmGroupDao;
-import com.cloud.network.as.dao.AutoScaleVmGroupPolicyMapDao;
-import com.cloud.network.as.dao.AutoScaleVmProfileDao;
-import com.cloud.network.as.dao.ConditionDao;
-import com.cloud.network.as.dao.CounterDao;
-import com.cloud.network.dao.FirewallRulesCidrsDao;
-import com.cloud.network.dao.FirewallRulesDao;
-import com.cloud.network.dao.IPAddressDao;
-import com.cloud.network.dao.LoadBalancerDao;
-import com.cloud.network.dao.NetworkDao;
-import com.cloud.network.dao.PhysicalNetworkDao;
-import com.cloud.network.dao.NetworkDomainDao;
-import com.cloud.network.dao.NetworkRuleConfigDao;
-import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
-import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
-import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao;
-import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO;
-import com.cloud.network.dao.Site2SiteVpnGatewayDao;
-import com.cloud.network.dao.Site2SiteCustomerGatewayDao;
+import com.cloud.network.as.*;
+import com.cloud.network.as.dao.*;
+import com.cloud.network.dao.*;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.network.security.SecurityGroup;
import com.cloud.network.security.SecurityGroupManager;
import com.cloud.network.security.SecurityGroupVO;
import com.cloud.network.security.dao.SecurityGroupDao;
-import com.cloud.network.vpc.StaticRouteVO;
-import com.cloud.network.vpc.VpcGatewayVO;
-import com.cloud.network.vpc.VpcManager;
-import com.cloud.network.vpc.VpcOffering;
-import com.cloud.network.vpc.VpcVO;
+import com.cloud.network.vpc.*;
import com.cloud.network.vpc.dao.StaticRouteDao;
+import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.network.vpc.dao.VpcGatewayDao;
import com.cloud.network.vpc.dao.VpcOfferingDao;
import com.cloud.offering.DiskOffering;
@@ -183,57 +71,16 @@ import com.cloud.projects.ProjectAccount;
import com.cloud.projects.ProjectInvitation;
import com.cloud.projects.ProjectService;
import com.cloud.resource.ResourceManager;
-import com.cloud.server.Criteria;
-import com.cloud.server.ManagementServer;
-import com.cloud.server.ResourceTag;
+import com.cloud.server.*;
import com.cloud.server.ResourceTag.TaggedResourceType;
-import com.cloud.server.StatsCollector;
-import com.cloud.server.TaggedResourceService;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
-import com.cloud.storage.DiskOfferingVO;
-import com.cloud.storage.GuestOS;
-import com.cloud.storage.GuestOSCategoryVO;
-import com.cloud.storage.Snapshot;
-import com.cloud.storage.SnapshotVO;
+import com.cloud.storage.*;
import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.StorageManager;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.StoragePoolVO;
-import com.cloud.storage.StorageStats;
-import com.cloud.storage.UploadVO;
-import com.cloud.storage.VMTemplateHostVO;
-import com.cloud.storage.VMTemplateS3VO;
-import com.cloud.storage.VMTemplateSwiftVO;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.Volume;
import com.cloud.storage.Volume.Type;
-import com.cloud.storage.VolumeHostVO;
-import com.cloud.storage.VolumeVO;
-import com.cloud.storage.dao.DiskOfferingDao;
-import com.cloud.storage.dao.GuestOSCategoryDao;
-import com.cloud.storage.dao.GuestOSDao;
-import com.cloud.storage.dao.SnapshotDao;
-import com.cloud.storage.dao.SnapshotPolicyDao;
-import com.cloud.storage.dao.StoragePoolDao;
-import com.cloud.storage.dao.UploadDao;
-import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.dao.VMTemplateDetailsDao;
-import com.cloud.storage.dao.VMTemplateHostDao;
-import com.cloud.storage.dao.VMTemplateS3Dao;
-import com.cloud.storage.dao.VMTemplateSwiftDao;
-import com.cloud.storage.dao.VolumeDao;
-import com.cloud.storage.dao.VolumeHostDao;
+import com.cloud.storage.dao.*;
import com.cloud.storage.snapshot.SnapshotPolicy;
-import com.cloud.user.Account;
-import com.cloud.user.AccountDetailsDao;
-import com.cloud.user.AccountVO;
-import com.cloud.user.ResourceLimitService;
-import com.cloud.user.SSHKeyPairVO;
-import com.cloud.user.User;
-import com.cloud.user.UserAccount;
-import com.cloud.user.UserStatisticsVO;
-import com.cloud.user.UserVO;
+import com.cloud.user.*;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.SSHKeyPairDao;
import com.cloud.user.dao.UserDao;
@@ -242,23 +89,13 @@ import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.component.ComponentLocator;
-import com.cloud.vm.ConsoleProxyVO;
-import com.cloud.vm.DomainRouterVO;
-import com.cloud.vm.InstanceGroup;
-import com.cloud.vm.InstanceGroupVO;
-import com.cloud.vm.NicProfile;
-import com.cloud.vm.UserVmDetailVO;
-import com.cloud.vm.UserVmManager;
-import com.cloud.vm.UserVmVO;
-import com.cloud.vm.VMInstanceVO;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VmStats;
-import com.cloud.vm.dao.ConsoleProxyDao;
-import com.cloud.vm.dao.DomainRouterDao;
-import com.cloud.vm.dao.UserVmDao;
-import com.cloud.vm.dao.UserVmDetailsDao;
-import com.cloud.vm.dao.VMInstanceDao;
-import com.cloud.network.vpc.dao.VpcDao;
+import com.cloud.vm.*;
+import com.cloud.vm.dao.*;
+import org.apache.cloudstack.api.ApiConstants.HostDetails;
+import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.api.response.*;
+
+import java.util.*;
public class ApiDBUtils {
private static ManagementServer _ms;
@@ -699,7 +536,7 @@ public class ApiDBUtils {
public static Snapshot findSnapshotById(long snapshotId) {
SnapshotVO snapshot = _snapshotDao.findById(snapshotId);
- if (snapshot != null && snapshot.getRemoved() == null && snapshot.getStatus() == Snapshot.Status.BackedUp) {
+ if (snapshot != null && snapshot.getRemoved() == null && snapshot.getState() == Snapshot.State.BackedUp) {
return snapshot;
} else {
return null;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 641f25b..54639a8 100755
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -16,125 +16,9 @@
// under the License.
package com.cloud.api;
-import static java.util.Collections.emptyList;
-import static java.util.Collections.singletonList;
-
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import org.apache.cloudstack.api.BaseCmd;
-import org.apache.cloudstack.api.ResponseGenerator;
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.acl.ControlledEntity;
-import org.apache.cloudstack.acl.ControlledEntity.ACLType;
-import org.apache.cloudstack.api.ApiConstants.HostDetails;
-import org.apache.cloudstack.api.ApiConstants.VMDetails;
-import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
-import org.apache.cloudstack.api.response.AccountResponse;
-
import com.cloud.api.query.ViewResponseHelper;
-import com.cloud.api.query.vo.AccountJoinVO;
-import com.cloud.api.query.vo.AsyncJobJoinVO;
-import com.cloud.api.query.vo.ControlledViewEntity;
-import com.cloud.api.query.vo.DataCenterJoinVO;
-import com.cloud.api.query.vo.DiskOfferingJoinVO;
-import com.cloud.api.query.vo.DomainRouterJoinVO;
-import com.cloud.api.query.vo.EventJoinVO;
-import com.cloud.api.query.vo.HostJoinVO;
-import com.cloud.api.query.vo.InstanceGroupJoinVO;
-import com.cloud.api.query.vo.ProjectAccountJoinVO;
-import com.cloud.api.query.vo.ProjectInvitationJoinVO;
-import com.cloud.api.query.vo.ProjectJoinVO;
-import com.cloud.api.query.vo.ResourceTagJoinVO;
-import com.cloud.api.query.vo.SecurityGroupJoinVO;
-import com.cloud.api.query.vo.ServiceOfferingJoinVO;
-import com.cloud.api.query.vo.StoragePoolJoinVO;
-import com.cloud.api.query.vo.UserAccountJoinVO;
-import com.cloud.api.query.vo.UserVmJoinVO;
-import com.cloud.api.query.vo.VolumeJoinVO;
+import com.cloud.api.query.vo.*;
import com.cloud.api.response.ApiResponseSerializer;
-import org.apache.cloudstack.api.response.AsyncJobResponse;
-import org.apache.cloudstack.api.response.AutoScalePolicyResponse;
-import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
-import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
-import org.apache.cloudstack.api.response.CapabilityResponse;
-import org.apache.cloudstack.api.response.CapacityResponse;
-import org.apache.cloudstack.api.response.ClusterResponse;
-import org.apache.cloudstack.api.response.ConditionResponse;
-import org.apache.cloudstack.api.response.ConfigurationResponse;
-import org.apache.cloudstack.api.response.ControlledEntityResponse;
-import org.apache.cloudstack.api.response.CounterResponse;
-import org.apache.cloudstack.api.response.CreateCmdResponse;
-import org.apache.cloudstack.api.response.DiskOfferingResponse;
-import org.apache.cloudstack.api.response.DomainResponse;
-import org.apache.cloudstack.api.response.DomainRouterResponse;
-import org.apache.cloudstack.api.response.EventResponse;
-import org.apache.cloudstack.api.response.ExtractResponse;
-import org.apache.cloudstack.api.response.FirewallResponse;
-import org.apache.cloudstack.api.response.FirewallRuleResponse;
-import org.apache.cloudstack.api.response.GuestOSResponse;
-import org.apache.cloudstack.api.response.HostResponse;
-import org.apache.cloudstack.api.response.HypervisorCapabilitiesResponse;
-import org.apache.cloudstack.api.response.ControlledViewEntityResponse;
-import org.apache.cloudstack.api.response.IPAddressResponse;
-import org.apache.cloudstack.api.response.InstanceGroupResponse;
-import org.apache.cloudstack.api.response.IpForwardingRuleResponse;
-import org.apache.cloudstack.api.response.LBStickinessPolicyResponse;
-import org.apache.cloudstack.api.response.LBStickinessResponse;
-import org.apache.cloudstack.api.response.LDAPConfigResponse;
-import org.apache.cloudstack.api.response.LoadBalancerResponse;
-import org.apache.cloudstack.api.response.NetworkACLResponse;
-import org.apache.cloudstack.api.response.NetworkOfferingResponse;
-import org.apache.cloudstack.api.response.NetworkResponse;
-import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
-import org.apache.cloudstack.api.response.PodResponse;
-import org.apache.cloudstack.api.response.PrivateGatewayResponse;
-import org.apache.cloudstack.api.response.ProjectAccountResponse;
-import org.apache.cloudstack.api.response.ProjectInvitationResponse;
-import org.apache.cloudstack.api.response.ProjectResponse;
-import org.apache.cloudstack.api.response.ProviderResponse;
-import org.apache.cloudstack.api.response.RemoteAccessVpnResponse;
-import org.apache.cloudstack.api.response.ResourceCountResponse;
-import org.apache.cloudstack.api.response.ResourceLimitResponse;
-import org.apache.cloudstack.api.response.ResourceTagResponse;
-import org.apache.cloudstack.api.response.SecurityGroupResponse;
-import org.apache.cloudstack.api.response.SecurityGroupRuleResponse;
-import org.apache.cloudstack.api.response.ServiceOfferingResponse;
-import org.apache.cloudstack.api.response.ServiceResponse;
-import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse;
-import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse;
-import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse;
-import org.apache.cloudstack.api.response.SnapshotPolicyResponse;
-import org.apache.cloudstack.api.response.SnapshotResponse;
-import org.apache.cloudstack.api.response.SnapshotScheduleResponse;
-import org.apache.cloudstack.api.response.StaticRouteResponse;
-import org.apache.cloudstack.api.response.StorageNetworkIpRangeResponse;
-import org.apache.cloudstack.api.response.StoragePoolResponse;
-import org.apache.cloudstack.api.response.SwiftResponse;
-import org.apache.cloudstack.api.response.SystemVmInstanceResponse;
-import org.apache.cloudstack.api.response.SystemVmResponse;
-import org.apache.cloudstack.api.response.TemplatePermissionsResponse;
-import org.apache.cloudstack.api.response.TemplateResponse;
-import org.apache.cloudstack.api.response.TrafficTypeResponse;
-import org.apache.cloudstack.api.response.UserResponse;
-import org.apache.cloudstack.api.response.UserVmResponse;
-import org.apache.cloudstack.api.response.VirtualRouterProviderResponse;
-import org.apache.cloudstack.api.response.VlanIpRangeResponse;
-import org.apache.cloudstack.api.response.VolumeResponse;
-import org.apache.cloudstack.api.response.VpcOfferingResponse;
-import org.apache.cloudstack.api.response.VpcResponse;
-import org.apache.cloudstack.api.response.VpnUsersResponse;
-import org.apache.cloudstack.api.response.ZoneResponse;
-
-import org.apache.cloudstack.api.response.S3Response;
import com.cloud.async.AsyncJob;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityVO;
@@ -143,53 +27,21 @@ import com.cloud.configuration.Configuration;
import com.cloud.configuration.Resource.ResourceOwnerType;
import com.cloud.configuration.ResourceCount;
import com.cloud.configuration.ResourceLimit;
-import com.cloud.dc.ClusterVO;
-import com.cloud.dc.DataCenter;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.HostPodVO;
-import com.cloud.dc.Pod;
-import com.cloud.dc.StorageNetworkIpRange;
-import com.cloud.dc.Vlan;
+import com.cloud.dc.*;
import com.cloud.dc.Vlan.VlanType;
-import com.cloud.dc.VlanVO;
import com.cloud.domain.Domain;
import com.cloud.event.Event;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.hypervisor.HypervisorCapabilities;
-import com.cloud.network.IPAddressVO;
-import com.cloud.network.IpAddress;
-import com.cloud.network.Network;
+import com.cloud.network.*;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
-import com.cloud.network.NetworkProfile;
-import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.TrafficType;
-import com.cloud.network.PhysicalNetwork;
-import com.cloud.network.PhysicalNetworkServiceProvider;
-import com.cloud.network.PhysicalNetworkTrafficType;
-import com.cloud.network.PhysicalNetworkVO;
-import com.cloud.network.RemoteAccessVpn;
-import com.cloud.network.Site2SiteCustomerGateway;
-import com.cloud.network.Site2SiteVpnConnection;
-import com.cloud.network.Site2SiteVpnGateway;
-import com.cloud.network.VirtualRouterProvider;
-import com.cloud.network.VpnUser;
-import com.cloud.network.as.AutoScalePolicy;
-import com.cloud.network.as.AutoScaleVmGroup;
-import com.cloud.network.as.AutoScaleVmProfile;
-import com.cloud.network.as.AutoScaleVmProfileVO;
-import com.cloud.network.as.Condition;
-import com.cloud.network.as.ConditionVO;
-import com.cloud.network.as.Counter;
+import com.cloud.network.as.*;
import com.cloud.network.router.VirtualRouter;
-import com.cloud.network.rules.FirewallRule;
-import com.cloud.network.rules.FirewallRuleVO;
-import com.cloud.network.rules.LoadBalancer;
-import com.cloud.network.rules.PortForwardingRule;
-import com.cloud.network.rules.StaticNatRule;
-import com.cloud.network.rules.StickinessPolicy;
+import com.cloud.network.rules.*;
import com.cloud.network.security.SecurityGroup;
import com.cloud.network.security.SecurityRule;
import com.cloud.network.security.SecurityRule.SecurityRuleType;
@@ -207,25 +59,11 @@ import com.cloud.projects.ProjectInvitation;
import com.cloud.server.Criteria;
import com.cloud.server.ResourceTag;
import com.cloud.server.ResourceTag.TaggedResourceType;
-import com.cloud.storage.GuestOS;
-import com.cloud.storage.GuestOSCategoryVO;
-import com.cloud.storage.S3;
-import com.cloud.storage.Snapshot;
+import com.cloud.storage.*;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.Storage.TemplateType;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.StoragePoolVO;
-import com.cloud.storage.StorageStats;
-import com.cloud.storage.Swift;
-import com.cloud.storage.UploadVO;
-import com.cloud.storage.VMTemplateHostVO;
-import com.cloud.storage.VMTemplateS3VO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-import com.cloud.storage.VMTemplateSwiftVO;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.Volume;
-import com.cloud.storage.VolumeVO;
import com.cloud.storage.snapshot.SnapshotPolicy;
import com.cloud.storage.snapshot.SnapshotSchedule;
import com.cloud.template.VirtualMachineTemplate;
@@ -242,6 +80,21 @@ import com.cloud.vm.InstanceGroup;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Type;
+import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.acl.ControlledEntity.ACLType;
+import org.apache.cloudstack.api.ApiConstants.HostDetails;
+import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.ResponseGenerator;
+import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
+import org.apache.cloudstack.api.response.*;
+import org.apache.log4j.Logger;
+
+import java.text.DecimalFormat;
+import java.util.*;
+
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
public class ApiResponseHelper implements ResponseGenerator {
@@ -378,7 +231,7 @@ public class ApiResponseHelper implements ResponseGenerator {
snapshotResponse.setCreated(snapshot.getCreated());
snapshotResponse.setName(snapshot.getName());
snapshotResponse.setIntervalType(ApiDBUtils.getSnapshotIntervalTypes(snapshot.getId()));
- snapshotResponse.setState(snapshot.getStatus());
+ snapshotResponse.setState(snapshot.getState());
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(TaggedResourceType.Snapshot, snapshot.getId());
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index ed27200..b4612ae 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -50,10 +50,10 @@ import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import com.cloud.event.ActionEventUtils;
import com.cloud.utils.ReflectUtil;
import org.apache.cloudstack.acl.APILimitChecker;
import org.apache.cloudstack.acl.APIChecker;
-import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
@@ -116,7 +116,6 @@ import com.cloud.configuration.ConfigurationVO;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
-import com.cloud.event.EventUtils;
import com.cloud.exception.AccountLimitException;
import com.cloud.exception.CloudAuthenticationException;
import com.cloud.exception.InsufficientCapacityException;
@@ -467,7 +466,7 @@ public class ApiServer implements HttpRequestHandler {
asyncCmd.setStartEventId(startEventId);
// save the scheduled event
- Long eventId = EventUtils.saveScheduledEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId,
+ Long eventId = ActionEventUtils.onScheduledActionEvent((callerUserId == null) ? User.UID_SYSTEM : callerUserId,
asyncCmd.getEntityOwnerId(), asyncCmd.getEventType(), asyncCmd.getEventDescription(),
startEventId);
if (startEventId == 0) {
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java b/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
index 25298a9..74200e2 100755
--- a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
+++ b/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
@@ -16,20 +16,10 @@
// under the License.
package com.cloud.baremetal;
-import java.util.Date;
-import java.util.List;
-
-import javax.ejb.Local;
-
-import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
-import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
-import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
-import org.apache.log4j.Logger;
-
import com.cloud.configuration.Resource.ResourceType;
import com.cloud.dc.DataCenterVO;
import com.cloud.event.EventTypes;
-import com.cloud.event.UsageEventVO;
+import com.cloud.event.UsageEventUtils;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
@@ -46,6 +36,14 @@ import com.cloud.user.Account;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
+import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
+import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
+import org.apache.log4j.Logger;
+
+import javax.ejb.Local;
+import java.util.Date;
+import java.util.List;
@Local(value=TemplateAdapter.class)
public class BareMetalTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter {
@@ -82,9 +80,9 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
private void templateCreateUsage(VMTemplateVO template, HostVO host) {
if (template.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
- UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_TEMPLATE_CREATE, template.getAccountId(), host.getDataCenterId(),
- template.getId(), template.getName(), null, template.getSourceTemplateId(), 0L);
- _usageEventDao.persist(usageEvent);
+ UsageEventUtils.publishUsageEvent(EventTypes.EVENT_TEMPLATE_CREATE, template.getAccountId(), host.getDataCenterId(),
+ template.getId(), template.getName(), null, template.getSourceTemplateId(), 0L,
+ template.getClass().getName(), template.getUuid());
}
}
@@ -172,8 +170,8 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
_tmpltZoneDao.remove(templateZone.getId());
}
- UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), pxeServer.getDataCenterId(), templateId, null);
- _usageEventDao.persist(usageEvent);
+ UsageEventUtils.publishUsageEvent(eventType, account.getId(), pxeServer.getDataCenterId(),
+ templateId, null, template.getClass().getName(), template.getUuid());
} finally {
if (lock != null) {
_tmpltHostDao.releaseFromLockTable(lock.getId());
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
index 57cfb39..6ff37ea 100755
--- a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
+++ b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
@@ -16,28 +16,11 @@
// under the License.
package com.cloud.baremetal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Executors;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.cloudstack.api.command.user.template.CreateTemplateCmd;
-import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
-import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
-import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
-import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
-import org.apache.log4j.Logger;
-
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
import com.cloud.agent.api.baremetal.IpmiBootorResetCommand;
import com.cloud.agent.manager.Commands;
-import org.apache.cloudstack.api.command.user.vm.StartVMCmd;
import com.cloud.baremetal.PxeServerManager.PxeServerType;
import com.cloud.configuration.Resource.ResourceType;
import com.cloud.configuration.dao.ConfigurationDao;
@@ -47,14 +30,8 @@ import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.domain.DomainVO;
import com.cloud.event.EventTypes;
-import com.cloud.event.UsageEventVO;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.PermissionDeniedException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.exception.StorageUnavailableException;
+import com.cloud.event.UsageEventUtils;
+import com.cloud.exception.*;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -71,11 +48,7 @@ import com.cloud.storage.Volume;
import com.cloud.template.TemplateAdapter;
import com.cloud.template.TemplateAdapter.TemplateAdapterType;
import com.cloud.template.TemplateProfile;
-import com.cloud.user.Account;
-import com.cloud.user.AccountVO;
-import com.cloud.user.SSHKeyPair;
-import com.cloud.user.User;
-import com.cloud.user.UserContext;
+import com.cloud.user.*;
import com.cloud.uservm.UserVm;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
@@ -88,19 +61,26 @@ import com.cloud.utils.db.DB;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.fsm.StateListener;
import com.cloud.utils.net.NetUtils;
-import com.cloud.vm.BareMetalVmService;
-import com.cloud.vm.NicProfile;
-import com.cloud.vm.NicVO;
-import com.cloud.vm.ReservationContext;
-import com.cloud.vm.UserVmManagerImpl;
-import com.cloud.vm.UserVmVO;
-import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.*;
import com.cloud.vm.VirtualMachine.Event;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachine.Type;
-import com.cloud.vm.VirtualMachineName;
-import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfile.Param;
+import org.apache.cloudstack.api.command.user.template.CreateTemplateCmd;
+import org.apache.cloudstack.api.command.user.vm.DeployVMCmd;
+import org.apache.cloudstack.api.command.user.vm.StartVMCmd;
+import org.apache.cloudstack.api.command.user.vm.UpgradeVMCmd;
+import org.apache.cloudstack.api.command.user.volume.AttachVolumeCmd;
+import org.apache.cloudstack.api.command.user.volume.DetachVolumeCmd;
+import org.apache.log4j.Logger;
+
+import javax.ejb.Local;
+import javax.naming.ConfigurationException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executors;
@Local(value={BareMetalVmManager.class, BareMetalVmService.class})
public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMetalVmManager, BareMetalVmService, Manager,
@@ -367,8 +347,9 @@ public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMet
s_logger.debug("Successfully allocated DB entry for " + vm);
}
UserContext.current().setEventDetails("Vm Id: " + vm.getId());
- UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE, accountId, cmd.getZoneId(), vm.getId(), vm.getHostName(), offering.getId(), template.getId(), HypervisorType.BareMetal.toString());
- _usageEventDao.persist(usageEvent);
+ UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, accountId, cmd.getZoneId(), vm.getId(),
+ vm.getHostName(), offering.getId(), template.getId(), HypervisorType.BareMetal.toString(),
+ VirtualMachine.class.getName(), vm.getUuid());
_resourceLimitMgr.incrementResourceCount(accountId, ResourceType.user_vm);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/configuration/DefaultInterceptorLibrary.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/DefaultInterceptorLibrary.java b/server/src/com/cloud/configuration/DefaultInterceptorLibrary.java
index ced2618..13a22db 100644
--- a/server/src/com/cloud/configuration/DefaultInterceptorLibrary.java
+++ b/server/src/com/cloud/configuration/DefaultInterceptorLibrary.java
@@ -16,18 +16,18 @@
// under the License.
package com.cloud.configuration;
-import java.util.List;
-
-import com.cloud.event.ActionEventCallback;
+import com.cloud.event.ActionEventUtils;
import com.cloud.utils.component.AnnotationInterceptor;
import com.cloud.utils.component.InterceptorLibrary;
import com.cloud.utils.db.DatabaseCallback;
+import java.util.List;
+
public class DefaultInterceptorLibrary implements InterceptorLibrary {
@Override
public void addInterceptors(List<AnnotationInterceptor<?>> interceptors) {
interceptors.add(new DatabaseCallback());
- interceptors.add(new ActionEventCallback());
+ interceptors.add(new ActionEventUtils.ActionEventCallback());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/event/ActionEventCallback.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/ActionEventCallback.java b/server/src/com/cloud/event/ActionEventCallback.java
deleted file mode 100644
index f941400..0000000
--- a/server/src/com/cloud/event/ActionEventCallback.java
+++ /dev/null
@@ -1,135 +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.event;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Method;
-
-import net.sf.cglib.proxy.Callback;
-import net.sf.cglib.proxy.MethodInterceptor;
-import net.sf.cglib.proxy.MethodProxy;
-
-import com.cloud.user.UserContext;
-import com.cloud.utils.component.AnnotationInterceptor;
-
-public class ActionEventCallback implements MethodInterceptor, AnnotationInterceptor<EventVO> {
-
- @Override
- public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
- EventVO event = interceptStart(method);
- boolean success = true;
- try {
- return methodProxy.invokeSuper(object, args);
- } catch (Exception e){
- success = false;
- interceptException(method, event);
- throw e;
- } finally {
- if(success){
- interceptComplete(method, event);
- }
- }
- }
-
- @Override
- public boolean needToIntercept(AnnotatedElement element) {
- if (!(element instanceof Method)) {
- return false;
-
- }
- Method method = (Method)element;
- ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
- if (actionEvent != null) {
- return true;
- }
-
- return false;
- }
-
- @Override
- public EventVO interceptStart(AnnotatedElement element) {
- EventVO event = null;
- Method method = (Method)element;
- ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
- if (actionEvent != null) {
- boolean async = actionEvent.async();
- if(async){
- UserContext ctx = UserContext.current();
- long userId = ctx.getCallerUserId();
- long accountId = ctx.getAccountId();
- long startEventId = ctx.getStartEventId();
- String eventDescription = actionEvent.eventDescription();
- if(ctx.getEventDetails() != null){
- eventDescription += ". "+ctx.getEventDetails();
- }
- EventUtils.saveStartedEvent(userId, accountId, actionEvent.eventType(), eventDescription, startEventId);
- }
- }
- return event;
- }
-
- @Override
- public void interceptComplete(AnnotatedElement element, EventVO event) {
- Method method = (Method)element;
- ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
- if (actionEvent != null) {
- UserContext ctx = UserContext.current();
- long userId = ctx.getCallerUserId();
- long accountId = ctx.getAccountId();
- long startEventId = ctx.getStartEventId();
- String eventDescription = actionEvent.eventDescription();
- if(ctx.getEventDetails() != null){
- eventDescription += ". "+ctx.getEventDetails();
- }
- if(actionEvent.create()){
- //This start event has to be used for subsequent events of this action
- startEventId = EventUtils.saveCreatedEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully created entity for "+eventDescription);
- ctx.setStartEventId(startEventId);
- } else {
- EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully completed "+eventDescription, startEventId);
- }
- }
- }
-
- @Override
- public void interceptException(AnnotatedElement element, EventVO event) {
- Method method = (Method)element;
- ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
- if (actionEvent != null) {
- UserContext ctx = UserContext.current();
- long userId = ctx.getCallerUserId();
- long accountId = ctx.getAccountId();
- long startEventId = ctx.getStartEventId();
- String eventDescription = actionEvent.eventDescription();
- if(ctx.getEventDetails() != null){
- eventDescription += ". "+ctx.getEventDetails();
- }
- if(actionEvent.create()){
- long eventId = EventUtils.saveCreatedEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while creating entity for "+eventDescription);
- ctx.setStartEventId(eventId);
- } else {
- EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while "+eventDescription, startEventId);
- }
- }
- }
-
- @Override
- public Callback getCallback() {
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/event/ActionEventUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/ActionEventUtils.java b/server/src/com/cloud/event/ActionEventUtils.java
new file mode 100755
index 0000000..744f46f
--- /dev/null
+++ b/server/src/com/cloud/event/ActionEventUtils.java
@@ -0,0 +1,288 @@
+// 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.event;
+
+import com.cloud.event.dao.EventDao;
+import com.cloud.server.ManagementServer;
+import com.cloud.user.Account;
+import com.cloud.user.AccountVO;
+import com.cloud.user.User;
+import com.cloud.user.UserContext;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.user.dao.UserDao;
+import com.cloud.utils.component.Adapters;
+import com.cloud.utils.component.AnnotationInterceptor;
+import com.cloud.utils.component.ComponentLocator;
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+import org.apache.cloudstack.framework.events.EventBus;
+import org.apache.cloudstack.framework.events.EventBusException;
+import org.apache.log4j.Logger;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ActionEventUtils {
+
+ private static EventDao _eventDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(EventDao.class);
+ private static AccountDao _accountDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(AccountDao.class);
+ protected static UserDao _userDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(UserDao.class);
+ private static final Logger s_logger = Logger.getLogger(ActionEventUtils.class);
+
+ // get the event bus provider if configured
+ protected static EventBus _eventBus = null;
+
+ static {
+ Adapters<EventBus> eventBusImpls = ComponentLocator.getLocator(ManagementServer.Name).getAdapters(EventBus.class);
+ if (eventBusImpls != null) {
+ Enumeration<EventBus> eventBusenum = eventBusImpls.enumeration();
+ if (eventBusenum != null && eventBusenum.hasMoreElements()) {
+ _eventBus = eventBusenum.nextElement(); // configure event bus if configured
+ }
+ }
+ }
+
+ public static Long onActionEvent(Long userId, Long accountId, Long domainId, String type, String description) {
+
+ publishOnEventBus(userId, accountId, EventCategory.ACTION_EVENT.getName(),
+ type, com.cloud.event.Event.State.Completed);
+
+ Event event = persistActionEvent(userId, accountId, domainId, null, type, Event.State.Completed,
+ description, null);
+
+ return event.getId();
+ }
+
+ /*
+ * Save event after scheduling an async job
+ */
+ public static Long onScheduledActionEvent(Long userId, Long accountId, String type, String description,
+ long startEventId) {
+
+ publishOnEventBus(userId, accountId, EventCategory.ACTION_EVENT.getName(), type,
+ com.cloud.event.Event.State.Scheduled);
+
+ Event event = persistActionEvent(userId, accountId, null, null, type, Event.State.Scheduled,
+ description, startEventId);
+
+ return event.getId();
+ }
+
+ /*
+ * Save event after starting execution of an async job
+ */
+ public static Long onStartedActionEvent(Long userId, Long accountId, String type, String description,
+ long startEventId) {
+
+ publishOnEventBus(userId, accountId, EventCategory.ACTION_EVENT.getName(), type,
+ com.cloud.event.Event.State.Started);
+
+ Event event = persistActionEvent(userId, accountId, null, null, type, Event.State.Started,
+ description, startEventId);
+ return event.getId();
+ }
+
+ public static Long onCompletedActionEvent(Long userId, Long accountId, String level, String type,
+ String description, long startEventId) {
+
+ publishOnEventBus(userId, accountId, EventCategory.ACTION_EVENT.getName(), type,
+ com.cloud.event.Event.State.Completed);
+
+ Event event = persistActionEvent(userId, accountId, null, level, type, Event.State.Completed,
+ description, startEventId);
+
+ return event.getId();
+ }
+
+ public static Long onCreatedActionEvent(Long userId, Long accountId, String level, String type, String description) {
+
+ publishOnEventBus(userId, accountId, EventCategory.ACTION_EVENT.getName(), type,
+ com.cloud.event.Event.State.Created);
+
+ Event event = persistActionEvent(userId, accountId, null, level, type, Event.State.Created, description, null);
+
+ return event.getId();
+ }
+
+ private static Event persistActionEvent(Long userId, Long accountId, Long domainId, String level, String type,
+ Event.State state, String description, Long startEventId) {
+ EventVO event = new EventVO();
+ event.setUserId(userId);
+ event.setAccountId(accountId);
+ event.setType(type);
+ event.setState(state);
+ event.setDescription(description);
+ if (domainId != null) {
+ event.setDomainId(domainId);
+ } else {
+ event.setDomainId(getDomainId(accountId));
+ }
+ if (level != null && !level.isEmpty()) {
+ event.setLevel(level);
+ }
+ if (startEventId != null) {
+ event.setStartId(startEventId);
+ }
+ event = _eventDao.persist(event);
+ return event;
+ }
+
+ private static void publishOnEventBus(long userId, long accountId, String eventCategory,
+ String eventType, Event.State state) {
+ if (_eventBus == null) {
+ return; // no provider is configured to provide events bus, so just return
+ }
+
+ org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(
+ ManagementServer.Name,
+ eventCategory,
+ eventType,
+ EventTypes.getEntityForEvent(eventType), null);
+
+ Map<String, String> eventDescription = new HashMap<String, String>();
+ Account account = _accountDao.findById(accountId);
+ User user = _userDao.findById(userId);
+ eventDescription.put("user", user.getUuid());
+ eventDescription.put("account", account.getUuid());
+ eventDescription.put("event", eventType);
+ eventDescription.put("status", state.toString());
+ event.setDescription(eventDescription);
+
+ try {
+ _eventBus.publish(event);
+ } catch (EventBusException e) {
+ s_logger.warn("Failed to publish action event on the the event bus.");
+ }
+ }
+
+ private static long getDomainId(long accountId){
+ AccountVO account = _accountDao.findByIdIncludingRemoved(accountId);
+ return account.getDomainId();
+ }
+
+ public static class ActionEventCallback implements MethodInterceptor, AnnotationInterceptor<EventVO> {
+
+ @Override
+ public Object intercept(Object object, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
+ EventVO event = interceptStart(method);
+ boolean success = true;
+ try {
+ return methodProxy.invokeSuper(object, args);
+ } catch (Exception e){
+ success = false;
+ interceptException(method, event);
+ throw e;
+ } finally {
+ if(success){
+ interceptComplete(method, event);
+ }
+ }
+ }
+
+ @Override
+ public boolean needToIntercept(AnnotatedElement element) {
+ if (!(element instanceof Method)) {
+ return false;
+
+ }
+ Method method = (Method)element;
+ ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
+ if (actionEvent != null) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public EventVO interceptStart(AnnotatedElement element) {
+ EventVO event = null;
+ Method method = (Method)element;
+ ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
+ if (actionEvent != null) {
+ boolean async = actionEvent.async();
+ if(async){
+ UserContext ctx = UserContext.current();
+ long userId = ctx.getCallerUserId();
+ long accountId = ctx.getAccountId();
+ long startEventId = ctx.getStartEventId();
+ String eventDescription = actionEvent.eventDescription();
+ if(ctx.getEventDetails() != null){
+ eventDescription += ". "+ctx.getEventDetails();
+ }
+ ActionEventUtils.onStartedActionEvent(userId, accountId, actionEvent.eventType(), eventDescription, startEventId);
+ }
+ }
+ return event;
+ }
+
+ @Override
+ public void interceptComplete(AnnotatedElement element, EventVO event) {
+ Method method = (Method)element;
+ ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
+ if (actionEvent != null) {
+ UserContext ctx = UserContext.current();
+ long userId = ctx.getCallerUserId();
+ long accountId = ctx.getAccountId();
+ long startEventId = ctx.getStartEventId();
+ String eventDescription = actionEvent.eventDescription();
+ if(ctx.getEventDetails() != null){
+ eventDescription += ". "+ctx.getEventDetails();
+ }
+ if(actionEvent.create()){
+ //This start event has to be used for subsequent events of this action
+ startEventId = ActionEventUtils.onCreatedActionEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully created entity for " + eventDescription);
+ ctx.setStartEventId(startEventId);
+ } else {
+ ActionEventUtils.onCompletedActionEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully completed " + eventDescription, startEventId);
+ }
+ }
+ }
+
+ @Override
+ public void interceptException(AnnotatedElement element, EventVO event) {
+ Method method = (Method)element;
+ ActionEvent actionEvent = method.getAnnotation(ActionEvent.class);
+ if (actionEvent != null) {
+ UserContext ctx = UserContext.current();
+ long userId = ctx.getCallerUserId();
+ long accountId = ctx.getAccountId();
+ long startEventId = ctx.getStartEventId();
+ String eventDescription = actionEvent.eventDescription();
+ if(ctx.getEventDetails() != null){
+ eventDescription += ". "+ctx.getEventDetails();
+ }
+ if(actionEvent.create()){
+ long eventId = ActionEventUtils.onCreatedActionEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while creating entity for " + eventDescription);
+ ctx.setStartEventId(eventId);
+ } else {
+ ActionEventUtils.onCompletedActionEvent(userId, accountId, EventVO.LEVEL_ERROR, actionEvent.eventType(), "Error while " + eventDescription, startEventId);
+ }
+ }
+ }
+
+ @Override
+ public Callback getCallback() {
+ return this;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/event/AlertGenerator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/AlertGenerator.java b/server/src/com/cloud/event/AlertGenerator.java
new file mode 100644
index 0000000..4286377
--- /dev/null
+++ b/server/src/com/cloud/event/AlertGenerator.java
@@ -0,0 +1,87 @@
+// 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.event;
+
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.HostPodVO;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.HostPodDao;
+import com.cloud.server.ManagementServer;
+import com.cloud.utils.component.Adapters;
+import com.cloud.utils.component.ComponentLocator;
+import org.apache.cloudstack.framework.events.*;
+import org.apache.log4j.Logger;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+public class AlertGenerator {
+
+ private static final Logger s_logger = Logger.getLogger(AlertGenerator.class);
+ private static DataCenterDao _dcDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(DataCenterDao.class);
+ private static HostPodDao _podDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(HostPodDao.class);
+
+ // get the event bus provider if configured
+ protected static EventBus _eventBus = null;
+ static {
+ Adapters<EventBus> eventBusImpls = ComponentLocator.getLocator(ManagementServer.Name).getAdapters(EventBus.class);
+ if (eventBusImpls != null) {
+ Enumeration<EventBus> eventBusenum = eventBusImpls.enumeration();
+ if (eventBusenum != null && eventBusenum.hasMoreElements()) {
+ _eventBus = eventBusenum.nextElement(); // configure event bus if configured
+ }
+ }
+ }
+
+ public static void publishAlertOnEventBus(String alertType, long dataCenterId, Long podId, String subject, String body) {
+ if (_eventBus == null) {
+ return; // no provider is configured to provider events bus, so just return
+ }
+
+ org.apache.cloudstack.framework.events.Event event =
+ new org.apache.cloudstack.framework.events.Event(ManagementServer.Name,
+ EventCategory.ALERT_EVENT.getName(),
+ alertType,
+ null,
+ null);
+
+ Map<String, String> eventDescription = new HashMap<String, String>();
+ DataCenterVO dc = _dcDao.findById(dataCenterId);
+ HostPodVO pod = _podDao.findById(podId);
+
+ eventDescription.put("event", alertType);
+ if (dc != null) {
+ eventDescription.put("dataCenterId", dc.getUuid());
+ } else {
+ eventDescription.put("dataCenterId", null);
+ }
+ if (pod != null) {
+ eventDescription.put("podId", pod.getUuid());
+ } else {
+ eventDescription.put("podId", null);
+ }
+ event.setDescription(eventDescription);
+
+ try {
+ _eventBus.publish(event);
+ } catch (EventBusException e) {
+ s_logger.warn("Failed to publish alert on the the event bus.");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/event/EventUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/EventUtils.java b/server/src/com/cloud/event/EventUtils.java
deleted file mode 100755
index 3672ee7..0000000
--- a/server/src/com/cloud/event/EventUtils.java
+++ /dev/null
@@ -1,102 +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.event;
-
-import com.cloud.event.dao.EventDao;
-import com.cloud.server.ManagementServer;
-import com.cloud.user.AccountVO;
-import com.cloud.user.dao.AccountDao;
-import com.cloud.utils.component.ComponentLocator;
-
-public class EventUtils {
- private static EventDao _eventDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(EventDao.class);
- private static AccountDao _accountDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(AccountDao.class);
-
- public static Long saveEvent(Long userId, Long accountId, Long domainId, String type, String description) {
- EventVO event = new EventVO();
- event.setUserId(userId);
- event.setAccountId(accountId);
- event.setDomainId(domainId);
- event.setType(type);
- event.setDescription(description);
- event = _eventDao.persist(event);
- return event.getId();
- }
-
- /*
- * Save event after scheduling an async job
- */
- public static Long saveScheduledEvent(Long userId, Long accountId, String type, String description, long startEventId) {
- EventVO event = new EventVO();
- event.setUserId(userId);
- event.setAccountId(accountId);
- event.setDomainId(getDomainId(accountId));
- event.setType(type);
- event.setStartId(startEventId);
- event.setState(Event.State.Scheduled);
- event.setDescription("Scheduled async job for "+description);
- event = _eventDao.persist(event);
- return event.getId();
- }
-
- /*
- * Save event after starting execution of an async job
- */
- public static Long saveStartedEvent(Long userId, Long accountId, String type, String description, long startEventId) {
- EventVO event = new EventVO();
- event.setUserId(userId);
- event.setAccountId(accountId);
- event.setDomainId(getDomainId(accountId));
- event.setType(type);
- event.setState(Event.State.Started);
- event.setDescription("Starting job for "+description);
- event.setStartId(startEventId);
- event = _eventDao.persist(event);
- return event.getId();
- }
-
- public static Long saveEvent(Long userId, Long accountId, String level, String type, String description, long startEventId) {
- EventVO event = new EventVO();
- event.setUserId(userId);
- event.setAccountId(accountId);
- event.setDomainId(getDomainId(accountId));
- event.setType(type);
- event.setDescription(description);
- event.setLevel(level);
- event.setStartId(startEventId);
- event = _eventDao.persist(event);
- return (event != null ? event.getId() : null);
- }
-
- public static Long saveCreatedEvent(Long userId, Long accountId, String level, String type, String description) {
- EventVO event = new EventVO();
- event.setUserId(userId);
- event.setAccountId(accountId);
- event.setDomainId(getDomainId(accountId));
- event.setType(type);
- event.setLevel(level);
- event.setState(Event.State.Created);
- event.setDescription(description);
- event = _eventDao.persist(event);
- return event.getId();
- }
-
- private static long getDomainId(long accountId){
- AccountVO account = _accountDao.findByIdIncludingRemoved(accountId);
- return account.getDomainId();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e7a554fc/server/src/com/cloud/event/UsageEventUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/UsageEventUtils.java b/server/src/com/cloud/event/UsageEventUtils.java
new file mode 100644
index 0000000..904525e
--- /dev/null
+++ b/server/src/com/cloud/event/UsageEventUtils.java
@@ -0,0 +1,119 @@
+package com.cloud.event;
+
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.event.dao.UsageEventDao;
+import com.cloud.server.ManagementServer;
+import com.cloud.user.Account;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.utils.component.Adapters;
+import com.cloud.utils.component.ComponentLocator;
+import org.apache.cloudstack.framework.events.EventBus;
+import org.apache.cloudstack.framework.events.Event;
+import org.apache.cloudstack.framework.events.EventBusException;
+import org.apache.log4j.Logger;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+public class UsageEventUtils {
+
+ private static UsageEventDao _usageEventDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(UsageEventDao.class);
+ private static AccountDao _accountDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(AccountDao.class);
+ private static DataCenterDao _dcDao = ComponentLocator.getLocator(ManagementServer.Name).getDao(DataCenterDao.class);
+ private static final Logger s_logger = Logger.getLogger(UsageEventUtils.class);
+
+ // get the event bus provider if configured
+ protected static EventBus _eventBus = null;
+ static {
+ Adapters<EventBus> eventBusImpls = ComponentLocator.getLocator(ManagementServer.Name).getAdapters(EventBus.class);
+ if (eventBusImpls != null) {
+ Enumeration<EventBus> eventBusenum = eventBusImpls.enumeration();
+ if (eventBusenum != null && eventBusenum.hasMoreElements()) {
+ _eventBus = eventBusenum.nextElement(); // configure event bus if configured
+ }
+ }
+ }
+
+ public static void publishUsageEvent(String usageType, long accountId, long zoneId,
+ long resourceId, String resourceName,
+ Long offeringId, Long templateId, Long size,
+ String entityType, String entityUUID) {
+ saveUsageEvent(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, size);
+ publishUsageEvent(usageType, accountId, zoneId, entityType, entityUUID);
+ }
+
+ public static void publishUsageEvent(String usageType, long accountId, long zoneId, long resourceId,
+ String resourceName, String entityType, String entityUUID) {
+ saveUsageEvent(usageType, accountId, zoneId, resourceId, resourceName);
+ publishUsageEvent(usageType, accountId, zoneId, entityType, entityUUID);
+ }
+
+ public static void publishUsageEvent(String usageType, long accountId, long zoneId,
+ long ipAddressId, String ipAddress, boolean isSourceNat,
+ String guestType, boolean isSystem, String entityType, String entityUUID) {
+ saveUsageEvent(usageType, accountId, zoneId, ipAddressId, ipAddress, isSourceNat, guestType, isSystem);
+ publishUsageEvent(usageType, accountId, zoneId, entityType, entityUUID);
+ }
+
+ public static void publishUsageEvent(String usageType, long accountId, long zoneId, long resourceId,
+ String resourceName, Long offeringId, Long templateId, String resourceType,
+ String entityType, String entityUUID) {
+ saveUsageEvent(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, resourceType);
+ publishUsageEvent(usageType, accountId, zoneId, entityType, entityUUID);
+ }
+
+ public static void publishUsageEvent(String usageType, long accountId,long zoneId, long vmId,
+ long securityGroupId, String entityType, String entityUUID) {
+ saveUsageEvent(usageType, accountId, zoneId, vmId, securityGroupId);
+ publishUsageEvent(usageType, accountId, zoneId, entityType, entityUUID);
+ }
+
+ public static void saveUsageEvent(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, Long size) {
+ _usageEventDao.persist( new UsageEventVO(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, size));
+ }
+
+ public static void saveUsageEvent(String usageType, long accountId, long zoneId, long resourceId, String resourceName) {
+ _usageEventDao.persist( new UsageEventVO(usageType, accountId, zoneId, resourceId, resourceName));
+ }
+
+ public static void saveUsageEvent(String usageType, long accountId, long zoneId, long ipAddressId, String ipAddress, boolean isSourceNat, String guestType, boolean isSystem) {
+ _usageEventDao.persist( new UsageEventVO(usageType, accountId, zoneId, ipAddressId, ipAddress, isSourceNat, guestType, isSystem));
+ }
+
+ public static void saveUsageEvent(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, String resourceType) {
+ _usageEventDao.persist( new UsageEventVO(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, resourceType));
+ }
+
+ public static void saveUsageEvent(String usageType, long accountId,long zoneId, long vmId, long securityGroupId) {
+ _usageEventDao.persist( new UsageEventVO( usageType, accountId, zoneId, vmId, securityGroupId));
+ }
+
+ private static void publishUsageEvent(String usageEventType, Long accountId, Long zoneId, String resourceType, String resourceUUID) {
+
+ if (_eventBus == null) {
+ return; // no provider is configured to provider events bus, so just return
+ }
+
+ Account account = _accountDao.findById(accountId);
+ DataCenterVO dc = _dcDao.findById(zoneId);
+
+ Event event = new Event(ManagementServer.Name, EventCategory.USAGE_EVENT.getName(), usageEventType,
+ resourceType, resourceUUID);
+
+ Map<String, String> eventDescription = new HashMap<String, String>();
+ eventDescription.put("account", account.getUuid());
+ eventDescription.put("zone", dc.getUuid());
+ eventDescription.put("event", usageEventType);
+ eventDescription.put("resource", resourceType);
+ eventDescription.put("id", resourceUUID);
+ event.setDescription(eventDescription);
+
+ try {
+ _eventBus.publish(event);
+ } catch (EventBusException e) {
+ s_logger.warn("Failed to publish usage event on the the event bus.");
+ }
+ }
+}