Switch crontab to calendar

calendar is more exact.

Change-Id: Ia5d5484e5e0441acbca2937aff7dca5129429be1
This commit is contained in:
zhangshuai 2017-03-03 09:36:07 +08:00
parent 06c3a3235a
commit 7731d6c144
11 changed files with 97 additions and 72 deletions

View File

@ -441,14 +441,14 @@ trigger_name_1:
trigger_properties:
description: |
The property list for trigger. it must include "``pattern``" and
"``window``", may include "``format``" "``start_time``" and "``end_time``".
"``format``", may include "``window``" "``start_time``" and "``end_time``".
in: body
required: true
type: dict
trigger_properties_1:
description: |
The property list for trigger. it must include "``pattern``" and
"``window``", may include "``format``" "``start_time``" and "``end_time``".
"``format``", may include "``window``" "``start_time``" and "``end_time``".
in: body
required: false
type: dict

View File

@ -1,12 +1,12 @@
{"trigger_info": {
"name": "My backup trigger",
"type": "time",
"properties": {
"format": "crontab",
"pattern": "0 9 * * *",
"start_time": "2015-12-17T08:30:00",
"end_time": "2016-03-17T08:30:00",
"window": "3600",
"name": "My backup trigger",
"type": "time",
"properties": {
"format": "calendar",
"pattern": "BEGIN:VEVENT\\nRRULE:FREQ=HOURLY;INTERVAL=1;\\nEND:VEVENT",
"start_time": "2015-12-17T08:30:00",
"end_time": "2016-03-17T08:30:00",
"window": "3600"
}
}
}
}

View File

@ -1,13 +1,13 @@
{"trigger_info": {
"id": "2a9ce1f3-cc1a-4516-9435-0ebb13caa398",
"type": "time",
"name": "My backup trigger",
"properties": {
"format": "crontab",
"pattern": "0 9 * * *",
"start_time": "2015-12-17T08:30:00",
"end_time": "2016-03-17T08:30:00",
"window": "3600",
"id": "2a9ce1f3-cc1a-4516-9435-0ebb13caa398",
"name": "My backup trigger",
"type": "time",
"properties": {
"format": "calendar",
"pattern": "BEGIN:VEVENT\\nRRULE:FREQ=HOURLY;INTERVAL=1;\\nEND:VEVENT",
"start_time": "2015-12-17T08:30:00",
"end_time": "2016-03-17T08:30:00",
"window": "3600"
}
}
}
}

View File

@ -1,11 +1,11 @@
{"trigger_info": {
"name": "Trigger for backup",
"properties": {
"format": "crontab",
"pattern": "0 10 * * *",
"start_time": "2015-12-17T08:30:00",
"end_time": "2016-03-17T08:30:00",
"window": "3600",
"name": "Trigger for backup",
"properties": {
"format": "calendar",
"pattern": "BEGIN:VEVENT\\nRRULE:FREQ=HOURLY;INTERVAL=1;\\nEND:VEVENT",
"start_time": "2015-12-17T08:30:00",
"end_time": "2016-03-17T08:30:00",
"window": "3600"
}
}
}
}

View File

@ -1,13 +1,13 @@
{"trigger_info": {
"id": "2a9ce1f3-cc1a-4516-9435-0ebb13caa398",
"type": "time",
"name": "Trigger for backup",
"properties": {
"format": "crontab",
"pattern": "0 10 * * *",
"start_time": "2015-12-17T08:30:00",
"end_time": "2016-03-17T08:30:00",
"window": "3600",
"id": "2a9ce1f3-cc1a-4516-9435-0ebb13caa398",
"name": "Trigger for backup",
"type": "time",
"properties": {
"format": "calendar",
"pattern": "BEGIN:VEVENT\\nRRULE:FREQ=HOURLY;INTERVAL=1;\\nEND:VEVENT",
"start_time": "2015-12-17T08:30:00",
"end_time": "2016-03-17T08:30:00",
"window": "3600"
}
}
}
}

View File

@ -4,14 +4,14 @@
"type": "time",
"name": "My backup trigger",
"properties": {
"format": "crontab",
"pattern": "0 9 * * *",
"format": "calendar",
"pattern": "BEGIN:VEVENT\\nRRULE:FREQ=HOURLY;INTERVAL=1;\\nEND:VEVENT",
"start_time": "2015-12-17T08:30:00",
"end_time": "2016-03-17T08:30:00",
"window": "3600",
"window": "3600"
}
}
},
}
],
"triggers_links": [
{
@ -19,4 +19,4 @@
"rel": "next"
}
]
}
}

