-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
623 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.