forked from StackStorm/st2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor content registration into their own files
* Add: Create bootstrap folder in components for registration. * Fix: Deleted st2api model.
- Loading branch information
Lakshmi Kannan
committed
Sep 9, 2014
1 parent
fb9bfab
commit a0e45ad
Showing
10 changed files
with
97 additions
and
86 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import glob | ||
import json | ||
|
||
from oslo.config import cfg | ||
|
||
from st2common import log as logging | ||
from st2common.exceptions.db import StackStormDBObjectNotFoundError | ||
from st2common.persistence.action import Action | ||
from st2common.models.db.action import ActionDB | ||
from st2common.util.action_db import get_runnertype_by_name | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def register_actions(): | ||
actions = glob.glob(cfg.CONF.actions.modules_path + '/*.json') | ||
for action in actions: | ||
LOG.debug('Loading action from %s.', action) | ||
with open(action, 'r') as fd: | ||
try: | ||
content = json.load(fd) | ||
except ValueError: | ||
LOG.exception('Unable to load action from %s.', action) | ||
continue | ||
try: | ||
model = Action.get_by_name(str(content['name'])) | ||
except ValueError: | ||
model = ActionDB() | ||
model.name = content['name'] | ||
model.description = content['description'] | ||
model.enabled = content['enabled'] | ||
model.entry_point = content['entry_point'] | ||
model.parameters = content.get('parameters', {}) | ||
model.required_parameters = content.get('required_parameters', []) | ||
try: | ||
runner_type = get_runnertype_by_name(str(content['runner_type'])) | ||
model.runner_type = {'name': runner_type.name} | ||
except StackStormDBObjectNotFoundError: | ||
LOG.exception('Failed to register action %s as runner %s was not found', | ||
model.name, str(content['runner_type'])) | ||
continue | ||
try: | ||
model = Action.add_or_update(model) | ||
LOG.audit('Action created. Action %s from %s.', model, action) | ||
except Exception: | ||
LOG.exception('Failed to create action %s.', model.name) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import glob | ||
import json | ||
|
||
from oslo.config import cfg | ||
|
||
from st2api.service import triggers as TriggerService | ||
from st2common import log as logging | ||
from st2common.models.api.reactor import RuleAPI, TriggerAPI | ||
from st2common.persistence.reactor import Rule | ||
from st2common.util import reference | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def register_rules(): | ||
rules = glob.glob(cfg.CONF.rules.rules_path + '/*.json') | ||
for rule in rules: | ||
LOG.debug('Loading rule from %s.', rule) | ||
with open(rule, 'r') as fd: | ||
try: | ||
content = json.load(fd) | ||
except ValueError: | ||
LOG.exception('Unable to load rule from %s.', rule) | ||
continue | ||
rule_api = RuleAPI(**content) | ||
trigger_api = TriggerAPI(**rule_api.trigger) | ||
|
||
rule_db = RuleAPI.to_model(rule_api) | ||
trigger_db = TriggerService.create_trigger_db(trigger_api) | ||
|
||
try: | ||
rule_db.id = Rule.get_by_name(rule_api.name).id | ||
except ValueError: | ||
LOG.info('Rule %s not found. Creating new one.', rule) | ||
|
||
rule_db.trigger = reference.get_ref_from_model(trigger_db) | ||
|
||
try: | ||
rule_db = Rule.add_or_update(rule_db) | ||
LOG.audit('Rule updated. Rule %s from %s.', rule_db, rule) | ||
except Exception: | ||
LOG.exception('Failed to create rule %s.', rule_api.name) |