Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<embedded>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-link-inspector.ui.apps</artifactId>
<type>zip</type>
<target>/apps/etoolbox-link-inspector-packages/application/install</target>
</embedded>
<embedded>
Expand All @@ -56,15 +55,18 @@
<embedded>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-link-inspector.ui.content</artifactId>
<type>zip</type>
<target>/apps/etoolbox-link-inspector-packages/content/install</target>
</embedded>
<embedded>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-link-inspector.ui.config</artifactId>
<type>zip</type>
<target>/apps/etoolbox-link-inspector-packages/application/install</target>
</embedded>
<embedded>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-contractor.all</artifactId>
<target>/apps/etoolbox-link-inspector-packages/lib/install</target>
</embedded>
</embeddeds>
</configuration>
</plugin>
Expand Down Expand Up @@ -146,6 +148,11 @@
<version>${project.version}</version>
<type>zip</type>
</dependency>

<dependency>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-contractor.all</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>zip</type>
</dependency>
</dependencies>
</project>
7 changes: 7 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ Import-Package: javax.annotation;version=0.0.0,*
<artifactId>jackson-core</artifactId>
<scope>test</scope>
</dependency>

<!-- Other dependencies -->
<dependency>
<groupId>com.exadel.etoolbox</groupId>
<artifactId>etoolbox-contractor.core</artifactId>
</dependency>

<!-- Adobe AEM Dependencies -->
<dependency>
<groupId>com.adobe.aem</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.exadel.etoolbox.linkinspector.core.models.ui;

