diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 8906bc96c..871a4973a 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -41,6 +41,7 @@ import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; +import org.eclipse.hawkbit.repository.exception.ToManyStatusEntriesException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -153,8 +154,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService { return handleAuthentifiactionMessage(message); } catch (final IllegalArgumentException ex) { throw new AmqpRejectAndDontRequeueException("Invalid message!", ex); - } catch (final TenantNotExistException teex) { - throw new AmqpRejectAndDontRequeueException(teex); + } catch (final TenantNotExistException | ToManyStatusEntriesException e) { + throw new AmqpRejectAndDontRequeueException(e); } finally { SecurityContextHolder.setContext(oldContext); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java index 3b4767c60..4a8d0a747 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java @@ -7,6 +7,7 @@ * http://www.eclipse.org/legal/epl-v10.html */ package org.eclipse.hawkbit.ui.artifacts.event; + /** * * Holds the upload file status. @@ -14,24 +15,36 @@ package org.eclipse.hawkbit.ui.artifacts.event; */ public class UploadStatusEvent { + /** + * Event type definition of events during the artifact upload life-cycle + * from receiving the upload until the process end. + */ public enum UploadStatusEventType { - UPLOAD_FAILED, UPLOAD_IN_PROGRESS, UPLOAD_STARTED, UPLOAD_FINISHED, UPLOAD_SUCCESSFUL, UPLOAD_STREAMING_FAILED, UPLOAD_STREAMING_FINISHED, ABORT_UPLOAD + RECEIVE_UPLOAD, UPLOAD_FAILED, UPLOAD_IN_PROGRESS, UPLOAD_STARTED, UPLOAD_FINISHED, UPLOAD_SUCCESSFUL, UPLOAD_STREAMING_FAILED, UPLOAD_STREAMING_FINISHED, ABORT_UPLOAD } - private UploadStatusEventType uploadProgressEventType; + private final UploadStatusEventType uploadProgressEventType; private UploadFileStatus uploadStatus; - public UploadStatusEvent(UploadStatusEventType eventType, UploadFileStatus entity) { + /** + * Constructor. + * + * @param eventType + * the type of the event + * @param uploadStatus + * the upload status of this event + */ + public UploadStatusEvent(final UploadStatusEventType eventType, final UploadFileStatus uploadStatus) { this.uploadProgressEventType = eventType; - this.uploadStatus = entity; + this.uploadStatus = uploadStatus; } public UploadFileStatus getUploadStatus() { return uploadStatus; } - public void setUploadStatus(UploadFileStatus uploadStatus) { + public void setUploadStatus(final UploadFileStatus uploadStatus) { this.uploadStatus = uploadStatus; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 78a6fd9a9..cd6d82194 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -71,10 +71,10 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene private transient EventBus.SessionEventBus eventBus; private final SoftwareModule selectedSw; private SoftwareModule selectedSwForUpload; - private ArtifactUploadState artifactUploadState; + private final ArtifactUploadState artifactUploadState; UploadHandler(final String fileName, final long fileSize, final UploadLayout view, final long maxSize, - final Upload upload, final String mimeType, SoftwareModule selectedSw) { + final Upload upload, final String mimeType, final SoftwareModule selectedSw) { super(); this.aborted = false; this.fileName = fileName; @@ -142,7 +142,11 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene try { if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName, selectedSwForUpload)) { view.increaseNumberOfFileUploadsExpected(); - return view.saveUploadedFileDetails(fileName, 0, mimeType, selectedSwForUpload); + final OutputStream saveUploadedFileDetails = view.saveUploadedFileDetails(fileName, 0, mimeType, + selectedSwForUpload); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.RECEIVE_UPLOAD, + new UploadFileStatus(fileName, 0, -1, selectedSwForUpload))); + return saveUploadedFileDetails; } } catch (final ArtifactUploadFailedException e) { LOG.error("Atifact upload failed {} ", e); @@ -163,8 +167,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void uploadSucceeded(final SucceededEvent event) { LOG.debug("Streaming finished for file :{}", event.getFilename()); - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_SUCCESSFUL, new UploadFileStatus( - event.getFilename(), 0, event.getLength(), selectedSwForUpload))); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_SUCCESSFUL, + new UploadFileStatus(event.getFilename(), 0, event.getLength(), selectedSwForUpload))); } /** @@ -190,8 +194,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void uploadFinished(final FinishedEvent event) { LOG.debug("Upload finished for file :{}", event.getFilename()); - eventBus.publish(this, - new UploadStatusEvent(UploadStatusEventType.UPLOAD_FINISHED, new UploadFileStatus(event.getFilename()))); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FINISHED, + new UploadFileStatus(event.getFilename()))); } /** @@ -202,8 +206,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void streamingStarted(final StreamingStartEvent event) { LOG.debug("Streaming started for file :{}", fileName); - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( - fileName, 0, 0, selectedSw))); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, + new UploadFileStatus(fileName, 0, 0, selectedSw))); } /** @@ -214,8 +218,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public void uploadStarted(final StartedEvent event) { uploadInterrupted = false; - selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().isPresent() ? artifactUploadState - .getSelectedBaseSoftwareModule().get() : null; + selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().isPresent() + ? artifactUploadState.getSelectedBaseSoftwareModule().get() : null; if (view.isSoftwareModuleSelected()) { // single file session @@ -223,9 +227,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene LOG.debug("Upload started for file :{}", event.getFilename()); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus(event.getFilename(), 0, 0, selectedSwForUpload))); - } - } - else { + } + } else { failureReason = i18n.get("message.upload.failed"); upload.interruptUpload(); // actual interrupt will happen a bit late so setting the below @@ -291,8 +294,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene interruptFileStreaming(); return; } - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus( - fileName, event.getBytesReceived(), event.getContentLength(), selectedSw))); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, + new UploadFileStatus(fileName, event.getBytesReceived(), event.getContentLength(), selectedSw))); // Logging to solve sonar issue LOG.trace("Streaming in progress for file :{}", event.getFileName()); } @@ -332,8 +335,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene if (failureReason == null) { failureReason = event.getReason().getMessage(); } - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( - fileName, failureReason, selectedSwForUpload))); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, + new UploadFileStatus(fileName, failureReason, selectedSwForUpload))); if (!aborted) { LOG.info("Upload failed for file :{}", event.getFilename()); LOG.info("Upload failed for file :{}", event.getReason()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index b1e8ebf45..d9996cc9a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -25,6 +25,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; +import org.eclipse.hawkbit.ui.artifacts.event.UploadFileStatus; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; @@ -273,6 +274,10 @@ public class UploadLayout extends VerticalLayout { private void processFile(final Html5File file, final SoftwareModule selectedSw) { if (!isDirectory(file)) { if (!checkForDuplicate(file.getFileName(), selectedSw)) { + + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.RECEIVE_UPLOAD, + new UploadFileStatus(file.getFileName(), 0, -1, selectedSw))); + artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); file.setStreamVariable(createStreamVariable(file, selectedSw)); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java index b2ca37269..9b7473e5a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java @@ -16,6 +16,7 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; +import org.eclipse.hawkbit.ui.artifacts.event.UploadFileStatus; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; @@ -56,11 +57,7 @@ import elemental.json.JsonValue; /** * Shows upload status during upload. - * - * - * */ - @ViewScope @SpringComponent public class UploadStatusInfoWindow extends Window { @@ -135,22 +132,32 @@ public class UploadStatusInfoWindow extends Window { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final UploadStatusEvent event) { - if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_IN_PROGRESS) { - UI.getCurrent() - .access(() -> updateProgress(event.getUploadStatus().getFileName(), - event.getUploadStatus().getBytesRead(), event.getUploadStatus().getContentLength(), - event.getUploadStatus().getSoftwareModule())); - } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STARTED) { - UI.getCurrent().access(() -> onStartOfUpload(event)); - } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FAILED) { - ui.access(() -> uploadFailed(event.getUploadStatus().getFileName(), - event.getUploadStatus().getFailureReason(), event.getUploadStatus().getSoftwareModule())); - } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_SUCCESSFUL) { - UI.getCurrent().access(() -> uploadSucceeded(event.getUploadStatus().getFileName(), - event.getUploadStatus().getSoftwareModule())); - } else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FINISHED) { - ui.access(() -> uploadSucceeded(event.getUploadStatus().getFileName(), - event.getUploadStatus().getSoftwareModule())); + + final UploadFileStatus uploadStatus = event.getUploadStatus(); + switch (event.getUploadProgressEventType()) { + case UPLOAD_IN_PROGRESS: + ui.access(() -> updateProgress(uploadStatus.getFileName(), uploadStatus.getBytesRead(), + uploadStatus.getContentLength(), uploadStatus.getSoftwareModule())); + break; + case UPLOAD_STARTED: + ui.access(() -> onStartOfUpload(event)); + break; + case UPLOAD_STREAMING_FAILED: + ui.access(() -> uploadFailed(uploadStatus.getFileName(), uploadStatus.getFailureReason(), + uploadStatus.getSoftwareModule())); + break; + case UPLOAD_SUCCESSFUL: + // fall through here + case UPLOAD_STREAMING_FINISHED: + ui.access(() -> uploadSucceeded(uploadStatus.getFileName(), uploadStatus.getSoftwareModule())); + break; + case RECEIVE_UPLOAD: + uploadRecevied(uploadStatus.getFileName(), uploadStatus.getSoftwareModule()); + break; + case UPLOAD_FINISHED: + case ABORT_UPLOAD: + case UPLOAD_FAILED: + default: } } @@ -176,8 +183,12 @@ public class UploadStatusInfoWindow extends Window { final Item item = container .addItem(getItemid(statusObject.getFilename(), statusObject.getSelectedSoftwareModule())); item.getItemProperty(REASON).setValue(statusObject.getReason() != null ? statusObject.getReason() : ""); - item.getItemProperty(STATUS).setValue(statusObject.getStatus()); - item.getItemProperty(PROGRESS).setValue(statusObject.getProgress()); + if (statusObject.getStatus() != null) { + item.getItemProperty(STATUS).setValue(statusObject.getStatus()); + } + if (statusObject.getProgress() != null) { + item.getItemProperty(PROGRESS).setValue(statusObject.getProgress()); + } item.getItemProperty(FILE_NAME).setValue(statusObject.getFilename()); final SoftwareModule sw = statusObject.getSelectedSoftwareModule(); item.getItemProperty(SPUILabelDefinitions.NAME_VERSION) @@ -321,17 +332,20 @@ public class UploadStatusInfoWindow extends Window { restoreState(); } - void uploadStarted(final String filename, final SoftwareModule softwareModule) { + private void uploadRecevied(final String filename, final SoftwareModule softwareModule) { final Item item = uploads.addItem(getItemid(filename, softwareModule)); if (item != null) { item.getItemProperty(FILE_NAME).setValue(filename); item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue( HawkbitCommonUtil.getFormattedNameVersion(softwareModule.getName(), softwareModule.getVersion())); + final UploadStatusObject uploadStatus = new UploadStatusObject(filename, softwareModule); + uploadStatus.setStatus("Active"); + artifactUploadState.getUploadedFileStatusList().add(uploadStatus); } - grid.scrollToEnd(); - final UploadStatusObject uploadStatus = new UploadStatusObject(filename, softwareModule); - uploadStatus.setStatus("Active"); - artifactUploadState.getUploadedFileStatusList().add(uploadStatus); + } + + void uploadStarted(final String filename, final SoftwareModule softwareModule) { + grid.scrollTo(getItemid(filename, softwareModule)); } void updateProgress(final String filename, final long readBytes, final long contentLength,