Skip to content

Commit

Permalink
forgot to stage
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDigitalEagle committed Nov 29, 2022
1 parent 95905b7 commit ffc95ec
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 15 deletions.
46 changes: 31 additions & 15 deletions broker/create_registry_server_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,23 @@ func (broker *SCSBroker) createRegistryServerInstance(serviceId string, instance
return "", errors.New("no domains found for this instance")
}

route, _, err := cfClient.CreateRoute(ccv3.Route{
SpaceGUID: spaceGUID,
DomainGUID: domains[0].GUID,
Host: appName,
})
if err != nil {
return "", err
}

_, err = cfClient.MapRoute(route.GUID, app.GUID)

if err != nil {
return "", err
}

time.Sleep(time.Second)

broker.Logger.Info("Starting Application")
app, _, err = cfClient.UpdateApplicationStart(app.GUID)
if err != nil {
Expand Down Expand Up @@ -182,21 +199,6 @@ func (broker *SCSBroker) createRegistryServerInstance(serviceId string, instance
return "", err
}

route, _, err := cfClient.CreateRoute(ccv3.Route{
SpaceGUID: spaceGUID,
DomainGUID: domains[0].GUID,
Host: appName,
})
if err != nil {
return "", err
}

_, err = cfClient.MapRoute(route.GUID, app.GUID)

if err != nil {
return "", err
}

broker.Logger.Info("Starting Application")
app, _, err = cfClient.UpdateApplicationStart(app.GUID)
if err != nil {
Expand Down Expand Up @@ -270,5 +272,19 @@ func (broker *SCSBroker) createRegistryServerInstance(serviceId string, instance

broker.Logger.Info(route.URL)

sucessfulStart, err := broker.MonitorApplicationStartup(cfClient, community, broker.Logger, app.GUID)
if err != nil || sucessfulStart == false {
broker.Logger.Info("Crashed application retarting...")
app, _, err = cfClient.UpdateApplicationStart(app.GUID)
if err != nil {
broker.Logger.Info("Application Start Failed, Trying restart")
app, _, err = cfClient.UpdateApplicationRestart(app.GUID)
if err != nil {
broker.Logger.Info("Application Start failed")
return "", err
}
}
}

return route.URL, nil
}
45 changes: 45 additions & 0 deletions broker/monitor_application.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package broker

import (
"time"

"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/lager"
"github.com/cloudfoundry-community/go-cfclient"
)

func (broker *SCSBroker) MonitorApplicationStartup(cfClient *ccv3.Client, community *cfclient.Client, logger lager.Logger, appGUID string) (bool, error) {

waittime := 30
timepassed := 0

for timepassed < waittime {
time.Sleep(time.Second)
timepassed += 1
successStart, err := broker.checkApplicationStatus(cfClient, community, logger, appGUID)
if err != nil {
return false, err
}
if !successStart {
return successStart, err
}
}

return true, nil

}

func (broker *SCSBroker) checkApplicationStatus(cfClient *ccv3.Client, community *cfclient.Client, logger lager.Logger, appGUID string) (bool, error) {
stats, err := getProcessStatsByAppAndType(cfClient, community, broker.Logger, appGUID, "web")
if err != nil {
return false, err
}

for _, stat := range stats {
if stat.State == "CRASHED" {
return false, err
}
}

return true, nil
}

0 comments on commit ffc95ec

Please sign in to comment.