Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
3d4d8225
Commit
3d4d8225
authored
Jul 21, 2015
by
woodsaj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement updateQuota function
parent
c2381308
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
1 deletions
+41
-1
pkg/api/quota.go
+5
-0
pkg/models/quotas.go
+11
-0
pkg/services/sqlstore/quota.go
+25
-1
No files found.
pkg/api/quota.go
View file @
3d4d8225
...
...
@@ -19,6 +19,11 @@ func GetOrgQuotas(c *middleware.Context) Response {
func
UpdateOrgQuota
(
c
*
middleware
.
Context
,
cmd
m
.
UpdateQuotaCmd
)
Response
{
cmd
.
OrgId
=
c
.
ParamsInt64
(
":orgId"
)
cmd
.
Target
=
m
.
QuotaTarget
(
c
.
Params
(
":target"
))
if
!
cmd
.
Target
.
IsValid
()
{
return
ApiError
(
404
,
"Invalid quota target"
,
nil
)
}
if
err
:=
bus
.
Dispatch
(
&
cmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to update org quotas"
,
err
)
}
...
...
pkg/models/quotas.go
View file @
3d4d8225
package
models
import
(
"errors"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/setting"
"time"
...
...
@@ -16,6 +17,13 @@ const (
QUOTA_COLLECTOR
QuotaTarget
=
"collector"
)
var
ErrInvalidQuotaTarget
=
errors
.
New
(
"Invalid quota target"
)
func
(
q
QuotaTarget
)
IsValid
()
bool
{
_
,
ok
:=
DefaultQuotas
[
q
]
return
ok
}
// defaults are set from settings package.
var
DefaultQuotas
map
[
QuotaTarget
]
int64
...
...
@@ -64,6 +72,9 @@ type UpdateQuotaCmd struct {
}
func
QuotaReached
(
org_id
int64
,
target
QuotaTarget
)
(
bool
,
error
)
{
if
!
target
.
IsValid
()
{
return
true
,
ErrInvalidQuotaTarget
}
query
:=
GetQuotaByTargetQuery
{
OrgId
:
org_id
,
Target
:
target
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
true
,
err
...
...
pkg/services/sqlstore/quota.go
View file @
3d4d8225
...
...
@@ -86,5 +86,29 @@ func GetQuotas(query *m.GetQuotasQuery) error {
}
func
UpdateQuota
(
cmd
*
m
.
UpdateQuotaCmd
)
error
{
return
nil
return
inTransaction2
(
func
(
sess
*
session
)
error
{
//Check if quota is already defined in the DB
quota
:=
m
.
Quota
{
Target
:
cmd
.
Target
,
OrgId
:
cmd
.
OrgId
,
}
has
,
err
:=
sess
.
Get
(
quota
)
if
err
!=
nil
{
return
err
}
quota
.
Limit
=
cmd
.
Limit
if
has
==
false
{
//No quota in the DB for this target, so create a new one.
if
_
,
err
:=
sess
.
Insert
(
&
quota
);
err
!=
nil
{
return
err
}
}
else
{
//update existing quota entry in the DB.
if
_
,
err
:=
sess
.
Id
(
quota
.
Id
)
.
Update
(
&
quota
);
err
!=
nil
{
return
err
}
}
return
nil
})
}
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