View File

@ -488,31 +488,48 @@ This example will show protecting volume.
#. Execute a protect operation automatically with a scheduler::
karbor trigger-create 'My Trigger' 'time' "pattern"="0 20 * * 2","format"="crontab"
+------------+---------------------------------------+
| Property | Value |
+------------+---------------------------------------+
| id | b25e2ac8-a7a0-4466-aafe-9363839cfa60 |
| name | My Trigger |
| properties | { |
| | "format": "crontab", |
| | "pattern": "0 20 * * 2", |
| | "start_time": "2017-02-13 02:04:31" |
| | } |
| type | time |
+------------+---------------------------------------+
karbor scheduledoperation-create 'Protect with My Trigger' protect b25e2ac8-a7a0-4466-aafe-9363839cfa60 "plan_id"="ef8b83f3-d0c4-48ec-8949-5c72bbf14103","provider_id"="cf56bd3e-97a7-4078-b6d5-f36246333fd9"
karbor trigger-create 'My Trigger' 'time' "pattern"="BEGIN:VEVENT\nRRULE:FREQ=MINUTELY;INTERVAL=5;\nEND:VEVENT","format"="calendar"
+------------+------------------------------------------------------------------------------+
| Property | Value |
+------------+------------------------------------------------------------------------------+
| id | b065836f-6485-429d-b12c-e04395c5f58e |
| name | My Trigger |
| properties | { |
| | "format": "calendar", |
| | "pattern": "BEGIN:VEVENT\\nRRULE:FREQ=MINUTELY;INTERVAL=5;\\nEND:VEVENT", |
| | "start_time": "2017-03-02 22:56:42" |
| | } |
| type | time |
+------------+------------------------------------------------------------------------------+
karbor scheduledoperation-create 'Protect with My Trigger' protect b065836f-6485-429d-b12c-e04395c5f58e "plan_id"="ca572b42-6d35-4d81-bb4e-c9b100a3387a","provider_id"="cf56bd3e-97a7-4078-b6d5-f36246333fd9"
+----------------------+---------------------------------------------------------+
| Property | Value |
+----------------------+---------------------------------------------------------+
| description | None |
| enabled | True |
| id | b3a1b864-31ef-4354-8b0a-1c7da2cf9a13 |
| name | Protect with My Trigger |
| id | 2ebcf7cc-d8fe-4a70-af71-8a13f20556fb |
| name | PMT |
| operation_definition | { |
| | "plan_id": "ef8b83f3-d0c4-48ec-8949-5c72bbf14103", |
| | "plan_id": "ca572b42-6d35-4d81-bb4e-c9b100a3387a", |
| | "provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9" |
| | } |
| operation_type | protect |
| trigger_id | b25e2ac8-a7a0-4466-aafe-9363839cfa60 |
| trigger_id | b065836f-6485-429d-b12c-e04395c5f58e |
+----------------------+---------------------------------------------------------+
karbor checkpoint-list cf56bd3e-97a7-4078-b6d5-f36246333fd9
+--------------------------------------+----------------------------------+-----------+-----------------------------------------------------------+------------+
| Id | Project id | Status | Protection plan | Created at |
+--------------------------------------+----------------------------------+-----------+-----------------------------------------------------------+------------+
| 92e74f0c-8519-4928-9bd5-0039e0fe92b0 | 9632a0c585c94d708c57a83190913c76 | available | { | 2017-03-03 |
| | | | "id": "ca572b42-6d35-4d81-bb4e-c9b100a3387a", | |
| | | | "name": "Plan1", | |
| | | | "provider_id": "cf56bd3e-97a7-4078-b6d5-f36246333fd9", | |
| | | | "resources": [ | |
| | | | { | |
| | | | "id": "d72e83c2-4083-4cc7-9283-4578332732ab", | |
| | | | "name": "Volume1", | |
| | | | "type": "OS::Cinder::Volume" | |
| | | | } | |
| | | | ] | |
| | | | } | |
+--------------------------------------+----------------------------------+-----------+-----------------------------------------------------------+------------+

View File

@ -39,7 +39,7 @@ time_trigger_opts = [
help='The maximum window time'),
cfg.StrOpt('time_format',
default='crontab',
default='calendar',
help='The type of time format which is used to compute time')
]

View File

