// AddAPIServiceToSyncOnStart registers an API service to sync only when the controller starts.
514527
func (c *autoRegisterController) AddAPIServiceToSyncOnStart(in *apiregistration.APIService) {
	c.addAPIServiceToSync(in, manageOnStart)
}
556771
func (s *NetworkService) AddNetworkServiceProvider(p *AddNetworkServiceProviderParams) (*AddNetworkServiceProviderResponse, error) {
	resp, err := s.cs.newRequest("addNetworkServiceProvider", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r AddNetworkServiceProviderResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
364159
func (c *autoRegisterController) RemoveAPIServiceToSync(name string) {
	c.apiServicesToSyncLock.Lock()
	defer c.apiServicesToSyncLock.Unlock()

	delete(c.apiServicesToSync, name)
	c.queue.Add(name)
}
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
}
255326
func (a *Agent) addServiceInternal(service *structs.NodeService, chkTypes []*structs.CheckType, persist bool, token string, source configSource) error {
	// Pause the service syncs during modification
	a.PauseSync()
	defer a.ResumeSync()

	// Take a snapshot of the current state of checks (if any), and
	// restore them before resuming anti-entropy.
	snap := a.snapshotCheckState()
	defer a.restoreCheckState(snap)

	var checks []*structs.HealthCheck

	// Create an associated health check
	for i, chkType := range chkTypes {
		checkID := string(chkType.CheckID)
		if checkID == "" {
			checkID = fmt.Sprintf("service:%s", service.ID)
			if len(chkTypes) > 1 {
				checkID += fmt.Sprintf(":%d", i+1)
			}
		}
		name := chkType.Name
		if name == "" {
			name = fmt.Sprintf("Service '%s' check", service.Service)
		}
		check := &structs.HealthCheck{
			Node:        a.config.NodeName,
			CheckID:     types.CheckID(checkID),
			Name:        name,
			Status:      api.HealthCritical,
			Notes:       chkType.Notes,
			ServiceID:   service.ID,
			ServiceName: service.Service,
			ServiceTags: service.Tags,
		}
		if chkType.Status != "" {
			check.Status = chkType.Status
		}

		checks = append(checks, check)
	}

	// cleanup, store the ids of services and checks that weren't previously
	// registered so we clean them up if somthing fails halfway through the
	// process.
	var cleanupServices []string
	var cleanupChecks []types.CheckID

	if s := a.State.Service(service.ID); s == nil {
		cleanupServices = append(cleanupServices, service.ID)
	}

	for _, check := range checks {
		if c := a.State.Check(check.CheckID); c == nil {
			cleanupChecks = append(cleanupChecks, check.CheckID)
		}
	}

	err := a.State.AddServiceWithChecks(service, checks, token)
	if err != nil {
		a.cleanupRegistration(cleanupServices, cleanupChecks)
		return err
	}

	for i := range checks {
		if err := a.addCheck(checks[i], chkTypes[i], service, persist, token, source); err != nil {
			a.cleanupRegistration(cleanupServices, cleanupChecks)
			return err
		}

		if persist && a.config.DataDir != "" {
			if err := a.persistCheck(checks[i], chkTypes[i]); err != nil {
				a.cleanupRegistration(cleanupServices, cleanupChecks)
				return err

			}
		}
	}

	// Persist the service to a file
	if persist && a.config.DataDir != "" {
		if err := a.persistService(service); err != nil {
			a.cleanupRegistration(cleanupServices, cleanupChecks)
			return err
		}
	}

	return nil
}
1205709
func (f *Facade) validateServiceStart(ctx datastore.Context, svc *service.Service) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.validateServiceStart"))
	logger := plog.WithFields(log.Fields{
		"service": svc.Name,
		"id":      svc.ID,
		"parentserviceid": svc.ParentServiceID,
	})

	if svc.EmergencyShutdown {
		return ErrEmergencyShutdownNoOp
	}

	// Make sure the tenant mount is right: CC-3536
	if err := f.verifyTenantMounts(ctx, svc); err != nil {
		logger.WithError(err).Error("Tenant Mount and Export are inconsistent")
		return err
	}

	// ensure that all endpoints are available
	for _, ep := range svc.Endpoints {
		if ep.IsConfigurable() {
			as, err := f.FindAssignmentByServiceEndpoint(ctx, svc.ID, ep.Name)
			if err != nil {
				logger.WithField("epname", ep.Name).WithError(err).Error("Could not look up assignment")
				return err
			}
			if as == nil {
				return ErrServiceMissingAssignment
			}
		}
	}

	if err := validateServiceOptions(svc); err != nil {
		logger.WithError(err).Error("Could not start service")
		return err
	}

	return nil
}
333274
func (i *injector) AddServices(vals ...interface{}) {
	for _, v := range vals {
		i.AddService(v)
	}
}
651981
func (s *UCSService) AddUcsManager(p *AddUcsManagerParams) (*AddUcsManagerResponse, error) {
	resp, err := s.cs.newRequest("addUcsManager", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r AddUcsManagerResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
902176
func (_m *Balancer) AddService(_a0 *types.Service) error {
	ret := _m.Called(_a0)

	var r0 error
	if rf, ok := ret.Get(0).(func(*types.Service) error); ok {
		r0 = rf(_a0)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
799993
func (c *Client) AddUnits(args AddUnitsParams) ([]string, error) {
	if len(args.AttachStorage) > 0 {
		if args.NumUnits != 1 {
			return nil, errors.New("cannot attach existing storage when more than one unit is requested")
		}
		if c.BestAPIVersion() < 5 {
			return nil, errors.New("this juju controller does not support AttachStorage")
		}
	}
	attachStorage := make([]string, len(args.AttachStorage))
	for i, id := range args.AttachStorage {
		if !names.IsValidStorage(id) {
			return nil, errors.NotValidf("storage ID %q", id)
		}
		attachStorage[i] = names.NewStorageTag(id).String()
	}
	results := new(params.AddApplicationUnitsResults)
	err := c.facade.FacadeCall("AddUnits", params.AddApplicationUnits{
		ApplicationName: args.ApplicationName,
		NumUnits:        args.NumUnits,
		Placement:       args.Placement,
		Policy:          args.Policy,
		AttachStorage:   attachStorage,
	}, results)
	return results.Units, err
}
736430
func (actor Actor) BindServiceByApplicationAndServiceInstance(appGUID string, serviceInstanceGUID string) (Warnings, error) {
	_, warnings, err := actor.CloudControllerClient.CreateServiceBinding(appGUID, serviceInstanceGUID, "", false, nil)

	return Warnings(warnings), err
}
777047
func (c FakeClient) AddDockerResource(id *charm.URL, resourceName string, imageName, digest string) (revision int, err error) {
	return -1, nil
}
616571
func (r *proxyHandler) updateAPIService(apiService *apiregistrationapi.APIService) {
	if apiService.Spec.Service == nil {
		r.handlingInfo.Store(proxyHandlingInfo{local: true})
		return
	}

	newInfo := proxyHandlingInfo{
		name: apiService.Name,
		restConfig: &restclient.Config{
			TLSClientConfig: restclient.TLSClientConfig{
				Insecure:   apiService.Spec.InsecureSkipTLSVerify,
				ServerName: apiService.Spec.Service.Name + "." + apiService.Spec.Service.Namespace + ".svc",
				CertData:   r.proxyClientCert,
				KeyData:    r.proxyClientKey,
				CAData:     apiService.Spec.CABundle,
			},
		},
		serviceName:      apiService.Spec.Service.Name,
		serviceNamespace: apiService.Spec.Service.Namespace,
		servicePort:      apiService.Spec.Service.Port,
		serviceAvailable: apiregistrationapi.IsAPIServiceConditionTrue(apiService, apiregistrationapi.Available),
	}
	if r.proxyTransport != nil && r.proxyTransport.DialContext != nil {
		newInfo.restConfig.Dial = r.proxyTransport.DialContext
	}
	newInfo.proxyRoundTripper, newInfo.transportBuildingError = restclient.TransportFor(newInfo.restConfig)
	if newInfo.transportBuildingError != nil {
		klog.Warning(newInfo.transportBuildingError.Error())
	}
	r.handlingInfo.Store(newInfo)
}
1041742
func (c *AggregationController) RemoveAPIService(apiServiceName string) {
	if err := c.openAPIAggregationManager.RemoveAPIServiceSpec(apiServiceName); err != nil {
		utilruntime.HandleError(fmt.Errorf("removing %q from AggregationController failed with: %v", apiServiceName, err))
	}
	// This will only remove it if it was failing before. If it was successful, processNextWorkItem will figure it out
	// and will not add it again to the queue.
	c.queue.Forget(apiServiceName)
}
1212231
func (state *ServicesState) AddServiceEntry(newSvc service.Service) {
	defer metrics.MeasureSince([]string{"services_state", "AddServiceEntry"}, time.Now())

	state.Lock()
	defer state.Unlock()

	if !state.HasServer(newSvc.Hostname) {
		state.Servers[newSvc.Hostname] = NewServer(newSvc.Hostname)
	}

	server := state.Servers[newSvc.Hostname]

	// Only apply changes that are newer or services are missing
	if !server.HasService(newSvc.ID) {
		server.Services[newSvc.ID] = &newSvc
		state.ServiceChanged(&newSvc, service.UNKNOWN, newSvc.Updated)
		state.retransmit(newSvc)
	} else if newSvc.Invalidates(server.Services[newSvc.ID]) {
		// We have to set these even if the status did not change
		server.LastUpdated = newSvc.Updated

		// Store the previous newSvc so we can compare it
		oldEntry := server.Services[newSvc.ID]

		// Update the new one
		server.Services[newSvc.ID] = &newSvc

		// When the status changes, the SeviceChanged() method will
		// update all the accounting fields in the state and Server newSvc.
		if oldEntry.Status != newSvc.Status {
			state.ServiceChanged(&newSvc, oldEntry.Status, newSvc.Updated)
		}

		// We tell our gossip peers about the updated service
		// by sending them the record. We're saved from an endless
		// retransmit loop by the Invalidates() call above.
		state.retransmit(newSvc)
	}
}
749211
func (s *StorageAPI) AddUnitStorage(
	args params.StoragesAddParams,
) (params.ErrorResults, error) {
	canAccess, err := s.accessUnit()
	if err != nil {
		return params.ErrorResults{}, err
	}
	if len(args.Storages) == 0 {
		return params.ErrorResults{}, nil
	}

	serverErr := func(err error) params.ErrorResult {
		return params.ErrorResult{common.ServerError(err)}
	}

	storageErr := func(err error, s, u string) params.ErrorResult {
		return serverErr(errors.Annotatef(err, "adding storage %v for %v", s, u))
	}

	result := make([]params.ErrorResult, len(args.Storages))
	for i, one := range args.Storages {
		u, err := accessUnitTag(one.UnitTag, canAccess)
		if err != nil {
			result[i] = serverErr(err)
			continue
		}

		cons, err := unitStorageConstraints(s.backend, u)
		if err != nil {
			result[i] = serverErr(err)
			continue
		}

		oneCons, err := validConstraints(one, cons)
		if err != nil {
			result[i] = storageErr(err, one.StorageName, one.UnitTag)
			continue
		}

		_, err = s.storage.AddStorageForUnit(u, one.StorageName, oneCons)
		if err != nil {
			result[i] = storageErr(err, one.StorageName, one.UnitTag)
		}
	}
	return params.ErrorResults{Results: result}, nil
}
1142043
func ValidateAPIServiceStatusUpdate(newAPIService *apiregistration.APIService, oldAPIService *apiregistration.APIService) field.ErrorList {
	allErrs := validation.ValidateObjectMetaUpdate(&newAPIService.ObjectMeta, &oldAPIService.ObjectMeta, field.NewPath("metadata"))
	allErrs = append(allErrs, ValidateAPIServiceStatus(&newAPIService.Status, field.NewPath("status"))...)
	return allErrs
}