Merge with master
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -29,7 +30,6 @@ import org.eclipse.hawkbit.ddi.json.model.DdiControllerBase;
|
||||
import org.eclipse.hawkbit.ddi.json.model.DdiPolling;
|
||||
import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
@@ -108,16 +108,18 @@ public final class DataConversionHelper {
|
||||
return file;
|
||||
}
|
||||
|
||||
static DdiControllerBase fromTarget(final Target target, final List<Action> actions,
|
||||
static DdiControllerBase fromTarget(final Target target, final Optional<Action> action,
|
||||
final String defaultControllerPollTime, final TenantAware tenantAware) {
|
||||
final DdiControllerBase result = new DdiControllerBase(
|
||||
new DdiConfig(new DdiPolling(defaultControllerPollTime)));
|
||||
|
||||
boolean addedUpdate = false;
|
||||
boolean addedCancel = false;
|
||||
final long countCancelingActions = actions.stream().filter(a -> a.getStatus() == Status.CANCELING).count();
|
||||
for (final Action action : actions) {
|
||||
if (countCancelingActions <= 0 && !action.isCancelingOrCanceled() && !addedUpdate) {
|
||||
if (action.isPresent()) {
|
||||
if (action.get().isCancelingOrCanceled()) {
|
||||
result.add(linkTo(
|
||||
methodOn(DdiRootController.class, tenantAware.getCurrentTenant()).getControllerCancelAction(
|
||||
tenantAware.getCurrentTenant(), target.getControllerId(), action.get().getId()))
|
||||
.withRel(DdiRestConstants.CANCEL_ACTION));
|
||||
} else {
|
||||
// we need to add the hashcode here of the actionWithStatus
|
||||
// because the action might
|
||||
// have changed from 'soft' to 'forced' type and we need to
|
||||
@@ -125,15 +127,8 @@ public final class DataConversionHelper {
|
||||
// response because of eTags.
|
||||
result.add(linkTo(methodOn(DdiRootController.class, tenantAware.getCurrentTenant())
|
||||
.getControllerBasedeploymentAction(tenantAware.getCurrentTenant(), target.getControllerId(),
|
||||
action.getId(), calculateEtag(action)))
|
||||
action.get().getId(), calculateEtag(action.get())))
|
||||
.withRel(DdiRestConstants.DEPLOYMENT_BASE_ACTION));
|
||||
addedUpdate = true;
|
||||
} else if (action.isCancelingOrCanceled() && !addedCancel) {
|
||||
result.add(linkTo(
|
||||
methodOn(DdiRootController.class, tenantAware.getCurrentTenant()).getControllerCancelAction(
|
||||
tenantAware.getCurrentTenant(), target.getControllerId(), action.getId()))
|
||||
.withRel(DdiRestConstants.CANCEL_ACTION));
|
||||
addedCancel = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(
|
||||
DataConversionHelper.fromTarget(target, controllerManagement.findActionByTargetAndActive(target),
|
||||
DataConversionHelper.fromTarget(target, controllerManagement.findOldestActiveActionByTarget(target),
|
||||
controllerManagement.getPollingTime(), tenantAware),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user