Fix bulk progress bar (#428)

* Fix progress par computation for bulk upload. Fixed sonar issues on the
way.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2017-02-08 08:57:05 +01:00
committed by GitHub
parent 1ad9b915c4
commit dce3263df3
14 changed files with 141 additions and 200 deletions

View File

@@ -18,15 +18,14 @@ _hawkBit_ is able to run in a cluster with some constraints. This guide provides
Event communication between nodes is based on [Spring Cloud Bus](https://cloud.spring.io/spring-cloud-bus/) and [Spring Cloud Stream](http://docs.spring.io/spring-cloud-stream/docs/current/reference/htmlsingle/). There are different [binder implementations](http://docs.spring.io/spring-cloud-stream/docs/current/reference/htmlsingle/#_binders) available. The _hawkbit example app_ uses RabbitMQ binder. Every node gets his own queue to receive cluster events, the default payload is JSON. Event communication between nodes is based on [Spring Cloud Bus](https://cloud.spring.io/spring-cloud-bus/) and [Spring Cloud Stream](http://docs.spring.io/spring-cloud-stream/docs/current/reference/htmlsingle/). There are different [binder implementations](http://docs.spring.io/spring-cloud-stream/docs/current/reference/htmlsingle/#_binders) available. The _hawkbit example app_ uses RabbitMQ binder. Every node gets his own queue to receive cluster events, the default payload is JSON.
If an event is thrown locally at one node, it will be automatically delivered to all other available nodes via the Spring Cloud Bus's topic exchange: If an event is thrown locally at one node, it will be automatically delivered to all other available nodes via the Spring Cloud Bus's topic exchange:
[[images/eventing-within-cluster.png]] ![](../images/eventing-within-cluster.png){:width="100%"}
Via the ServiceMatcher you can check whether an event happened locally at one node or on a different node. Via the ServiceMatcher you can check whether an event happened locally at one node or on a different node.
`serviceMatcher.isFromSelf(event)` `serviceMatcher.isFromSelf(event)`
# Caching # Caching
Every node is maintaining its own caches independent from other nodes. So there is no globally shared/synchronized cache instance within the cluster. In order to keep nodes in sync a TTL (time to live) can be set for all caches to ensure that after some time the cache is refreshed from the database. To enable the TTL just set the property "hawkbit.cache.global.ttl" (value in milliseconds). Every node is maintaining its own caches independent from other nodes. So there is no globally shared/synchronized cache instance within the cluster. In order to keep nodes in sync a TTL (time to live) can be set for all caches to ensure that after some time the cache is refreshed from the database. To enable the TTL just set the property "hawkbit.cache.global.ttl" (value in milliseconds). Of course you can implement a shared cache, e.g. Redis.
Of course you can implement a shared cache, e.g. Redis.
See [CacheAutoConfiguration](https://github.com/eclipse/hawkbit/blob/master/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java) See [CacheAutoConfiguration](https://github.com/eclipse/hawkbit/blob/master/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java)
# Schedulers # Schedulers

View File

@@ -213,12 +213,12 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
@Override @Override
protected void starting(final Description description) { protected void starting(final Description description) {
LOG.info("Starting Test {}...", description.getMethodName()); LOG.info("Starting Test {}...", description.getMethodName());
}; }
@Override @Override
protected void succeeded(final Description description) { protected void succeeded(final Description description) {
LOG.info("Test {} succeeded.", description.getMethodName()); LOG.info("Test {} succeeded.", description.getMethodName());
}; }
@Override @Override
protected void failed(final Throwable e, final Description description) { protected void failed(final Throwable e, final Description description) {

View File

@@ -172,7 +172,7 @@ public abstract class AbstractDeleteActionsLayout extends VerticalLayout impleme
showBulkUploadWindow(); showBulkUploadWindow();
} }
protected void setUploadStatusButtonCaption(final Long count) { protected void setUploadStatusButtonCaption(final int count) {
if (bulkUploadStatusButton == null) { if (bulkUploadStatusButton == null) {
return; return;
} }

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.ui.management; package org.eclipse.hawkbit.ui.management;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executor;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@@ -55,6 +56,7 @@ import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions;
import org.eclipse.hawkbit.ui.utils.UINotification; import org.eclipse.hawkbit.ui.utils.UINotification;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.vaadin.spring.events.EventBus.UIEventBus; import org.vaadin.spring.events.EventBus.UIEventBus;
import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod; import org.vaadin.spring.events.annotation.EventBusListenerMethod;
@@ -113,7 +115,7 @@ public class DeploymentView extends AbstractNotificationView implements BrowserW
final ManagementViewClientCriterion managementViewClientCriterion, final TagManagement tagManagement, final ManagementViewClientCriterion managementViewClientCriterion, final TagManagement tagManagement,
final TargetFilterQueryManagement targetFilterQueryManagement, final SystemManagement systemManagement, final TargetFilterQueryManagement targetFilterQueryManagement, final SystemManagement systemManagement,
final NotificationUnreadButton notificationUnreadButton, final NotificationUnreadButton notificationUnreadButton,
final DeploymentViewMenuItem deploymentViewMenuItem) { final DeploymentViewMenuItem deploymentViewMenuItem, @Qualifier("uiExecutor") final Executor uiExecutor) {
super(eventBus, notificationUnreadButton); super(eventBus, notificationUnreadButton);
this.permChecker = permChecker; this.permChecker = permChecker;
this.i18n = i18n; this.i18n = i18n;
@@ -132,7 +134,7 @@ public class DeploymentView extends AbstractNotificationView implements BrowserW
this.targetTableLayout = new TargetTableLayout(eventbus, targetTable, targetManagement, entityFactory, i18n, this.targetTableLayout = new TargetTableLayout(eventbus, targetTable, targetManagement, entityFactory, i18n,
eventBus, uiNotification, managementUIState, managementViewClientCriterion, deploymentManagement, eventBus, uiNotification, managementUIState, managementViewClientCriterion, deploymentManagement,
uiproperties, permChecker, uiNotification, tagManagement, distributionSetManagement); uiproperties, permChecker, uiNotification, tagManagement, distributionSetManagement, uiExecutor);
this.distributionTagLayout = new DistributionTagLayout(eventbus, managementUIState, i18n, permChecker, eventBus, this.distributionTagLayout = new DistributionTagLayout(eventbus, managementUIState, i18n, permChecker, eventBus,
tagManagement, entityFactory, uiNotification, distFilterParameters, distributionSetManagement, tagManagement, entityFactory, uiNotification, distFilterParameters, distributionSetManagement,

View File

@@ -509,7 +509,6 @@ public class ActionHistoryTable extends TreeTable {
final ActionStatusIconMapper mapping = ActionStatusIconMapper.MAPPINGS.get(status); final ActionStatusIconMapper mapping = ActionStatusIconMapper.MAPPINGS.get(status);
if (mapping == null) { if (mapping == null) {
LOG.error("Unknown status icon mapping");
label.setDescription(""); label.setDescription("");
label.setValue(""); label.setValue("");
return label; return label;

View File

@@ -22,7 +22,7 @@ import com.vaadin.server.FontAwesome;
* *
*/ */
public final class ActionStatusIconMapper { public final class ActionStatusIconMapper {
static final Map<Action.Status, ActionStatusIconMapper> MAPPINGS = Maps.newHashMapWithExpectedSize(10); static final Map<Action.Status, ActionStatusIconMapper> MAPPINGS = Maps.newEnumMap(Action.Status.class);
static { static {
MAPPINGS.put(Action.Status.FINISHED, new ActionStatusIconMapper("label.finished", MAPPINGS.put(Action.Status.FINISHED, new ActionStatusIconMapper("label.finished",

View File

@@ -403,8 +403,8 @@ public class DeleteActionsLayout extends AbstractDeleteActionsLayout {
@Override @Override
protected void restoreBulkUploadStatusCount() { protected void restoreBulkUploadStatusCount() {
final Long failedCount = managementUIState.getTargetTableFilters().getBulkUpload().getFailedUploadCount(); final int failedCount = managementUIState.getTargetTableFilters().getBulkUpload().getFailedUploadCount();
final Long successCount = managementUIState.getTargetTableFilters().getBulkUpload().getSucessfulUploadCount(); final int successCount = managementUIState.getTargetTableFilters().getBulkUpload().getSucessfulUploadCount();
if (failedCount != 0 || successCount != 0) { if (failedCount != 0 || successCount != 0) {
setUploadStatusButtonCaption(failedCount + successCount); setUploadStatusButtonCaption(failedCount + successCount);
enableBulkUploadStatusButton(); enableBulkUploadStatusButton();

View File

@@ -24,9 +24,9 @@ public class TargetBulkUpload implements Serializable {
private String description; private String description;
private long sucessfulUploadCount; private int sucessfulUploadCount;
private long failedUploadCount; private int failedUploadCount;
private float progressBarCurrentValue; private float progressBarCurrentValue;
@@ -96,7 +96,7 @@ public class TargetBulkUpload implements Serializable {
/** /**
* @return the sucessfulUploadCount * @return the sucessfulUploadCount
*/ */
public long getSucessfulUploadCount() { public int getSucessfulUploadCount() {
return sucessfulUploadCount; return sucessfulUploadCount;
} }
@@ -104,14 +104,14 @@ public class TargetBulkUpload implements Serializable {
* @param sucessfulUploadCount * @param sucessfulUploadCount
* the sucessfulUploadCount to set * the sucessfulUploadCount to set
*/ */
public void setSucessfulUploadCount(final long sucessfulUploadCount) { public void setSucessfulUploadCount(final int sucessfulUploadCount) {
this.sucessfulUploadCount = sucessfulUploadCount; this.sucessfulUploadCount = sucessfulUploadCount;
} }
/** /**
* @return the failedUploadCount * @return the failedUploadCount
*/ */
public long getFailedUploadCount() { public int getFailedUploadCount() {
return failedUploadCount; return failedUploadCount;
} }
@@ -119,7 +119,7 @@ public class TargetBulkUpload implements Serializable {
* @param failedUploadCount * @param failedUploadCount
* the failedUploadCount to set * the failedUploadCount to set
*/ */
public void setFailedUploadCount(final long failedUploadCount) { public void setFailedUploadCount(final int failedUploadCount) {
this.failedUploadCount = failedUploadCount; this.failedUploadCount = failedUploadCount;
} }

View File

@@ -8,7 +8,6 @@
*/ */
package org.eclipse.hawkbit.ui.management.targettable; package org.eclipse.hawkbit.ui.management.targettable;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@@ -16,7 +15,10 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@@ -29,9 +31,8 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
import org.eclipse.hawkbit.ui.common.tagdetails.AbstractTagToken.TagData; import org.eclipse.hawkbit.ui.common.tagdetails.AbstractTagToken.TagData;
import org.eclipse.hawkbit.ui.components.HawkbitErrorNotificationMessage; import org.eclipse.hawkbit.ui.components.HawkbitErrorNotificationMessage;
import org.eclipse.hawkbit.ui.management.event.BulkUploadValidationMessageEvent; import org.eclipse.hawkbit.ui.management.event.BulkUploadValidationMessageEvent;
@@ -42,11 +43,14 @@ import org.eclipse.hawkbit.ui.management.state.TargetBulkUpload;
import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil;
import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.I18N;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus;
import com.google.common.base.Splitter;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import com.google.common.io.LineProcessor;
import com.vaadin.server.Page; import com.vaadin.server.Page;
import com.vaadin.ui.Alignment; import com.vaadin.ui.Alignment;
import com.vaadin.ui.ComboBox; import com.vaadin.ui.ComboBox;
@@ -74,6 +78,8 @@ public class BulkUploadHandler extends CustomComponent
private static final long serialVersionUID = -1273494705754674501L; private static final long serialVersionUID = -1273494705754674501L;
private static final Logger LOG = LoggerFactory.getLogger(BulkUploadHandler.class); private static final Logger LOG = LoggerFactory.getLogger(BulkUploadHandler.class);
private static final Splitter SPLITTER = Splitter.on(',').omitEmptyStrings().trimResults();
private final transient TargetManagement targetManagement; private final transient TargetManagement targetManagement;
private final transient TagManagement tagManagement; private final transient TagManagement tagManagement;
@@ -91,18 +97,19 @@ public class BulkUploadHandler extends CustomComponent
private final TargetBulkTokenTags targetBulkTokenTags; private final TargetBulkTokenTags targetBulkTokenTags;
private final Label targetsCountLabel; private final Label targetsCountLabel;
private long failedTargetCount; private int successfullTargetCount;
private long successfullTargetCount;
private final transient Executor executor; private final transient Executor uiExecutor;
private final transient EventBus.UIEventBus eventBus; private final transient EventBus.UIEventBus eventBus;
private transient EntityFactory entityFactory; private final transient EntityFactory entityFactory;
private final UI uiInstance; private final UI uiInstance;
public BulkUploadHandler(final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout, BulkUploadHandler(final TargetBulkUpdateWindowLayout targetBulkUpdateWindowLayout,
final TargetManagement targetManagement, final ManagementUIState managementUIState, final TargetManagement targetManagement, final TagManagement tagManagement,
final DeploymentManagement deploymentManagement, final I18N i18n, final UI uiInstance) { final EntityFactory entityFactory, final DistributionSetManagement distributionSetManagement,
final ManagementUIState managementUIState, final DeploymentManagement deploymentManagement, final I18N i18n,
final UI uiInstance, final Executor uiExecutor) {
this.uiInstance = uiInstance; this.uiInstance = uiInstance;
this.comboBox = targetBulkUpdateWindowLayout.getDsNamecomboBox(); this.comboBox = targetBulkUpdateWindowLayout.getDsNamecomboBox();
this.descTextArea = targetBulkUpdateWindowLayout.getDescTextArea(); this.descTextArea = targetBulkUpdateWindowLayout.getDescTextArea();
@@ -113,11 +120,11 @@ public class BulkUploadHandler extends CustomComponent
this.targetsCountLabel = targetBulkUpdateWindowLayout.getTargetsCountLabel(); this.targetsCountLabel = targetBulkUpdateWindowLayout.getTargetsCountLabel();
this.targetBulkTokenTags = targetBulkUpdateWindowLayout.getTargetBulkTokenTags(); this.targetBulkTokenTags = targetBulkUpdateWindowLayout.getTargetBulkTokenTags();
this.i18n = i18n; this.i18n = i18n;
executor = (Executor) SpringContextHelper.getBean("uiExecutor"); this.uiExecutor = uiExecutor;
this.eventBus = targetBulkUpdateWindowLayout.getEventBus(); this.eventBus = targetBulkUpdateWindowLayout.getEventBus();
distributionSetManagement = SpringContextHelper.getBean(DistributionSetManagement.class); this.distributionSetManagement = distributionSetManagement;
tagManagement = SpringContextHelper.getBean(TagManagement.class); this.tagManagement = tagManagement;
entityFactory = SpringContextHelper.getBean(EntityFactory.class); this.entityFactory = entityFactory;
} }
void buildLayout() { void buildLayout() {
@@ -148,7 +155,7 @@ public class BulkUploadHandler extends CustomComponent
} catch (final IOException e) { } catch (final IOException e) {
LOG.error("Error while reading file {}", filename, e); LOG.error("Error while reading file {}", filename, e);
} }
return new NullOutputStream(); return ByteStreams.nullOutputStream();
} }
@Override @Override
@@ -158,7 +165,7 @@ public class BulkUploadHandler extends CustomComponent
@Override @Override
public void uploadSucceeded(final SucceededEvent event) { public void uploadSucceeded(final SucceededEvent event) {
executor.execute(new UploadAsync()); uiExecutor.execute(new UploadAsync());
} }
class UploadAsync implements Runnable { class UploadAsync implements Runnable {
@@ -179,11 +186,10 @@ public class BulkUploadHandler extends CustomComponent
private void readFileStream(final InputStream tempStream) { private void readFileStream(final InputStream tempStream) {
String line; String line;
final long totalNumberOfLines = getTotalNumberOfLines(); final BigDecimal totalNumberOfLines = getTotalNumberOfLines();
try (final BufferedReader reader = new BufferedReader( try (final LineNumberReader reader = new LineNumberReader(
new InputStreamReader(tempStream, Charset.defaultCharset()))) { new InputStreamReader(tempStream, Charset.defaultCharset()))) {
LOG.info("Bulk file upload started"); LOG.info("Bulk file upload started");
long innerCounter = 0;
/** /**
* Once control is in upload succeeded method automatically * Once control is in upload succeeded method automatically
@@ -191,9 +197,9 @@ public class BulkUploadHandler extends CustomComponent
* below event. * below event.
*/ */
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_PROCESS_STARTED)); eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_PROCESS_STARTED));
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
innerCounter++; readLine(line, reader.getLineNumber(), totalNumberOfLines);
readEachLine(line, innerCounter, totalNumberOfLines);
} }
} catch (final IOException e) { } catch (final IOException e) {
@@ -203,46 +209,48 @@ public class BulkUploadHandler extends CustomComponent
} finally { } finally {
deleteFile(); deleteFile();
} }
syncCountAfterUpload(totalNumberOfLines); syncCountAfterUpload(totalNumberOfLines.intValue());
doAssignments(); doAssignments();
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_COMPLETED)); eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_UPLOAD_COMPLETED));
// Clearing after assignments are done // Clearing after assignments are done
managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().clear(); managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().clear();
resetCounts(); resetSuccessfullTargetCount();
} }
private void syncCountAfterUpload(final long totalNumberOfLines) { private void syncCountAfterUpload(final int totalNumberOfLines) {
if ((successfullTargetCount + failedTargetCount) != totalNumberOfLines) { final int syncedFailedTargetCount = totalNumberOfLines - successfullTargetCount;
// something went wrong due to runtimeexception etc. managementUIState.getTargetTableFilters().getBulkUpload().setSucessfulUploadCount(successfullTargetCount);
final long syncedFailedTargetCount = totalNumberOfLines - successfullTargetCount;
managementUIState.getTargetTableFilters().getBulkUpload()
.setSucessfulUploadCount(successfullTargetCount);
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_TARGET_CREATED));
managementUIState.getTargetTableFilters().getBulkUpload().setFailedUploadCount(syncedFailedTargetCount); managementUIState.getTargetTableFilters().getBulkUpload().setFailedUploadCount(syncedFailedTargetCount);
managementUIState.getTargetTableFilters().getBulkUpload().setProgressBarCurrentValue(1); managementUIState.getTargetTableFilters().getBulkUpload().setProgressBarCurrentValue(1);
} eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_TARGET_CREATED));
} }
private long getTotalNumberOfLines() { private BigDecimal getTotalNumberOfLines() {
try {
return new BigDecimal(Files.readLines(tempFile, Charset.defaultCharset(), new LineProcessor<Integer>() {
private int count;
long totalFileSize = 0; @Override
try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(tempFile), public Integer getResult() {
Charset.defaultCharset())) { return count;
try (BufferedReader readerForSize = new BufferedReader(inputStreamReader)) {
totalFileSize = readerForSize.lines().count();
} }
} catch (final FileNotFoundException e) {
LOG.error("Error reading file {}", tempFile.getName(), e); @Override
public boolean processLine(final String line) {
count++;
return true;
}
}));
} catch (final IOException e) { } catch (final IOException e) {
LOG.error("Error while closing reader of file {}", tempFile.getName(), e); LOG.error("Error while reading temp file for upload.", e);
} }
return totalFileSize; return new BigDecimal(0);
} }
private void resetCounts() { private void resetSuccessfullTargetCount() {
successfullTargetCount = 0; successfullTargetCount = 0;
failedTargetCount = 0;
} }
private void deleteFile() { private void deleteFile() {
@@ -255,25 +263,22 @@ public class BulkUploadHandler extends CustomComponent
tempFile = null; tempFile = null;
} }
private void readEachLine(final String line, final long innerCounter, final long totalNumberOfLines) { private void readLine(final String line, final int lineNumber, final BigDecimal totalNumberOfLines) {
final String csvDelimiter = ","; final List<String> targets = SPLITTER.splitToList(line);
final String[] targets = line.split(csvDelimiter); if (targets.size() == 2) {
if (targets.length == 2) { final String controllerId = targets.get(0);
final String controllerId = targets[0]; final String targetName = targets.get(1);
final String targetName = targets[1];
addNewTarget(controllerId, targetName); addNewTarget(controllerId, targetName);
} else {
failedTargetCount++;
} }
final float current = managementUIState.getTargetTableFilters().getBulkUpload()
final float previous = managementUIState.getTargetTableFilters().getBulkUpload()
.getProgressBarCurrentValue(); .getProgressBarCurrentValue();
final float next = innerCounter / totalNumberOfLines; final float done = new BigDecimal(lineNumber).divide(totalNumberOfLines, 2, RoundingMode.UP).floatValue();
if (Math.abs(next - 0.1) < 0.00001 || current - next >= 0 || next - current >= 0.05
|| Math.abs(next - 1) < 0.00001) { if (done > previous) {
managementUIState.getTargetTableFilters().getBulkUpload().setProgressBarCurrentValue(next);
managementUIState.getTargetTableFilters().getBulkUpload() managementUIState.getTargetTableFilters().getBulkUpload()
.setSucessfulUploadCount(successfullTargetCount); .setSucessfulUploadCount(successfullTargetCount);
managementUIState.getTargetTableFilters().getBulkUpload().setFailedUploadCount(failedTargetCount); managementUIState.getTargetTableFilters().getBulkUpload().setProgressBarCurrentValue(done);
eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_TARGET_CREATED)); eventBus.publish(this, new TargetTableEvent(TargetComponentEvent.BULK_TARGET_CREATED));
} }
} }
@@ -332,25 +337,14 @@ public class BulkUploadHandler extends CustomComponent
return targetBulkTokenTags.getTokenField().getValue() != null; return targetBulkTokenTags.getTokenField().getValue() != null;
} }
/**
* @return
*/
private boolean ifDsSelected() { private boolean ifDsSelected() {
return comboBox.getValue() != null; return comboBox.getValue() != null;
} }
/**
* @return
*/
private boolean ifTargetsCreatedSuccessfully() { private boolean ifTargetsCreatedSuccessfully() {
return !managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().isEmpty(); return !managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().isEmpty();
} }
/**
* @param errorMessage
* @param dsAssignmentFailedMsg
* @param tagAssignmentFailedMsg
*/
private void displayValidationMessage(final StringBuilder errorMessage, final String dsAssignmentFailedMsg, private void displayValidationMessage(final StringBuilder errorMessage, final String dsAssignmentFailedMsg,
final String tagAssignmentFailedMsg) { final String tagAssignmentFailedMsg) {
if (dsAssignmentFailedMsg != null) { if (dsAssignmentFailedMsg != null) {
@@ -367,54 +361,23 @@ public class BulkUploadHandler extends CustomComponent
} }
} }
// Exception squid:S1166 - Targets that exist already are simply ignored
@SuppressWarnings("squid:S1166")
private void addNewTarget(final String controllerId, final String name) { private void addNewTarget(final String controllerId, final String name) {
final String newControllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerId); final String newControllerId = HawkbitCommonUtil.trimAndNullIfEmpty(controllerId);
if (mandatoryCheck(newControllerId) && duplicateCheck(newControllerId)) { final String description = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final String newName = HawkbitCommonUtil.trimAndNullIfEmpty(name);
final String newDesc = HawkbitCommonUtil.trimAndNullIfEmpty(descTextArea.getValue());
final Target newTarget = targetManagement.createTarget(entityFactory.target().create() try {
.controllerId(newControllerId).name(newName).description(newDesc)); targetManagement.createTarget(entityFactory.target().create().controllerId(newControllerId).name(name)
.description(description));
eventBus.publish(this, new TargetTableEvent(BaseEntityEventType.ADD_ENTITY, newTarget));
managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().add(newControllerId); managementUIState.getTargetTableFilters().getBulkUpload().getTargetsCreated().add(newControllerId);
successfullTargetCount++; successfullTargetCount++;
}
} catch (final EntityAlreadyExistsException ex) {
// Targets that exist already are simply ignored
} }
} }
private boolean mandatoryCheck(final String newControlllerId) {
if (newControlllerId == null) {
failedTargetCount++;
return false;
} else {
return true;
}
}
private boolean duplicateCheck(final String newControlllerId) {
final Target existingTarget = targetManagement.findTargetByControllerID(newControlllerId.trim());
if (existingTarget != null) {
failedTargetCount++;
return false;
} else {
return true;
}
}
private static class NullOutputStream extends OutputStream {
/**
* null output stream.
*
* @param i
* byte
*/
@Override
public void write(final int i) throws IOException {
// do nothing
}
} }
/** /**

View File

@@ -8,12 +8,13 @@
*/ */
package org.eclipse.hawkbit.ui.management.targettable; package org.eclipse.hawkbit.ui.management.targettable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory;
import org.eclipse.hawkbit.repository.TagManagement; import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.ui.SpPermissionChecker; import org.eclipse.hawkbit.ui.SpPermissionChecker;
@@ -64,6 +65,12 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
private final I18N i18n; private final I18N i18n;
private final transient TargetManagement targetManagement; private final transient TargetManagement targetManagement;
private final transient DistributionSetManagement distributionSetManagement;
private final transient TagManagement tagManagement;
private final transient EntityFactory entityFactory;
private final transient Executor uiExecutor;
private final transient EventBus.UIEventBus eventBus; private final transient EventBus.UIEventBus eventBus;
@@ -92,7 +99,8 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
TargetBulkUpdateWindowLayout(final I18N i18n, final TargetManagement targetManagement, final UIEventBus eventBus, TargetBulkUpdateWindowLayout(final I18N i18n, final TargetManagement targetManagement, final UIEventBus eventBus,
final ManagementUIState managementUIState, final DeploymentManagement deploymentManagement, final ManagementUIState managementUIState, final DeploymentManagement deploymentManagement,
final UiProperties uiproperties, final SpPermissionChecker checker, final UINotification uinotification, final UiProperties uiproperties, final SpPermissionChecker checker, final UINotification uinotification,
final TagManagement tagManagement) { final TagManagement tagManagement, final DistributionSetManagement distributionSetManagement,
final EntityFactory entityFactory, final Executor uiExecutor) {
this.i18n = i18n; this.i18n = i18n;
this.targetManagement = targetManagement; this.targetManagement = targetManagement;
this.eventBus = eventBus; this.eventBus = eventBus;
@@ -101,6 +109,10 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
this.managementUIState = managementUIState; this.managementUIState = managementUIState;
this.deploymentManagement = deploymentManagement; this.deploymentManagement = deploymentManagement;
this.uiproperties = uiproperties; this.uiproperties = uiproperties;
this.tagManagement = tagManagement;
this.distributionSetManagement = distributionSetManagement;
this.entityFactory = entityFactory;
this.uiExecutor = uiExecutor;
createRequiredComponents(); createRequiredComponents();
buildLayout(); buildLayout();
@@ -113,8 +125,8 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
targetBulkUpload.setDsNameAndVersion((Long) dsNamecomboBox.getValue()); targetBulkUpload.setDsNameAndVersion((Long) dsNamecomboBox.getValue());
targetBulkUpload.setDescription(descTextArea.getValue()); targetBulkUpload.setDescription(descTextArea.getValue());
targetBulkUpload.setProgressBarCurrentValue(0F); targetBulkUpload.setProgressBarCurrentValue(0F);
targetBulkUpload.setFailedUploadCount(0L); targetBulkUpload.setFailedUploadCount(0);
targetBulkUpload.setSucessfulUploadCount(0L); targetBulkUpload.setSucessfulUploadCount(0);
closeButton.setEnabled(false); closeButton.setEnabled(false);
minimizeButton.setEnabled(true); minimizeButton.setEnabled(true);
} }
@@ -163,8 +175,9 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
} }
private BulkUploadHandler getBulkUploadHandler() { private BulkUploadHandler getBulkUploadHandler() {
final BulkUploadHandler bulkUploadHandler = new BulkUploadHandler(this, targetManagement, managementUIState, final BulkUploadHandler bulkUploadHandler = new BulkUploadHandler(this, targetManagement, tagManagement,
deploymentManagement, i18n, UI.getCurrent()); entityFactory, distributionSetManagement, managementUIState, deploymentManagement, i18n,
UI.getCurrent(), uiExecutor);
bulkUploadHandler.buildLayout(); bulkUploadHandler.buildLayout();
bulkUploadHandler.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_BUTTON); bulkUploadHandler.addStyleName(SPUIStyleDefinitions.BULK_UPLOAD_BUTTON);
return bulkUploadHandler; return bulkUploadHandler;
@@ -231,14 +244,11 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
final Map<String, Object> queryConfiguration = Maps.newHashMapWithExpectedSize(2); final Map<String, Object> queryConfiguration = Maps.newHashMapWithExpectedSize(2);
final List<String> list = new ArrayList<>();
queryConfiguration.put(SPUIDefinitions.FILTER_BY_NO_TAG, queryConfiguration.put(SPUIDefinitions.FILTER_BY_NO_TAG,
managementUIState.getDistributionTableFilters().isNoTagSelected()); managementUIState.getDistributionTableFilters().isNoTagSelected());
if (!managementUIState.getDistributionTableFilters().getDistSetTags().isEmpty()) { queryConfiguration.put(SPUIDefinitions.FILTER_BY_TAG,
list.addAll(managementUIState.getDistributionTableFilters().getDistSetTags()); managementUIState.getDistributionTableFilters().getDistSetTags());
}
queryConfiguration.put(SPUIDefinitions.FILTER_BY_TAG, list);
final BeanQueryFactory<DistributionBeanQuery> distributionQF = new BeanQueryFactory<>( final BeanQueryFactory<DistributionBeanQuery> distributionQF = new BeanQueryFactory<>(
DistributionBeanQuery.class); DistributionBeanQuery.class);
@@ -287,8 +297,8 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
final TargetBulkUpload targetBulkUpload = managementUIState.getTargetTableFilters().getBulkUpload(); final TargetBulkUpload targetBulkUpload = managementUIState.getTargetTableFilters().getBulkUpload();
targetBulkUpload.setDescription(null); targetBulkUpload.setDescription(null);
targetBulkUpload.setDsNameAndVersion(null); targetBulkUpload.setDsNameAndVersion(null);
targetBulkUpload.setFailedUploadCount(0L); targetBulkUpload.setFailedUploadCount(0);
targetBulkUpload.setSucessfulUploadCount(0L); targetBulkUpload.setSucessfulUploadCount(0);
targetBulkUpload.getAssignedTagNames().clear(); targetBulkUpload.getAssignedTagNames().clear();
targetBulkUpload.getTargetsCreated().clear(); targetBulkUpload.getTargetsCreated().clear();
} }
@@ -303,14 +313,12 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
dsNamecomboBox.setValue(targetBulkUpload.getDsNameAndVersion()); dsNamecomboBox.setValue(targetBulkUpload.getDsNameAndVersion());
descTextArea.setValue(targetBulkUpload.getDescription()); descTextArea.setValue(targetBulkUpload.getDescription());
targetBulkTokenTags.addAlreadySelectedTags(); targetBulkTokenTags.addAlreadySelectedTags();
if (targetBulkUpload.getSucessfulUploadCount() > 0 || targetBulkUpload.getFailedUploadCount() > 0) {
if (targetBulkUpload.getProgressBarCurrentValue() >= 1) {
targetsCountLabel.setVisible(true); targetsCountLabel.setVisible(true);
targetsCountLabel.setCaption(getFormattedCountLabelValue(targetBulkUpload.getSucessfulUploadCount(), targetsCountLabel.setCaption(getFormattedCountLabelValue(targetBulkUpload.getSucessfulUploadCount(),
targetBulkUpload.getFailedUploadCount())); targetBulkUpload.getFailedUploadCount()));
} }
if (targetBulkUpload.getProgressBarCurrentValue() < 1) {
bulkUploader.getUpload().setEnabled(false);
}
} }
/** /**
@@ -324,13 +332,11 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
getTargetsCountLabel().setVisible(true); getTargetsCountLabel().setVisible(true);
getTargetsCountLabel().setCaption(targetCountLabel); getTargetsCountLabel().setCaption(targetCountLabel);
getBulkUploader().getUpload().setEnabled(true);
closeButton.setEnabled(true); closeButton.setEnabled(true);
minimizeButton.setEnabled(false); minimizeButton.setEnabled(false);
} }
private static String getFormattedCountLabelValue(final long succussfulUploadCount, final long failedUploadCount) { private static String getFormattedCountLabelValue(final int succussfulUploadCount, final int failedUploadCount) {
return new StringBuilder().append("Successful :").append(succussfulUploadCount) return new StringBuilder().append("Successful :").append(succussfulUploadCount)
.append("<font color=RED> Failed :").append(failedUploadCount).append("</font>").toString(); .append("<font color=RED> Failed :").append(failedUploadCount).append("</font>").toString();
} }
@@ -347,18 +353,14 @@ public class TargetBulkUpdateWindowLayout extends CustomComponent {
.buildWindow(); .buildWindow();
bulkUploadWindow.addStyleName("bulk-upload-window"); bulkUploadWindow.addStyleName("bulk-upload-window");
bulkUploadWindow.setImmediate(true); bulkUploadWindow.setImmediate(true);
if (isNoBulkUploadInProgress()) { if (managementUIState.getTargetTableFilters().getBulkUpload().getProgressBarCurrentValue() <= 0) {
bulkUploader.getUpload().setEnabled(true); bulkUploader.getUpload().setEnabled(true);
} else {
bulkUploader.getUpload().setEnabled(false);
} }
return bulkUploadWindow; return bulkUploadWindow;
} }
private boolean isNoBulkUploadInProgress() {
final float progressBarCurrentValue = managementUIState.getTargetTableFilters().getBulkUpload()
.getProgressBarCurrentValue();
return Math.abs(progressBarCurrentValue - 0) < 0.00001 || Math.abs(progressBarCurrentValue - 1) < 0.00001;
}
private void minimizeWindow() { private void minimizeWindow() {
bulkUploadWindow.close(); bulkUploadWindow.close();
managementUIState.setBulkUploadWindowMinimised(true); managementUIState.setBulkUploadWindowMinimised(true);

View File

@@ -9,6 +9,7 @@
package org.eclipse.hawkbit.ui.management.targettable; package org.eclipse.hawkbit.ui.management.targettable;
import java.util.Set; import java.util.Set;
import java.util.concurrent.Executor;
import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
@@ -79,14 +80,16 @@ public class TargetTableHeader extends AbstractTableHeader {
final UINotification notification, final ManagementUIState managementUIState, final UINotification notification, final ManagementUIState managementUIState,
final ManagementViewClientCriterion managementViewClientCriterion, final TargetManagement targetManagement, final ManagementViewClientCriterion managementViewClientCriterion, final TargetManagement targetManagement,
final DeploymentManagement deploymentManagement, final UiProperties uiproperties, final UIEventBus eventBus, final DeploymentManagement deploymentManagement, final UiProperties uiproperties, final UIEventBus eventBus,
final EntityFactory entityFactory, final UINotification uinotification, final TagManagement tagManagement, DistributionSetManagement distributionSetManagement) { final EntityFactory entityFactory, final UINotification uinotification, final TagManagement tagManagement,
final DistributionSetManagement distributionSetManagement, final Executor uiExecutor) {
super(i18n, permChecker, eventbus, managementUIState, null, null); super(i18n, permChecker, eventbus, managementUIState, null, null);
this.notification = notification; this.notification = notification;
this.managementViewClientCriterion = managementViewClientCriterion; this.managementViewClientCriterion = managementViewClientCriterion;
this.targetAddUpdateWindow = new TargetAddUpdateWindowLayout(i18n, targetManagement, eventBus, uinotification, this.targetAddUpdateWindow = new TargetAddUpdateWindowLayout(i18n, targetManagement, eventBus, uinotification,
entityFactory); entityFactory);
this.targetBulkUpdateWindow = new TargetBulkUpdateWindowLayout(i18n, targetManagement, eventBus, this.targetBulkUpdateWindow = new TargetBulkUpdateWindowLayout(i18n, targetManagement, eventBus,
managementUIState, deploymentManagement, uiproperties, permChecker, uinotification, tagManagement); managementUIState, deploymentManagement, uiproperties, permChecker, uinotification, tagManagement,
distributionSetManagement, entityFactory, uiExecutor);
this.distributionSetManagement = distributionSetManagement; this.distributionSetManagement = distributionSetManagement;
onLoadRestoreState(); onLoadRestoreState();
} }
@@ -336,12 +339,13 @@ public class TargetTableHeader extends AbstractTableHeader {
return; return;
} }
final Long distributionSetId = distributionIdSet.iterator().next(); final Long distributionSetId = distributionIdSet.iterator().next();
DistributionSet distributionSet =distributionSetManagement.findDistributionSetById(distributionSetId); final DistributionSet distributionSet = distributionSetManagement
if(distributionSet == null){ .findDistributionSetById(distributionSetId);
if (distributionSet == null) {
notification.displayWarning(i18n.get("distributionset.not.exists")); notification.displayWarning(i18n.get("distributionset.not.exists"));
return; return;
} }
DistributionSetIdName distributionSetIdName = new DistributionSetIdName(distributionSet); final DistributionSetIdName distributionSetIdName = new DistributionSetIdName(distributionSet);
managementUIState.getTargetTableFilters().setDistributionSet(distributionSetIdName); managementUIState.getTargetTableFilters().setDistributionSet(distributionSetIdName);
addFilterTextField(distributionSetIdName); addFilterTextField(distributionSetIdName);
} }
@@ -378,8 +382,7 @@ public class TargetTableHeader extends AbstractTableHeader {
private static Set<Long> getDropppedDistributionDetails(final TableTransferable transferable) { private static Set<Long> getDropppedDistributionDetails(final TableTransferable transferable) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final AbstractTable<?, Long> distTable = (AbstractTable<?, Long>) transferable final AbstractTable<?, Long> distTable = (AbstractTable<?, Long>) transferable.getSourceComponent();
.getSourceComponent();
return distTable.getDeletedEntityByTransferable(transferable); return distTable.getDeletedEntityByTransferable(transferable);
} }

View File

@@ -8,6 +8,8 @@
*/ */
package org.eclipse.hawkbit.ui.management.targettable; package org.eclipse.hawkbit.ui.management.targettable;
import java.util.concurrent.Executor;
import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.EntityFactory;
@@ -44,13 +46,14 @@ public class TargetTableLayout extends AbstractTableLayout<TargetTable> {
final ManagementViewClientCriterion managementViewClientCriterion, final ManagementViewClientCriterion managementViewClientCriterion,
final DeploymentManagement deploymentManagement, final UiProperties uiproperties, final DeploymentManagement deploymentManagement, final UiProperties uiproperties,
final SpPermissionChecker permissionChecker, final UINotification uinotification, final SpPermissionChecker permissionChecker, final UINotification uinotification,
final TagManagement tagManagement, final DistributionSetManagement distributionSetManagement) { final TagManagement tagManagement, final DistributionSetManagement distributionSetManagement,
final Executor uiExecutor) {
this.eventBus = eventBus; this.eventBus = eventBus;
this.targetDetails = new TargetDetails(i18n, eventbus, permissionChecker, managementUIState, uinotification, this.targetDetails = new TargetDetails(i18n, eventbus, permissionChecker, managementUIState, uinotification,
tagManagement, targetManagement, entityFactory); tagManagement, targetManagement, entityFactory);
this.targetTableHeader = new TargetTableHeader(i18n, permissionChecker, eventBus, notification, this.targetTableHeader = new TargetTableHeader(i18n, permissionChecker, eventBus, notification,
managementUIState, managementViewClientCriterion, targetManagement, deploymentManagement, uiproperties, managementUIState, managementViewClientCriterion, targetManagement, deploymentManagement, uiproperties,
eventbus, entityFactory, uinotification, tagManagement, distributionSetManagement); eventbus, entityFactory, uinotification, tagManagement, distributionSetManagement, uiExecutor);
super.init(targetTableHeader, targetTable, targetDetails); super.init(targetTableHeader, targetTable, targetDetails);
} }

