bug 10382: wrapped usage events in txn

This commit is contained in:
kishan 2011-07-01 18:11:56 +05:30
parent 1dcbfe09f9
commit fd6900a3d8
5 changed files with 51 additions and 26 deletions

View File

@ -340,7 +340,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
return true;
}
@Override
@Override @DB
@ActionEvent(eventType = EventTypes.EVENT_LOAD_BALANCER_CREATE, eventDescription = "creating load balancer")
public LoadBalancer createLoadBalancerRule(LoadBalancer lb) throws NetworkRuleConflictException {
UserContext caller = UserContext.current();
@ -394,6 +394,9 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
throw new InvalidParameterValueException("LB service is not supported in network id=" + networkId);
}
Transaction txn = Transaction.currentTxn();
txn.start();
LoadBalancerVO newRule = new LoadBalancerVO(lb.getXid(), lb.getName(), lb.getDescription(), lb.getSourceIpAddressId(), lb.getSourcePortEnd(), lb.getDefaultPortStart(), lb.getAlgorithm(),
networkId, ipAddr.getAccountId(), ipAddr.getDomainId());
@ -408,6 +411,7 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
UserContext.current().setEventDetails("Load balancer Id: " + newRule.getId());
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_LOAD_BALANCER_CREATE, ipAddr.getAllocatedToAccountId(), ipAddr.getDataCenterId(), newRule.getId(), null);
_usageEventDao.persist(usageEvent);
txn.commit();
return newRule;
} catch (Exception e) {
_lbDao.remove(newRule.getId());

View File

@ -188,7 +188,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
}
}
@Override
@Override @DB
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "creating forwarding rule", create = true)
public PortForwardingRule createPortForwardingRule(PortForwardingRule rule, Long vmId) throws NetworkRuleConflictException {
UserContext ctx = UserContext.current();
@ -257,6 +257,9 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
dstIp = new Ip(guestNic.getIp4Address());
}
Transaction txn = Transaction.currentTxn();
txn.start();
PortForwardingRuleVO newRule = new PortForwardingRuleVO(rule.getXid(), rule.getSourceIpAddressId(), rule.getSourcePortStart(), rule.getSourcePortEnd(), dstIp, rule.getDestinationPortStart(),
rule.getDestinationPortEnd(), rule.getProtocol().toLowerCase(), rule.getSourceCidrList(), networkId, accountId, domainId, vmId);
newRule = _forwardingDao.persist(newRule);
@ -269,6 +272,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
UserContext.current().setEventDetails("Rule Id: " + newRule.getId());
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_RULE_ADD, newRule.getAccountId(), ipAddress.getDataCenterId(), newRule.getId(), null);
_usageEventDao.persist(usageEvent);
txn.commit();
return newRule;
} catch (Exception e) {
_forwardingDao.remove(newRule.getId());
@ -279,7 +283,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
}
}
@Override
@Override @DB
@ActionEvent(eventType = EventTypes.EVENT_NET_RULE_ADD, eventDescription = "creating static nat rule", create = true)
public StaticNatRule createStaticNatRule(StaticNatRule rule) throws NetworkRuleConflictException {
Account caller = UserContext.current().getCaller();
@ -330,6 +334,9 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
throw new InvalidParameterValueException("Start port can't be bigger than end port");
}
Transaction txn = Transaction.currentTxn();
txn.start();
FirewallRuleVO newRule = new FirewallRuleVO(rule.getXid(), rule.getSourceIpAddressId(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol().toLowerCase(),
networkId, accountId, domainId, rule.getPurpose());
newRule = _firewallDao.persist(newRule);
@ -343,6 +350,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_RULE_ADD, newRule.getAccountId(), 0, newRule.getId(), null);
_usageEventDao.persist(usageEvent);
txn.commit();
StaticNatRule staticNatRule = new StaticNatRuleImpl(newRule, dstIp);
return staticNatRule;

View File

@ -1591,7 +1591,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
* Just allocate a volume in the database, don't send the createvolume cmd to hypervisor. The volume will be finally created
* only when it's attached to a VM.
*/
@Override
@Override @DB
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_CREATE, eventDescription = "creating volume", create = true)
public VolumeVO allocVolume(CreateVolumeCmd cmd) throws ResourceAllocationException {
// FIXME: some of the scheduled event stuff might be missing here...
@ -1743,6 +1743,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
userSpecifiedName = getRandomVolumeName();
}
Transaction txn = Transaction.currentTxn();
txn.start();
VolumeVO volume = new VolumeVO(userSpecifiedName, -1, -1, -1, -1, new Long(-1), null, null, 0, Volume.Type.DATADISK);
volume.setPoolId(null);
volume.setDataCenterId(zoneId);
@ -1758,6 +1761,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
volume = _volsDao.persist(volume);
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOfferingId, null, size);
_usageEventDao.persist(usageEvent);
txn.commit();
UserContext.current().setEventDetails("Volume Id: " + volume.getId());

