use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class ApiDBUtils method findJobInstanceUuid.
public static String findJobInstanceUuid(final AsyncJob job) {
if (job == null) {
return null;
}
String jobInstanceId = null;
final 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) {
final VolumeVO volume = ApiDBUtils.findVolumeById(job.getInstanceId());
if (volume != null) {
jobInstanceId = volume.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Template || jobInstanceType == ApiCommandJobType.Iso) {
final 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) {
final VMInstanceVO vm = ApiDBUtils.findVMInstanceById(job.getInstanceId());
if (vm != null) {
jobInstanceId = vm.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Snapshot) {
final Snapshot snapshot = ApiDBUtils.findSnapshotById(job.getInstanceId());
if (snapshot != null) {
jobInstanceId = snapshot.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Host) {
final Host host = ApiDBUtils.findHostById(job.getInstanceId());
if (host != null) {
jobInstanceId = host.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.StoragePool) {
final StoragePoolVO spool = ApiDBUtils.findStoragePoolById(job.getInstanceId());
if (spool != null) {
jobInstanceId = spool.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.IpAddress) {
final IPAddressVO ip = ApiDBUtils.findIpAddressById(job.getInstanceId());
if (ip != null) {
jobInstanceId = ip.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PhysicalNetwork) {
final PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(job.getInstanceId());
if (pnet != null) {
jobInstanceId = pnet.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.TrafficType) {
final PhysicalNetworkTrafficTypeVO trafficType = ApiDBUtils.findPhysicalNetworkTrafficTypeById(job.getInstanceId());
if (trafficType != null) {
jobInstanceId = trafficType.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PhysicalNetworkServiceProvider) {
final PhysicalNetworkServiceProvider sp = ApiDBUtils.findPhysicalNetworkServiceProviderById(job.getInstanceId());
if (sp != null) {
jobInstanceId = sp.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.FirewallRule) {
final FirewallRuleVO fw = ApiDBUtils.findFirewallRuleById(job.getInstanceId());
if (fw != null) {
jobInstanceId = fw.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Account) {
final Account acct = ApiDBUtils.findAccountById(job.getInstanceId());
if (acct != null) {
jobInstanceId = acct.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.User) {
final User usr = ApiDBUtils.findUserById(job.getInstanceId());
if (usr != null) {
jobInstanceId = usr.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.StaticRoute) {
final StaticRouteVO route = ApiDBUtils.findStaticRouteById(job.getInstanceId());
if (route != null) {
jobInstanceId = route.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PrivateGateway) {
final VpcGatewayVO gateway = ApiDBUtils.findVpcGatewayById(job.getInstanceId());
if (gateway != null) {
jobInstanceId = gateway.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Network) {
final 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 cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createTemplateResponses.
@Override
public List<TemplateResponse> createTemplateResponses(final ResponseView view, final long templateId, final Long snapshotId, final Long volumeId, final boolean readyOnly) {
Long zoneId = null;
if (snapshotId != null) {
final Snapshot snapshot = ApiDBUtils.findSnapshotById(snapshotId);
final VolumeVO volume = findVolumeById(snapshot.getVolumeId());
// if volume comes back null, use another technique to try to discover the zone
if (volume == null) {
final SnapshotDataStoreVO snapshotStore = _snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Primary);
if (snapshotStore != null) {
final long storagePoolId = snapshotStore.getDataStoreId();
final StoragePoolVO storagePool = _storagePoolDao.findById(storagePoolId);
if (storagePool != null) {
zoneId = storagePool.getDataCenterId();
}
}
} else {
zoneId = volume.getDataCenterId();
}
} else {
final 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-archive by CloudStack-extras.
the class ListSnapshotsCmd method execute.
@Override
public void execute() {
List<? extends Snapshot> result = _snapshotService.listSnapshots(this);
ListResponse<SnapshotResponse> response = new ListResponse<SnapshotResponse>();
List<SnapshotResponse> snapshotResponses = new ArrayList<SnapshotResponse>();
for (Snapshot snapshot : result) {
SnapshotResponse snapshotResponse = _responseGenerator.createSnapshotResponse(snapshot);
snapshotResponse.setObjectName("snapshot");
snapshotResponses.add(snapshotResponse);
}
response.setResponses(snapshotResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.storage.Snapshot in project CloudStack-archive by CloudStack-extras.
the class CreateTemplateCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
Long volumeId = getVolumeId();
Long snapshotId = getSnapshotId();
Long accountId = null;
if (volumeId != null) {
Volume volume = _entityMgr.findById(Volume.class, volumeId);
if (volume != null) {
accountId = volume.getAccountId();
} else {
throw new InvalidParameterValueException("Unable to find volume by id=" + volumeId);
}
} else {
Snapshot snapshot = _entityMgr.findById(Snapshot.class, snapshotId);
if (snapshot != null) {
accountId = snapshot.getAccountId();
} else {
throw new InvalidParameterValueException("Unable to find snapshot by id=" + snapshotId);
}
}
Account account = _accountService.getAccount(accountId);
//Can create templates for enabled projects/accounts only
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
Project project = _projectService.findByProjectAccountId(accountId);
if (project.getState() != Project.State.Active) {
PermissionDeniedException ex = new PermissionDeniedException("Can't add resources to the specified project id in state=" + project.getState() + " as it's no longer active");
ex.addProxyObject(project, project.getId(), "projectId");
}
} else if (account.getState() == Account.State.disabled) {
throw new PermissionDeniedException("The owner of template is disabled: " + account);
}
return accountId;
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class CreateVolumeCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Volume Id: " + getEntityId() + ((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
final Volume volume = _volumeService.createVolume(this);
if (volume != null) {
final VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume);
// FIXME - have to be moved to ApiResponseHelper
if (getSnapshotId() != null) {
final Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId());
if (snap != null) {
// if the volume was
response.setSnapshotId(snap.getUuid());
// created from a
// snapshot,
// snapshotId will
// be set so we pass
// it back in the
// response
}
}
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a volume");
}
}
Aggregations