|
General Tips
Can non-periodic policy be executed at time schedules of hour : minutes ?
How to schedule policy to take back up of data at 1:00a.m. on all the 7 days of the week?
General Tips
If I schedule some policy on 31st
of every month and if a month does not have 31, what will be the result
?
If you schedule some policy on 31st of every month, then the policy
will be executed only for the months which contain the date 31st. For
example, if you have scheduled policy on 31st of every month starting
from January, then the policy will be executed on January 31. For February,
it will not be executed, since it does not have 31. Again on March 31,
the policy will be executed and so on.
Write a custom or user module implementing RunProcessInterface or use your existing user module (if any)
From the user module, get the handle of NmsPolicyAPI as given below
NmsPolicyAPI api = (NmsPolicyAPI)NmsUtil.getAPI("NmsPolicyAPI");
Create a instance for the PolicyObject you have added as
PolicyObject po = new WebNmsBackupPolicy(); po.setName("WebNmsBackupPolicy");
Check whether the
policy already exists with the same
name "WebNmsBackupPolicy", If not, add it as
Vector v = api.getPolicyNames() // gives you names of all
available policy objects
if(!(v.contains("WebNmsBackupPolicy")))
{
// If object doesn't exist add it
api.addPolicy(po);
}
else
{
// don't add as the policy objects already exists. This will help you to avoid adding same object again during warm start.
Is there a simpler service/mechanism
in Web NMS which I can use to periodically monitor the status of a certain
operation in devices? I need a very simple callback mechanism from a timer-based
service.
By using either the PeriodicPolicyObject or the Scheduler, you can
achieve the above requirement. The following code snippet gives you an
idea as to how you achieve this. (You can execute the code given below
from your custom module).
Code snippet
|
// create a new Scheduler or use existing schedulers in WebNMS // for creating a Scheduler Scheduler sch = Scheduler.createScheduler("Test",4); sch.start(); // write a class implementing Runnable let's call it as MyRunnable Runnable run = new MyRunnable(); // To schedule it after (say)10 seconds from current time long timeToSchedule = System.currentTimeMillis() + 10000; sch. scheduleTask(run, timeToSchedule); // once it is scheduled after 10 seconds run method of your Runnable implementation class MyRunnable will be called public void run() { // check whether the task is over boolean completed = <check the operation> // if the task is completed don't do anything else reschedule the same class again for next 10th second. Continue this operation till the task is over if(!completed) { long timeToSchedule = System.currentTimeMillis() + 10000; sch. scheduleTask(this, timeToSchedule); } } |
For further details refer to the documentation for scheduling services and the Javadocs of Scheduler.
Periodic policies are getting executed
once they are added ; whereas in the case of non-periodic policies, it
is not so. Why ?
This is because a default time period (10 seconds) is set for periodic
policies. So, periodic policies are getting executed automatically.
On the other hand, no default period or time can be specified for Non-
Periodic policies. You explicitly need to schedule the policy using the
SchedulePolicyUI. Otherwise, it will not be executed. Refer to the following
sections of our documentation for further details.
Refer to Executing & Stop Policy
Refer to Scheduling Policy
Can non-periodic policy be executed at time
schedules of hour : minutes ?
No, non-periodic policies cannot be executed like that. It can be executed
to the precision of hours only and not hours:minutes. For example, it
can be executed at 11:00, 12:00, etc. and not at 11:30, 12:15, etc.
To schedule a non-periodic policy, you can use the method 'setTimeVector()' available in the class PolicyObject. Please look here for details on Time Vector (com.adventnet.management.policydb.PolicyObject.setTimeVector()). We provide below a code snippet to show how you can execute a policy (this is for executing a policy at any point of time and not for scheduling).
/* 'napi' denotes "NmsPolicyAPI" , 'examplepolicy' denotes the name of the policy*/
|
PolicyEvent pe = new PolicyEvent(napi.getPolicy("examplepolicy")); pe.addPolicyNamesToTrigger("examplepolicy"); napi.executePolicy(pe); |
TimeVectorStructure: TimeVector in PolicyObject contains information about scheduling pattern configured for it. TimeVector contains either
7 vectors (in case of day wise ) (or)
31 Vectors (in case of date wise) .
In each and every vector, information about scheduling hours will be stored as Integer Objects.
For example: If you have scheduled PolicyObject at 1, l5 and 20 hrs for 5 dates then time vector looks as
{
[1, 15, 20]
[1, 15, 20]
[1, 15, 20]
[1, 15, 20]
[1, 15, 20]
}
Here 1, 5 and 20 are IntegerObjects holding the value 1 , 5 and 20 respectively. If you have scheduled PolicyObject as
1st date 1,10 hrs
6th date 18 , 22 hrs
9th date 5 , 16 hrs
then the vector will look like
{
[1,10]
[]
[]
[]
[]
[18,22]
[]
[]
[5,15]
:
:
:
[]
}
In case of day wise scheduling, Vector size will be seven. If you are going to schedule the Policy in day wise mode as
Sunday 3, 6 hrs, Monday 6, 7 hrs, Tuesday 4, 9 hrs, Wednesday 9, 11 hrs, Friday 9, 11 hrs, Saturday 3, 13 hrs, then timeVector looks as
{
[ 3, 6]
[ 6 , 7]
[ 4 , 9]
[ 9 , 11]
[]
[9,11]
[3 , 13]
}
If no time is mentioned for a particular day / date then the corresponding vector size for that particular day / date is zero
You must use NonPeriodic policy to achieve the above requirement. To schedule certain policies for execution at specific hours, you need to use Non Periodic Policy. This sometimes appear to be Periodic Policy, but is actually a non periodic policy. Periodic Policy is for scheduling a policy for execution at periodic intervals from the time of server startup. For example, if you specify the time interval as 30 seconds, the policy is scheduled for execution for every 30 seconds from server startup.
As per the asked query, this requirement can be achieved only through non-periodic policy for the following reason. Assume the server is started on Sunday, 3:00 PM, and is scheduled for execution for the first time on Monday, 1:00 AM which is 10 hrs from server startup. Again on Tuesday, it is scheduled for 1:00 AM. Here, the time interval becomes 24 hrs. Hence, it can be inferred that this type of scheduling can be executed only by non periodic policy. In this case, choose the option 'day' as 'All Days' and timing as '1:00 A.M' to achieve your requirement.
|