View File

@ -73,9 +73,11 @@ import com.cloud.storage.template.TemplateConstants;
import com.cloud.storage.template.TemplateInfo;
import com.cloud.user.Account;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.JoinBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.vm.SecondaryStorageVm;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.UserVmManager;
@ -381,6 +383,7 @@ public class DownloadMonitorImpl implements DownloadMonitor {
}
@DB
public void handleDownloadEvent(HostVO host, VMTemplateVO template, Status dnldStatus) {
if ((dnldStatus == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) || (dnldStatus==Status.ABANDONED)){
VMTemplateHostVO vmTemplateHost = new VMTemplateHostVO(host.getId(), template.getId());
@ -391,24 +394,9 @@ public class DownloadMonitorImpl implements DownloadMonitor {
VMTemplateHostVO vmTemplateHost = _vmTemplateHostDao.findByHostTemplate(host.getId(), template.getId());
if (dnldStatus == Status.DOWNLOADED) {
long size = -1;
if(vmTemplateHost!=null){
size = vmTemplateHost.getPhysicalSize();
}
else{
s_logger.warn("Failed to get size for template" + template.getName());
}
String eventType = EventTypes.EVENT_TEMPLATE_CREATE;
if((template.getFormat()).equals(ImageFormat.ISO)){
eventType = EventTypes.EVENT_ISO_CREATE;
}
if(template.getAccountId() != Account.ACCOUNT_ID_SYSTEM){
UsageEventVO usageEvent = new UsageEventVO(eventType, template.getAccountId(), host.getDataCenterId(), template.getId(), template.getName(), null, template.getSourceTemplateId() , size);
_usageEventDao.persist(usageEvent);
}
}
Transaction txn = Transaction.currentTxn();
txn.start();
if (vmTemplateHost != null) {
Long poolId = vmTemplateHost.getPoolId();
if (poolId != null) {
@ -440,6 +428,24 @@ public class DownloadMonitorImpl implements DownloadMonitor {
}
}
if (dnldStatus == Status.DOWNLOADED) {
long size = -1;
if(vmTemplateHost!=null){
size = vmTemplateHost.getPhysicalSize();
}
else{
s_logger.warn("Failed to get size for template" + template.getName());
}
String eventType = EventTypes.EVENT_TEMPLATE_CREATE;
if((template.getFormat()).equals(ImageFormat.ISO)){
eventType = EventTypes.EVENT_ISO_CREATE;
}
if(template.getAccountId() != Account.ACCOUNT_ID_SYSTEM){
UsageEventVO usageEvent = new UsageEventVO(eventType, template.getAccountId(), host.getDataCenterId(), template.getId(), template.getName(), null, template.getSourceTemplateId() , size);
_usageEventDao.persist(usageEvent);
}
}
txn.commit();
}
@Override

View File

@ -1580,6 +1580,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
// Specify RAW format makes it unusable for snapshots.
privateTemplate.setFormat(ImageFormat.RAW);
}
Transaction txn = Transaction.currentTxn();
txn.start();
String checkSum = getChecksum(secondaryStorageHost.getId(), answer.getPath());
privateTemplate.setChecksum(checkSum);
_templateDao.update(templateId, privateTemplate);
@ -1598,7 +1600,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_TEMPLATE_CREATE, privateTemplate.getAccountId(), secondaryStorageHost.getDataCenterId(), privateTemplate.getId(),
privateTemplate.getName(), null, privateTemplate.getSourceTemplateId(), templateHostVO.getSize());
_usageEventDao.persist(usageEvent);
txn.commit();
}
} finally {
if (privateTemplate == null) {
@ -2320,7 +2322,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId, diskSize, networkList, null, group, userData, sshKeyPair, hypervisor, caller, requestedIps, defaultIp);
}
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "deploying Vm", create = true)
@DB @ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "deploying Vm", create = true)
protected UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, String hostName, String displayName, Account owner, Long diskOfferingId,
Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group, String userData, String sshKeyPair, HypervisorType hypervisor, Account caller, Map<Long, String> requestedIps, String defaultNetworkIp) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, ResourceAllocationException {
@ -2498,7 +2500,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
} else {
hypervisorType = template.getHypervisorType();
}
Transaction txn = Transaction.currentTxn();
txn.start();
UserVmVO vm = new UserVmVO(id, instanceName, displayName, template.getId(), hypervisorType, template.getGuestOSId(), offering.getOfferHA(), offering.getLimitCpuUse(), owner.getDomainId(), owner.getId(),
offering.getId(), userData, hostName);
@ -2527,7 +2530,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
_usageEventDao.persist(usageEvent);
_accountMgr.incrementResourceCount(accountId, ResourceType.user_vm);
txn.commit();
// Assign instance to the group
try {
if (group != null) {