Merge pull request #620 from Megala21/revert_task

Reverting task related changes, that are done for cloud deployment
merge-requests/7/head
Susinda Perera 8 years ago committed by GitHub
commit 1009c98da4

@ -420,12 +420,5 @@ public interface DeviceDAO {
*/ */
List<EnrolmentInfo> getEnrolmentsByStatus(List<DeviceIdentifier> deviceIds, Status status, List<EnrolmentInfo> getEnrolmentsByStatus(List<DeviceIdentifier> deviceIds, Status status,
int tenantId) throws DeviceManagementDAOException; int tenantId) throws DeviceManagementDAOException;
/**
* Retrieving the tenants which are have device enrolled.
* @return
* @throws DeviceManagementDAOException
*/
List<Integer> getDeviceEnrolledTenants() throws DeviceManagementDAOException;
} }

@ -1062,26 +1062,4 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
return devices; return devices;
} }
public List<Integer> getDeviceEnrolledTenants() throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Integer> tenants = new ArrayList<>();
try {
conn = this.getConnection();
String sql = "SELECT distinct(TENANT_ID) FROM DM_DEVICE";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
tenants.add(rs.getInt("TENANT_ID"));
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving tenants which have " +
"device registered.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return tenants;
}
} }

@ -307,10 +307,6 @@ public interface DeviceManagementProviderService {
PolicyMonitoringManager getPolicyMonitoringManager(String deviceType); PolicyMonitoringManager getPolicyMonitoringManager(String deviceType);
List<Integer> getDeviceEnrolledTenants() throws DeviceManagementException;
/** /**
* Change device status. * Change device status.
* *
@ -321,5 +317,4 @@ public interface DeviceManagementProviderService {
*/ */
boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus) boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus)
throws DeviceManagementException; throws DeviceManagementException;
} }

@ -1279,21 +1279,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return dms.getPolicyMonitoringManager(); return dms.getPolicyMonitoringManager();
} }
@Override
public List<Integer> getDeviceEnrolledTenants() throws DeviceManagementException {
try {
DeviceManagementDAOFactory.openConnection();
return deviceDAO.getDeviceEnrolledTenants();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while retrieving the tenants " +
"which have device enrolled.", e);
} catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
@Override @Override
public List<Device> getDevicesOfUser(String username) throws DeviceManagementException { public List<Device> getDevicesOfUser(String username) throws DeviceManagementException {
List<Device> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();

@ -22,25 +22,17 @@ package org.wso2.carbon.device.mgt.core.task.impl;
import com.google.gson.Gson; import com.google.gson.Gson;
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.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
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;
import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.ntask.core.Task;
import org.wso2.carbon.user.api.Tenant;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import java.util.List;
import java.util.List;
import java.util.Map; import java.util.Map;
public class DeviceDetailsRetrieverTask implements Task { public class DeviceDetailsRetrieverTask implements Task {
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class); private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
// private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(); // private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl();
private String deviceType; private String deviceType;
private String oppConfig; private String oppConfig;
private OperationMonitoringTaskConfig operationMonitoringTaskConfig; private OperationMonitoringTaskConfig operationMonitoringTaskConfig;
@ -65,41 +57,18 @@ public class DeviceDetailsRetrieverTask implements Task {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device details retrieving task started to run."); log.debug("Device details retrieving task started to run.");
} }
try {
// Tenant tenants[] = DeviceManagementDataHolder.getInstance().
// getRealmService().getTenantManager().getAllTenants();
List<Integer> tenants = DeviceManagementDataHolder.getInstance(). DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
getDeviceManagementProvider().getDeviceEnrolledTenants(); operationMonitoringTaskConfig);
for (Integer tenant : tenants) { //pass the configurations also from here, monitoring tasks
String tenantDomain = DeviceManagementDataHolder.getInstance(). try {
getRealmService().getTenantManager().getDomain(tenant); deviceTaskManager.addOperations();
try { } catch (DeviceMgtTaskException e) {
PrivilegedCarbonContext.startTenantFlow(); log.error(
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); "Error occurred while trying to add the operations to device to retrieve device details.",
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant); e);
DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType,
operationMonitoringTaskConfig);
//pass the configurations also from here, monitoring tasks
try {
deviceTaskManager.addOperations();
} catch (DeviceMgtTaskException e) {
log.error("Error occurred while trying to add the operations to " +
"device to retrieve device details.", e);
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
} catch (UserStoreException e) {
log.error("Error occurred while trying to get the available tenants", e);
} catch (DeviceManagementException e) {
log.error("Error occurred while trying to get the available tenants " +
"from device manager provider service.", e);
} }
} }
} }

