WIP: Add Tenanted Device Task Configurations #370
Draft
pramilaniroshan
wants to merge 7 commits from pramilaniroshan/device-mgt-core:device-tenant-task-configuration
into master
Loading…
Reference in new issue
There is no content yet.
Delete Branch 'pramilaniroshan/device-mgt-core:device-tenant-task-configuration'
Deleting a branch is permanent. It CANNOT be undone. Continue?
This allowing users to configure task frequencies independently for each tenant.
https://roadmap.entgra.net/issues/9181
String deviceType = entry.getKey();
int frequency = entry.getValue();
// Create a JsonObject for the current device type
JsonObject deviceObject = new JsonObject();
Move declaration out side the loop.
this deviceObject should be created for each entry in the deviceFrequencies map; otherwise,it'll adding the same deviceObject/frequencies for all device types
private static final Log log = LogFactory.getLog(DeviceTaskConfigurationServiceImpl.class);
private final MetadataDAO metadataDAO;
Use MetadataManagementService instead of MetadataDAO.
DeviceManagementProviderService dms = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
List<DeviceType> deviceTypes = dms.getDeviceTypes();
for (DeviceType deviceType : deviceTypes) {
deviceFrequencies.put(deviceType.getName(), getDefaultTaskFrequency(dms, deviceType.getName()));
Remove the logic and just call the addTaskFrequency method.
what's the reason for this? with this it's bit clean method when calling
Logic is repeating in both methods
}
@Override
public void completedServerStartup() {
In here, frequencies are setting back to the default frequencies on every server startup. Isn't this an issue?
No. we checking if task frequencies already added or not, this run when migration happen
if (!metadataDAO.isExist(tenantId, MetadataConstants.DEVICE_TASK_FREQUENCY))
Got it :)
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
}
private void addMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
Add Java Doc comment
metadata.setMetaValue(jsonObject.toString());
return metadata;
}
Remove unnecessary new line
}
private int getDefaultTaskFrequency(DeviceManagementProviderService dms, String deviceType) {
Add Java Doc comment
private int getDefaultTaskFrequency(DeviceManagementProviderService dms, String deviceType) {
OperationMonitoringTaskConfig operationMonitoringTaskConfig = dms.getDeviceMonitoringConfig(deviceType);
Can 'operationMonitoringTaskConfig' become null, if so handle it here.
If it is not, do we need to have a separate method here? Can't we get the value from following way?
dms.getDeviceMonitoringConfig(deviceType).getFrequency()
I added separate method because it's improved readability and maintainability
for (DeviceType deviceType : deviceTypes) {
deviceFrequencies.put(deviceType.getName(), frequency);
}
MetadataManagementDAOFactory.beginTransaction();
This line should be the first line of a try-catch block. If there is an error because of issue in upper lines then finally block will execute without an open connection.
Further, when you use meta service, you will not need to have this logic.
// Retrieve the frequency for the given device type
return deviceFrequencyMap.get(deviceType).getFrequency();
} else {
throw new MetadataManagementException("Device type not found: " + deviceType);
Log the error and throw
}
@Override
public void completedServerStartup() {
Can't we use already existing 'completedServerStartup' listener?
yes we can, but i decided to create a new one with new thread
}
}
} catch (MetadataManagementException e) {
String msg = "Error occurred while adding default task frequency metadata entry.";
It is not required to assign the log message to variable since there is only one usage.
log.error("Error occurred while trying to get the available tenants " +
"from device manager provider service.", e);
} catch (MetadataManagementException e) {
String msg = "Error occurred while getting task frequency metadata entry.";
It is not required to assign the log message to variable since there is only one usage.
log.error("Error occurred while trying to add the operations to " +
"device to retrieve device details.", e);
} catch (MetadataManagementException e) {
String msg = "Error occurred while getting task frequency metadata entry.";
It is not required to assign the log message to variable since there is only one usage.
}
try {
deviceTaskConfigurationService.addDefaultTaskFrequency(MultitenantConstants.SUPER_TENANT_ID);
Tenant[] tenantArray = realmService.getTenantManager().getAllTenants();
From this call, doesn't it return super tenant details?
No. It's doesn't return super tenant details
Add Tenanted Device Task Configurationsto WIP: Add Tenanted Device Task Configurations 5 months agoe1066fff23
to0fdeec4c5f
5 months agoWIP: Add Tenanted Device Task Configurationsto Add Tenanted Device Task Configurations 5 months agoAdd Tenanted Device Task Configurationsto WIP: Add Tenanted Device Task Configurations 5 months agogetDeviceTaskManagerService();
OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceManagementService.
getOperationMonitoringConfig();
TaskManagementService taskManagementService= DeviceManagementDataHolder.getInstance().getTaskManagementService();
Format code
}
}
private void startTasksForTenant(Map<String, OperationMonitoringTaskConfig> deviceConfigMap,DeviceTaskManagerService deviceTaskManagerService) throws DeviceMgtTaskException {
Format code
private final MetadataManagementService metadataManagementService;
private static DeviceTaskConfigurationServiceImpl instance;
Make volatile
*/
void updateTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig)
throws DeviceMgtTaskException;
void updateTask(int taskId,DeviceTaskManagerWrapper deviceTaskManagerWrapper)
Format code
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
this.executeTask(operationMonitoringTaskConfig, startupOperationConfig, Utils.getTenantedTaskFrequency(tenantId, deviceType));
Format code
public boolean isTaskExist(String taskName) throws TaskManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
TaskManagementDAOFactory.beginTransaction();
What is the requirement for the transaction scope to read database?
log.error(msg, e);
throw new TenantMgtException(msg, e);
} catch (DeviceManagementException e) {
throw new TenantMgtException("Error occurred while getting DeviceManagementService", e);
Log the error
0fdeec4c5f
todd71027f4b
5 months agoReviewers