-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Rollout and activate" action #19
Merged
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b06c268
[ERM-3] - Display target path even if page cannot be rolledout there.
SkoryUladzislau 5442820
[ERM-4] - Implement the "Rollout and activate" action
SkoryUladzislau d4d3c5a
[ERM-4] - Set status as failed if there was exception during replication
SkoryUladzislau a0b45b0
[ERM-4] - Implement the "Rollout and activate" action
AlKaliada 6c1dda3
[ERM-4] - Implement the "Rollout and activate" action
AlKaliada bfca6e4
[ERM-4] - Implement the "Rollout and activate" action
AlKaliada 8741aba
[ERM-4] - Implement the "Rollout and activate" action
AlKaliada e60a51e
[ERM-4] - Do not replicate blueprint locales
SkoryUladzislau 36f284d
[ERM-4] - Do not skip RolloutManager.Trigger.ROLLOUT trigger
SkoryUladzislau ebcb073
[ERM-4] - Styles improvements
AlKaliada dd84fa3
[TECH] - Update pom version
SkoryUladzislau fe31718
Merge remote-tracking branch 'origin/feature/ERM-4' into feature/ERM-4_
SkoryUladzislau 935e7d0
[ERM-4] - Update rollout-manager-dialog css styles
SkoryUladzislau a40ec82
[ERM-4] - Styles improvements
AlKaliada 6420aac
Merge remote-tracking branch 'origin/feature/ERM-4' into feature/ERM-4
AlKaliada 4cfcf90
[ERM-4] - Fixed disabled checkboxes
AlKaliada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/models/RolloutItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.exadel.etoolbox.rolloutmanager.core.models; | ||
|
||
public class RolloutItem { | ||
private String master; | ||
private String target; | ||
private int depth; | ||
boolean autoRolloutTrigger; | ||
|
||
public String getMaster() { | ||
return master; | ||
} | ||
|
||
public String getTarget() { | ||
return target; | ||
} | ||
|
||
public int getDepth() { | ||
return depth; | ||
} | ||
|
||
public boolean isAutoRolloutTrigger() { | ||
return autoRolloutTrigger; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
core/src/main/java/com/exadel/etoolbox/rolloutmanager/core/models/RolloutStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.exadel.etoolbox.rolloutmanager.core.models; | ||
|
||
public class RolloutStatus { | ||
private boolean isSuccess; | ||
private final String target; | ||
|
||
public RolloutStatus(String target) { | ||
this.target = target; | ||
} | ||
|
||
public boolean isSuccess() { | ||
return isSuccess; | ||
} | ||
|
||
public void setSuccess(boolean success) { | ||
isSuccess = success; | ||
} | ||
|
||
public String getTarget() { | ||
return target; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...rc/main/java/com/exadel/etoolbox/rolloutmanager/core/services/PageReplicationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.exadel.etoolbox.rolloutmanager.core.services; | ||
|
||
import com.day.cq.wcm.api.PageManager; | ||
import com.exadel.etoolbox.rolloutmanager.core.models.RolloutItem; | ||
import com.exadel.etoolbox.rolloutmanager.core.models.RolloutStatus; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Provides methods for checking if a live relationship can be synchronized with a blueprint in scope of usage | ||
* the rollout manager tool. | ||
*/ | ||
public interface PageReplicationService { | ||
List<RolloutStatus> replicateItems(ResourceResolver resourceResolver, RolloutItem[] items, PageManager pageManager); | ||
} |
118 changes: 118 additions & 0 deletions
118
...ava/com/exadel/etoolbox/rolloutmanager/core/services/impl/PageReplicationServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.exadel.etoolbox.rolloutmanager.core.services.impl; | ||
|
||
import com.day.cq.replication.ReplicationActionType; | ||
import com.day.cq.replication.ReplicationException; | ||
import com.day.cq.replication.Replicator; | ||
import com.day.cq.wcm.api.Page; | ||
import com.day.cq.wcm.api.PageManager; | ||
import com.day.cq.wcm.msm.api.LiveRelationshipManager; | ||
import com.exadel.etoolbox.rolloutmanager.core.models.RolloutItem; | ||
import com.exadel.etoolbox.rolloutmanager.core.models.RolloutStatus; | ||
import com.exadel.etoolbox.rolloutmanager.core.services.PageReplicationService; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.apache.sling.event.jobs.JobManager; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Reference; | ||
import org.osgi.service.metatype.annotations.AttributeDefinition; | ||
import org.osgi.service.metatype.annotations.Designate; | ||
import org.osgi.service.metatype.annotations.ObjectClassDefinition; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.jcr.Session; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Component(service = PageReplicationService.class) | ||
@Designate(ocd = PageReplicationServiceImpl.Configuration.class) | ||
public class PageReplicationServiceImpl implements PageReplicationService { | ||
private static final Logger LOG = LoggerFactory.getLogger(PageReplicationServiceImpl.class); | ||
|
||
@ObjectClassDefinition(name = "EToolbox Page Replication Service Configuration") | ||
@interface Configuration { | ||
|
||
@AttributeDefinition( | ||
name = "Pool size", | ||
description = "The number of Threads in the pool") | ||
int poolSize() default 5; | ||
} | ||
|
||
@Activate | ||
private PageReplicationServiceImpl.Configuration config; | ||
|
||
@Reference | ||
private LiveRelationshipManager liveRelationshipManager; | ||
|
||
@Reference | ||
private JobManager jobManager; | ||
|
||
@Reference | ||
private Replicator replicator; | ||
|
||
public List<RolloutStatus> replicateItems(ResourceResolver resourceResolver, RolloutItem[] items, PageManager pageManager) { | ||
return Arrays.stream(items) | ||
.collect(Collectors.groupingBy(RolloutItem::getDepth)) | ||
.entrySet() | ||
.stream() | ||
.sorted(Map.Entry.comparingByKey()) | ||
.map(Map.Entry::getValue) | ||
.flatMap(sortedByDepthItems -> replicateSortedByDepthItems(resourceResolver, sortedByDepthItems, pageManager)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private Stream<RolloutStatus> replicateSortedByDepthItems(ResourceResolver resourceResolver, List<RolloutItem> items, PageManager pageManager) { | ||
ExecutorService executorService = Executors.newFixedThreadPool(config.poolSize()); | ||
return items.stream() | ||
.filter(item -> StringUtils.isNotBlank(item.getTarget())) | ||
.map(item -> CompletableFuture.supplyAsync(() -> replicate(resourceResolver, item, pageManager), executorService)) | ||
.collect(Collectors.toList()) | ||
.stream() | ||
.map(CompletableFuture::join); | ||
} | ||
|
||
private RolloutStatus replicate(ResourceResolver resourceResolver, RolloutItem targetItem, PageManager pageManager) { | ||
|
||
String targetPath = targetItem.getTarget(); | ||
RolloutStatus status = new RolloutStatus(targetPath); | ||
|
||
Optional<Page> targetPage = Optional.ofNullable(pageManager.getPage(targetPath)); | ||
Session session = resourceResolver.adaptTo(Session.class); | ||
if (!targetPage.isPresent() || ObjectUtils.isEmpty(session)) { | ||
status.setSuccess(false); | ||
LOG.warn("Replication failed - target page is null, page path: {}", targetPath); | ||
return status; | ||
} | ||
try { | ||
replicator.replicate(session, ReplicationActionType.ACTIVATE, targetPath); | ||
} catch (ReplicationException ex) { | ||
status.setSuccess(false); | ||
LOG.error("Exception during page replication", ex); | ||
} | ||
status.setSuccess(true); | ||
return status; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...etoolbox/rolloutmanager/core/servlets/collect-expected-items-with-no-valid-live-copy.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"master": "/content/my-site/language-masters/en/testResource", | ||
"path": "/content/my-site/fr/en/testResource", | ||
"depth": 0, | ||
"liveCopies": [], | ||
"isNew": true, | ||
"autoRolloutTrigger": false, | ||
"lastRolledOut": "", | ||
"disabled": true | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❗ Need to move this inside
try
, or else the status success will be reset to "true" after set to "false"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done