bug 7504: Events refactoring

status 7504: resolved fixed
This commit is contained in:
kishan 2010-12-24 19:38:28 +05:30
parent 53d3455cbe
commit e51dc79000
12 changed files with 81 additions and 253 deletions

View File

@ -85,7 +85,7 @@ public class DeleteAccountCmd extends BaseAsyncCmd {
@Override
public String getEventDescription() {
User user = _responseGenerator.findUserById(getId());
return (user != null ? ("User " + user.getUsername() + " (id: " + user.getId() + ") and accountId = " + user.getAccountId()) : "user delete, but this user does not exist in the system");
return (user != null ? ("deleting User " + user.getUsername() + " (id: " + user.getId() + ") and accountId = " + user.getAccountId()) : "user delete, but this user does not exist in the system");
}
@Override

View File

@ -1939,21 +1939,19 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
return;
}
String params = "\nsourceNat=" + false + "\ndcId=" + zoneId;
// Associate the IP's to DomR
boolean success = _networkMgr.associateIP(router,ipAddrsList, true, 0);
String errorMsg = "Unable to assign public IP address pool";
if (!success) {
s_logger.debug(errorMsg);
for(String ip : ipAddrsList){
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_NET_IP_ASSIGN, "Unable to assign public IP " +ip, params);
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_NET_IP_ASSIGN, "Unable to assign public IP " +ip);
}
throw new CloudRuntimeException(errorMsg);
}
txn.commit();
for(String ip : ipAddrsList){
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, EventTypes.EVENT_NET_IP_ASSIGN, "Successfully assigned account IP " +ip, params);
EventUtils.saveEvent(userId, accountId, EventVO.LEVEL_INFO, EventTypes.EVENT_NET_IP_ASSIGN, "Successfully assigned account IP " +ip);
}
}
} catch (CloudRuntimeException iee) {

View File

@ -313,7 +313,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
// Increment the number of public IPs for this accountId in the database
_accountMgr.incrementResourceCount(ownerId, ResourceType.public_ip);
event.setParameters("address=" + ip.getAddress() + "\nsourceNat=true\ndcId="+dcId);
event.setDescription("Acquired a public ip: " + ip.getAddress());
_eventDao.persist(event);
} else {
@ -351,7 +350,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (ip == null) {
txn.rollback();
event.setLevel(EventVO.LEVEL_ERROR);
event.setParameters("dcId=" + dcId);
event.setDescription("Failed to acquire a public ip.");
_eventDao.persist(event);
s_logger.error("Unable to get source nat ip address for account " + ownerId);
@ -681,13 +679,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
final EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(ip.getAllocatedToAccountId());
event.setType(EventTypes.EVENT_NET_IP_RELEASE);
event.setParameters("address=" + ipAddress + "\nsourceNat="+ip.isSourceNat());
event.setDescription("released a public ip: " + ipAddress);
_eventDao.persist(event);
EventUtils.saveEvent(userId, ip.getAllocatedToAccountId(), EventTypes.EVENT_NET_IP_RELEASE, "released a public ip: " + ipAddress);
return success;
}

View File

@ -377,8 +377,6 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
} else {
event.setDescription("Successfully created load balancer " + lb.getName() + " on ip address " + srcIp + "[" + srcPortStart + "->"
+ defPortStart + "]");
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);

View File

