Fixing bugs and adding the ability to read from cdm-config.xml file for monitoring task

revert-70aa11f8
geethkokila 9 years ago
parent b906d43cc8
commit c6d993e532

@ -24,34 +24,64 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "PolicyConfiguration") @XmlRootElement(name = "PolicyConfiguration")
public class PolicyConfiguration { public class PolicyConfiguration {
private String monitoringClass; private String monitoringClass;
private int maxRetries; private boolean monitoringEnable;
private int minRetriesToMarkUnreachable; private int monitoringFrequency;
private int maxRetries;
@XmlElement(name = "monitoringClass", required = true) private int minRetriesToMarkUnreachable;
public String getMonitoringClass() { private int minRetriesToMarkInactive;
return monitoringClass;
} @XmlElement(name = "monitoringClass", required = true)
public String getMonitoringClass() {
public void setMonitoringClass(String monitoringClass) { return monitoringClass;
this.monitoringClass = monitoringClass; }
}
public void setMonitoringClass(String monitoringClass) {
@XmlElement(name = "maxRetries", required = true) this.monitoringClass = monitoringClass;
public int getMaxRetries() { }
return maxRetries;
} @XmlElement(name = "maxRetries", required = true)
public int getMaxRetries() {
public void setMaxRetries(int maxRetries) { return maxRetries;
this.maxRetries = maxRetries; }
}
public void setMaxRetries(int maxRetries) {
@XmlElement(name = "minRetriesToMarkUnreachable", required = true) this.maxRetries = maxRetries;
public int getMinRetriesToMarkUnreachable() { }
return minRetriesToMarkUnreachable;
} @XmlElement(name = "minRetriesToMarkUnreachable", required = true)
public int getMinRetriesToMarkUnreachable() {
public void setMinRetriesToMarkUnreachable(int minRetriesToMarkUnreachable) { return 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); 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); TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.DELEGATION_TASK_CLAZZ, properties, triggerInfo);
taskManager.rescheduleTask(taskInfo.getName());
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) { } catch (TaskException e) {
String msg = "Error occurred while creating the policy delegation task for tenant " + PrivilegedCarbonContext. 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext; 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.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.service.TaskService; import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
@ -84,8 +86,12 @@ public class PolicyManagementServiceComponent {
componentContext.getBundleContext().registerService( componentContext.getBundleContext().registerService(
PolicyManagerService.class.getName(), new PolicyManagerServiceImpl(), null); PolicyManagerService.class.getName(), new PolicyManagerServiceImpl(), null);
TaskScheduleService taskScheduleService = new TaskScheduleServiceImpl(); PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
taskScheduleService.startTask(30000); getDeviceManagementConfigRepository().getPolicyConfiguration();
if(policyConfiguration.getMonitoringEnable()) {
TaskScheduleService taskScheduleService = new TaskScheduleServiceImpl();
taskScheduleService.startTask(policyConfiguration.getMonitoringFrequency());
}
} catch (Throwable t) { } catch (Throwable t) {
log.error("Error occurred while initializing the Policy management core.", t); log.error("Error occurred while initializing the Policy management core.", t);
@ -165,7 +171,7 @@ public class PolicyManagementServiceComponent {
protected void setPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) { protected void setPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
if (log.isDebugEnabled()) { 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 // TODO: FIX THE device type by taking from properties
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(policyMonitoringService.getType(), PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(policyMonitoringService.getType(),
@ -174,7 +180,7 @@ public class PolicyManagementServiceComponent {
protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) { protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
if (log.isDebugEnabled()) { 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 // TODO: FIX THE device type by taking from properties
PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService(policyMonitoringService.getType()); 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.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; 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.ComplianceData;
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException; import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
@ -39,4 +40,6 @@ public interface MonitoringManager {
void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException; 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.DeviceManagementException;
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.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.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; 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.operation.mgt.CommandOperation;
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.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
@ -54,18 +59,24 @@ import java.util.Map;
public class MonitoringManagerImpl implements MonitoringManager { public class MonitoringManagerImpl implements MonitoringManager {
private PolicyDAO policyDAO; private PolicyDAO policyDAO;
private DeviceDAO deviceDAO; // private DeviceDAO deviceDAO;
private DeviceTypeDAO deviceTypeDAO;
private MonitoringDAO monitoringDAO; private MonitoringDAO monitoringDAO;
private ComplianceDecisionPoint complianceDecisionPoint; private ComplianceDecisionPoint complianceDecisionPoint;
private PolicyConfiguration policyConfiguration;
private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class); private static final Log log = LogFactory.getLog(MonitoringManagerImpl.class);
private static final String OPERATION_MONITOR = "MONITOR"; private static final String OPERATION_MONITOR = "MONITOR";
public MonitoringManagerImpl() { public MonitoringManagerImpl() {
this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO(); this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO();
this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); // this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
this.monitoringDAO = PolicyManagementDAOFactory.getMonitoringDAO(); this.monitoringDAO = PolicyManagementDAOFactory.getMonitoringDAO();
this.complianceDecisionPoint = new ComplianceDecisionPointImpl(); this.complianceDecisionPoint = new ComplianceDecisionPointImpl();
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getDeviceManagementConfigRepository().getPolicyConfiguration();
} }
@Override @Override
@ -242,6 +253,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
Map<Integer, Device> deviceIdsToAddOperation = new HashMap<>(); Map<Integer, Device> deviceIdsToAddOperation = new HashMap<>();
Map<Integer, Device> deviceIdsWithExistingOperation = new HashMap<>(); Map<Integer, Device> deviceIdsWithExistingOperation = new HashMap<>();
Map<Integer, Device> inactiveDeviceIds = new HashMap<>(); Map<Integer, Device> inactiveDeviceIds = new HashMap<>();
Map<Integer, Device> deviceToMarkUnreachable = new HashMap<>();
Map<Integer, Integer> firstTimeDeviceIdsWithPolicyIds = new HashMap<>(); Map<Integer, Integer> firstTimeDeviceIdsWithPolicyIds = new HashMap<>();
Map<Integer, ComplianceData> tempMap = new HashMap<>(); Map<Integer, ComplianceData> tempMap = new HashMap<>();
@ -258,8 +270,12 @@ public class MonitoringManagerImpl implements MonitoringManager {
} else { } else {
deviceIdsWithExistingOperation.put(complianceData.getDeviceId(), deviceIdsWithExistingOperation.put(complianceData.getDeviceId(),
deviceIds.get(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(), inactiveDeviceIds.put(complianceData.getDeviceId(),
deviceIds.get(complianceData.getDeviceId())); deviceIds.get(complianceData.getDeviceId()));
} }
@ -288,9 +304,6 @@ public class MonitoringManagerImpl implements MonitoringManager {
if (!deviceIdsWithExistingOperation.isEmpty()) { if (!deviceIdsWithExistingOperation.isEmpty()) {
monitoringDAO.updateAttempts(new ArrayList<>(deviceIdsWithExistingOperation.keySet()), false); 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(); 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) private void addMonitoringOperationsToDatabase(List<Device> devices)
@ -325,8 +361,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
service.addOperation(monitoringOperation, deviceIdentifiers); service.addOperation(monitoringOperation, deviceIdentifiers);
// PolicyManagementDataHolder.getInstance().getDeviceManagementService().
// addOperation(monitoringOperation, deviceIdentifiers);
} }
private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) { private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) {

@ -188,8 +188,19 @@ public class PolicyManagerImpl implements PolicyManager {
public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException { public boolean updatePolicyPriorities(List<Policy> policies) throws PolicyManagementException {
boolean bool; boolean bool;
try { try {
List<Policy> existingPolicies = this.getPolicies();
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
bool = policyDAO.updatePolicyPriorities(policies); 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); policyDAO.recordUpdatedPolicies(policies);
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (PolicyManagerDAOException e) { } 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.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.Task; 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.common.spi.PolicyMonitoringService;
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager; 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."); log.debug("Monitoring task started to run.");
} }
MonitoringManager monitoringManager = new MonitoringManagerImpl();
List<DeviceType> deviceTypes = new ArrayList<>(); List<DeviceType> deviceTypes = new ArrayList<>();
try { try {
DeviceManagementDAOFactory.openConnection(); deviceTypes = monitoringManager.getDeviceTypes();
deviceTypes = deviceTypeDAO.getDeviceTypes(); } catch (PolicyComplianceException e) {
} catch (Exception e) { log.error("Error occurred while getting the device types.");
log.error("Error occurred while getting the device types.", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
} }
if (!deviceTypes.isEmpty()) { if (!deviceTypes.isEmpty()) {
@ -78,7 +78,6 @@ public class MonitoringTask implements Task {
DeviceManagementProviderService deviceManagementProviderService = DeviceManagementProviderService deviceManagementProviderService =
PolicyManagementDataHolder.getInstance().getDeviceManagementService(); PolicyManagementDataHolder.getInstance().getDeviceManagementService();
MonitoringManager monitoringManager = new MonitoringManagerImpl();
for (DeviceType deviceType : deviceTypes) { for (DeviceType deviceType : deviceTypes) {
PolicyMonitoringService monitoringService = 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; 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.common.TaskException;
import org.wso2.carbon.ntask.core.TaskInfo; import org.wso2.carbon.ntask.core.TaskInfo;
import org.wso2.carbon.ntask.core.TaskManager; import org.wso2.carbon.ntask.core.TaskManager;
@ -37,45 +39,56 @@ import java.util.Map;
public class TaskScheduleServiceImpl implements TaskScheduleService { public class TaskScheduleServiceImpl implements TaskScheduleService {
private static Log log = LogFactory.getLog(TaskScheduleServiceImpl.class); private static Log log = LogFactory.getLog(TaskScheduleServiceImpl.class);
private PolicyConfiguration policyConfiguration;
public TaskScheduleServiceImpl() {
this.policyConfiguration = DeviceConfigurationManager.getInstance().getDeviceManagementConfig().
getDeviceManagementConfigRepository().getPolicyConfiguration();
}
@Override @Override
public void startTask(int monitoringFrequency) throws PolicyMonitoringTaskException { 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()) { if (policyConfiguration.getMonitoringEnable()) {
log.debug("Monitoring task is started for the tenant id " + tenantId);
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 triggerInfo = new TriggerInfo();
triggerInfo.setRepeatCount(-1); triggerInfo.setIntervalMillis(monitoringFrequency);
triggerInfo.setRepeatCount(-1);
Map<String, String> properties = new HashMap<>(); Map<String, String> properties = new HashMap<>();
properties.put(PolicyManagementConstants.TENANT_ID, String.valueOf(tenantId)); 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.registerTask(taskInfo);
taskManager.rescheduleTask(taskInfo.getName()); taskManager.rescheduleTask(taskInfo.getName());
} catch (TaskException e) { } catch (TaskException e) {
String msg = "Error occurred while creating the task for tenant " + PrivilegedCarbonContext. throw new PolicyMonitoringTaskException("Error occurred while creating the task for tenant " + PrivilegedCarbonContext.
getThreadLocalCarbonContext().getTenantId(); getThreadLocalCarbonContext().getTenantId(), e);
log.error(msg, e); }
throw new PolicyMonitoringTaskException(msg, 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 taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
taskManager.deleteTask(taskName); taskManager.deleteTask(taskName);
} catch (TaskException e) { } catch (TaskException e) {
String msg = "Error occurred while deleting the task for tenant " + PrivilegedCarbonContext. throw new PolicyMonitoringTaskException("Error occurred while deleting the task for tenant " + PrivilegedCarbonContext.
getThreadLocalCarbonContext().getTenantId(); getThreadLocalCarbonContext().getTenantId(), e);
log.error(msg, e);
throw new PolicyMonitoringTaskException(msg, e);
} }
} }
@ -103,29 +114,25 @@ public class TaskScheduleServiceImpl implements TaskScheduleService {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId); String taskName = PolicyManagementConstants.MONITORING_TASK_NAME + "_" + String.valueOf(tenantId);
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService(); TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE); TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.MONITORING_TASK_TYPE);
taskManager.deleteTask(taskName); taskManager.deleteTask(taskName);
TriggerInfo triggerInfo = new TriggerInfo(); TriggerInfo triggerInfo = new TriggerInfo();
triggerInfo.setIntervalMillis(monitoringFrequency); triggerInfo.setIntervalMillis(monitoringFrequency);
triggerInfo.setRepeatCount(-1); triggerInfo.setRepeatCount(-1);
Map<String, String> properties = new HashMap<>(); Map<String, String> properties = new HashMap<>();
properties.put("tenantId", String.valueOf(tenantId)); 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.registerTask(taskInfo);
taskManager.rescheduleTask(taskInfo.getName()); taskManager.rescheduleTask(taskInfo.getName());
} catch (TaskException e) { } catch (TaskException e) {
String msg = "Error occurred while updating the task for tenant " + PrivilegedCarbonContext. throw new PolicyMonitoringTaskException("Error occurred while updating the task for tenant " + PrivilegedCarbonContext.
getThreadLocalCarbonContext().getTenantId(); getThreadLocalCarbonContext().getTenantId(), e);
log.error(msg, e);
throw new PolicyMonitoringTaskException(msg, e);
} }
} }

@ -26,6 +26,9 @@ import org.testng.annotations.BeforeSuite;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; 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.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
@ -61,6 +64,7 @@ public abstract class BasePolicyManagementDAOTest {
this.initSQLScript(); this.initSQLScript();
this.initialize(); this.initialize();
this.initiatePrivilegedCaronContext(); this.initiatePrivilegedCaronContext();
DeviceConfigurationManager.getInstance().initConfig();
} }
public void initialize() throws TaskException { 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> </IdentityConfiguration>
<PolicyConfiguration> <PolicyConfiguration>
<monitoringClass>org.wso2.carbon.policy.mgt</monitoringClass> <monitoringClass>org.wso2.carbon.policy.mgt</monitoringClass>
<monitoringEnable>true</monitoringEnable>
<monitoringFrequency>60000</monitoringFrequency>
<maxRetries>5</maxRetries> <maxRetries>5</maxRetries>
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable> <minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
<minRetriesToMarkInactive>20</minRetriesToMarkInactive>
</PolicyConfiguration> </PolicyConfiguration>
</ManagementRepository> </ManagementRepository>
</DeviceMgtConfiguration> </DeviceMgtConfiguration>

Loading…
Cancel
Save