Feature/type for multi actions (#986)

* Introduce different types of Multi Action Event to distinguish between an Assignment and a Cancel.
* Minimize the payload for the multiAction assignment and cancel event. Write tests for the MultiActionCancelEvent.
* Remove unused action status.
* Move list of actionIds to MultiActionEvent and declare it as abstract.
* Remove unused imports.

Signed-off-by: Michael Herdt <Michael.Herdt2@bosch-si.com>
This commit is contained in:
Michael Herdt
2020-09-25 13:12:42 +02:00
committed by GitHub
parent 1b92b653da
commit e82b9cee70
9 changed files with 291 additions and 102 deletions

View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) 2020 Bosch.IO 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.event.remote;
import org.eclipse.hawkbit.repository.model.Action;
import java.util.List;
/**
* Generic deployment event for the Multi-Assignments feature. The event extends
* the {@link MultiActionEvent} and holds a list of controller IDs to identify
* the targets which are affected by a deployment action and a list of
* actionIds containing the identifiers of the affected actions
* as payload. This event is only published in case of an assignment.
*/
public class MultiActionAssignEvent extends MultiActionEvent {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public MultiActionAssignEvent() {
// for serialization libs like jackson
}
/**
* Constructor.
*
* @param tenant
* tenant the event is scoped to
* @param applicationId
* the application id
* @param actions
* the actions of the deployment action
*/
public MultiActionAssignEvent(String tenant, String applicationId, List<Action> actions) {
super(tenant, applicationId, actions);
}
}

View File

@@ -0,0 +1,47 @@
/**
* Copyright (c) 2020 Bosch.IO 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.event.remote;
import java.util.List;
import org.eclipse.hawkbit.repository.model.Action;
/**
* Generic deployment event for the Multi-Assignments feature. The event extends
* the {@link MultiActionEvent} and holds a list of controller IDs to identify
* the targets which are affected by a deployment action and a list of
* actionIds containing the identifiers of the affected actions
* as payload. This event is only published in case of an cancellation.
*/
public class MultiActionCancelEvent extends MultiActionEvent {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public MultiActionCancelEvent() {
// for serialization libs like jackson
}
/**
* Constructor.
*
* @param tenant
* tenant the event is scoped to
* @param applicationId
* the application id
* @param actions
* the actions to be canceled
*/
public MultiActionCancelEvent(String tenant, String applicationId, List<Action> actions) {
super(tenant, applicationId, actions);
}
}

View File

@@ -8,9 +8,14 @@
*/
package org.eclipse.hawkbit.repository.event.remote;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Target;
import org.springframework.hateoas.Identifiable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* Generic deployment event for the Multi-Assignments feature. The event payload
@@ -18,11 +23,12 @@ import java.util.List;
* a deployment action (e.g. a software assignment (update) or a cancellation of
* an update).
*/
public class MultiActionEvent extends RemoteTenantAwareEvent implements Iterable<String> {
public abstract class MultiActionEvent extends RemoteTenantAwareEvent implements Iterable<String> {
private static final long serialVersionUID = 1L;
private final List<String> controllerIds = new ArrayList<>();
private final List<Long> actionIds = new ArrayList<>();
/**
* Default constructor.
@@ -33,17 +39,18 @@ public class MultiActionEvent extends RemoteTenantAwareEvent implements Iterable
/**
* Constructor.
*
*
* @param tenant
* tenant the event is scoped to
* @param applicationId
* the application id
* @param controllerIds
* the controller IDs of the affected targets
* @param actions
* the actions involved
*/
public MultiActionEvent(final String tenant, final String applicationId, final List<String> controllerIds) {
public MultiActionEvent(String tenant, String applicationId, List<Action> actions) {
super(applicationId, tenant, applicationId);
this.controllerIds.addAll(controllerIds);
this.controllerIds.addAll(getControllerIdsFromActions(actions));
this.actionIds.addAll(getIdsFromActions(actions));
}
public List<String> getControllerIds() {
@@ -55,4 +62,17 @@ public class MultiActionEvent extends RemoteTenantAwareEvent implements Iterable
return controllerIds.iterator();
}
}
public List<Long> getActionIds() {
return actionIds;
}
private static List<String> getControllerIdsFromActions(final List<Action> actions) {
return actions.stream().map(Action::getTarget).map(Target::getControllerId).distinct()
.collect(Collectors.toList());
}
private static List<Long> getIdsFromActions(final List<Action> actions) {
return actions.stream().map(Identifiable::getId).collect(Collectors.toList());
}
}