View File

@@ -29,7 +29,8 @@ import java.util.List;
* unassigned targets will be displayed. * unassigned targets will be displayed.
* *
*/ */
@SuppressWarnings("squid:TrailingCommentCheck") // Exception squid - non Java 8 compatible GWT code that runs on browser
@SuppressWarnings({ "squid:TrailingCommentCheck", "squid:S1604" })
public class GroupsPieChartWidget extends DockLayoutPanel { public class GroupsPieChartWidget extends DockLayoutPanel {
private static final String ATTR_VISIBILITY = "visibility"; private static final String ATTR_VISIBILITY = "visibility";

View File

@@ -8,7 +8,6 @@
*/ */
package org.eclipse.hawkbit.ui.utils; package org.eclipse.hawkbit.ui.utils;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
@@ -19,7 +18,6 @@ import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.PollStatus; import org.eclipse.hawkbit.repository.model.PollStatus;
import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon;
import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery; import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery;
import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
@@ -506,35 +504,6 @@ public final class HawkbitCommonUtil {
return String.format("%.1f", tmpFinishedPercentage); return String.format("%.1f", tmpFinishedPercentage);
} }
/**
* Reset the values of status progress bar on change of values.
*
* @param bar
* DistributionBar
* @param item
* row of the table
*/
private static void setProgressBarDetails(final DistributionBar bar, final Item item) {
bar.setNumberOfParts(6);
final Long notStartedTargetsCount = getStatusCount(SPUILabelDefinitions.VAR_COUNT_TARGETS_NOT_STARTED, item);
HawkbitCommonUtil.setBarPartSize(bar, TotalTargetCountStatus.Status.NOTSTARTED.toString().toLowerCase(),
notStartedTargetsCount.intValue(), 0);
HawkbitCommonUtil.setBarPartSize(bar, TotalTargetCountStatus.Status.SCHEDULED.toString().toLowerCase(),
getStatusCount(SPUILabelDefinitions.VAR_COUNT_TARGETS_SCHEDULED, item).intValue(), 1);
HawkbitCommonUtil.setBarPartSize(bar, TotalTargetCountStatus.Status.RUNNING.toString().toLowerCase(),
getStatusCount(SPUILabelDefinitions.VAR_COUNT_TARGETS_RUNNING, item).intValue(), 2);
HawkbitCommonUtil.setBarPartSize(bar, TotalTargetCountStatus.Status.ERROR.toString().toLowerCase(),
getStatusCount(SPUILabelDefinitions.VAR_COUNT_TARGETS_ERROR, item).intValue(), 3);
HawkbitCommonUtil.setBarPartSize(bar, TotalTargetCountStatus.Status.FINISHED.toString().toLowerCase(),
getStatusCount(SPUILabelDefinitions.VAR_COUNT_TARGETS_FINISHED, item).intValue(), 4);
HawkbitCommonUtil.setBarPartSize(bar, TotalTargetCountStatus.Status.CANCELLED.toString().toLowerCase(),
getStatusCount(SPUILabelDefinitions.VAR_COUNT_TARGETS_CANCELLED, item).intValue(), 5);
}
private static boolean isNoTargets(final Long... statusCount) {
return (Arrays.asList(statusCount).stream().filter(value -> value > 0).toArray().length) == 0;
}
private static Long getStatusCount(final String propertName, final Item item) { private static Long getStatusCount(final String propertName, final Item item) {
return (Long) item.getItemProperty(propertName).getValue(); return (Long) item.getItemProperty(propertName).getValue();
} }