aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/vespa/system.go
blob: b49dad97ee78c6975d4de02bdcaeb6150d248d63 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package vespa

import "fmt"

// PublicSystem represents the main Vespa Cloud system.
var PublicSystem = System{
	Name:           "public",
	URL:            "https://api-ctl.vespa-cloud.com:4443",
	ConsoleURL:     "https://console.vespa-cloud.com",
	DefaultZone:    ZoneID{Environment: "dev", Region: "aws-us-east-1c"},
	EndpointDomain: "vespa-app.cloud",
}

// PublicCDSystem represents the CD variant of the Vespa Cloud system.
var PublicCDSystem = System{
	Name:           "publiccd",
	URL:            "https://api-ctl.cd.vespa-cloud.com:4443",
	ConsoleURL:     "https://console.cd.vespa-cloud.com",
	DefaultZone:    ZoneID{Environment: "dev", Region: "aws-us-east-1c"},
	EndpointDomain: "cd.vespa-app.cloud",
}

// MainSystem represents the main hosted Vespa system.
var MainSystem = System{
	Name:           "main",
	URL:            "https://api.vespa.ouryahoo.com:4443",
	ConsoleURL:     "https://console.vespa.ouryahoo.com",
	DefaultZone:    ZoneID{Environment: "dev", Region: "us-east-1"},
	AthenzDomain:   "vespa.vespa",
	EndpointDomain: "vespa.oath.cloud",
}

// CDSystem represents the CD variant of the hosted Vespa system.
var CDSystem = System{
	Name:           "cd",
	URL:            "https://api-cd.vespa.ouryahoo.com:4443",
	ConsoleURL:     "https://console-cd.vespa.ouryahoo.com",
	DefaultZone:    ZoneID{Environment: "dev", Region: "cd-us-west-1"},
	AthenzDomain:   "vespa.vespa.cd",
	EndpointDomain: "cd.vespa.oath.cloud",
}

// System represents a Vespa system.
type System struct {
	Name string
	// URL is the API URL for this system.
	URL        string
	ConsoleURL string
	// DefaultZone is default zone to use in manual deployments to this system.
	DefaultZone ZoneID
	// AthenzDomain is the Athenz domain used by this system. This is empty for systems not using Athenz for tenant
	// authentication.
	AthenzDomain string
	// EndpointDomain is the domain used for application endpoints in this system
	EndpointDomain string
}

// IsPublic returns whether system s is a public (Vespa Cloud) system.
func (s System) IsPublic() bool { return s.Name == PublicSystem.Name || s.Name == PublicCDSystem.Name }

// DeployURL returns the API URL to use for deploying to this system.
func (s System) DeployURL(deployment Deployment) string {
	return fmt.Sprintf("%s/application/v4/tenant/%s/application/%s/instance/%s/deploy/%s",
		s.URL,
		deployment.Application.Tenant,
		deployment.Application.Application,
		deployment.Application.Instance,
		jobName(deployment.Zone))
}

// SubmitURL returns the API URL for submitting an application package for production deployment.
func (s System) SubmitURL(deployment Deployment) string {
	return fmt.Sprintf("%s/application/v4/tenant/%s/application/%s/submit", s.URL, deployment.Application.Tenant, deployment.Application.Application)
}

// DeploymentURL returns the API URL of given deployment.
func (s System) DeploymentURL(deployment Deployment) string {
	return fmt.Sprintf("%s/application/v4/tenant/%s/application/%s/instance/%s/environment/%s/region/%s",
		s.URL,
		deployment.Application.Tenant,
		deployment.Application.Application,
		deployment.Application.Instance,
		deployment.Zone.Environment,
		deployment.Zone.Region)
}

// RunURL returns the API URL for a given deployment job run.
func (s System) RunURL(deployment Deployment, id int64) string {
	return fmt.Sprintf("%s/application/v4/tenant/%s/application/%s/instance/%s/job/%s/run/%d",
		s.URL,
		deployment.Application.Tenant, deployment.Application.Application, deployment.Application.Instance,
		jobName(deployment.Zone), id)
}

// RunsURL returns the API URL listing all runs for given deployment.
func (s System) RunsURL(deployment Deployment) string {
	return fmt.Sprintf("%s/application/v4/tenant/%s/application/%s/instance/%s/job/%s",
		s.URL,
		deployment.Application.Tenant, deployment.Application.Application, deployment.Application.Instance,
		jobName(deployment.Zone))
}

// ConsoleRunURL returns the console URL for a deployment job run in this system.
func (s System) ConsoleRunURL(deployment Deployment, run int64) string {
	return fmt.Sprintf("%s/tenant/%s/application/%s/%s/instance/%s/job/%s/run/%d",
		s.ConsoleURL, deployment.Application.Tenant, deployment.Application.Application, deployment.Zone.Environment,
		deployment.Application.Instance, jobName(deployment.Zone), run)
}

func jobName(zone ZoneID) string {
	env := zone.Environment
	if env == "prod" {
		env = "production"
	}
	return env + "-" + zone.Region
}

// GetSystem returns the system of given name.
func GetSystem(name string) (System, error) {
	switch name {
	case "cd":
		return CDSystem, nil
	case "main":
		return MainSystem, nil
	case "public":
		return PublicSystem, nil
	case "publiccd":
		return PublicCDSystem, nil
	}
	return System{}, fmt.Errorf("invalid system: %s", name)
}