Changed policy evaluation point

merge-requests/7/head
Supun94 8 years ago
parent 62acc2ebf2
commit 35f3fcc8f9

@ -33,7 +33,7 @@ public class PolicyConfiguration {
private int minRetriesToMarkUnreachable;
private int minRetriesToMarkInactive;
private List<String> platforms;
private String policyEvaluationPointName;
private String policyEvaluationPointName;
@XmlElement(name = "MonitoringClass", required = true)
public String getMonitoringClass() {

@ -21,6 +21,7 @@ package org.wso2.carbon.policy.decision.point.internal;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.user.core.service.RealmService;
@ -51,11 +52,8 @@ public class MergedPolicyEvaluationServiceComponent {
}
try {
//TODO: fetch PEP class from config
componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(),
new MergedPolicyEvaluationServiceComponent(), null);
new MergedEvaluationPoint(), null);
} catch (Throwable t) {
log.error("Error occurred while initializing the policy evaluation bundle");
}

@ -22,6 +22,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint;
import org.wso2.carbon.policy.decision.point.simple.PolicyEvaluationServiceImpl;
import org.wso2.carbon.policy.decision.point.simple.SimpleEvaluationImpl;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
import org.wso2.carbon.user.core.service.RealmService;
@ -52,9 +54,8 @@ public class PolicyEvaluationServiceComponent {
}
try {
//TODO: fetch PEP class from config
componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(),
new MergedEvaluationPoint(), null);
new PolicyEvaluationServiceImpl(), null);
} catch (Throwable t) {
log.error("Error occurred while initializing the simple policy evaluation bundle");
}

@ -173,6 +173,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
@Override
public PolicyEvaluationPoint getPEP() throws PolicyManagementException {
PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
}

@ -18,6 +18,8 @@
package org.wso2.carbon.policy.mgt.core.internal;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
@ -36,6 +38,7 @@ public class PolicyManagementDataHolder {
private RealmService realmService;
private TenantManager tenantManager;
private PolicyEvaluationPoint policyEvaluationPoint;
private Map<String, PolicyEvaluationPoint> policyEvaluationPoints = new HashMap<>();
private PolicyInformationPoint policyInformationPoint;
private DeviceManagementProviderService deviceManagementService;
private MonitoringManager monitoringManager;
@ -88,13 +91,23 @@ public class PolicyManagementDataHolder {
}
public PolicyEvaluationPoint getPolicyEvaluationPoint() {
return policyEvaluationPoint;
PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig().getPolicyConfiguration();
String policyEvaluationPointName = policyConfiguration.getPolicyEvaluationPointName();
return policyEvaluationPoints.get(policyEvaluationPointName);
}
public void setPolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) {
this.policyEvaluationPoint = policyEvaluationPoint;
public void putPolicyEvaluationPoint(String name, PolicyEvaluationPoint policyEvaluationPoint) {
policyEvaluationPoints.put(name,policyEvaluationPoint);
// this.policyEvaluationPoint = policyEvaluationPoint;
}
public void removePolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) {
policyEvaluationPoints.put(policyEvaluationPoint.getName(), this.policyEvaluationPoint);
// this.policyEvaluationPoint = policyEvaluationPoint;
}
public PolicyInformationPoint getPolicyInformationPoint() {
return policyInformationPoint;
}

@ -46,9 +46,9 @@ import org.wso2.carbon.user.core.service.RealmService;
* policy="dynamic"
* bind="setRealmService"
* unbind="unsetRealmService"
* @scr.reference name="org.wso2.carbon.devicemgt.simple.policy.evaluation.manager"
* @scr.reference name="org.wso2.carbon.devicemgt.policy.evaluation.manager"
* interface="org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint"
* cardinality="1..1"
* cardinality="1..n"
* policy="dynamic"
* bind="setPEPService"
* unbind="unsetPEPService"
@ -159,14 +159,14 @@ public class PolicyManagementServiceComponent {
if (log.isDebugEnabled()) {
log.debug("Setting Policy Information Service");
}
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(pepService);
PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(pepService.getName(), pepService);
}
protected void unsetPEPService(PolicyEvaluationPoint pepService) {
if (log.isDebugEnabled()) {
log.debug("Removing Policy Information Service");
}
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(null);
PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(null);
}
protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) {

@ -51,7 +51,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
@Override
public void init() throws Exception {
PolicyEvaluationPoint evaluationPoint = new SimplePolicyEvaluationTest();
PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(evaluationPoint);
PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(evaluationPoint.getName(), evaluationPoint);
}
@Test
@ -93,7 +93,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
}
@Test(dependsOnMethods = ("activatePolicies"))
public void getEffectivePolicy() throws DeviceManagementException, PolicyEvaluationException {
public void getEffectivePolicy(DeviceIdentifier identifier) throws DeviceManagementException, PolicyEvaluationException {
log.debug("Getting effective policy for device started ..........");
@ -103,7 +103,6 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest {
PolicyEvaluationPoint evaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint();
for (Device device : devices) {
DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setType(device.getType());
identifier.setId(device.getDeviceIdentifier());
Policy policy = evaluationPoint.getEffectivePolicy(identifier);

@ -79,7 +79,7 @@ SimplePolicyEvaluationTest implements PolicyEvaluationPoint {
@Override
public String getName() {
return "MergedPolicyEvaluationServiceComponent";
return "SimplePolicyEvaluationServiceComponent";
}
public void sortPolicies(List<Policy> policyList) throws PolicyEvaluationException {

@ -42,8 +42,8 @@
<maxRetries>5</maxRetries>
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
<minRetriesToMarkInactive>20</minRetriesToMarkInactive>
<!--<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>
<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>
<!--<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
</PolicyConfiguration>
</ManagementRepository>
</DeviceMgtConfiguration>

@ -43,8 +43,8 @@
<MaxRetries>5</MaxRetries>
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>
<!--<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>
<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>
<!--<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
<Platforms>
<Platform>android</Platform>
<Platform>ios</Platform>

Loading…
Cancel
Save