@ -21,18 +21,16 @@ 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.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
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.Task; import org.wso2.carbon.ntask.core.Task;
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
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;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -61,94 +59,69 @@ public class MonitoringTask implements Task {
log.debug("Monitoring task started to run."); log.debug("Monitoring task started to run.");
} }
MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager();
List<String> deviceTypes = new ArrayList<>();
List<String> configDeviceTypes = new ArrayList<>();
try { try {
deviceTypes = monitoringManager.getDeviceTypes();
PolicyManagementDataHolder.getInstance(). for (String deviceType : deviceTypes) {
getRealmService().getTenantManager().getAllTenants(); if (isPlatformExist(deviceType)) {
DeviceManagementProviderService deviceManagementService = new DeviceManagementProviderServiceImpl(); configDeviceTypes.add(deviceType);
List<Integer> tenants = deviceManagementService.getDeviceEnrolledTenants(); }
}
for (Integer tenant : tenants) { } catch (PolicyComplianceException e) {
String tenantDomain = PolicyManagementDataHolder.getInstance(). log.error("Error occurred while getting the device types.");
getRealmService().getTenantManager().getDomain(tenant); }
try { if (!deviceTypes.isEmpty()) {
PrivilegedCarbonContext.startTenantFlow(); try {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); DeviceManagementProviderService deviceManagementProviderService =
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant); PolicyManagementDataHolder.getInstance().getDeviceManagementService();
for (String deviceType : configDeviceTypes) {
MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager(); if (log.isDebugEnabled()) {
List<String> deviceTypes = new ArrayList<>(); log.debug("Running task for device type : " + deviceType);
List<String> configDeviceTypes = new ArrayList<>();
try {
deviceTypes = monitoringManager.getDeviceTypes();
for (String deviceType : deviceTypes) {
if (isPlatformExist(deviceType)) {
configDeviceTypes.add(deviceType);
}
}
} catch (PolicyComplianceException e) {
log.error("Error occurred while getting the device types.");
} }
if (!deviceTypes.isEmpty()) { PolicyMonitoringManager monitoringService =
try { PolicyManagementDataHolder.getInstance().getDeviceManagementService()
DeviceManagementProviderService deviceManagementProviderService = .getPolicyMonitoringManager(deviceType);
PolicyManagementDataHolder.getInstance().getDeviceManagementService(); List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType);
for (String deviceType : configDeviceTypes) { if (monitoringService != null && !devices.isEmpty()) {
if (log.isDebugEnabled()) { List<Device> notifiableDevices = new ArrayList<>();
log.debug("Running task for device type : " + deviceType); if (log.isDebugEnabled()) {
} log.debug("Removing inactive and blocked devices from the list for the device type : " +
PolicyMonitoringManager monitoringService = deviceType);
PolicyManagementDataHolder.getInstance().getDeviceManagementService() }
.getPolicyMonitoringManager(deviceType); for (Device device : devices) {
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType);
if (monitoringService != null && !devices.isEmpty()) { EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus();
List<Device> notifiableDevices = new ArrayList<>(); if (status.equals(EnrolmentInfo.Status.BLOCKED) ||
if (log.isDebugEnabled()) { status.equals(EnrolmentInfo.Status.REMOVED) ||
log.debug("Removing inactive and blocked devices from the list for the device type : " + status.equals(EnrolmentInfo.Status.UNCLAIMED) ||
deviceType); status.equals(EnrolmentInfo.Status.DISENROLLMENT_REQUESTED) ||
} status.equals(EnrolmentInfo.Status.SUSPENDED)) {
for (Device device : devices) { continue;
} else {
EnrolmentInfo.Status status = device.getEnrolmentInfo().getStatus(); notifiableDevices.add(device);
if (status.equals(EnrolmentInfo.Status.BLOCKED) ||
status.equals(EnrolmentInfo.Status.REMOVED) ||
status.equals(EnrolmentInfo.Status.UNCLAIMED) ||
status.equals(EnrolmentInfo.Status.DISENROLLMENT_REQUESTED) ||
status.equals(EnrolmentInfo.Status.SUSPENDED)) {
continue;
} else {
notifiableDevices.add(device);
}
}
if (log.isDebugEnabled()) {
log.debug("Following devices selected to send the notification for " + deviceType);
for (Device device : notifiableDevices) {
log.debug(device.getDeviceIdentifier());
}
}
if (!notifiableDevices.isEmpty()) {
monitoringManager.addMonitoringOperation(notifiableDevices);
}
}
} }
if (log.isDebugEnabled()) { }
log.debug("Monitoring task running completed."); if (log.isDebugEnabled()) {
log.debug("Following devices selected to send the notification for " + deviceType);
for (Device device : notifiableDevices) {
log.debug(device.getDeviceIdentifier());
} }
} catch (Exception e) {
log.error("Error occurred while trying to run a task.", e);
} }
} else { if (!notifiableDevices.isEmpty()) {
log.info("No device types registered currently. So did not run the monitoring task."); monitoringManager.addMonitoringOperation(notifiableDevices);
}
} }
} finally {
PrivilegedCarbonContext.endTenantFlow();
} }
if (log.isDebugEnabled()) {
log.debug("Monitoring task running completed.");
}
} catch (Exception e) {
log.error("Error occurred while trying to run a task.", e);
} }
} else {
} catch (UserStoreException e) { log.info("No device types registered currently. So did not run the monitoring task.");
log.error("Error occurred while trying to get the available tenants", e);
} catch (DeviceManagementException e) {
log.error("Error occurred while trying to get the available tenants from device manager service ", e);
} }
} }

Loading…
Cancel
Save