func StartRunnerAndMakeConnection(manifest *manifest.Manifest, log *logger.GaugeLogger, killChannel chan bool) (*TestRunner, error) { port, err := conn.GetPortFromEnvironmentVariable(common.GaugePortEnvName) if err != nil { port = 0 } gaugeConnectionHandler, connHandlerErr := conn.NewGaugeConnectionHandler(port, nil) if connHandlerErr != nil { return nil, connHandlerErr } testRunner, err := startRunner(manifest, strconv.Itoa(gaugeConnectionHandler.ConnectionPortNumber()), log, killChannel) if err != nil { return nil, err } runnerConnection, connectionError := gaugeConnectionHandler.AcceptConnection(config.RunnerConnectionTimeout(), testRunner.ErrorChannel) testRunner.Connection = runnerConnection if connectionError != nil { log.Debug("Runner connection error: %s", connectionError) err := testRunner.killRunner() if err != nil { log.Debug("Error while killing runner: %s", err) } return nil, connectionError } return testRunner, nil }
func startAPIService(port int) (error, *gaugeApiMessageHandler) { specInfoGatherer := new(specInfoGatherer) apiHandler := &gaugeApiMessageHandler{specInfoGatherer: specInfoGatherer} gaugeConnectionHandler, err := conn.NewGaugeConnectionHandler(port, apiHandler) if err != nil { return err, nil } if port == 0 { if err := common.SetEnvVariable(common.ApiPortEnvVariableName, strconv.Itoa(gaugeConnectionHandler.ConnectionPortNumber())); err != nil { return errors.New(fmt.Sprintf("Failed to set Env variable %s. %s", common.ApiPortEnvVariableName, err.Error())), nil } } go gaugeConnectionHandler.HandleMultipleConnections() apiHandler.runner = specInfoGatherer.makeListOfAvailableSteps(nil) return nil, apiHandler }
func startPluginsForExecution(manifest *manifest.Manifest) (*Handler, []string) { var warnings []string handler := &Handler{} envProperties := make(map[string]string) for _, pluginID := range manifest.Plugins { pd, err := GetPluginDescriptor(pluginID, "") if err != nil { warnings = append(warnings, fmt.Sprintf("Error starting plugin %s. Failed to get plugin.json. %s. To install, run `gauge --install %s`.", pluginID, err.Error(), pluginID)) continue } compatibilityErr := version.CheckCompatibility(version.CurrentGaugeVersion, &pd.GaugeVersionSupport) if compatibilityErr != nil { warnings = append(warnings, fmt.Sprintf("Compatible %s plugin version to current Gauge version %s not found", pd.Name, version.CurrentGaugeVersion)) continue } if isExecutionScopePlugin(pd) { gaugeConnectionHandler, err := conn.NewGaugeConnectionHandler(0, nil) if err != nil { warnings = append(warnings, err.Error()) continue } envProperties[pluginConnectionPortEnv] = strconv.Itoa(gaugeConnectionHandler.ConnectionPortNumber()) err = SetEnvForPlugin(executionScope, pd, manifest, envProperties) if err != nil { warnings = append(warnings, fmt.Sprintf("Error setting environment for plugin %s %s. %s", pd.Name, pd.Version, err.Error())) continue } plugin, err := StartPlugin(pd, executionScope) if err != nil { warnings = append(warnings, fmt.Sprintf("Error starting plugin %s %s. %s", pd.Name, pd.Version, err.Error())) continue } pluginConnection, err := gaugeConnectionHandler.AcceptConnection(config.PluginConnectionTimeout(), make(chan error)) if err != nil { warnings = append(warnings, fmt.Sprintf("Error starting plugin %s %s. Failed to connect to plugin. %s", pd.Name, pd.Version, err.Error())) plugin.pluginCmd.Process.Kill() continue } plugin.connection = pluginConnection handler.addPlugin(pluginID, plugin) } } return handler, warnings }
func StartAPIService(port int, startChannels *runner.StartChannels) { specInfoGatherer := new(infoGatherer.SpecInfoGatherer) apiHandler := &gaugeApiMessageHandler{specInfoGatherer: specInfoGatherer} gaugeConnectionHandler, err := conn.NewGaugeConnectionHandler(port, apiHandler) if err != nil { startChannels.ErrorChan <- err return } if port == 0 { if err := common.SetEnvVariable(common.ApiPortEnvVariableName, strconv.Itoa(gaugeConnectionHandler.ConnectionPortNumber())); err != nil { startChannels.ErrorChan <- errors.New(fmt.Sprintf("Failed to set Env variable %s. %s", common.ApiPortEnvVariableName, err.Error())) return } } go gaugeConnectionHandler.HandleMultipleConnections() runner, err := specInfoGatherer.MakeListOfAvailableSteps(startChannels.KillChan) if err != nil { startChannels.ErrorChan <- err return } startChannels.RunnerChan <- runner }
// StartAPIService starts the Gauge API service func startAPIService(port int, startChannels *runner.StartChannels, sig *infoGatherer.SpecInfoGatherer) { apiHandler := &gaugeAPIMessageHandler{specInfoGatherer: sig} gaugeConnectionHandler, err := conn.NewGaugeConnectionHandler(port, apiHandler) if err != nil { startChannels.ErrorChan <- fmt.Errorf("Connection error. %s", err.Error()) return } if port == 0 { if err := common.SetEnvVariable(common.APIPortEnvVariableName, strconv.Itoa(gaugeConnectionHandler.ConnectionPortNumber())); err != nil { startChannels.ErrorChan <- fmt.Errorf("Failed to set Env variable %s. %s", common.APIPortEnvVariableName, err.Error()) return } } go gaugeConnectionHandler.HandleMultipleConnections() runner, err := connectToRunner(startChannels.KillChan) if err != nil { startChannels.ErrorChan <- err return } startChannels.RunnerChan <- runner }