From b28e0822c7b8328641ddf1002621564820f95f82 Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 23 Nov 2017 14:44:33 +0530 Subject: [PATCH 1/3] Move archival DB script to correct place (missed from #977) --- .../src/main/resources/dbscripts/cdm}/archival/mysql.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename features/device-mgt/{org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts => org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm}/archival/mysql.sql (100%) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/archival/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql similarity index 100% rename from features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/archival/mysql.sql rename to features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/archival/mysql.sql From 1449698a3cde49de7f10c9c15f02b83bb422d3a6 Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 23 Nov 2017 16:33:14 +0530 Subject: [PATCH 2/3] 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(); From 6cb3ffa3ca9f9505b9fc140faed15a0cdb8df5fb Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 23 Nov 2017 16:40:53 +0530 Subject: [PATCH 3/3] Fixed build failure due to incorrect class name --- .../mgt/core/internal/DeviceManagementServiceComponent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 669463785b..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 @@ -117,7 +117,7 @@ import java.util.concurrent.TimeUnit; * bind="setDeviceTypeGeneratorService" * unbind="unsetDeviceTypeGeneratorService" */ -public class deviceDeviceManagementServiceComponent { +public class DeviceManagementServiceComponent { private static final Object LOCK = new Object(); private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);