Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e5a442ad
authored
Apr 03, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common, vm: extract activity code composition functionality
parent
299383c0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
9 deletions
+25
-9
circle/common/models.py
+9
-0
circle/vm/models/activity.py
+16
-9
No files found.
circle/common/models.py
View file @
e5a442ad
...
...
@@ -36,6 +36,15 @@ def activitycontextimpl(act, on_abort=None, on_commit=None):
activity_context
=
contextmanager
(
activitycontextimpl
)
activity_code_separator
=
'.'
def
join_activity_code
(
*
args
):
"""Join the specified parts into an activity code.
"""
return
activity_code_separator
.
join
(
args
)
class
ActivityModel
(
TimeStampedModel
):
activity_code
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'activity code'
))
parent
=
ForeignKey
(
'self'
,
blank
=
True
,
null
=
True
,
related_name
=
'children'
)
...
...
circle/vm/models/activity.py
View file @
e5a442ad
...
...
@@ -6,7 +6,11 @@ from django.db.models import CharField, ForeignKey
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
common.models
import
ActivityModel
,
activitycontextimpl
from
common.models
import
(
ActivityModel
,
activitycontextimpl
,
join_activity_code
,
)
logger
=
getLogger
(
__name__
)
...
...
@@ -23,6 +27,7 @@ class ActivityInProgressError(Exception):
class
InstanceActivity
(
ActivityModel
):
ACTIVITY_CODE_BASE
=
join_activity_code
(
'vm'
,
'Instance'
)
instance
=
ForeignKey
(
'Instance'
,
related_name
=
'activity_log'
,
help_text
=
_
(
'Instance this activity works on.'
),
verbose_name
=
_
(
'instance'
))
...
...
@@ -53,9 +58,10 @@ class InstanceActivity(ActivityModel):
if
concurrency_check
and
active_activities
.
exists
():
raise
ActivityInProgressError
(
active_activities
[
0
])
act
=
cls
(
activity_code
=
'vm.Instance.'
+
code_suffix
,
instance
=
instance
,
parent
=
None
,
resultant_state
=
None
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
user
)
activity_code
=
join_activity_code
(
cls
.
ACTIVITY_CODE_BASE
,
code_suffix
)
act
=
cls
(
activity_code
=
activity_code
,
instance
=
instance
,
parent
=
None
,
resultant_state
=
None
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
user
)
act
.
save
()
return
act
...
...
@@ -66,7 +72,7 @@ class InstanceActivity(ActivityModel):
raise
ActivityInProgressError
(
active_children
[
0
])
act
=
InstanceActivity
(
activity_code
=
self
.
activity_code
+
'.'
+
code_suffix
,
activity_code
=
join_activity_code
(
self
.
activity_code
,
code_suffix
)
,
instance
=
self
.
instance
,
parent
=
self
,
resultant_state
=
None
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
self
.
user
)
act
.
save
()
...
...
@@ -97,6 +103,7 @@ def instance_activity(code_suffix, instance, on_abort=None, on_commit=None,
class
NodeActivity
(
ActivityModel
):
ACTIVITY_CODE_BASE
=
join_activity_code
(
'vm'
,
'Node'
)
node
=
ForeignKey
(
'Node'
,
related_name
=
'activity_log'
,
help_text
=
_
(
'Node this activity works on.'
),
verbose_name
=
_
(
'node'
))
...
...
@@ -119,15 +126,15 @@ class NodeActivity(ActivityModel):
@classmethod
def
create
(
cls
,
code_suffix
,
node
,
task_uuid
=
None
,
user
=
None
):
act
=
cls
(
activity_code
=
'vm.Node.'
+
code_suffix
,
node
=
node
,
parent
=
None
,
started
=
timezone
.
now
()
,
task_uuid
=
task_uuid
,
user
=
user
)
act
ivity_code
=
join_activity_code
(
cls
.
ACTIVITY_CODE_BASE
,
code_suffix
)
act
=
cls
(
activity_code
=
activity_code
,
node
=
node
,
parent
=
None
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
user
)
act
.
save
()
return
act
def
create_sub
(
self
,
code_suffix
,
task_uuid
=
None
):
act
=
NodeActivity
(
activity_code
=
self
.
activity_code
+
'.'
+
code_suffix
,
activity_code
=
join_activity_code
(
self
.
activity_code
,
code_suffix
)
,
node
=
self
.
node
,
parent
=
self
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
self
.
user
)
act
.
save
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment