Skip to content
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

Code cleanup and split off responsibilities for validation and node transaction tracking #63

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
eu.xenit.alfresco.processor.task.cron=* * * * * ? 2099
eu.xenit.alfresco.processor.task.delay=0
eu.xenit.alfresco.processor.enabled=true
eu.xenit.alfresco.processor.tracking.threadpool-size=5
eu.xenit.alfresco.processor.tracking.enabled=true
eu.xenit.alfresco.processor.run-once=true
eu.xenit.alfresco.processor.scope=ALL
eu.xenit.alfresco.processor.run-once=false
eu.xenit.alfresco.processor.transaction.start=1
eu.xenit.alfresco.processor.transaction.limit=1000
eu.xenit.alfresco.processor.transaction.time.increment=15
eu.xenit.alfresco.processor.transaction.time.start=2020-10-08
eu.xenit.alfresco.processor.transaction.time.start=2020-11-26
eu.xenit.alfresco.processor.validation.content.type-filter={http://www.alfresco.org/model/content/1.0}content
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
<constructor-arg name="processorService" ref="healthProcessorPlatform.proxy"/>
</bean>

<bean id="eu.xenit.alfresco.processor.tasks.processorTaskScheduler.jobDetail"
<bean id="eu.xenit.alfresco.processor.tasks.processorTask.jobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="name" value="healthProcessorTask" />
<property name="targetObject" ref="eu.xenit.alfresco.processor.processorTask"/>
<property name="targetMethod" value="execute"/>
</bean>

<bean id="eu.xenit.alfresco.processor.tasks.processorTaskScheduler.trigger"
<bean id="eu.xenit.alfresco.processor.tasks.processorTask.trigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="name" value="healthProcessorTrigger" />
<property name="jobDetail" ref="eu.xenit.alfresco.processor.tasks.processorTaskScheduler.jobDetail"/>
<property name="jobDetail" ref="eu.xenit.alfresco.processor.tasks.processorTask.jobDetail"/>
<property name="cronExpression">
<value>${eu.xenit.alfresco.processor.task.cron}</value>
</property>
Expand All @@ -28,12 +28,11 @@
</property>
</bean>

<bean id="eu.xenit.alfresco.processor.tasks.scheduler"
class="org.springframework.scheduling.quartz.SchedulerAccessorBean">
<bean id="eu.xenit.alfresco.processor.tasks.processorTask.scheduler" class="org.springframework.scheduling.quartz.SchedulerAccessorBean">
<property name="scheduler" ref="schedulerFactory"/>
<property name="triggers">
<list>
<ref bean="eu.xenit.alfresco.processor.tasks.processorTaskScheduler.trigger"/>
<ref bean="eu.xenit.alfresco.processor.tasks.processorTask.trigger"/>
</list>
</property>
</bean>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Ignore indexing by node type or by node aspects -->

<bean id="eu.xenit.alfresco.search.abstractIndexFilter" abstract="true" init-method="init" >
<property name="namespaceService" ref="namespaceService"/>
<property name="dictionaryService" ref="dictionaryService"/>
</bean>

<bean id="eu.xenit.alfresco.search.TypeIndexFilter"
class="org.alfresco.repo.search.TypeIndexFilter"
parent="eu.xenit.alfresco.search.abstractIndexFilter">
<property name="ignorePathsForSpecificTypes">
<value>${search.solrTrackingSupport.ignorePathsForSpecificTypes:false}</value>
</property>
<property name="typesForIgnoringPaths">
<list>
<value>{http://www.alfresco.org/model/content/1.0}person</value>
<value>{http://www.alfresco.org/model/application/1.0}configurations</value>
<value>{http://www.alfresco.org/model/content/1.0}authorityContainer</value>
</list>
</property>
</bean>

<bean id="eu.xenit.alfresco.search.AspectIndexFilter"
class="org.alfresco.repo.search.AspectIndexFilter"
parent="eu.xenit.alfresco.search.abstractIndexFilter">
<property name="ignorePathsForSpecificAspects">
<value>${search.solrTrackingSupport.ignorePathsForSpecificAspects:false}</value>
</property>
<property name="aspectsForIgnoringPaths">
<list></list>
</property>
</bean>

<bean id="eu.xenit.alfresco.search.solrTrackingComponent"
class="org.alfresco.repo.solr.SOLRTrackingComponentImpl"
init-method="init">
<property name="permissionService" ref="permissionService"/>
<property name="dictionaryService" ref="dictionaryService"/>
<property name="ownableService" ref="ownableService"/>
<property name="tenantService" ref="tenantService"/>
<property name="nodeDAO" ref="nodeDAO"/>
<property name="qnameDAO" ref="qnameDAO"/>
<property name="solrDAO" ref="solrDAO" />
<property name="dictionaryDAO" ref="dictionaryDAO" />
<property name="aclDAO" ref="aclDAO" />
<property name="enabled">
<value>${eu.xenit.alfresco.processor.tracking.enabled:true}</value>
</property>
<property name="typeIndexFilter" ref="eu.xenit.alfresco.search.TypeIndexFilter" />
<property name="aspectIndexFilter" ref="eu.xenit.alfresco.search.AspectIndexFilter" />
<property name="namespaceService" ref="namespaceService" />
</bean>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@
<constructor-arg name="attributeService" ref="attributeService"/>
<constructor-arg name="descriptorService" ref="descriptorComponent"/>
</bean>
<bean id="eu.xenit.alfresco.processor.service.progressTracker"
class="eu.xenit.alfresco.processor.service.ProgressTracker">
<constructor-arg name="tracker" ref="eu.xenit.alfresco.search.solrTrackingComponent"/>
</bean>
<bean id="eu.xenit.alfresco.processor.service.nodeTxService"
class="eu.xenit.alfresco.processor.service.NodeTxService">
<constructor-arg name="tracker" ref="eu.xenit.alfresco.search.solrTrackingComponent"/>
</bean>
<bean id="eu.xenit.alfresco.processor.service.cycleService"
class="eu.xenit.alfresco.processor.service.CycleService">
<constructor-arg name="retryingTransactionHelper" ref="retryingTransactionHelper"/>
<constructor-arg name="progressTracker" ref="eu.xenit.alfresco.processor.service.progressTracker"/>
<constructor-arg name="nodeTxService" ref="eu.xenit.alfresco.processor.service.nodeTxService"/>
<constructor-arg name="validationService" ref="eu.xenit.alfresco.processor.service.validationService"/>
</bean>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<property name="sourceBeanName" value="healthProcessorPlatform"/>
<property name="interfaces">
<list>
<value>eu.xenit.alfresco.processor.service.ProcessorService</value>
<value>eu.xenit.alfresco.processor.service.IProcessorService</value>
</list>
</property>
</bean>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="eu.xenit.alfresco.processor.modules.contentExistenceValidator"
class="eu.xenit.alfresco.processor.modules.ContentExistenceValidator"
init-method="initialize">
<constructor-arg name="filterType">
<value>${eu.xenit.alfresco.processor.validation.content.type-filter}</value>
</constructor-arg>
<constructor-arg name="contentService" ref="contentService"/>
<constructor-arg name="nodeService" ref="nodeService"/>
<constructor-arg name="dictionaryService" ref="dictionaryService"/>
</bean>
<bean id="eu.xenit.alfresco.processor.service.validationService"
class="eu.xenit.alfresco.processor.service.ValidationService">
<constructor-arg name="nodeValidators">
<list>
<ref bean="eu.xenit.alfresco.processor.modules.contentExistenceValidator" />
</list>
</constructor-arg >
</bean>
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="classpath:alfresco/module/alfresco-health-processor/context/validation-context.xml" />
<import resource="classpath:alfresco/module/alfresco-health-processor/context/search-context.xml" />
<import resource="classpath:alfresco/module/alfresco-health-processor/context/service-context.xml" />
<import resource="classpath:alfresco/module/alfresco-health-processor/context/subsystem-context.xml" />
<import resource="classpath:alfresco/module/alfresco-health-processor/context/job-scheduling-context.xml" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
<bean id="healthProcessorPlatform"
class="eu.xenit.alfresco.processor.service.ProcessorService">
<constructor-arg name="retryingTransactionHelper" ref="retryingTransactionHelper" />
<constructor-arg name="configurationService" ref="eu.xenit.alfresco.processor.service.healthProcessorConfiguration"/>
<constructor-arg name="configuration" ref="eu.xenit.alfresco.processor.service.healthProcessorConfiguration"/>
<constructor-arg name="processorAttributeService" ref="eu.xenit.alfresco.processor.service.processorAttributeService"/>
<constructor-arg name="cycleService" ref="eu.xenit.alfresco.processor.service.cycleService"/>
<constructor-arg name="executorService">
<bean class="java.util.concurrent.Executors" factory-method="newFixedThreadPool">
<constructor-arg>
<value>${eu.xenit.alfresco.processor.tracking.threadpool-size}</value>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package eu.xenit.alfresco.processor.model;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
* Information object containing the parameters for the tracking activity.
*/
@Data
@AllArgsConstructor
public class Cycle {
private int txnLimit;
private long firstTxn;
private int timeIncrementSeconds;
private long firstCommitTime;
private TrackerInfo trackerInfo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package eu.xenit.alfresco.processor.model;

import lombok.Data;

import java.time.OffsetDateTime;

/**
* Information object to save the state of the tracking activity. The state is persisted to allow for the correct
* continuation after a restart of the system.
*/
@Data
public class TrackerInfo {
/**
* Timestamp of the last action
*/
private OffsetDateTime timestamp;
/**
* Id of the last transaction processed by the tracker
*/
private Long transactionId;
/**
* Highest commit time in ms of processed transaction
*/
private Long commitTimeMs = -1L;
/**
* Name of the artifact running this tracker software
*/
private String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package eu.xenit.alfresco.processor.modules;

import lombok.RequiredArgsConstructor;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.InvalidParameterException;

@RequiredArgsConstructor
public class ContentExistenceValidator implements NodeValidator {
private static final Logger logger = LoggerFactory.getLogger(ContentExistenceValidator.class);

private QName filterTypeQName = null;

protected final String filterType;

protected final ContentService contentService;

protected final NodeService nodeService;

protected final DictionaryService dictionaryService;

ContentExistenceValidator initialize() {
filterTypeQName = QName.createQName(filterType);
return this;
}

@Override
public boolean validate(NodeRef nodeRef) {
logger.trace(">>> Entering ContentExistenceValidator.validate()");
if(nodeRef == null) {
throw new InvalidParameterException("NodeRef cannot be null!");
}

if(!this.nodeService.exists(nodeRef)) {
logger.debug("Node does not exist: {}", nodeRef);
return false;
}

QName type = this.nodeService.getType(nodeRef);
if(!this.dictionaryService.isSubClass(type, filterTypeQName)) {
logger.debug("Node {} is of type {}, skipping because it's subclass of {}", nodeRef, type, filterTypeQName);
return true;
}

ContentReader reader = this.contentService
.getReader(nodeRef, ContentModel.PROP_CONTENT);

if(reader != null && reader.exists()) {
logger.debug("Node Content Does Exist {}", nodeRef);
logger.trace("<<< Exiting ContentExistenceValidator.validate()");
return true;
}

logger.error("Node Content Does Not Exist {}", nodeRef);
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package eu.xenit.alfresco.processor.modules;

import org.alfresco.service.cmr.repository.NodeRef;

public interface NodeValidator {
boolean validate(NodeRef nodeRef);
}
Loading