func (c *BaseCluster) getAppEnv(appName string, t *TargetServer) (map[string]string, error) { c.SendLog(fmt.Sprintf("Getting ENV for %s", appName)) client, err := cc.NewClientWithHTTP(fmt.Sprintf("http://%s", t.IP), c.ControllerKey, &http.Client{Transport: &http.Transport{Dial: t.SSHClient.Dial}}) if err != nil { return nil, err } client.Host = fmt.Sprintf("controller.%s", c.oldDomain) release, err := client.GetAppRelease(appName) if err != nil { return nil, err } return release.Env, nil }
func (c *BaseCluster) migrateDomain(dm *ct.DomainMigration, t *TargetServer) (*ct.DomainMigration, error) { c.SendLog(fmt.Sprintf("Migrating domain (%s to %s)", dm.OldDomain, dm.Domain)) client, err := cc.NewClientWithHTTP(fmt.Sprintf("http://%s", t.IP), c.ControllerKey, &http.Client{Transport: &http.Transport{Dial: t.SSHClient.Dial}}) if err != nil { return nil, err } if v1client, ok := client.(*v1controller.Client); ok { v1client.Host = fmt.Sprintf("controller.%s", dm.OldDomain) } events := make(chan *ct.Event) stream, err := client.StreamEvents(ct.StreamEventsOptions{ ObjectTypes: []ct.EventType{ct.EventTypeDomainMigration}, }, events) if err != nil { return nil, fmt.Errorf("Error opening domain migration event stream: %s", err) } defer stream.Close() if err := client.PutDomain(dm); err != nil { return nil, fmt.Errorf("Error starting domain migration: %s", err) } timeout := time.After(5 * time.Minute) var e *ct.DomainMigrationEvent for { select { case event, ok := <-events: if !ok { return nil, fmt.Errorf("Error streaming domain migration events: %s", stream.Err()) } if err := json.Unmarshal(event.Data, &e); err != nil { return nil, err } if e.Error != "" { return nil, fmt.Errorf("Domain migration error: %s", e.Error) } if e.DomainMigration.FinishedAt != nil { return e.DomainMigration, nil } case <-timeout: return nil, errors.New("timed out waiting for domain migration to complete") } } }
// Workaround for https://github.com/flynn/flynn/issues/2987 // Make sure system apps are using correct cert func (c *BaseCluster) migrateDomainWorkaroundIssue2987(dm *ct.DomainMigration, t *TargetServer) error { client, err := cc.NewClientWithHTTP(fmt.Sprintf("http://%s", t.IP), c.ControllerKey, &http.Client{Transport: &http.Transport{Dial: t.SSHClient.Dial}}) if err != nil { return fmt.Errorf("Error creating client: %s", err) } if v1client, ok := client.(*v1controller.Client); ok { v1client.Host = fmt.Sprintf("controller.%s", dm.OldDomain) } for _, appName := range []string{"controller", "dashboard"} { app, err := client.GetApp(appName) if err != nil { return fmt.Errorf("Error fetching app %s: %s", appName, err) } routes, err := client.RouteList(app.ID) if err != nil { return fmt.Errorf("Error listing routes for %s: %s", appName, err) } var route *router.Route for _, r := range routes { if strings.HasSuffix(r.Domain, dm.Domain) { route = r break } } if route == nil { return fmt.Errorf("couldn't find route for %s matching %s", appName, dm.Domain) } route.Certificate = &router.Certificate{ Cert: dm.TLSCert.Cert, Key: dm.TLSCert.PrivateKey, } if err := client.UpdateRoute(app.ID, route.FormattedID(), route); err != nil { return fmt.Errorf("Error updating route for app %s: %s", appName, err) } } return nil }
func main() { conf, err := loadConfigFromEnv() if err != nil { log.Fatal(err) } log.SetOutput(conf.logOut) httpClient := &http.Client{} client, err := cc.NewClientWithHTTP("", conf.controllerKey, httpClient) if err != nil { log.Fatal(err) } recorder := httprecorder.NewWithClient(httpClient) e := &generator{ conf: conf, client: client, recorder: recorder, resourceIds: make(map[string]string), } providerLog := log.New(conf.logOut, "provider: ", 1) go e.listenAndServe(providerLog) examples := []g.Example{ // Run provider_create first so that discoverd service has time to // propagate {"provider_create", e.createProvider}, {"app_create_error", e.createAppError}, {"app_create", e.createApp}, {"app_initial_release_get", e.getInitialAppRelease}, {"app_get", e.getApp}, {"app_list", e.listApps}, {"app_log", e.getAppLog}, {"app_log_stream", e.streamAppLog}, {"app_update", e.updateApp}, {"route_create", e.createRoute}, {"route_get", e.getRoute}, {"route_update", e.updateRoute}, {"route_list", e.listRoutes}, {"route_delete", e.deleteRoute}, {"artifact_create", e.createArtifact}, {"release_create", e.createRelease}, {"artifact_list", e.listArtifacts}, {"release_list", e.listReleases}, {"app_release_set", e.setAppRelease}, {"app_release_get", e.getAppRelease}, {"app_release_list", e.listAppReleases}, {"formation_put", e.putFormation}, {"formation_get", e.getFormation}, {"formation_get_expanded", e.getExpandedFormation}, {"formation_list", e.listFormations}, {"formations_list_active", e.listActiveFormations}, {"formations_stream", e.streamFormations}, {"release_create2", e.createRelease}, {"deployment_create", e.createDeployment}, {"deployment_get", e.getDeployment}, {"deployment_list", e.listDeployments}, {"formation_delete", e.deleteFormation}, {"job_run", e.runJob}, {"job_list", e.listJobs}, {"job_update", e.updateJob}, {"job_get", e.getJob}, {"job_delete", e.deleteJob}, {"provider_get", e.getProvider}, {"provider_list", e.listProviders}, {"provider_resource_create", e.createProviderResource}, {"provider_resource_put", e.putProviderResource}, {"app_resource_list", e.listAppResources}, {"provider_resource_get", e.getProviderResource}, {"provider_resource_list", e.listProviderResources}, {"provider_resource_delete", e.deleteProviderResource}, {"app_delete", e.deleteApp}, {"events_list", e.eventsList}, {"events_stream", e.eventsStream}, {"event_get", e.eventGet}, {"ca_cert", e.getCACert}, {"cluster_backup", e.clusterBackup}, } if os.Getenv("SKIP_MIGRATE_DOMAIN") != "true" { examples = append(examples, g.Example{"migrate_cluster_domain", e.migrateClusterDomain}) } var out io.Writer if len(os.Args) > 1 { var err error out, err = os.Create(os.Args[1]) if err != nil { log.Fatal(err) } } else { out = os.Stdout } if err := g.WriteOutput(recorder, examples, out); err != nil { log.Fatal(err) } }
func main() { conf, err := loadConfigFromEnv() if err != nil { log.Fatal(err) } log.SetOutput(conf.logOut) httpClient := &http.Client{} client, err := cc.NewClientWithHTTP("", conf.controllerKey, httpClient) if err != nil { log.Fatal(err) } recorder := httprecorder.NewWithClient(httpClient) e := &generator{ conf: conf, client: client, resourceIds: make(map[string]string), } providerLog := log.New(conf.logOut, "provider: ", 1) go e.listenAndServe(providerLog) examples := []g.Example{ // Run provider_create first so that discoverd service has time to // propagate {"provider_create", e.createProvider}, {"app_create_error", e.createAppError}, {"app_create", e.createApp}, {"app_initial_release_get", e.getInitialAppRelease}, {"app_get", e.getApp}, {"app_list", e.listApps}, {"app_log", e.getAppLog}, {"app_update", e.updateApp}, {"app_resource_list", e.listAppResources}, {"route_create", e.createRoute}, {"route_get", e.getRoute}, {"route_list", e.listRoutes}, {"route_delete", e.deleteRoute}, {"artifact_create", e.createArtifact}, {"release_create", e.createRelease}, {"artifact_list", e.listArtifacts}, {"release_list", e.listReleases}, {"app_release_set", e.setAppRelease}, {"app_release_get", e.getAppRelease}, {"formation_put", e.putFormation}, {"formation_get", e.getFormation}, {"formation_list", e.listFormations}, {"release_create2", e.createRelease}, {"deployment_create", e.createDeployment}, {"formation_delete", e.deleteFormation}, {"job_run", e.runJob}, {"job_list", e.listJobs}, {"job_update", e.updateJob}, {"job_delete", e.deleteJob}, {"provider_get", e.getProvider}, {"provider_list", e.listProviders}, {"provider_resource_create", e.createProviderResource}, {"provider_resource_get", e.getProviderResource}, {"provider_resource_list", e.listProviderResources}, {"app_delete", e.deleteApp}, } // TODO: GET /apps/:app_id/jobs/:job_id/log (event-stream) var out io.Writer if len(os.Args) > 1 { var err error out, err = os.Create(os.Args[1]) if err != nil { log.Fatal(err) } } else { out = os.Stdout } if err := g.WriteOutput(recorder, examples, out); err != nil { log.Fatal(err) } }