use of org.ovirt.engine.core.common.businessentities.storage.ImageTransfer in project ovirt-engine by oVirt.
the class TransferImageCommand method updateEntityPhase.
protected void updateEntityPhase(ImageTransferPhase phase) {
ImageTransfer updates = new ImageTransfer(getCommandId());
updates.setPhase(phase);
updateEntity(updates);
}
use of org.ovirt.engine.core.common.businessentities.storage.ImageTransfer in project ovirt-engine by oVirt.
the class TransferImageStatusCommand method executeCommand.
@Override
protected void executeCommand() {
if (getParameters().getTransferImageCommandId() == null && getParameters().getDiskId() == null) {
log.error("Invalid parameters: command or disk id must be specified");
setSucceeded(false);
}
ImageTransfer entity;
if (getParameters().getTransferImageCommandId() != null) {
entity = imageTransferDao.get(getParameters().getTransferImageCommandId());
} else {
entity = imageTransferDao.getByDiskId(getParameters().getDiskId());
}
if (entity != null) {
// Always update; this serves as a keepalive
entity = imageTransferUpdater.updateEntity(getParameters().getUpdates(), entity.getId(), false);
} else {
// with phase "UNKNOWN" and the UI will know what to do.
if (getParameters().getTransferImageCommandId() != null) {
log.info("TransferImageStatus request for missing or removed entity, command id {}", getParameters().getTransferImageCommandId());
} else {
log.info("TransferImageStatus request for missing or removed entity, disk id {}", getParameters().getDiskId());
}
entity = new ImageTransfer();
entity.setId(getParameters().getTransferImageCommandId());
entity.setPhase(ImageTransferPhase.UNKNOWN);
entity.setType(TransferType.Unknown);
entity.setActive(false);
}
setSucceeded(true);
getReturnValue().setActionReturnValue(entity);
}
use of org.ovirt.engine.core.common.businessentities.storage.ImageTransfer in project ovirt-engine by oVirt.
the class ImageTransferUpdater method updateEntity.
public ImageTransfer updateEntity(ImageTransfer updates, Guid commandId, boolean clearResourceId) {
// TODO this lock might not be enough; analyze possible concurrent calls
EngineLock lock = getEntityUpdateLock(commandId);
try {
lockManager.acquireLockWait(lock);
ImageTransfer entity = imageTransferDao.get(commandId);
if (entity == null) {
log.error("Attempt to update non-existent ImageTransfer entity");
return null;
}
entity.setLastUpdated(new Date());
if (updates != null) {
if (updates.getId() != null) {
entity.setId(updates.getId());
}
if (updates.getPhase() != null) {
String disk = entity.getDiskId() != null ? String.format(" (image %s)", entity.getDiskId().toString()) : "";
String message = entity.getMessage() != null ? String.format(" (message: '%s')", entity.getMessage()) : "";
log.info("Updating image transfer {}{} phase to {}{}", commandId, disk, updates.getPhase(), message);
entity.setPhase(updates.getPhase());
}
if (updates.getType() != null) {
entity.setType(updates.getType());
}
if (updates.getActive() != null) {
entity.setActive(updates.getActive());
}
if (updates.getMessage() != null) {
entity.setMessage(updates.getMessage());
}
if (updates.getVdsId() != null) {
entity.setVdsId(updates.getVdsId());
}
if (updates.getDiskId() != null) {
entity.setDiskId(updates.getDiskId());
}
if (updates.getImagedTicketId() != null || clearResourceId) {
entity.setImagedTicketId(updates.getImagedTicketId());
}
if (updates.getProxyUri() != null) {
entity.setProxyUri(updates.getProxyUri());
}
if (updates.getDaemonUri() != null) {
entity.setDaemonUri(updates.getDaemonUri());
}
if (updates.getSignedTicket() != null) {
entity.setSignedTicket(updates.getSignedTicket());
}
if (updates.getBytesSent() != null) {
entity.setBytesSent(updates.getBytesSent());
}
if (updates.getBytesTotal() != null) {
entity.setBytesTotal(updates.getBytesTotal());
}
}
imageTransferDao.update(entity);
return entity;
} finally {
lockManager.releaseLock(lock);
}
}
use of org.ovirt.engine.core.common.businessentities.storage.ImageTransfer in project ovirt-engine by oVirt.
the class UploadImageHandler method initiateResumeUploadStartTransfer.
private void initiateResumeUploadStartTransfer(FrontendActionAsyncResult result) {
if (result.getReturnValue() != null && result.getReturnValue().getSucceeded()) {
ImageTransfer rv = result.getReturnValue().getActionReturnValue();
setCommandId(rv.getId());
setBytesSent(rv.getBytesSent());
setBytesEndOffset(rv.getBytesTotal());
startStatusPolling();
} else {
setProgressStr(messages.uploadImageFailedToResumeMessage(result.getReturnValue().getDescription()));
}
}
use of org.ovirt.engine.core.common.businessentities.storage.ImageTransfer in project ovirt-engine by oVirt.
the class UploadImageHandler method startStatusPolling.
private void startStatusPolling() {
setContinuePolling(true);
Scheduler.get().scheduleFixedDelay(() -> {
// $NON-NLS-1$
log.info("Polling for status");
TransferImageStatusParameters statusParameters = new TransferImageStatusParameters(getCommandId());
ImageTransfer updates = new ImageTransfer();
updateBytesSent(updates);
updates.setMessage(getProgressStr());
statusParameters.setUpdates(updates);
Frontend.getInstance().runAction(ActionType.TransferImageStatus, statusParameters, this::respondToPollStatus);
return isContinuePolling();
}, POLLING_DELAY_MS);
}
Aggregations