|
|
@ -14,6 +14,22 @@
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
* 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.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
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.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
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;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
|
|
|
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.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager;
|
|
|
|
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 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) {
|
|
|
@ -61,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();
|
|
|
@ -86,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
|
|
|
|
|
|
|
|
|
|
|
@ -106,6 +143,11 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager {
|
|
|
|
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.");
|
|
|
@ -153,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
|
|
|
@ -163,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.
|
|
|
|
}
|
|
|
|
}
|
|
|
|