You are viewing a plain text version of this content. The canonical link for it is here.
Posted to imperius-user@incubator.apache.org by sm...@irit.fr on 2009/09/17 23:25:41 UTC
Re: spl policy
> Hi
please can you help me, to write the syntax of policy for this example
I need it for today
thank you
> smaili,
>
> Welcome to the policy world!
>
> Regarding your questions about how to use Imperius to create policy-based
> applications, I would like to explain to you by walking you through a
> concrete example that uses your scenario.
>
> In a policy managed environment, you should have sensors that collect
> information from your managed system and effectors that execute actions
> when your policy is enforced.
>
> In you scenario, sensors and effectors can be combined in an anchor class,
> PollingOperation.java as shown below. This class does both of information
> collection and action execution. In addition, you also need to write a
> policy which describes your control logical, please see Policy given
> below.
>
> Once you have these components in place, you need to write your
> application
> that uses Imperius Policy Engine to evaluate your conditions and take
> actions accordingly.
>
> You should see the following messages when you execute the Manager.java.
>
> ***********DeletePolicy : dummy***********
> ***********DeletePolicy complete***********
> ***********CreatePolicy : dummy***********
> ***********CreatePolicy complete***********
> Policy Created : dummy true
>
> Execution Result is 1
>
> I hope I have answered your questions.
>
> Xiping
> IBM T.J. Watson Research Center
>
>
>
> =============================================================================================================
>
> 1) Anchor class PollingOperation
>
> package com.abdel;
>
> public class PollingOperation {
> public static int POLLING_OPERATION = 1;
> public static int PUSHING_OPERATION = 2;
>
> private int operation = POLLING_OPERATION;
> private int numOfOperations;
> private int pollingInterval;
>
> public void setCurOperation(int op) {
> this.operation = op;
> }
>
> public PollingOperation(int interval, int numOfOperations) {
> this.pollingInterval = interval;
> this.numOfOperations = numOfOperations;
> }
>
> public int getCurOperation() {
> return this.operation;
> }
>
> public void setNumOfOperation(int num) {
> this.numOfOperations = num;
> }
>
> public int getNumberOfOperations() {
> return this.numOfOperations;
> }
>
> public void changePollingInterval(int delta) {
> this.pollingInterval += delta;
> }
> }
>
> 2) Policy
>
> Import Class com.abdel.PollingOperation:pop;
> Strategy Execute_All_Applicable;
> Policy {
> Declaration {
> pollingOp = 1;
> threshold = 10;
> delta = 5;
> }
> Condition {
> pop.getCurOperation() == pollingOp &&
> pop.getNumberOfOperations() > threshold
> }
> Decision {
> pop.changePollingInterval(delta)
> }
> }:1;
>
> 3) Application
>
> package com.abdel;
>
> import java.io.DataInputStream;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.util.Hashtable;
> import java.util.Map;
>
> import org.apache.imperius.javaspl.Java_SPLPolicyRuleProvider;
> import org.apache.imperius.spl.parser.exceptions.SPLException;
>
> public class Manager {
>
> public static void main(String[] args) throws SPLException,
> IOException {
>
> if (args.length != 1) {
> System.out.println("Usage: Manager <policy>");
> System.exit(0);
> }
>
> // read in policy
> DataInputStream dis = new DataInputStream(new FileInputStream
> (args[0]));
> StringBuffer sb = new StringBuffer();
> String s = null;
> while ((s = dis.readLine()) != null) {
> sb.append(s+"\n");
> }
>
> // setup
> Map objMap = new Hashtable();
> PollingOperation pop = new PollingOperation(5, 11);
> objMap.put("pop", pop);
>
>
> Java_SPLPolicyRuleProvider jspl = Java_SPLPolicyRuleProvider.
> getInstance();
> String policyName = "dummy";
>
> // delete policy if exists
> try {
> jspl.deletePolicy(policyName);
> } catch(Exception e) { }
>
> // create policy
> boolean createReturn = jspl.createPolicy("dummy", sb.toString
> ());
> System.out.println("Policy Created : " + policyName + " " +
> createReturn);
> System.out.println("");
>
> // evaluate policy
> Object result = jspl.executePolicy(policyName, objMap);
> System.out.println("Execution Result is " + result);
>
> }
> }
>
Re: spl policy
Posted by Xiping Wang <xi...@us.ibm.com>.
In the example I gave below shows exactly what you described in your
scenario, including an SPL policy, an anchor class and an application
program.
Xiping
IBM T.J. Watson Research Center
From: smaili@irit.fr
To: imperius-user@incubator.apache.org
Date: 09/17/2009 07:26 PM
Subject: Re: spl policy
> Hi
please can you help me, to write the syntax of policy for this example
I need it for today
thank you
> smaili,
>
> Welcome to the policy world!
>
> Regarding your questions about how to use Imperius to create policy-based
> applications, I would like to explain to you by walking you through a
> concrete example that uses your scenario.
>
> In a policy managed environment, you should have sensors that collect
> information from your managed system and effectors that execute actions
> when your policy is enforced.
>
> In you scenario, sensors and effectors can be combined in an anchor
class,
> PollingOperation.java as shown below. This class does both of information
> collection and action execution. In addition, you also need to write a
> policy which describes your control logical, please see Policy given
> below.
>
> Once you have these components in place, you need to write your
> application
> that uses Imperius Policy Engine to evaluate your conditions and take
> actions accordingly.
>
> You should see the following messages when you execute the Manager.java.
>
> ***********DeletePolicy : dummy***********
> ***********DeletePolicy complete***********
> ***********CreatePolicy : dummy***********
> ***********CreatePolicy complete***********
> Policy Created : dummy true
>
> Execution Result is 1
>
> I hope I have answered your questions.
>
> Xiping
> IBM T.J. Watson Research Center
>
>
>
>
=============================================================================================================
>
> 1) Anchor class PollingOperation
>
> package com.abdel;
>
> public class PollingOperation {
> public static int POLLING_OPERATION = 1;
> public static int PUSHING_OPERATION = 2;
>
> private int operation = POLLING_OPERATION;
> private int numOfOperations;
> private int pollingInterval;
>
> public void setCurOperation(int op) {
> this.operation = op;
> }
>
> public PollingOperation(int interval, int numOfOperations) {
> this.pollingInterval = interval;
> this.numOfOperations = numOfOperations;
> }
>
> public int getCurOperation() {
> return this.operation;
> }
>
> public void setNumOfOperation(int num) {
> this.numOfOperations = num;
> }
>
> public int getNumberOfOperations() {
> return this.numOfOperations;
> }
>
> public void changePollingInterval(int delta) {
> this.pollingInterval += delta;
> }
> }
>
> 2) Policy
>
> Import Class com.abdel.PollingOperation:pop;
> Strategy Execute_All_Applicable;
> Policy {
> Declaration {
> pollingOp = 1;
> threshold = 10;
> delta = 5;
> }
> Condition {
> pop.getCurOperation() == pollingOp &&
> pop.getNumberOfOperations() > threshold
> }
> Decision {
> pop.changePollingInterval(delta)
> }
> }:1;
>
> 3) Application
>
> package com.abdel;
>
> import java.io.DataInputStream;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.util.Hashtable;
> import java.util.Map;
>
> import org.apache.imperius.javaspl.Java_SPLPolicyRuleProvider;
> import org.apache.imperius.spl.parser.exceptions.SPLException;
>
> public class Manager {
>
> public static void main(String[] args) throws SPLException,
> IOException {
>
> if (args.length != 1) {
> System.out.println("Usage: Manager <policy>");
> System.exit(0);
> }
>
> // read in policy
> DataInputStream dis = new DataInputStream(new FileInputStream
> (args[0]));
> StringBuffer sb = new StringBuffer();
> String s = null;
> while ((s = dis.readLine()) != null) {
> sb.append(s+"\n");
> }
>
> // setup
> Map objMap = new Hashtable();
> PollingOperation pop = new PollingOperation(5, 11);
> objMap.put("pop", pop);
>
>
> Java_SPLPolicyRuleProvider jspl = Java_SPLPolicyRuleProvider.
> getInstance();
> String policyName = "dummy";
>
> // delete policy if exists
> try {
> jspl.deletePolicy(policyName);
> } catch(Exception e) { }
>
> // create policy
> boolean createReturn = jspl.createPolicy("dummy", sb.toString
> ());
> System.out.println("Policy Created : " + policyName + " " +
> createReturn);
> System.out.println("");
>
> // evaluate policy
> Object result = jspl.executePolicy(policyName, objMap);
> System.out.println("Execution Result is " + result);
>
> }
> }
>