use of org.alfresco.heartbeat.datasender.HBDataSenderService in project alfresco-repository by Alfresco.
the class HBDataCollectorServiceImplTest method testOnLicenseChangeOverridesDefaultEnabled.
/**
* Heartbeat enabled by default but disabled in licence on onLicenseChange
*/
@Test
public void testOnLicenseChangeOverridesDefaultEnabled() throws Exception {
// Enable heartbeat by setting the default enabled state ( as if set in prop file)
final HBDataCollectorServiceImpl collectorService = new HBDataCollectorServiceImpl(true);
final HBDataSenderService sender = mock(HBDataSenderService.class);
collectorService.setHbDataSenderService(sender);
// Register few collectors
registerValidCollectors(collectorService);
// Heartbeat disabled in licence
enabledHbInLicense(collectorService, false);
// Check heart beat is disabled and all collector jobs are unscheduled
assertFalse(collectorService.isEnabled());
assertCollectorJobsNotScheduled("Job was scheduled but HB is disabled");
// Also check sender is updated
verify(sender).enable(false);
}
use of org.alfresco.heartbeat.datasender.HBDataSenderService in project alfresco-repository by Alfresco.
the class LockingJob method execute.
@Override
public void execute(final JobExecutionContext jobexecutioncontext) throws JobExecutionException {
final JobDataMap dataMap = jobexecutioncontext.getJobDetail().getJobDataMap();
final HBBaseDataCollector collector = (HBBaseDataCollector) dataMap.get(COLLECTOR_KEY);
final HBDataSenderService hbDataSenderService = (HBDataSenderService) dataMap.get(DATA_SENDER_SERVICE_KEY);
final JobLockService jobLockService = (JobLockService) dataMap.get(JOB_LOCK_SERVICE_KEY);
ParameterCheck.mandatory(COLLECTOR_KEY, collector);
ParameterCheck.mandatory(DATA_SENDER_SERVICE_KEY, hbDataSenderService);
ParameterCheck.mandatory(JOB_LOCK_SERVICE_KEY, jobLockService);
QName lockQname = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, collector.getCollectorId());
LockCallback lockCallback = new LockCallback(lockQname);
try {
// Get lock
String lockToken = jobLockService.getLock(lockQname, LOCK_TTL);
// Register the refresh callback which will keep the lock alive.
// The lock will not be released manually,
// instead the job lock service will check the callback (running) flag every LOCK_TTL/2 ms from lock acquisition
// and release the lock when the flag is set to false.
jobLockService.refreshLock(lockToken, lockQname, LOCK_TTL, lockCallback);
if (logger.isDebugEnabled()) {
logger.debug("Lock acquired: " + lockQname + ": " + lockToken);
}
// Collect data and pass it to the data sender service
collectAndSendDataLocked(collector, hbDataSenderService);
} catch (LockAcquisitionException e) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping collect and send data (could not get lock): " + e.getMessage());
}
} finally {
if (logger.isDebugEnabled()) {
logger.debug("Finished collector job. ID: " + collector.getCollectorId());
}
lockCallback.running.set(false);
}
}
use of org.alfresco.heartbeat.datasender.HBDataSenderService in project alfresco-repository by Alfresco.
the class NonLockingJob method execute.
@Override
public void execute(final JobExecutionContext jobExecutionContext) throws JobExecutionException {
final JobDataMap dataMap = jobExecutionContext.getJobDetail().getJobDataMap();
final HBBaseDataCollector collector = (HBBaseDataCollector) dataMap.get(COLLECTOR_KEY);
final HBDataSenderService hbDataSenderService = (HBDataSenderService) dataMap.get(DATA_SENDER_SERVICE_KEY);
ParameterCheck.mandatory(COLLECTOR_KEY, collector);
ParameterCheck.mandatory(DATA_SENDER_SERVICE_KEY, hbDataSenderService);
try {
List<HBData> data = collector.collectData();
hbDataSenderService.sendData(data);
if (logger.isDebugEnabled()) {
logger.debug("Finished collector job. ID:" + collector.getCollectorId());
}
} catch (final Exception e) {
// Log the error but don't rethrow, collector errors are non fatal
logger.error("Heartbeat failed to collect data for collector ID: " + collector.getCollectorId(), e);
}
}
use of org.alfresco.heartbeat.datasender.HBDataSenderService in project alfresco-repository by Alfresco.
the class HBDataCollectorServiceImplTest method testOnLicenseChangeOverridesDefaultDisabled.
/**
* Heartbeat disabled by default but enabled in licence on onLicenseChange
*/
@Test
public void testOnLicenseChangeOverridesDefaultDisabled() throws Exception {
// Disable heartbeat by setting the default enabled state ( as if set in prop file)
final HBDataCollectorServiceImpl collectorService = new HBDataCollectorServiceImpl(false);
final HBDataSenderService sender = mock(HBDataSenderService.class);
collectorService.setHbDataSenderService(sender);
// Register few collectors
registerValidCollectors(collectorService);
// Heartbeat enabled in licence
enabledHbInLicense(collectorService, true);
// Check heart beat is enabled and all collector jobs are scheduled
assertTrue(collectorService.isEnabled());
assertCollectorJobsScheduled("Job was not scheduled but HB is enabled");
// Also check sender is updated
verify(sender).enable(true);
}
Aggregations