mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing bugs and adding the ability to read from cdm-config.xml file for monitoring task
This commit is contained in:
parent
b906d43cc8
commit
c6d993e532
@ -24,34 +24,64 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
@XmlRootElement(name = "PolicyConfiguration")
|
||||
public class PolicyConfiguration {
|
||||
|
||||
private String monitoringClass;
|
||||
private int maxRetries;
|
||||
private int minRetriesToMarkUnreachable;
|
||||
private String monitoringClass;
|
||||
private boolean monitoringEnable;
|
||||
private int monitoringFrequency;
|
||||
private int maxRetries;
|
||||
private int minRetriesToMarkUnreachable;
|
||||
private int minRetriesToMarkInactive;
|
||||
|
||||
@XmlElement(name = "monitoringClass", required = true)
|
||||
public String getMonitoringClass() {
|
||||
return monitoringClass;
|
||||
}
|
||||
@XmlElement(name = "monitoringClass", required = true)
|
||||
public String getMonitoringClass() {
|
||||
return monitoringClass;
|
||||
}
|
||||
|
||||
public void setMonitoringClass(String monitoringClass) {
|
||||
this.monitoringClass = monitoringClass;
|
||||
}
|
||||
public void setMonitoringClass(String monitoringClass) {
|
||||
this.monitoringClass = monitoringClass;
|
||||
}
|
||||
|
||||
@XmlElement(name = "maxRetries", required = true)
|
||||
public int getMaxRetries() {
|
||||
return maxRetries;
|
||||
}
|
||||
@XmlElement(name = "maxRetries", required = true)
|
||||
public int getMaxRetries() {
|
||||
return maxRetries;
|
||||
}
|
||||
|
||||
public void setMaxRetries(int maxRetries) {
|
||||
this.maxRetries = maxRetries;
|
||||
}
|
||||
public void setMaxRetries(int maxRetries) {
|
||||
this.maxRetries = maxRetries;
|
||||
}
|
||||
|
||||
@XmlElement(name = "minRetriesToMarkUnreachable", required = true)
|
||||
public int getMinRetriesToMarkUnreachable() {
|
||||
return minRetriesToMarkUnreachable;
|
||||
}
|
||||
@XmlElement(name = "minRetriesToMarkUnreachable", required = true)
|
||||
public int getMinRetriesToMarkUnreachable() {
|
||||
return minRetriesToMarkUnreachable;
|
||||
}
|
||||
|
||||
public void setMinRetriesToMarkUnreachable(int minRetriesToMarkUnreachable) {
|
||||
this.minRetriesToMarkUnreachable = minRetriesToMarkUnreachable;
|
||||
}
|
||||
public void setMinRetriesToMarkUnreachable(int minRetriesToMarkUnreachable) {
|
||||
this.minRetriesToMarkUnreachable = minRetriesToMarkUnreachable;
|
||||
}
|
||||
|
||||
@XmlElement(name = "monitoringEnable", required = true)
|
||||
public boolean getMonitoringEnable() {
|
||||
return monitoringEnable;
|
||||
}
|
||||
|
||||
public void setMonitoringEnable(boolean monitoringEnable) {
|
||||
this.monitoringEnable = monitoringEnable;
|
||||
}
|
||||
|
||||
@XmlElement(name = "minRetriesToMarkInactive", required = true)
|
||||
public int getMinRetriesToMarkInactive() {
|
||||
return minRetriesToMarkInactive;
|
||||
}
|
||||
|
||||
public void setMinRetriesToMarkInactive(int minRetriesToMarkInactive) {
|
||||
this.minRetriesToMarkInactive = minRetriesToMarkInactive;
|
||||
}
|
||||
|
||||
@XmlElement(name = "monitoringFrequency", required = true)
|
||||
public int getMonitoringFrequency() {
|
||||
return monitoringFrequency;
|
||||
}
|
||||
|
||||
public void setMonitoringFrequency(int monitoringFrequency) {
|
||||
this.monitoringFrequency = monitoringFrequency;
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,11 +127,16 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
||||
|
||||
String taskName = PolicyManagementConstants.DELEGATION_TASK_NAME + "_" + String.valueOf(tenantId);
|
||||
|
||||
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.DELEGATION_TASK_CLAZZ, properties, triggerInfo);
|
||||
if(!taskManager.isTaskScheduled(taskName)) {
|
||||
|
||||
taskManager.registerTask(taskInfo);
|
||||
taskManager.rescheduleTask(taskInfo.getName());
|
||||
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.DELEGATION_TASK_CLAZZ, properties, triggerInfo);
|
||||
|
||||
taskManager.registerTask(taskInfo);
|
||||
taskManager.rescheduleTask(taskInfo.getName());
|
||||
} else {
|
||||
throw new PolicyManagementException("There is a task already running for policy changes. Please try to apply " +
|
||||
"changes after few minutes.");
|
||||
}
|
||||
|
||||
} catch (TaskException e) {
|
||||
String msg = "Error occurred while creating the policy delegation task for tenant " + PrivilegedCarbonContext.
|
||||
|
||||
@ -21,6 +21,8 @@ package org.wso2.carbon.policy.mgt.core.internal;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||
@ -84,8 +86,12 @@ public class PolicyManagementServiceComponent {
|
||||
componentContext.getBundleContext().registerService(
|
||||
PolicyManagerService.class.getName(), new PolicyManagerServiceImpl(), null);
|
||||
|
||||
TaskScheduleService taskScheduleService = new TaskScheduleServiceImpl();
|
||||
taskScheduleService.startTask(30000);
|
||||
PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getDeviceManagementConfigRepository().getPolicyConfiguration();
|
||||
if(policyConfiguration.getMonitoringEnable()) {
|
||||
TaskScheduleService taskScheduleService = new TaskScheduleServiceImpl();
|
||||
taskScheduleService.startTask(policyConfiguration.getMonitoringFrequency());
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
log.error("Error occurred while initializing the Policy management core.", t);
|
||||
@ -165,7 +171,7 @@ public class PolicyManagementServiceComponent {
|
||||
|
||||
protected void setPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting Policy Monitoring Service");
|
||||
log.debug("Setting Policy Monitoring Service for " + policyMonitoringService.getType());
|
||||
}
|
||||
// TODO: FIX THE device type by taking from properties
|
||||
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(policyMonitoringService.getType(),
|
||||
@ -174,7 +180,7 @@ public class PolicyManagementServiceComponent {
|
||||
|
||||
protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Removing the Policy Monitoring Service");
|
||||
log.debug("Removing the Policy Monitoring Service for " + policyMonitoringService.getType());
|
||||
}
|
||||
// TODO: FIX THE device type by taking from properties
|
||||
PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService(policyMonitoringService.getType());
|
||||
|
||||
@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.core.mgt;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||
@ -39,4 +40,6 @@ public interface MonitoringManager {
|
||||
|
||||
void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException;
|
||||
|
||||
List<DeviceType> getDeviceTypes() throws PolicyComplianceException;
|
||||
|
||||
}
|
||||
|
||||
@ -26,8 +26,13 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
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.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfigRepository;
|
||||
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
|
||||
@ -54,18 +59,24 @@ import java.util.Map;
|
||||
public class MonitoringManagerImpl implements MonitoringManager {
|
||||
|
||||
private PolicyDAO policyDAO;
|
||||
private DeviceDAO deviceDAO;
|
||||
// private DeviceDAO deviceDAO;
|
||||
private DeviceTypeDAO deviceTypeDAO;
|
||||
private MonitoringDAO monitoringDAO;
|
||||
private ComplianceDecisionPoint complianceDecisionPoint;
|
||||
private PolicyConfiguration policyConfiguration;
|
||||
|
||||
private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class);
|
||||
private static final String OPERATION_MONITOR = "MONITOR";
|
||||
|
||||
public MonitoringManagerImpl() {
|
||||
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
|
||||
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
// this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
this.monitoringDAO = PolicyManagementDAOFactory.getMonitoringDAO();
|
||||
this.complianceDecisionPoint = new ComplianceDecisionPointImpl();
|
||||
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getDeviceManagementConfigRepository().getPolicyConfiguration();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -242,6 +253,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
||||
Map<Integer, Device> deviceIdsToAddOperation = new HashMap<>();
|
||||
Map<Integer, Device> deviceIdsWithExistingOperation = new HashMap<>();
|
||||
Map<Integer, Device> inactiveDeviceIds = new HashMap<>();
|
||||
Map<Integer, Device> deviceToMarkUnreachable = new HashMap<>();
|
||||
Map<Integer, Integer> firstTimeDeviceIdsWithPolicyIds = new HashMap<>();
|
||||
|
||||
Map<Integer, ComplianceData> tempMap = new HashMap<>();
|
||||
@ -258,8 +270,12 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
||||
} else {
|
||||
deviceIdsWithExistingOperation.put(complianceData.getDeviceId(),
|
||||
deviceIds.get(complianceData.getDeviceId()));
|
||||
if (complianceData.getAttempts() >= policyConfiguration.getMinRetriesToMarkUnreachable()) {
|
||||
deviceToMarkUnreachable.put(complianceData.getDeviceId(),
|
||||
deviceIds.get(complianceData.getDeviceId()));
|
||||
}
|
||||
}
|
||||
if (complianceData.getAttempts() >= 20) {
|
||||
if (complianceData.getAttempts() >= policyConfiguration.getMinRetriesToMarkInactive()) {
|
||||
inactiveDeviceIds.put(complianceData.getDeviceId(),
|
||||
deviceIds.get(complianceData.getDeviceId()));
|
||||
}
|
||||
@ -288,9 +304,6 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
||||
|
||||
if (!deviceIdsWithExistingOperation.isEmpty()) {
|
||||
monitoringDAO.updateAttempts(new ArrayList<>(deviceIdsWithExistingOperation.keySet()), false);
|
||||
//TODO: Add attempts. This has to be fixed in the get pending operation tables too. This will be
|
||||
// decisionPoint.setDevicesAsUnreachable(this.getDeviceIdentifiersFromDevices(
|
||||
// new ArrayList<>(deviceIdsWithExistingOperation.values())));
|
||||
}
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
|
||||
@ -312,6 +325,29 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : This should be uncommented, this is to mark the device as unreachable, But given the current implementation
|
||||
// we are not able to do so.
|
||||
|
||||
// if(!deviceToMarkUnreachable.isEmpty()) {
|
||||
// decisionPoint.setDevicesAsUnreachable(this.getDeviceIdentifiersFromDevices(
|
||||
// new ArrayList<>(deviceToMarkUnreachable.values())));
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceType> getDeviceTypes() throws PolicyComplianceException {
|
||||
|
||||
List<DeviceType> deviceTypes = new ArrayList<>();
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
deviceTypes = deviceTypeDAO.getDeviceTypes();
|
||||
} catch (Exception e) {
|
||||
log.error("Error occurred while getting the device types.", e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
return deviceTypes;
|
||||
}
|
||||
|
||||
private void addMonitoringOperationsToDatabase(List<Device> devices)
|
||||
@ -325,8 +361,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
||||
|
||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||
service.addOperation(monitoringOperation, deviceIdentifiers);
|
||||
// PolicyManagementDataHolder.getInstance().getDeviceManagementService().
|
||||
// addOperation(monitoringOperation, deviceIdentifiers);
|
||||
|
||||
}
|
||||
|
||||
private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) {
|
||||
|
||||
@ -188,8 +188,19 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
|
||||
boolean bool;
|
||||
try {
|
||||
List<Policy> existingPolicies = this.getPolicies();
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
bool = policyDAO.updatePolicyPriorities(policies);
|
||||
|
||||
// This logic is added because ui sends only policy id and priority to update priorities.
|
||||
|
||||
for (Policy policy : policies) {
|
||||
for(Policy exPolicy: existingPolicies) {
|
||||
if(policy.getId() == exPolicy.getId()) {
|
||||
policy.setProfile(exPolicy.getProfile());
|
||||
}
|
||||
}
|
||||
}
|
||||
policyDAO.recordUpdatedPolicies(policies);
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
|
||||
@ -29,6 +29,7 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.ntask.core.Task;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager;
|
||||
@ -63,14 +64,13 @@ public class MonitoringTask implements Task {
|
||||
log.debug("Monitoring task started to run.");
|
||||
}
|
||||
|
||||
MonitoringManager monitoringManager = new MonitoringManagerImpl();
|
||||
|
||||
List<DeviceType> deviceTypes = new ArrayList<>();
|
||||
try {
|
||||
DeviceManagementDAOFactory.openConnection();
|
||||
deviceTypes = deviceTypeDAO.getDeviceTypes();
|
||||
} catch (Exception e) {
|
||||
log.error("Error occurred while getting the device types.", e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
deviceTypes = monitoringManager.getDeviceTypes();
|
||||
} catch (PolicyComplianceException e) {
|
||||
log.error("Error occurred while getting the device types.");
|
||||
}
|
||||
|
||||
if (!deviceTypes.isEmpty()) {
|
||||
@ -78,7 +78,6 @@ public class MonitoringTask implements Task {
|
||||
|
||||
DeviceManagementProviderService deviceManagementProviderService =
|
||||
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
||||
MonitoringManager monitoringManager = new MonitoringManagerImpl();
|
||||
|
||||
for (DeviceType deviceType : deviceTypes) {
|
||||
PolicyMonitoringService monitoringService =
|
||||
|
||||
@ -22,6 +22,8 @@ package org.wso2.carbon.policy.mgt.core.task;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||
import org.wso2.carbon.ntask.common.TaskException;
|
||||
import org.wso2.carbon.ntask.core.TaskInfo;
|
||||
import org.wso2.carbon.ntask.core.TaskManager;
|
||||
@ -37,45 +39,56 @@ import java.util.Map;
|
||||
public class TaskScheduleServiceImpl implements TaskScheduleService {
|
||||
|
||||
private static Log log = LogFactory.getLog(TaskScheduleServiceImpl.class);
|
||||
private PolicyConfiguration policyConfiguration;
|
||||
|
||||
|
||||
public TaskScheduleServiceImpl() {
|
||||
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
|
||||
getDeviceManagementConfigRepository().getPolicyConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startTask(int monitoringFrequency) throws PolicyMonitoringTaskException {
|
||||
|
||||
if (monitoringFrequency <= 0) {
|
||||
throw new PolicyMonitoringTaskException("Time interval cannot be 0 or less than 0.");
|
||||
}
|
||||
try {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||
taskService.registerTaskType(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Monitoring task is started for the tenant id " + tenantId);
|
||||
if (policyConfiguration.getMonitoringEnable()) {
|
||||
|
||||
if (monitoringFrequency <= 0) {
|
||||
throw new PolicyMonitoringTaskException("Time interval cannot be 0 or less than 0.");
|
||||
}
|
||||
try {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||
taskService.registerTaskType(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||
|
||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Monitoring task is started for the tenant id " + tenantId);
|
||||
}
|
||||
|
||||
TriggerInfo triggerInfo = new TriggerInfo();
|
||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||
|
||||
triggerInfo.setIntervalMillis(monitoringFrequency);
|
||||
triggerInfo.setRepeatCount(-1);
|
||||
TriggerInfo triggerInfo = new TriggerInfo();
|
||||
triggerInfo.setIntervalMillis(monitoringFrequency);
|
||||
triggerInfo.setRepeatCount(-1);
|
||||
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put(PolicyManagementConstants.TENANT_ID, String.valueOf(tenantId));
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put(PolicyManagementConstants.TENANT_ID, String.valueOf(tenantId));
|
||||
|
||||
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
|
||||
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
|
||||
|
||||
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.MONITORING_TASK_CLAZZ, properties, triggerInfo);
|
||||
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.MONITORING_TASK_CLAZZ,
|
||||
properties, triggerInfo);
|
||||
|
||||
taskManager.registerTask(taskInfo);
|
||||
taskManager.rescheduleTask(taskInfo.getName());
|
||||
taskManager.registerTask(taskInfo);
|
||||
taskManager.rescheduleTask(taskInfo.getName());
|
||||
|
||||
|
||||
} catch (TaskException e) {
|
||||
String msg = "Error occurred while creating the task for tenant " + PrivilegedCarbonContext.
|
||||
getThreadLocalCarbonContext().getTenantId();
|
||||
log.error(msg, e);
|
||||
throw new PolicyMonitoringTaskException(msg, e);
|
||||
} catch (TaskException e) {
|
||||
throw new PolicyMonitoringTaskException("Error occurred while creating the task for tenant " + PrivilegedCarbonContext.
|
||||
getThreadLocalCarbonContext().getTenantId(), e);
|
||||
}
|
||||
} else {
|
||||
throw new PolicyMonitoringTaskException("Policy monitoring is not enabled in the cdm-config.xml.");
|
||||
}
|
||||
|
||||
|
||||
@ -90,10 +103,8 @@ public class TaskScheduleServiceImpl implements TaskScheduleService {
|
||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||
taskManager.deleteTask(taskName);
|
||||
} catch (TaskException e) {
|
||||
String msg = "Error occurred while deleting the task for tenant " + PrivilegedCarbonContext.
|
||||
getThreadLocalCarbonContext().getTenantId();
|
||||
log.error(msg, e);
|
||||
throw new PolicyMonitoringTaskException(msg, e);
|
||||
throw new PolicyMonitoringTaskException("Error occurred while deleting the task for tenant " + PrivilegedCarbonContext.
|
||||
getThreadLocalCarbonContext().getTenantId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,29 +114,25 @@ public class TaskScheduleServiceImpl implements TaskScheduleService {
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
|
||||
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||
|
||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
|
||||
|
||||
taskManager.deleteTask(taskName);
|
||||
|
||||
TriggerInfo triggerInfo = new TriggerInfo();
|
||||
|
||||
triggerInfo.setIntervalMillis(monitoringFrequency);
|
||||
triggerInfo.setRepeatCount(-1);
|
||||
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put("tenantId", String.valueOf(tenantId));
|
||||
|
||||
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.MONITORING_TASK_CLAZZ, properties, triggerInfo);
|
||||
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.MONITORING_TASK_CLAZZ, properties,
|
||||
triggerInfo);
|
||||
|
||||
taskManager.registerTask(taskInfo);
|
||||
taskManager.rescheduleTask(taskInfo.getName());
|
||||
|
||||
} catch (TaskException e) {
|
||||
String msg = "Error occurred while updating the task for tenant " + PrivilegedCarbonContext.
|
||||
getThreadLocalCarbonContext().getTenantId();
|
||||
log.error(msg, e);
|
||||
throw new PolicyMonitoringTaskException(msg, e);
|
||||
throw new PolicyMonitoringTaskException("Error occurred while updating the task for tenant " + PrivilegedCarbonContext.
|
||||
getThreadLocalCarbonContext().getTenantId(), e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -26,6 +26,9 @@ import org.testng.annotations.BeforeSuite;
|
||||
import org.w3c.dom.Document;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
||||
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
@ -61,6 +64,7 @@ public abstract class BasePolicyManagementDAOTest {
|
||||
this.initSQLScript();
|
||||
this.initialize();
|
||||
this.initiatePrivilegedCaronContext();
|
||||
DeviceConfigurationManager.getInstance().initConfig();
|
||||
}
|
||||
|
||||
public void initialize() throws TaskException {
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. 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.
|
||||
-->
|
||||
|
||||
<DeviceMgtConfiguration>
|
||||
<ManagementRepository>
|
||||
<DataSourceConfiguration>
|
||||
<JndiLookupDefinition>
|
||||
<Name>jdbc/DM_DS</Name>
|
||||
</JndiLookupDefinition>
|
||||
</DataSourceConfiguration>
|
||||
<EmailClientConfiguration>
|
||||
<minimumThread>8</minimumThread>
|
||||
<maximumThread>100</maximumThread>
|
||||
<keepAliveTime>20</keepAliveTime>
|
||||
<ThreadQueueCapacity>1000</ThreadQueueCapacity>
|
||||
</EmailClientConfiguration>
|
||||
<IdentityConfiguration>
|
||||
<ServerUrl>https://localhost:9443</ServerUrl>
|
||||
<AdminUsername>admin</AdminUsername>
|
||||
<AdminPassword>admin</AdminPassword>
|
||||
</IdentityConfiguration>
|
||||
<PolicyConfiguration>
|
||||
<monitoringClass>org.wso2.carbon.policy.mgt</monitoringClass>
|
||||
<monitoringEnable>true</monitoringEnable>
|
||||
<monitoringFrequency>60000</monitoringFrequency>
|
||||
<maxRetries>5</maxRetries>
|
||||
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
|
||||
<minRetriesToMarkInactive>20</minRetriesToMarkInactive>
|
||||
</PolicyConfiguration>
|
||||
</ManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
<Notifications>
|
||||
<NotificationMessage type="enrol">
|
||||
<Subject>Enroll your Device with WSO2 MDM</Subject>
|
||||
<Header>Dear {first-name},</Header>
|
||||
<Body>
|
||||
You have been registered to the WSO2 MDM. Below is the link to enroll.
|
||||
</Body>
|
||||
<Url>{downloadUrl}</Url>
|
||||
<Footer1>
|
||||
Best Regards,
|
||||
</Footer1>
|
||||
<Footer2>
|
||||
WSO2 MDM Team.
|
||||
</Footer2>
|
||||
<Footer3>
|
||||
http://www.wso2.com
|
||||
</Footer3>
|
||||
</NotificationMessage>
|
||||
<NotificationMessage type="userRegistration">
|
||||
<Subject>Enroll your Device with WSO2 MDM</Subject>
|
||||
<Header>Dear {first-name},</Header>
|
||||
<Body>
|
||||
You have been registered to WSO2 MDM with following credentials.
|
||||
Username: {user-name}
|
||||
Password: {password}
|
||||
Below is the link to enroll.
|
||||
</Body>
|
||||
<Url>{downloadUrl}</Url>
|
||||
<Footer1>
|
||||
Best Regards,
|
||||
</Footer1>
|
||||
<Footer2>
|
||||
WSO2 MDM Team.
|
||||
</Footer2>
|
||||
<Footer3>
|
||||
http://www.wso2.com
|
||||
</Footer3>
|
||||
</NotificationMessage>
|
||||
</Notifications>
|
||||
@ -37,8 +37,11 @@
|
||||
</IdentityConfiguration>
|
||||
<PolicyConfiguration>
|
||||
<monitoringClass>org.wso2.carbon.policy.mgt</monitoringClass>
|
||||
<monitoringEnable>true</monitoringEnable>
|
||||
<monitoringFrequency>60000</monitoringFrequency>
|
||||
<maxRetries>5</maxRetries>
|
||||
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
|
||||
<minRetriesToMarkInactive>20</minRetriesToMarkInactive>
|
||||
</PolicyConfiguration>
|
||||
</ManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user