// DecorateService calls sdhf(...) to satisfy ServiceDecoratorHookHandler
435429
func (sdhf ServiceDecoratorHookFunc) DecorateService(context map[string]interface{},
	serviceName string,
	template *gocf.Template,
	S3Bucket string,
	S3Key string,
	buildID string,
	awsSession *session.Session,
	noop bool,
	logger *logrus.Logger) error {
	return sdhf(context,
		serviceName,
		template,
		S3Bucket,
		S3Key,
		buildID,
		awsSession,
		noop,
		logger)
}
1281148
func InstallService(context Context, binPath string, force bool, timeout time.Duration, log Log) error {
	resolvedBinPath, err := chooseBinPath(binPath)
	if err != nil {
		return err
	}
	log.Debug("Using binPath: %s", resolvedBinPath)

	label := DefaultServiceLabel(context.GetRunMode())
	service := launchd.NewService(label)
	plist, err := keybasePlist(context, resolvedBinPath, label, log)
	if err != nil {
		return err
	}
	UninstallKeybaseServices(context, log)
	log.Debug("Installing service (%s, timeout=%s)", label, timeout)
	if _, err := installKeybaseService(context, service, plist, timeout, log); err != nil {
		log.Errorf("Error installing Keybase service: %s", err)
		pid, err := fallbackStartProcessAndWaitForInfo(context, service, plist, context.GetServiceInfoPath(), timeout, log)
		if err != nil {
			return err
		}
		log.Debug("fallback keybase service started, pid=%d", pid)
		return nil
	}
	log.Debug("keybase service installed via launchd successfully")
	return nil
}
282214
func DeleteService(key ServiceKey) error {
	mutex.Lock()
	defer mutex.Unlock()

	err := deleteServiceLocked(key)
	if err != nil {
		return err
	}

	return nil
}
900522
func (b *FusisBalancer) AddService(svc *types.Service) error {
	// Allocate a new VIP if no address provided
	if svc.Address == "" {
		if err := b.ipam.AllocateVIP(svc); err != nil {
			return err
		}
	}

	return b.store.AddService(svc)
}
1372477
func (m *MockServiceAccess) DiscoverService(arg0 string) (upgradeseries.AgentService, error) {
	ret := m.ctrl.Call(m, "DiscoverService", arg0)
	ret0, _ := ret[0].(upgradeseries.AgentService)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
66664
func (lad *LogAggregatorDecorator) DecorateTemplate(serviceName string,
	lambdaResourceName string,
	lambdaResource gocf.LambdaFunction,
	resourceMetadata map[string]interface{},
	S3Bucket string,
	S3Key string,
	buildID string,
	template *gocf.Template,
	context map[string]interface{},
	logger *logrus.Logger) error {

	// The relay function should consume the stream
	if lad.logRelay.LogicalResourceName() == lambdaResourceName {
		// Need to add a Lambda EventSourceMapping
		eventSourceMappingResourceName := sparta.CloudFormationResourceName("LogAggregator",
			"EventSourceMapping",
			lambdaResourceName)

		template.AddResource(eventSourceMappingResourceName, &gocf.LambdaEventSourceMapping{
			StartingPosition: gocf.String(lad.kinesisMapping.StartingPosition),
			BatchSize:        gocf.Integer(lad.kinesisMapping.BatchSize),
			EventSourceArn:   gocf.GetAtt(lad.kinesisStreamResourceName, "Arn"),
			FunctionName:     gocf.GetAtt(lambdaResourceName, "Arn"),
		})
	} else {
		// The other functions should publish their logs to the stream
		subscriptionName := logAggregatorResName(fmt.Sprintf("Lambda%s", lambdaResourceName))
		subscriptionFilterRes := &gocf.LogsSubscriptionFilter{
			DestinationArn: gocf.GetAtt(lad.kinesisStreamResourceName, "Arn"),
			RoleArn:        gocf.GetAtt(lad.iamRoleNameResourceName, "Arn"),
			LogGroupName: gocf.Join("",
				gocf.String("/aws/lambda/"),
				gocf.Ref(lambdaResourceName)),
			FilterPattern: gocf.String("{$.level = info || $.level = warning || $.level = error }"),
		}
		template.AddResource(subscriptionName, subscriptionFilterRes)
	}
	return nil
}
761
func NewService() *Service {
	s := &Service{
		TokenGenerator: rand.NewTokenGenerator(64),
		IDGenerator:    snowflake.NewIDGenerator(),
		time:           time.Now,
	}
	s.initializeSources(context.TODO())
	return s
}
686179
func (c *AvailableConditionController) addService(obj interface{}) {
	for _, apiService := range c.getAPIServicesFor(obj.(*v1.Service)) {
		c.enqueue(apiService)
	}
}
103654
func NewService(sessionService SessionService, identityService IdentityService, ecdsaKey *ecdsa.PrivateKey) (service *Service, err error) {
	service = &Service{sessionService: sessionService, identityService: identityService, jwtSigningKey: ecdsaKey}
	return
}
1322221
func ReStartService() error {
	// TODO(tsm): refactor to make use of service.RestartableService
	svc, err := discoverService(ServiceName)
	if err != nil {
		return errors.Trace(err)
	}
	return restartService(svc)
}
85585
func (sys *System) detectService() {
	switch DetectService() {
	case "upstart":
		sys.NewService = NewServiceUpstart
	case "systemd":
		sys.NewService = NewServiceSystemd
	case "alpineinit":
		sys.NewService = NewAlpineServiceInit
	default:
		sys.NewService = NewServiceInit
	}
}
1124537
func (c *ServicedCli) cmdServiceTune(ctx *cli.Context) {
	args := ctx.Args()
	if len(args) < 1 {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "tune")
		c.exit(1)
		return
	}

	svcDetails, _, err := c.searchForService(args[0], ctx.Bool("no-prefix-match"))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	service, err := c.driver.GetService(svcDetails.ID)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	}

	// Check the arguments
	if !(ctx.IsSet("instances") || ctx.IsSet("ramCommitment") || ctx.IsSet("ramThreshold")) {
		fmt.Printf("Incorrect Usage.\n\n")
		cli.ShowCommandHelp(ctx, "tune")
		return
	}

	modified := false
	if ctx.IsSet("instances") {
		oldInstanceCount := service.Instances
		newInstanceCount := ctx.Int("instances")
		if oldInstanceCount != newInstanceCount {
			service.Instances = newInstanceCount
			modified = true
		}
	}

	if ctx.IsSet("ramCommitment") {
		oldCommitment := service.RAMCommitment
		newCommitment, err := utils.NewEngNotationFromString(ctx.String("ramCommitment"))
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			c.exit(1)
			return
		}

		if oldCommitment.Value != newCommitment.Value {
			service.RAMCommitment = newCommitment
			modified = true
		}
	}

	if ctx.IsSet("ramThreshold") {
		oldThreshold := uint64(service.RAMThreshold)
		newThreshold := ctx.String("ramThreshold")

		suffix := newThreshold[len(newThreshold)-1:]
		if suffix != "%" {
			fmt.Fprintln(os.Stderr, fmt.Errorf("ramThreshold '%s' does not end with %%", newThreshold))
			c.exit(1)
			return
		}

		percent := newThreshold[:len(newThreshold)-1]
		val, err := strconv.ParseUint(percent, 10, 64)
		if err != nil {
			fmt.Fprintln(os.Stderr, fmt.Errorf("ramThreshold '%s' must be an integer", newThreshold))
			c.exit(1)
			return
		}

		if oldThreshold != val {
			service.RAMThreshold = uint(val)
			modified = true
		}
	}

	if modified {
		if service, err := c.driver.UpdateServiceObj(*service); err != nil {
			fmt.Fprintln(os.Stderr, err)
		} else if service == nil {
			fmt.Fprintln(os.Stderr, "received nil service")
			c.exit(1)
			return
		} else {
			fmt.Println(service.ID)
		}
	} else {
		fmt.Printf("Service already reflects desired configured - no changes made\n\n")
		return
	}

}
1033884
func (d *decorator) Decorate(proposal *peer.Proposal, input *peer.ChaincodeInput) *peer.ChaincodeInput {
	return input
}
849646
func (s *Store) AddService(service string, config *discoverd.ServiceConfig) error {
	if config == nil {
		config = DefaultServiceConfig
	}

	// Serialize command.
	cmd, err := json.Marshal(&addServiceCommand{
		Service: service,
		Config:  config,
	})
	if err != nil {
		return err
	}

	if _, err := s.raftApply(addServiceCommandType, cmd); err != nil {
		return err
	}
	return err
}
1259023
func (extension EncoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder {
	return encoder
}
909575
func decorate(s string) string {
	file, line, ok := callerinfo() // decorate + log + public function.
	if ok {
		// Truncate file name at last file name separator.
		if index := strings.LastIndex(file, "/"); index >= 0 {
			file = file[index+1:]
		} else if index = strings.LastIndex(file, "\\"); index >= 0 {
			file = file[index+1:]
		}
	} else {
		file = "???"
		line = 1
	}
	buf := new(bytes.Buffer)
	// Every line is indented at least one tab.
	buf.WriteByte('\t')
	fmt.Fprintf(buf, "%s:%d: ", file, line)
	lines := strings.Split(s, "\n")
	if l := len(lines); l > 1 && lines[l-1] == "" {
		lines = lines[:l-1]
	}
	for i, line := range lines {
		if i > 0 {
			// Second and subsequent lines are indented an extra tab.
			buf.WriteString("\n\t\t")
		}
		buf.WriteString(line)
	}
	buf.WriteByte('\n')
	return buf.String()
}
1156663
func (_m *API) AddService(_a0 api.ServiceConfig) (*service.ServiceDetails, error) {
	ret := _m.Called(_a0)

	var r0 *service.ServiceDetails
	if rf, ok := ret.Get(0).(func(api.ServiceConfig) *service.ServiceDetails); ok {
		r0 = rf(_a0)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(*service.ServiceDetails)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(api.ServiceConfig) error); ok {
		r1 = rf(_a0)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}