Changed the structure of the response body for Distribution statistics (#1397)
* changed the structure of the response body Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com> * Fixed tests Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com> * refactoring Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com> --------- Signed-off-by: Denislav Prinov <denislav.prinov@bosch.com>
This commit is contained in:
@@ -16,20 +16,19 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MgmtDistributionSetStatistics {
|
||||
private static final String TOTAL = "total";
|
||||
|
||||
@JsonProperty
|
||||
@JsonProperty("actions")
|
||||
private Map<String, Long> totalActionsPerStatus;
|
||||
|
||||
@JsonProperty
|
||||
@JsonProperty("rollouts")
|
||||
private Map<String, Long> totalRolloutsPerStatus;
|
||||
|
||||
@JsonProperty
|
||||
private Long totalAutoAssignments;
|
||||
|
||||
private MgmtDistributionSetStatistics() {
|
||||
// Private constructor to enforce the use of the builder pattern
|
||||
}
|
||||
@@ -47,14 +46,15 @@ public class MgmtDistributionSetStatistics {
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private Map<String, Long> totalActionsPerStatus;
|
||||
private Map<String, Long> totalRolloutsPerStatus;
|
||||
|
||||
private final Map<String, Long> totalActionsPerStatus;
|
||||
private final Map<String, Long> totalRolloutsPerStatus;
|
||||
private Long totalAutoAssignments;
|
||||
private final boolean fullRepresentation;
|
||||
|
||||
public Builder() {
|
||||
public Builder(boolean fullRepresentation) {
|
||||
totalActionsPerStatus = new HashMap<>();
|
||||
totalRolloutsPerStatus = new HashMap<>();
|
||||
this.fullRepresentation = fullRepresentation;
|
||||
}
|
||||
|
||||
public Builder addTotalActionPerStatus(String status, Long count) {
|
||||
@@ -76,13 +76,13 @@ public class MgmtDistributionSetStatistics {
|
||||
MgmtDistributionSetStatistics statistics = new MgmtDistributionSetStatistics();
|
||||
statistics.totalActionsPerStatus = calculateTotalWithStatus(totalActionsPerStatus);
|
||||
statistics.totalRolloutsPerStatus = calculateTotalWithStatus(totalRolloutsPerStatus);
|
||||
statistics.totalAutoAssignments = totalAutoAssignments;
|
||||
statistics.totalAutoAssignments = fullRepresentation ? (totalAutoAssignments == null ? Long.valueOf(0) : totalAutoAssignments) : totalAutoAssignments;
|
||||
return statistics;
|
||||
}
|
||||
|
||||
private Map<String, Long> calculateTotalWithStatus(Map<String, Long> statusMap) {
|
||||
if (statusMap.isEmpty()) {
|
||||
return null;
|
||||
if (!fullRepresentation && statusMap.isEmpty()) {
|
||||
return statusMap;
|
||||
}
|
||||
|
||||
long total = statusMap.values().stream().mapToLong(Long::longValue).sum();
|
||||
|
||||
@@ -417,7 +417,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtDistributionSetStatistics> getRolloutsCountByStatusForDistributionSet(Long distributionSetId) {
|
||||
MgmtDistributionSetStatistics.Builder statistics = new MgmtDistributionSetStatistics.Builder();
|
||||
MgmtDistributionSetStatistics.Builder statistics = new MgmtDistributionSetStatistics.Builder(false);
|
||||
distributionSetManagement.countRolloutsByStatusForDistributionSet(distributionSetId).forEach(statistic ->
|
||||
statistics.addTotalRolloutPerStatus(String.valueOf(statistic.getName()), Long.parseLong(statistic.getData().toString())));
|
||||
return ResponseEntity.ok(statistics.build());
|
||||
@@ -425,7 +425,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtDistributionSetStatistics> getActionsCountByStatusForDistributionSet(Long distributionSetId) {
|
||||
MgmtDistributionSetStatistics.Builder statistics = new MgmtDistributionSetStatistics.Builder();
|
||||
MgmtDistributionSetStatistics.Builder statistics = new MgmtDistributionSetStatistics.Builder(false);
|
||||
distributionSetManagement.countActionsByStatusForDistributionSet(distributionSetId).forEach(statistic ->
|
||||
statistics.addTotalActionPerStatus(String.valueOf(statistic.getName()), Long.parseLong(statistic.getData().toString())));
|
||||
return ResponseEntity.ok(statistics.build());
|
||||
@@ -433,14 +433,14 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtDistributionSetStatistics> getAutoAssignmentsCountForDistributionSet(Long distributionSetId) {
|
||||
MgmtDistributionSetStatistics.Builder statistics = new MgmtDistributionSetStatistics.Builder();
|
||||
MgmtDistributionSetStatistics.Builder statistics = new MgmtDistributionSetStatistics.Builder(false);
|
||||
statistics.addTotalAutoAssignments(distributionSetManagement.countAutoAssignmentsForDistributionSet(distributionSetId));
|
||||
return ResponseEntity.ok(statistics.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtDistributionSetStatistics> getStatisticsForDistributionSet(Long distributionSetId) {
|
||||
MgmtDistributionSetStatistics.Builder statistics = new MgmtDistributionSetStatistics.Builder();
|
||||
MgmtDistributionSetStatistics.Builder statistics = new MgmtDistributionSetStatistics.Builder(true);
|
||||
distributionSetManagement.countRolloutsByStatusForDistributionSet(distributionSetId).forEach(statistic ->
|
||||
statistics.addTotalRolloutPerStatus(String.valueOf(statistic.getName()), Long.parseLong(statistic.getData().toString())));
|
||||
distributionSetManagement.countActionsByStatusForDistributionSet(distributionSetId).forEach(statistic ->
|
||||
|
||||
@@ -1458,17 +1458,17 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/rollouts", ds1.getId()).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus.READY", equalTo(1)))
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus.RUNNING", equalTo(1)))
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus.total", equalTo(2)))
|
||||
.andExpect(jsonPath("totalActionsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("rollouts.READY", equalTo(1)))
|
||||
.andExpect(jsonPath("rollouts.RUNNING", equalTo(1)))
|
||||
.andExpect(jsonPath("rollouts.total", equalTo(2)))
|
||||
.andExpect(jsonPath("actions").doesNotExist())
|
||||
.andExpect(jsonPath("totalAutoAssignments").doesNotExist());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/rollouts", ds2.getId()).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("totalActionsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("rollouts").doesNotExist())
|
||||
.andExpect(jsonPath("actions").doesNotExist())
|
||||
.andExpect(jsonPath("totalAutoAssignments").doesNotExist());
|
||||
}
|
||||
|
||||
@@ -1488,16 +1488,16 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/actions", ds1.getId()).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("totalActionsPerStatus.RUNNING", equalTo(4)))
|
||||
.andExpect(jsonPath("totalActionsPerStatus.total", equalTo(4)))
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("actions.RUNNING", equalTo(4)))
|
||||
.andExpect(jsonPath("actions.total", equalTo(4)))
|
||||
.andExpect(jsonPath("rollouts").doesNotExist())
|
||||
.andExpect(jsonPath("totalAutoAssignments").doesNotExist());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/actions", ds2.getId()).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("totalActionsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("rollouts").doesNotExist())
|
||||
.andExpect(jsonPath("actions").doesNotExist())
|
||||
.andExpect(jsonPath("totalAutoAssignments").doesNotExist());
|
||||
}
|
||||
|
||||
@@ -1518,14 +1518,14 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("totalAutoAssignments", equalTo(2)))
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("totalActionsPerStatus").doesNotExist());
|
||||
.andExpect(jsonPath("rollouts").doesNotExist())
|
||||
.andExpect(jsonPath("actions").doesNotExist());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/autoassignments", ds2.getId()).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("totalActionsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("rollouts").doesNotExist())
|
||||
.andExpect(jsonPath("actions").doesNotExist())
|
||||
.andExpect(jsonPath("totalAutoAssignments").doesNotExist());
|
||||
}
|
||||
|
||||
@@ -1550,17 +1550,17 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("totalAutoAssignments", equalTo(1)))
|
||||
.andExpect(jsonPath("totalActionsPerStatus.RUNNING", equalTo(4)))
|
||||
.andExpect(jsonPath("totalActionsPerStatus.total", equalTo(4)))
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus.RUNNING", equalTo(1)))
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus.total", equalTo(1)));
|
||||
.andExpect(jsonPath("actions.RUNNING", equalTo(4)))
|
||||
.andExpect(jsonPath("actions.total", equalTo(4)))
|
||||
.andExpect(jsonPath("rollouts.RUNNING", equalTo(1)))
|
||||
.andExpect(jsonPath("rollouts.total", equalTo(1)));
|
||||
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/autoassignments", ds2.getId()).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("totalRolloutsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("totalActionsPerStatus").doesNotExist())
|
||||
.andExpect(jsonPath("rollouts").doesNotExist())
|
||||
.andExpect(jsonPath("actions").doesNotExist())
|
||||
.andExpect(jsonPath("totalAutoAssignments").doesNotExist());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user