Introduce action status scoped custom code (#1277)
* Allow providing a custom code with an action status feedback to give more fine grained device specific details. * Add ddi rest docs for new optional status code value. * Provide new code value via mgmt api. Fix review findings. * Fix failing tests Signed-off-by: Michael Herdt <Michael.Herdt@bosch.io> Co-authored-by: Stefan Behl <stefan.behl@bosch.io>
This commit is contained in:
@@ -20,6 +20,8 @@ final class DdiApiModelProperties {
|
||||
|
||||
static final String TARGET_EXEC_STATUS = "status of the action execution";
|
||||
|
||||
static final String TARGET_EXEC_STATUS_CODE = "optional individual status code";
|
||||
|
||||
static final String TARGET_RESULT_VALUE = "result of the action execution";
|
||||
|
||||
static final String TARGET_RESULT_DETAILS = "List of details message information";
|
||||
|
||||
@@ -185,17 +185,17 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
|
||||
final Action cancelAction = deploymentManagement.cancelAction(actionId);
|
||||
|
||||
final DdiStatus ddiStatus = new DdiStatus(DdiStatus.ExecutionStatus.CLOSED,
|
||||
new DdiResult(DdiResult.FinalResult.SUCCESS, new DdiProgress(2, 5)), List.of("Some feedback"));
|
||||
new DdiResult(DdiResult.FinalResult.SUCCESS, new DdiProgress(2, 5)), null, List.of("Some feedback"));
|
||||
final DdiActionFeedback feedback = new DdiActionFeedback(Instant.now().toString(), ddiStatus);
|
||||
|
||||
mockMvc.perform(post(
|
||||
DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.CANCEL_ACTION
|
||||
+ "/{actionId}/feedback",
|
||||
tenantAware.getCurrentTenant(), target.getControllerId(), cancelAction.getId()).content(
|
||||
objectMapper.writeValueAsString(feedback))
|
||||
tenantAware.getCurrentTenant(), target.getControllerId(), cancelAction.getId())
|
||||
.content(objectMapper.writeValueAsString(feedback))
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andDo(this.document
|
||||
.document(
|
||||
pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
|
||||
parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
|
||||
parameterWithName("actionId").description(DdiApiModelProperties.ACTION_ID_CANCELED)),
|
||||
@@ -206,6 +206,8 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
|
||||
optionalRequestFieldWithPath("time")
|
||||
.description(DdiApiModelProperties.FEEDBACK_ACTION_TIME),
|
||||
requestFieldWithPath("status").description(DdiApiModelProperties.TARGET_STATUS),
|
||||
requestFieldWithPath("status.code")
|
||||
.description(DdiApiModelProperties.TARGET_EXEC_STATUS_CODE),
|
||||
requestFieldWithPath("status.execution")
|
||||
.description(DdiApiModelProperties.TARGET_EXEC_STATUS).type("enum")
|
||||
.attributes(key("value").value(
|
||||
@@ -396,17 +398,14 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
|
||||
final Long actionId = getFirstAssignedActionId(assignDistributionSet(set.getId(), target.getControllerId()));
|
||||
|
||||
final DdiStatus ddiStatus = new DdiStatus(DdiStatus.ExecutionStatus.CLOSED,
|
||||
new DdiResult(DdiResult.FinalResult.SUCCESS, new DdiProgress(2, 5)), List.of("Feedback message"));
|
||||
new DdiResult(DdiResult.FinalResult.SUCCESS, new DdiProgress(2, 5)), 200, List.of("Feedback message"));
|
||||
final DdiActionFeedback feedback = new DdiActionFeedback(Instant.now().toString(), ddiStatus);
|
||||
|
||||
mockMvc.perform(post(
|
||||
DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/" + DdiRestConstants.DEPLOYMENT_BASE_ACTION
|
||||
+ "/{actionId}/feedback",
|
||||
tenantAware.getCurrentTenant(), target.getControllerId(), actionId)
|
||||
.content(objectMapper.writeValueAsString(feedback))
|
||||
mockMvc.perform(post(DdiRestConstants.BASE_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ DdiRestConstants.DEPLOYMENT_BASE_ACTION + "/{actionId}/feedback", tenantAware.getCurrentTenant(),
|
||||
target.getControllerId(), actionId).content(objectMapper.writeValueAsString(feedback))
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaTypes.HAL_JSON_VALUE))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()).andDo(this.document.document(
|
||||
pathParameters(parameterWithName("tenant").description(ApiModelPropertiesGeneric.TENANT),
|
||||
parameterWithName("controllerId").description(DdiApiModelProperties.CONTROLLER_ID),
|
||||
parameterWithName("actionId").description(DdiApiModelProperties.ACTION_ID)),
|
||||
@@ -418,6 +417,8 @@ public class RootControllerDocumentationTest extends AbstractApiRestDocumentatio
|
||||
optionalRequestFieldWithPath("time")
|
||||
.description(DdiApiModelProperties.FEEDBACK_ACTION_TIME),
|
||||
requestFieldWithPath("status").description(DdiApiModelProperties.TARGET_STATUS),
|
||||
requestFieldWithPath("status.code")
|
||||
.description(DdiApiModelProperties.TARGET_EXEC_STATUS_CODE),
|
||||
requestFieldWithPath("status.execution")
|
||||
.description(DdiApiModelProperties.TARGET_EXEC_STATUS).type("enum")
|
||||
.attributes(key("value").value(
|
||||
|
||||
@@ -251,6 +251,11 @@ public abstract class AbstractApiRestDocumentation extends AbstractRestIntegrati
|
||||
.addUpdateActionStatus(entityFactory.actionStatus().create(action.getId()).status(Status.FINISHED));
|
||||
}
|
||||
|
||||
protected void provideCodeFeedback(final Action action, final int code) {
|
||||
controllerManagement.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(action.getId()).code(code).status(Status.RUNNING));
|
||||
}
|
||||
|
||||
protected Target createTargetByGivenNameWithAttributes(final String name, final DistributionSet distributionSet) {
|
||||
return createTargetByGivenNameWithAttributes(name, true, false, distributionSet);
|
||||
}
|
||||
|
||||
@@ -150,6 +150,8 @@ public final class MgmtApiModelProperties {
|
||||
|
||||
public static final String ACTION_STATUS_REPORTED_AT = "Time at which the status was reported (server time).";
|
||||
|
||||
public static final String ACTION_STATUS_CODE = "(Optional) Code provided by the device related to the status.";
|
||||
|
||||
public static final String ACTION_STATUS_LIST = "List of action status.";
|
||||
|
||||
public static final String ACTION_EXECUTION_STATUS = "Status of action.";
|
||||
|
||||
@@ -462,7 +462,8 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving a specific action on a specific target. Required Permission: READ_TARGET.")
|
||||
public void getStatusFromAction() throws Exception {
|
||||
final Action action = generateActionForTarget(targetId);
|
||||
final Action action = generateActionForTarget(targetId, false);
|
||||
provideCodeFeedback(action, 200);
|
||||
|
||||
mockMvc.perform(
|
||||
get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/" + MgmtRestConstants.TARGET_V1_ACTIONS
|
||||
@@ -481,7 +482,10 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
.description(MgmtApiModelProperties.ACTION_STATUS_MESSAGES).type("String"),
|
||||
fieldWithPath("content[].reportedAt")
|
||||
.description(MgmtApiModelProperties.ACTION_STATUS_REPORTED_AT).type("String"),
|
||||
fieldWithPath("content[].type").description(MgmtApiModelProperties.ACTION_STATUS_TYPE)
|
||||
optionalRequestFieldWithPath("content[].code")
|
||||
.description(MgmtApiModelProperties.ACTION_STATUS_CODE).type("Integer"),
|
||||
fieldWithPath(
|
||||
"content[].type").description(MgmtApiModelProperties.ACTION_STATUS_TYPE)
|
||||
.attributes(key("value").value(
|
||||
"['finished', 'error', 'warning', 'pending', 'running', 'canceled', 'retrieved', 'canceling']")))));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user