mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' into 'master'
Execute device detail retriever and monitoring task for all tenant See merge request entgra/carbon-device-mgt!575
This commit is contained in:
commit
e20b0459a2
@ -37,6 +37,7 @@ package org.wso2.carbon.device.mgt.core.task.impl;
|
|||||||
|
|
||||||
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.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
||||||
@ -55,8 +56,6 @@ public class DeviceDetailsRetrieverTask implements Task {
|
|||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
|
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
|
||||||
private String deviceType;
|
private String deviceType;
|
||||||
private boolean executeForTenants = false;
|
|
||||||
private final String IS_CLOUD = "is.cloud";
|
|
||||||
private DeviceManagementProviderService deviceManagementProviderService;
|
private DeviceManagementProviderService deviceManagementProviderService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -76,27 +75,7 @@ public class DeviceDetailsRetrieverTask implements Task {
|
|||||||
.getDeviceMonitoringConfig(deviceType);
|
.getDeviceMonitoringConfig(deviceType);
|
||||||
StartupOperationConfig startupOperationConfig = deviceManagementProviderService
|
StartupOperationConfig startupOperationConfig = deviceManagementProviderService
|
||||||
.getStartupOperationConfig(deviceType);
|
.getStartupOperationConfig(deviceType);
|
||||||
|
|
||||||
if (System.getProperty(IS_CLOUD) != null && Boolean.parseBoolean(System.getProperty(IS_CLOUD))) {
|
|
||||||
executeForTenants = true;
|
|
||||||
}
|
|
||||||
if (executeForTenants) {
|
|
||||||
this.executeForAllTenants(operationMonitoringTaskConfig, startupOperationConfig);
|
this.executeForAllTenants(operationMonitoringTaskConfig, startupOperationConfig);
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Device details retrieving task started to run.");
|
|
||||||
}
|
|
||||||
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, operationMonitoringTaskConfig,
|
|
||||||
startupOperationConfig);
|
|
||||||
//pass the configurations also from here, monitoring tasks
|
|
||||||
try {
|
|
||||||
if (deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType)) {
|
|
||||||
deviceTaskManager.addOperations();
|
|
||||||
}
|
|
||||||
} catch (DeviceMgtTaskException e) {
|
|
||||||
log.error("Error occurred while trying to add the operations to device to retrieve device details.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeForAllTenants(OperationMonitoringTaskConfig operationMonitoringTaskConfig,
|
private void executeForAllTenants(OperationMonitoringTaskConfig operationMonitoringTaskConfig,
|
||||||
@ -111,17 +90,38 @@ public class DeviceDetailsRetrieverTask implements Task {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Task is running for " + tenants.size() + " tenants and the device type is " + deviceType);
|
log.debug("Task is running for " + tenants.size() + " tenants and the device type is " + deviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Integer tenant : tenants) {
|
for (Integer tenant : tenants) {
|
||||||
String tenantDomain = DeviceManagementDataHolder.getInstance().
|
if (MultitenantConstants.SUPER_TENANT_ID == tenant) {
|
||||||
getRealmService().getTenantManager().getDomain(tenant);
|
this.executeTask(operationMonitoringTaskConfig, startupOperationConfig);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant, true);
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant);
|
this.executeTask(operationMonitoringTaskConfig, startupOperationConfig);
|
||||||
|
} finally {
|
||||||
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Error occurred while trying to get the available tenants " +
|
||||||
|
"from device manager provider service.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute device detail retriever task
|
||||||
|
* @param operationMonitoringTaskConfig which contains monitoring operations and related details
|
||||||
|
* @param startupOperationConfig which contains startup operations and realted details
|
||||||
|
*/
|
||||||
|
private void executeTask(OperationMonitoringTaskConfig operationMonitoringTaskConfig,
|
||||||
|
StartupOperationConfig startupOperationConfig) {
|
||||||
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
|
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
|
||||||
operationMonitoringTaskConfig,
|
operationMonitoringTaskConfig,
|
||||||
startupOperationConfig);
|
startupOperationConfig);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Device details retrieving task started to run.");
|
||||||
|
}
|
||||||
//pass the configurations also from here, monitoring tasks
|
//pass the configurations also from here, monitoring tasks
|
||||||
try {
|
try {
|
||||||
if (deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType)) {
|
if (deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType)) {
|
||||||
@ -131,16 +131,6 @@ public class DeviceDetailsRetrieverTask implements Task {
|
|||||||
log.error("Error occurred while trying to add the operations to " +
|
log.error("Error occurred while trying to add the operations to " +
|
||||||
"device to retrieve device details.", e);
|
"device to retrieve device details.", e);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (UserStoreException e) {
|
|
||||||
log.error("Error occurred while trying to get the available tenants", e);
|
|
||||||
} catch (DeviceManagementException e) {
|
|
||||||
log.error("Error occurred while trying to get the available tenants " +
|
|
||||||
"from device manager provider service.", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -165,7 +165,6 @@ public class DeviceTaskManagerTest extends BaseDeviceManagementTest {
|
|||||||
description = "Testing device detail retriever task execution for tenants")
|
description = "Testing device detail retriever task execution for tenants")
|
||||||
public void testDeviceDetailRetrieverTaskExecuteForAllTenants() throws OperationManagementException {
|
public void testDeviceDetailRetrieverTaskExecuteForAllTenants() throws OperationManagementException {
|
||||||
DeviceDetailsRetrieverTask deviceDetailsRetrieverTask = new DeviceDetailsRetrieverTask();
|
DeviceDetailsRetrieverTask deviceDetailsRetrieverTask = new DeviceDetailsRetrieverTask();
|
||||||
System.setProperty("is.cloud", "true");
|
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("DEVICE_TYPE", TestDataHolder.TEST_DEVICE_TYPE);
|
map.put("DEVICE_TYPE", TestDataHolder.TEST_DEVICE_TYPE);
|
||||||
deviceDetailsRetrieverTask.setProperties(map);
|
deviceDetailsRetrieverTask.setProperties(map);
|
||||||
|
|||||||
@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.core.task;
|
|||||||
|
|
||||||
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.wso2.carbon.base.MultitenantConstants;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
@ -43,9 +44,6 @@ public class MonitoringTask implements Task {
|
|||||||
private static final Log log = LogFactory.getLog(MonitoringTask.class);
|
private static final Log log = LogFactory.getLog(MonitoringTask.class);
|
||||||
|
|
||||||
Map<String, String> properties;
|
Map<String, String> properties;
|
||||||
private boolean executeForTenants = false;
|
|
||||||
private final String IS_CLOUD = "is.cloud";
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setProperties(Map<String, String> map) {
|
public void setProperties(Map<String, String> map) {
|
||||||
@ -62,14 +60,8 @@ public class MonitoringTask implements Task {
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Monitoring task started to run.");
|
log.debug("Monitoring task started to run.");
|
||||||
}
|
}
|
||||||
if (System.getProperty(IS_CLOUD) != null && Boolean.parseBoolean(System.getProperty(IS_CLOUD))) {
|
|
||||||
executeForTenants = true;
|
|
||||||
}
|
|
||||||
if (executeForTenants) {
|
|
||||||
this.executeforAllTenants();
|
this.executeforAllTenants();
|
||||||
} else {
|
|
||||||
this.executeTask();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,19 +87,18 @@ public class MonitoringTask implements Task {
|
|||||||
DeviceManagementProviderService deviceManagementService = new DeviceManagementProviderServiceImpl();
|
DeviceManagementProviderService deviceManagementService = new DeviceManagementProviderServiceImpl();
|
||||||
List<Integer> tenants = deviceManagementService.getDeviceEnrolledTenants();
|
List<Integer> tenants = deviceManagementService.getDeviceEnrolledTenants();
|
||||||
for (Integer tenant : tenants) {
|
for (Integer tenant : tenants) {
|
||||||
String tenantDomain = PolicyManagementDataHolder.getInstance().
|
if (MultitenantConstants.SUPER_TENANT_ID == tenant) {
|
||||||
getRealmService().getTenantManager().getDomain(tenant);
|
this.executeTask();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant, true);
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant);
|
|
||||||
this.executeTask();
|
this.executeTask();
|
||||||
} finally {
|
} finally {
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (UserStoreException e) {
|
|
||||||
log.error("Error occurred while trying to get the available tenants", e);
|
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
log.error("Error occurred while trying to get the available tenants from device manager service ", e);
|
log.error("Error occurred while trying to get the available tenants from device manager service ", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user