Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
82e7286d
Commit
82e7286d
authored
7 years ago
by
Christian Pointner
Browse files
Options
Downloads
Patches
Plain Diff
import session id is now of type uint64
parent
08c5e5ac
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
importer/session_store.go
+25
-35
25 additions, 35 deletions
importer/session_store.go
with
25 additions
and
35 deletions
importer/session_store.go
+
25
−
35
View file @
82e7286d
...
@@ -25,17 +25,16 @@
...
@@ -25,17 +25,16 @@
package
importer
package
importer
import
(
import
(
"crypto/rand"
"encoding/base64"
"fmt"
"fmt"
"log"
"log"
"math/rand"
"net/http"
"net/http"
"strings"
"strings"
"time"
"time"
)
)
type
newSessionResponse
struct
{
type
newSessionResponse
struct
{
id
string
id
uint64
session
*
Session
session
*
Session
responsecode
int
responsecode
int
errorstring
string
errorstring
string
...
@@ -56,11 +55,11 @@ type getSessionResponse struct {
...
@@ -56,11 +55,11 @@ type getSessionResponse struct {
type
getSessionRequest
struct
{
type
getSessionRequest
struct
{
group
string
group
string
id
string
id
uint64
response
chan
getSessionResponse
response
chan
getSessionResponse
}
}
type
SessionsUpdateCB
func
(
added
,
removed
map
[
string
]
string
,
userdata
interface
{})
bool
type
SessionsUpdateCB
func
(
added
,
removed
map
[
uint64
]
string
,
userdata
interface
{})
bool
type
SessionsListCB
struct
{
type
SessionsListCB
struct
{
cb
SessionsUpdateCB
cb
SessionsUpdateCB
...
@@ -68,7 +67,7 @@ type SessionsListCB struct {
...
@@ -68,7 +67,7 @@ type SessionsListCB struct {
}
}
type
listSessionsResponse
struct
{
type
listSessionsResponse
struct
{
sessions
map
[
string
]
string
sessions
map
[
uint64
]
string
responsecode
int
responsecode
int
errorstring
string
errorstring
string
}
}
...
@@ -87,7 +86,7 @@ type removeSessionResponse struct {
...
@@ -87,7 +86,7 @@ type removeSessionResponse struct {
type
removeSessionRequest
struct
{
type
removeSessionRequest
struct
{
group
string
group
string
id
string
id
uint64
response
chan
removeSessionResponse
response
chan
removeSessionResponse
}
}
...
@@ -97,11 +96,11 @@ type sessionStoreSessionElement struct {
...
@@ -97,11 +96,11 @@ type sessionStoreSessionElement struct {
}
}
type
sessionStoreGroupElement
struct
{
type
sessionStoreGroupElement
struct
{
sessions
map
[
string
]
*
sessionStoreSessionElement
sessions
map
[
uint64
]
*
sessionStoreSessionElement
updateCBs
[]
SessionsListCB
updateCBs
[]
SessionsListCB
}
}
func
(
group
*
sessionStoreGroupElement
)
callUpdateHandler
(
added
,
removed
map
[
string
]
string
)
{
func
(
group
*
sessionStoreGroupElement
)
callUpdateHandler
(
added
,
removed
map
[
uint64
]
string
)
{
var
keptCBs
[]
SessionsListCB
var
keptCBs
[]
SessionsListCB
for
_
,
cb
:=
range
group
.
updateCBs
{
for
_
,
cb
:=
range
group
.
updateCBs
{
if
cb
.
cb
!=
nil
{
if
cb
.
cb
!=
nil
{
...
@@ -113,14 +112,14 @@ func (group *sessionStoreGroupElement) callUpdateHandler(added, removed map[stri
...
@@ -113,14 +112,14 @@ func (group *sessionStoreGroupElement) callUpdateHandler(added, removed map[stri
group
.
updateCBs
=
keptCBs
group
.
updateCBs
=
keptCBs
}
}
func
(
group
*
sessionStoreGroupElement
)
callUpdateHandlerAdd
(
id
,
refId
string
)
{
func
(
group
*
sessionStoreGroupElement
)
callUpdateHandlerAdd
(
id
uint64
,
refId
string
)
{
added
:=
make
(
map
[
string
]
string
)
added
:=
make
(
map
[
uint64
]
string
)
added
[
id
]
=
refId
added
[
id
]
=
refId
group
.
callUpdateHandler
(
added
,
nil
)
group
.
callUpdateHandler
(
added
,
nil
)
}
}
func
(
group
*
sessionStoreGroupElement
)
callUpdateHandlerRemove
(
id
,
refId
string
)
{
func
(
group
*
sessionStoreGroupElement
)
callUpdateHandlerRemove
(
id
uint64
,
refId
string
)
{
removed
:=
make
(
map
[
string
]
string
)
removed
:=
make
(
map
[
uint64
]
string
)
removed
[
id
]
=
refId
removed
[
id
]
=
refId
group
.
callUpdateHandler
(
nil
,
removed
)
group
.
callUpdateHandler
(
nil
,
removed
)
}
}
...
@@ -140,28 +139,19 @@ type SessionStore struct {
...
@@ -140,28 +139,19 @@ type SessionStore struct {
workerChan
chan
<-
workerRequest
workerChan
chan
<-
workerRequest
}
}
func
generateSessionId
()
(
string
,
error
)
{
func
generateSessionId
()
uint64
{
var
b
[
32
]
byte
// TODO: get this from store import object
if
_
,
err
:=
rand
.
Read
(
b
[
:
]);
err
!=
nil
{
return
uint64
(
rand
.
Int63
())
return
""
,
err
}
return
base64
.
RawURLEncoding
.
EncodeToString
(
b
[
:
]),
nil
}
}
func
(
store
*
SessionStore
)
new
(
ctx
*
ImportContext
,
refId
string
)
(
resp
newSessionResponse
)
{
func
(
store
*
SessionStore
)
new
(
ctx
*
ImportContext
,
refId
string
)
(
resp
newSessionResponse
)
{
resp
.
responsecode
=
http
.
StatusOK
resp
.
responsecode
=
http
.
StatusOK
resp
.
errorstring
=
"OK"
resp
.
errorstring
=
"OK"
id
,
err
:=
generateSessionId
()
if
err
!=
nil
{
resp
.
responsecode
=
http
.
StatusInternalServerError
resp
.
errorstring
=
err
.
Error
()
return
}
resp
.
id
=
id
resp
.
id
=
generateSessionId
()
if
_
,
exists
:=
store
.
store
[
ctx
.
GroupName
];
!
exists
{
if
_
,
exists
:=
store
.
store
[
ctx
.
GroupName
];
!
exists
{
newgroup
:=
&
sessionStoreGroupElement
{}
newgroup
:=
&
sessionStoreGroupElement
{}
newgroup
.
sessions
=
make
(
map
[
string
]
*
sessionStoreSessionElement
)
newgroup
.
sessions
=
make
(
map
[
uint64
]
*
sessionStoreSessionElement
)
store
.
store
[
ctx
.
GroupName
]
=
newgroup
store
.
store
[
ctx
.
GroupName
]
=
newgroup
}
}
ctx
.
conf
=
store
.
conf
ctx
.
conf
=
store
.
conf
...
@@ -188,7 +178,7 @@ func (store *SessionStore) new(ctx *ImportContext, refId string) (resp newSessio
...
@@ -188,7 +178,7 @@ func (store *SessionStore) new(ctx *ImportContext, refId string) (resp newSessio
return
return
}
}
func
(
store
*
SessionStore
)
get
(
groupname
,
id
string
)
(
resp
getSessionResponse
)
{
func
(
store
*
SessionStore
)
get
(
groupname
string
,
id
uint64
)
(
resp
getSessionResponse
)
{
resp
.
responsecode
=
http
.
StatusOK
resp
.
responsecode
=
http
.
StatusOK
resp
.
errorstring
=
"OK"
resp
.
errorstring
=
"OK"
...
@@ -212,7 +202,7 @@ func (store *SessionStore) get(groupname, id string) (resp getSessionResponse) {
...
@@ -212,7 +202,7 @@ func (store *SessionStore) get(groupname, id string) (resp getSessionResponse) {
func
(
store
*
SessionStore
)
list
(
groupname
string
,
userdata
interface
{},
cb
SessionsUpdateCB
)
(
resp
listSessionsResponse
)
{
func
(
store
*
SessionStore
)
list
(
groupname
string
,
userdata
interface
{},
cb
SessionsUpdateCB
)
(
resp
listSessionsResponse
)
{
resp
.
responsecode
=
http
.
StatusOK
resp
.
responsecode
=
http
.
StatusOK
resp
.
errorstring
=
"OK"
resp
.
errorstring
=
"OK"
resp
.
sessions
=
make
(
map
[
string
]
string
)
resp
.
sessions
=
make
(
map
[
uint64
]
string
)
if
group
,
exists
:=
store
.
store
[
groupname
];
exists
{
if
group
,
exists
:=
store
.
store
[
groupname
];
exists
{
for
id
,
e
:=
range
group
.
sessions
{
for
id
,
e
:=
range
group
.
sessions
{
resp
.
sessions
[
id
]
=
e
.
refId
resp
.
sessions
[
id
]
=
e
.
refId
...
@@ -222,14 +212,14 @@ func (store *SessionStore) list(groupname string, userdata interface{}, cb Sessi
...
@@ -222,14 +212,14 @@ func (store *SessionStore) list(groupname string, userdata interface{}, cb Sessi
}
}
}
else
if
cb
!=
nil
{
}
else
if
cb
!=
nil
{
newgroup
:=
&
sessionStoreGroupElement
{}
newgroup
:=
&
sessionStoreGroupElement
{}
newgroup
.
sessions
=
make
(
map
[
string
]
*
sessionStoreSessionElement
)
newgroup
.
sessions
=
make
(
map
[
uint64
]
*
sessionStoreSessionElement
)
newgroup
.
updateCBs
=
[]
SessionsListCB
{
SessionsListCB
{
cb
,
userdata
}}
newgroup
.
updateCBs
=
[]
SessionsListCB
{
SessionsListCB
{
cb
,
userdata
}}
store
.
store
[
groupname
]
=
newgroup
store
.
store
[
groupname
]
=
newgroup
}
}
return
return
}
}
func
(
store
*
SessionStore
)
remove
(
groupname
,
id
string
)
(
resp
removeSessionResponse
)
{
func
(
store
*
SessionStore
)
remove
(
groupname
string
,
id
uint64
)
(
resp
removeSessionResponse
)
{
resp
.
responsecode
=
http
.
StatusOK
resp
.
responsecode
=
http
.
StatusOK
resp
.
errorstring
=
"OK"
resp
.
errorstring
=
"OK"
...
@@ -295,7 +285,7 @@ func (store *SessionStore) dispatchRequests() {
...
@@ -295,7 +285,7 @@ func (store *SessionStore) dispatchRequests() {
// *********************************************************
// *********************************************************
// Public Interface
// Public Interface
func
(
store
*
SessionStore
)
New
(
ctx
*
ImportContext
,
refId
string
)
(
string
,
*
Session
,
int
,
string
)
{
func
(
store
*
SessionStore
)
New
(
ctx
*
ImportContext
,
refId
string
)
(
uint64
,
*
Session
,
int
,
string
)
{
resCh
:=
make
(
chan
newSessionResponse
)
resCh
:=
make
(
chan
newSessionResponse
)
req
:=
newSessionRequest
{}
req
:=
newSessionRequest
{}
req
.
ctx
=
ctx
req
.
ctx
=
ctx
...
@@ -307,7 +297,7 @@ func (store *SessionStore) New(ctx *ImportContext, refId string) (string, *Sessi
...
@@ -307,7 +297,7 @@ func (store *SessionStore) New(ctx *ImportContext, refId string) (string, *Sessi
return
res
.
id
,
res
.
session
,
res
.
responsecode
,
res
.
errorstring
return
res
.
id
,
res
.
session
,
res
.
responsecode
,
res
.
errorstring
}
}
func
(
store
*
SessionStore
)
Get
(
group
,
id
string
)
(
*
Session
,
string
,
int
,
string
)
{
func
(
store
*
SessionStore
)
Get
(
group
string
,
id
uint64
)
(
*
Session
,
string
,
int
,
string
)
{
resCh
:=
make
(
chan
getSessionResponse
)
resCh
:=
make
(
chan
getSessionResponse
)
req
:=
getSessionRequest
{}
req
:=
getSessionRequest
{}
req
.
group
=
group
req
.
group
=
group
...
@@ -319,7 +309,7 @@ func (store *SessionStore) Get(group, id string) (*Session, string, int, string)
...
@@ -319,7 +309,7 @@ func (store *SessionStore) Get(group, id string) (*Session, string, int, string)
return
res
.
session
,
res
.
refId
,
res
.
responsecode
,
res
.
errorstring
return
res
.
session
,
res
.
refId
,
res
.
responsecode
,
res
.
errorstring
}
}
func
(
store
*
SessionStore
)
List
(
group
string
,
userdata
interface
{},
cb
SessionsUpdateCB
)
(
map
[
string
]
string
,
int
,
string
)
{
func
(
store
*
SessionStore
)
List
(
group
string
,
userdata
interface
{},
cb
SessionsUpdateCB
)
(
map
[
uint64
]
string
,
int
,
string
)
{
resCh
:=
make
(
chan
listSessionsResponse
)
resCh
:=
make
(
chan
listSessionsResponse
)
req
:=
listSessionsRequest
{}
req
:=
listSessionsRequest
{}
req
.
group
=
group
req
.
group
=
group
...
@@ -332,7 +322,7 @@ func (store *SessionStore) List(group string, userdata interface{}, cb SessionsU
...
@@ -332,7 +322,7 @@ func (store *SessionStore) List(group string, userdata interface{}, cb SessionsU
return
res
.
sessions
,
res
.
responsecode
,
res
.
errorstring
return
res
.
sessions
,
res
.
responsecode
,
res
.
errorstring
}
}
func
(
store
*
SessionStore
)
Remove
(
group
,
id
string
)
(
int
,
string
)
{
func
(
store
*
SessionStore
)
Remove
(
group
string
,
id
uint64
)
(
int
,
string
)
{
resCh
:=
make
(
chan
removeSessionResponse
)
resCh
:=
make
(
chan
removeSessionResponse
)
req
:=
removeSessionRequest
{}
req
:=
removeSessionRequest
{}
req
.
group
=
group
req
.
group
=
group
...
...
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