Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
Hide 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):
...
@@ -36,6 +36,15 @@ def activitycontextimpl(act, on_abort=None, on_commit=None):
activity_context
=
contextmanager
(
activitycontextimpl
)
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
):
class
ActivityModel
(
TimeStampedModel
):
activity_code
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'activity code'
))
activity_code
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'activity code'
))
parent
=
ForeignKey
(
'self'
,
blank
=
True
,
null
=
True
,
related_name
=
'children'
)
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
...
@@ -6,7 +6,11 @@ from django.db.models import CharField, ForeignKey
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
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__
)
logger
=
getLogger
(
__name__
)
...
@@ -23,6 +27,7 @@ class ActivityInProgressError(Exception):
...
@@ -23,6 +27,7 @@ class ActivityInProgressError(Exception):
class
InstanceActivity
(
ActivityModel
):
class
InstanceActivity
(
ActivityModel
):
ACTIVITY_CODE_BASE
=
join_activity_code
(
'vm'
,
'Instance'
)
instance
=
ForeignKey
(
'Instance'
,
related_name
=
'activity_log'
,
instance
=
ForeignKey
(
'Instance'
,
related_name
=
'activity_log'
,
help_text
=
_
(
'Instance this activity works on.'
),
help_text
=
_
(
'Instance this activity works on.'
),
verbose_name
=
_
(
'instance'
))
verbose_name
=
_
(
'instance'
))
...
@@ -53,9 +58,10 @@ class InstanceActivity(ActivityModel):
...
@@ -53,9 +58,10 @@ class InstanceActivity(ActivityModel):
if
concurrency_check
and
active_activities
.
exists
():
if
concurrency_check
and
active_activities
.
exists
():
raise
ActivityInProgressError
(
active_activities
[
0
])
raise
ActivityInProgressError
(
active_activities
[
0
])
act
=
cls
(
activity_code
=
'vm.Instance.'
+
code_suffix
,
activity_code
=
join_activity_code
(
cls
.
ACTIVITY_CODE_BASE
,
code_suffix
)
instance
=
instance
,
parent
=
None
,
resultant_state
=
None
,
act
=
cls
(
activity_code
=
activity_code
,
instance
=
instance
,
parent
=
None
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
user
)
resultant_state
=
None
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
user
)
act
.
save
()
act
.
save
()
return
act
return
act
...
@@ -66,7 +72,7 @@ class InstanceActivity(ActivityModel):
...
@@ -66,7 +72,7 @@ class InstanceActivity(ActivityModel):
raise
ActivityInProgressError
(
active_children
[
0
])
raise
ActivityInProgressError
(
active_children
[
0
])
act
=
InstanceActivity
(
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
,
instance
=
self
.
instance
,
parent
=
self
,
resultant_state
=
None
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
self
.
user
)
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
self
.
user
)
act
.
save
()
act
.
save
()
...
@@ -97,6 +103,7 @@ def instance_activity(code_suffix, instance, on_abort=None, on_commit=None,
...
@@ -97,6 +103,7 @@ def instance_activity(code_suffix, instance, on_abort=None, on_commit=None,
class
NodeActivity
(
ActivityModel
):
class
NodeActivity
(
ActivityModel
):
ACTIVITY_CODE_BASE
=
join_activity_code
(
'vm'
,
'Node'
)
node
=
ForeignKey
(
'Node'
,
related_name
=
'activity_log'
,
node
=
ForeignKey
(
'Node'
,
related_name
=
'activity_log'
,
help_text
=
_
(
'Node this activity works on.'
),
help_text
=
_
(
'Node this activity works on.'
),
verbose_name
=
_
(
'node'
))
verbose_name
=
_
(
'node'
))
...
@@ -119,15 +126,15 @@ class NodeActivity(ActivityModel):
...
@@ -119,15 +126,15 @@ class NodeActivity(ActivityModel):
@classmethod
@classmethod
def
create
(
cls
,
code_suffix
,
node
,
task_uuid
=
None
,
user
=
None
):
def
create
(
cls
,
code_suffix
,
node
,
task_uuid
=
None
,
user
=
None
):
act
=
cls
(
activity_code
=
'vm.Node.'
+
code_suffix
,
act
ivity_code
=
join_activity_code
(
cls
.
ACTIVITY_CODE_BASE
,
code_suffix
)
node
=
node
,
parent
=
None
,
started
=
timezone
.
now
()
,
act
=
cls
(
activity_code
=
activity_code
,
node
=
node
,
parent
=
None
,
task_uuid
=
task_uuid
,
user
=
user
)
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
user
)
act
.
save
()
act
.
save
()
return
act
return
act
def
create_sub
(
self
,
code_suffix
,
task_uuid
=
None
):
def
create_sub
(
self
,
code_suffix
,
task_uuid
=
None
):
act
=
NodeActivity
(
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
(),
node
=
self
.
node
,
parent
=
self
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
self
.
user
)
task_uuid
=
task_uuid
,
user
=
self
.
user
)
act
.
save
()
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