OSGi improvement to #977

4.x.x
charitha 7 years ago
parent b28e0822c7
commit 1449698a3c

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* *
* WSO2 Inc. licenses this file to you under the Apache License, * WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except * Version 2.0 (the "License"); you may not use this file except
@ -15,12 +15,18 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.core.internal; package org.wso2.carbon.device.mgt.core.internal;
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.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDestinationDAOFactory;
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalSourceDAOFactory;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.task.ArchivalTaskManager; import org.wso2.carbon.device.mgt.core.task.ArchivalTaskManager;
import org.wso2.carbon.device.mgt.core.task.impl.ArchivalTaskManagerImpl; import org.wso2.carbon.device.mgt.core.task.impl.ArchivalTaskManagerImpl;
import org.wso2.carbon.ntask.core.service.TaskService; import org.wso2.carbon.ntask.core.service.TaskService;
@ -33,6 +39,12 @@ import org.wso2.carbon.ntask.core.service.TaskService;
* policy="dynamic" * policy="dynamic"
* bind="setTaskService" * bind="setTaskService"
* unbind="unsetTaskService" * unbind="unsetTaskService"
* @scr.reference name="org.wso2.carbon.device.manager"
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
* cardinality="1..1"
* policy="dynamic"
* bind="setDeviceManagementService"
* unbind="unsetDeviceManagementService"
*/ */
public class ActivityDataPurgingServiceComponent { public class ActivityDataPurgingServiceComponent {
private static Log log = LogFactory.getLog(ActivityDataPurgingServiceComponent.class); private static Log log = LogFactory.getLog(ActivityDataPurgingServiceComponent.class);
@ -42,25 +54,45 @@ public class ActivityDataPurgingServiceComponent {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Initializing activity data archival task manager bundle."); log.debug("Initializing activity data archival task manager bundle.");
} }
/* Initialising data archival configurations */
DeviceManagementConfig config =
DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
boolean archivalTaskEnabled = false;
boolean purgingTaskEnabled = false;
if (config.getArchivalConfiguration() != null
&& config.getArchivalConfiguration().getArchivalTaskConfiguration() != null){
archivalTaskEnabled = config.getArchivalConfiguration().getArchivalTaskConfiguration().isEnabled();
purgingTaskEnabled = config.getArchivalConfiguration().getArchivalTaskConfiguration()
.getPurgingTaskConfiguration() != null
&& config.getArchivalConfiguration()
.getArchivalTaskConfiguration().getPurgingTaskConfiguration().isEnabled();
}
if (archivalTaskEnabled || purgingTaskEnabled) {
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
ArchivalSourceDAOFactory.init(dsConfig);
DataSourceConfig purgingDSConfig = config.getArchivalConfiguration().getDataSourceConfig();
ArchivalDestinationDAOFactory.init(purgingDSConfig);
}
ArchivalTaskManager archivalTaskManager = new ArchivalTaskManagerImpl(); ArchivalTaskManager archivalTaskManager = new ArchivalTaskManagerImpl();
// This will start the data archival task // This will start the data archival task
boolean purgingTaskEnabled = if (archivalTaskEnabled) {
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
.getArchivalTaskConfiguration().isEnabled();
if (purgingTaskEnabled) {
archivalTaskManager.scheduleArchivalTask(); archivalTaskManager.scheduleArchivalTask();
log.info("Data archival task has been scheduled.");
} else { } else {
log.warn("Data archival task has been disabled. It is recommended to enable archival task to prune the " + log.warn("Data archival task has been disabled. It is recommended to enable archival task to " +
"transactional databases tables time to time."); "prune the transactional databases tables time to time if you are using MySQL.");
} }
// This will start the data deletion task. // This will start the data deletion task.
boolean deletionTaskEnabled = if (purgingTaskEnabled) {
DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration()
.getArchivalTaskConfiguration().getPurgingTaskConfiguration().isEnabled();
if (deletionTaskEnabled) {
archivalTaskManager.scheduleDeletionTask(); archivalTaskManager.scheduleDeletionTask();
log.info("Data purging task has been scheduled for archived data.");
} }
} catch (Throwable e) { } catch (Throwable e) {
log.error("Error occurred while initializing activity data archival task manager service.", e); log.error("Error occurred while initializing activity data archival task manager service.", e);
@ -81,6 +113,14 @@ public class ActivityDataPurgingServiceComponent {
DeviceManagementDataHolder.getInstance().setTaskService(null); DeviceManagementDataHolder.getInstance().setTaskService(null);
} }
protected void setDeviceManagementService(DeviceManagementProviderService deviceManagementService){
}
protected void unsetDeviceManagementService(DeviceManagementProviderService deviceManagementService){
}
@SuppressWarnings("unused") @SuppressWarnings("unused")
protected void deactivate(ComponentContext componentContext) { protected void deactivate(ComponentContext componentContext) {

@ -38,8 +38,6 @@ import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderServ
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagerProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfigurationManager; import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfigurationManager;
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalDestinationDAOFactory;
import org.wso2.carbon.device.mgt.core.archival.dao.ArchivalSourceDAOFactory;
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl; import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
@ -169,11 +167,6 @@ public class DeviceManagementServiceComponent {
/* Initialize Operation Manager */ /* Initialize Operation Manager */
this.initOperationsManager(); this.initOperationsManager();
/* Initialising data archival configurations */
ArchivalSourceDAOFactory.init(dsConfig);
DataSourceConfig purgingDSConfig = config.getArchivalConfiguration().getDataSourceConfig();
ArchivalDestinationDAOFactory.init(purgingDSConfig);
PushNotificationProviderRepository pushNotificationRepo = new PushNotificationProviderRepository(); PushNotificationProviderRepository pushNotificationRepo = new PushNotificationProviderRepository();
List<String> pushNotificationProviders = config.getPushNotificationConfiguration() List<String> pushNotificationProviders = config.getPushNotificationConfiguration()
.getPushNotificationProviders(); .getPushNotificationProviders();

Loading…
Cancel
Save