From 174b10a4d65ae8fdee07eb405f7faed5b3ccd878 Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Wed, 3 Apr 2024 16:07:34 +0530 Subject: [PATCH] Add Tenant TaskConfigurations dummy commit --- .../metadata/mgt/DeviceFrequencyMap.java | 35 ++++ .../mgt/DeviceTaskConfigurationService.java | 47 +++++ .../internal/DeviceManagementDataHolder.java | 10 ++ .../DeviceManagementServiceComponent.java | 18 +- .../DeviceTaskConfigurationServiceImpl.java | 164 ++++++++++++++++++ .../mgt/TaskConfigurationStartupHandler.java | 58 +++++++ .../mgt/dao/util/MetadataConstants.java | 1 + .../mgt/core/task/DeviceTaskManager.java | 3 +- .../mgt/core/device/mgt/core/task/Utils.java | 9 + .../task/impl/DeviceDetailsRetrieverTask.java | 16 +- .../core/task/impl/DeviceTaskManagerImpl.java | 10 +- .../mgt/core/task/DeviceTaskManagerTest.java | 22 ++- .../mgt/common/spi/TenantManagerService.java | 1 + .../core/tenant/mgt/core/TenantManager.java | 7 + .../mgt/core/impl/TenantManagerImpl.java | 14 ++ .../core/impl/TenantManagerServiceImpl.java | 5 + .../core/internal/TenantMgtDataHolder.java | 10 ++ .../internal/TenantMgtServiceComponent.java | 4 + .../listener/DeviceMgtTenantListener.java | 1 + 19 files changed, 416 insertions(+), 19 deletions(-) create mode 100644 components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceFrequencyMap.java create mode 100644 components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceTaskConfigurationService.java create mode 100644 components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceTaskConfigurationServiceImpl.java create mode 100644 components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/TaskConfigurationStartupHandler.java diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceFrequencyMap.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceFrequencyMap.java new file mode 100644 index 0000000000..fa5ca3328a --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceFrequencyMap.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.device.mgt.core.device.mgt.common.metadata.mgt; + +import java.util.HashMap; + +public class DeviceFrequencyMap extends HashMap { + public static class Device { + private int frequency; + + public int getFrequency() { + return frequency; + } + + public void setFrequency(int frequency) { + this.frequency = frequency; + } + } +} diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceTaskConfigurationService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceTaskConfigurationService.java new file mode 100644 index 0000000000..6099edd908 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/metadata/mgt/DeviceTaskConfigurationService.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.device.mgt.core.device.mgt.common.metadata.mgt; + +import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; + + +public interface DeviceTaskConfigurationService { + + /** + * This method is useful to + * + * @throws MetadataManagementException if error while adding default TaskFrequency + */ + void addDefaultTaskFrequency(int tenantId) throws MetadataManagementException; + + /** + * This method is useful to reset existing TaskFrequency to default values in xml + * + * @throws MetadataManagementException if error while resetting default TaskFrequency + */ + void resetToDefaultTaskFrequency() throws MetadataManagementException; + + /** + * This method is useful to get existing TaskFrequency by device type and tenant id + * + * @throws MetadataManagementException if error while getting existing TaskFrequency + */ + int getTaskFrequency(String deviceType, int tenantId) throws MetadataManagementException; + +} diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementDataHolder.java index 6736874487..f56bb49ef6 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -21,6 +21,7 @@ package io.entgra.device.mgt.core.device.mgt.core.internal; import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices; import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceTaskConfigurationService; import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService; import org.wso2.carbon.context.PrivilegedCarbonContext; import io.entgra.device.mgt.core.device.mgt.common.DeviceStatusTaskPluginConfig; @@ -98,6 +99,7 @@ public class DeviceManagementDataHolder { private DeviceStatusManagementService deviceStatusManagementService; private APIApplicationServices apiApplicationServices; private PublisherRESTAPIServices publisherRESTAPIServices; + private DeviceTaskConfigurationService deviceTaskConfigurationService; private final Map deviceStatusTaskPluginConfigs = Collections.synchronizedMap( new HashMap<>()); @@ -398,6 +400,14 @@ public class DeviceManagementDataHolder { this.deviceStatusManagementService = deviceStatusManagementService; } + public DeviceTaskConfigurationService getDeviceTaskConfigurationService() { + return deviceTaskConfigurationService; + } + + public void setDeviceTaskConfigurationService(DeviceTaskConfigurationService deviceTaskConfigurationService) { + this.deviceTaskConfigurationService = deviceTaskConfigurationService; + } + public TraccarManagementService getTraccarManagementService() { TraccarManagementService traccarManagementService; PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementServiceComponent.java index b3bc1f2f0d..4852ace9fe 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -18,7 +18,7 @@ package io.entgra.device.mgt.core.device.mgt.core.internal; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService; -import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceStatusManagementServiceImpl; +import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.*; import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -33,6 +33,7 @@ import io.entgra.device.mgt.core.device.mgt.common.event.config.EventConfigurati import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeoLocationProviderService; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceTaskConfigurationService; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.WhiteLabelManagementService; import io.entgra.device.mgt.core.device.mgt.common.notification.mgt.NotificationManagementService; @@ -62,8 +63,6 @@ import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.DeviceInform import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl; import io.entgra.device.mgt.core.device.mgt.core.event.config.EventConfigurationProviderServiceImpl; import io.entgra.device.mgt.core.device.mgt.core.geo.service.GeoLocationProviderServiceImpl; -import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.MetadataManagementServiceImpl; -import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.WhiteLabelManagementServiceImpl; import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.notification.mgt.NotificationManagementServiceImpl; import io.entgra.device.mgt.core.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory; @@ -416,6 +415,19 @@ public class DeviceManagementServiceComponent { ExecutorService executorService = Executors.newFixedThreadPool(50); DeviceManagementDataHolder.getInstance().setEventConfigExecutors(executorService); + +// /* Registering Device Task manager Service */ +// DeviceTaskConfigurationService deviceTaskConfigurationService = new DeviceTaskConfigurationServiceImpl(); +// DeviceManagementDataHolder.getInstance().setDeviceTaskConfigurationService(deviceTaskConfigurationService); +// try { +// deviceTaskConfigurationService.addDefaultTaskFrequency(tenantId); +// } catch (Throwable e) { +// log.error("Error occurred while adding default device task frequency", e); +// +// } +// bundleContext.registerService(DeviceTaskConfigurationService.class.getName(), deviceTaskConfigurationService, null); + /* Registering Device Task manager Service */ + bundleContext.registerService(ServerStartupObserver.class, new TaskConfigurationStartupHandler(), null); } private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceTaskConfigurationServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceTaskConfigurationServiceImpl.java new file mode 100644 index 0000000000..9d722637d3 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/DeviceTaskConfigurationServiceImpl.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.device.mgt.core.device.mgt.core.metadata.mgt; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import io.entgra.device.mgt.core.device.mgt.common.OperationMonitoringTaskConfig; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceFrequencyMap; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceTaskConfigurationService; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata; +import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceType; +import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder; +import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataDAO; +import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOException; +import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory; +import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util.MetadataConstants; +import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public class DeviceTaskConfigurationServiceImpl implements DeviceTaskConfigurationService { + + private static final Log log = LogFactory.getLog(DeviceTaskConfigurationServiceImpl.class); + + private final MetadataDAO metadataDAO; + + public DeviceTaskConfigurationServiceImpl() { + this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO(); + } + + private void addMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException { + metadataDAO.addMetadata(tenantId, metadata); + if (log.isDebugEnabled()) { + log.debug(key + " metadata entry has been inserted successfully"); + } + } + + private Metadata constructTaskFrequencyMetadata(Map deviceFrequencies) { + JsonObject jsonObject = new JsonObject(); + + for (Map.Entry entry : deviceFrequencies.entrySet()) { + String deviceType = entry.getKey(); + int frequency = entry.getValue(); + + // Create a JsonObject for the current device type + JsonObject deviceObject = new JsonObject(); + deviceObject.addProperty("frequency", String.valueOf(frequency)); + jsonObject.add(deviceType, deviceObject); + } + + Metadata metadata = new Metadata(); + metadata.setMetaKey(MetadataConstants.DEVICE_TASK_FREQUENCY); + metadata.setMetaValue(jsonObject.toString()); + + return metadata; + } + + + private int getDefaultTaskFrequency(String deviceType) { + DeviceManagementProviderService dms = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(); + OperationMonitoringTaskConfig operationMonitoringTaskConfig = dms.getDeviceMonitoringConfig(deviceType); + return operationMonitoringTaskConfig.getFrequency(); + } + + @Override + public void addDefaultTaskFrequency(int tenantId) throws MetadataManagementException { + try { + Map deviceFrequencies = new HashMap<>(); + DeviceManagementProviderService dms = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(); + List deviceTypes = dms.getDeviceTypes(); + log.error("addDefaultTaskFrequency"); + for (DeviceType deviceType : deviceTypes) { + log.error(deviceType.getName()); + log.error(getDefaultTaskFrequency(deviceType.getName())); + deviceFrequencies.put(deviceType.getName(), getDefaultTaskFrequency(deviceType.getName())); + } + MetadataManagementDAOFactory.beginTransaction(); + if (!metadataDAO.isExist(tenantId, MetadataConstants.DEVICE_TASK_FREQUENCY)) { + Metadata defaultTaskFrequencyMetadata = constructTaskFrequencyMetadata(deviceFrequencies); + // Add default TaskFrequency + addMetadataEntry(tenantId, defaultTaskFrequencyMetadata, MetadataConstants.DEVICE_TASK_FREQUENCY); + } + MetadataManagementDAOFactory.commitTransaction(); + } catch (MetadataManagementDAOException e) { + MetadataManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while inserting default task frequency metadata entry."; + log.error(msg, e); + throw new MetadataManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new MetadataManagementException(msg, e); + } catch (DeviceManagementException e) { + throw new RuntimeException(e); + } finally { + MetadataManagementDAOFactory.closeConnection(); + } + + } + + @Override + public void resetToDefaultTaskFrequency() throws MetadataManagementException { + + } + + @Override + public int getTaskFrequency(String deviceType, int tenantId) throws MetadataManagementException { + try { + MetadataManagementDAOFactory.openConnection(); + Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.DEVICE_TASK_FREQUENCY); + String metaValue = metadata.getMetaValue(); + + if(metaValue == null){ + addDefaultTaskFrequency(tenantId); + } + + Gson gson = new Gson(); + DeviceFrequencyMap deviceFrequencyMap = gson.fromJson(metaValue, DeviceFrequencyMap.class); + + // Check if the device type exists in the map + if (deviceFrequencyMap.containsKey(deviceType)) { + // Retrieve the frequency for the given device type + return deviceFrequencyMap.get(deviceType).getFrequency(); + } else { + throw new MetadataManagementException("Device type not found: " + deviceType); + } + } catch (MetadataManagementDAOException e) { + String msg = "Error occurred while retrieving device task frequency metadata for tenant:" + tenantId; + log.error(msg, e); + throw new MetadataManagementException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while opening a connection to the data source"; + log.error(msg, e); + throw new MetadataManagementException(msg, e); + } finally { + MetadataManagementDAOFactory.closeConnection(); + } + } +} diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/TaskConfigurationStartupHandler.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/TaskConfigurationStartupHandler.java new file mode 100644 index 0000000000..1652cc8217 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/TaskConfigurationStartupHandler.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.device.mgt.core.device.mgt.core.metadata.mgt; + +import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceTaskConfigurationService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.core.ServerStartupObserver; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; + +public class TaskConfigurationStartupHandler implements ServerStartupObserver { + + private static final Log log = LogFactory.getLog(TaskConfigurationStartupHandler.class); + + @Override + public void completingServerStartup() { + + } + + @Override + public void completedServerStartup() { + Thread t = new Thread(new Runnable() { + @Override + public void run() { + if (log.isDebugEnabled()) { + log.debug("Server has just started, hence started publishing unpublished APIs"); + log.debug("Total number of unpublished APIs: "); + } + DeviceTaskConfigurationService deviceTaskConfigurationService = new DeviceTaskConfigurationServiceImpl(); + try { + deviceTaskConfigurationService.addDefaultTaskFrequency(MultitenantConstants.SUPER_TENANT_ID); + } catch (MetadataManagementException e) { + throw new RuntimeException(e); + } + log.info("Finish Adding default task"); + } + }); + t.start(); + } + +} diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/dao/util/MetadataConstants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/dao/util/MetadataConstants.java index 5d2c44af42..e3ff271383 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/dao/util/MetadataConstants.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/metadata/mgt/dao/util/MetadataConstants.java @@ -23,4 +23,5 @@ public class MetadataConstants { public static final String ALLOWED_DEVICE_STATUS_META_KEY = "allowed_device_status"; public static final String IS_DEVICE_STATUS_CHECK_META_KEY = "device-status-check"; + public static final String DEVICE_TASK_FREQUENCY = "device_task_frequency"; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/DeviceTaskManager.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/DeviceTaskManager.java index 1ec11d9b3d..33351eac6f 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/DeviceTaskManager.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/DeviceTaskManager.java @@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.device.mgt.core.task; import io.entgra.device.mgt.core.device.mgt.common.DynamicTaskContext; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; public interface DeviceTaskManager { @@ -58,7 +59,7 @@ public interface DeviceTaskManager { * This method will add the operations to devices * @throws DeviceMgtTaskException */ - void addOperations(DynamicTaskContext dynamicTaskContext) throws DeviceMgtTaskException; + void addOperations(DynamicTaskContext dynamicTaskContext, int frequency) throws DeviceMgtTaskException, MetadataManagementException; // /** diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/Utils.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/Utils.java index fce1336c86..9b9ca58202 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/Utils.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/Utils.java @@ -18,6 +18,9 @@ package io.entgra.device.mgt.core.device.mgt.core.task; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceTaskConfigurationService; +import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.context.PrivilegedCarbonContext; import java.util.ArrayList; @@ -67,4 +70,10 @@ public class Utils { } } + public static int getTenantedTaskFrequency(int tenantId, String deviceType) throws MetadataManagementException { + DeviceTaskConfigurationService deviceTaskConfigurationService = DeviceManagementDataHolder.getInstance().getDeviceTaskConfigurationService(); + return deviceTaskConfigurationService.getTaskFrequency(deviceType, tenantId); + } + + } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index 9ddeea4e7a..0fa3a6d8cd 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -18,6 +18,8 @@ package io.entgra.device.mgt.core.device.mgt.core.task.impl; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; +import io.entgra.device.mgt.core.device.mgt.core.task.Utils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.base.MultitenantConstants; @@ -64,13 +66,13 @@ public class DeviceDetailsRetrieverTask extends DynamicPartitionedScheduleTask { } for (Integer tenant : tenants) { if (MultitenantConstants.SUPER_TENANT_ID == tenant) { - this.executeTask(operationMonitoringTaskConfig, startupOperationConfig); + this.executeTask(operationMonitoringTaskConfig, startupOperationConfig, Utils.getTenantedTaskFrequency(MultitenantConstants.SUPER_TENANT_ID , deviceType)); continue; } try { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant, true); - this.executeTask(operationMonitoringTaskConfig, startupOperationConfig); + this.executeTask(operationMonitoringTaskConfig, startupOperationConfig, Utils.getTenantedTaskFrequency(tenant, deviceType)); } finally { PrivilegedCarbonContext.endTenantFlow(); } @@ -78,6 +80,9 @@ public class DeviceDetailsRetrieverTask extends DynamicPartitionedScheduleTask { } catch (DeviceManagementException e) { 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."; + log.error(msg, e); } } @@ -87,7 +92,7 @@ public class DeviceDetailsRetrieverTask extends DynamicPartitionedScheduleTask { * @param startupOperationConfig which contains startup operations and realted details */ private void executeTask(OperationMonitoringTaskConfig operationMonitoringTaskConfig, - StartupOperationConfig startupOperationConfig) { + StartupOperationConfig startupOperationConfig, int frequency) { DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, operationMonitoringTaskConfig, startupOperationConfig); @@ -97,11 +102,14 @@ public class DeviceDetailsRetrieverTask extends DynamicPartitionedScheduleTask { //pass the configurations also from here, monitoring tasks try { if (deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType)) { - deviceTaskManager.addOperations(getTaskContext()); + deviceTaskManager.addOperations(getTaskContext(), frequency); } } catch (DeviceMgtTaskException e) { 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."; + log.error(msg, e); } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/impl/DeviceTaskManagerImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/impl/DeviceTaskManagerImpl.java index cce42b48a0..890e99eab5 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/impl/DeviceTaskManagerImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/task/impl/DeviceTaskManagerImpl.java @@ -100,11 +100,11 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { @Override - public void addOperations(DynamicTaskContext dynamicTaskContext) throws DeviceMgtTaskException { + public void addOperations(DynamicTaskContext dynamicTaskContext, int frequency) throws DeviceMgtTaskException { DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance(). getDeviceManagementProvider(); //list operations for device type - List operations = this.getValidOperationNames(); + List operations = this.getValidOperationNames(frequency); if (operations.isEmpty()) { if (log.isDebugEnabled()) { log.debug("No operations are available."); @@ -125,12 +125,14 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { } } - private List getValidOperationNames() throws DeviceMgtTaskException { + private List getValidOperationNames(int frequency) throws DeviceMgtTaskException { List monitoringOperations = this.getOperationList(); List opNames = new ArrayList<>(); Long milliseconds = System.currentTimeMillis(); - int frequency = this.getTaskFrequency(); + //int frequency = Utils.getTenantedTaskFrequency(tenantId,deviceType); + log.info("frequency" + frequency); + System.out.println("frequency" + frequency); Map mp = Utils.getTenantedTaskOperationMap(map, deviceType); for (MonitoringOperation top : monitoringOperations) { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/task/DeviceTaskManagerTest.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/task/DeviceTaskManagerTest.java index e232bffe44..659ac984cc 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/task/DeviceTaskManagerTest.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/java/io/entgra/device/mgt/core/device/mgt/core/task/DeviceTaskManagerTest.java @@ -18,6 +18,8 @@ package io.entgra.device.mgt.core.device.mgt.core.task; import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceTaskConfigurationService; +import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceTaskConfigurationServiceImpl; import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -63,6 +65,7 @@ public class DeviceTaskManagerTest extends BaseDeviceManagementTest { private static final Log log = LogFactory.getLog(DeviceTaskManagerTest.class); private static final String NEW_DEVICE_TYPE = "NEW-DEVICE-TYPE"; + private static final int FREQUENCY = 60000; private List deviceIds; private DeviceTaskManager deviceTaskManager; private DeviceManagementProviderService deviceMgtProviderService; @@ -89,6 +92,8 @@ public class DeviceTaskManagerTest extends BaseDeviceManagementTest { HeartBeatManagementService heartBeatManagementService = new TestHeartBeatManagementService(); DeviceManagementDataHolder.getInstance() .setHeartBeatService(heartBeatManagementService); + DeviceTaskConfigurationService deviceTaskConfigurationService = new DeviceTaskConfigurationServiceImpl(); + DeviceManagementDataHolder.getInstance().setDeviceTaskConfigurationService(deviceTaskConfigurationService); this.operationManager = PowerMockito.spy( new OperationManagerImpl(TestDataHolder.TEST_DEVICE_TYPE, deviceManagementService)); try { @@ -121,9 +126,9 @@ public class DeviceTaskManagerTest extends BaseDeviceManagementTest { } @Test(groups = "Device Task Manager Test Group", description = "Testing adding operations to devices.") - public void testAddOperation() throws DeviceMgtTaskException, OperationManagementException { + public void testAddOperation() throws DeviceMgtTaskException, OperationManagementException, MetadataManagementException { log.info("Attempting to add operations for devices."); - this.deviceTaskManager.addOperations(null); + this.deviceTaskManager.addOperations(null,FREQUENCY); for (DeviceIdentifier deviceId : deviceIds) { List operationList = this.operationManager.getOperations(deviceId); Assert.assertNotNull(operationList); @@ -134,25 +139,28 @@ public class DeviceTaskManagerTest extends BaseDeviceManagementTest { @Test(groups = "Device Task Manager Test Group", description = "Testing adding operations when no devices are available") - public void testAddOperationsWithoutDevices() throws DeviceManagementException, DeviceMgtTaskException { + public void testAddOperationsWithoutDevices() throws DeviceManagementException, DeviceMgtTaskException, MetadataManagementException { this.deviceMgtProviderService.registerDeviceType( new TestDeviceManagementService(NEW_DEVICE_TYPE, TestDataHolder.SUPER_TENANT_DOMAIN)); DeviceTaskManager taskManager = new DeviceTaskManagerImpl(NEW_DEVICE_TYPE, TestDataHolder.generateMonitoringTaskConfig(true, 50000, 3)); - taskManager.addOperations(null); + taskManager.addOperations(null, FREQUENCY); } @Test(groups = "Device Task Manager Test Group", dependsOnMethods = "testAddOperationsWithoutDevices", description = "Testing adding operations when no operations are scheduled") - public void testAddOperationsWithoutOperations() throws DeviceMgtTaskException { + public void testAddOperationsWithoutOperations() throws DeviceMgtTaskException, MetadataManagementException { DeviceTaskManager taskManager = new DeviceTaskManagerImpl(NEW_DEVICE_TYPE, TestDataHolder.generateMonitoringTaskConfig(true, 50000, 3)); - taskManager.addOperations(null); + taskManager.addOperations(null, FREQUENCY); } @Test(groups = "Device Task Manager Test Group", description = "Testing device detail retriever task execution") - public void testDeviceDetailRetrieverTaskExecute() throws OperationManagementException { + public void testDeviceDetailRetrieverTaskExecute() throws OperationManagementException, MetadataManagementException { DeviceDetailsRetrieverTask deviceDetailsRetrieverTask = new DeviceDetailsRetrieverTask(); + DeviceTaskConfigurationService deviceTaskConfigurationService = DeviceManagementDataHolder + .getInstance().getDeviceTaskConfigurationService(); + deviceTaskConfigurationService.addDefaultTaskFrequency(MultitenantConstants.SUPER_TENANT_ID); Map map = new HashMap<>(); map.put("DEVICE_TYPE", TestDataHolder.TEST_DEVICE_TYPE); deviceDetailsRetrieverTask.setProperties(map); diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.common/src/main/java/io/entgra/device/mgt/core/tenant/mgt/common/spi/TenantManagerService.java b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.common/src/main/java/io/entgra/device/mgt/core/tenant/mgt/common/spi/TenantManagerService.java index a43f20f24c..5577ef4368 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.common/src/main/java/io/entgra/device/mgt/core/tenant/mgt/common/spi/TenantManagerService.java +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.common/src/main/java/io/entgra/device/mgt/core/tenant/mgt/common/spi/TenantManagerService.java @@ -26,4 +26,5 @@ public interface TenantManagerService { void addDefaultAppCategories(TenantInfoBean tenantInfoBean) throws TenantMgtException; void addDefaultDeviceStatusFilters(TenantInfoBean tenantInfoBean) throws TenantMgtException; + void addDefaultDeviceTaskConfiguration(TenantInfoBean tenantInfoBean) throws TenantMgtException; } \ No newline at end of file diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/TenantManager.java b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/TenantManager.java index 97eb706be7..3cf7e7fc62 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/TenantManager.java +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/TenantManager.java @@ -43,4 +43,11 @@ public interface TenantManager { * @throws TenantMgtException Throws when error occurred while adding default application categories */ void addDefaultDeviceStatusFilters(TenantInfoBean tenantInfoBean) throws TenantMgtException; + + /** + * Add default device task configuration to a tenant described by the tenant info bean + * @param tenantInfoBean The info bean that provides tenant info + * @throws TenantMgtException Throws when error occurred while adding default TaskFrequency + */ + void addDefaultDeviceTaskConfiguration(TenantInfoBean tenantInfoBean) throws TenantMgtException; } diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/impl/TenantManagerImpl.java b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/impl/TenantManagerImpl.java index 5dc2eb7f08..539f242364 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/impl/TenantManagerImpl.java +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/impl/TenantManagerImpl.java @@ -113,6 +113,20 @@ public class TenantManagerImpl implements TenantManager { } } + @Override + public void addDefaultDeviceTaskConfiguration(TenantInfoBean tenantInfoBean) throws TenantMgtException { + initTenantFlow(tenantInfoBean); + try { + TenantMgtDataHolder.getInstance().getDeviceTaskConfigurationService().addDefaultTaskFrequency(tenantInfoBean.getTenantId()); + } catch (MetadataManagementException e) { + String msg = "Error occurred while adding default TaskFrequency"; + log.error(msg, e); + throw new TenantMgtException(msg, e); + } finally { + endTenantFlow(); + } + } + private void initTenantFlow(TenantInfoBean tenantInfoBean) { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/impl/TenantManagerServiceImpl.java b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/impl/TenantManagerServiceImpl.java index da21a52100..21d0350e66 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/impl/TenantManagerServiceImpl.java +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/impl/TenantManagerServiceImpl.java @@ -38,4 +38,9 @@ public class TenantManagerServiceImpl implements TenantManagerService { public void addDefaultDeviceStatusFilters(TenantInfoBean tenantInfoBean) throws TenantMgtException { TenantMgtDataHolder.getInstance().getTenantManager().addDefaultDeviceStatusFilters(tenantInfoBean); } + + @Override + public void addDefaultDeviceTaskConfiguration(TenantInfoBean tenantInfoBean) throws TenantMgtException { + TenantMgtDataHolder.getInstance().getTenantManager().addDefaultDeviceTaskConfiguration(tenantInfoBean); + } } diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtDataHolder.java b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtDataHolder.java index 9658d68848..b386b436e7 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtDataHolder.java +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtDataHolder.java @@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.tenant.mgt.core.internal; import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceTaskConfigurationService; import io.entgra.device.mgt.core.tenant.mgt.core.TenantManager; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.WhiteLabelManagementService; import org.wso2.carbon.user.core.service.RealmService; @@ -34,6 +35,7 @@ public class TenantMgtDataHolder { private RealmService realmService; private DeviceStatusManagementService deviceStatusManagementService; + private DeviceTaskConfigurationService deviceTaskConfigurationService; public RealmService getRealmService() { return realmService; @@ -78,4 +80,12 @@ public class TenantMgtDataHolder { public void setDeviceStatusManagementService(DeviceStatusManagementService deviceStatusManagementService) { this.deviceStatusManagementService = deviceStatusManagementService; } + + public DeviceTaskConfigurationService getDeviceTaskConfigurationService() { + return deviceTaskConfigurationService; + } + + public void setDeviceTaskConfigurationService(DeviceTaskConfigurationService deviceTaskConfigurationService) { + this.deviceTaskConfigurationService = deviceTaskConfigurationService; + } } diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java index fa2f26c972..d3b6ea4c3d 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/internal/TenantMgtServiceComponent.java @@ -19,7 +19,9 @@ package io.entgra.device.mgt.core.tenant.mgt.core.internal; import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager; import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceTaskConfigurationService; import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceStatusManagementServiceImpl; +import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceTaskConfigurationServiceImpl; import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerService; import io.entgra.device.mgt.core.tenant.mgt.core.TenantManager; import io.entgra.device.mgt.core.tenant.mgt.core.impl.TenantManagerImpl; @@ -70,6 +72,8 @@ public class TenantMgtServiceComponent { componentContext.getBundleContext().registerService(DeviceStatusManagementService.class.getName(), deviceStatusManagementService, null); TenantMgtDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService); + DeviceTaskConfigurationService deviceTaskConfigurationService = new DeviceTaskConfigurationServiceImpl(); + TenantMgtDataHolder.getInstance().setDeviceTaskConfigurationService(deviceTaskConfigurationService); DeviceMgtTenantListener deviceMgtTenantListener = new DeviceMgtTenantListener(); if(log.isDebugEnabled()) { log.info("Tenant management listener is registering"); diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/listener/DeviceMgtTenantListener.java b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/listener/DeviceMgtTenantListener.java index 978e69b0e4..69437fc84b 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/listener/DeviceMgtTenantListener.java +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/src/main/java/io/entgra/device/mgt/core/tenant/mgt/core/listener/DeviceMgtTenantListener.java @@ -39,6 +39,7 @@ public class DeviceMgtTenantListener implements TenantMgtListener { tenantManager.addDefaultRoles(tenantInfoBean); tenantManager.addDefaultAppCategories(tenantInfoBean); tenantManager.addDefaultDeviceStatusFilters(tenantInfoBean); + tenantManager.addDefaultDeviceTaskConfiguration(tenantInfoBean); } catch (TenantMgtException e) { String msg = "Error occurred while executing tenant creation flow"; log.error(msg, e);