Assign multiple distribution sets to a target via mgmt api (#886)
* Add multiassignment to mgmt api target endpoint * Remove single assignment ds to targets offline * Fix tests * Add quota for maxResultingActionsPerManualAssignment * Fix assignment with same target or distribution set multiple times in one request * Log UI error * Add tests * Enable single assignment requests with multiple DSs and types * Remove redundant target to DS assignment methods * Add tests, fix assignment * Fix possible nullpointer during target assignment request * Update api docu * Clean up deployment management code * Enforce MaxActions quota for offline assignment * Fix review findings * Rename property, add migration into * Add builder for DeploymentRequest * Change offline assignment method to accept an assignment list, like online assignment * Fix PR findings Signed-off-by: Stefan Klotz <stefan.klotz@bosch-si.com>
This commit is contained in:
committed by
Stefan Behl
parent
dba972423b
commit
8687510131
@@ -8,8 +8,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.json.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* A generic abstract rest model which contains only a ID for use-case e.g.
|
||||
@@ -19,12 +19,28 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MgmtId {
|
||||
|
||||
@JsonProperty
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public MgmtId() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
* Constructor
|
||||
*
|
||||
* @param id
|
||||
* ID of object
|
||||
*/
|
||||
@JsonCreator
|
||||
public MgmtId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the ID
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -32,7 +48,7 @@ public class MgmtId {
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* the id to set
|
||||
* the ID to set
|
||||
*/
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.mgmt.json.model.distributionset;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMaintenanceWindowRequestBody;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@@ -20,18 +21,21 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MgmtTargetAssignmentRequestBody {
|
||||
|
||||
@JsonProperty
|
||||
private String id;
|
||||
|
||||
private long forcetime;
|
||||
|
||||
private MgmtActionType type;
|
||||
private MgmtMaintenanceWindowRequestBody maintenanceWindow;
|
||||
|
||||
/**
|
||||
* {@link MgmtMaintenanceWindowRequestBody} object containing schedule,
|
||||
* duration and timezone.
|
||||
* JsonCreator Constructor
|
||||
*
|
||||
* @param id
|
||||
* Mandatory ID of the target that should be assigned
|
||||
*/
|
||||
private MgmtMaintenanceWindowRequestBody maintenanceWindow;
|
||||
@JsonCreator
|
||||
public MgmtTargetAssignmentRequestBody(@JsonProperty(required = true, value = "id") final String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
|
||||
@@ -18,5 +18,4 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MgmtSoftwareModuleTypeAssigment extends MgmtId {
|
||||
|
||||
}
|
||||
|
||||
@@ -7,19 +7,29 @@ import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMaintenanceWindowRequestBody;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Request Body of DistributionSet for assignment operations (ID only).
|
||||
*
|
||||
*/
|
||||
public class MgmtDistributionSetAssignment extends MgmtId {
|
||||
|
||||
private long forcetime;
|
||||
private MgmtActionType type;
|
||||
private MgmtMaintenanceWindowRequestBody maintenanceWindow;
|
||||
|
||||
/**
|
||||
* {@link MgmtMaintenanceWindowRequestBody} object defining a schedule,
|
||||
* duration and timezone.
|
||||
* Constructor
|
||||
*
|
||||
* @param id
|
||||
* ID of object
|
||||
*/
|
||||
private MgmtMaintenanceWindowRequestBody maintenanceWindow;
|
||||
@JsonCreator
|
||||
public MgmtDistributionSetAssignment(@JsonProperty(required = true, value = "id") final Long id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public MgmtActionType getType() {
|
||||
return type;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2019 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.mgmt.json.model.target;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
|
||||
/**
|
||||
* Class to hold multiple distribution set assignments. A JSON object
|
||||
* representing a single {@link MgmtDistributionSetAssignment} can be
|
||||
* deserialized to an object of this class.
|
||||
*/
|
||||
@JsonDeserialize(using = MgmtDistributionSetAssignmentsDeserializer.class)
|
||||
public class MgmtDistributionSetAssignments extends ArrayList<MgmtDistributionSetAssignment> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Constructor for an object that contains no distribution set assignment
|
||||
*
|
||||
*/
|
||||
public MgmtDistributionSetAssignments() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for an object that contains a single distribution set
|
||||
* assignment
|
||||
*
|
||||
* @param assignment
|
||||
* the assignment
|
||||
*/
|
||||
public MgmtDistributionSetAssignments(final MgmtDistributionSetAssignment assignment) {
|
||||
super();
|
||||
add(assignment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for an object that contains multiple distribution set
|
||||
* assignments
|
||||
*
|
||||
* @param assignments
|
||||
* the assignments
|
||||
*/
|
||||
public MgmtDistributionSetAssignments(final List<MgmtDistributionSetAssignment> assignments) {
|
||||
super(assignments);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Copyright (c) 2019 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.mgmt.json.model.target;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
|
||||
/**
|
||||
* Deserializes a single object or a List of
|
||||
* {@link MgmtDistributionSetAssignment}s
|
||||
*/
|
||||
public class MgmtDistributionSetAssignmentsDeserializer extends StdDeserializer<MgmtDistributionSetAssignments> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Mandatory constructor
|
||||
*/
|
||||
public MgmtDistributionSetAssignmentsDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
protected MgmtDistributionSetAssignmentsDeserializer(final Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MgmtDistributionSetAssignments deserialize(final JsonParser jp, final DeserializationContext ctx)
|
||||
throws IOException {
|
||||
final MgmtDistributionSetAssignments assignments = new MgmtDistributionSetAssignments();
|
||||
final ObjectCodec codec = jp.getCodec();
|
||||
final JsonNode node = codec.readTree(jp);
|
||||
if (node.isArray()) {
|
||||
assignments.addAll(Arrays.asList(codec.treeToValue(node, MgmtDistributionSetAssignment[].class)));
|
||||
} else {
|
||||
assignments.add(codec.treeToValue(node, MgmtDistributionSetAssignment.class));
|
||||
}
|
||||
return assignments;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import org.eclipse.hawkbit.mgmt.json.model.action.MgmtActionRequestBodyPut;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.action.MgmtActionStatus;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentResponseBody;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtDistributionSetAssignment;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtDistributionSetAssignments;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetAttributes;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
|
||||
@@ -261,8 +261,8 @@ public interface MgmtTargetRestApi {
|
||||
*
|
||||
* @param targetId
|
||||
* of the target to change
|
||||
* @param dsId
|
||||
* of the distributionset that is to be assigned
|
||||
* @param dsAssignments
|
||||
* the requested Assignments that shall be made
|
||||
* @param offline
|
||||
* to <code>true</code> if update was executed offline, i.e. not
|
||||
* managed by hawkBit.
|
||||
@@ -275,7 +275,7 @@ public interface MgmtTargetRestApi {
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<MgmtTargetAssignmentResponseBody> postAssignedDistributionSet(
|
||||
@PathVariable("targetId") String targetId, MgmtDistributionSetAssignment dsId,
|
||||
@PathVariable("targetId") String targetId, MgmtDistributionSetAssignments dsAssignments,
|
||||
@RequestParam(value = "offline", required = false) boolean offline);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user