ManagementApi: Action does not have property containing rollout name (#1116)
* Mgmt Rest API: Enhance Action payload with rollout properties Signed-off-by: Stefan Behl <stefan.behl@bosch.io> * Enhance Mgmt REST API docs Signed-off-by: Stefan Behl <stefan.behl@bosch.io> * Minor changes Signed-off-by: Stefan Behl <stefan.behl@bosch.io>
This commit is contained in:
@@ -28,6 +28,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.ActionStatusFields;
|
||||
@@ -39,6 +40,7 @@ import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.PollStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetMetadata;
|
||||
import org.eclipse.hawkbit.rest.data.ResponseList;
|
||||
@@ -215,6 +217,12 @@ public final class MgmtTargetMapper {
|
||||
result.setStatus(MgmtAction.ACTION_FINISHED);
|
||||
}
|
||||
|
||||
Rollout rollout = action.getRollout();
|
||||
if (rollout != null) {
|
||||
result.setRollout(rollout.getId());
|
||||
result.setRolloutName(rollout.getName());
|
||||
}
|
||||
|
||||
if (action.hasMaintenanceSchedule()) {
|
||||
final MgmtMaintenanceWindow maintenanceWindow = new MgmtMaintenanceWindow();
|
||||
maintenanceWindow.setSchedule(action.getMaintenanceWindowSchedule());
|
||||
@@ -248,6 +256,12 @@ public final class MgmtTargetMapper {
|
||||
ActionStatusFields.ID.getFieldName() + ":" + SortDirection.DESC))
|
||||
.withRel(MgmtRestConstants.TARGET_V1_ACTION_STATUS));
|
||||
|
||||
final Rollout rollout = action.getRollout();
|
||||
if (rollout != null) {
|
||||
result.add(linkTo(methodOn(MgmtRolloutRestApi.class).getRollout(rollout.getId()))
|
||||
.withRel(MgmtRestConstants.TARGET_V1_ROLLOUT));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
@@ -51,6 +52,7 @@ import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetMetadata;
|
||||
@@ -2039,5 +2041,38 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("An action provides information of the rollout it was created for (if any).")
|
||||
public void getActionWithRolloutInfo() throws Exception {
|
||||
|
||||
// setup
|
||||
final int amountTargets = 10;
|
||||
final List<Target> targets = testdataFactory.createTargets(amountTargets, "trg", "trg");
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
|
||||
final Rollout rollout = testdataFactory.createRolloutByVariables("My Rollout", "My Rollout Description", 1,
|
||||
"name==trg*", ds, "50", "5");
|
||||
rolloutManagement.start(rollout.getId());
|
||||
rolloutManagement.handleRollouts();
|
||||
|
||||
// get all actions for the first target
|
||||
final Target target = targets.get(0);
|
||||
mvc.perform(get("/rest/v1/targets/{targetId}/actions", target.getControllerId())).andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(jsonPath("content.[0].rollout", equalTo(rollout.getId().intValue())))
|
||||
.andExpect(jsonPath("content.[0].rolloutName", equalTo(rollout.getName())));
|
||||
|
||||
// get the first action for the first target;
|
||||
// verify that also the rollout link is present
|
||||
final Slice<Action> action = deploymentManagement.findActionsByTarget(target.getControllerId(),
|
||||
PageRequest.of(0, 100));
|
||||
assertThat(action.getContent()).hasSize(1);
|
||||
mvc.perform(get("/rest/v1/targets/{targetId}/actions/{actionId}", target.getControllerId(),
|
||||
action.getContent().get(0).getId())).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(jsonPath("$.rollout", equalTo(rollout.getId().intValue())))
|
||||
.andExpect(jsonPath("$.rolloutName", equalTo(rollout.getName()))).andExpect(jsonPath(
|
||||
"$._links.rollout.href", containsString("/rest/v1/rollouts/" + rollout.getId().intValue())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user