Merge pull request #74 from bsinno/Sonar_remove_unused_method_parameters
Looks good, thx for the contribution
This commit is contained in:
@@ -572,7 +572,7 @@ public class DeploymentManagement {
|
|||||||
@Modifying
|
@Modifying
|
||||||
@Transactional
|
@Transactional
|
||||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
|
||||||
public Action forceQuitAction(@NotNull final Action action, @NotNull final Target target) {
|
public Action forceQuitAction(@NotNull final Action action) {
|
||||||
final Action mergedAction = entityManager.merge(action);
|
final Action mergedAction = entityManager.merge(action);
|
||||||
|
|
||||||
if (!mergedAction.isCancelingOrCanceled()) {
|
if (!mergedAction.isCancelingOrCanceled()) {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class Target extends NamedEntity implements Persistable<Long> {
|
|||||||
private String controllerId;
|
private String controllerId;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private boolean isNew = false;
|
private boolean entityNew = false;
|
||||||
|
|
||||||
@ManyToMany(targetEntity = TargetTag.class)
|
@ManyToMany(targetEntity = TargetTag.class)
|
||||||
@JoinTable(name = "sp_target_target_tag", joinColumns = {
|
@JoinTable(name = "sp_target_target_tag", joinColumns = {
|
||||||
@@ -217,15 +217,15 @@ public class Target extends NamedEntity implements Persistable<Long> {
|
|||||||
@Override
|
@Override
|
||||||
@Transient
|
@Transient
|
||||||
public boolean isNew() {
|
public boolean isNew() {
|
||||||
return isNew;
|
return entityNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param isNew
|
* @param isNew
|
||||||
* the isNew to set
|
* the isNew to set
|
||||||
*/
|
*/
|
||||||
public void setNew(final boolean isNew) {
|
public void setNew(final boolean entityNew) {
|
||||||
this.isNew = isNew;
|
this.entityNew = entityNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class TargetInfo implements Persistable<Long>, Serializable {
|
|||||||
private Long targetId;
|
private Long targetId;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private boolean isNew = false;
|
private boolean entityNew = false;
|
||||||
|
|
||||||
@CascadeOnDelete
|
@CascadeOnDelete
|
||||||
@OneToOne(cascade = { CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.LAZY, targetEntity = Target.class)
|
@OneToOne(cascade = { CascadeType.MERGE, CascadeType.REMOVE }, fetch = FetchType.LAZY, targetEntity = Target.class)
|
||||||
@@ -154,15 +154,15 @@ public class TargetInfo implements Persistable<Long>, Serializable {
|
|||||||
@Override
|
@Override
|
||||||
@Transient
|
@Transient
|
||||||
public boolean isNew() {
|
public boolean isNew() {
|
||||||
return isNew;
|
return entityNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param isNew
|
* @param isNew
|
||||||
* the isNew to set
|
* the isNew to set
|
||||||
*/
|
*/
|
||||||
public void setNew(final boolean isNew) {
|
public void setNew(final boolean entityNew) {
|
||||||
this.isNew = isNew;
|
this.entityNew = entityNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository;
|
|||||||
|
|
||||||
import static org.fest.assertions.api.Assertions.assertThat;
|
import static org.fest.assertions.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -312,7 +311,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
|||||||
deploymentManagement.cancelAction(assigningAction, target);
|
deploymentManagement.cancelAction(assigningAction, target);
|
||||||
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
|
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
|
||||||
|
|
||||||
deploymentManagement.forceQuitAction(assigningAction, target);
|
deploymentManagement.forceQuitAction(assigningAction);
|
||||||
|
|
||||||
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
|
assigningAction = deploymentManagement.findActionWithDetails(assigningAction.getId());
|
||||||
|
|
||||||
@@ -350,8 +349,7 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
|||||||
|
|
||||||
// force quit assignment
|
// force quit assignment
|
||||||
try {
|
try {
|
||||||
deploymentManagement.forceQuitAction(assigningAction,
|
deploymentManagement.forceQuitAction(assigningAction);
|
||||||
targetManagement.findTargetByControllerID(target.getControllerId()));
|
|
||||||
fail("expected ForceQuitActionNotAllowedException");
|
fail("expected ForceQuitActionNotAllowedException");
|
||||||
} catch (final ForceQuitActionNotAllowedException ex) {
|
} catch (final ForceQuitActionNotAllowedException ex) {
|
||||||
}
|
}
|
||||||
@@ -764,13 +762,16 @@ public class DeploymentManagementTest extends AbstractIntegrationTest {
|
|||||||
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision());
|
||||||
|
|
||||||
// verifying that the assignment is correct
|
// verifying that the assignment is correct
|
||||||
assertEquals("Active target actions are wrong", 1, deploymentManagement.findActiveActionsByTarget(targ).size());
|
assertThat(deploymentManagement.findActiveActionsByTarget(targ).size()).as("Active target actions are wrong")
|
||||||
assertEquals("Target actions are wrong", 1, deploymentManagement.findActionsByTarget(targ).size());
|
.isEqualTo(1);
|
||||||
assertEquals("Target status is wrong", TargetUpdateStatus.PENDING, targ.getTargetInfo().getUpdateStatus());
|
assertThat(deploymentManagement.findActionsByTarget(targ).size()).as("Target actions are wrong").isEqualTo(1);
|
||||||
assertEquals("Assigned ds is wrong", dsA, targ.getAssignedDistributionSet());
|
assertThat(targ.getTargetInfo().getUpdateStatus()).as("UpdateStatus of target is wrong")
|
||||||
assertEquals("Active ds is wrong", dsA,
|
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||||
deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet());
|
assertThat(targ.getAssignedDistributionSet()).as("Assigned distribution set of target is wrong").isEqualTo(dsA);
|
||||||
assertNull("Installed ds should be null", targ.getTargetInfo().getInstalledDistributionSet());
|
assertThat(deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet())
|
||||||
|
.as("Distribution set of actionn is wrong").isEqualTo(dsA);
|
||||||
|
assertThat(deploymentManagement.findActiveActionsByTarget(targ).get(0).getDistributionSet())
|
||||||
|
.as("Installed distribution set of action should be null").isNotNull();
|
||||||
|
|
||||||
final Page<Action> updAct = actionRepository.findByDistributionSet(pageReq, dsA);
|
final Page<Action> updAct = actionRepository.findByDistributionSet(pageReq, dsA);
|
||||||
final Action action = updAct.getContent().get(0);
|
final Action action = updAct.getContent().get(0);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
import org.eclipse.hawkbit.AbstractIntegrationTest;
|
||||||
import org.eclipse.hawkbit.TestDataUtil;
|
import org.eclipse.hawkbit.TestDataUtil;
|
||||||
@@ -34,6 +35,8 @@ import org.eclipse.hawkbit.repository.model.Target;
|
|||||||
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.repository.model.TotalTargetCountStatus;
|
||||||
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
|
||||||
|
import org.eclipse.hawkbit.repository.utils.MultipleInvokeHelper;
|
||||||
|
import org.eclipse.hawkbit.repository.utils.SuccessCondition;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Description;
|
import org.springframework.context.annotation.Description;
|
||||||
@@ -859,7 +862,7 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verify the creation and the start of a rollout in asynchronous mode.")
|
@Description("Verify the creation and the start of a rollout in asynchronous mode.")
|
||||||
public void createAndStartRolloutInAsync() {
|
public void createAndStartRolloutInAsync() throws Exception {
|
||||||
|
|
||||||
final int amountTargetsForRollout = 500;
|
final int amountTargetsForRollout = 500;
|
||||||
final int amountGroups = 5;
|
final int amountGroups = 5;
|
||||||
@@ -883,31 +886,18 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
|||||||
|
|
||||||
myRollout = rolloutManagement.createRolloutAsync(myRollout, amountGroups, conditions);
|
myRollout = rolloutManagement.createRolloutAsync(myRollout, amountGroups, conditions);
|
||||||
|
|
||||||
int counter = 1;
|
SuccessConditionRolloutStatus conditionRolloutTargetCount = new SuccessConditionRolloutStatus(
|
||||||
int counterMax = 10;
|
RolloutStatus.READY);
|
||||||
while (!isRolloutInGivenStatus(myRollout.getId(), RolloutStatus.READY) && (counter <= counterMax)) {
|
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
|
||||||
try {
|
conditionRolloutTargetCount, 15000, 500)).as("Rollout status").isNotNull();
|
||||||
Thread.sleep(500);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.READY);
|
||||||
rolloutManagement.startRolloutAsync(myRollout);
|
rolloutManagement.startRolloutAsync(myRollout);
|
||||||
|
|
||||||
counter = 1;
|
conditionRolloutTargetCount = new SuccessConditionRolloutStatus(RolloutStatus.RUNNING);
|
||||||
counterMax = 10;
|
assertThat(MultipleInvokeHelper.doWithTimeout(new RolloutStatusCallable(myRollout.getId()),
|
||||||
while (!isRolloutInGivenStatus(myRollout.getId(), RolloutStatus.RUNNING) && counter <= counterMax) {
|
conditionRolloutTargetCount, 15000, 500)).as("Rollout status").isNotNull();
|
||||||
try {
|
|
||||||
Thread.sleep(500);
|
|
||||||
} catch (final InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
myRollout = rolloutManagement.findRolloutById(myRollout.getId());
|
||||||
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING);
|
assertThat(myRollout.getStatus()).isEqualTo(RolloutStatus.RUNNING);
|
||||||
@@ -917,14 +907,6 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
|||||||
validateRolloutActionStatus(myRollout.getId(), expectedTargetCountStatus);
|
validateRolloutActionStatus(myRollout.getId(), expectedTargetCountStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isRolloutInGivenStatus(final Long rolloutID, final RolloutStatus status) {
|
|
||||||
final Rollout myRollout = rolloutManagement.findRolloutById(rolloutID);
|
|
||||||
if (myRollout.getStatus() == status) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateRolloutGroupActionStatus(final RolloutGroup rolloutGroup,
|
private void validateRolloutGroupActionStatus(final RolloutGroup rolloutGroup,
|
||||||
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus) {
|
final Map<TotalTargetCountStatus.Status, Long> expectedTargetCountStatus) {
|
||||||
final RolloutGroup rolloutGroupWithDetail = rolloutGroupManagement
|
final RolloutGroup rolloutGroupWithDetail = rolloutGroupManagement
|
||||||
@@ -1021,4 +1003,35 @@ public class RolloutManagementTest extends AbstractIntegrationTest {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class SuccessConditionRolloutStatus implements SuccessCondition<RolloutStatus> {
|
||||||
|
|
||||||
|
private final RolloutStatus rolloutStatus;
|
||||||
|
|
||||||
|
public SuccessConditionRolloutStatus(final RolloutStatus rolloutStatus) {
|
||||||
|
this.rolloutStatus = rolloutStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean success(final RolloutStatus result) {
|
||||||
|
return result.equals(rolloutStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RolloutStatusCallable implements Callable<RolloutStatus> {
|
||||||
|
|
||||||
|
final Long rolloutId;
|
||||||
|
|
||||||
|
RolloutStatusCallable(final Long rolloutId) {
|
||||||
|
this.rolloutId = rolloutId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RolloutStatus call() throws Exception {
|
||||||
|
|
||||||
|
final Rollout myRollout = rolloutManagement.findRolloutById(rolloutId);
|
||||||
|
return myRollout.getStatus();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*/
|
||||||
|
package org.eclipse.hawkbit.repository.utils;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to call a request multiple times regarding a given condition until
|
||||||
|
* timeout is reached.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public final class MultipleInvokeHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call with timeout until result is not null.
|
||||||
|
*
|
||||||
|
* @param callable
|
||||||
|
* class
|
||||||
|
* @param timeout
|
||||||
|
* value
|
||||||
|
* @param pollInterval
|
||||||
|
* value
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static <T> T doWithTimeoutUntilResultIsNotNull(final Callable<T> callable, final long timeout,
|
||||||
|
final long pollInterval) throws Exception // NOPMD
|
||||||
|
{
|
||||||
|
return doWithTimeout(callable, new SuccessCondition<T>() {
|
||||||
|
@Override
|
||||||
|
public boolean success(final T result) {
|
||||||
|
return result != null;
|
||||||
|
};
|
||||||
|
}, timeout, pollInterval);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call with timeout.
|
||||||
|
*
|
||||||
|
* @param callable
|
||||||
|
* class
|
||||||
|
* @param successCondition
|
||||||
|
* class
|
||||||
|
* @param timeout
|
||||||
|
* value
|
||||||
|
* @param pollInterval
|
||||||
|
* value
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static <T> T doWithTimeout(final Callable<T> callable, final SuccessCondition<T> successCondition,
|
||||||
|
final long timeout, final long pollInterval) throws Exception // NOPMD
|
||||||
|
{
|
||||||
|
|
||||||
|
if (pollInterval < 0) {
|
||||||
|
throw new IllegalArgumentException("pollInterval must non negative");
|
||||||
|
}
|
||||||
|
|
||||||
|
long duration = 0;
|
||||||
|
Exception exception = null;
|
||||||
|
T returnValue = null;
|
||||||
|
while (untilTimeoutReached(timeout, duration)) {
|
||||||
|
try {
|
||||||
|
returnValue = callable.call();
|
||||||
|
// clear exception
|
||||||
|
exception = null;
|
||||||
|
} catch (final Exception ex) {
|
||||||
|
exception = ex;
|
||||||
|
}
|
||||||
|
Thread.sleep(pollInterval);
|
||||||
|
duration += pollInterval > 0 ? pollInterval : 1;
|
||||||
|
if (exception == null && successCondition.success(returnValue)) {
|
||||||
|
return returnValue;
|
||||||
|
} else {
|
||||||
|
returnValue = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (exception != null) {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean untilTimeoutReached(final long timeout, final long duration) {
|
||||||
|
return duration <= timeout || timeout < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*/
|
||||||
|
package org.eclipse.hawkbit.repository.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SuccessCondition Interface.
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
* type of the value to get verified
|
||||||
|
*/
|
||||||
|
public interface SuccessCondition<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The implementation of the success condition.
|
||||||
|
*
|
||||||
|
* @param result
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean success(final T result);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -209,7 +209,7 @@ public class TargetResource implements TargetRestApi {
|
|||||||
final Action action = findActionWithExceptionIfNotFound(actionId);
|
final Action action = findActionWithExceptionIfNotFound(actionId);
|
||||||
|
|
||||||
if (force) {
|
if (force) {
|
||||||
this.deploymentManagement.forceQuitAction(action, target);
|
this.deploymentManagement.forceQuitAction(action);
|
||||||
} else {
|
} else {
|
||||||
this.deploymentManagement.cancelAction(action, target);
|
this.deploymentManagement.cancelAction(action, target);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -844,7 +844,7 @@ public class ActionHistoryTable extends TreeTable implements Handler {
|
|||||||
if (actionId != null) {
|
if (actionId != null) {
|
||||||
final Action activeAction = deploymentManagement.findAction(actionId);
|
final Action activeAction = deploymentManagement.findAction(actionId);
|
||||||
try {
|
try {
|
||||||
deploymentManagement.forceQuitAction(activeAction, target);
|
deploymentManagement.forceQuitAction(activeAction);
|
||||||
return true;
|
return true;
|
||||||
} catch (final CancelActionNotAllowedException e) {
|
} catch (final CancelActionNotAllowedException e) {
|
||||||
LOG.info("Force Cancel action not allowed exception :{}", e);
|
LOG.info("Force Cancel action not allowed exception :{}", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user