Skip to content

Commit

Permalink
Update all of the old UUID refs to new
Browse files Browse the repository at this point in the history
  • Loading branch information
DaneEveritt committed Jul 20, 2020
1 parent 5079c67 commit cb850fd
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func rootCmdRun(*cobra.Command, []string) {

// Just for some nice log output.
for _, s := range server.GetServers().All() {
log.WithField("server", s.Uuid).Info("loaded configuration for server")
log.WithField("server", s.Id()).Info("loaded configuration for server")
}

// Create a new WaitGroup that limits us to 4 servers being bootstrapped at a time
Expand Down
2 changes: 1 addition & 1 deletion installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func New(data []byte) (*Installer, error) {

// Returns the UUID associated with this installer instance.
func (i *Installer) Uuid() string {
return i.server.Uuid
return i.server.Id()
}

// Return the server instance.
Expand Down
2 changes: 1 addition & 1 deletion router/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func AuthorizationMiddleware(c *gin.Context) {
// Helper function to fetch a server out of the servers collection stored in memory.
func GetServer(uuid string) *server.Server {
return server.GetServers().Find(func(s *server.Server) bool {
return uuid == s.Uuid
return uuid == s.Id()
})
}

Expand Down
4 changes: 2 additions & 2 deletions router/router_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ func deleteServer(c *gin.Context) {
}
}(s.Filesystem.Path())

var uuid = s.Uuid
var uuid = s.Id()
server.GetServers().Remove(func(s2 *server.Server) bool {
return s2.Uuid == uuid
return s2.Id() == uuid
})

// Deallocate the reference to this server.
Expand Down
12 changes: 6 additions & 6 deletions router/router_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,33 @@ func postServerArchive(c *gin.Context) {
start := time.Now()

if err := server.Archiver.Archive(); err != nil {
zap.S().Errorw("failed to get archive for server", zap.String("server", s.Uuid), zap.Error(err))
zap.S().Errorw("failed to get archive for server", zap.String("server", server.Id()), zap.Error(err))
return
}

zap.S().Debugw(
"successfully created archive for server",
zap.String("server", server.Uuid),
zap.String("server", server.Id()),
zap.Duration("time", time.Now().Sub(start).Round(time.Microsecond)),
)

r := api.NewRequester()
rerr, err := r.SendArchiveStatus(server.Uuid, true)
rerr, err := r.SendArchiveStatus(server.Id(), true)
if rerr != nil || err != nil {
if err != nil {
zap.S().Errorw("failed to notify panel with archive status", zap.String("server", server.Uuid), zap.Error(err))
zap.S().Errorw("failed to notify panel with archive status", zap.String("server", server.Id()), zap.Error(err))
return
}

zap.S().Errorw(
"panel returned an error when sending the archive status",
zap.String("server", server.Uuid),
zap.String("server", server.Id()),
zap.Error(errors.New(rerr.String())),
)
return
}

zap.S().Debugw("successfully notified panel about archive status", zap.String("server", server.Uuid))
zap.S().Debugw("successfully notified panel about archive status", zap.String("server", server.Id()))
}(s)

c.Status(http.StatusAccepted)
Expand Down
2 changes: 1 addition & 1 deletion server/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (a *Archiver) ArchivePath() string {

// ArchiveName returns the name of the server's archive.
func (a *Archiver) ArchiveName() string {
return a.Server.Uuid + ".tar.gz"
return a.Server.Id() + ".tar.gz"
}

// Exists returns a boolean based off if the archive exists.
Expand Down
14 changes: 7 additions & 7 deletions server/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *Server) Reinstall() error {

// Internal installation function used to simplify reporting back to the Panel.
func (s *Server) internalInstall() error {
script, rerr, err := api.NewRequester().GetInstallationScript(s.Uuid)
script, rerr, err := api.NewRequester().GetInstallationScript(s.Id())
if err != nil || rerr != nil {
if err != nil {
return err
Expand Down Expand Up @@ -170,7 +170,7 @@ func (s *Server) AbortInstallation() {

// Removes the installer container for the server.
func (ip *InstallationProcess) RemoveContainer() {
err := ip.client.ContainerRemove(ip.context, ip.Server.Uuid+"_installer", types.ContainerRemoveOptions{
err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", types.ContainerRemoveOptions{
RemoveVolumes: true,
Force: true,
})
Expand Down Expand Up @@ -313,7 +313,7 @@ func (ip *InstallationProcess) BeforeExecute() (string, error) {
Force: true,
}

if err := ip.client.ContainerRemove(ip.context, ip.Server.Uuid+"_installer", opts); err != nil {
if err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", opts); err != nil {
if !client.IsErrNotFound(err) {
e = append(e, err)
}
Expand All @@ -333,7 +333,7 @@ func (ip *InstallationProcess) BeforeExecute() (string, error) {

// Returns the log path for the installation process.
func (ip *InstallationProcess) GetLogPath() string {
return filepath.Join(config.Get().System.GetInstallLogPath(), ip.Server.Uuid+".log")
return filepath.Join(config.Get().System.GetInstallLogPath(), ip.Server.Id()+".log")
}

// Cleans up after the execution of the installation process. This grabs the logs from the
Expand Down Expand Up @@ -369,7 +369,7 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
|
| Details
| ------------------------------
Server UUID: {{.Server.Uuid}}
Server UUID: {{.Server.Id()}}
Container Image: {{.Script.ContainerImage}}
Container Entrypoint: {{.Script.Entrypoint}}
Expand Down Expand Up @@ -448,7 +448,7 @@ func (ip *InstallationProcess) Execute(installPath string) (string, error) {
}

ip.Server.Log().WithField("install_script", installPath+"/install.sh").Info("creating install container for server process")
r, err := ip.client.ContainerCreate(ip.context, conf, hostConf, nil, ip.Server.Uuid+"_installer")
r, err := ip.client.ContainerCreate(ip.context, conf, hostConf, nil, ip.Server.Id()+"_installer")
if err != nil {
return "", errors.WithStack(err)
}
Expand Down Expand Up @@ -516,7 +516,7 @@ func (ip *InstallationProcess) StreamOutput(id string) error {
func (s *Server) SyncInstallState(successful bool) error {
r := api.NewRequester()

rerr, err := r.SendInstallationStatus(s.Uuid, successful)
rerr, err := r.SendInstallationStatus(s.Id(), successful)
if rerr != nil || err != nil {
if err != nil {
return errors.WithStack(err)
Expand Down
9 changes: 2 additions & 7 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ type Server struct {
// writing the configuration to the disk.
sync.RWMutex

// The unique identifier for the server that should be used when referencing
// it against the Panel API (and internally). This will be used when naming
// docker containers as well as in log output.
Uuid string `json:"-"`

// Maintains the configuration for the server. This is the data that gets returned by the Panel
// such as build settings and container images.
cfg Configuration
Expand Down Expand Up @@ -99,7 +94,7 @@ eloop:
}

func (s *Server) Log() *log.Entry {
return log.WithField("server", s.Uuid)
return log.WithField("server", s.Id())
}

// Syncs the state of the server on the Panel with Wings. This ensures that we're always
Expand Down Expand Up @@ -159,7 +154,7 @@ func (s *Server) CreateEnvironment() error {

// Gets the process configuration data for the server.
func (s *Server) GetProcessConfiguration() (*api.ServerConfigurationResponse, *api.RequestError, error) {
return api.NewRequester().GetServerConfiguration(s.Uuid)
return api.NewRequester().GetServerConfiguration(s.Id())
}

// Helper function that can receieve a power action and then process the
Expand Down
2 changes: 1 addition & 1 deletion server/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func saveServerStates() error {
// Get the states of all servers on the daemon.
states := map[string]string{}
for _, s := range GetServers().All() {
states[s.Uuid] = s.GetState()
states[s.Id()] = s.GetState()
}

// Convert the map to a json object.
Expand Down
3 changes: 1 addition & 2 deletions server/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s *Server) UpdateDataStructure(data []byte, background bool) error {
// Don't allow obviously corrupted data to pass through into this function. If the UUID
// doesn't match something has gone wrong and the API is attempting to meld this server
// instance into a totally different one, which would be bad.
if src.Uuid != "" && s.Uuid != "" && src.Uuid != s.Uuid {
if src.Uuid != "" && s.Id() != "" && src.Uuid != s.Id() {
return errors.New("attempting to merge a data stack with an invalid UUID")
}

Expand Down Expand Up @@ -95,7 +95,6 @@ func (s *Server) UpdateDataStructure(data []byte, background bool) error {

// Update the configuration once we have a lock on the configuration object.
s.cfg = c
s.Uuid = c.Uuid

if background {
go s.runBackgroundActions()
Expand Down
6 changes: 3 additions & 3 deletions sftp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Initialize(config *config.Configuration) error {

func validatePath(fs sftp_server.FileSystem, p string) (string, error) {
s := server.GetServers().Find(func(server *server.Server) bool {
return server.Uuid == fs.UUID
return server.Id() == fs.UUID
})

if s == nil {
Expand All @@ -61,7 +61,7 @@ func validatePath(fs sftp_server.FileSystem, p string) (string, error) {

func validateDiskSpace(fs sftp_server.FileSystem) bool {
s := server.GetServers().Find(func(server *server.Server) bool {
return server.Uuid == fs.UUID
return server.Id() == fs.UUID
})

if s == nil {
Expand Down Expand Up @@ -105,7 +105,7 @@ func validateCredentials(c sftp_server.AuthenticationRequest) (*sftp_server.Auth
}

s := server.GetServers().Find(func(server *server.Server) bool {
return server.Uuid == resp.Server
return server.Id() == resp.Server
})

if s == nil {
Expand Down

0 comments on commit cb850fd

Please sign in to comment.