mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Rename push status to push notification status and add configurable initial delay for scheduler task
This commit is contained in:
parent
1470abeb0b
commit
e1e2b14b5f
@ -21,6 +21,7 @@ import org.wso2.carbon.device.mgt.common.*;
|
|||||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This represents the Device Operation management functionality which should be implemented by
|
* This represents the Device Operation management functionality which should be implemented by
|
||||||
|
|||||||
@ -90,6 +90,7 @@ public final class DeviceManagementConstants {
|
|||||||
private PushNotifications() {
|
private PushNotifications() {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
public static final int DEFAULT_SCHEDULER_TASK_INITIAL_DELAY = 60000;
|
||||||
public static final int DEFAULT_BATCH_DELAY_MILLS = 60000;
|
public static final int DEFAULT_BATCH_DELAY_MILLS = 60000;
|
||||||
public static final int DEFAULT_BATCH_SIZE = 1000;
|
public static final int DEFAULT_BATCH_SIZE = 1000;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,35 +28,46 @@ import java.util.List;
|
|||||||
@XmlRootElement(name = "PushNotificationConfiguration")
|
@XmlRootElement(name = "PushNotificationConfiguration")
|
||||||
public class PushNotificationConfiguration {
|
public class PushNotificationConfiguration {
|
||||||
|
|
||||||
private int SchedulerBatchSize;
|
private int schedulerBatchSize;
|
||||||
private int SchedulerBatchDelayMills;
|
private int schedulerBatchDelayMills;
|
||||||
private boolean SchedulerTaskEnabled;
|
private int schedulerTaskInitialDelay;
|
||||||
|
private boolean schedulerTaskEnabled;
|
||||||
private List<String> pushNotificationProviders;
|
private List<String> pushNotificationProviders;
|
||||||
|
|
||||||
@XmlElement(name = "SchedulerBatchSize", required = true)
|
@XmlElement(name = "SchedulerBatchSize", required = true)
|
||||||
public int getSchedulerBatchSize() {
|
public int getSchedulerBatchSize() {
|
||||||
return SchedulerBatchSize;
|
return schedulerBatchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSchedulerBatchSize(int SchedulerBatchSize) {
|
public void setSchedulerBatchSize(int schedulerBatchSize) {
|
||||||
this.SchedulerBatchSize = SchedulerBatchSize;
|
this.schedulerBatchSize = schedulerBatchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElement(name = "SchedulerBatchDelayMills", required = true)
|
@XmlElement(name = "SchedulerBatchDelayMills", required = true)
|
||||||
public int getSchedulerBatchDelayMills() {
|
public int getSchedulerBatchDelayMills() {
|
||||||
return SchedulerBatchDelayMills;
|
return schedulerBatchDelayMills;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSchedulerBatchDelayMills(int SchedulerBatchDelayMills) {
|
public void setSchedulerBatchDelayMills(int schedulerBatchDelayMills) {
|
||||||
this.SchedulerBatchDelayMills = SchedulerBatchDelayMills;
|
this.schedulerBatchDelayMills = schedulerBatchDelayMills;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElement(name = "SchedulerTaskInitialDelay", required = true)
|
||||||
|
public int getSchedulerTaskInitialDelay() {
|
||||||
|
return schedulerTaskInitialDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSchedulerTaskInitialDelay(int schedulerTaskInitialDelay) {
|
||||||
|
this.schedulerTaskInitialDelay = schedulerTaskInitialDelay;
|
||||||
|
}
|
||||||
|
|
||||||
@XmlElement(name = "SchedulerTaskEnabled", required = true)
|
@XmlElement(name = "SchedulerTaskEnabled", required = true)
|
||||||
public boolean isSchedulerTaskEnabled() {
|
public boolean isSchedulerTaskEnabled() {
|
||||||
return SchedulerTaskEnabled;
|
return schedulerTaskEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSchedulerTaskEnabled(boolean schedulerTaskEnabled) {
|
public void setSchedulerTaskEnabled(boolean schedulerTaskEnabled) {
|
||||||
SchedulerTaskEnabled = schedulerTaskEnabled;
|
this.schedulerTaskEnabled = schedulerTaskEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlElementWrapper(name = "PushNotificationProviders", required = true)
|
@XmlElementWrapper(name = "PushNotificationProviders", required = true)
|
||||||
|
|||||||
@ -35,7 +35,7 @@ public class Operation implements Serializable {
|
|||||||
REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE
|
REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PushStatus {
|
public enum PushNotificationStatus {
|
||||||
SCHEDULED, COMPLETED
|
SCHEDULED, COMPLETED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -182,25 +182,37 @@ public class DeviceManagementServiceComponent {
|
|||||||
* of Device Management Service component in order to avoid bundle start up order related complications */
|
* of Device Management Service component in order to avoid bundle start up order related complications */
|
||||||
notifyStartupListeners();
|
notifyStartupListeners();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Device management core bundle has been successfully initialized");
|
log.debug("Push notification batch enabled : " + config.getPushNotificationConfiguration()
|
||||||
|
.isSchedulerTaskEnabled());
|
||||||
}
|
}
|
||||||
// Start Push Notification Scheduler Task
|
// Start Push Notification Scheduler Task
|
||||||
if (config.getPushNotificationConfiguration().isSchedulerTaskEnabled()) {
|
if (config.getPushNotificationConfiguration().isSchedulerTaskEnabled()) {
|
||||||
if (config.getPushNotificationConfiguration().getSchedulerBatchSize() <= 0) {
|
if (config.getPushNotificationConfiguration().getSchedulerBatchSize() <= 0) {
|
||||||
log.error("Push notification batch size cannot be 0 or less than 0. Setting default batch size to:" +
|
log.error("Push notification batch size cannot be 0 or less than 0. Setting default batch size " +
|
||||||
" " + DeviceManagementConstants.PushNotifications.DEFAULT_BATCH_SIZE);
|
"to:" + DeviceManagementConstants.PushNotifications.DEFAULT_BATCH_SIZE);
|
||||||
config.getPushNotificationConfiguration().setSchedulerBatchSize(DeviceManagementConstants.PushNotifications
|
config.getPushNotificationConfiguration().setSchedulerBatchSize(DeviceManagementConstants
|
||||||
.DEFAULT_BATCH_SIZE);
|
.PushNotifications.DEFAULT_BATCH_SIZE);
|
||||||
}
|
}
|
||||||
if (config.getPushNotificationConfiguration().getSchedulerBatchDelayMills() <= 0) {
|
if (config.getPushNotificationConfiguration().getSchedulerBatchDelayMills() <= 0) {
|
||||||
log.error("Push notification batch delay cannot be 0 or less than 0. Setting default batch delay " +
|
log.error("Push notification batch delay cannot be 0 or less than 0. Setting default batch delay " +
|
||||||
"milliseconds to" + DeviceManagementConstants.PushNotifications.DEFAULT_BATCH_DELAY_MILLS);
|
"milliseconds to" + DeviceManagementConstants.PushNotifications.DEFAULT_BATCH_DELAY_MILLS);
|
||||||
config.getPushNotificationConfiguration().setSchedulerBatchDelayMills(DeviceManagementConstants.PushNotifications
|
config.getPushNotificationConfiguration().setSchedulerBatchDelayMills(DeviceManagementConstants
|
||||||
.DEFAULT_BATCH_DELAY_MILLS);
|
.PushNotifications.DEFAULT_BATCH_DELAY_MILLS);
|
||||||
|
}
|
||||||
|
if (config.getPushNotificationConfiguration().getSchedulerTaskInitialDelay() < 0) {
|
||||||
|
log.error("Push notification initial delay cannot be less than 0. Setting default initial " +
|
||||||
|
"delay milliseconds to" + DeviceManagementConstants.PushNotifications
|
||||||
|
.DEFAULT_SCHEDULER_TASK_INITIAL_DELAY);
|
||||||
|
config.getPushNotificationConfiguration().setSchedulerTaskInitialDelay(DeviceManagementConstants
|
||||||
|
.PushNotifications.DEFAULT_SCHEDULER_TASK_INITIAL_DELAY);
|
||||||
}
|
}
|
||||||
ScheduledExecutorService pushNotificationExecutor = Executors.newSingleThreadScheduledExecutor();
|
ScheduledExecutorService pushNotificationExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||||
pushNotificationExecutor.schedule(new PushNotificationSchedulerTask(), config.getPushNotificationConfiguration()
|
pushNotificationExecutor.scheduleWithFixedDelay(new PushNotificationSchedulerTask(), config
|
||||||
.getSchedulerBatchDelayMills(), TimeUnit.MILLISECONDS);
|
.getPushNotificationConfiguration().getSchedulerTaskInitialDelay(), config
|
||||||
|
.getPushNotificationConfiguration().getSchedulerBatchDelayMills(), TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Device management core bundle has been successfully initialized");
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error("Error occurred while initializing device management core bundle", e);
|
log.error("Error occurred while initializing device management core bundle", e);
|
||||||
|
|||||||
@ -194,15 +194,13 @@ public class OperationManagerImpl implements OperationManager {
|
|||||||
log.debug("Sending push notification to " + deviceId + " from add operation method.");
|
log.debug("Sending push notification to " + deviceId + " from add operation method.");
|
||||||
}
|
}
|
||||||
notificationStrategy.execute(new NotificationContext(deviceId, operation));
|
notificationStrategy.execute(new NotificationContext(deviceId, operation));
|
||||||
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon
|
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.COMPLETED);
|
||||||
.device.mgt.core.dto.operation.mgt.Operation.PushStatus.COMPLETED);
|
|
||||||
} catch (PushNotificationExecutionFailedException e) {
|
} catch (PushNotificationExecutionFailedException e) {
|
||||||
log.error("Error occurred while sending push notifications to " +
|
log.error("Error occurred while sending push notifications to " +
|
||||||
deviceId.getType() + " device carrying id '" +
|
deviceId.getType() + " device carrying id '" +
|
||||||
deviceId + "'", e);
|
deviceId + "'", e);
|
||||||
// Reschedule if push notification failed.
|
// Reschedule if push notification failed.
|
||||||
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon
|
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED);
|
||||||
.device.mgt.core.dto.operation.mgt.Operation.PushStatus.SCHEDULED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,7 +29,7 @@ public class OperationMapping {
|
|||||||
private int operationId;
|
private int operationId;
|
||||||
private int tenantId;
|
private int tenantId;
|
||||||
private Operation.Status status;
|
private Operation.Status status;
|
||||||
private Operation.PushStatus pushStatus;
|
private Operation.PushNotificationStatus pushNotificationStatus;
|
||||||
|
|
||||||
public int getOperationId() {
|
public int getOperationId() {
|
||||||
return operationId;
|
return operationId;
|
||||||
@ -63,11 +63,11 @@ public class OperationMapping {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Operation.PushStatus getPushStatus() {
|
public Operation.PushNotificationStatus getPushNotificationStatus() {
|
||||||
return pushStatus;
|
return pushNotificationStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPushStatus(Operation.PushStatus pushStatus) {
|
public void setPushNotificationStatus(Operation.PushNotificationStatus pushNotificationStatus) {
|
||||||
this.pushStatus = pushStatus;
|
this.pushNotificationStatus = pushNotificationStatus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,12 +85,12 @@ public interface OperationDAO {
|
|||||||
/**
|
/**
|
||||||
* This method provides operation mappings for given status
|
* This method provides operation mappings for given status
|
||||||
* @param opStatus Operation status
|
* @param opStatus Operation status
|
||||||
* @param pushStatus Push notification Status
|
* @param pushNotificationStatus Push notification Status
|
||||||
* @param limit Limit for no devices
|
* @param limit Limit for no devices
|
||||||
* @return Tenant based operation mappings list
|
* @return Tenant based operation mappings list
|
||||||
* @throws OperationManagementDAOException
|
* @throws OperationManagementDAOException
|
||||||
*/
|
*/
|
||||||
Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushNotificationStatus pushNotificationStatus,
|
||||||
int limit) throws OperationManagementDAOException;;
|
int limit) throws OperationManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ public interface OperationMappingDAO {
|
|||||||
|
|
||||||
void removeOperationMapping(int operationId, Integer deviceId) throws OperationManagementDAOException;
|
void removeOperationMapping(int operationId, Integer deviceId) throws OperationManagementDAOException;
|
||||||
|
|
||||||
void updateOperationMapping(int operationId, Integer deviceId, Operation.PushStatus pushStatus) throws
|
void updateOperationMapping(int operationId, Integer deviceId, Operation.PushNotificationStatus pushNotificationStatus) throws
|
||||||
OperationManagementDAOException;
|
OperationManagementDAOException;
|
||||||
void updateOperationMapping(List<OperationMapping> operationMappingList) throws
|
void updateOperationMapping(List<OperationMapping> operationMappingList) throws
|
||||||
OperationManagementDAOException;
|
OperationManagementDAOException;
|
||||||
|
|||||||
@ -1095,21 +1095,22 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushNotificationStatus pushNotificationStatus,
|
||||||
int limit) throws OperationManagementDAOException {
|
int limit) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
|
Connection conn;
|
||||||
OperationMapping operationMapping;
|
OperationMapping operationMapping;
|
||||||
Map<Integer, List<OperationMapping>> operationMappingsTenantMap = new HashMap<>();
|
Map<Integer, List<OperationMapping>> operationMappingsTenantMap = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " +
|
String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " +
|
||||||
"DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = '?' AND " +
|
"DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = ? AND " +
|
||||||
"op.PUSH_NOTIFICATION_STATUS = '?' AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID ORDER BY " +
|
"op.PUSH_NOTIFICATION_STATUS = ? AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID ORDER BY " +
|
||||||
"op.OPERATION_ID LIMIT ?";
|
"op.OPERATION_ID LIMIT ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, opStatus.toString());
|
stmt.setString(1, opStatus.toString());
|
||||||
stmt.setString(2, pushStatus.toString());
|
stmt.setString(2, pushNotificationStatus.toString());
|
||||||
stmt.setInt(3, limit);
|
stmt.setInt(3, limit);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|||||||
@ -46,9 +46,9 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
stmt.setInt(2, operationId);
|
stmt.setInt(2, operationId);
|
||||||
stmt.setString(3, Operation.Status.PENDING.toString());
|
stmt.setString(3, Operation.Status.PENDING.toString());
|
||||||
if (isScheduled) {
|
if (isScheduled) {
|
||||||
stmt.setString(4, Operation.PushStatus.SCHEDULED.toString());
|
stmt.setString(4, Operation.PushNotificationStatus.SCHEDULED.toString());
|
||||||
} else {
|
} else {
|
||||||
stmt.setString(4, Operation.PushStatus.COMPLETED.toString());
|
stmt.setString(4, Operation.PushNotificationStatus.COMPLETED.toString());
|
||||||
}
|
}
|
||||||
stmt.setLong(5, time);
|
stmt.setLong(5, time);
|
||||||
stmt.setLong(6, time);
|
stmt.setLong(6, time);
|
||||||
@ -79,14 +79,14 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateOperationMapping(int operationId, Integer deviceId, Operation.PushStatus pushStatus) throws OperationManagementDAOException {
|
public void updateOperationMapping(int operationId, Integer deviceId, Operation.PushNotificationStatus pushNotificationStatus) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "UPDATE DM_ENROLMENT_OP_MAPPING SET PUSH_NOTIFICATION_STATUS = ? WHERE ENROLMENT_ID = ? and " +
|
String sql = "UPDATE DM_ENROLMENT_OP_MAPPING SET PUSH_NOTIFICATION_STATUS = ? WHERE ENROLMENT_ID = ? and " +
|
||||||
"OPERATION_ID = ?";
|
"OPERATION_ID = ?";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, pushStatus.toString());
|
stmt.setString(1, pushNotificationStatus.toString());
|
||||||
stmt.setInt(2, deviceId);
|
stmt.setInt(2, deviceId);
|
||||||
stmt.setInt(3, operationId);
|
stmt.setInt(3, operationId);
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
@ -108,7 +108,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
if (conn.getMetaData().supportsBatchUpdates()) {
|
if (conn.getMetaData().supportsBatchUpdates()) {
|
||||||
for (OperationMapping operationMapping : operationMappingList) {
|
for (OperationMapping operationMapping : operationMappingList) {
|
||||||
stmt.setString(1, operationMapping.getPushStatus().toString());
|
stmt.setString(1, operationMapping.getPushNotificationStatus().toString());
|
||||||
stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId()));
|
stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId()));
|
||||||
stmt.setInt(3, operationMapping.getOperationId());
|
stmt.setInt(3, operationMapping.getOperationId());
|
||||||
stmt.addBatch();
|
stmt.addBatch();
|
||||||
@ -116,7 +116,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
|||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
} else {
|
} else {
|
||||||
for (OperationMapping operationMapping : operationMappingList) {
|
for (OperationMapping operationMapping : operationMappingList) {
|
||||||
stmt.setString(1, operationMapping.getPushStatus().toString());
|
stmt.setString(1, operationMapping.getPushNotificationStatus().toString());
|
||||||
stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId()));
|
stmt.setInt(2, Integer.parseInt(operationMapping.getDeviceIdentifier().getId()));
|
||||||
stmt.setInt(3, operationMapping.getOperationId());
|
stmt.setInt(3, operationMapping.getOperationId());
|
||||||
stmt.executeUpdate();
|
stmt.executeUpdate();
|
||||||
|
|||||||
@ -368,7 +368,7 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushNotificationStatus pushNotificationStatus,
|
||||||
int limit) throws OperationManagementDAOException {
|
int limit) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@ -377,13 +377,13 @@ public class OracleOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " +
|
String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " +
|
||||||
"DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = '?' AND op" +
|
"DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = ? AND op" +
|
||||||
".PUSH_NOTIFICATION_STATUS = '?' AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID AND ROWNUM" +
|
".PUSH_NOTIFICATION_STATUS = ? AND d.DEVICE_TYPE_ID = dt.ID AND d.ID=op.ENROLMENT_ID AND ROWNUM" +
|
||||||
" <= ? ORDER BY op.OPERATION_ID";
|
" <= ? ORDER BY op.OPERATION_ID";
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, opStatus.toString());
|
stmt.setString(1, opStatus.toString());
|
||||||
stmt.setString(2, pushStatus.toString());
|
stmt.setString(2, pushNotificationStatus.toString());
|
||||||
stmt.setInt(3, limit);
|
stmt.setInt(3, limit);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|||||||
@ -269,7 +269,7 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushStatus pushStatus,
|
public Map<Integer, List<OperationMapping>> getOperationMappingsByStatus(Operation.Status opStatus, Operation.PushNotificationStatus pushNotificationStatus,
|
||||||
int limit) throws OperationManagementDAOException {
|
int limit) throws OperationManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
@ -278,12 +278,12 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
|
|||||||
try {
|
try {
|
||||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||||
String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " +
|
String sql = "SELECT op.ENROLMENT_ID, op.OPERATION_ID, dt.NAME ,d.TENANT_ID FROM DM_DEVICE d, " +
|
||||||
"DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = '?' AND op" +
|
"DM_ENROLMENT_OP_MAPPING op, DM_DEVICE_TYPE dt WHERE op.STATUS = ? AND op" +
|
||||||
".PUSH_NOTIFICATION_STATUS = '?' AND d.DEVICE_TYPE_ID = dt.ID " +
|
".PUSH_NOTIFICATION_STATUS = ? AND d.DEVICE_TYPE_ID = dt.ID " +
|
||||||
"AND d.ID=op.ENROLMENT_ID ORDER BY op.OPERATION_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
"AND d.ID=op.ENROLMENT_ID ORDER BY op.OPERATION_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
stmt.setString(1, opStatus.toString());
|
stmt.setString(1, opStatus.toString());
|
||||||
stmt.setString(2, pushStatus.toString());
|
stmt.setString(2, pushNotificationStatus.toString());
|
||||||
stmt.setInt(3, limit);
|
stmt.setInt(3, limit);
|
||||||
rs = stmt.executeQuery();
|
rs = stmt.executeQuery();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user