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