@@ -3,6 +3,7 @@ package codeflow
3
3
import (
4
4
"log"
5
5
"net/http"
6
+ "time"
6
7
7
8
"gopkg.in/mgo.v2/bson"
8
9
@@ -21,11 +22,59 @@ func (x *Admin) Register(api *rest.Api) []*rest.Route {
21
22
rest .Put (x .Path + "/serviceSpecs" , x .updateServiceSpec ),
22
23
rest .Delete (x .Path + "/serviceSpecs/#slug" , x .deleteServiceSpec ),
23
24
rest .Get (x .Path + "/serviceSpecs/#slug/services" , x .serviceSpecServices ),
25
+ rest .Put (x .Path + "/deployallprojects" , x .deployAllProjects ),
26
+ rest .Put (x .Path + "/deployloadbalancers" , x .deployAllLoadBalancers ),
24
27
)
25
28
log .Printf ("Started the codeflow admin handler on %s\n " , x .Path )
26
29
return routes
27
30
}
28
31
32
+ // Deploys all projects (does not touch services)
33
+ func (x * Admin ) deployAllProjects (w rest.ResponseWriter , r * rest.Request ) {
34
+ projects := []Project {}
35
+ m := bson.M {"deleted" : false }
36
+ results := db .Collection ("projects" ).Find (m )
37
+ results .Query .Sort ("-$natural" ).All (& projects )
38
+ log .Printf ("Deploying %d projects" , len (projects ))
39
+ for _ , p := range projects {
40
+ log .Printf ("Deploying %s..." , p .Slug )
41
+ release := Release {}
42
+ if err := GetCurrentRelease (p .Id , & release ); err != nil {
43
+ log .Printf ("GetCurrentRelease::Error: %s; Aborting release for %s" , err , p .Slug )
44
+ } else {
45
+ log .Printf ("Deploying %s release" , release .Id )
46
+ err := CreateDeploy (& release )
47
+ if err != nil {
48
+ log .Printf ("ERROR '%s' creating deployment for %s" , err , p .Slug )
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ // Deploys all loadBalancers
55
+ func (x * Admin ) deployAllLoadBalancers (w rest.ResponseWriter , r * rest.Request ) {
56
+ projects := []Project {}
57
+ m := bson.M {"deleted" : false }
58
+ results := db .Collection ("projects" ).Find (m )
59
+ results .Query .Sort ("-$natural" ).All (& projects )
60
+ for _ , p := range projects {
61
+ log .Printf ("Finding services for '%s' project..." , p .Slug )
62
+ l := bson.M {"projectId" : p .Id }
63
+ lbResults := db .Collection ("extensions" ).Find (l )
64
+ loadBalancer := & LoadBalancer {}
65
+ for lbResults .Next (loadBalancer ) {
66
+ log .Printf ("Deploying loadbalancer %s for %s" , loadBalancer .Name , p .Slug )
67
+ err := ExtensionUpdated (loadBalancer )
68
+ if err != nil {
69
+ log .Printf ("ERROR '%s' updating loadBalancer %s" , err , loadBalancer .Name )
70
+ }
71
+ }
72
+ }
73
+ // Throttle so that we can be "nice" to the amazon APIs
74
+ log .Println ("Sleeping 1 second" )
75
+ time .Sleep (time .Second * 1 )
76
+ }
77
+
29
78
func (x * Admin ) deleteServiceSpec (w rest.ResponseWriter , r * rest.Request ) {
30
79
slug := r .PathParam ("slug" )
31
80
0 commit comments