mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
REPO-2625 / REPO-2626: Use of the heartbeat data sender
This commit is contained in:
@@ -25,13 +25,25 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.heartbeat;
|
package org.alfresco.heartbeat;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import org.alfresco.heartbeat.datasender.HBData;
|
||||||
import org.alfresco.repo.descriptor.DescriptorDAO;
|
import org.alfresco.repo.descriptor.DescriptorDAO;
|
||||||
import org.alfresco.repo.dictionary.CustomModelsInfo;
|
import org.alfresco.repo.dictionary.CustomModelsInfo;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
import org.alfresco.repo.usage.RepoUsageComponent;
|
import org.alfresco.repo.usage.RepoUsageComponent;
|
||||||
import org.alfresco.service.cmr.admin.RepoUsage;
|
import org.alfresco.service.cmr.admin.RepoUsage;
|
||||||
import org.alfresco.service.cmr.dictionary.CustomModelService;
|
import org.alfresco.service.cmr.dictionary.CustomModelService;
|
||||||
import org.alfresco.service.cmr.repository.HBDataCollectorService;
|
|
||||||
import org.alfresco.service.cmr.security.AuthorityService;
|
import org.alfresco.service.cmr.security.AuthorityService;
|
||||||
import org.alfresco.service.cmr.security.AuthorityType;
|
import org.alfresco.service.cmr.security.AuthorityType;
|
||||||
import org.alfresco.service.descriptor.Descriptor;
|
import org.alfresco.service.descriptor.Descriptor;
|
||||||
@@ -39,18 +51,10 @@ import org.alfresco.service.license.LicenseException;
|
|||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.extensions.surf.util.Base64;
|
import org.springframework.extensions.surf.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
public class CommunityHBDataCollector extends HBBaseDataCollector
|
||||||
import java.net.InetAddress;
|
{
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class CommunityHBDataCollector extends HBBaseDataCollector {
|
|
||||||
|
|
||||||
/** The logger. */
|
/** The logger. */
|
||||||
private static final Log logger = LogFactory.getLog(CommunityHBDataCollector.class);
|
private static final Log logger = LogFactory.getLog(CommunityHBDataCollector.class);
|
||||||
@@ -78,35 +82,39 @@ public class CommunityHBDataCollector extends HBBaseDataCollector {
|
|||||||
/** Provides information about custom models */
|
/** Provides information about custom models */
|
||||||
private CustomModelService customModelService;
|
private CustomModelService customModelService;
|
||||||
|
|
||||||
public void setCurrentRepoDescriptorDAO(DescriptorDAO currentRepoDescriptorDAO) {
|
public void setCurrentRepoDescriptorDAO(DescriptorDAO currentRepoDescriptorDAO)
|
||||||
|
{
|
||||||
this.currentRepoDescriptorDAO = currentRepoDescriptorDAO;
|
this.currentRepoDescriptorDAO = currentRepoDescriptorDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServerDescriptorDAO(DescriptorDAO serverDescriptorDAO) {
|
public void setServerDescriptorDAO(DescriptorDAO serverDescriptorDAO)
|
||||||
|
{
|
||||||
this.serverDescriptorDAO = serverDescriptorDAO;
|
this.serverDescriptorDAO = serverDescriptorDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthorityService(AuthorityService authorityService) {
|
public void setAuthorityService(AuthorityService authorityService)
|
||||||
|
{
|
||||||
this.authorityService = authorityService;
|
this.authorityService = authorityService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRepoUsageComponent(RepoUsageComponent repoUsageComponent) {
|
public void setRepoUsageComponent(RepoUsageComponent repoUsageComponent)
|
||||||
|
{
|
||||||
this.repoUsageComponent = repoUsageComponent;
|
this.repoUsageComponent = repoUsageComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransactionService(TransactionService transactionService) {
|
public void setTransactionService(TransactionService transactionService)
|
||||||
|
{
|
||||||
this.transactionService = transactionService;
|
this.transactionService = transactionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCustomModelService(CustomModelService customModelService) {
|
public void setCustomModelService(CustomModelService customModelService)
|
||||||
|
{
|
||||||
this.customModelService = customModelService;
|
this.customModelService = customModelService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HBData> collectData()
|
public List<HBData> collectData()
|
||||||
{
|
{
|
||||||
|
|
||||||
String timeStamp = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss.sss'Z'").format(new Date());
|
|
||||||
List<HBData> collectedData = new LinkedList<>();
|
List<HBData> collectedData = new LinkedList<>();
|
||||||
|
|
||||||
RetryingTransactionHelper.RetryingTransactionCallback<Void> initCallback = new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
RetryingTransactionHelper.RetryingTransactionCallback<Void> initCallback = new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||||
@@ -120,7 +128,6 @@ public class CommunityHBDataCollector extends HBBaseDataCollector {
|
|||||||
};
|
};
|
||||||
transactionService.getRetryingTransactionHelper().doInTransaction(initCallback, true);
|
transactionService.getRetryingTransactionHelper().doInTransaction(initCallback, true);
|
||||||
|
|
||||||
|
|
||||||
// collect repository info data
|
// collect repository info data
|
||||||
logger.debug("Preparing repository info data...");
|
logger.debug("Preparing repository info data...");
|
||||||
Map<String, Object> infoValues = new HashMap<String, Object>();
|
Map<String, Object> infoValues = new HashMap<String, Object>();
|
||||||
@@ -133,7 +140,7 @@ public class CommunityHBDataCollector extends HBBaseDataCollector {
|
|||||||
this.currentRepoDescriptorDAO.getDescriptor().getId(),
|
this.currentRepoDescriptorDAO.getDescriptor().getId(),
|
||||||
"acs.repository.info",
|
"acs.repository.info",
|
||||||
"1.0",
|
"1.0",
|
||||||
timeStamp,
|
new Date(),
|
||||||
infoValues);
|
infoValues);
|
||||||
collectedData.add(infoData);
|
collectedData.add(infoData);
|
||||||
|
|
||||||
@@ -148,7 +155,7 @@ public class CommunityHBDataCollector extends HBBaseDataCollector {
|
|||||||
this.currentRepoDescriptorDAO.getDescriptor().getId(),
|
this.currentRepoDescriptorDAO.getDescriptor().getId(),
|
||||||
"acs.repository.usage.system",
|
"acs.repository.usage.system",
|
||||||
"1.0",
|
"1.0",
|
||||||
timeStamp,
|
new Date(),
|
||||||
systemUsageValues);
|
systemUsageValues);
|
||||||
collectedData.add(systemUsageData);
|
collectedData.add(systemUsageData);
|
||||||
|
|
||||||
@@ -171,7 +178,7 @@ public class CommunityHBDataCollector extends HBBaseDataCollector {
|
|||||||
this.currentRepoDescriptorDAO.getDescriptor().getId(),
|
this.currentRepoDescriptorDAO.getDescriptor().getId(),
|
||||||
"acs.repository.usage.model",
|
"acs.repository.usage.model",
|
||||||
"1.0",
|
"1.0",
|
||||||
timeStamp,
|
new Date(),
|
||||||
modelUsageValues);
|
modelUsageValues);
|
||||||
collectedData.add(modelUsageData);
|
collectedData.add(modelUsageData);
|
||||||
|
|
||||||
@@ -209,14 +216,13 @@ public class CommunityHBDataCollector extends HBBaseDataCollector {
|
|||||||
this.currentRepoDescriptorDAO.getDescriptor().getId(),
|
this.currentRepoDescriptorDAO.getDescriptor().getId(),
|
||||||
"acs.repository.license",
|
"acs.repository.license",
|
||||||
"1.0",
|
"1.0",
|
||||||
timeStamp,
|
new Date(),
|
||||||
licenseValues);
|
licenseValues);
|
||||||
collectedData.add(licenseData);
|
collectedData.add(licenseData);
|
||||||
|
|
||||||
return collectedData;
|
return collectedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes static parameters on first invocation. Avoid doing it on construction due to bootstrap dependencies
|
* Initializes static parameters on first invocation. Avoid doing it on construction due to bootstrap dependencies
|
||||||
* (e.g. patch service must have run)
|
* (e.g. patch service must have run)
|
||||||
|
@@ -27,6 +27,7 @@ package org.alfresco.heartbeat;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.heartbeat.datasender.HBData;
|
||||||
import org.alfresco.service.cmr.repository.HBDataCollectorService;
|
import org.alfresco.service.cmr.repository.HBDataCollectorService;
|
||||||
|
|
||||||
public abstract class HBBaseDataCollector
|
public abstract class HBBaseDataCollector
|
||||||
|
@@ -28,21 +28,25 @@ package org.alfresco.heartbeat;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.alfresco.heartbeat.datasender.HBData;
|
||||||
|
import org.alfresco.heartbeat.datasender.HBDataSenderService;
|
||||||
import org.alfresco.service.cmr.repository.HBDataCollectorService;
|
import org.alfresco.service.cmr.repository.HBDataCollectorService;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
|
|
||||||
public class HBDataCollectorServiceImpl implements HBDataCollectorService
|
public class HBDataCollectorServiceImpl implements HBDataCollectorService
|
||||||
{
|
{
|
||||||
|
|
||||||
/** The logger. */
|
/** The logger. */
|
||||||
private static final Log logger = LogFactory.getLog(HBDataCollectorServiceImpl.class);
|
private static final Log logger = LogFactory.getLog(HBDataCollectorServiceImpl.class);
|
||||||
|
|
||||||
private List<HBBaseDataCollector> collectors = new LinkedList<>();
|
private List<HBBaseDataCollector> collectors = new LinkedList<>();
|
||||||
// private HBDataSenderService dataSender;
|
private HBDataSenderService hbDataSenderService;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
|
public void setHbDataSenderService(HBDataSenderService hbDataSenderService)
|
||||||
|
{
|
||||||
|
this.hbDataSenderService = hbDataSenderService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerCollector(HBBaseDataCollector collector)
|
public void registerCollector(HBBaseDataCollector collector)
|
||||||
@@ -55,17 +59,15 @@ public class HBDataCollectorServiceImpl implements HBDataCollectorService
|
|||||||
{
|
{
|
||||||
for (HBBaseDataCollector collector : collectors)
|
for (HBBaseDataCollector collector : collectors)
|
||||||
{
|
{
|
||||||
|
|
||||||
List<HBData> data = collector.collectData();
|
List<HBData> data = collector.collectData();
|
||||||
|
try
|
||||||
// try
|
{
|
||||||
// {
|
hbDataSenderService.sendData(data);
|
||||||
// dataSender.sendData(data);
|
}
|
||||||
// }
|
catch (Exception e)
|
||||||
// catch (Exception e)
|
{
|
||||||
// {
|
// log exception;
|
||||||
// // log exception;
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,51 +25,27 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.heartbeat;
|
package org.alfresco.heartbeat;
|
||||||
|
|
||||||
import org.alfresco.repo.descriptor.DescriptorDAO;
|
import java.io.IOException;
|
||||||
import org.alfresco.repo.dictionary.CustomModelsInfo;
|
import java.security.GeneralSecurityException;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
import java.util.Date;
|
||||||
import org.alfresco.repo.usage.RepoUsageComponent;
|
|
||||||
import org.alfresco.service.cmr.admin.RepoUsage;
|
|
||||||
import org.alfresco.service.cmr.dictionary.CustomModelService;
|
|
||||||
import org.alfresco.service.cmr.repository.HBDataCollectorService;
|
import org.alfresco.service.cmr.repository.HBDataCollectorService;
|
||||||
import org.alfresco.service.cmr.security.AuthorityService;
|
|
||||||
import org.alfresco.service.cmr.security.AuthorityType;
|
|
||||||
import org.alfresco.service.descriptor.Descriptor;
|
|
||||||
import org.alfresco.service.license.LicenseDescriptor;
|
import org.alfresco.service.license.LicenseDescriptor;
|
||||||
import org.alfresco.service.license.LicenseException;
|
|
||||||
import org.alfresco.service.license.LicenseService;
|
import org.alfresco.service.license.LicenseService;
|
||||||
import org.alfresco.service.license.LicenseService.LicenseChangeHandler;
|
import org.alfresco.service.license.LicenseService.LicenseChangeHandler;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
|
||||||
import org.alfresco.traitextender.SpringExtensionBundle;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONException;
|
import org.quartz.Job;
|
||||||
import org.json.JSONObject;
|
import org.quartz.JobDataMap;
|
||||||
import org.quartz.*;
|
import org.quartz.JobDetail;
|
||||||
|
import org.quartz.JobExecutionContext;
|
||||||
|
import org.quartz.JobExecutionException;
|
||||||
|
import org.quartz.Scheduler;
|
||||||
|
import org.quartz.SchedulerException;
|
||||||
|
import org.quartz.SimpleTrigger;
|
||||||
|
import org.quartz.Trigger;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.extensions.surf.util.Base64;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.security.GeneralSecurityException;
|
|
||||||
import java.security.KeyStore;
|
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.security.cert.Certificate;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class communicates some very basic repository statistics to Alfresco on a regular basis.
|
* This class communicates some very basic repository statistics to Alfresco on a regular basis.
|
||||||
@@ -205,13 +181,13 @@ public class HeartBeat implements LicenseChangeHandler
|
|||||||
* @throws GeneralSecurityException
|
* @throws GeneralSecurityException
|
||||||
* an encryption related exception
|
* an encryption related exception
|
||||||
*/
|
*/
|
||||||
public void sendData() throws IOException, GeneralSecurityException
|
public void collectAndSendData() throws IOException, GeneralSecurityException
|
||||||
{
|
{
|
||||||
this.dataCollectorService.collectAndSendData();
|
this.dataCollectorService.collectAndSendData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens for license changes. If a license is change or removed, the heartbeat job is resheduled.
|
* Listens for license changes. If a license is change or removed, the heartbeat job is rescheduled.
|
||||||
*/
|
*/
|
||||||
public synchronized void onLicenseChange(LicenseDescriptor licenseDescriptor)
|
public synchronized void onLicenseChange(LicenseDescriptor licenseDescriptor)
|
||||||
{
|
{
|
||||||
@@ -297,7 +273,7 @@ public class HeartBeat implements LicenseChangeHandler
|
|||||||
final HeartBeat heartBeat = (HeartBeat) dataMap.get("heartBeat");
|
final HeartBeat heartBeat = (HeartBeat) dataMap.get("heartBeat");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
heartBeat.sendData();
|
heartBeat.collectAndSendData();
|
||||||
}
|
}
|
||||||
catch (final Exception e)
|
catch (final Exception e)
|
||||||
{
|
{
|
||||||
|
@@ -3,8 +3,12 @@
|
|||||||
|
|
||||||
<beans>
|
<beans>
|
||||||
|
|
||||||
|
<bean id="hbDataSenderService" class="org.alfresco.heartbeat.datasender.internal.HBDataSenderServiceImpl">
|
||||||
|
</bean>
|
||||||
|
|
||||||
<!-- HeartBeat data collector service -->
|
<!-- HeartBeat data collector service -->
|
||||||
<bean id="hbDataCollectorService" class="org.alfresco.heartbeat.HBDataCollectorServiceImpl">
|
<bean id="hbDataCollectorService" class="org.alfresco.heartbeat.HBDataCollectorServiceImpl">
|
||||||
|
<property name="hbDataSenderService" ref="hbDataSenderService" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- HeartBeat abstract data collector -->
|
<!-- HeartBeat abstract data collector -->
|
||||||
|
Reference in New Issue
Block a user