Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 41 additions & 63 deletions src/jetstream/plugins/cfapppush/pushapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import (
"bytes"
"encoding/json"
"errors"

"fmt"
"html/template"
"io"
"strconv"
"strings"

"code.cloudfoundry.org/cli/actor/pushaction"
"code.cloudfoundry.org/cli/actor/sharedaction"
"code.cloudfoundry.org/cli/actor/v2action"
"code.cloudfoundry.org/cli/actor/v2v3action"
"code.cloudfoundry.org/cli/actor/v3action"
"code.cloudfoundry.org/cli/actor/v7action"
"code.cloudfoundry.org/cli/actor/v7pushaction"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
"code.cloudfoundry.org/cli/cf/commandregistry"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/clock"

"code.cloudfoundry.org/cli/util/configv3"
"code.cloudfoundry.org/cli/util/manifestparser"
"code.cloudfoundry.org/cli/util/progressbar"
"code.cloudfoundry.org/cli/util/ui"
"github.com/gorilla/websocket"
Expand All @@ -27,20 +28,19 @@ import (

"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/command/translatableerror"
v6 "code.cloudfoundry.org/cli/command/v6"
"code.cloudfoundry.org/cli/command/v6/shared"
sharedV3 "code.cloudfoundry.org/cli/command/v6/shared"
v7 "code.cloudfoundry.org/cli/command/v7"
"code.cloudfoundry.org/cli/command/v7/shared"

"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/interfaces"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/api"
)

// CFPushApp abstracts the push functionality form the CLI library
type CFPushApp struct {
pushCommand *v6.PushCommand
pushCommand *v7.PushCommand
flagContext flags.FlagContext
deps commandregistry.Dependency
config *CFPushAppConfig
portalProxy interfaces.PortalProxy
portalProxy api.PortalProxy
}

// CFPushAppConfig is the configuration used
Expand All @@ -51,6 +51,7 @@ type CFPushAppConfig struct {
APIEndpointURL string
DopplerLoggingEndpoint string
SkipSSLValidation bool
CACert string
AuthToken string
OrgGUID string
OrgName string
Expand Down Expand Up @@ -116,9 +117,8 @@ func (p *PushError) Error() string {
}

// Constructor returns a CFPush based on the supplied config
func Constructor(config *CFPushAppConfig, portalProxy interfaces.PortalProxy) CFPush {

pushCmd := &v6.PushCommand{}
func Constructor(config *CFPushAppConfig, portalProxy api.PortalProxy) CFPush {
pushCmd := &v7.PushCommand{}
cfPush := &CFPushApp{
pushCommand: pushCmd,
config: config,
Expand All @@ -134,7 +134,6 @@ func (c *CFPushApp) init(config *CFPushAppConfig) error {

// Init initializes the push operation with the specified application directory and manifest path
func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushAppOverrides) error {

// App name
if len(overrides.Name) > 0 {
c.pushCommand.OptionalArgs = flag.OptionalAppName{
Expand All @@ -150,18 +149,13 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp

// Start Command
if len(overrides.StartCmd) > 0 {
c.pushCommand.Command = flag.Command{}
err := c.pushCommand.Command.UnmarshalFlag(overrides.StartCmd)
c.pushCommand.StartCommand = flag.Command{}
err := c.pushCommand.StartCommand.UnmarshalFlag(overrides.StartCmd)
if err != nil {
return err
}
}

// Domain
if len(overrides.Domain) > 0 {
c.pushCommand.Domain = overrides.Domain
}

// HealthCheckType
if len(overrides.HealthCheckType) > 0 {
err := c.pushCommand.HealthCheckType.UnmarshalFlag(overrides.HealthCheckType)
Expand All @@ -170,11 +164,6 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp
}
}

// Hostname
if len(overrides.Host) > 0 {
c.pushCommand.Hostname = overrides.Host
}

// App instances
if overrides.Instances != nil {
c.pushCommand.Instances = flag.Instances{}
Expand All @@ -183,20 +172,12 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp

// Disk Quota
if len(overrides.DiskQuota) > 0 {
c.pushCommand.DiskQuota = flag.Megabytes{}
err := c.pushCommand.DiskQuota.UnmarshalFlag(overrides.DiskQuota)
if err != nil {
return err
}
c.pushCommand.Disk = overrides.DiskQuota
}

// Memory Quota
if len(overrides.MemQuota) > 0 {
c.pushCommand.Memory = flag.Megabytes{}
err := c.pushCommand.Memory.UnmarshalFlag(overrides.MemQuota)
if err != nil {
return err
}
c.pushCommand.Memory = overrides.MemQuota
}

// No Route
Expand All @@ -210,21 +191,21 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp

// Route path
if len(overrides.Path) > 0 {
c.pushCommand.RoutePath = flag.V6RoutePath{}
err := c.pushCommand.RoutePath.UnmarshalFlag(overrides.Path)
if err != nil {
return err
}
c.pushCommand.AppPath = flag.PathWithExistenceCheck(overrides.Path)
}

// Stack
if len(overrides.Stack) > 0 {
c.pushCommand.StackName = overrides.Stack
c.pushCommand.Stack = overrides.Stack
}

// Health check time
if overrides.Time != nil {
c.pushCommand.HealthCheckTimeout = uint64(*overrides.Time)
c.pushCommand.HealthCheckTimeout = flag.PositiveInteger{}
err := c.pushCommand.HealthCheckTimeout.UnmarshalFlag(strconv.Itoa(int(*overrides.Time)))
if err != nil {
return err
}
}

// Docker image
Expand All @@ -243,7 +224,9 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp
}

// Manifest path
c.pushCommand.PathToManifest = flag.PathWithExistenceCheck(manifestPath)
c.pushCommand.PathToManifest = flag.ManifestPathWithExistenceCheck(manifestPath)
c.pushCommand.ManifestLocator = manifestparser.NewLocator()
c.pushCommand.ManifestParser = manifestparser.ManifestParser{}

return nil
}
Expand All @@ -252,12 +235,13 @@ func (c *CFPushApp) Init(appDir string, manifestPath string, overrides CFPushApp
func (c *CFPushApp) setConfig(config *configv3.Config) error {
config.SetOrganizationInformation(c.config.OrgGUID, c.config.OrgName)
config.SetSpaceInformation(c.config.SpaceGUID, c.config.SpaceName, false)
c.pushCommand.VersionActor = c.pushCommand.Actor
c.pushCommand.PushActor = v7pushaction.NewActor(c.pushCommand.Actor, sharedaction.NewActor(config))
return nil
}

// Run performs the actual push
func (c *CFPushApp) Run(msgSender DeployAppMessageSender, clientWebsocket *websocket.Conn) error {

// Get a CF Config
config, err := configv3.LoadConfig()
if err != nil {
Expand Down Expand Up @@ -285,7 +269,11 @@ func (c *CFPushApp) Run(msgSender DeployAppMessageSender, clientWebsocket *webso
defer commandUI.FlushDeferred()

err = c.setup(config, commandUI, msgSender, clientWebsocket)
//err = c.pushCommand.Setup(config, commandUI)
if err != nil {
return handleError(err, *commandUI)
}

err = c.pushCommand.Setup(config, commandUI)
if err != nil {
return handleError(err, *commandUI)
}
Expand All @@ -298,6 +286,7 @@ func (c *CFPushApp) Run(msgSender DeployAppMessageSender, clientWebsocket *webso

// Set to a null progress bar
c.pushCommand.ProgressBar = &cfPushProgressBar{}
c.pushCommand.DiffDisplayer = shared.NewManifestDiffDisplayer(commandUI)

// Perform the push
args := make([]string, 0)
Expand All @@ -316,7 +305,7 @@ func (c *CFPushApp) setup(config command.Config, ui command.UI, msgSender Deploy
sharedActor := sharedaction.NewActor(config)
cmd.SharedActor = sharedActor

ccClient, uaaClient, err := shared.GetNewClientsAndConnectToCF(config, ui)
ccClient, uaaClient, routingClient, err := shared.GetNewClientsAndConnectToCF(config, ui, ccversion.MinSupportedV2ClientVersion)
if err != nil {
return err
}
Expand All @@ -330,26 +319,15 @@ func (c *CFPushApp) setup(config command.Config, ui command.UI, msgSender Deploy

ccClient.WrapConnection(pushConnectionWrapper)

ccClientV3, _, err := sharedV3.NewV3BasedClients(config, ui, true)
ccClientV3 := shared.NewWrappedCloudControllerClient(config, ui, pushConnectionWrapper)
if err != nil {
return err
}

v2Actor := v2action.NewActor(ccClient, uaaClient, config)
v3Actor := v3action.NewActor(ccClientV3, config, sharedActor, nil)

stratosV2Actor := cfV2Actor{
wrapped: v2Actor,
msgSender: msgSender,
clientWebsocket: clientWebsocket,
}

cmd.RestartActor = v2Actor
cmd.Actor = pushaction.NewActor(stratosV2Actor, v3Actor, sharedActor)

cmd.ApplicationSummaryActor = v2v3action.NewActor(v2Actor, v3Actor)
ccClientV3.Requester = ccClient.Requester
v7Actor := v7action.NewActor(ccClientV3, config, sharedActor, uaaClient, routingClient, clock.NewClock())

cmd.NOAAClient = shared.NewNOAAClient(ccClient.DopplerEndpoint(), config, uaaClient, ui)
cmd.Actor = v7Actor

cmd.ProgressBar = progressbar.NewProgressBar()
return nil
Expand Down