本文整理了Java中com.cloud.storage.Volume.getUuid()
方法的一些代码示例,展示了Volume.getUuid()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Volume.getUuid()
方法的具体详情如下:
包路径:com.cloud.storage.Volume
类名称:Volume
方法名:getUuid
暂无
代码示例来源:origin: apache/cloudstack
public CheckVMActivityOnStoragePoolCommand(final Host host, final StoragePool pool, final List<Volume> volumeList, final DateTime suspectTime) {
this.host = new HostTO(host);
this.pool = new StorageFilerTO(pool);
this.suspectTimeSeconds = suspectTime.getMillis()/1000L;
final StringBuilder stringBuilder = new StringBuilder();
for (final Volume v : volumeList) {
stringBuilder.append(v.getUuid()).append(",");
}
this.volumeList = stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
}
代码示例来源:origin: apache/cloudstack
private void pubishOnEventBus(String event, String status, Volume vo, State oldState, State newState) {
String configKey = Config.PublishResourceStateEvent.key();
String value = _configDao.getValue(configKey);
boolean configValue = Boolean.parseBoolean(value);
if(!configValue)
return;
try {
s_eventBus = ComponentContext.getComponent(EventBus.class);
} catch (NoSuchBeanDefinitionException nbe) {
return; // no provider is configured to provide events bus, so just return
}
String resourceName = getEntityFromClassName(Volume.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 state change event on the the event bus.");
}
}
代码示例来源:origin: apache/cloudstack
/**
* We will add a mapping of volume to storage pool if needed. The conditions to add a mapping are the following:
* <ul>
* <li> The candidate storage pool where the volume is to be allocated can be accessed by the target host
* <li> If no storage pool is found to allocate the volume we throw an exception.
* </ul>
*
* Side note: this method should only be called if the volume is on local storage or if we are executing a cross cluster migration.
*/
protected void createVolumeToStoragePoolMappingIfPossible(VirtualMachineProfile profile, Host targetHost, Map<Volume, StoragePool> volumeToPoolObjectMap, Volume volume,
StoragePoolVO currentPool) {
List<StoragePool> storagePoolList = getCandidateStoragePoolsToMigrateLocalVolume(profile, targetHost, volume);
if (CollectionUtils.isEmpty(storagePoolList)) {
throw new CloudRuntimeException(String.format("There is not storage pools available at the target host [%s] to migrate volume [%s]", targetHost.getUuid(), volume.getUuid()));
}
Collections.shuffle(storagePoolList);
boolean canTargetHostAccessVolumeCurrentStoragePool = false;
for (StoragePool storagePool : storagePoolList) {
if (storagePool.getId() == currentPool.getId()) {
canTargetHostAccessVolumeCurrentStoragePool = true;
break;
}
}
if (!canTargetHostAccessVolumeCurrentStoragePool) {
volumeToPoolObjectMap.put(volume, _storagePoolDao.findByUuid(storagePoolList.get(0).getUuid()));
}
}
代码示例来源:origin: apache/cloudstack
@Override
public void create() throws ResourceAllocationException {
Volume volume = _volumeService.allocVolume(this);
if (volume != null) {
setEntityId(volume.getId());
setEntityUuid(volume.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create volume");
}
}
代码示例来源:origin: apache/cloudstack
public VmWorkMigrate(long userId, long accountId, long vmId, String handlerName,
long srcHostId, DeployDestination dst) {
super(userId, accountId, vmId, handlerName);
this.srcHostId = srcHostId;
zoneId = dst.getDataCenter() != null ? dst.getDataCenter().getId() : null;
podId = dst.getPod() != null ? dst.getPod().getId() : null;
clusterId = dst.getCluster() != null ? dst.getCluster().getId() : null;
hostId = dst.getHost() != null ? dst.getHost().getId() : null;
if (dst.getStorageForDisks() != null) {
storage = new HashMap<String, String>(dst.getStorageForDisks().size());
for (Map.Entry<Volume, StoragePool> entry : dst.getStorageForDisks().entrySet()) {
storage.put(entry.getKey().getUuid(), entry.getValue().getUuid());
}
} else {
storage = null;
}
}
代码示例来源:origin: apache/cloudstack
private void saveUsageEvent(Volume volume, Boolean displayVolume) {
// Update only when the flag has changed && only when volume in a non-destroyed state.
if ((displayVolume != null && displayVolume != volume.isDisplayVolume()) && !isVolumeDestroyed(volume)) {
if (displayVolume) {
// flag turned 1 equivalent to freshly created volume
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), volume.getDiskOfferingId(),
volume.getTemplateId(), volume.getSize(), Volume.class.getName(), volume.getUuid());
} else {
// flag turned 0 equivalent to deleting a volume
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), Volume.class.getName(),
volume.getUuid());
}
}
}
代码示例来源:origin: apache/cloudstack
/**
* Executes the managed storage checks for the volumes that the user has not entered a mapping of <volume, storage pool>. The following checks are performed.
* <ul>
* <li> If the current storage pool is not a managed storage, we do not need to proceed with this method;
* <li> We check if the target host has access to the current managed storage pool. If it does not have an exception will be thrown.
* </ul>
*/
protected void executeManagedStorageChecksWhenTargetStoragePoolNotProvided(Host targetHost, StoragePoolVO currentPool, Volume volume) {
if (!currentPool.isManaged()) {
return;
}
if (_poolHostDao.findByPoolHost(currentPool.getId(), targetHost.getId()) == null) {
throw new CloudRuntimeException(String.format("The target host does not have access to the volume's managed storage pool. [volumeId=%s, storageId=%s, targetHostId=%s].", volume.getUuid(),
currentPool.getUuid(), targetHost.getUuid()));
}
}
代码示例来源:origin: apache/cloudstack
@Override
public void destroyVolume(Volume volume) {
try {
// Mark volume as removed if volume has not been created on primary
if (volume.getState() == Volume.State.Allocated) {
_volsDao.remove(volume.getId());
stateTransitTo(volume, Volume.Event.DestroyRequested);
} else {
volService.destroyVolume(volume.getId());
}
// FIXME - All this is boiler plate code and should be done as part of state transition. This shouldn't be part of orchestrator.
// publish usage event for the volume
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), Volume.class.getName(),
volume.getUuid(), volume.isDisplayVolume());
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume, volume.isDisplay());
_resourceLimitMgr.decrementResourceCount(volume.getAccountId(), ResourceType.primary_storage, volume.isDisplay(), new Long(volume.getSize()));
} catch (Exception e) {
s_logger.debug("Failed to destroy volume" + volume.getId(), e);
throw new CloudRuntimeException("Failed to destroy volume" + volume.getId(), e);
}
}
代码示例来源:origin: apache/cloudstack
@Override
public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, Volume vol, boolean status, Object opaque) {
pubishOnEventBus(transition.getEvent().name(), "postStateTransitionEvent", vol, transition.getCurrentState(), transition.getToState());
if(transition.isImpacted(StateMachine2.Transition.Impact.USAGE)) {
Long instanceId = vol.getInstanceId();
VMInstanceVO vmInstanceVO = null;
if(instanceId != null) {
vmInstanceVO = _vmInstanceDao.findById(instanceId);
}
if(instanceId == null || vmInstanceVO.getType() == VirtualMachine.Type.User) {
if (transition.getToState() == State.Ready) {
if (transition.getCurrentState() == State.Resizing) {
// Log usage event for volumes belonging user VM's only
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(),
vol.getDiskOfferingId(), vol.getTemplateId(), vol.getSize(), Volume.class.getName(), vol.getUuid());
} else {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), vol.getDiskOfferingId(), null, vol.getSize(),
Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
}
} else if (transition.getToState() == State.Destroy && vol.getVolumeType() != Volume.Type.ROOT) { //Do not Publish Usage Event for ROOT Disk as it would have been published already while destroying a VM
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(),
Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
} else if (transition.getToState() == State.Uploaded) {
//Currently we are not capturing Usage for Secondary Storage so Usage for this operation will be captured when it is moved to primary storage
}
}
}
return true;
}
代码示例来源:origin: apache/cloudstack
@Override
public SnapshotScheduleResponse createSnapshotScheduleResponse(SnapshotSchedule snapshotSchedule) {
SnapshotScheduleResponse response = new SnapshotScheduleResponse();
response.setId(snapshotSchedule.getUuid());
if (snapshotSchedule.getVolumeId() != null) {
Volume vol = ApiDBUtils.findVolumeById(snapshotSchedule.getVolumeId());
if (vol != null) {
response.setVolumeId(vol.getUuid());
}
}
if (snapshotSchedule.getPolicyId() != null) {
SnapshotPolicy policy = ApiDBUtils.findSnapshotPolicyById(snapshotSchedule.getPolicyId());
if (policy != null) {
response.setSnapshotPolicyId(policy.getUuid());
}
}
response.setScheduled(snapshotSchedule.getScheduledTimestamp());
response.setObjectName("snapshot");
return response;
}
代码示例来源:origin: apache/cloudstack
@Override
public SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy) {
SnapshotPolicyResponse policyResponse = new SnapshotPolicyResponse();
policyResponse.setId(policy.getUuid());
Volume vol = ApiDBUtils.findVolumeById(policy.getVolumeId());
if (vol != null) {
policyResponse.setVolumeId(vol.getUuid());
}
policyResponse.setSchedule(policy.getSchedule());
policyResponse.setIntervalType(policy.getInterval());
policyResponse.setMaxSnaps(policy.getMaxSnaps());
policyResponse.setTimezone(policy.getTimezone());
policyResponse.setForDisplay(policy.isDisplay());
policyResponse.setObjectName("snapshotpolicy");
return policyResponse;
}
代码示例来源:origin: apache/cloudstack
volService.revokeAccess(volumeInfo, host, volumeInfo.getDataStore());
} else {
s_logger.warn("Unable to remove host-side clustered file system for the following volume: " + volume.getUuid());
代码示例来源:origin: apache/cloudstack
@Override
public void execute() {
CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getId()));
String uploadUrl = _volumeService.extractVolume(this);
if (uploadUrl != null) {
ExtractResponse response = new ExtractResponse();
response.setResponseName(getCommandName());
response.setObjectName("volume");
Volume vol = _entityMgr.findById(Volume.class, id);
response.setId(vol.getUuid());
response.setName(vol.getName());
DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
response.setZoneId(zone.getUuid());
response.setZoneName(zone.getName());
response.setMode(mode);
response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString());
Account account = _entityMgr.findById(Account.class, getEntityOwnerId());
response.setAccountId(account.getUuid());
response.setUrl(uploadUrl);
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to extract volume");
}
}
}
内容来源于网络,如有侵权,请联系作者删除!