Skip to content

Commit

Permalink
hotfix-110724-1 (#182)
Browse files Browse the repository at this point in the history
- fixed an issue when trying to update a orchestrator that is offline
  • Loading branch information
cjlapao authored Jul 11, 2024
1 parent c7d90e9 commit 33c5051
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/orchestrator/get_host_hardware_info.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package orchestrator

import (
"time"

"github.com/Parallels/prl-devops-service/data/models"
"github.com/Parallels/prl-devops-service/errors"
"github.com/Parallels/prl-devops-service/helpers"
Expand All @@ -9,6 +11,7 @@ import (

func (s *OrchestratorService) GetHostHardwareInfo(host *models.OrchestratorHost) (*api_models.SystemUsageResponse, error) {
httpClient := s.getApiClient(*host)
httpClient.WithTimeout(10 * time.Second)
path := "/v1/config/hardware"
url, err := helpers.JoinUrl([]string{host.GetHost(), path})
if err != nil {
Expand Down
106 changes: 95 additions & 11 deletions src/orchestrator/update_host.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package orchestrator

import (
"strings"

"github.com/Parallels/prl-devops-service/basecontext"
"github.com/Parallels/prl-devops-service/data/models"
"github.com/Parallels/prl-devops-service/mappers"
Expand All @@ -13,27 +15,109 @@ func (s *OrchestratorService) UpdateHost(ctx basecontext.ApiContext, host *model
return nil, err
}

hw, err := s.GetHostHardwareInfo(host)
dbHost, err := dbService.GetOrchestratorHost(ctx, host.ID)
if err != nil {
return nil, err
}

host.Enabled = true
if host.Architecture != hw.CpuType {
if host.Resources == nil {
host.Resources = &models.HostResources{}
if dbHost.State == "healthy" {
if hw, err := s.GetHostHardwareInfo(host); err == nil {
if host.Architecture != hw.CpuType {
if host.Resources == nil {
host.Resources = &models.HostResources{}
}

dtoResources := mappers.MapHostResourcesFromSystemUsageResponse(*hw)
host.Resources = &dtoResources
host.Architecture = hw.CpuType
host.CpuModel = hw.CpuBrand
}
}
}

dtoResources := mappers.MapHostResourcesFromSystemUsageResponse(*hw)
host.Resources = &dtoResources
host.Architecture = hw.CpuType
host.CpuModel = hw.CpuBrand
host.Enabled = dbHost.Enabled
host.CreatedAt = dbHost.CreatedAt
host.UpdatedAt = dbHost.UpdatedAt
if host.Authentication == nil {
host.Authentication = dbHost.Authentication
}
if host.Resources == nil {
host.Resources = dbHost.Resources
}
if host.Host == "" {
host.Host = dbHost.Host
}
if host.Port == "" {
host.Port = dbHost.Port
}
if host.PathPrefix == "" {
host.PathPrefix = dbHost.PathPrefix
}
if len(dbHost.RequiredClaims) > 0 {
for _, dbClaim := range dbHost.RequiredClaims {
if dbClaim != "" {
found := false
hostClaim:
for _, claim := range host.RequiredClaims {
if strings.EqualFold(claim, dbClaim) {
found = true
break hostClaim
}
}
if !found {
host.RequiredClaims = append(host.RequiredClaims, dbClaim)
}
}
}
}
if len(dbHost.RequiredRoles) > 0 {
for _, dbRole := range dbHost.RequiredRoles {
if dbRole != "" {
found := false
hostRole:
for _, role := range host.RequiredRoles {
if strings.EqualFold(role, dbRole) {
found = true
break hostRole
}
}
if !found {
host.RequiredRoles = append(host.RequiredRoles, dbRole)
}
}
}
}
if len(dbHost.Tags) > 0 {
for _, dbTag := range dbHost.Tags {
if dbTag != "" {
found := false
hostTag:
for _, tag := range host.Tags {
if strings.EqualFold(tag, dbTag) {
found = true
break hostTag
}
}
if !found {
host.Tags = append(host.Tags, dbTag)
}
}
}
}
if host.Description == "" {
host.Description = dbHost.Description
}
if host.Schema == "" {
host.Schema = dbHost.Schema
}
if len(dbHost.VirtualMachines) > 0 {
host.VirtualMachines = dbHost.VirtualMachines
}

dbHost, err := dbService.UpdateOrchestratorHostDetails(ctx, host)
updatedHost, err := dbService.UpdateOrchestratorHostDetails(ctx, host)
if err != nil {
return nil, err
}

return dbHost, nil
return updatedHost, nil
}

0 comments on commit 33c5051

Please sign in to comment.