mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt
This commit is contained in:
commit
a461e887d1
@ -21,7 +21,7 @@ package org.wso2.carbon.device.mgt.common;
|
||||
public class EnrolmentInfo {
|
||||
|
||||
public enum Status {
|
||||
CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED
|
||||
CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED, DISENROLLMENT_REQUESTED
|
||||
}
|
||||
|
||||
public enum OwnerShip {
|
||||
|
||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.config;
|
||||
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
||||
import org.wso2.carbon.device.mgt.core.config.email.EmailConfigurations;
|
||||
import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations;
|
||||
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
@ -33,6 +34,7 @@ public class DeviceManagementConfigRepository {
|
||||
private DataSourceConfig dataSourceConfig;
|
||||
private EmailConfigurations emailConfigurations;
|
||||
private IdentityConfigurations identityConfigurations;
|
||||
private PolicyConfiguration policyConfiguration;
|
||||
|
||||
@XmlElement(name = "DataSourceConfiguration", required = true)
|
||||
public DataSourceConfig getDataSourceConfig() {
|
||||
@ -60,4 +62,13 @@ public class DeviceManagementConfigRepository {
|
||||
public void setIdentityConfigurations(IdentityConfigurations identityConfigurations) {
|
||||
this.identityConfigurations = identityConfigurations;
|
||||
}
|
||||
|
||||
@XmlElement(name = "PolicyConfiguration", required = true)
|
||||
public PolicyConfiguration getPolicyConfiguration() {
|
||||
return policyConfiguration;
|
||||
}
|
||||
|
||||
public void setPolicyConfiguration(PolicyConfiguration policyConfiguration) {
|
||||
this.policyConfiguration = policyConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.device.mgt.core.config.policy;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "PolicyConfiguration")
|
||||
public class PolicyConfiguration {
|
||||
|
||||
private String monitoringClass;
|
||||
private int maxRetries;
|
||||
private int minRetriesToMarkUnreachable;
|
||||
|
||||
@XmlElement(name = "monitoringClass", required = true)
|
||||
public String getMonitoringClass() {
|
||||
return monitoringClass;
|
||||
}
|
||||
|
||||
public void setMonitoringClass(String monitoringClass) {
|
||||
this.monitoringClass = monitoringClass;
|
||||
}
|
||||
|
||||
@XmlElement(name = "maxRetries", required = true)
|
||||
public int getMaxRetries() {
|
||||
return maxRetries;
|
||||
}
|
||||
|
||||
public void setMaxRetries(int maxRetries) {
|
||||
this.maxRetries = maxRetries;
|
||||
}
|
||||
|
||||
@XmlElement(name = "minRetriesToMarkUnreachable", required = true)
|
||||
public int getMinRetriesToMarkUnreachable() {
|
||||
return minRetriesToMarkUnreachable;
|
||||
}
|
||||
|
||||
public void setMinRetriesToMarkUnreachable(int minRetriesToMarkUnreachable) {
|
||||
this.minRetriesToMarkUnreachable = minRetriesToMarkUnreachable;
|
||||
}
|
||||
}
|
||||
@ -60,5 +60,7 @@ public interface DeviceDAO {
|
||||
EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser,
|
||||
int tenantId) throws DeviceManagementDAOException;
|
||||
|
||||
|
||||
List<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException;
|
||||
}
|
||||
|
||||
|
||||
@ -442,4 +442,33 @@ public class DeviceDAOImpl implements DeviceDAO {
|
||||
return enrolmentInfo;
|
||||
}
|
||||
|
||||
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
List<Device> devices = new ArrayList<Device>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
stmt = conn.prepareStatement("SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
|
||||
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
||||
"e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
|
||||
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " +
|
||||
"AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_ID = e.DEVICE_ID " +
|
||||
"AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?");
|
||||
stmt.setInt(1, tenantId);
|
||||
stmt.setString(2, status.toString());
|
||||
stmt.setInt(3, tenantId);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Device device = this.loadDevice(rs);
|
||||
devices.add(device);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
||||
"'" + status + "'", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,9 +26,7 @@ import java.util.List;
|
||||
|
||||
public class ConfigOperation extends Operation {
|
||||
|
||||
private List<Property> properties;
|
||||
|
||||
public ConfigOperation() {
|
||||
/* public ConfigOperation() {
|
||||
properties = new ArrayList<Property>();
|
||||
}
|
||||
|
||||
@ -38,7 +36,7 @@ public class ConfigOperation extends Operation {
|
||||
|
||||
public void addConfigProperty(String name, Object value, Class<?> type) {
|
||||
properties.add(new Property(name, value, type));
|
||||
}
|
||||
}*/
|
||||
|
||||
public static class Property implements Serializable {
|
||||
private String name;
|
||||
|
||||
@ -79,4 +79,13 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM
|
||||
List<Device> getDevicesByName(String deviceName) throws DeviceManagementException;
|
||||
|
||||
void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve list of devices based on the device status
|
||||
*
|
||||
* @param status Device status
|
||||
* @return List of devices
|
||||
* @throws DeviceManagementException
|
||||
*/
|
||||
List<Device> getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException;
|
||||
}
|
||||
|
||||
@ -716,6 +716,45 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<Device> getDevicesByStatus(EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||
List<Device> devices = new ArrayList<Device>();
|
||||
List<Device> allDevices;
|
||||
try {
|
||||
DeviceManagementDAOFactory.getConnection();
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
allDevices = deviceDAO.getDevicesByStatus(status, tenantId);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String errorMsg = "Error occurred while fetching the list of devices that matches to status: '"
|
||||
+ status + "'";
|
||||
log.error(errorMsg, e);
|
||||
throw new DeviceManagementException(errorMsg, e);
|
||||
} finally {
|
||||
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
log.warn("Error occurred while closing the connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
for (Device device : allDevices) {
|
||||
Device dmsDevice =
|
||||
this.getPluginRepository().getDeviceManagementService(
|
||||
device.getType()).getDeviceManager().getDevice(
|
||||
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||
if (dmsDevice != null) {
|
||||
device.setFeatures(dmsDevice.getFeatures());
|
||||
device.setProperties(dmsDevice.getProperties());
|
||||
}
|
||||
devices.add(device);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private int getTenantId() {
|
||||
|
||||
ThreadLocal<Integer> tenantId = new ThreadLocal<Integer>();
|
||||
@ -728,4 +767,5 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
}
|
||||
return tenant;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,38 +19,38 @@
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common;
|
||||
|
||||
public class PolicyVerificationException extends Exception {
|
||||
public class PolicyMonitoringTaskException extends Exception {
|
||||
|
||||
private String policyVerificationErrorMessage;
|
||||
private String policyMonitoingErrorMessage;
|
||||
|
||||
public String getPolicyVerificationErrorMessage() {
|
||||
return policyVerificationErrorMessage;
|
||||
public String getPolicyMonitoingErrorMessage() {
|
||||
return policyMonitoingErrorMessage;
|
||||
}
|
||||
|
||||
public void setPolicyVerificationErrorMessage(String policyVerificationErrorMessage) {
|
||||
this.policyVerificationErrorMessage = policyVerificationErrorMessage;
|
||||
public void setPolicyMonitoingErrorMessage(String policyMonitoingErrorMessage) {
|
||||
this.policyMonitoingErrorMessage = policyMonitoingErrorMessage;
|
||||
}
|
||||
|
||||
public PolicyVerificationException(String message) {
|
||||
public PolicyMonitoringTaskException(String message) {
|
||||
super(message);
|
||||
setPolicyVerificationErrorMessage(message);
|
||||
setPolicyMonitoingErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyVerificationException(String message, Exception ex) {
|
||||
public PolicyMonitoringTaskException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setPolicyVerificationErrorMessage(message);
|
||||
setPolicyMonitoingErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyVerificationException(String message, Throwable cause) {
|
||||
public PolicyMonitoringTaskException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setPolicyVerificationErrorMessage(message);
|
||||
setPolicyMonitoingErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyVerificationException() {
|
||||
public PolicyMonitoringTaskException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PolicyVerificationException(Throwable cause) {
|
||||
public PolicyMonitoringTaskException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.common.monitor;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public class ComplianceData {
|
||||
@ -30,6 +31,10 @@ public class ComplianceData {
|
||||
private int policyId;
|
||||
List<ComplianceFeature> complianceFeatures;
|
||||
private boolean status;
|
||||
private Timestamp lastRequestedTime;
|
||||
private Timestamp lastSucceededTime;
|
||||
private Timestamp lastFailedTime;
|
||||
private int attempts;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
@ -47,6 +52,38 @@ public class ComplianceData {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Timestamp getLastRequestedTime() {
|
||||
return lastRequestedTime;
|
||||
}
|
||||
|
||||
public void setLastRequestedTime(Timestamp lastRequestedTime) {
|
||||
this.lastRequestedTime = lastRequestedTime;
|
||||
}
|
||||
|
||||
public Timestamp getLastSucceededTime() {
|
||||
return lastSucceededTime;
|
||||
}
|
||||
|
||||
public void setLastSucceededTime(Timestamp lastSucceededTime) {
|
||||
this.lastSucceededTime = lastSucceededTime;
|
||||
}
|
||||
|
||||
public Timestamp getLastFailedTime() {
|
||||
return lastFailedTime;
|
||||
}
|
||||
|
||||
public void setLastFailedTime(Timestamp lastFailedTime) {
|
||||
this.lastFailedTime = lastFailedTime;
|
||||
}
|
||||
|
||||
public int getAttempts() {
|
||||
return attempts;
|
||||
}
|
||||
|
||||
public void setAttempts(int attempts) {
|
||||
this.attempts = attempts;
|
||||
}
|
||||
|
||||
public int getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
@ -20,14 +20,19 @@
|
||||
package org.wso2.carbon.policy.mgt.common.monitor;
|
||||
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ComplianceDecisionPoint {
|
||||
|
||||
String getNoneComplianceRule(Policy policy) throws PolicyComplianceException;
|
||||
|
||||
void setDeviceAsUnreachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
|
||||
void setDevicesAsUnreachable(List<DeviceIdentifier> deviceIdentifiers) throws PolicyComplianceException;
|
||||
|
||||
void setDevicesAsUnreachableWith(List<Device> devices) throws PolicyComplianceException;
|
||||
|
||||
void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
|
||||
|
||||
@ -28,10 +28,12 @@ import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PolicyMonitoringService {
|
||||
public interface PolicyMonitoringService {
|
||||
|
||||
void notifyDevices(List<Device> devices) throws PolicyComplianceException;
|
||||
|
||||
ComplianceData checkPolicyCompliance(DeviceIdentifier deviceIdentifier, Policy policy, Object response)
|
||||
throws PolicyComplianceException;
|
||||
|
||||
String getType();
|
||||
}
|
||||
|
||||
@ -21,17 +21,11 @@ package org.wso2.carbon.policy.mgt.core;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.*;
|
||||
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;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -69,6 +63,8 @@ public interface PolicyManagerService {
|
||||
|
||||
PolicyEvaluationPoint getPEP() throws PolicyManagementException;
|
||||
|
||||
TaskScheduleService getTaskScheduleService() throws PolicyMonitoringTaskException;
|
||||
|
||||
int getPolicyCount() throws PolicyManagementException;
|
||||
|
||||
List<ComplianceFeature> CheckPolicyCompliance(DeviceIdentifier deviceIdentifier, Object
|
||||
|
||||
@ -35,6 +35,8 @@ import org.wso2.carbon.policy.mgt.core.impl.PolicyInformationPointImpl;
|
||||
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.impl.MonitoringManagerImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleServiceImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -203,6 +205,11 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
|
||||
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduleService getTaskScheduleService() throws PolicyMonitoringTaskException {
|
||||
return new TaskScheduleServiceImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPolicyCount() throws PolicyManagementException {
|
||||
return policyAdministratorPoint.getPolicyCount();
|
||||
|
||||
@ -30,16 +30,21 @@ public interface MonitoringDAO {
|
||||
|
||||
void setDeviceAsCompliance(int deviceId, int policyId) throws MonitoringDAOException;
|
||||
|
||||
void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature> complianceFeatures)
|
||||
void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature>
|
||||
complianceFeatures)
|
||||
throws MonitoringDAOException;
|
||||
|
||||
ComplianceData getCompliance(int deviceId) throws MonitoringDAOException;
|
||||
|
||||
List<ComplianceData> getCompliance(List<Integer> deviceIds) throws MonitoringDAOException;
|
||||
|
||||
List<ComplianceFeature> getNoneComplianceFeatures(int policyComplianceStatusId) throws MonitoringDAOException;
|
||||
|
||||
void deleteNoneComplianceData(int policyComplianceStatusId) throws MonitoringDAOException;
|
||||
|
||||
void updateAttempts(int deviceId, boolean reset) throws MonitoringDAOException;
|
||||
|
||||
void updateAttempts(List<Integer> deviceId, boolean reset) throws MonitoringDAOException;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -29,11 +29,9 @@ import org.wso2.carbon.policy.mgt.core.dao.PolicyManagementDAOFactory;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.PolicyManagerDAOException;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.util.PolicyManagementDAOUtil;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
@ -46,14 +44,17 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet generatedKeys = null;
|
||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID, POLICY_ID, STATUS) VALUES" +
|
||||
" (?, ?, ?) ";
|
||||
String query = "INSERT INTO DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID, POLICY_ID, STATUS, LAST_FAILED_TIME, " +
|
||||
"ATTEMPTS) VALUES (?, ?, ?, ?, ?) ";
|
||||
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(2, policyId);
|
||||
stmt.setInt(3, 0);
|
||||
stmt.setTimestamp(4, currentTimestamp);
|
||||
stmt.setInt(5, 0);
|
||||
stmt.executeUpdate();
|
||||
|
||||
generatedKeys = stmt.getGeneratedKeys();
|
||||
@ -78,12 +79,15 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET STATUS = ? WHERE DEVICE_ID = ?";
|
||||
String query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET STATUS = ?, ATTEMPTS=0, LAST_SUCCESS_TIME = ?" +
|
||||
" WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, 1);
|
||||
stmt.setInt(2, deviceId);
|
||||
stmt.setTimestamp(2, currentTimestamp);
|
||||
stmt.setInt(3, deviceId);
|
||||
|
||||
stmt.executeUpdate();
|
||||
|
||||
@ -105,8 +109,8 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_POLICY_COMPLIANCE_FEATURES (COMPLIANCE_STATUS_ID, FEATURE_CODE, STATUS) " +
|
||||
"VALUES" +
|
||||
" (?, ?, ?) ";
|
||||
"VALUES (?, ?, ?) ";
|
||||
|
||||
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||
for (ComplianceFeature feature : complianceFeatures) {
|
||||
stmt.setInt(1, policyComplianceStatusId);
|
||||
@ -145,6 +149,10 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
complianceData.setDeviceId(resultSet.getInt("DEVICE_ID"));
|
||||
complianceData.setPolicyId(resultSet.getInt("POLICY_ID"));
|
||||
complianceData.setStatus(resultSet.getBoolean("STATUS"));
|
||||
complianceData.setAttempts(resultSet.getInt("ATTEMPTS"));
|
||||
complianceData.setLastRequestedTime(resultSet.getTimestamp("LAST_REQUESTED_TIME"));
|
||||
complianceData.setLastSucceededTime(resultSet.getTimestamp("LAST_SUCCESS_TIME"));
|
||||
complianceData.setLastFailedTime(resultSet.getTimestamp("LAST_FAILED_TIME"));
|
||||
}
|
||||
return complianceData;
|
||||
|
||||
@ -158,6 +166,48 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ComplianceData> getCompliance(List<Integer> deviceIds) throws MonitoringDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet resultSet = null;
|
||||
List<ComplianceData> complianceDataList = null;
|
||||
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "SELECT * FROM DM_POLICY_COMPLIANCE_STATUS WHERE DEVICE_ID IN (?)";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setString(1, makeString(deviceIds));
|
||||
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
ComplianceData complianceData = new ComplianceData();
|
||||
|
||||
complianceData.setId(resultSet.getInt("ID"));
|
||||
complianceData.setDeviceId(resultSet.getInt("DEVICE_ID"));
|
||||
complianceData.setPolicyId(resultSet.getInt("POLICY_ID"));
|
||||
complianceData.setStatus(resultSet.getBoolean("STATUS"));
|
||||
complianceData.setAttempts(resultSet.getInt("ATTEMPTS"));
|
||||
complianceData.setLastRequestedTime(resultSet.getTimestamp("LAST_REQUESTED_TIME"));
|
||||
complianceData.setLastSucceededTime(resultSet.getTimestamp("LAST_SUCCESS_TIME"));
|
||||
complianceData.setLastFailedTime(resultSet.getTimestamp("LAST_FAILED_TIME"));
|
||||
|
||||
complianceDataList.add(complianceData);
|
||||
}
|
||||
return complianceDataList;
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to retrieve compliance data from database.";
|
||||
log.error(msg, e);
|
||||
throw new MonitoringDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
|
||||
this.closeConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ComplianceFeature> getNoneComplianceFeatures(int policyComplianceStatusId) throws
|
||||
MonitoringDAOException {
|
||||
@ -217,7 +267,66 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
|
||||
@Override
|
||||
public void updateAttempts(int deviceId, boolean reset) throws MonitoringDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
|
||||
conn = this.getConnection();
|
||||
String query = "";
|
||||
if (reset) {
|
||||
query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = 0, LAST_REQUESTED_TIME = ? " +
|
||||
"WHERE DEVICE_ID = ?";
|
||||
} else {
|
||||
query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = ATTEMPTS + 1, LAST_REQUESTED_TIME = ? " +
|
||||
"WHERE DEVICE_ID = ?";
|
||||
}
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setTimestamp(1, currentTimestamp);
|
||||
stmt.setInt(2, deviceId);
|
||||
stmt.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to update the attempts data in database.";
|
||||
log.error(msg, e);
|
||||
throw new MonitoringDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAttempts(List<Integer> deviceIds, boolean reset) throws MonitoringDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||
try {
|
||||
|
||||
conn = this.getConnection();
|
||||
String query = "";
|
||||
if (reset) {
|
||||
query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = 0, LAST_REQUESTED_TIME = ? " +
|
||||
"WHERE DEVICE_ID = ?";
|
||||
} else {
|
||||
query = "UPDATE DM_POLICY_COMPLIANCE_STATUS SET ATTEMPTS = ATTEMPTS + 1, LAST_REQUESTED_TIME = ? " +
|
||||
"WHERE DEVICE_ID = ?";
|
||||
}
|
||||
stmt = conn.prepareStatement(query);
|
||||
for (int deviceId : deviceIds) {
|
||||
stmt.setTimestamp(1, currentTimestamp);
|
||||
stmt.setInt(2, deviceId);
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Unable to update the attempts data in database.";
|
||||
log.error(msg, e);
|
||||
throw new MonitoringDAOException(msg, e);
|
||||
} finally {
|
||||
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -238,4 +347,14 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
log.warn("Unable to close the database connection.");
|
||||
}
|
||||
}
|
||||
|
||||
private String makeString(List<Integer> values) {
|
||||
|
||||
StringBuilder buff = new StringBuilder();
|
||||
for (int value : values) {
|
||||
buff.append(value).append(",");
|
||||
}
|
||||
buff.deleteCharAt(buff.length() - 1);
|
||||
return buff.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,15 +23,13 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
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.EnrolmentInfo;
|
||||
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.dao.DeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.EnrolmentDAO;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData;
|
||||
@ -39,10 +37,7 @@ import org.wso2.carbon.policy.mgt.common.monitor.ComplianceDecisionPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.PolicyComplianceException;
|
||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.PolicyManager;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.PolicyManagerImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -51,50 +46,58 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ComplianceDecisionPointImpl.class);
|
||||
|
||||
private EnrolmentDAO enrolmentDAO;
|
||||
private DeviceDAO deviceDAO;
|
||||
|
||||
private PolicyManager policyManager;
|
||||
|
||||
public ComplianceDecisionPointImpl() {
|
||||
enrolmentDAO = DeviceManagementDAOFactory.getEnrollmentDAO();
|
||||
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
policyManager = new PolicyManagerImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNoneComplianceRule(Policy policy) throws PolicyComplianceException {
|
||||
return policy.getCompliance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceAsUnreachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||
public void setDevicesAsUnreachable(List<DeviceIdentifier> deviceIdentifiers) throws PolicyComplianceException {
|
||||
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.UNREACHABLE, tenantId);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while setting the device as unreachable for " +
|
||||
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
|
||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) {
|
||||
Device device = service.getDevice(deviceIdentifier);
|
||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.UNREACHABLE);
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while setting the device as unreachable";
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDevicesAsUnreachableWith(List<Device> devices) throws PolicyComplianceException {
|
||||
try {
|
||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||
for (Device device : devices) {
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||
deviceIdentifier.setId(device.getDeviceIdentifier());
|
||||
deviceIdentifier.setType(device.getType());
|
||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.UNREACHABLE);
|
||||
}
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while setting the device as unreachable";
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceAsReachable(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||
Device device = service.getDevice(deviceIdentifier);
|
||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.ACTIVE);
|
||||
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while setting the device as reachable for " +
|
||||
deviceIdentifier.getId() + " - " + deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
@ -167,12 +170,12 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
||||
public void markDeviceAsNoneCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.BLOCKED, tenantId);
|
||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||
Device device = service.getDevice(deviceIdentifier);
|
||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.BLOCKED);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while marking device as none compliance " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
@ -184,16 +187,15 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
||||
public void markDeviceAsCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||
Device device = service.getDevice(deviceIdentifier);
|
||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.ACTIVE);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while marking device as compliance " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
}
|
||||
|
||||
}
|
||||
@ -202,12 +204,13 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
||||
public void deactivateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.INACTIVE, tenantId);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||
Device device = service.getDevice(deviceIdentifier);
|
||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.INACTIVE);
|
||||
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while deactivating the device " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
@ -219,12 +222,12 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
||||
public void activateDevice(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException {
|
||||
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
enrolmentDAO.setStatus(device.getId(), device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
DeviceManagementProviderService service = this.getDeviceManagementProviderService();
|
||||
Device device = service.getDevice(deviceIdentifier);
|
||||
service.setStatus(deviceIdentifier, device.getEnrolmentInfo().getOwner(),
|
||||
EnrolmentInfo.Status.ACTIVE);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while activating the device " + deviceIdentifier.getId() + " - " +
|
||||
deviceIdentifier.getType();
|
||||
log.error(msg, e);
|
||||
@ -257,4 +260,8 @@ public class ComplianceDecisionPointImpl implements ComplianceDecisionPoint {
|
||||
this.markDeviceAsNoneCompliance(deviceIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
private DeviceManagementProviderService getDeviceManagementProviderService() {
|
||||
return PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ package org.wso2.carbon.policy.mgt.core.impl;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||
@ -130,7 +129,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
|
||||
|
||||
@Override
|
||||
public void setPolicyUsed(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException {
|
||||
policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy.getId(), policy.getProfile().getProfileFeaturesList());
|
||||
policyManager.addAppliedPolicyToDevice(deviceIdentifier, policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
package org.wso2.carbon.policy.mgt.core.internal;
|
||||
|
||||
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;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
||||
@ -35,6 +36,7 @@ public class PolicyManagementDataHolder {
|
||||
private PolicyInformationPoint policyInformationPoint;
|
||||
private DeviceManagementProviderService deviceManagementService;
|
||||
private Map<String, PolicyMonitoringService> policyMonitoringServiceMap;
|
||||
private TaskService taskService;
|
||||
|
||||
private static PolicyManagementDataHolder thisInstance = new PolicyManagementDataHolder();
|
||||
|
||||
@ -99,4 +101,12 @@ public class PolicyManagementDataHolder {
|
||||
public void unsetPolicyMonitoringService(String deviceType) {
|
||||
this.policyMonitoringServiceMap.remove(deviceType);
|
||||
}
|
||||
|
||||
public TaskService getTaskService() {
|
||||
return taskService;
|
||||
}
|
||||
|
||||
public void setTaskService(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@ 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.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.spi.PolicyMonitoringService;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
@ -58,6 +59,12 @@ import org.wso2.carbon.user.core.service.RealmService;
|
||||
* policy="dynamic"
|
||||
* bind="setPolicyMonitoringService"
|
||||
* unbind="unsetPolicyMonitoringService"
|
||||
* @scr.reference name="ntask.component"
|
||||
* interface="org.wso2.carbon.ntask.core.service.TaskService"
|
||||
* cardinality="1..1"
|
||||
* policy="dynamic"
|
||||
* bind="setTaskService"
|
||||
* unbind="unsetTaskService"
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class PolicyManagementServiceComponent {
|
||||
@ -131,7 +138,7 @@ public class PolicyManagementServiceComponent {
|
||||
|
||||
protected void unsetPEPService(PolicyEvaluationPoint pepService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Unsetting Policy Information Service");
|
||||
log.debug("Removing Policy Information Service");
|
||||
}
|
||||
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(null);
|
||||
}
|
||||
@ -145,7 +152,7 @@ public class PolicyManagementServiceComponent {
|
||||
|
||||
protected void unsetDeviceManagementService(DeviceManagementProviderService deviceManagementService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Unsetting Device Management Service");
|
||||
log.debug("Removing Device Management Service");
|
||||
}
|
||||
PolicyManagementDataHolder.getInstance().setDeviceManagementService(null);
|
||||
}
|
||||
@ -156,15 +163,30 @@ public class PolicyManagementServiceComponent {
|
||||
log.debug("Setting Policy Monitoring Service");
|
||||
}
|
||||
// TODO: FIX THE device type by taking from properties
|
||||
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService("", policyMonitoringService);
|
||||
PolicyManagementDataHolder.getInstance().setPolicyMonitoringService(policyMonitoringService.getType(),
|
||||
policyMonitoringService);
|
||||
}
|
||||
|
||||
protected void unsetPolicyMonitoringService(PolicyMonitoringService policyMonitoringService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting Policy Monitoring Service");
|
||||
log.debug("Removing the Policy Monitoring Service");
|
||||
}
|
||||
// TODO: FIX THE device type by taking from properties
|
||||
PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService("");
|
||||
PolicyManagementDataHolder.getInstance().unsetPolicyMonitoringService(policyMonitoringService.getType());
|
||||
}
|
||||
|
||||
protected void setTaskService(TaskService taskService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Setting the task service.");
|
||||
}
|
||||
PolicyManagementDataHolder.getInstance().setTaskService(taskService);
|
||||
}
|
||||
|
||||
protected void unsetTaskService(TaskService taskService) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Removing the task service.");
|
||||
}
|
||||
PolicyManagementDataHolder.getInstance().setTaskService(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,6 +19,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.policy.mgt.common.monitor.ComplianceData;
|
||||
import org.wso2.carbon.policy.mgt.common.monitor.ComplianceFeature;
|
||||
@ -36,4 +37,6 @@ public interface MonitoringManager {
|
||||
|
||||
ComplianceData getDevicePolicyCompliance(DeviceIdentifier deviceIdentifier) throws PolicyComplianceException;
|
||||
|
||||
void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException;
|
||||
|
||||
}
|
||||
|
||||
@ -60,8 +60,10 @@ public interface PolicyManager {
|
||||
|
||||
List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException;
|
||||
|
||||
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws
|
||||
PolicyManagementException;
|
||||
void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature>
|
||||
profileFeatures) throws PolicyManagementException;
|
||||
|
||||
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException;
|
||||
|
||||
boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ 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.util.PolicyManagerUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class MonitoringManagerImpl implements MonitoringManager {
|
||||
|
||||
@ -186,4 +186,87 @@ public class MonitoringManagerImpl implements MonitoringManager {
|
||||
}
|
||||
return complianceData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMonitoringOperation(List<Device> devices) throws PolicyComplianceException {
|
||||
|
||||
try {
|
||||
|
||||
ComplianceDecisionPoint decisionPoint = new ComplianceDecisionPointImpl();
|
||||
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Map<Integer, Device> deviceIds = new HashMap<>();
|
||||
|
||||
for (Device device : devices) {
|
||||
deviceIds.put(device.getId(), device);
|
||||
}
|
||||
|
||||
List<ComplianceData> complianceDatas = monitoringDAO.getCompliance(new ArrayList<>(deviceIds.keySet()));
|
||||
|
||||
Map<Integer, Device> deviceIdsToAddOperation = new HashMap<>();
|
||||
Map<Integer, Device> deviceIdsWithExistingOperation = new HashMap<>();
|
||||
Map<Integer, Device> inactiveDeviceIds = new HashMap<>();
|
||||
|
||||
Map<Integer, ComplianceData> tempMap = new HashMap<>();
|
||||
|
||||
|
||||
for (ComplianceData complianceData : complianceDatas) {
|
||||
|
||||
tempMap.put(complianceData.getDeviceId(), complianceData);
|
||||
|
||||
if (complianceData.getAttempts() == 0) {
|
||||
deviceIdsToAddOperation.put(complianceData.getDeviceId(),
|
||||
deviceIds.get(complianceData.getDeviceId()));
|
||||
} else {
|
||||
deviceIdsWithExistingOperation.put(complianceData.getDeviceId(),
|
||||
deviceIds.get(complianceData.getDeviceId()));
|
||||
}
|
||||
if (complianceData.getAttempts() >= 20) {
|
||||
inactiveDeviceIds.put(complianceData.getDeviceId(),
|
||||
deviceIds.get(complianceData.getDeviceId()));
|
||||
}
|
||||
}
|
||||
|
||||
for (Device device : devices) {
|
||||
if (!tempMap.containsKey(device.getId())) {
|
||||
deviceIdsToAddOperation.put(device.getId(), device);
|
||||
}
|
||||
}
|
||||
|
||||
if (!deviceIdsToAddOperation.isEmpty()) {
|
||||
this.addMonitoringOperationsToDatabase(new ArrayList<>(deviceIdsToAddOperation.values()));
|
||||
}
|
||||
|
||||
if (!deviceIdsWithExistingOperation.isEmpty()) {
|
||||
monitoringDAO.updateAttempts(new ArrayList<>(deviceIdsWithExistingOperation.keySet()), false);
|
||||
decisionPoint.setDevicesAsUnreachable(this.getDeviceIdentifiersFromDevices(
|
||||
new ArrayList<>(deviceIdsWithExistingOperation.values())));
|
||||
}
|
||||
|
||||
} catch (MonitoringDAOException e) {
|
||||
String msg = "Error occurred from monitoring dao.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyComplianceException(msg, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void addMonitoringOperationsToDatabase(List<Device> devices) throws PolicyComplianceException {
|
||||
|
||||
}
|
||||
|
||||
private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) {
|
||||
|
||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||
for (Device device : devices) {
|
||||
DeviceIdentifier identifier = new DeviceIdentifier();
|
||||
identifier.setId(device.getDeviceIdentifier());
|
||||
identifier.setType(device.getType());
|
||||
|
||||
deviceIdentifiers.add(identifier);
|
||||
}
|
||||
return deviceIdentifiers;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -653,14 +653,15 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> profileFeatures) throws
|
||||
public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId,
|
||||
List<ProfileFeature> profileFeatures) throws
|
||||
PolicyManagementException {
|
||||
|
||||
int deviceId = -1;
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
deviceId = device.getId();
|
||||
deviceId = device.getId();
|
||||
boolean exist = policyDAO.checkPolicyAvailable(deviceId);
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
if (exist) {
|
||||
@ -687,6 +688,45 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws
|
||||
PolicyManagementException {
|
||||
|
||||
int deviceId = -1;
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||
deviceId = device.getId();
|
||||
boolean exist = policyDAO.checkPolicyAvailable(deviceId);
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
if (exist) {
|
||||
Policy policySaved = policyDAO.getAppliedPolicy(deviceId);
|
||||
if (!policy.equals(policySaved)) {
|
||||
policyDAO.updateEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile().
|
||||
getProfileFeaturesList());
|
||||
}
|
||||
} else {
|
||||
policyDAO.addEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile().
|
||||
getProfileFeaturesList());
|
||||
}
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
try {
|
||||
PolicyManagementDAOFactory.rollbackTransaction();
|
||||
} catch (PolicyManagerDAOException e1) {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the evaluated policy to device (" +
|
||||
deviceId + " - " + policy.getId() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred while getting the device details (" + deviceIdentifier.getId() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||
|
||||
|
||||
@ -20,19 +20,13 @@ package org.wso2.carbon.policy.mgt.core.service;
|
||||
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.Feature;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.*;
|
||||
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;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyInformationPoint;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Profile;
|
||||
import org.wso2.carbon.policy.mgt.common.ProfileFeature;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl;
|
||||
import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -112,6 +106,11 @@ public class PolicyManagementService implements PolicyManagerService {
|
||||
return policyManagerService.getPEP();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskScheduleService getTaskScheduleService() throws PolicyMonitoringTaskException {
|
||||
return policyManagerService.getTaskScheduleService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPolicyCount() throws PolicyManagementException {
|
||||
return policyManagerService.getPolicyCount();
|
||||
|
||||
@ -19,6 +19,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.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||
@ -27,6 +29,8 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
import org.wso2.carbon.ntask.core.Task;
|
||||
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;
|
||||
import org.wso2.carbon.policy.mgt.core.mgt.impl.MonitoringManagerImpl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -34,10 +38,14 @@ import java.util.Map;
|
||||
public class MonitoringTask implements Task {
|
||||
|
||||
private DeviceTypeDAO deviceTypeDAO;
|
||||
private static Log log = LogFactory.getLog(MonitoringTask.class);
|
||||
|
||||
Map<String, String> properties;
|
||||
|
||||
|
||||
@Override
|
||||
public void setProperties(Map<String, String> map) {
|
||||
|
||||
this.properties = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,23 +55,34 @@ public class MonitoringTask implements Task {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
|
||||
if(log.isDebugEnabled()) {
|
||||
log.debug("Monitoring task started to run.");
|
||||
}
|
||||
|
||||
try {
|
||||
List<DeviceType> deviceTypes = deviceTypeDAO.getDeviceTypes();
|
||||
|
||||
|
||||
DeviceManagementProviderService deviceManagementProviderService =
|
||||
PolicyManagementDataHolder.getInstance().getDeviceManagementService();
|
||||
MonitoringManager monitoringManager = new MonitoringManagerImpl();
|
||||
|
||||
for (DeviceType deviceType : deviceTypes) {
|
||||
PolicyMonitoringService monitoringService =
|
||||
PolicyManagementDataHolder.getInstance().getPolicyMonitoringService(deviceType.getName());
|
||||
|
||||
List<Device> devices = deviceManagementProviderService.getAllDevices(deviceType.getName());
|
||||
monitoringService.notifyDevices(devices);
|
||||
if (monitoringService != null && !devices.isEmpty()) {
|
||||
monitoringManager.addMonitoringOperation(devices);
|
||||
monitoringService.notifyDevices(devices);
|
||||
}
|
||||
}
|
||||
|
||||
if(log.isDebugEnabled()) {
|
||||
log.debug("Monitoring task running completed.");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
String msg = "Error occurred while trying to run a task.";
|
||||
log.error(msg, e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.task;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
||||
|
||||
public interface TaskScheduleService {
|
||||
|
||||
void startTask(int monitoringFrequency) throws PolicyMonitoringTaskException;
|
||||
|
||||
void stopTask() throws PolicyMonitoringTaskException;
|
||||
|
||||
void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException;
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.task;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.ntask.common.TaskException;
|
||||
import org.wso2.carbon.ntask.core.TaskInfo;
|
||||
import org.wso2.carbon.ntask.core.TaskManager;
|
||||
import org.wso2.carbon.ntask.core.service.TaskService;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException;
|
||||
import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagementConstants;
|
||||
import org.wso2.carbon.policy.mgt.core.util.PolicyManagerUtil;
|
||||
import org.wso2.carbon.ntask.core.TaskInfo.TriggerInfo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TaskScheduleServiceImpl implements TaskScheduleService {
|
||||
|
||||
private static Log log = LogFactory.getLog(TaskScheduleServiceImpl.class);
|
||||
|
||||
@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 = PolicyManagerUtil.getTenantId();
|
||||
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||
taskService.registerTaskType(PolicyManagementConstants.TASK_TYPE);
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Monitoring task is started for the tenant id " + tenantId);
|
||||
}
|
||||
|
||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.TASK_TYPE);
|
||||
|
||||
TriggerInfo triggerInfo = new TriggerInfo();
|
||||
|
||||
triggerInfo.setIntervalMillis(monitoringFrequency);
|
||||
triggerInfo.setRepeatCount(-1);
|
||||
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put(PolicyManagementConstants.TENANT_ID, String.valueOf(tenantId));
|
||||
|
||||
String taskName = PolicyManagementConstants.TASK_NAME + "_" + String.valueOf(tenantId);
|
||||
|
||||
TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.TASK_CLAZZ, properties, triggerInfo);
|
||||
|
||||
taskManager.registerTask(taskInfo);
|
||||
taskManager.rescheduleTask(taskInfo.getName());
|
||||
|
||||
|
||||
} catch (TaskException e) {
|
||||
String msg = "Error occurred while creating the task for tenant " + PolicyManagerUtil.getTenantId();
|
||||
log.error(msg, e);
|
||||
throw new PolicyMonitoringTaskException(msg ,e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopTask() throws PolicyMonitoringTaskException {
|
||||
try {
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
String taskName = PolicyManagementConstants.TASK_NAME + "_" + String.valueOf(tenantId);
|
||||
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.TASK_TYPE);
|
||||
taskManager.deleteTask(taskName);
|
||||
} catch (TaskException e) {
|
||||
String msg = "Error occurred while deleting the task for tenant " + PolicyManagerUtil.getTenantId();
|
||||
log.error(msg, e);
|
||||
throw new PolicyMonitoringTaskException(msg ,e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTask(int monitoringFrequency) throws PolicyMonitoringTaskException {
|
||||
try{
|
||||
int tenantId = PolicyManagerUtil.getTenantId();
|
||||
String taskName = PolicyManagementConstants.TASK_NAME + "_" + String.valueOf(tenantId);
|
||||
TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService();
|
||||
|
||||
TaskManager taskManager = taskService.getTaskManager(PolicyManagementConstants.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.TASK_CLAZZ, properties, triggerInfo);
|
||||
|
||||
taskManager.registerTask(taskInfo);
|
||||
taskManager.rescheduleTask(taskInfo.getName());
|
||||
|
||||
} catch (TaskException e) {
|
||||
String msg = "Error occurred while updating the task for tenant " + PolicyManagerUtil.getTenantId();
|
||||
log.error(msg, e);
|
||||
throw new PolicyMonitoringTaskException(msg ,e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -24,10 +24,17 @@ public final class PolicyManagementConstants {
|
||||
public static final String ANY = "ANY";
|
||||
public static final String POLICY_BUNDLE = "POLICY_BUNDLE";
|
||||
|
||||
public static final String TENANT_ID = "TENANT_ID";
|
||||
|
||||
public static final String MONITOR = "MONITOR";
|
||||
public static final String ENFORCE = "ENFORCE";
|
||||
public static final String WARN = "WARN";
|
||||
public static final String BLOCK = "BLOCK";
|
||||
|
||||
|
||||
public static final String TASK_TYPE = "MONITORING_TASK";
|
||||
public static final String TASK_NAME = "MONITORING";
|
||||
public static final String TASK_CLAZZ = "org.wso2.carbon.policy.mgt.core.task.MonitoringTask";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -35,6 +35,11 @@
|
||||
<AdminUsername>admin</AdminUsername>
|
||||
<AdminPassword>admin</AdminPassword>
|
||||
</IdentityConfiguration>
|
||||
<PolicyConfiguration>
|
||||
<monitoringClass>org.wso2.carbon.policy.mgt</monitoringClass>
|
||||
<maxRetries>5</maxRetries>
|
||||
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
|
||||
</PolicyConfiguration>
|
||||
</ManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
||||
|
||||
@ -0,0 +1,154 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>oauth-extentions-feature</artifactId>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>org.wso2.carbon.oauth.extensions.server.feature</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<name>WSO2 Carbon - Oauth Extensions Server Feature</name>
|
||||
<url>http://wso2.org</url>
|
||||
<description>This feature contains oauth functionality
|
||||
</description>
|
||||
|
||||
<!--<dependencies>-->
|
||||
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.wso2.mdm</groupId>-->
|
||||
<!--<artifactId>dynamic-client-manager</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
<!--</dependencies>-->
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>src/main/resources</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
<includes>
|
||||
<include>build.properties</include>
|
||||
<include>p2.inf</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>org.wso2.mdm</groupId>
|
||||
<artifactId>dynamic-client-manager</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>war</type>
|
||||
<overWrite>true</overWrite>
|
||||
<outputDirectory>${basedir}/src/main/resources/</outputDirectory>
|
||||
<destFileName>dynamic-client-manager.war</destFileName>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>org.wso2.maven</groupId>
|
||||
<artifactId>carbon-p2-plugin</artifactId>
|
||||
<version>${carbon.p2.plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>p2-feature-generation</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>p2-feature-gen</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<id>org.wso2.carbon.oauth.extensions.server</id>
|
||||
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||
<adviceFile>
|
||||
<properties>
|
||||
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||
</properties>
|
||||
</adviceFile>
|
||||
<!--<bundles>-->
|
||||
<!--<bundleDef>-->
|
||||
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.core:${carbon.device.mgt.version}-->
|
||||
<!--</bundleDef>-->
|
||||
<!--<bundleDef>-->
|
||||
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.common:${carbon.device.mgt.version}-->
|
||||
<!--</bundleDef>-->
|
||||
<!--<bundleDef>-->
|
||||
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.simple.policy.decision.point:${carbon.device.mgt.version}-->
|
||||
<!--</bundleDef>-->
|
||||
<!--<bundleDef>-->
|
||||
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.policy.information.point:${carbon.device.mgt.version}-->
|
||||
<!--</bundleDef>-->
|
||||
<!--</bundles>-->
|
||||
<importFeatures>
|
||||
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}
|
||||
</importFeatureDef>
|
||||
</importFeatures>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@ -0,0 +1,2 @@
|
||||
instructions.configure = \
|
||||
org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.oauth.extensions.server_${feature.version}/dynamic-client-manager.war,target:${installFolder}/../../deployment/server/webapps/dynamic-client-manager.war,overwrite:true);\
|
||||
42
features/oauth-extensions/pom.xml
Normal file
42
features/oauth-extensions/pom.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>carbon-devicemgt</artifactId>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||
<artifactId>oauth-extentions-feature</artifactId>
|
||||
<version>0.9.2-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WSO2 Carbon - Policy Management Feature</name>
|
||||
<url>http://wso2.org</url>
|
||||
|
||||
<modules>
|
||||
<module>org.wso2.carbon.oauth.extensions.server.feature</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
Loading…
Reference in New Issue
Block a user