Browse Source

small fixes from testing greenhouse desktop

master
forest 5 months ago
parent
commit
78e993f6f9
1 changed files with 14 additions and 3 deletions
  1. +14
    -3
      backend.go

+ 14
- 3
backend.go View File

@ -55,11 +55,13 @@ type ThresholdMetrics struct {
}
type ThresholdTenantInfo struct {
ThresholdServers []string
ClientStates map[string]ThresholdClientState
Listeners []ThresholdTunnel
AuthorizedDomains []string
PortStart int
PortEnd int
EmailAddress string
}
type ThresholdClientState struct {
@ -103,6 +105,7 @@ const knapsackNumberOfGuessesFactor = float64(5)
const shufflingCircuitBreakerLimit = 1000
const GIGABYTE = int64(1000000000)
const TERABYTE = int64(1000000000000)
const tenantPinDuration = 6 * time.Hour
const managementClientCertSubject = "management@greenhouse.server.garden"
const freeSubdomainDomain = "greenhouseusers.com"
@ -329,12 +332,17 @@ func (app *BackendApp) GetTenantInfo(tenantId int) (*ThresholdTenantInfo, error)
return nil, err
}
thresholdServerHostPorts := []string{}
actions := make([]func() taskResult, 0)
for _, row := range tenantVPSInstanceRows {
vpsInstance, hasVpsInstance := vpsInstances[row.GetVPSInstanceId()]
if hasVpsInstance && row.TenantId == tenantId && row.Active {
activeOrPinned := (row.Active || row.DeactivatedAt != nil && row.DeactivatedAt.Add(tenantPinDuration).After(time.Now()))
if hasVpsInstance && row.TenantId == tenantId && activeOrPinned {
thresholdServerHostPorts = append(thresholdServerHostPorts, fmt.Sprintf("%s:%d", vpsInstance.IPV4, app.ThresholdManagementPort))
actions = append(actions, func() taskResult {
responseBytes, err := app.MyHTTP200(
"GET",
@ -357,13 +365,17 @@ func (app *BackendApp) GetTenantInfo(tenantId int) (*ThresholdTenantInfo, error)
results := doInParallel(false, actions...)
//log.Printf("%+v, %d", tenant.TunnelSettings.AuthorizedDomains, len(tenant.TunnelSettings.AuthorizedDomains))
errorStrings := []string{}
toReturn := ThresholdTenantInfo{
ThresholdServers: thresholdServerHostPorts,
ClientStates: map[string]ThresholdClientState{},
Listeners: []ThresholdTunnel{},
AuthorizedDomains: tenant.TunnelSettings.AuthorizedDomains,
PortStart: tenant.TunnelSettings.PortStart,
PortEnd: tenant.TunnelSettings.PortEnd,
EmailAddress: tenant.Email,
}
listenersToReturn := map[string]ThresholdTunnel{}
for _, result := range results {
@ -388,7 +400,7 @@ func (app *BackendApp) GetTenantInfo(tenantId int) (*ThresholdTenantInfo, error)
toReturn.Listeners = append(toReturn.Listeners, listener)
}
if len(errorStrings) > 0 {
return nil, errors.Errorf("ConsumeMetrics() doInParallel(actions...): %s\n\n", strings.Join(errorStrings, "\n"))
return nil, errors.Errorf("GetTenantInfo() doInParallel(actions...): %s\n\n", strings.Join(errorStrings, "\n"))
}
return &toReturn, nil
@ -499,7 +511,6 @@ func (app *BackendApp) Rebalance() (bool, error) {
//TODO
desiredInstancesPerTenant := 2
tenantPinDuration := 6 * time.Hour
tenants, err := app.Model.GetTenants()
if err != nil {


Loading…
Cancel
Save