|
|
@ -17,7 +17,7 @@
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
|
|
|
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
|
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
|
|
|
* Version 2.0 (the "License"); you may not use this file except
|
|
|
|
* Version 2.0 (the "License"); you may not use this file except
|
|
|
|
* in compliance with the License.
|
|
|
|
* in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* You may obtain a copy of the License at
|
|
|
@ -44,6 +44,7 @@ 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;
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.StartupOperationConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
@ -62,7 +63,17 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class);
|
|
|
|
private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class);
|
|
|
|
private String deviceType;
|
|
|
|
private String deviceType;
|
|
|
|
static volatile Map<Integer, Map<String, Map<String, Long>>> map = new HashMap<>();
|
|
|
|
static volatile Map<Integer, Map<String, Map<String, Long>>> map = new HashMap<>();
|
|
|
|
|
|
|
|
private static volatile Map<Integer, List<String>> startupConfigMap = new HashMap<>();
|
|
|
|
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
|
|
|
|
private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
|
|
|
|
|
|
|
|
private StartupOperationConfig startupOperationConfig;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceTaskManagerImpl(String deviceType,
|
|
|
|
|
|
|
|
OperationMonitoringTaskConfig operationMonitoringTaskConfig,
|
|
|
|
|
|
|
|
StartupOperationConfig startupOperationConfig) {
|
|
|
|
|
|
|
|
this.deviceType = deviceType;
|
|
|
|
|
|
|
|
this.operationMonitoringTaskConfig = operationMonitoringTaskConfig;
|
|
|
|
|
|
|
|
this.startupOperationConfig = startupOperationConfig;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceTaskManagerImpl(String deviceType,
|
|
|
|
public DeviceTaskManagerImpl(String deviceType,
|
|
|
|
OperationMonitoringTaskConfig operationMonitoringTaskConfig) {
|
|
|
|
OperationMonitoringTaskConfig operationMonitoringTaskConfig) {
|
|
|
@ -79,6 +90,13 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
return operationMonitoringTaskConfig.getMonitoringOperation();
|
|
|
|
return operationMonitoringTaskConfig.getMonitoringOperation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getStartupOperations() {
|
|
|
|
|
|
|
|
if (startupOperationConfig != null) {
|
|
|
|
|
|
|
|
return startupOperationConfig.getStartupOperations();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getTaskFrequency() throws DeviceMgtTaskException {
|
|
|
|
public int getTaskFrequency() throws DeviceMgtTaskException {
|
|
|
|
return operationMonitoringTaskConfig.getFrequency();
|
|
|
|
return operationMonitoringTaskConfig.getFrequency();
|
|
|
@ -104,6 +122,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
List<Device> devices;
|
|
|
|
List<Device> devices;
|
|
|
|
List<String> operations;
|
|
|
|
List<String> operations;
|
|
|
|
List<DeviceIdentifier> validDeviceIdentifiers;
|
|
|
|
List<DeviceIdentifier> validDeviceIdentifiers;
|
|
|
|
|
|
|
|
List<String> startupOperations;
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
@ -118,18 +137,17 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
.size());
|
|
|
|
.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (String str : operations) {
|
|
|
|
for (String str : operations) {
|
|
|
|
Operation operation;
|
|
|
|
CommandOperation operation = new CommandOperation();
|
|
|
|
if ("SERVER_VERSION".equals(str)) {
|
|
|
|
|
|
|
|
operation = new ProfileOperation();
|
|
|
|
|
|
|
|
operation.setPayLoad(ServerConfiguration.getInstance().getFirstProperty("Version"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
operation = new CommandOperation();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
operation.setType(Operation.Type.COMMAND);
|
|
|
|
|
|
|
|
operation.setEnabled(true);
|
|
|
|
operation.setEnabled(true);
|
|
|
|
|
|
|
|
operation.setType(Operation.Type.COMMAND);
|
|
|
|
operation.setCode(str);
|
|
|
|
operation.setCode(str);
|
|
|
|
deviceManagementProviderService.addOperation(deviceType, operation, validDeviceIdentifiers);
|
|
|
|
deviceManagementProviderService.addOperation(deviceType, operation, validDeviceIdentifiers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
startupOperations = getStartupOperations();
|
|
|
|
|
|
|
|
if (startupOperations != null && !startupOperations.isEmpty()) {
|
|
|
|
|
|
|
|
addStartupOperations(startupOperations, validDeviceIdentifiers,
|
|
|
|
|
|
|
|
deviceManagementProviderService);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("No operations are available.");
|
|
|
|
log.debug("No operations are available.");
|
|
|
@ -177,6 +195,32 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
return opNames;
|
|
|
|
return opNames;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addStartupOperations(List<String> startupOperations, List<DeviceIdentifier> validDeviceIdentifiers
|
|
|
|
|
|
|
|
, DeviceManagementProviderService deviceManagementProviderService) throws DeviceMgtTaskException {
|
|
|
|
|
|
|
|
boolean isStartupConfig = Utils.getIsTenantedStartupConfig(startupConfigMap, deviceType);
|
|
|
|
|
|
|
|
if (isStartupConfig) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
for (String startupOp : startupOperations) {
|
|
|
|
|
|
|
|
if ("SERVER_VERSION".equals(startupOp)) {
|
|
|
|
|
|
|
|
operation = new ProfileOperation();
|
|
|
|
|
|
|
|
operation.setPayLoad(ServerConfiguration.getInstance().getFirstProperty("Version"));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
operation = new CommandOperation();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
operation.setType(Operation.Type.COMMAND);
|
|
|
|
|
|
|
|
operation.setEnabled(true);
|
|
|
|
|
|
|
|
operation.setCode(startupOp);
|
|
|
|
|
|
|
|
deviceManagementProviderService.addOperation(deviceType, operation, validDeviceIdentifiers);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (InvalidDeviceException e) {
|
|
|
|
|
|
|
|
throw new DeviceMgtTaskException("Invalid DeviceIdentifiers found.", e);
|
|
|
|
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
|
|
|
|
throw new DeviceMgtTaskException("Error occurred while adding the operations to devices", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<MonitoringOperation> getOperationListforTask() throws DeviceMgtTaskException {
|
|
|
|
private List<MonitoringOperation> getOperationListforTask() throws DeviceMgtTaskException {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
|
|
|
@ -187,17 +231,31 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
deviceType);//Get task list from each device type
|
|
|
|
deviceType);//Get task list from each device type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getStartupOperationListForTask() {
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance()
|
|
|
|
|
|
|
|
.getDeviceManagementProvider();
|
|
|
|
|
|
|
|
return deviceManagementProviderService.getStartupOperations(deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isTaskOperation(String opName) {
|
|
|
|
public boolean isTaskOperation(String opName) {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
List<MonitoringOperation> monitoringOperations = this.getOperationListforTask();
|
|
|
|
List<MonitoringOperation> monitoringOperations = this.getOperationListforTask();
|
|
|
|
|
|
|
|
List<String> startupOperations = this.getStartupOperationListForTask();
|
|
|
|
for (MonitoringOperation taop : monitoringOperations) {
|
|
|
|
for (MonitoringOperation taop : monitoringOperations) {
|
|
|
|
if (taop.getTaskName().equalsIgnoreCase(opName)) {
|
|
|
|
if (taop.getTaskName().equalsIgnoreCase(opName)) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (startupOperations != null && !startupOperations.isEmpty()) {
|
|
|
|
|
|
|
|
for (String operation : startupOperations) {
|
|
|
|
|
|
|
|
if (opName.equalsIgnoreCase(operation)) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
// ignoring the error, no need to throw, If error occurs, return value will be false.
|
|
|
|
// ignoring the error, no need to throw, If error occurs, return value will be false.
|
|
|
|
}
|
|
|
|
}
|
|
|
|