|
|
@ -27,7 +27,6 @@ import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;
|
|
|
@ -37,7 +36,6 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -56,6 +54,7 @@ public class PushNotificationSchedulerTask implements Runnable {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
Map<Integer, List<OperationMapping>> operationMappingsTenantMap = new HashMap<>();
|
|
|
|
Map<Integer, List<OperationMapping>> operationMappingsTenantMap = new HashMap<>();
|
|
|
|
List<OperationMapping> operationsCompletedList = new LinkedList<>();
|
|
|
|
List<OperationMapping> operationsCompletedList = new LinkedList<>();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
@ -63,16 +62,14 @@ public class PushNotificationSchedulerTask implements Runnable {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//Get next available operation list per device batch
|
|
|
|
//Get next available operation list per device batch
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
operationMappingsTenantMap = operationDAO.getOperationMappingsByStatus(Operation.Status
|
|
|
|
operationMappingsTenantMap = operationDAO.getOperationMappingsByStatus(Operation.Status
|
|
|
|
.PENDING, Operation.PushStatus.SCHEDULED, DeviceConfigurationManager.getInstance()
|
|
|
|
.PENDING, Operation.PushNotificationStatus.SCHEDULED, DeviceConfigurationManager.getInstance()
|
|
|
|
.getDeviceManagementConfig().getPushNotificationConfiguration().getSchedulerBatchSize());
|
|
|
|
.getDeviceManagementConfig().getPushNotificationConfiguration().getSchedulerBatchSize());
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
log.error("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
log.error("Unable to retrieve scheduled pending operations for task.", e);
|
|
|
|
log.error("Unable to retrieve scheduled pending operations for task.", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Sending push notification to each device
|
|
|
|
// Sending push notification to each device
|
|
|
|
for (List<OperationMapping> operationMappings : operationMappingsTenantMap.values()) {
|
|
|
|
for (List<OperationMapping> operationMappings : operationMappingsTenantMap.values()) {
|
|
|
@ -92,7 +89,7 @@ public class PushNotificationSchedulerTask implements Runnable {
|
|
|
|
notificationStrategy.execute(new NotificationContext(operationMapping.getDeviceIdentifier(),
|
|
|
|
notificationStrategy.execute(new NotificationContext(operationMapping.getDeviceIdentifier(),
|
|
|
|
provider.getOperation(operationMapping.getDeviceIdentifier().getType(), operationMapping
|
|
|
|
provider.getOperation(operationMapping.getDeviceIdentifier().getType(), operationMapping
|
|
|
|
.getOperationId())));
|
|
|
|
.getOperationId())));
|
|
|
|
operationMapping.setPushStatus(Operation.PushStatus.COMPLETED);
|
|
|
|
operationMapping.setPushNotificationStatus(Operation.PushNotificationStatus.COMPLETED);
|
|
|
|
operationsCompletedList.add(operationMapping);
|
|
|
|
operationsCompletedList.add(operationMapping);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
log.error("Error occurred while getting notification strategy for operation mapping " +
|
|
|
|
log.error("Error occurred while getting notification strategy for operation mapping " +
|
|
|
@ -123,5 +120,8 @@ public class PushNotificationSchedulerTask implements Runnable {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Push notification job running completed.");
|
|
|
|
log.debug("Push notification job running completed.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Throwable cause) {
|
|
|
|
|
|
|
|
log.error("PushNotificationSchedulerTask failed due to " + cause);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|