Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #71

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
72e0118
start refactor
zyxkad Jun 11, 2024
e081599
refactoring cluster
zyxkad Jun 18, 2024
5e89ede
add socket logic
zyxkad Jun 20, 2024
103c480
migrated more cluster
zyxkad Jun 26, 2024
451a665
abstract subscription, token, and user api
zyxkad Jun 27, 2024
8cbd7c5
fix wrong jwt subject usage
zyxkad Jun 27, 2024
e17d8c7
fix format
zyxkad Jun 27, 2024
f2dbcbf
add permHandler
zyxkad Jun 28, 2024
b7b6cc6
complete api
zyxkad Jun 29, 2024
a498e11
go fmt
zyxkad Jul 1, 2024
0ab1240
Merge branch 'master' into refactor
zyxkad Aug 6, 2024
10eee06
update dockerfile
zyxkad Aug 6, 2024
8dca5cb
seperate config
zyxkad Aug 8, 2024
9d44901
fix notifier error
zyxkad Aug 8, 2024
caae4f7
add webhook
zyxkad Aug 8, 2024
74c811d
add license header to installer.sh
zyxkad Aug 9, 2024
18ee907
update cluster handler
zyxkad Aug 10, 2024
4fe7a79
start to reforge storage sync
zyxkad Aug 11, 2024
3c20fd8
run go fmt
zyxkad Aug 11, 2024
173aced
refactored most stuffs
zyxkad Aug 11, 2024
650b0c3
refactored all errors
zyxkad Aug 12, 2024
1d399d9
add gc
zyxkad Aug 13, 2024
e723847
fix certificate request logic
zyxkad Aug 13, 2024
5465766
add report API
zyxkad Aug 14, 2024
16e9db4
seperate runner
zyxkad Aug 17, 2024
88b902b
refactor file download
zyxkad Aug 17, 2024
8cf633b
fill more manager
zyxkad Aug 17, 2024
f2a883d
implemented singleUserManager
zyxkad Aug 17, 2024
a09e758
run go fmt
zyxkad Aug 17, 2024
29265d0
bump go version to 1.23
zyxkad Aug 17, 2024
d436d88
use report API
zyxkad Aug 17, 2024
8698d11
fix nil pointer config
zyxkad Aug 17, 2024
774a388
fix typo
zyxkad Aug 17, 2024
9308d58
fix http client
zyxkad Aug 17, 2024
0ec5189
fix report API, and a few translations
zyxkad Aug 18, 2024
07bf29d
fix unused import
zyxkad Aug 18, 2024
62c50ae
update config
zyxkad Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
start refactor
zyxkad committed Jun 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 72e01184ca81bd0e64e81d2b45effaf9cf1d80e4
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# syntax=docker/dockerfile:1
# Copyright (C) 2023 Kevin Z <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

ARG GO_VERSION=1.21
ARG REPO=github.com/LiterMC/go-openbmclapi
File renamed without changes.
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* OpenBmclAPI (Golang Edition)
* Copyright (C) 2024 Kevin Z <[email protected]>
* All rights reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cluster

import (
"context"
"sync/atomic"
)

type Cluster struct {
id string
secret string
host string
port uint16

storageManager *storage.Manager
storages []int // the index of storages in the storage manager

status atomic.Int32
}

// ID returns the cluster id
func (cr *Cluster) ID() string {
return cr.id
}

// Host returns the cluster public host
func (cr *Cluster) Host() string {
return cr.host
}

// Port returns the cluster public port
func (cr *Cluster) Port() string {
return cr.port
}

// Init do setup on the cluster
// Init should only be called once during the cluster's whole life
// The context passed in only affect the logical of Init method
func (cr *Cluster) Init(ctx context.Context) error {
return
}

// Enable send enable packet to central server
// The context passed in only affect the logical of Enable method
func (cr *Cluster) Enable(ctx context.Context) error {
return
}

// Disable send disable packet to central server
// The context passed in only affect the logical of Disable method
func (cr *Cluster) Disable(ctx context.Context) error {
return
}

// setDisabled marked the cluster as disabled or kicked
func (cr *Cluster) setDisabled(kicked bool) {
return
}
20 changes: 20 additions & 0 deletions cluster/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* OpenBmclAPI (Golang Edition)
* Copyright (C) 2024 Kevin Z <[email protected]>
* All rights reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cluster
45 changes: 45 additions & 0 deletions cluster/keepalive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* OpenBmclAPI (Golang Edition)
* Copyright (C) 2024 Kevin Z <[email protected]>
* All rights reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cluster

import (
"context"
)

type KeepAliveRes int

// Succeed returns true when KeepAlive actions is succeed as well as the cluster is not kicked by the controller
func (r KeepAliveRes) Succeed() bool {
return r == 0
}

// Failed returns true when KeepAlive action is succeed but the cluster is forced kick by the controller
func (r KeepAliveRes) Kicked() bool {
return r == 1
}

// Failed returns true when KeepAlive is interrupted by unexpected reason
func (r KeepAliveRes) Failed() bool {
return r == 2
}

func (cr *Cluster) KeepAlive(ctx context.Context) KeepAliveRes {
//
}
61 changes: 61 additions & 0 deletions cluster/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* OpenBmclAPI (Golang Edition)
* Copyright (C) 2024 Kevin Z <[email protected]>
* All rights reserved
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cluster

const (
clusterDisabled = 0
clusterEnabled = 1
clusterEnabling = 2
clusterKicked = 4
)

// Enabled returns true if the cluster is enabled or enabling
func (cr *Cluster) Enabled() bool {
s := cr.status.Load()
return s == clusterEnabled || s == clusterEnabling
}

// Running returns true if the cluster is completely enabled
func (cr *Cluster) Running() bool {
return cr.status.Load() == clusterEnabled
}

// Disabled returns true if the cluster is disabled manually
func (cr *Cluster) Disabled() bool {
return cr.status.Load() == clusterDisabled
}

// IsKicked returns true if the cluster is kicked by the central server
func (cr *Cluster) IsKicked() bool {
return cr.status.Load() == clusterKicked
}

// WaitForEnable returns a channel which receives true when cluster enabled succeed, or receives false when it failed to enable
// If the cluster is already enable, the channel always returns true
// The channel should not be used multiple times
func (cr *Cluster) WaitForEnable() <-chan bool {
ch := make(chan bool, 1)
if cr.Running() {
ch <- true
} else {
cr.enableSignals = append(cr.enableSignals, ch)
}
return ch
}
2 changes: 0 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
@@ -360,8 +360,6 @@ var emptyHashes = func() (hashes map[string]struct{}) {
return
}()

var HeaderXPoweredBy = fmt.Sprintf("go-openbmclapi/%s; url=https://github.com/LiterMC/go-openbmclapi", build.BuildVersion)

//go:embed robots.txt
var robotTxtContent string

Loading