|
|
@ -18,6 +18,7 @@
|
|
|
|
package io.entgra.device.mgt.core.device.mgt.core.operation.timeout.task.impl;
|
|
|
|
package io.entgra.device.mgt.core.device.mgt.core.operation.timeout.task.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
|
|
|
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException;
|
|
|
|
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 io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
|
|
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
|
|
@ -36,7 +37,6 @@ import java.util.List;
|
|
|
|
public class OperationTimeoutTask extends DynamicPartitionedScheduleTask {
|
|
|
|
public class OperationTimeoutTask extends DynamicPartitionedScheduleTask {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(OperationTimeoutTask.class);
|
|
|
|
private static final Log log = LogFactory.getLog(OperationTimeoutTask.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void setup() {
|
|
|
|
protected void setup() {
|
|
|
|
|
|
|
|
|
|
|
@ -44,12 +44,13 @@ public class OperationTimeoutTask extends DynamicPartitionedScheduleTask {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void executeDynamicTask() {
|
|
|
|
protected void executeDynamicTask() {
|
|
|
|
|
|
|
|
if (isQualifiedToExecuteTask()) { // this task will run only in one node when the deployment has multiple nodes
|
|
|
|
String operationTimeoutTaskConfigStr = getProperty(
|
|
|
|
String operationTimeoutTaskConfigStr = getProperty(
|
|
|
|
OperationTimeoutTaskManagerServiceImpl.OPERATION_TIMEOUT_TASK_CONFIG);
|
|
|
|
OperationTimeoutTaskManagerServiceImpl.OPERATION_TIMEOUT_TASK_CONFIG);
|
|
|
|
Gson gson = new Gson();
|
|
|
|
Gson gson = new Gson();
|
|
|
|
OperationTimeout operationTimeoutConfig = gson.fromJson(operationTimeoutTaskConfigStr, OperationTimeout.class);
|
|
|
|
OperationTimeout operationTimeoutConfig = gson.fromJson(operationTimeoutTaskConfigStr, OperationTimeout.class);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
long timeMillis = System.currentTimeMillis() - operationTimeoutConfig.getTimeout() * 60 * 1000;
|
|
|
|
long timeMillis = System.currentTimeMillis() - (long) operationTimeoutConfig.getTimeout();
|
|
|
|
List<String> deviceTypes = new ArrayList<>();
|
|
|
|
List<String> deviceTypes = new ArrayList<>();
|
|
|
|
if (operationTimeoutConfig.getDeviceTypes().size() == 1 &&
|
|
|
|
if (operationTimeoutConfig.getDeviceTypes().size() == 1 &&
|
|
|
|
"ALL".equals(operationTimeoutConfig.getDeviceTypes().get(0))) {
|
|
|
|
"ALL".equals(operationTimeoutConfig.getDeviceTypes().get(0))) {
|
|
|
@ -85,4 +86,18 @@ public class OperationTimeoutTask extends DynamicPartitionedScheduleTask {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isQualifiedToExecuteTask() {
|
|
|
|
|
|
|
|
if (isDynamicTaskEligible()) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return DeviceManagementDataHolder.getInstance().getHeartBeatService().isQualifiedToExecuteTask();
|
|
|
|
|
|
|
|
} catch (HeartBeatManagementException e) {
|
|
|
|
|
|
|
|
log.error("Error while checking is qualified to execute task", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|