From 1449698a3cde49de7f10c9c15f02b83bb422d3a6 Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 23 Nov 2017 16:33:14 +0530 Subject: [PATCH] OSGi improvement to #977 --- .../ActivityDataPurgingServiceComponent.java | 64 +++++++++++++++---- .../DeviceManagementServiceComponent.java | 7 -- 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/ActivityDataPurgingServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/ActivityDataPurgingServiceComponent.java index 2136054ad8..19048b5bcc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/ActivityDataPurgingServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/ActivityDataPurgingServiceComponent.java @@ -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, * Version 2.0 (the "License"); you may not use this file except @@ -15,12 +15,18 @@ * specific language governing permissions and limitations * under the License. */ + package org.wso2.carbon.device.mgt.core.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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.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.impl.ArchivalTaskManagerImpl; import org.wso2.carbon.ntask.core.service.TaskService; @@ -33,6 +39,12 @@ import org.wso2.carbon.ntask.core.service.TaskService; * policy="dynamic" * bind="setTaskService" * 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 { private static Log log = LogFactory.getLog(ActivityDataPurgingServiceComponent.class); @@ -42,25 +54,45 @@ public class ActivityDataPurgingServiceComponent { if (log.isDebugEnabled()) { 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(); // This will start the data archival task - boolean purgingTaskEnabled = - DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration() - .getArchivalTaskConfiguration().isEnabled(); - - if (purgingTaskEnabled) { + if (archivalTaskEnabled) { archivalTaskManager.scheduleArchivalTask(); + log.info("Data archival task has been scheduled."); } else { - log.warn("Data archival task has been disabled. It is recommended to enable archival task to prune the " + - "transactional databases tables time to time."); + log.warn("Data archival task has been disabled. It is recommended to enable archival task to " + + "prune the transactional databases tables time to time if you are using MySQL."); } + // This will start the data deletion task. - boolean deletionTaskEnabled = - DeviceConfigurationManager.getInstance().getDeviceManagementConfig().getArchivalConfiguration() - .getArchivalTaskConfiguration().getPurgingTaskConfiguration().isEnabled(); - if (deletionTaskEnabled) { + if (purgingTaskEnabled) { archivalTaskManager.scheduleDeletionTask(); + log.info("Data purging task has been scheduled for archived data."); } } catch (Throwable 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); } + protected void setDeviceManagementService(DeviceManagementProviderService deviceManagementService){ + + } + + protected void unsetDeviceManagementService(DeviceManagementProviderService deviceManagementService){ + + } + @SuppressWarnings("unused") protected void deactivate(ComponentContext componentContext) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 7dda339501..0c45b6ffda 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -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.config.AppManagementConfig; 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.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; @@ -169,11 +167,6 @@ public class DeviceManagementServiceComponent { /* Initialize Operation Manager */ this.initOperationsManager(); - /* Initialising data archival configurations */ - ArchivalSourceDAOFactory.init(dsConfig); - DataSourceConfig purgingDSConfig = config.getArchivalConfiguration().getDataSourceConfig(); - ArchivalDestinationDAOFactory.init(purgingDSConfig); - PushNotificationProviderRepository pushNotificationRepo = new PushNotificationProviderRepository(); List pushNotificationProviders = config.getPushNotificationConfiguration() .getPushNotificationProviders();