Merge branch 'master' into 'master'

Fix the task running issue in tenant mode

See merge request entgra/carbon-device-mgt!39
revert-70aa11f8
Charitha Goonetilleke 6 years ago
commit e39478c0d2

@ -147,8 +147,7 @@ public class OperationManagerImpl implements OperationManager {
} }
@Override @Override
public Activity addOperation(Operation operation, public Activity addOperation(Operation operation, List<DeviceIdentifier> deviceIds)
List<DeviceIdentifier> deviceIds)
throws OperationManagementException, InvalidDeviceException { throws OperationManagementException, InvalidDeviceException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("operation:[" + operation.toString() + "]"); log.debug("operation:[" + operation.toString() + "]");
@ -160,7 +159,13 @@ public class OperationManagerImpl implements OperationManager {
try { try {
DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds); DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList(); List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
if (validDeviceIds.size() > 0) { if (!validDeviceIds.isEmpty()) {
if (log.isDebugEnabled() && deviceIds.get(0).getType() != null) {
log.debug("Adding operation for Device type : " + deviceIds.get(0).getType() + ", tenant ID:"
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId() + ", domain:"
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()
+ ", device count:" + deviceIds.size() + " operation type:" + operation.getCode());
}
DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds); DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
List<DeviceIdentifier> authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList(); List<DeviceIdentifier> authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList();
if (authorizedDeviceIds.size() <= 0) { if (authorizedDeviceIds.size() <= 0) {
@ -285,6 +290,11 @@ public class OperationManagerImpl implements OperationManager {
} }
private void sendNotification(Operation operation, Device device) { private void sendNotification(Operation operation, Device device) {
if (log.isDebugEnabled()) {
log.debug("Sending notification for device id: " + device.getDeviceIdentifier() + ", type:" + device
.getType() + ", tenant:" + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()
+ ", domain:" + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());
}
NotificationStrategy notificationStrategy = getNotificationStrategy(); NotificationStrategy notificationStrategy = getNotificationStrategy();
/* /*
* If notification strategy has not enable to send push notification using scheduler task we will send * If notification strategy has not enable to send push notification using scheduler task we will send
@ -315,6 +325,9 @@ public class OperationManagerImpl implements OperationManager {
log.error("Error occurred while setting push notification status to SCHEDULED.", ex); log.error("Error occurred while setting push notification status to SCHEDULED.", ex);
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
} }
} catch (Exception e) {
log.error("Error occurred while sending notifications to " + device.getType() + " device carrying id '"
+ device.getDeviceIdentifier() + "'", e);
} }
} }
} }

@ -86,6 +86,10 @@ public class DeviceDetailsRetrieverTask implements Task {
try { try {
List<Integer> tenants = DeviceManagementDataHolder.getInstance(). List<Integer> tenants = DeviceManagementDataHolder.getInstance().
getDeviceManagementProvider().getDeviceEnrolledTenants(); getDeviceManagementProvider().getDeviceEnrolledTenants();
if (log.isDebugEnabled()) {
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(). String tenantDomain = DeviceManagementDataHolder.getInstance().
getRealmService().getTenantManager().getDomain(tenant); getRealmService().getTenantManager().getDomain(tenant);

@ -22,6 +22,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.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.MonitoringOperation; import org.wso2.carbon.device.mgt.common.MonitoringOperation;
@ -84,18 +85,26 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
try { try {
List<Device> devices; List<Device> devices;
List<String> operations; List<String> operations;
List<DeviceIdentifier> validDeviceIdentifiers;
operations = this.getValidOperationNames(); //list operations for each device type operations = this.getValidOperationNames(); //list operations for each device type
devices = deviceManagementProviderService.getAllDevices(deviceType, false);//list devices for each type devices = deviceManagementProviderService.getAllDevices(deviceType, false);//list devices for each type
if (!devices.isEmpty()) { if (!devices.isEmpty()) {
if (operations != null && DeviceManagerUtil.getValidDeviceIdentifiers(devices).size() != 0) { if (log.isDebugEnabled() && deviceType != null) {
log.info("Devices exist to add operations and the total number of devices are " + devices.size());
}
validDeviceIdentifiers = DeviceManagerUtil.getValidDeviceIdentifiers(devices);
if (!validDeviceIdentifiers.isEmpty()) {
if (log.isDebugEnabled() && deviceType != null) {
log.debug("Number of valid device identifier size to add operations: " + validDeviceIdentifiers
.size());
}
for (String str : operations) { for (String str : operations) {
CommandOperation operation = new CommandOperation(); CommandOperation operation = new CommandOperation();
operation.setEnabled(true); operation.setEnabled(true);
operation.setType(Operation.Type.COMMAND); operation.setType(Operation.Type.COMMAND);
operation.setCode(str); operation.setCode(str);
deviceManagementProviderService.addOperation(deviceType, operation, deviceManagementProviderService.addOperation(deviceType, operation, validDeviceIdentifiers);
DeviceManagerUtil.getValidDeviceIdentifiers(devices));
} }
} else { } else {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -174,4 +183,3 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
} }
} }

Loading…
Cancel
Save