mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Execute device detail retreiver and monitoring task for all tenant
This commit is contained in:
parent
f97e3d0ee7
commit
da5a1caf2b
@ -55,8 +55,7 @@ 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 static final int SUPER_TENANT_ID = -1234;
|
||||||
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);
|
||||||
|
this.executeForAllTenants(operationMonitoringTaskConfig, startupOperationConfig);
|
||||||
if (System.getProperty(IS_CLOUD) != null && Boolean.parseBoolean(System.getProperty(IS_CLOUD))) {
|
|
||||||
executeForTenants = true;
|
|
||||||
}
|
|
||||||
if (executeForTenants) {
|
|
||||||
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,
|
||||||
@ -113,24 +92,17 @@ public class DeviceDetailsRetrieverTask implements Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Integer tenant : tenants) {
|
for (Integer tenant : tenants) {
|
||||||
|
if (SUPER_TENANT_ID == tenant) {
|
||||||
|
this.executeTask(operationMonitoringTaskConfig, startupOperationConfig);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String tenantDomain = DeviceManagementDataHolder.getInstance().
|
String tenantDomain = DeviceManagementDataHolder.getInstance().
|
||||||
getRealmService().getTenantManager().getDomain(tenant);
|
getRealmService().getTenantManager().getDomain(tenant);
|
||||||
try {
|
try {
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant);
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant);
|
||||||
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
|
this.executeTask(operationMonitoringTaskConfig, startupOperationConfig);
|
||||||
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);
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
}
|
}
|
||||||
@ -143,4 +115,28 @@ public class DeviceDetailsRetrieverTask implements Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
operationMonitoringTaskConfig,
|
||||||
|
startupOperationConfig);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Device details retrieving task started to run.");
|
||||||
|
}
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -42,10 +42,9 @@ 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;
|
private static final int SUPER_TENANT_ID = -1234;
|
||||||
private boolean executeForTenants = false;
|
|
||||||
private final String IS_CLOUD = "is.cloud";
|
|
||||||
|
|
||||||
|
Map<String, String> properties;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setProperties(Map<String, String> map) {
|
public void setProperties(Map<String, String> map) {
|
||||||
@ -62,14 +61,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;
|
this.executeforAllTenants();
|
||||||
}
|
|
||||||
if (executeForTenants) {
|
|
||||||
this.executeforAllTenants();
|
|
||||||
} else {
|
|
||||||
this.executeTask();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,6 +88,10 @@ 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) {
|
||||||
|
if (SUPER_TENANT_ID == tenant) {
|
||||||
|
this.executeTask();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String tenantDomain = PolicyManagementDataHolder.getInstance().
|
String tenantDomain = PolicyManagementDataHolder.getInstance().
|
||||||
getRealmService().getTenantManager().getDomain(tenant);
|
getRealmService().getTenantManager().getDomain(tenant);
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user