Sonar issue fixed
Signed-off-by: Dominic Schabel <dominic.schabel@bosch-si.com>
This commit is contained in:
@@ -43,7 +43,7 @@ public interface Action extends TenantAwareBaseEntity {
|
||||
* otherwise
|
||||
*/
|
||||
default boolean isCancelingOrCanceled() {
|
||||
return Status.CANCELING.equals(getStatus()) || Status.CANCELED.equals(getStatus());
|
||||
return Status.CANCELING == getStatus() || Status.CANCELED == getStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ public interface Action extends TenantAwareBaseEntity {
|
||||
* {@code false}
|
||||
*/
|
||||
default boolean isHitAutoForceTime(final long hitTimeMillis) {
|
||||
if (ActionType.TIMEFORCED.equals(getActionType())) {
|
||||
if (ActionType.TIMEFORCED == getActionType()) {
|
||||
return hitTimeMillis >= getForcedTime();
|
||||
}
|
||||
return false;
|
||||
@@ -139,7 +139,7 @@ public interface Action extends TenantAwareBaseEntity {
|
||||
* @return true when action is forced, false otherwise
|
||||
*/
|
||||
default boolean isForced() {
|
||||
return ActionType.FORCED.equals(getActionType());
|
||||
return ActionType.FORCED == getActionType();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -147,7 +147,7 @@ public class TotalTargetCountStatus {
|
||||
// Exception squid:MethodCyclomaticComplexity - simple state conversion, not
|
||||
// really complex.
|
||||
@SuppressWarnings("squid:MethodCyclomaticComplexity")
|
||||
private Status convertStatus(final Action.Status status){
|
||||
private Status convertStatus(final Action.Status status) {
|
||||
switch (status) {
|
||||
case SCHEDULED:
|
||||
return Status.SCHEDULED;
|
||||
@@ -164,10 +164,9 @@ public class TotalTargetCountStatus {
|
||||
case CANCELING:
|
||||
return Status.RUNNING;
|
||||
case DOWNLOADED:
|
||||
return Action.ActionType.DOWNLOAD_ONLY.equals(rolloutType) ? Status.FINISHED : Status.RUNNING;
|
||||
return Action.ActionType.DOWNLOAD_ONLY == rolloutType ? Status.FINISHED : Status.RUNNING;
|
||||
default:
|
||||
throw new IllegalArgumentException("State " + status + "is not valid");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public final class RolloutHelper {
|
||||
* the Status
|
||||
*/
|
||||
public static void verifyRolloutInStatus(final Rollout rollout, final Rollout.RolloutStatus status) {
|
||||
if (!rollout.getStatus().equals(status)) {
|
||||
if (rollout.getStatus() != status) {
|
||||
throw new RolloutIllegalStateException("Rollout is not in status " + status.toString());
|
||||
}
|
||||
}
|
||||
@@ -143,8 +143,6 @@ public final class RolloutHelper {
|
||||
* Filters the groups of a Rollout to match a specific status and adds a
|
||||
* group to the result.
|
||||
*
|
||||
* @param rollout
|
||||
* the rollout
|
||||
* @param status
|
||||
* the required status for the groups
|
||||
* @param group
|
||||
@@ -153,7 +151,7 @@ public final class RolloutHelper {
|
||||
*/
|
||||
public static List<Long> getGroupsByStatusIncludingGroup(final List<RolloutGroup> groups,
|
||||
final RolloutGroup.RolloutGroupStatus status, final RolloutGroup group) {
|
||||
return groups.stream().filter(innerGroup -> innerGroup.getStatus().equals(status) || innerGroup.equals(group))
|
||||
return groups.stream().filter(innerGroup -> innerGroup.getStatus() == status || innerGroup.equals(group))
|
||||
.map(RolloutGroup::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -200,15 +198,13 @@ public final class RolloutHelper {
|
||||
if (!StringUtils.isEmpty(previousGroupFilters)) {
|
||||
if (!StringUtils.isEmpty(groupFilter)) {
|
||||
return concatAndTargetFilters(baseFilter, groupFilter, previousGroupFilters);
|
||||
} else {
|
||||
return concatAndTargetFilters(baseFilter, previousGroupFilters);
|
||||
}
|
||||
return concatAndTargetFilters(baseFilter, previousGroupFilters);
|
||||
}
|
||||
if (!StringUtils.isEmpty(groupFilter)) {
|
||||
return concatAndTargetFilters(baseFilter, groupFilter);
|
||||
} else {
|
||||
return baseFilter;
|
||||
}
|
||||
return baseFilter;
|
||||
}
|
||||
|
||||
private static boolean isTargetFilterInGroups(final String groupFilter, final List<RolloutGroup> groups) {
|
||||
@@ -231,9 +227,8 @@ public final class RolloutHelper {
|
||||
static String getGroupTargetFilter(final String baseFilter, final RolloutGroup group) {
|
||||
if (StringUtils.isEmpty(group.getTargetFilterQuery())) {
|
||||
return baseFilter;
|
||||
} else {
|
||||
return concatAndTargetFilters(baseFilter, group.getTargetFilterQuery());
|
||||
}
|
||||
return concatAndTargetFilters(baseFilter, group.getTargetFilterQuery());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,10 +247,9 @@ public final class RolloutHelper {
|
||||
}
|
||||
|
||||
public static void checkIfRolloutCanStarted(final Rollout rollout, final Rollout mergedRollout) {
|
||||
if (!(Rollout.RolloutStatus.READY.equals(mergedRollout.getStatus()))) {
|
||||
if (Rollout.RolloutStatus.READY != mergedRollout.getStatus()) {
|
||||
throw new RolloutIllegalStateException("Rollout can only be started in state ready but current state is "
|
||||
+ rollout.getStatus().name().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -374,8 +374,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_COMMITTED)
|
||||
@Retryable(include = ConcurrencyFailureException.class, exclude = EntityAlreadyExistsException.class,
|
||||
maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
@Retryable(include = ConcurrencyFailureException.class, exclude = EntityAlreadyExistsException.class, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Target findOrRegisterTargetIfItDoesNotExist(final String controllerId, final URI address) {
|
||||
final Specification<JpaTarget> spec = (targetRoot, query, cb) -> cb
|
||||
.equal(targetRoot.get(JpaTarget_.controllerId), controllerId);
|
||||
@@ -394,9 +393,11 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetPollEvent(result, bus.getId())));
|
||||
|
||||
return result;
|
||||
} catch (final EntityAlreadyExistsException e){
|
||||
LOG.warn("Caught an EntityAlreadyExistsException while creating non existing target " +
|
||||
"[controllerId:{}, address:{}, tenant: {}]", controllerId, address, tenantAware.getCurrentTenant());
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
LOG.warn(
|
||||
"Caught an EntityAlreadyExistsException while creating non existing target "
|
||||
+ "[controllerId:{}, address:{}, tenant: {}]",
|
||||
controllerId, address, tenantAware.getCurrentTenant());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -491,7 +492,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
private Target updateTargetStatus(final JpaTarget toUpdate, final URI address) {
|
||||
boolean storeEager = isStoreEager(toUpdate, address);
|
||||
|
||||
if (TargetUpdateStatus.UNKNOWN.equals(toUpdate.getUpdateStatus())) {
|
||||
if (TargetUpdateStatus.UNKNOWN == toUpdate.getUpdateStatus()) {
|
||||
toUpdate.setUpdateStatus(TargetUpdateStatus.REGISTERED);
|
||||
storeEager = true;
|
||||
}
|
||||
@@ -589,15 +590,15 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
|
||||
/**
|
||||
* ActionStatus updates are allowed mainly if the action is active. If the
|
||||
* action is not active we accept further status updates if permitted so
|
||||
* by repository configuration. In this case, only the values: Status.ERROR
|
||||
* and Status.FINISHED are allowed. In the case of a DOWNLOAD_ONLY action,
|
||||
* we accept status updates only once.
|
||||
* action is not active we accept further status updates if permitted so by
|
||||
* repository configuration. In this case, only the values: Status.ERROR and
|
||||
* Status.FINISHED are allowed. In the case of a DOWNLOAD_ONLY action, we
|
||||
* accept status updates only once.
|
||||
*/
|
||||
private boolean isUpdatingActionStatusAllowed(final JpaAction action, final JpaActionStatus actionStatus) {
|
||||
|
||||
final boolean isIntermediateFeedback = !FINISHED.equals(actionStatus.getStatus())
|
||||
&& !Status.ERROR.equals(actionStatus.getStatus());
|
||||
final boolean isIntermediateFeedback = (FINISHED != actionStatus.getStatus())
|
||||
&& (Status.ERROR != actionStatus.getStatus());
|
||||
|
||||
final boolean isAllowedByRepositoryConfiguration = !repositoryProperties.isRejectActionStatusForClosedAction()
|
||||
&& isIntermediateFeedback;
|
||||
@@ -608,7 +609,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
private static boolean isDownloadOnly(final JpaAction action) {
|
||||
return DOWNLOAD_ONLY.equals(action.getActionType());
|
||||
return DOWNLOAD_ONLY == action.getActionType();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -651,7 +652,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
private String handleDownloadedActionStatus(final JpaAction action) {
|
||||
if(!isDownloadOnly(action)){
|
||||
if (!isDownloadOnly(action)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -697,9 +698,11 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
target.setInstalledDistributionSet(ds);
|
||||
target.setInstallationDate(System.currentTimeMillis());
|
||||
|
||||
// Target reported an installation of a DOWNLOAD_ONLY assignment, the assigned DS has to be adapted
|
||||
// because the currently assigned DS can be unequal to the currently installed DS (the downloadOnly DS)
|
||||
if(isDownloadOnly(action)){
|
||||
// Target reported an installation of a DOWNLOAD_ONLY assignment, the
|
||||
// assigned DS has to be adapted
|
||||
// because the currently assigned DS can be unequal to the currently
|
||||
// installed DS (the downloadOnly DS)
|
||||
if (isDownloadOnly(action)) {
|
||||
target.setAssignedDistributionSet(action.getDistributionSet());
|
||||
}
|
||||
|
||||
@@ -838,7 +841,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
// retrieves after the other we don't want to store to protect to
|
||||
// overflood action status in
|
||||
// case controller retrieves a action multiple times.
|
||||
if (resultList.isEmpty() || !Status.RETRIEVED.equals(resultList.get(0)[1])) {
|
||||
if (resultList.isEmpty() || (Status.RETRIEVED != resultList.get(0)[1])) {
|
||||
// document that the status has been retrieved
|
||||
actionStatusRepository
|
||||
.save(new JpaActionStatus(action, Status.RETRIEVED, System.currentTimeMillis(), message));
|
||||
|
||||
@@ -238,7 +238,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
|
||||
}
|
||||
|
||||
private static boolean isRolloutStatusReady(final RolloutGroup rolloutGroup) {
|
||||
return rolloutGroup != null && RolloutStatus.READY.equals(rolloutGroup.getRollout().getStatus());
|
||||
return rolloutGroup != null && (RolloutStatus.READY == rolloutGroup.getRollout().getStatus());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate.addSuccessAndErrorConditionsAndActions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -105,8 +107,6 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import static org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate.addSuccessAndErrorConditionsAndActions;
|
||||
|
||||
/**
|
||||
* JPA implementation of {@link RolloutManagement}.
|
||||
*/
|
||||
@@ -336,14 +336,14 @@ public class JpaRolloutManagement extends AbstractRolloutManagement {
|
||||
int readyGroups = 0;
|
||||
int totalTargets = 0;
|
||||
for (final RolloutGroup group : rolloutGroups) {
|
||||
if (RolloutGroupStatus.READY.equals(group.getStatus())) {
|
||||
if (RolloutGroupStatus.READY == group.getStatus()) {
|
||||
readyGroups++;
|
||||
totalTargets += group.getTotalTargets();
|
||||
continue;
|
||||
}
|
||||
|
||||
final RolloutGroup filledGroup = fillRolloutGroupWithTargets(rollout, group);
|
||||
if (RolloutGroupStatus.READY.equals(filledGroup.getStatus())) {
|
||||
if (RolloutGroupStatus.READY == filledGroup.getStatus()) {
|
||||
readyGroups++;
|
||||
totalTargets += filledGroup.getTotalTargets();
|
||||
}
|
||||
|
||||
@@ -38,8 +38,9 @@ public class ThresholdRolloutGroupSuccessCondition implements RolloutGroupCondit
|
||||
return true;
|
||||
}
|
||||
|
||||
Action.Status completeActionStatus = Action.ActionType.DOWNLOAD_ONLY.equals(rollout.getActionType()) ?
|
||||
Action.Status.DOWNLOADED : Action.Status.FINISHED;
|
||||
final Action.Status completeActionStatus = (Action.ActionType.DOWNLOAD_ONLY == rollout.getActionType())
|
||||
? Action.Status.DOWNLOADED
|
||||
: Action.Status.FINISHED;
|
||||
final long finished = this.actionRepository.countByRolloutIdAndRolloutGroupIdAndStatus(rollout.getId(),
|
||||
rolloutGroup.getId(), completeActionStatus);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user