Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vmine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pipelines
tools
vmine
Commits
d1a79e49
Commit
d1a79e49
authored
3 weeks ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Split buildGroupFromRequest() for readability
parent
44d2d719
No related branches found
No related tags found
1 merge request
!20
Refactor the Engine with stronger guarantees
Pipeline
#88166
passed
3 weeks ago
Stage: test
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
engine.go
+27
-9
27 additions, 9 deletions
engine.go
with
27 additions
and
9 deletions
engine.go
+
27
−
9
View file @
d1a79e49
...
...
@@ -179,11 +179,9 @@ func (e *Engine) CreateGroup(req *CreateGroupRequest) (*CreateGroupResponse, err
}
gctx
:=
newGroupContext
(
ttl
)
tx
:=
newTX
()
// Populate the groupContext with the final Group object, and
// register it while we're still holding the lock.
err
:=
e
.
buildGroupFromRequest
(
gctx
,
tx
,
req
)
tx
,
err
:=
e
.
createAndBuildGroup
(
gc
tx
,
req
)
if
err
==
nil
{
if
_
,
ok
:=
e
.
groups
[
gctx
.
group
.
ID
];
ok
{
err
=
errors
.
New
(
"group already exists"
)
...
...
@@ -211,13 +209,24 @@ func (e *Engine) CreateGroup(req *CreateGroupRequest) (*CreateGroupResponse, err
},
nil
}
func
(
e
*
Engine
)
buildGroupFromRequest
(
gctx
*
groupContext
,
tx
Transaction
,
req
*
CreateGroupRequest
)
error
{
// Create a new Group from the CreateGroupRequest, and prepare its
// environment in a new Transaction.
func
(
e
*
Engine
)
createAndBuildGroup
(
gctx
*
groupContext
,
req
*
CreateGroupRequest
)
(
Transaction
,
error
)
{
if
err
:=
e
.
newGroupFromRequest
(
gctx
,
req
);
err
!=
nil
{
return
nil
,
err
}
return
e
.
buildTransaction
(
gctx
)
}
// Build a Group from a CreateGroupRequest.
func
(
e
*
Engine
)
newGroupFromRequest
(
gctx
*
groupContext
,
req
*
CreateGroupRequest
)
error
{
req
,
err
:=
fillCreateGroupRequest
(
gctx
,
req
,
e
.
subnets
)
if
err
!=
nil
{
return
err
}
// Create the group.
// Create the group
and attach it to the groupContext
.
group
,
err
:=
newGroup
(
req
,
e
.
registry
)
if
err
!=
nil
{
return
err
...
...
@@ -229,8 +238,7 @@ func (e *Engine) buildGroupFromRequest(gctx *groupContext, tx Transaction, req *
return
err
}
// Checking if the memory is available and agreeing to start
// the group should both happen while the lock is held.
// Allocate memory, if we're keeping track of it.
if
e
.
memory
!=
nil
{
ram
:=
group
.
ram
()
if
!
e
.
memory
.
Acquire
(
ram
)
{
...
...
@@ -241,10 +249,20 @@ func (e *Engine) buildGroupFromRequest(gctx *groupContext, tx Transaction, req *
})
}
// Build the group resources and set up the transaction.
return
group
.
BuildWithProviders
(
tx
,
e
.
net
,
e
.
vm
)
return
nil
}
// Setup the group resources by attaching them to a new Transaction.
func
(
e
*
Engine
)
buildTransaction
(
gctx
*
groupContext
)
(
Transaction
,
error
)
{
tx
:=
newTX
()
err
:=
gctx
.
group
.
BuildWithProviders
(
tx
,
e
.
net
,
e
.
vm
)
return
tx
,
err
}
// Fill in missing values in the CreateGroupRequest, possibly by
// allocating shared resources such as subnets, IP addresses, etc.
func
fillCreateGroupRequest
(
gctx
*
groupContext
,
req
*
CreateGroupRequest
,
netAlloc
*
allocator
.
SubnetAllocator
)
(
*
CreateGroupRequest
,
error
)
{
var
ipnet
*
net
.
IPNet
var
err
error
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment