Skip to content

Commit dac63d0

Browse files
Worked on function for adding transaction and components of scheduler and session
1 parent 0ed1e02 commit dac63d0

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

cmd/laclm/main.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import (
1313
"github.com/MakeNowJust/heredoc"
1414
"github.com/joho/godotenv"
1515
"github.com/spf13/cobra"
16-
"go.uber.org/zap"
1716
"go.uber.org/automaxprocs/maxprocs"
17+
"go.uber.org/zap"
1818

1919
"github.com/PythonHacker24/linux-acl-management-backend/api/routes"
2020
"github.com/PythonHacker24/linux-acl-management-backend/config"
2121
"github.com/PythonHacker24/linux-acl-management-backend/internal/scheduler"
2222
"github.com/PythonHacker24/linux-acl-management-backend/internal/scheduler/fcfs"
2323
"github.com/PythonHacker24/linux-acl-management-backend/internal/session"
24+
"github.com/PythonHacker24/linux-acl-management-backend/internal/transprocessor"
2425
"github.com/PythonHacker24/linux-acl-management-backend/internal/utils"
2526
)
2627

@@ -119,19 +120,28 @@ func run(ctx context.Context) error {
119120
)
120121

121122
/* RULE: complete backend system must initiate before http server starts */
123+
124+
/* DATABASE CONNECTIONS MUST BE MADE BEFORE SCHEDULER STARTS */
122125

123126
/*
124127
initializing schedular
125128
scheduler uses context to quit - part of waitgroup
126129
propogates error through error channel
127130
*/
128131
errCh := make(chan error, 1)
132+
133+
/* create a session manager */
129134
sessionManager := session.NewManager()
130135

136+
/* create a permissions processor */
137+
permProcessor := transprocessor.NewPermProcessor()
138+
131139
/* currently FCFS scheduler */
132-
transSched := fcfs.NewFCFSScheduler(sessionManager)
140+
transSched := fcfs.NewFCFSScheduler(sessionManager, permProcessor)
141+
142+
/* initialize the scheduler */
133143
scheduler.InitSchedular(ctx, transSched, &wg, errCh)
134-
144+
135145
/* setting up http mux and routes */
136146
mux := http.NewServeMux()
137147

internal/auth/service.go

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal/session/manager.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,25 @@ func (m *Manager) ExpireSession(username string) {
7373
/* remove session from sessionsMap */
7474
delete(m.sessionsMap, username)
7575
}
76+
77+
/* add transaction to a session */
78+
func (m *Manager) AddTransaction(username string, txn interface{}) error {
79+
/* thread safety the manager mutex */
80+
m.mutex.Lock()
81+
defer m.mutex.Unlock()
82+
83+
/* get the session from sessions map with O(1) runtime */
84+
session, exists := m.sessionsMap[username]
85+
if !exists {
86+
return fmt.Errorf("Session not found")
87+
}
88+
89+
/* thread safety for the session */
90+
session.Mutex.Lock()
91+
defer session.Mutex.Unlock()
92+
93+
/* push transaction into the queue from back */
94+
session.TransactionQueue.PushBack(txn)
95+
96+
return nil
97+
}

internal/transprocessor/perm-processor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ func (p *PermProcessor) Process(ctx context.Context, curSession *session.Session
3636
)
3737
return ctx.Err()
3838
default:
39+
/*
40+
permprocessor hands over transactions to remoteprocessor/localprocessor depending upon request
41+
remoteprocessor -> handles permissions on remote servers
42+
localprocessor -> handles permissions on local system (where this backend is deployed)
43+
*/
3944
_ = transaction
4045
}
4146

0 commit comments

Comments
 (0)