|
|
|
@ -14,6 +14,22 @@
|
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
|
|
|
|
* Version 2.0 (the "License"); you may not use this file except
|
|
|
|
|
* in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -21,16 +37,19 @@ package org.wso2.carbon.device.mgt.core.task.impl;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.base.ServerConfiguration;
|
|
|
|
|
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.InvalidDeviceException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
|
|
|
|
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.OperationManagementException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
|
|
|
|
@ -44,7 +63,17 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
|
private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class);
|
|
|
|
|
private String deviceType;
|
|
|
|
|
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 StartupOperationConfig startupOperationConfig;
|
|
|
|
|
|
|
|
|
|
public DeviceTaskManagerImpl(String deviceType,
|
|
|
|
|
OperationMonitoringTaskConfig operationMonitoringTaskConfig,
|
|
|
|
|
StartupOperationConfig startupOperationConfig) {
|
|
|
|
|
this.deviceType = deviceType;
|
|
|
|
|
this.operationMonitoringTaskConfig = operationMonitoringTaskConfig;
|
|
|
|
|
this.startupOperationConfig = startupOperationConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DeviceTaskManagerImpl(String deviceType,
|
|
|
|
|
OperationMonitoringTaskConfig operationMonitoringTaskConfig) {
|
|
|
|
@ -61,6 +90,13 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
|
return operationMonitoringTaskConfig.getMonitoringOperation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<String> getStartupOperations() {
|
|
|
|
|
if (startupOperationConfig != null) {
|
|
|
|
|
return startupOperationConfig.getStartupOperations();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getTaskFrequency() throws DeviceMgtTaskException {
|
|
|
|
|
return operationMonitoringTaskConfig.getFrequency();
|
|
|
|
@ -86,6 +122,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
|
List<Device> devices;
|
|
|
|
|
List<String> operations;
|
|
|
|
|
List<DeviceIdentifier> validDeviceIdentifiers;
|
|
|
|
|
List<String> startupOperations;
|
|
|
|
|
operations = this.getValidOperationNames(); //list operations for each device type
|
|
|
|
|
devices = deviceManagementProviderService.getAllDevices(deviceType, false);//list devices for each type
|
|
|
|
|
|
|
|
|
@ -106,6 +143,11 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
|
operation.setCode(str);
|
|
|
|
|
deviceManagementProviderService.addOperation(deviceType, operation, validDeviceIdentifiers);
|
|
|
|
|
}
|
|
|
|
|
startupOperations = getStartupOperations();
|
|
|
|
|
if (startupOperations != null && !startupOperations.isEmpty()) {
|
|
|
|
|
addStartupOperations(startupOperations, validDeviceIdentifiers,
|
|
|
|
|
deviceManagementProviderService);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("No operations are available.");
|
|
|
|
@ -153,6 +195,32 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder
|
|
|
|
@ -163,17 +231,31 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
|
deviceType);//Get task list from each device type
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<String> getStartupOperationListForTask() {
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder.getInstance()
|
|
|
|
|
.getDeviceManagementProvider();
|
|
|
|
|
return deviceManagementProviderService.getStartupOperations(deviceType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isTaskOperation(String opName) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
List<MonitoringOperation> monitoringOperations = this.getOperationListforTask();
|
|
|
|
|
List<String> startupOperations = this.getStartupOperationListForTask();
|
|
|
|
|
for (MonitoringOperation taop : monitoringOperations) {
|
|
|
|
|
if (taop.getTaskName().equalsIgnoreCase(opName)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (startupOperations != null && !startupOperations.isEmpty()) {
|
|
|
|
|
for (String operation : startupOperations) {
|
|
|
|
|
if (opName.equalsIgnoreCase(operation)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (DeviceMgtTaskException e) {
|
|
|
|
|
// ignoring the error, no need to throw, If error occurs, return value will be false.
|
|
|
|
|
}
|
|
|
|
|