import com.exadel.etoolbox.linkinspector.core.services.data.GridResourcesGenerator;
import lombok.Getter;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.sling.api.resource.Resource;
Expand All @@ -38,26 +39,30 @@
adaptables = Resource.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class StatsModal {
public class StatsModel {
private static final String ARRAY_VALUES_SEPARATOR = ", ";
private static final String ALL_STATUS_CODES_MSG = "All error codes outside the range '200-207'";

@ValueMapValue
@Getter
private String lastGenerated;

@ValueMapValue
@Getter
private String searchPath;

@ValueMapValue
private String[] excludedPaths;

@ValueMapValue
@Getter
private boolean checkActivation;

@ValueMapValue
private boolean skipModifiedAfterActivation;

@ValueMapValue
@Getter
private String lastModifiedBoundary;

@ValueMapValue
Expand All @@ -67,6 +72,7 @@ public class StatsModal {
private String[] excludedLinksPatterns;

@ValueMapValue
@Getter
private String excludeTags;

@ValueMapValue
Expand All @@ -76,30 +82,14 @@ public class StatsModal {
private String[] statistics;


public String getLastGenerated() {
return lastGenerated;
}

public String getSearchPath() {
return searchPath;
}

public String getExcludedPaths() {
return arrayToStringValue(excludedPaths);
}

public boolean getCheckActivation() {
return checkActivation;
}

public boolean getSkipModifiedAfterActivation() {
return checkActivation && skipModifiedAfterActivation;
}

public String getLastModifiedBoundary() {
return lastModifiedBoundary;
}

public String getExcludedProperties() {
return arrayToStringValue(excludedProperties);
}
Expand All @@ -108,10 +98,6 @@ public String getExcludedLinksPatterns() {
return arrayToStringValue(excludedLinksPatterns);
}

public String getExcludeTags() {
return excludeTags;
}

/**
* Represents the value of the 'Status codes' field from the {@link GridResourcesGenerator} configuration used
* during data feed generation
Expand Down Expand Up @@ -147,6 +133,10 @@ public Map<String, String> getStatistics() {
LinkedHashMap::new));
}

public boolean isValid() {
return StringUtils.isNotBlank(lastGenerated) && StringUtils.isNotBlank(searchPath);
}

/**
* Transforms array of Strings to a single comma separated String
* @param stringArray - the input array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

package com.exadel.etoolbox.linkinspector.core.schedulers;

import com.exadel.etoolbox.contractor.ContractorException;
import com.exadel.etoolbox.contractor.service.tasking.Contractor;
import com.exadel.etoolbox.linkinspector.core.services.job.DataFeedJobExecutor;
import com.exadel.etoolbox.linkinspector.core.services.job.SlingJobUtil;
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.Deactivate;
Expand All @@ -39,22 +39,18 @@ public class DataFeedGenerationTask implements Runnable {
@ObjectClassDefinition(name = "EToolbox Link Inspector - Data Feed Generation Task")
public @interface Config {

@AttributeDefinition(name = "Cron-job expression")
@AttributeDefinition(name = "Cron expression")
String scheduler_expression() default "0 0 5 1/1 * ? *";

@AttributeDefinition(name = "Concurrent task",
description = "Whether or not to schedule this task concurrently")
boolean scheduler_concurrent() default false;

@AttributeDefinition(name = "Enabled",
description = "Whether or not to enable this task")
description = "Whether to enable this task")
boolean enabled() default false;
}

private static final Logger LOG = LoggerFactory.getLogger(DataFeedGenerationTask.class);

@Reference
private JobManager jobManager;
private Contractor contractor;

private boolean enabled;

Expand All @@ -67,8 +63,12 @@ public void run() {
LOG.debug("The Data Feed Generation scheduled task is not enabled");
return;
}
LOG.debug("The Data Feed Generation scheduled task started");
SlingJobUtil.addJob(jobManager, DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC, Collections.emptyMap());
LOG.debug("The Data Feed Generation scheduled task is going to start");
try {
contractor.runExclusive(DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC);
} catch (ContractorException e) {
LOG.error("An error occurred while running the scheduled Data Feed Generation task", e);
}
}

/**
Expand All @@ -87,6 +87,6 @@ protected void activate(Config config) {
protected void deactivate() {
LOG.debug("Deactivating DataFeedGenerationTask, sling jobs with the topic {} will be stopped and removed",
DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC);
SlingJobUtil.stopAndRemoveJobs(jobManager, DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC);
contractor.discardAll(DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

package com.exadel.etoolbox.linkinspector.core.services.data;

import com.exadel.etoolbox.linkinspector.core.models.ui.StatsModel;

/**
* Lists the JCR property names for generation statistics data written
* by {@link GridResourcesGenerator#generateGridResources}. Further, these property names are used to map the statistics
* values to the {@link com.exadel.etoolbox.linkinspector.core.models.ui.StatsModal} fields
* values to the {@link StatsModel} fields
*/
public final class GenerationStatsProps {
private GenerationStatsProps() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,26 @@
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationStatus;
import com.day.crx.JcrConstants;
import com.exadel.etoolbox.contractor.entity.Context;
import com.exadel.etoolbox.contractor.service.tasking.Contractor;
import com.exadel.etoolbox.linkinspector.api.Link;
import com.exadel.etoolbox.linkinspector.core.services.data.GenerationStatsProps;
import com.exadel.etoolbox.linkinspector.core.services.data.GridResourcesGenerator;
import com.exadel.etoolbox.linkinspector.core.services.data.ConfigService;
import com.exadel.etoolbox.linkinspector.core.services.helpers.LinkHelper;
import com.exadel.etoolbox.linkinspector.core.services.data.models.GridResource;
import com.exadel.etoolbox.linkinspector.core.services.job.DataFeedJobExecutor;
import com.exadel.etoolbox.linkinspector.core.services.util.LinkInspectorResourceUtil;
import com.exadel.etoolbox.linkinspector.core.services.util.LinksCounter;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.jcr.resource.api.JcrResourceConstants;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
Expand Down Expand Up @@ -68,6 +73,8 @@ public class GridResourcesGeneratorImpl implements GridResourcesGenerator {
private LinkHelper linkHelper;
@Reference
private ConfigService configService;
@Reference
private Contractor contractor;

private ExecutorService executorService;

Expand All @@ -77,21 +84,35 @@ public class GridResourcesGeneratorImpl implements GridResourcesGenerator {
@Override
public List<GridResource> generateGridResources(String gridResourceType, ResourceResolver resourceResolver) {
StopWatch stopWatch = StopWatch.createStarted();

String searchPath = configService.getSearchPath();
LOG.debug("Start broken links collecting, path: {}", searchPath);
Map<Link, List<GridResource>> linkToGridResourcesMap;

try (Context context = contractor.newJobContext(
DataFeedJobExecutor.GENERATE_DATA_FEED_TOPIC,
"Scanning " + searchPath)) {

LOG.debug("Start broken links collecting, path: {}", searchPath);
Resource rootResource = resourceResolver.getResource(searchPath);
if (rootResource == null) {
LOG.warn("Search path resource is null, link inspector report generation is stopped");
context.feedback().state(Job.JobState.DROPPED).message("Search path resource not found").send();
return Collections.emptyList();
}

Resource rootResource = resourceResolver.getResource(searchPath);
if (rootResource == null) {
LOG.warn("Search path resource is null, link inspector report generation is stopped");
return Collections.emptyList();
}
linkToGridResourcesMap = new HashMap<>();
int traversedNodesCounter = getGridResourcesViaTraversing(
rootResource,
gridResourceType,
linkToGridResourcesMap,
context);

Map<Link, List<GridResource>> linkToGridResourcesMap = new HashMap<>();
int traversedNodesCounter = getGridResourcesViaTraversing(rootResource, gridResourceType, linkToGridResourcesMap);
LOG.debug("Traversal is completed in {} ms, path: {}, traversed nodes count: {}",
stopWatch.getTime(TimeUnit.MILLISECONDS), searchPath, traversedNodesCounter);
LOG.info("Traversal is completed in {} ms, path: {}, traversed nodes count: {}",
stopWatch.getTime(TimeUnit.MILLISECONDS), searchPath, traversedNodesCounter);
context.feedback("Completed");
}

if (linkToGridResourcesMap.isEmpty()) {
if (MapUtils.isEmpty(linkToGridResourcesMap)) {
LOG.warn("Collecting reported links is completed in {} ms, path: {}. No links reported after traversing",
stopWatch.getTime(TimeUnit.MILLISECONDS), searchPath);
LinksCounter emptyCounter = new LinksCounter();
Expand All @@ -113,7 +134,9 @@ public List<GridResource> generateGridResources(String gridResourceType, Resourc

private int getGridResourcesViaTraversing(Resource resource,
String gridResourceType,
Map<Link, List<GridResource>> allLinkToGridResourcesMap) {
Map<Link, List<GridResource>> allLinkToGridResourcesMap,
Context context) {
context.feedback("Scanning {}", resource.getPath());
int traversedNodesCount = 0;
if (!isAllowedResource(resource)) {
return traversedNodesCount;
Expand All @@ -129,7 +152,7 @@ private int getGridResourcesViaTraversing(Resource resource,
Iterator<Resource> children = resource.listChildren();
while (children.hasNext()) {
Resource child = children.next();
traversedNodesCount += getGridResourcesViaTraversing(child, gridResourceType, allLinkToGridResourcesMap);
traversedNodesCount += getGridResourcesViaTraversing(child, gridResourceType, allLinkToGridResourcesMap, context);
}
return traversedNodesCount;
}
Expand Down
Loading