@ -13,16 +13,18 @@
import copy
import eventlet
from croniter import croniter
from datetime import datetime
from functools import partial
from karbor.common import constants
from karbor.services.operationengine.engine.triggers.timetrigger \
.timeformats import calendar_time
from karbor.tests.fullstack import karbor_base
from karbor.tests.fullstack import karbor_objects as objects
from karbor.tests.fullstack import utils
DEFAULT_PROPERTY = {'pattern': '0 20 * * 2', 'format': 'crontab'}
pattern = "BEGIN:VEVENT\nRRULE:FREQ=WEEKLY;INTERVAL=1;\nEND:VEVENT"
DEFAULT_PROPERTY = {'pattern': pattern}
class ScheduledOperationsTest(karbor_base.KarborBaseTest):
@ -87,8 +89,9 @@ class ScheduledOperationsTest(karbor_base.KarborBaseTest):
return 0
cur_time = copy.deepcopy(start_time)
cal_obj = calendar_time.ICal(start_time, pattern)
for i in range(freq):
next_time = croniter(pattern, cur_time).get_next(datetime)
next_time = cal_obj.compute_next_time(cur_time)
cur_time = next_time
return (next_time - start_time).seconds
@ -106,8 +109,8 @@ class ScheduledOperationsTest(karbor_base.KarborBaseTest):
def test_scheduled_operations_create_and_scheduled(self):
freq = 2
pattern = '*/5 * * * *'
cur_property = {'pattern': pattern, 'format': 'crontab'}
pattern = "BEGIN:VEVENT\nRRULE:FREQ=MINUTELY;INTERVAL=5;\nEND:VEVENT"
cur_property = {'pattern': pattern, 'format': 'calendar'}
start_time = datetime.now().replace(microsecond=0)
operation = self.store(self._create_for_volume(cur_property))

View File

@ -19,10 +19,12 @@ class TriggersTest(karbor_base.KarborBaseTest):
"""Test Triggers operation"""
def test_triggers_list(self):
pattern1 = "BEGIN:VEVENT\nRRULE:FREQ=HOURLY;INTERVAL=1;\nEND:VEVENT"
trigger1 = self.store(objects.Trigger())
trigger1.create('time', {'pattern': '0 20 * * 2', 'format': 'crontab'})
trigger1.create('time', {'pattern': pattern1, 'format': 'calendar'})
pattern2 = "BEGIN:VEVENT\nRRULE:FREQ=WEEKLY;INTERVAL=1;\nEND:VEVENT"
trigger2 = self.store(objects.Trigger())
trigger2.create('time', {'pattern': '0 10 * * *', 'format': 'crontab'})
trigger2.create('time', {'pattern': pattern2, 'format': 'calendar'})
items = self.karbor_client.triggers.list()
ids = [item.id for item in items]
@ -31,15 +33,17 @@ class TriggersTest(karbor_base.KarborBaseTest):
def test_triggers_get(self):
trigger_name = "FullStack Trigger Test Get"
pattern = "BEGIN:VEVENT\nRRULE:FREQ=WEEKLY;INTERVAL=1;\nEND:VEVENT"
trigger = self.store(objects.Trigger())
trigger.create('time', {'pattern': '0 15 * * 2', 'format': 'crontab'},
trigger.create('time', {'pattern': pattern, 'format': 'calendar'},
name=trigger_name)
trigger = self.karbor_client.triggers.get(trigger.id)
self.assertEqual(trigger_name, trigger.name)
def test_triggers_delete(self):
pattern = "BEGIN:VEVENT\nRRULE:FREQ=WEEKLY;INTERVAL=1;\nEND:VEVENT"
trigger = objects.Trigger()
trigger.create('time', {'pattern': '0 12 * * 2', 'format': 'crontab'})
trigger.create('time', {'pattern': pattern, 'format': 'calendar'})
self.karbor_client.triggers.delete(trigger.id)
items = self.karbor_client.triggers.list()
ids = [item.id for item in items]

View File

@ -52,6 +52,7 @@ karbor.protectables =
image = karbor.services.protection.protectable_plugins.image:ImageProtectablePlugin
karbor.operationengine.engine.timetrigger.time_format =
crontab = karbor.services.operationengine.engine.triggers.timetrigger.timeformats.crontab_time:Crontab
calendar = karbor.services.operationengine.engine.triggers.timetrigger.timeformats.calendar_time:ICal
karbor.operationengine.engine.executor =
thread_pool = karbor.services.operationengine.engine.executors.thread_pool_executor:ThreadPoolExecutor
green_thread = karbor.services.operationengine.engine.executors.green_thread_executor:GreenThreadExecutor