Skip to content

Commit

Permalink
[UPDATE] no start option
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyTobi committed Nov 21, 2019
1 parent caf7832 commit 698c471
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
6 changes: 3 additions & 3 deletions cf/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type ApplicationPushData struct {

//PuppeteerPush push application interface
type PuppeteerPush interface {
PushApplication(venAppName string, spaceGUID string, parsedArguments *arguments.ParserArguments) error
PushApplication(venAppName string, venAppExists bool, spaceGUID string, parsedArguments *arguments.ParserArguments) error
}

var cliCalls cli.Calls
Expand All @@ -39,7 +39,7 @@ func NewApplicationPush(conn plugin.CliConnection, traceLogging bool) *Applicati
}

//PushApplication push application to cf
func (adp *ApplicationPushData) PushApplication(venAppName, spaceGUID string, parsedArguments *arguments.ParserArguments) error {
func (adp *ApplicationPushData) PushApplication(venAppName string, venAppExists bool, spaceGUID string, parsedArguments *arguments.ParserArguments) error {
v3Push, err := useV3Push()
if err != nil {
//fatal exit
Expand All @@ -58,7 +58,7 @@ func (adp *ApplicationPushData) PushApplication(venAppName, spaceGUID string, pa

var legacyPush v2.Push = v2.NewV2LegacyPush(adp.Connection, adp.TraceLogging)
if parsedArguments.AddRoutes {
return legacyPush.SwitchRoutesOnly(venAppName, parsedArguments.AppName, parsedArguments.Manifest.ApplicationManifests[0].Routes)
return legacyPush.SwitchRoutesOnly(venAppName, venAppExists, parsedArguments.AppName, parsedArguments.Manifest.ApplicationManifests[0].Routes)
}
return legacyPush.PushApplication(venAppName, spaceGUID, parsedArguments)
}
Expand Down
13 changes: 10 additions & 3 deletions cf/v2/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type DomainResponse struct {
}

func (resource *LegacyResourcesData) GetDomain(domains []map[string]string) (*[]Routes, error) {
//default order asc.
path := fmt.Sprintf(`/v2/domains`)

response, err := resource.getDomain(path)
Expand All @@ -41,12 +42,17 @@ func (resource *LegacyResourcesData) GetDomain(domains []map[string]string) (*[]
}

domainGUID := make(map[string]Routes)

for _, domainRes := range response.Resources {
for _, routes := range domains {
_, exists := domainGUID[domainRes.Metadata.GUID]
domain := routes["value"]
domain := routes["route"]
hostName := strings.ReplaceAll(domain, domainRes.Entity.Name, "")

_, exists := domainGUID[domain]
if exists {
exists = len(domainGUID[domain].Host) < len(hostName)
}

//question ist when route matches 2 time what kind of your we are using?
if strings.Contains(domain, domainRes.Entity.Name) && len(hostName) > 0 && !exists {
hostName = strings.TrimRight(hostName, ".")
newRoute := &Routes{
Expand All @@ -58,6 +64,7 @@ func (resource *LegacyResourcesData) GetDomain(domains []map[string]string) (*[]
}
}

//move to func and all recursive
for response.Pagination.NextUrl != "" && len(domainGUID) <= 0 {
response, err := resource.getDomain(response.Pagination.NextUrl)
if err != nil {
Expand Down
18 changes: 10 additions & 8 deletions cf/v2/push_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
//Push interface with all v3 actions
type Push interface {
PushApplication(venAppName string, spaceGUID string, parsedArguments *arguments.ParserArguments) error
SwitchRoutesOnly(venAppName string, appName string, routes []map[string]string) error
SwitchRoutesOnly(venAppName string, venAppExists bool, appName string, routes []map[string]string) error
}

//ResourcesData internal struct with connection an tracing options etc
Expand Down Expand Up @@ -71,7 +71,7 @@ func (resource *LegacyResourcesData) PushApplication(venAppName, spaceGUID strin
}

//SwitchRoutes switch route interface method to provide switch routes only option
func (resource *LegacyResourcesData) SwitchRoutesOnly(venAppName string, appName string, routes []map[string]string) (err error) {
func (resource *LegacyResourcesData) SwitchRoutesOnly(venAppName string,venAppExists bool, appName string, routes []map[string]string) (err error) {
domains, err := resource.GetDomain(routes)
if err != nil {
return err
Expand All @@ -86,12 +86,14 @@ func (resource *LegacyResourcesData) SwitchRoutesOnly(venAppName string, appName
}
}

ui.Say("remove routes from venerable application %s", venAppName)
for _, route := range *domains {
err = resource.UnMapRoute(venAppName, route.Host, route.Domain)
if err != nil {
//loop through
ui.Warn("could not remove route %s.%s from application", route.Host, route.Domain, venAppName)
if venAppExists {
ui.Say("remove routes from venerable application %s", venAppName)
for _, route := range *domains {
err = resource.UnMapRoute(venAppName, route.Host, route.Domain)
if err != nil {
//loop through
ui.Warn("could not remove route %s.%s from application", route.Host, route.Domain, venAppName)
}
}
}

Expand Down
20 changes: 10 additions & 10 deletions puppeteer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ func getActionsForApp(appRepo *ApplicationRepo, parsedArguments *arguments.Parse
// push
{
Forward: func() error {
venAppExists := venApp != nil
space, err := appRepo.conn.GetCurrentSpace()
if err != nil {
return err
}

var puppeteerPush cf.PuppeteerPush = cf.NewApplicationPush(appRepo.conn, appRepo.traceLogging)
return puppeteerPush.PushApplication(venName, space.Guid, parsedArguments)
return puppeteerPush.PushApplication(venName, venAppExists, space.Guid, parsedArguments)
},
//When upload fails the new application will be deleted and ven app will be renamed
ReversePrevious: func() error {
Expand Down Expand Up @@ -146,9 +146,9 @@ func getActionsForApp(appRepo *ApplicationRepo, parsedArguments *arguments.Parse
{
Forward: func() error {
//if venerableAction was set to stop
if strings.ToLower(parsedArguments.VenerableAction) == "stop" {
if strings.ToLower(parsedArguments.VenerableAction) == "stop" && venApp != nil {
return appRepo.StopApplication(venName)
} else if strings.ToLower(parsedArguments.VenerableAction) == "delete" {
} else if strings.ToLower(parsedArguments.VenerableAction) == "delete" && venApp != nil {
return appRepo.DeleteApplication(venName)
}
//do nothing with the ven app
Expand Down Expand Up @@ -211,12 +211,12 @@ func (CfPuppeteerPlugin) GetMetadata() plugin.PluginMetadata {
"-invocation-timeout": "timeout (in seconds) that controls individual health check invocations",
"-show-crash-log": "Show recent logs when applications crashes while the deployment",
//"-show-app-log": "tail and show application log during application start",
"-process": "use health check type process",
"-legacy-push": "use legacy push instead of new v3 api",
"-no-route": "deploy new application without adding routes",
"-route-only": "only add routes from manifest to application",
"-no-start": "don't start application after deployment",
"-docker-image": "docker image url",
"-process": "use health check type process",
"-legacy-push": "use legacy push instead of new v3 api",
"-no-route": "deploy new application without adding routes",
"-route-only": "only add routes from manifest to application",
"-no-start": "don't start application after deployment; venerable action will none",
"-docker-image": "docker image url",
"-docker-username": "docker repository username; used with password from env CF_DOCKER_PASSWORD",
},
},
Expand Down

0 comments on commit 698c471

Please sign in to comment.