use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class SnapshotManagerTest method testBackupSnapshotFromVmSnapshotF2.
// vm on KVM, first time
@Test
public void testBackupSnapshotFromVmSnapshotF2() {
when(_vmDao.findById(nullable(Long.class))).thenReturn(vmMock);
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
when(_vmSnapshotDao.findById(nullable(Long.class))).thenReturn(vmSnapshotMock);
when(snapshotStoreDao.findParent(any(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(null);
when(snapshotFactory.getSnapshot(nullable(Long.class), nullable(DataStore.class))).thenReturn(snapshotInfoMock);
when(storeMock.create(snapshotInfoMock)).thenReturn(snapshotInfoMock);
when(snapshotStoreDao.findByStoreSnapshot(nullable(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(snapshotStoreMock);
when(snapshotStoreDao.update(nullable(Long.class), nullable(SnapshotDataStoreVO.class))).thenReturn(true);
when(_snapshotDao.update(nullable(Long.class), nullable(SnapshotVO.class))).thenReturn(true);
when(vmMock.getAccountId()).thenReturn(2L);
when(snapshotStrategy.backupSnapshot(nullable(SnapshotInfo.class))).thenReturn(snapshotInfoMock);
Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);
Assert.assertNotNull(snapshot);
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class SnapshotManagerTest method testBackupSnapshotFromVmSnapshotF3.
// vm on KVM, already backed up
// (expected = InvalidParameterValueException.class)
@Test
public void testBackupSnapshotFromVmSnapshotF3() {
when(_vmDao.findById(nullable(Long.class))).thenReturn(vmMock);
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
when(_vmSnapshotDao.findById(nullable(Long.class))).thenReturn(vmSnapshotMock);
when(snapshotStoreDao.findParent(any(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(snapshotStoreMock);
when(snapshotStoreDao.findByStoreSnapshot(nullable(DataStoreRole.class), nullable(Long.class), nullable(Long.class))).thenReturn(snapshotStoreMock);
when(snapshotStoreMock.getInstallPath()).thenReturn("VM_SNAPSHOT_NAME");
when(vmSnapshotMock.getName()).thenReturn("VM_SNAPSHOT_NAME");
Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);
Assert.assertNull(snapshot);
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class ApiResponseHelper method createTemplateResponses.
@Override
public List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long snapshotId, Long volumeId, boolean readyOnly) {
Long zoneId = null;
if (snapshotId != null) {
Snapshot snapshot = ApiDBUtils.findSnapshotById(snapshotId);
VolumeVO volume = findVolumeById(snapshot.getVolumeId());
// if volume comes back null, use another technique to try to discover the zone
if (volume == null) {
SnapshotDataStoreVO snapshotStore = _snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
if (snapshotStore != null) {
long storagePoolId = snapshotStore.getDataStoreId();
StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
if (storagePool != null) {
zoneId = storagePool.getDataCenterId();
}
}
} else {
zoneId = volume.getDataCenterId();
}
} else {
VolumeVO volume = findVolumeById(volumeId);
zoneId = volume.getDataCenterId();
}
if (zoneId == null) {
throw new CloudRuntimeException("Unable to determine the zone ID");
}
return createTemplateResponses(view, templateId, zoneId, readyOnly);
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class ApiDBUtils method findJobInstanceUuid.
public static String findJobInstanceUuid(AsyncJob job) {
if (job == null) {
return null;
}
String jobInstanceId = null;
ApiCommandJobType jobInstanceType = EnumUtils.fromString(ApiCommandJobType.class, job.getInstanceType(), ApiCommandJobType.None);
if (job.getInstanceId() == null) {
// when assert is hit, implement 'getInstanceId' of BaseAsyncCmd and return appropriate instance id
assert (false);
return null;
}
if (jobInstanceType == ApiCommandJobType.Volume) {
VolumeVO volume = ApiDBUtils.findVolumeById(job.getInstanceId());
if (volume != null) {
jobInstanceId = volume.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Template || jobInstanceType == ApiCommandJobType.Iso) {
VMTemplateVO template = ApiDBUtils.findTemplateById(job.getInstanceId());
if (template != null) {
jobInstanceId = template.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.VirtualMachine || jobInstanceType == ApiCommandJobType.ConsoleProxy || jobInstanceType == ApiCommandJobType.SystemVm || jobInstanceType == ApiCommandJobType.DomainRouter) {
VMInstanceVO vm = ApiDBUtils.findVMInstanceById(job.getInstanceId());
if (vm != null) {
jobInstanceId = vm.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Snapshot) {
Snapshot snapshot = ApiDBUtils.findSnapshotById(job.getInstanceId());
if (snapshot != null) {
jobInstanceId = snapshot.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Host) {
Host host = ApiDBUtils.findHostById(job.getInstanceId());
if (host != null) {
jobInstanceId = host.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.StoragePool) {
StoragePoolVO spool = ApiDBUtils.findStoragePoolById(job.getInstanceId());
if (spool != null) {
jobInstanceId = spool.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.IpAddress) {
IPAddressVO ip = ApiDBUtils.findIpAddressById(job.getInstanceId());
if (ip != null) {
jobInstanceId = ip.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.SecurityGroup) {
SecurityGroup sg = ApiDBUtils.findSecurityGroupById(job.getInstanceId());
if (sg != null) {
jobInstanceId = sg.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PhysicalNetwork) {
PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(job.getInstanceId());
if (pnet != null) {
jobInstanceId = pnet.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.TrafficType) {
PhysicalNetworkTrafficTypeVO trafficType = ApiDBUtils.findPhysicalNetworkTrafficTypeById(job.getInstanceId());
if (trafficType != null) {
jobInstanceId = trafficType.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PhysicalNetworkServiceProvider) {
PhysicalNetworkServiceProvider sp = ApiDBUtils.findPhysicalNetworkServiceProviderById(job.getInstanceId());
if (sp != null) {
jobInstanceId = sp.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.FirewallRule) {
FirewallRuleVO fw = ApiDBUtils.findFirewallRuleById(job.getInstanceId());
if (fw != null) {
jobInstanceId = fw.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Account) {
Account acct = ApiDBUtils.findAccountById(job.getInstanceId());
if (acct != null) {
jobInstanceId = acct.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.User) {
User usr = ApiDBUtils.findUserById(job.getInstanceId());
if (usr != null) {
jobInstanceId = usr.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.StaticRoute) {
StaticRouteVO route = ApiDBUtils.findStaticRouteById(job.getInstanceId());
if (route != null) {
jobInstanceId = route.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PrivateGateway) {
VpcGatewayVO gateway = ApiDBUtils.findVpcGatewayById(job.getInstanceId());
if (gateway != null) {
jobInstanceId = gateway.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Counter) {
CounterVO counter = ApiDBUtils.getCounter(job.getInstanceId());
if (counter != null) {
jobInstanceId = counter.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Condition) {
ConditionVO condition = ApiDBUtils.findConditionById(job.getInstanceId());
if (condition != null) {
jobInstanceId = condition.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.AutoScalePolicy) {
AutoScalePolicyVO policy = ApiDBUtils.findAutoScalePolicyById(job.getInstanceId());
if (policy != null) {
jobInstanceId = policy.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.AutoScaleVmProfile) {
AutoScaleVmProfileVO profile = ApiDBUtils.findAutoScaleVmProfileById(job.getInstanceId());
if (profile != null) {
jobInstanceId = profile.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.AutoScaleVmGroup) {
AutoScaleVmGroupVO group = ApiDBUtils.findAutoScaleVmGroupById(job.getInstanceId());
if (group != null) {
jobInstanceId = group.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Network) {
NetworkVO networkVO = ApiDBUtils.findNetworkById(job.getInstanceId());
if (networkVO != null) {
jobInstanceId = networkVO.getUuid();
}
} else if (jobInstanceType != ApiCommandJobType.None) {
// entity table mapping
assert (false);
}
return jobInstanceId;
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class SnapshotStateListener method pubishOnEventBus.
private void pubishOnEventBus(String event, String status, Snapshot vo, State oldState, State newState) {
String configKey = Config.PublishResourceStateEvent.key();
String value = s_configDao.getValue(configKey);
boolean configValue = Boolean.parseBoolean(value);
if (!configValue) {
return;
}
try {
s_eventBus = ComponentContext.getComponent(EventBus.class);
} catch (NoSuchBeanDefinitionException nbe) {
// no provider is configured to provide events bus, so just return
return;
}
String resourceName = getEntityFromClassName(Snapshot.class.getName());
org.apache.cloudstack.framework.events.Event eventMsg = new org.apache.cloudstack.framework.events.Event(ManagementService.Name, EventCategory.RESOURCE_STATE_CHANGE_EVENT.getName(), event, resourceName, vo.getUuid());
Map<String, String> eventDescription = new HashMap<String, String>();
eventDescription.put("resource", resourceName);
eventDescription.put("id", vo.getUuid());
eventDescription.put("old-state", oldState.name());
eventDescription.put("new-state", newState.name());
String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
eventDescription.put("eventDateTime", eventDate);
eventMsg.setDescription(eventDescription);
try {
s_eventBus.publish(eventMsg);
} catch (EventBusException e) {
s_logger.warn("Failed to publish state change event on the the event bus.");
}
}
Aggregations