Merge branch 'master' into fix-improve-code-quality

# Conflicts:
#	hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadStatusInfoWindow.java

Signed-off-by: Dominic Schabel <dominic.schabel@bosch-si.com>
This commit is contained in:
Dominic Schabel
2016-08-19 11:24:24 +02:00
5 changed files with 88 additions and 52 deletions

View File

@@ -41,6 +41,7 @@ import org.eclipse.hawkbit.repository.RepositoryConstants;
import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.TenantNotExistException; 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;
import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionStatus;
@@ -153,8 +154,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
return handleAuthentifiactionMessage(message); return handleAuthentifiactionMessage(message);
} catch (final IllegalArgumentException ex) { } catch (final IllegalArgumentException ex) {
throw new AmqpRejectAndDontRequeueException("Invalid message!", ex); throw new AmqpRejectAndDontRequeueException("Invalid message!", ex);
} catch (final TenantNotExistException teex) { } catch (final TenantNotExistException | ToManyStatusEntriesException e) {
throw new AmqpRejectAndDontRequeueException(teex); throw new AmqpRejectAndDontRequeueException(e);
} finally { } finally {
SecurityContextHolder.setContext(oldContext); SecurityContextHolder.setContext(oldContext);
} }

View File

@@ -7,6 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
*/ */
package org.eclipse.hawkbit.ui.artifacts.event; package org.eclipse.hawkbit.ui.artifacts.event;
/** /**
* *
* Holds the upload file status. * Holds the upload file status.
@@ -14,24 +15,36 @@ package org.eclipse.hawkbit.ui.artifacts.event;
*/ */
public class UploadStatusEvent { 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 { 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; 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.uploadProgressEventType = eventType;
this.uploadStatus = entity; this.uploadStatus = uploadStatus;
} }
public UploadFileStatus getUploadStatus() { public UploadFileStatus getUploadStatus() {
return uploadStatus; return uploadStatus;
} }
public void setUploadStatus(UploadFileStatus uploadStatus) { public void setUploadStatus(final UploadFileStatus uploadStatus) {
this.uploadStatus = uploadStatus; this.uploadStatus = uploadStatus;
} }

View File

