func parseMonitor(monitorAction *models.Action) Monitor { monitorRunAction := monitorAction.GetRunAction() if monitorRunAction == nil { return Monitor{} } var port uint16 var uri string for i, arg := range monitorRunAction.Args { if arg == "-port" && len(monitorRunAction.Args) > i+1 { if p, err := strconv.ParseUint(monitorRunAction.Args[i+1], 0, 16); err == nil { port = uint16(p) } } else if arg == "-uri" && len(monitorRunAction.Args) > i+1 { uri = monitorRunAction.Args[i+1] } } if port != 0 || uri != "" { return Monitor{ Port: port, URI: uri, } } else { return Monitor{ Command: monitorRunAction.Path, CommandArgs: monitorRunAction.Args, } } }
func updateTimeoutInAction(logger lager.Logger, action *models.Action) { if action == nil { logger.Debug("no-action-to-convert") return } a := action.GetValue() switch actionModel := a.(type) { case *models.RunAction, *models.DownloadAction, *models.UploadAction: return case *models.TimeoutAction: timeoutAction := actionModel timeoutAction.TimeoutMs = timeoutAction.DeprecatedTimeoutNs / 1000000 case *models.EmitProgressAction: updateTimeoutInAction(logger, actionModel.Action) case *models.TryAction: updateTimeoutInAction(logger, actionModel.Action) case *models.ParallelAction: for _, subaction := range actionModel.Actions { updateTimeoutInAction(logger, subaction) } case *models.SerialAction: for _, subaction := range actionModel.Actions { updateTimeoutInAction(logger, subaction) } case *models.CodependentAction: for _, subaction := range actionModel.Actions { updateTimeoutInAction(logger, subaction) } } }
func (transformer *Transformer) StepFor( logStreamer log_streamer.LogStreamer, action *models.Action, container garden.Container, externalIP string, ports []executor.PortMapping, logger lager.Logger, ) steps.Step { a := action.GetValue() switch actionModel := a.(type) { case *models.RunAction: return steps.NewRun( container, *actionModel, logStreamer.WithSource(actionModel.LogSource), logger, externalIP, ports, transformer.exportNetworkEnvVars, transformer.clock, ) case *models.DownloadAction: return steps.NewDownload( container, *actionModel, transformer.cachedDownloader, transformer.downloadLimiter, logStreamer.WithSource(actionModel.LogSource), logger, ) case *models.UploadAction: return steps.NewUpload( container, *actionModel, transformer.uploader, transformer.compressor, transformer.tempDir, logStreamer.WithSource(actionModel.LogSource), transformer.uploadLimiter, logger, ) case *models.EmitProgressAction: return steps.NewEmitProgress( transformer.StepFor( logStreamer, actionModel.Action, container, externalIP, ports, logger, ), actionModel.StartMessage, actionModel.SuccessMessage, actionModel.FailureMessagePrefix, logStreamer.WithSource(actionModel.LogSource), logger, ) case *models.TimeoutAction: return steps.NewTimeout( transformer.StepFor( logStreamer.WithSource(actionModel.LogSource), actionModel.Action, container, externalIP, ports, logger, ), time.Duration(actionModel.Timeout), logger, ) case *models.TryAction: return steps.NewTry( transformer.StepFor( logStreamer.WithSource(actionModel.LogSource), actionModel.Action, container, externalIP, ports, logger, ), logger, ) case *models.ParallelAction: subSteps := make([]steps.Step, len(actionModel.Actions)) for i, action := range actionModel.Actions { subSteps[i] = transformer.StepFor( logStreamer.WithSource(actionModel.LogSource), action, container, externalIP, ports, logger, ) } return steps.NewParallel(subSteps) case *models.CodependentAction: subSteps := make([]steps.Step, len(actionModel.Actions)) for i, action := range actionModel.Actions { subSteps[i] = transformer.StepFor( logStreamer.WithSource(actionModel.LogSource), action, container, externalIP, ports, logger, ) } errorOnExit := true return steps.NewCodependent(subSteps, errorOnExit) case *models.SerialAction: subSteps := make([]steps.Step, len(actionModel.Actions)) for i, action := range actionModel.Actions { subSteps[i] = transformer.StepFor( logStreamer, action, container, externalIP, ports, logger, ) } return steps.NewSerial(subSteps) } panic(fmt.Sprintf("unknown action: %T", action)) }
Expect(err).NotTo(HaveOccurred()) Expect(json).To(MatchJSON("null")) }) }) It("JSON -> Action for Nil action", func() { By("unwrapping", func() { var unmarshalledAction *models.Action err := json.Unmarshal([]byte("null"), &unmarshalledAction) Expect(err).NotTo(HaveOccurred()) Expect(unmarshalledAction).To(BeNil()) }) }) Describe("Validate", func() { var action *models.Action Context("when the action has no inner actions", func() { It("is valid", func() { action = nil err := action.Validate() Expect(err).NotTo(HaveOccurred()) }) }) }) }) Describe("Download", func() { var downloadAction *models.DownloadAction