|
|
|
@ -16,21 +16,17 @@
|
|
|
|
|
* 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.framework.BundleContext;
|
|
|
|
|
import org.osgi.service.component.ComponentContext;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
|
|
|
|
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.device.details.mgt.DeviceInformationManager;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.search.mgt.impl.SearchManagerServiceImpl;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.status.task.DeviceStatusTaskException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.status.task.DeviceStatusTaskManagerService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.status.task.impl.DeviceStatusTaskManagerServiceImpl;
|
|
|
|
@ -39,7 +35,6 @@ import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerServiceImpl;
|
|
|
|
|
import org.wso2.carbon.ntask.core.service.TaskService;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -52,9 +47,11 @@ import java.util.Map;
|
|
|
|
|
* unbind="unsetTaskService"
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
public class DeviceTaskManagerServiceComponent {
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(DeviceTaskManagerServiceComponent.class);
|
|
|
|
|
private DeviceManagementConfig deviceManagementConfig;
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
protected void activate(ComponentContext componentContext) {
|
|
|
|
@ -62,45 +59,40 @@ public class DeviceTaskManagerServiceComponent {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Initializing device task manager bundle.");
|
|
|
|
|
}
|
|
|
|
|
getDeviceOperationMonitoringConfig(componentContext);
|
|
|
|
|
startOperationMonitoringTask(componentContext.getBundleContext());
|
|
|
|
|
//Start the DeviceStatusMonitoringTask for registered DeviceTypes
|
|
|
|
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
|
|
|
|
|
deviceManagementConfig = DeviceConfigurationManager.getInstance().
|
|
|
|
|
getDeviceManagementConfig();
|
|
|
|
|
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
|
|
|
|
|
startDeviceStatusMonitoringTask();
|
|
|
|
|
startDeviceStatusMonitoringTask(componentContext.getBundleContext());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentContext.getBundleContext().registerService(DeviceInformationManager.class,
|
|
|
|
|
new DeviceInformationManagerImpl(), null);
|
|
|
|
|
|
|
|
|
|
componentContext.getBundleContext().registerService(SearchManagerService.class,
|
|
|
|
|
new SearchManagerServiceImpl(), null);
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("Error occurred while initializing device task manager service.", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void getDeviceOperationMonitoringConfig(ComponentContext componentContext)
|
|
|
|
|
private void startOperationMonitoringTask(BundleContext bundleContext)
|
|
|
|
|
throws DeviceMgtTaskException {
|
|
|
|
|
DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl();
|
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(deviceTaskManagerService);
|
|
|
|
|
componentContext.getBundleContext().registerService(DeviceTaskManagerService.class,
|
|
|
|
|
deviceTaskManagerService, null);
|
|
|
|
|
bundleContext.registerService(DeviceTaskManagerService.class, deviceTaskManagerService, null);
|
|
|
|
|
Map<String, OperationMonitoringTaskConfig> deviceConfigMap = DeviceMonitoringOperationDataHolder
|
|
|
|
|
.getInstance().getOperationMonitoringConfigFromMap();
|
|
|
|
|
for (String platformType : new ArrayList<>(deviceConfigMap.keySet())) {
|
|
|
|
|
if (deviceConfigMap.get(platformType).isEnabled()){
|
|
|
|
|
deviceTaskManagerService.startTask(platformType, deviceConfigMap.get(platformType));
|
|
|
|
|
for (String platformType : deviceConfigMap.keySet()) {
|
|
|
|
|
OperationMonitoringTaskConfig taskConfig = deviceConfigMap.get(platformType);
|
|
|
|
|
if (taskConfig.isEnabled()) {
|
|
|
|
|
deviceTaskManagerService.startTask(platformType, taskConfig);
|
|
|
|
|
}
|
|
|
|
|
deviceConfigMap.remove(platformType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startDeviceStatusMonitoringTask() {
|
|
|
|
|
private void startDeviceStatusMonitoringTask(BundleContext bundleContext) {
|
|
|
|
|
DeviceStatusTaskManagerService deviceStatusTaskManagerService = new DeviceStatusTaskManagerServiceImpl();
|
|
|
|
|
DeviceManagementDataHolder.getInstance().setDeviceStatusTaskManagerService(deviceStatusTaskManagerService);
|
|
|
|
|
bundleContext.registerService(DeviceStatusTaskManagerService.class, deviceStatusTaskManagerService, null);
|
|
|
|
|
Map<DeviceType, DeviceStatusTaskPluginConfig> deviceStatusTaskPluginConfigs = DeviceManagementDataHolder.
|
|
|
|
|
getInstance().getDeviceStatusTaskPluginConfigs();
|
|
|
|
|
for (DeviceType deviceType : new ArrayList<>(deviceStatusTaskPluginConfigs.keySet())) {
|
|
|
|
|
for (DeviceType deviceType : deviceStatusTaskPluginConfigs.keySet()) {
|
|
|
|
|
try {
|
|
|
|
|
deviceStatusTaskManagerService.startTask(deviceType, deviceStatusTaskPluginConfigs.get(deviceType));
|
|
|
|
|
} catch (DeviceStatusTaskException e) {
|
|
|
|
@ -113,10 +105,41 @@ public class DeviceTaskManagerServiceComponent {
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
protected void deactivate(ComponentContext componentContext) {
|
|
|
|
|
try {
|
|
|
|
|
// DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl();
|
|
|
|
|
// taskManagerService.stopTask();
|
|
|
|
|
stopOperationMonitoringTask();
|
|
|
|
|
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
|
|
|
|
|
stopDeviceStatusMonitoringTask();
|
|
|
|
|
}
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
log.error("Error occurred while destroying the device details retrieving task manager service.", e);
|
|
|
|
|
log.error("Error occurred while shutting down device task manager service.", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void stopOperationMonitoringTask()
|
|
|
|
|
throws DeviceMgtTaskException {
|
|
|
|
|
DeviceTaskManagerService deviceTaskManagerService = DeviceManagementDataHolder.getInstance()
|
|
|
|
|
.getDeviceTaskManagerService();
|
|
|
|
|
Map<String, OperationMonitoringTaskConfig> deviceConfigMap = DeviceMonitoringOperationDataHolder
|
|
|
|
|
.getInstance().getOperationMonitoringConfigFromMap();
|
|
|
|
|
for (String platformType : deviceConfigMap.keySet()) {
|
|
|
|
|
OperationMonitoringTaskConfig taskConfig = deviceConfigMap.get(platformType);
|
|
|
|
|
if (taskConfig.isEnabled()) {
|
|
|
|
|
deviceTaskManagerService.stopTask(platformType, taskConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void stopDeviceStatusMonitoringTask() {
|
|
|
|
|
DeviceStatusTaskManagerService deviceStatusTaskManagerService = DeviceManagementDataHolder.getInstance()
|
|
|
|
|
.getDeviceStatusTaskManagerService();
|
|
|
|
|
Map<DeviceType, DeviceStatusTaskPluginConfig> deviceStatusTaskPluginConfigs = DeviceManagementDataHolder.
|
|
|
|
|
getInstance().getDeviceStatusTaskPluginConfigs();
|
|
|
|
|
for (DeviceType deviceType : deviceStatusTaskPluginConfigs.keySet()) {
|
|
|
|
|
try {
|
|
|
|
|
deviceStatusTaskManagerService.stopTask(deviceType, deviceStatusTaskPluginConfigs.get(deviceType));
|
|
|
|
|
} catch (DeviceStatusTaskException e) {
|
|
|
|
|
log.error("Exception occurred while stopping the DeviceStatusMonitoring Task for deviceType '" +
|
|
|
|
|
deviceType + "'", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|