Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
adantsou committed Dec 28, 2021
2 parents 0a2198a + 8aa02cb commit 02e1add
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected void doPost(final SlingHttpServletRequest request, final SlingHttpServ
private void writeStatusesIfFailed(List<RolloutStatus> rolloutStatuses, SlingHttpServletResponse response) {
List<String> failedTargets = rolloutStatuses.stream()
.filter(status -> !status.isSuccess())
.flatMap(status -> status.getTargets().stream())
.map(RolloutStatus::getTarget)
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(failedTargets)) {
LOG.debug("Rollout failed for the following targets: {}", failedTargets);
Expand All @@ -136,49 +136,40 @@ private List<RolloutStatus> doItemsRollout(RolloutItem[] items, PageManager page

private Stream<RolloutStatus> rolloutSortedByDepthItems(List<RolloutItem> items, PageManager pageManager, boolean isDeep) {
return items.stream()
.collect(Collectors.groupingBy(RolloutItem::getMaster))
.entrySet()
.stream()
.map(masterToTargets -> rollout(masterToTargets.getKey(), masterToTargets.getValue(), pageManager, isDeep));
.filter(item -> StringUtils.isNotBlank(item.getTarget()))
.map(item -> rollout(item, pageManager, isDeep));
}

private RolloutStatus rollout(String masterPath, List<RolloutItem> targetItems, PageManager pageManager, boolean isDeep) {
RolloutStatus status = new RolloutStatus();

List<String> targetPaths = rolloutItemsToTargetPaths(targetItems);
status.setTargets(targetPaths);
private RolloutStatus rollout(RolloutItem targetItem, PageManager pageManager, boolean isDeep) {
String targetPath = targetItem.getTarget();
RolloutStatus status = new RolloutStatus(targetPath);

String masterPath = targetItem.getMaster();
Optional<Page> masterPage = Optional.ofNullable(pageManager.getPage(masterPath));
if (!masterPage.isPresent() || CollectionUtils.isEmpty(targetPaths)) {
if (!masterPage.isPresent()) {
status.setSuccess(false);
LOG.warn("Rollout failed - master page is null or targets are empty, master page path: {}", masterPath);
LOG.warn("Rollout failed - master page is null, master page path: {}", masterPath);
return status;
}

RolloutManager.RolloutParams params = toRolloutParams(masterPage.get(), targetPaths, isDeep);
RolloutManager.RolloutParams params = toRolloutParams(masterPage.get(), targetPath, isDeep);
try {
LOG.debug(getRolloutLogMessage("Item rollout started", masterPath, params.targets));
LOG.debug("Item rollout started, master: {}, target: {}", masterPath, targetPath);
rolloutManager.rollout(params);
status.setSuccess(true);
LOG.debug(getRolloutLogMessage("Item rollout completed", masterPath, params.targets));
LOG.debug("Item rollout completed, master: {}, target: {}", masterPath, targetPath);
} catch (WCMException e) {
status.setSuccess(false);
LOG.error(getRolloutLogMessage("Item rollout failed", masterPath, params.targets), e);
String message = String.format("Item rollout failed, master: %s, target: %s", masterPath, targetPath);
LOG.error(message, e);
}
return status;
}

private List<String> rolloutItemsToTargetPaths(List<RolloutItem> items) {
return items.stream()
.map(RolloutItem::getTarget)
.filter(StringUtils::isNotBlank)
.collect(Collectors.toList());
}

private RolloutManager.RolloutParams toRolloutParams(Page masterPage, List<String> targetPaths, boolean isDeep) {
private RolloutManager.RolloutParams toRolloutParams(Page masterPage, String targetPath, boolean isDeep) {
RolloutManager.RolloutParams params = new RolloutManager.RolloutParams();
params.master = masterPage;
params.targets = targetPaths.toArray(new String[0]);
params.targets = new String[]{targetPath};
params.isDeep = isDeep;
params.trigger = RolloutManager.Trigger.ROLLOUT;
return params;
Expand All @@ -193,10 +184,6 @@ private RolloutItem[] jsonArrayToRolloutItems(String jsonArray) {
return new RolloutItem[0];
}

private String getRolloutLogMessage(String completionMsg, String masterPath, String[] targets) {
return String.format("%s, master: %s, targets: %s", completionMsg, masterPath, Arrays.toString(targets));
}

private static class RolloutItem {
private String master;
private String target;
Expand All @@ -217,7 +204,11 @@ public int getDepth() {

private static class RolloutStatus {
private boolean isSuccess;
private List<String> targets;
private final String target;

public RolloutStatus(String target) {
this.target = target;
}

public boolean isSuccess() {
return isSuccess;
Expand All @@ -227,12 +218,8 @@ public void setSuccess(boolean success) {
isSuccess = success;
}

public List<String> getTargets() {
return targets;
}

public void setTargets(List<String> targets) {
this.targets = targets;
public String getTarget() {
return target;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void doPost_RolloutTargets_Success() throws IOException, WCMException {

fixture.doPost(request, response);

verify(rolloutManager, times(3)).rollout(any(RolloutManager.RolloutParams.class));
verify(rolloutManager, times(6)).rollout(any(RolloutManager.RolloutParams.class));

assertEquals(HttpStatus.SC_OK, response.getStatus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@

.rollout-manager-logger-dialog .coral3-Dialog-wrapper {
width: 500px;
height: 165px;
height: auto;
}

0 comments on commit 02e1add

Please sign in to comment.