Adapt cancel flow (#1274)
* Adapt assignment events to communicate mass cancel operations within one event. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Fix edge cases identified by test failures. Adapt tests and reduce amount of published cancel events. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Fix license header Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Refactor visibility of methods in assignment strategy classes. Avoid having empty action status messages. Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> * Fix api docs Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> Co-authored-by: Bogdan Bondar <Bogdan.Bondar@bosch.io>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2022 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 org.eclipse.hawkbit.repository.model.ActionProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Abstract class providing information about an assignment.
|
||||
*/
|
||||
public abstract class AbstractAssignmentEvent extends RemoteTenantAwareEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Map<String, ActionProperties> actions = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
protected AbstractAssignmentEvent() {
|
||||
// for serialization libs like jackson
|
||||
}
|
||||
|
||||
protected AbstractAssignmentEvent(final Object source, final Action a, final String applicationId) {
|
||||
super(source, a.getTenant(), applicationId);
|
||||
actions.put(a.getTarget().getControllerId(), new ActionProperties(a));
|
||||
}
|
||||
|
||||
protected AbstractAssignmentEvent(final Object source, final String tenant, final List<Action> a,
|
||||
final String applicationId) {
|
||||
super(source, tenant, applicationId);
|
||||
actions.putAll(a.stream()
|
||||
.collect(Collectors.toMap(action -> action.getTarget().getControllerId(), ActionProperties::new)));
|
||||
}
|
||||
|
||||
public Map<String, ActionProperties> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
public Optional<ActionProperties> getActionPropertiesForController(final String controllerId) {
|
||||
return Optional.ofNullable(actions.get(controllerId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) 2022 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;
|
||||
|
||||
/**
|
||||
* Event that gets sent when the assignment of a distribution set to a target
|
||||
* gets canceled.
|
||||
*/
|
||||
public class CancelTargetAssignmentEvent extends AbstractAssignmentEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public CancelTargetAssignmentEvent() {
|
||||
// for serialization libs like jackson
|
||||
}
|
||||
|
||||
public CancelTargetAssignmentEvent(final Action a, final String applicationId) {
|
||||
super(applicationId, a, applicationId);
|
||||
}
|
||||
|
||||
public CancelTargetAssignmentEvent(final String tenant, final List<Action> a, final String applicationId) {
|
||||
super(applicationId, tenant, a, applicationId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,19 +9,16 @@
|
||||
package org.eclipse.hawkbit.repository.event.remote;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.ActionProperties;
|
||||
|
||||
/**
|
||||
* TenantAwareEvent that gets sent when a distribution set gets assigned to a
|
||||
* target.
|
||||
*/
|
||||
public class TargetAssignDistributionSetEvent extends RemoteTenantAwareEvent {
|
||||
public class TargetAssignDistributionSetEvent extends AbstractAssignmentEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -29,8 +26,6 @@ public class TargetAssignDistributionSetEvent extends RemoteTenantAwareEvent {
|
||||
|
||||
private boolean maintenanceWindowAvailable;
|
||||
|
||||
private final Map<String, ActionProperties> actions = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
@@ -54,12 +49,12 @@ public class TargetAssignDistributionSetEvent extends RemoteTenantAwareEvent {
|
||||
*/
|
||||
public TargetAssignDistributionSetEvent(final String tenant, final long distributionSetId, final List<Action> a,
|
||||
final String applicationId, final boolean maintenanceWindowAvailable) {
|
||||
super(distributionSetId, tenant, applicationId);
|
||||
super(distributionSetId, tenant,
|
||||
a.stream().filter(action -> action.getDistributionSet().getId().longValue() == distributionSetId)
|
||||
.collect(Collectors.toList()),
|
||||
applicationId);
|
||||
this.distributionSetId = distributionSetId;
|
||||
this.maintenanceWindowAvailable = maintenanceWindowAvailable;
|
||||
actions.putAll(a.stream().filter(action -> action.getDistributionSet().getId().longValue() == distributionSetId)
|
||||
.collect(Collectors.toMap(action -> action.getTarget().getControllerId(), ActionProperties::new)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,8 +78,4 @@ public class TargetAssignDistributionSetEvent extends RemoteTenantAwareEvent {
|
||||
return maintenanceWindowAvailable;
|
||||
}
|
||||
|
||||
public Map<String, ActionProperties> getActions() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
* 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.event.remote.entity;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
|
||||
/**
|
||||
* Event that gets sent when the assignment of a distribution set to a target
|
||||
* gets canceled.
|
||||
*/
|
||||
public class CancelTargetAssignmentEvent extends RemoteEntityEvent<Target> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long actionId;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public CancelTargetAssignmentEvent() {
|
||||
// for serialization libs like jackson
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param baseEntity
|
||||
* the target
|
||||
* @param actionId
|
||||
* the actionId
|
||||
* @param applicationId
|
||||
* the origin application id
|
||||
*/
|
||||
public CancelTargetAssignmentEvent(final Target baseEntity, final Long actionId, final String applicationId) {
|
||||
super(baseEntity, applicationId);
|
||||
this.actionId = actionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the action id of the assignment
|
||||
*/
|
||||
public Long getActionId() {
|
||||
return actionId;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user