@@ -71,10 +71,10 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
private transient EventBus.SessionEventBus eventBus; private transient EventBus.SessionEventBus eventBus;
private final SoftwareModule selectedSw; private final SoftwareModule selectedSw;
private SoftwareModule selectedSwForUpload; private SoftwareModule selectedSwForUpload;
private ArtifactUploadState artifactUploadState; private final ArtifactUploadState artifactUploadState;
UploadHandler(final String fileName, final long fileSize, final UploadLayout view, final long maxSize, 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(); super();
this.aborted = false; this.aborted = false;
this.fileName = fileName; this.fileName = fileName;
@@ -142,7 +142,11 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
try { try {
if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName, selectedSwForUpload)) { if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName, selectedSwForUpload)) {
view.increaseNumberOfFileUploadsExpected(); 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) { } catch (final ArtifactUploadFailedException e) {
LOG.error("Atifact upload failed {} ", e); LOG.error("Atifact upload failed {} ", e);
@@ -163,8 +167,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
@Override @Override
public void uploadSucceeded(final SucceededEvent event) { public void uploadSucceeded(final SucceededEvent event) {
LOG.debug("Streaming finished for file :{}", event.getFilename()); LOG.debug("Streaming finished for file :{}", event.getFilename());
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_SUCCESSFUL, new UploadFileStatus( eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_SUCCESSFUL,
event.getFilename(), 0, event.getLength(), selectedSwForUpload))); new UploadFileStatus(event.getFilename(), 0, event.getLength(), selectedSwForUpload)));
} }
/** /**
@@ -190,8 +194,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
@Override @Override
public void uploadFinished(final FinishedEvent event) { public void uploadFinished(final FinishedEvent event) {
LOG.debug("Upload finished for file :{}", event.getFilename()); LOG.debug("Upload finished for file :{}", event.getFilename());
eventBus.publish(this, eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FINISHED,
new UploadStatusEvent(UploadStatusEventType.UPLOAD_FINISHED, new UploadFileStatus(event.getFilename()))); new UploadFileStatus(event.getFilename())));
} }
/** /**
@@ -202,8 +206,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
@Override @Override
public void streamingStarted(final StreamingStartEvent event) { public void streamingStarted(final StreamingStartEvent event) {
LOG.debug("Streaming started for file :{}", fileName); LOG.debug("Streaming started for file :{}", fileName);
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED,
fileName, 0, 0, selectedSw))); new UploadFileStatus(fileName, 0, 0, selectedSw)));
} }
/** /**
@@ -214,8 +218,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
@Override @Override
public void uploadStarted(final StartedEvent event) { public void uploadStarted(final StartedEvent event) {
uploadInterrupted = false; uploadInterrupted = false;
selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().isPresent() ? artifactUploadState selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().isPresent()
.getSelectedBaseSoftwareModule().get() : null; ? artifactUploadState.getSelectedBaseSoftwareModule().get() : null;
if (view.isSoftwareModuleSelected()) { if (view.isSoftwareModuleSelected()) {
// single file session // single file session
@@ -223,9 +227,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
LOG.debug("Upload started for file :{}", event.getFilename()); LOG.debug("Upload started for file :{}", event.getFilename());
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED,
new UploadFileStatus(event.getFilename(), 0, 0, selectedSwForUpload))); new UploadFileStatus(event.getFilename(), 0, 0, selectedSwForUpload)));
} }
} } else {
else {
failureReason = i18n.get("message.upload.failed"); failureReason = i18n.get("message.upload.failed");
upload.interruptUpload(); upload.interruptUpload();
// actual interrupt will happen a bit late so setting the below // actual interrupt will happen a bit late so setting the below
@@ -291,8 +294,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
interruptFileStreaming(); interruptFileStreaming();
return; return;
} }
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus( eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS,
fileName, event.getBytesReceived(), event.getContentLength(), selectedSw))); new UploadFileStatus(fileName, event.getBytesReceived(), event.getContentLength(), selectedSw)));
// Logging to solve sonar issue // Logging to solve sonar issue
LOG.trace("Streaming in progress for file :{}", event.getFileName()); LOG.trace("Streaming in progress for file :{}", event.getFileName());
} }
@@ -332,8 +335,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
if (failureReason == null) { if (failureReason == null) {
failureReason = event.getReason().getMessage(); failureReason = event.getReason().getMessage();
} }
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED,
fileName, failureReason, selectedSwForUpload))); new UploadFileStatus(fileName, failureReason, selectedSwForUpload)));
if (!aborted) { if (!aborted) {
LOG.info("Upload failed for file :{}", event.getFilename()); LOG.info("Upload failed for file :{}", event.getFilename());
LOG.info("Upload failed for file :{}", event.getReason()); LOG.info("Upload failed for file :{}", event.getReason());

View File

@@ -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;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType; import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType;
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; 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;
import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType;
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; 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) { private void processFile(final Html5File file, final SoftwareModule selectedSw) {
if (!isDirectory(file)) { if (!isDirectory(file)) {
if (!checkForDuplicate(file.getFileName(), selectedSw)) { if (!checkForDuplicate(file.getFileName(), selectedSw)) {
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.RECEIVE_UPLOAD,
new UploadFileStatus(file.getFileName(), 0, -1, selectedSw)));
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
file.setStreamVariable(createStreamVariable(file, selectedSw)); file.setStreamVariable(createStreamVariable(file, selectedSw));
} }

View File

@@ -16,6 +16,7 @@ import javax.annotation.PreDestroy;
import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent; 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;
import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType;
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
@@ -56,11 +57,7 @@ import elemental.json.JsonValue;
/** /**
* Shows upload status during upload. * Shows upload status during upload.
*
*
*
*/ */
@ViewScope @ViewScope
@SpringComponent @SpringComponent
public class UploadStatusInfoWindow extends Window { public class UploadStatusInfoWindow extends Window {
@@ -135,22 +132,32 @@ public class UploadStatusInfoWindow extends Window {
@EventBusListenerMethod(scope = EventScope.SESSION) @EventBusListenerMethod(scope = EventScope.SESSION)
void onEvent(final UploadStatusEvent event) { void onEvent(final UploadStatusEvent event) {
if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_IN_PROGRESS) {
UI.getCurrent() final UploadFileStatus uploadStatus = event.getUploadStatus();
.access(() -> updateProgress(event.getUploadStatus().getFileName(), switch (event.getUploadProgressEventType()) {
event.getUploadStatus().getBytesRead(), event.getUploadStatus().getContentLength(), case UPLOAD_IN_PROGRESS:
event.getUploadStatus().getSoftwareModule())); ui.access(() -> updateProgress(uploadStatus.getFileName(), uploadStatus.getBytesRead(),
} else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STARTED) { uploadStatus.getContentLength(), uploadStatus.getSoftwareModule()));
UI.getCurrent().access(() -> onStartOfUpload(event)); break;
} else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FAILED) { case UPLOAD_STARTED:
ui.access(() -> uploadFailed(event.getUploadStatus().getFileName(), ui.access(() -> onStartOfUpload(event));
event.getUploadStatus().getFailureReason(), event.getUploadStatus().getSoftwareModule())); break;
} else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_SUCCESSFUL) { case UPLOAD_STREAMING_FAILED:
UI.getCurrent().access(() -> uploadSucceeded(event.getUploadStatus().getFileName(), ui.access(() -> uploadFailed(uploadStatus.getFileName(), uploadStatus.getFailureReason(),
event.getUploadStatus().getSoftwareModule())); uploadStatus.getSoftwareModule()));
} else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FINISHED) { break;
ui.access(() -> uploadSucceeded(event.getUploadStatus().getFileName(), case UPLOAD_SUCCESSFUL:
event.getUploadStatus().getSoftwareModule())); // 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 final Item item = container
.addItem(getItemid(statusObject.getFilename(), statusObject.getSelectedSoftwareModule())); .addItem(getItemid(statusObject.getFilename(), statusObject.getSelectedSoftwareModule()));
item.getItemProperty(REASON).setValue(statusObject.getReason() != null ? statusObject.getReason() : ""); item.getItemProperty(REASON).setValue(statusObject.getReason() != null ? statusObject.getReason() : "");
item.getItemProperty(STATUS).setValue(statusObject.getStatus()); if (statusObject.getStatus() != null) {
item.getItemProperty(PROGRESS).setValue(statusObject.getProgress()); item.getItemProperty(STATUS).setValue(statusObject.getStatus());
}
if (statusObject.getProgress() != null) {
item.getItemProperty(PROGRESS).setValue(statusObject.getProgress());
}
item.getItemProperty(FILE_NAME).setValue(statusObject.getFilename()); item.getItemProperty(FILE_NAME).setValue(statusObject.getFilename());
final SoftwareModule sw = statusObject.getSelectedSoftwareModule(); final SoftwareModule sw = statusObject.getSelectedSoftwareModule();
item.getItemProperty(SPUILabelDefinitions.NAME_VERSION) item.getItemProperty(SPUILabelDefinitions.NAME_VERSION)
@@ -321,17 +332,20 @@ public class UploadStatusInfoWindow extends Window {
restoreState(); 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)); final Item item = uploads.addItem(getItemid(filename, softwareModule));
if (item != null) { if (item != null) {
item.getItemProperty(FILE_NAME).setValue(filename); item.getItemProperty(FILE_NAME).setValue(filename);
item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue( item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(
HawkbitCommonUtil.getFormattedNameVersion(softwareModule.getName(), softwareModule.getVersion())); 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"); void uploadStarted(final String filename, final SoftwareModule softwareModule) {
artifactUploadState.getUploadedFileStatusList().add(uploadStatus); grid.scrollTo(getItemid(filename, softwareModule));
} }
void updateProgress(final String filename, final long readBytes, final long contentLength, void updateProgress(final String filename, final long readBytes, final long contentLength,