@ -3207,17 +3207,13 @@ public class ManagementServerImpl implements ManagementServer {
if ((cleanup != null) && cleanup.booleanValue()) {
boolean success = cleanupDomain(domainId, ownerId);
if (!success) {
EventUtils.saveEvent(new Long(1), ownerId, EventVO.LEVEL_ERROR, EventTypes.EVENT_DOMAIN_DELETE, "Failed to clean up domain resources and sub domains, domain with id " + domainId + " was not deleted.");
s_logger.error("Failed to clean up domain resources and sub domains, delete failed on domain " + domain.getName() + " (id: " + domainId + ").");
return false;
}
} else {
if (!_domainDao.remove(domainId)) {
EventUtils.saveEvent(new Long(1), ownerId, EventVO.LEVEL_ERROR, EventTypes.EVENT_DOMAIN_DELETE, "Domain with id " + domainId + " was not deleted");
s_logger.error("Delete failed on domain " + domain.getName() + " (id: " + domainId + "); please make sure all users and sub domains have been removed from the domain before deleting");
return false;
} else {
EventUtils.saveEvent(new Long(1), ownerId, EventVO.LEVEL_INFO, EventTypes.EVENT_DOMAIN_DELETE, "Domain with id " + domainId + " was deleted");
}
}
} else {
@ -3251,7 +3247,14 @@ public class ManagementServerImpl implements ManagementServer {
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
List<AccountVO> accounts = _accountDao.search(sc, null);
for (AccountVO account : accounts) {
success = (success && _accountMgr.deleteAccountInternal(account.getAccountId(), 0));
success = (success && _accountMgr.deleteAccountInternal(account.getAccountId()));
String description = "Account:" + account.getAccountId();
if(success){
EventUtils.saveEvent(User.UID_SYSTEM, account.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_ACCOUNT_DELETE, "Successfully deleted " +description);
}else{
EventUtils.saveEvent(User.UID_SYSTEM, account.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_ACCOUNT_DELETE, "Error deleting " +description);
}
}
}

View File

@ -91,6 +91,7 @@ import com.cloud.domain.Domain;
import com.cloud.domain.dao.DomainDao;
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;
@ -139,6 +140,7 @@ import com.cloud.storage.snapshot.SnapshotScheduler;
import com.cloud.template.TemplateManager;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.User;
import com.cloud.user.UserContext;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
@ -644,20 +646,10 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
@DB
protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId, long startEventId) {
EventVO event = new EventVO();
event.setUserId(UserContext.current().getUserId());
event.setAccountId(volume.getAccountId());
event.setType(EventTypes.EVENT_VOLUME_CREATE);
event.setState(Event.State.Started);
event.setStartId(startEventId);
event.setDescription("Creating volume from snapshot with id: "+snapshotId);
_eventDao.persist(event);
protected VolumeVO createVolumeFromSnapshot(VolumeVO volume, long snapshotId) {
// By default, assume failure.
VolumeVO createdVolume = null;
String details = null;
Long volumeId = null;
SnapshotVO snapshot = _snapshotDao.findById(snapshotId); // Precondition: snapshot is not null and not removed.
Long origVolumeId = snapshot.getVolumeId();
VolumeVO originalVolume = _volsDao.findById(origVolumeId); // NOTE: Original volume could be destroyed and removed.
@ -666,15 +658,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
template = _templateDao.findById(originalVolume.getTemplateId());
}
// everything went well till now
DataCenterVO dc = _dcDao.findById(originalVolume.getDataCenterId());
Pair<VolumeVO, String> volumeDetails = createVolumeFromSnapshot(volume, snapshot, template, originalVolume.getSize());
createdVolume = volumeDetails.first();
if (createdVolume != null) {
volumeId = createdVolume.getId();
}
details = volumeDetails.second();
Transaction txn = Transaction.currentTxn();
txn.start();
@ -687,27 +672,10 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
diskOfferingId = originalVolume.getDiskOfferingId();
long sizeMB = createdVolume.getSize()/(1024*1024);
String poolName = _storagePoolDao.findById(createdVolume.getPoolId()).getName();
String eventParams = "id=" + volumeId +"\ndoId="+diskOfferingId+"\ntId="+templateId+"\ndcId="+originalVolume.getDataCenterId()+"\nsize="+sizeMB;
event = new EventVO();
event.setAccountId(volume.getAccountId());
event.setUserId(UserContext.current().getUserId());
event.setType(EventTypes.EVENT_VOLUME_CREATE);
event.setParameters(eventParams);
event.setStartId(startEventId);
event.setState(Event.State.Completed);
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;
event.setDescription(details);
event.setLevel(EventVO.LEVEL_ERROR);
}
_eventDao.persist(event);
txn.commit();
return createdVolume;
}
@ -859,9 +827,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
txn.start();
if (Storage.ImageFormat.ISO == template.getFormat()) {
rootVol = new VolumeVO(VolumeType.ROOT, vm.getId(), vm.getInstanceName() + "-ROOT", dc.getId(), pod.getId(), account.getId(), account.getDomainId(),(size>0)? size : diskOffering.getDiskSizeInBytes());
createStartedEvent(account, rootVol);
rootVol.setDiskOfferingId(diskOffering.getId());
rootVol.setSourceType(SourceType.Template);
rootVol.setSourceId(template.getId());
@ -869,9 +834,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
rootVol = _volsDao.persist(rootVol);
} else {
rootVol = new VolumeVO(VolumeType.ROOT, vm.getId(), template.getId(), vm.getInstanceName() + "-ROOT", dc.getId(), pod.getId(), account.getId(), account.getDomainId(), offering.isRecreatable());
createStartedEvent(account, rootVol);
rootVol.setDiskOfferingId(offering.getId());
rootVol.setTemplateId(template.getId());
rootVol.setSourceId(template.getId());
@ -881,9 +843,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
if ((diskOffering != null && diskOffering.getDiskSizeInBytes() > 0) || (diskOffering != null && diskOffering.isCustomized())) {
dataVol = new VolumeVO(VolumeType.DATADISK, vm.getId(), vm.getInstanceName() + "-DATA", dc.getId(), pod.getId(), account.getId(), account.getDomainId(), (size>0)? size : diskOffering.getDiskSizeInBytes());
createStartedEvent(account, dataVol);
dataVol.setDiskOfferingId(diskOffering.getId());
dataVol.setSourceType(SourceType.DiskOffering);
dataVol.setSourceId(diskOffering.getId());
@ -924,17 +883,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
}
private void createStartedEvent(Account account, VolumeVO rootVol) {
EventVO event1 = new EventVO();
event1.setAccountId(account.getId());
event1.setUserId(1L);
event1.setType(EventTypes.EVENT_VOLUME_CREATE);
event1.setState(Event.State.Started);
event1.setDescription("Create volume: " + rootVol.getName()+ "started");
_eventDao.persist(event1);
}
@Override
public long createUserVM(Account account, VMInstanceVO vm, VMTemplateVO template, DataCenterVO dc, HostPodVO pod, ServiceOfferingVO offering, DiskOfferingVO diskOffering,
List<StoragePoolVO> avoids, long size) {
@ -954,25 +902,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
{
s_logger.warn("Error updating the attached value for volume "+v.getId()+":"+e);
}
long templateId = -1;
long doId = v.getDiskOfferingId();
if(v.getVolumeType() == VolumeType.ROOT && Storage.ImageFormat.ISO != template.getFormat()){
templateId = template.getId();
doId = -1;
}
long volumeId = v.getId();
// Create an event
long sizeMB = v.getSize() / (1024 * 1024);
String eventParams = "id=" + volumeId + "\ndoId=" + doId + "\ntId=" + templateId + "\ndcId=" + dc.getId() + "\nsize=" + sizeMB;
EventVO event = new EventVO();
event.setAccountId(account.getId());
event.setUserId(1L);
event.setType(EventTypes.EVENT_VOLUME_CREATE);
event.setParameters(eventParams);
event.setDescription("Created volume: " + v.getName() + " with size: " + sizeMB + " MB");
_eventDao.persist(event);
}
return volumes.get(0).getPoolId();
@ -1853,10 +1782,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
public VolumeVO createVolume(CreateVolumeCmd cmd) {
VolumeVO volume = _volsDao.findById(cmd.getEntityId());
// VolumeVO createdVolume = null;
Long userId = UserContext.current().getUserId();
if (cmd.getSnapshotId() != null) {
return createVolumeFromSnapshot(volume, cmd.getSnapshotId(), cmd.getStartEventId());
return createVolumeFromSnapshot(volume, cmd.getSnapshotId());
} else {
DataCenterVO dc = _dcDao.findById(cmd.getZoneId());
DiskOfferingVO diskOffering = _diskOfferingDao.findById(cmd.getDiskOfferingId());
@ -1880,12 +1808,6 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
}
*/
// Create an event
EventVO event = new EventVO();
event.setAccountId(volume.getAccountId());
event.setUserId(userId);
event.setType(EventTypes.EVENT_VOLUME_CREATE);
event.setStartId(cmd.getStartEventId());
/*
Transaction txn = Transaction.currentTxn();
@ -1906,14 +1828,8 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
// long sizeMB = createdVolume.getSize() / (1024 * 1024);
// StoragePoolVO pool = _storagePoolDao.findById(createdVolume.getPoolId());
// String eventParams = "id=" + createdVolume.getId() + "\ndoId=" + diskOffering.getId() + "\ntId=" + -1 + "\ndcId=" + dc.getId() + "\nsize=" + sizeMB;
String eventParams = "id=" + volume.getId() + "\ndoId=" + diskOffering.getId() + "\ntId=" + -1 + "\ndcId=" + dc.getId() + "\nsize=" + sizeMB;
event.setLevel(EventVO.LEVEL_INFO);
// event.setDescription("Created volume: " + createdVolume.getName() + " with size: " + sizeMB + " MB in pool: " + pool.getName());
// event.setDescription("Created volume: " + createdVolume.getName() + " with size: " + sizeMB + " MB");
event.setDescription("Created volume: " + volume.getName() + " with size: " + sizeMB + " MB");
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);
/*
@ -1944,15 +1860,7 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
Long volumeId = volume.getId();
_volsDao.destroyVolume(volumeId);
String eventParams = "id=" + volumeId;
EventVO event = new EventVO();
event.setAccountId(volume.getAccountId());
event.setUserId(1L);
event.setType(EventTypes.EVENT_VOLUME_DELETE);
event.setParameters(eventParams);
event.setDescription("Volume " +volume.getName()+ " deleted");
event.setLevel(EventVO.LEVEL_INFO);
_eventDao.persist(event);
EventUtils.saveEvent(User.UID_SYSTEM, volume.getAccountId(), EventTypes.EVENT_VOLUME_DELETE, "Volume " +volume.getName()+ " deleted");
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), null, null , null);
_usageEventDao.persist(usageEvent);
@ -2660,6 +2568,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
if(vm instanceof UserVm){
long sizeMB = size / (1024 * 1024);
EventUtils.saveEvent(User.UID_SYSTEM, vol.getAccountId(), EventTypes.EVENT_VOLUME_CREATE, "Created volume: "+ vol.getName() +" with size: " + sizeMB + " MB");
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), null , sizeMB);
_usageEventDao.persist(usageEvent);
}
@ -2697,6 +2608,9 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
if(vm instanceof UserVm){
long sizeMB = vol.getSize() / (1024 * 1024);
EventUtils.saveEvent(User.UID_SYSTEM, vol.getAccountId(), EventTypes.EVENT_VOLUME_CREATE, "Created volume: "+ vol.getName() +" with size: " + sizeMB + " MB");
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offering.getId(), template.getId() , sizeMB);
_usageEventDao.persist(usageEvent);
}

View File

@ -64,6 +64,7 @@ import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.event.Event;
import com.cloud.event.EventTypes;
import com.cloud.event.EventUtils;
import com.cloud.event.EventVO;
import com.cloud.event.dao.EventDao;
import com.cloud.exception.AgentUnavailableException;
@ -123,6 +124,7 @@ import com.cloud.utils.net.NfsUtils;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.SecondaryStorageVm;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.State;
import com.cloud.vm.VirtualMachine;
@ -227,8 +229,12 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
@Override
public SecondaryStorageVmVO startSecStorageVm(long secStorageVmId) {
boolean started = false;
long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_START, "Starting secondary storage Vm with Id: "+secStorageVmId);
try {
return start(secStorageVmId);
SecondaryStorageVmVO ssvm = start(secStorageVmId);
started = true;
return ssvm;
} catch (StorageUnavailableException e) {
s_logger.warn("Exception while trying to start secondary storage vm", e);
return null;
@ -240,6 +246,12 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
return null;
} catch (ResourceUnavailableException e) {
return null;
} finally {
if(started){
EventUtils.saveEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventVO.LEVEL_INFO, EventTypes.EVENT_SSVM_START, "Started secondary storage Vm with Id: "+secStorageVmId, startEventId);
} else {
EventUtils.saveEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventVO.LEVEL_ERROR, EventTypes.EVENT_SSVM_START, "Failed to start secondary storage Vm with Id: "+secStorageVmId, startEventId);
}
}
}
@ -369,6 +381,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
s_logger.debug("Assign secondary storage vm from a newly started instance for request from data center : " + dataCenterId);
}
long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_CREATE, "Creating secondary storage Vm in zone : "+dataCenterId);
Map<String, Object> context = createSecStorageVmInstance(dataCenterId);
long secStorageVmId = (Long) context.get("secStorageVmId");
@ -381,7 +394,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
if (context.get("publicIpAddress") != null) {
freePublicIpAddress((String) context.get("publicIpAddress"), dataCenterId, 0);
}
EventUtils.saveEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventVO.LEVEL_ERROR, EventTypes.EVENT_SSVM_CREATE, "Failed to create secondary storage Vm in zone : "+dataCenterId, startEventId);
return null;
}
@ -393,6 +406,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
SecStorageVmAlertEventArgs.SSVM_CREATED,
dataCenterId, secStorageVmId, secStorageVm, null)
);
EventUtils.saveEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventVO.LEVEL_INFO, EventTypes.EVENT_SSVM_CREATE, "Successfully created secondary storage Vm "+ secStorageVm.getName() +" in zone : "+dataCenterId, startEventId);
return secStorageVm;
} else {
if (s_logger.isDebugEnabled()) {
@ -406,17 +420,16 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
dataCenterId, secStorageVmId, null, "Unable to allocate storage")
);
destroySecStorageVmDBOnly(secStorageVmId);
EventUtils.saveEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventVO.LEVEL_ERROR, EventTypes.EVENT_SSVM_CREATE, "Failed to create secondary storage Vm in zone : "+dataCenterId, startEventId);
}
return null;
}
protected Map<String, Object> createSecStorageVmInstance(long dataCenterId) {
long startEventId = saveStartedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_CREATE, "Creating secondary storage Vm in zone : "+dataCenterId, 0);
HostVO secHost = _hostDao.findSecondaryStorageHost(dataCenterId);
if (secHost == null) {
String msg = "No secondary storage available in zone " + dataCenterId + ", cannot create secondary storage vm";
s_logger.warn(msg);
saveFailedEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_CREATE, msg, startEventId);
throw new CloudRuntimeException(msg);
}
@ -1174,13 +1187,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
}
_secStorageVmDao.remove(vmId);
final EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(Account.ACCOUNT_ID_SYSTEM);
event.setType(EventTypes.EVENT_SSVM_DESTROY);
event.setLevel(EventVO.LEVEL_INFO);
event.setDescription("Secondary Storage Vm destroyed - " + secStorageVm.getName());
_eventDao.persist(event);
EventUtils.saveEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_SSVM_DESTROY, "Secondary Storage Vm destroyed - " + secStorageVm.getName());
}
txn.commit();
return true;
@ -1383,34 +1390,6 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
return "secStorageVm." + id;
}
private Long saveStartedEvent(Long userId, Long accountId, String type, String description, long startEventId) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setType(type);
event.setState(Event.State.Started);
event.setDescription(description);
event.setStartId(startEventId);
event = _eventDao.persist(event);
if(event != null) {
return event.getId();
}
return null;
}
private void saveFailedEvent(Long userId, Long accountId, String type, String description, long startEventId) {
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(accountId);
event.setType(type);
event.setState(Event.State.Completed);
event.setLevel(EventVO.LEVEL_ERROR);
event.setDescription(description);
event.setStartId(startEventId);
_eventDao.persist(event);
return;
}
@Override
public SecondaryStorageVmVO findByName(String name) {
if (!VirtualMachineName.isValidSecStorageVmName(name, null)) {

View File

@ -43,7 +43,7 @@ public interface SnapshotManager {
* @param cmd the API command wrapping the parameters for creating the snapshot (mainly volumeId)
* @return the Snapshot that was created
*/
SnapshotVO createSnapshotImpl(Long volumeId, Long policyId, Long startEventId, Long snapshotId) throws ResourceAllocationException;
SnapshotVO createSnapshotImpl(Long volumeId, Long policyId, Long snapshotId) throws ResourceAllocationException;
/**
* After successfully creating a snapshot of a volume, copy the snapshot to the secondary storage for
@ -53,7 +53,7 @@ public interface SnapshotManager {
* @param startEventId event id of the scheduled event for this snapshot
* @return True if the snapshot was successfully backed up.
*/
public boolean backupSnapshotToSecondaryStorage(SnapshotVO snapshot, long startEventId);
public boolean backupSnapshotToSecondaryStorage(SnapshotVO snapshot);
/**
* Once a snapshot has completed,
@ -120,7 +120,7 @@ public interface SnapshotManager {
SnapshotPolicyVO getPolicyForVolume(long volumeId);
boolean destroySnapshotBackUp(long userId, long snapshotId, long policyId);
boolean destroySnapshotBackUp(long snapshotId, long policyId);
/**
* Create a snapshot of a volume

View File

@ -327,7 +327,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
}
@Override @DB
public SnapshotVO createSnapshotImpl(Long volumeId, Long policyId, Long snapshotId, Long startEventId) throws ResourceAllocationException {
public SnapshotVO createSnapshotImpl(Long volumeId, Long policyId, Long snapshotId) throws ResourceAllocationException {
VolumeVO v = _volsDao.findById(volumeId);
if ( v != null && _volsDao.getHypervisorType(v.getId()).equals(HypervisorType.KVM)) {
/*KVM needs to lock on the vm of volume, because it takes snapshot on behalf of vm, not volume*/
@ -373,7 +373,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
snapshot = createSnapshotOnPrimary(volume, policyId, snapshotId);
if (snapshot != null && snapshot.getStatus() == Snapshot.Status.CreatedOnPrimary ) {
snapshotId = snapshot.getId();
backedUp = backupSnapshotToSecondaryStorage(snapshot, startEventId);
backedUp = backupSnapshotToSecondaryStorage(snapshot);
if (!backedUp) {
throw new CloudRuntimeException("Created snapshot: " + snapshotId + " on primary but failed to backup on secondary");
}
@ -394,8 +394,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
Long volumeId = cmd.getVolumeId();
Long policyId = cmd.getPolicyId();
Long snapshotId = cmd.getEntityId();
Long startEventId = cmd.getStartEventId();
return createSnapshotImpl(volumeId, policyId, snapshotId, startEventId);
return createSnapshotImpl(volumeId, policyId, snapshotId);
}
private SnapshotVO updateDBOnCreate(Long id, String snapshotPath, long preSnapshotId) {
@ -428,7 +427,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
// It has entered backupSnapshotToSecondaryStorage.
// But we have no idea whether it was backed up or not.
// So call backupSnapshotToSecondaryStorage again.
backupSnapshotToSecondaryStorage(snapshot, 0);
backupSnapshotToSecondaryStorage(snapshot);
break;
case BackedUp:
// No need to do anything as snapshot has already been backed up.
@ -436,7 +435,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
}
@Override @DB
public boolean backupSnapshotToSecondaryStorage(SnapshotVO ss, long startEventId) {
public boolean backupSnapshotToSecondaryStorage(SnapshotVO ss) {
Long userId = getSnapshotUserId();
long snapshotId = ss.getId();
SnapshotVO snapshot = _snapshotDao.acquireInLockTable(snapshotId);
@ -454,7 +453,6 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
String primaryStoragePoolNameLabel = _storageMgr.getPrimaryStorageNameLabel(volume);
Long dcId = volume.getDataCenterId();
Long accountId = volume.getAccountId();
EventUtils.saveStartedEvent(userId, accountId, EventTypes.EVENT_SNAPSHOT_CREATE, "Start creating snapshot for volume:"+volumeId, startEventId);
String secondaryStoragePoolUrl = _storageMgr.getSecondaryStorageURL(volume.getDataCenterId());
String snapshotUuid = snapshot.getPath();
@ -511,23 +509,11 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
Transaction txn = Transaction.currentTxn();
txn.start();
// Create an event
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId(volume.getAccountId());
event.setType(EventTypes.EVENT_SNAPSHOT_CREATE);
event.setStartId(startEventId);
String snapshotName = snapshot.getName();
if (backedUp) {
snapshot.setBackupSnapshotId(backedUpSnapshotUuid);
snapshot.setStatus(Snapshot.Status.BackedUp);
_snapshotDao.update(snapshotId, snapshot);
String eventParams = "id=" + snapshotId + "\nssName=" + snapshotName +"\nsize=" + volume.getSize()+"\ndcId=" + volume.getDataCenterId();
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());
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), volume.getDataCenterId(), snapshotId, snapshot.getName(), null, null, volume.getSize());
_usageEventDao.persist(usageEvent);
}
@ -540,11 +526,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
// 3) backupSnapshotToSecondaryStorage of the next snapshot
// will take care of cleaning up the state of this snapshot
_snapshotDao.remove(snapshotId);
event.setLevel(EventVO.LEVEL_ERROR);
event.setDescription("Failed to backup snapshot id: " + snapshotId + " to secondary for volume:" + volumeId);
}
// Save the event
_eventDao.persist(event);
txn.commit();
return backedUp;
@ -601,7 +583,13 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
s_logger.debug("Max snaps: "+ policy.getMaxSnaps() + " exceeded for snapshot policy with Id: " + policyId + ". Deleting oldest snapshot: " + oldSnapId);
// Excess snapshot. delete it asynchronously
//destroySnapshotAsync(userId, volumeId, oldSnapId, policyId);
deleteSnapshotInternal(oldSnapId, policyId, userId);
// create the event
long startEventId = EventUtils.saveStartedEvent(userId, oldestSnapshot.getAccountId(), EventTypes.EVENT_SNAPSHOT_DELETE, "Deleting snapshot with Id:"+oldSnapId);
if(deleteSnapshotInternal(oldSnapId, policyId)){
EventUtils.saveEvent(userId, oldestSnapshot.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_SNAPSHOT_DELETE, "Deleted snapshot with Id:"+oldSnapId, startEventId);
} else {
EventUtils.saveEvent(userId, oldestSnapshot.getAccountId(), EventVO.LEVEL_ERROR, EventTypes.EVENT_SNAPSHOT_DELETE, "Failed to delete snapshot with Id:"+oldSnapId, startEventId);
}
snaps.remove(oldestSnapshot);
}
@ -633,7 +621,6 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
@Override @DB
public boolean deleteSnapshot(DeleteSnapshotCmd cmd) {
Long userId = getSnapshotUserId();
Long snapshotId = cmd.getId();
//Verify parameters
@ -651,7 +638,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
boolean status = true;
if (Type.MANUAL.ordinal() == snapshotCheck.getSnapshotType()) {
status = deleteSnapshotInternal(snapshotId, Snapshot.MANUAL_POLICY_ID, userId);
status = deleteSnapshotInternal(snapshotId, Snapshot.MANUAL_POLICY_ID);
if (!status) {
s_logger.warn("Failed to delete snapshot");
@ -661,7 +648,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
List<SnapshotPolicyVO> policies = listPoliciesforVolume(snapshotCheck.getVolumeId());
for (SnapshotPolicyVO policy : policies) {
status = deleteSnapshotInternal(snapshotId, policy.getId(), userId);
status = deleteSnapshotInternal(snapshotId, policy.getId());
if (!status) {
s_logger.warn("Failed to delete snapshot");
@ -673,7 +660,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
return status;
}
private boolean deleteSnapshotInternal(Long snapshotId, Long policyId, Long userId) {
private boolean deleteSnapshotInternal(Long snapshotId, Long policyId) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Calling deleteSnapshot for snapshotId: " + snapshotId + " and policyId " + policyId);
}
@ -699,14 +686,14 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
while (lastSnapshot.getRemoved() != null) {
String BackupSnapshotId = lastSnapshot.getBackupSnapshotId();
if (BackupSnapshotId != null) {
if (destroySnapshotBackUp(userId, lastId, policyId)) {
if (destroySnapshotBackUp(lastId, policyId)) {
} else {
s_logger.debug("Destroying snapshot backup failed " + lastSnapshot);
break;
}
}
postDeleteSnapshot(userId, lastId, policyId);
postDeleteSnapshot(lastId, policyId);
lastId = lastSnapshot.getPrevSnapshotId();
if (lastId == 0) {
break;
@ -723,7 +710,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
}
@Override @DB
public boolean destroySnapshotBackUp(long userId, long snapshotId, long policyId) {
public boolean destroySnapshotBackUp(long snapshotId, long policyId) {
boolean success = false;
String details = null;
SnapshotVO snapshot = _snapshotDao.findByIdIncludingRemoved(snapshotId);
@ -762,18 +749,6 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
s_logger.error(details);
}
// create the event
String eventParams = "id=" + snapshotId;
EventVO event = new EventVO();
event.setUserId(userId);
event.setAccountId((snapshot != null) ? snapshot.getAccountId() : 0);
event.setType(EventTypes.EVENT_SNAPSHOT_DELETE);
event.setDescription(details);
event.setParameters(eventParams);
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);
@ -785,7 +760,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
}
@DB
protected void postDeleteSnapshot(long userId, long snapshotId, long policyId) {
protected void postDeleteSnapshot(long snapshotId, long policyId) {
// Remove the snapshot from the snapshots table and the snap_policy_ref table.
Transaction txn = Transaction.currentTxn();
txn.start();
@ -957,15 +932,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
_accountMgr.decrementResourceCount(accountId, ResourceType.snapshot);
//Log event after successful deletion
String eventParams = "id=" + snapshot.getId();
EventVO event = new EventVO();
event.setUserId(1L);
event.setAccountId(snapshot.getAccountId());
event.setType(EventTypes.EVENT_SNAPSHOT_DELETE);
event.setDescription("Successfully deleted snapshot " + snapshot.getId() + " for volumeId: " + snapshot.getVolumeId());
event.setParameters(eventParams);
event.setLevel(EventVO.LEVEL_INFO);
_eventDao.persist(event);
EventUtils.saveEvent(User.UID_SYSTEM, snapshot.getAccountId(), EventTypes.EVENT_SNAPSHOT_DELETE, "Successfully deleted snapshot " + snapshot.getId() + " for volumeId: " + snapshot.getVolumeId());
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_SNAPSHOT_DELETE, snapshot.getAccountId(), volume.getDataCenterId(), snapshot.getId(), snapshot.getName(), null, null, volume.getSize());
_usageEventDao.persist(usageEvent);
}

View File

@ -112,7 +112,7 @@ public interface AccountManager extends Manager {
void checkAccess(Account account, ControlledEntity... entities) throws PermissionDeniedException;
boolean deleteAccountInternal(long accountId, long startEventId);
boolean deleteAccountInternal(long accountId);
UserVO createUser(CreateUserCmd cmd);

View File

@ -751,7 +751,7 @@ public class AccountManagerImpl implements AccountManager, AccountService {
}
@Override
public boolean deleteAccountInternal(long accountId, long startEventId) {
public boolean deleteAccountInternal(long accountId) {
boolean result = false;
try {
@ -779,13 +779,6 @@ public class AccountManagerImpl implements AccountManager, AccountService {
} catch (Exception e) {
s_logger.error("exception deleting account: " + accountId, e);
return false;
}finally{
String description = "Account:" + accountId ;
if(result){
EventUtils.saveEvent(UserContext.current().getUserId(), accountId, EventVO.LEVEL_INFO, EventTypes.EVENT_ACCOUNT_DELETE, "Successfully deleted " +description, startEventId);
}else{
EventUtils.saveEvent(UserContext.current().getUserId(), accountId, EventVO.LEVEL_ERROR, EventTypes.EVENT_ACCOUNT_DELETE, "Error deleting " +description, startEventId);
}
}
}
@ -1356,7 +1349,7 @@ public class AccountManagerImpl implements AccountManager, AccountService {
return true;
}
return deleteAccountInternal(accountId, cmd.getStartEventId());
return deleteAccountInternal(accountId);
}
@ -1500,7 +1493,13 @@ public class AccountManagerImpl implements AccountManager, AccountService {
throw new InvalidParameterValueException("Account id : " + user.getAccountId() + " is a system account, delete for user associated with this account is not allowed");
}
return _userDao.remove(id);
boolean success = _userDao.remove(id);
if(success){
EventUtils.saveEvent(new Long(1), new Long(1), EventVO.LEVEL_INFO, EventTypes.EVENT_USER_DELETE, "Deleted User, " + user.getUsername() + " for accountId = " + user.getAccountId());
} else {
EventUtils.saveEvent(new Long(1), new Long(1), EventVO.LEVEL_ERROR, EventTypes.EVENT_USER_DELETE, "Failed to delete User, " + user.getUsername() + " for accountId = " + user.getAccountId());
}
return success;
}
}

View File

@ -712,11 +712,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
}
}
EventVO event = new EventVO();
event.setAccountId(volume.getAccountId());
event.setUserId(1L);
event.setType(EventTypes.EVENT_VOLUME_DETACH);
event.setState(Event.State.Completed);
if (!sendCommand || (answer != null && answer.getResult())) {
// Mark the volume as detached
_volsDao.detachVolume(volume.getId());
@ -725,14 +720,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
_volsDao.update(volume.getId(), volume);
}
if(!vm.getName().equals(vm.getDisplayName())) {
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getName()+"("+vm.getDisplayName()+")");
} else {
event.setDescription("Volume: " +volume.getName()+ " successfully detached from VM: "+vm.getName());
}
event.setLevel(EventVO.LEVEL_INFO);
_eventDao.persist(event);
return _volsDao.findById(volumeId);
} else {
@ -1002,13 +989,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
_ipAddressDao.unassignIpAddress(userVm.getGuestIpAddress());
s_logger.debug("Released guest IP address=" + userVm.getGuestIpAddress() + " vmName=" + userVm.getName() + " dcId=" + userVm.getDataCenterId());
EventVO event = new EventVO();
event.setUserId(User.UID_SYSTEM);
event.setAccountId(userVm.getAccountId());
event.setType(EventTypes.EVENT_NET_IP_RELEASE);
event.setParameters("guestIPaddress=" + userVm.getGuestIpAddress() + "\nvmName=" + userVm.getName() + "\ndcId=" + userVm.getDataCenterId());
event.setDescription("released a public ip: " + userVm.getGuestIpAddress());
_eventDao.persist(event);
EventUtils.saveEvent(User.UID_SYSTEM, userVm.getAccountId(), EventTypes.EVENT_NET_IP_RELEASE, "released a public ip: " + userVm.getGuestIpAddress());
} else {
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
String guestIp = userVm.getGuestIpAddress();
@ -1151,15 +1132,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
}
diskOfferingId = volume.getDiskOfferingId();
long sizeMB = volume.getSize()/(1024*1024);
String eventParams = "id=" + volume.getId() +"\ndoId="+diskOfferingId+"\ntId="+templateId+"\ndcId="+volume.getDataCenterId()+"\nsize="+sizeMB;
EventVO volEvent = new EventVO();
volEvent.setAccountId(volume.getAccountId());
volEvent.setUserId(1L);
volEvent.setType(EventTypes.EVENT_VOLUME_CREATE);
volEvent.setParameters(eventParams);
StoragePoolVO pool = _storagePoolDao.findById(volume.getPoolId());
volEvent.setDescription("Created volume: "+ volume.getName() +" with size: " + sizeMB + " MB in pool: " + pool.getName());
_eventDao.persist(volEvent);
EventUtils.saveEvent(User.UID_SYSTEM, volume.getAccountId(), EventTypes.EVENT_VOLUME_CREATE, "Created volume: "+ volume.getName() +" with size: " + sizeMB + " MB in pool: " + pool.getName());
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOfferingId, templateId , sizeMB);
_usageEventDao.persist(usageEvent);
}
_accountMgr.incrementResourceCount(account.getId(), ResourceType.volume, new Long(volumes.size()));