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) { return; // no provider is configured to provide events bus, so just 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."); } }
@Override public void create() throws ResourceAllocationException { Snapshot snapshot = this._volumeService.allocSnapshotForVm(getVmId(), getVolumeId(), getSnapshotName()); if (snapshot != null) { this.setEntityId(snapshot.getId()); this.setEntityUuid(snapshot.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot from vm snapshot"); } }
@Override public void create() throws ResourceAllocationException { Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName(), getLocationType()); if (snapshot != null) { setEntityId(snapshot.getId()); setEntityUuid(snapshot.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot"); } }
@Override public void execute() { CallContext.current().setEventDetails("Volume Id: " + getEntityUuid() + ((getSnapshotId() == null) ? "" : " from snapshot: " + this._uuidMgr.getUuid(Snapshot.class, getSnapshotId()))); Volume volume = _volumeService.createVolume(this); if (volume != null) { VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume); //FIXME - have to be moved to ApiResponseHelper if (getSnapshotId() != null) { Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId()); if (snap != null) { response.setSnapshotId(snap.getUuid()); // if the volume was // 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"); } } }
@Override public void execute(){ CallContext.current().setEventDetails("Volume Id: "+ getEntityUuid() + ((getSnapshotId() == null) ? "" : " from snapshot: " + this._uuidMgr.getUuid(Snapshot.class, getSnapshotId()))); Volume volume = _volumeService.createVolume(this); if (volume != null) { VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume); //FIXME - have to be moved to ApiResponseHelper if (getSnapshotId() != null) { Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId()); if (snap != null) { response.setSnapshotId(snap.getUuid()); // if the volume was // 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"); } } }
@Override public SnapshotResponse createSnapshotResponse(Snapshot snapshot) { SnapshotResponse snapshotResponse = new SnapshotResponse(); snapshotResponse.setId(snapshot.getUuid()); s_logger.debug("Unable to find info for image store snapshot with uuid " + snapshot.getUuid()); snapshotResponse.setRevertable(false); } else {
@Override public void create() throws ResourceAllocationException { final Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName()); if (snapshot != null) { setEntityId(snapshot.getId()); setEntityUuid(snapshot.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot"); } }
@Override public void create() throws ResourceAllocationException { final Snapshot snapshot = this._volumeService.allocSnapshotForVm(getVmId(), getVolumeId(), getSnapshotName()); if (snapshot != null) { this.setEntityId(snapshot.getId()); this.setEntityUuid(snapshot.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot from vm snapshot"); } }
Snapshot snapshot = ApiDBUtils.findSnapshotById(job.getInstanceId()); if (snapshot != null) { jobInstanceId = snapshot.getUuid();
@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.Full, volume); //FIXME - have to be moved to ApiResponseHelper if (getSnapshotId() != null) { final Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId()); if (snap != null) { response.setSnapshotId(snap.getUuid()); // if the volume was // 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"); } } }
@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) { response.setSnapshotId(snap.getUuid()); // if the volume was // 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"); } }