// UpdateService adds or updates the given service in the bpf maps (in both -
// legacy and v2).
519120
func UpdateService(fe ServiceKey, backends []ServiceValue,
	addRevNAT bool, revNATID int,
	isLegacySVCEnabled bool,
	acquireBackendID func(loadbalancer.L3n4Addr) (loadbalancer.BackendID, error),
	releaseBackendID func(loadbalancer.BackendID)) error {

	var (
		weights         []uint16
		nNonZeroWeights uint16
	)

	// Find out which backends are new (i.e. the ones which do not exist yet and
	// will be created in this function) and acquire IDs for them
	newBackendIDs, err := acquireNewBackendIDs(backends, acquireBackendID)
	if err != nil {
		return err
	}

	// Store mapping of backend addr ID => backend ID in the cache
	cache.addBackendIDs(newBackendIDs)

	// Prepare the service cache for the updates
	svc, addedBackends, removedBackendIDs, err := cache.prepareUpdate(fe, backends)
	if err != nil {
		return err
	}

	// FIXME(brb) Uncomment the following code after we have enabled weights
	// in the BPF datapath code.
	//for _, be := range besValues {
	//	weights = append(weights, be.GetWeight())
	//	if be.GetWeight() != 0 {
	//		nNonZeroWeights++
	//	}
	//}

	mutex.Lock()
	defer mutex.Unlock()

	besValuesV2 := svc.getBackendsV2()

	log.WithFields(logrus.Fields{
		"frontend": fe,
		"backends": besValuesV2,
	}).Debugf("Updating BPF representation of service")

	// Add the new backends to the BPF maps
	if err := updateBackendsLocked(addedBackends); err != nil {
		return err
	}

	if isLegacySVCEnabled {
		besValues := svc.getBackends()
		// Update the legacy service BPF maps
		if err := updateServiceLegacyLocked(fe, besValues, addRevNAT, revNATID,
			weights, nNonZeroWeights); err != nil {
			return err
		}
	}

	// Update the v2 service BPF maps
	if err := updateServiceV2Locked(fe, besValuesV2, svc, addRevNAT, revNATID,
		weights, nNonZeroWeights, isLegacySVCEnabled); err != nil {
		return err
	}

	// Delete no longer needed backends
	if err := removeBackendsLocked(removedBackendIDs, fe.IsIPv6(),
		releaseBackendID); err != nil {
		return err
	}

	return nil
}
559272
func (g *Orchestrator) updateService(service *api.Service) {
	var constraints []constraint.Constraint

	if service.Spec.Task.Placement != nil && len(service.Spec.Task.Placement.Constraints) != 0 {
		constraints, _ = constraint.Parse(service.Spec.Task.Placement.Constraints)
	}

	g.globalServices[service.ID] = globalService{
		Service:     service,
		constraints: constraints,
	}
}
704277
func (s *NetworkService) UpdateNetworkServiceProvider(p *UpdateNetworkServiceProviderParams) (*UpdateNetworkServiceProviderResponse, error) {
	resp, err := s.cs.newRequest("updateNetworkServiceProvider", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r UpdateNetworkServiceProviderResponse
	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
}
553904
func (s *DescribeTaskSetsInput) SetService(v string) *DescribeTaskSetsInput {
	s.Service = &v
	return s
}
555864
func updateServiceLastConnected(ds models.DeviceService, lc int64, w http.ResponseWriter) error {
	ds.LastConnected = lc

	if err := dbClient.UpdateDeviceService(ds); err != nil {
		http.Error(w, err.Error(), http.StatusServiceUnavailable)
		return err
	}

	return nil
}
549251
func (s *UpdateTaskSetInput) SetService(v string) *UpdateTaskSetInput {
	s.Service = &v
	return s
}
1257822
func (s *Service) UpdateSource(ctx context.Context, id platform.ID, upd platform.SourceUpdate) (*platform.Source, error) {
	src, err := s.FindSourceByID(ctx, id)
	if err != nil {
		return nil, &platform.Error{
			Err: err,
			Op:  OpPrefix + platform.OpUpdateSource,
		}
	}

	upd.Apply(src)
	s.sourceKV.Store(src.ID.String(), src)
	return src, nil
}
161443
func (c *aPIServices) Update(aPIService *v1beta1.APIService) (result *v1beta1.APIService, err error) {
	result = &v1beta1.APIService{}
	err = c.client.Put().
		Resource("apiservices").
		Name(aPIService.Name).
		Body(aPIService).
		Do().
		Into(result)
	return
}
37036
func (f *Facade) UpdateServiceCache(ctx datastore.Context) error {
	svcNodes, err := f.zzk.GetServiceNodes()
	if err != nil {
		return err
	}
	for _, svcNode := range svcNodes {
		f.serviceStore.UpdateDesiredState(ctx, svcNode.ID, svcNode.DesiredState)
	}
	return nil
}
977229
func UpdateServiceProfile(db sqlx.Execer, sp *ServiceProfile) error {
	sp.UpdatedAt = time.Now()

	res, err := db.Exec(`
		update service_profile set
			updated_at = $2,

			ul_rate = $3,
			ul_bucket_size = $4,
			ul_rate_policy = $5,
			dl_rate = $6,
			dl_bucket_size = $7,
			dl_rate_policy = $8,
			add_gw_metadata = $9,
			dev_status_req_freq = $10,
			report_dev_status_battery = $11,
			report_dev_status_margin = $12,
			dr_min = $13,
			dr_max = $14,
			channel_mask = $15,
			pr_allowed = $16,
			hr_allowed = $17,
			ra_allowed = $18,
			nwk_geo_loc = $19,
			target_per = $20,
			min_gw_diversity = $21
		where
			service_profile_id = $1`,
		sp.ID,
		sp.UpdatedAt,
		sp.ULRate,
		sp.ULBucketSize,
		sp.ULRatePolicy,
		sp.DLRate,
		sp.DLBucketSize,
		sp.DLRatePolicy,
		sp.AddGWMetadata,
		sp.DevStatusReqFreq,
		sp.ReportDevStatusBattery,
		sp.ReportDevStatusMargin,
		sp.DRMin,
		sp.DRMax,
		sp.ChannelMask,
		sp.PRAllowed,
		sp.HRAllowed,
		sp.RAAllowed,
		sp.NwkGeoLoc,
		sp.TargetPER,
		sp.MinGWDiversity,
	)
	if err != nil {
		return handlePSQLError(err, "update error")
	}
	ra, err := res.RowsAffected()
	if err != nil {
		return handlePSQLError(err, "get rows affected error")
	}
	if ra == 0 {
		return ErrDoesNotExist
	}

	log.WithField("id", sp.ID).Info("service-profile updated")
	return nil
}
1225809
func (s *storeImpl) GetUpdatedServices(ctx datastore.Context, since time.Duration) ([]Service, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("ServiceStore.GetUpdatedServices"))
	q := datastore.NewQuery(ctx)
	t0 := time.Now().Add(-since)
	t0s := t0.Format(time.RFC3339)
	elasticQuery := search.Query().Range(search.Range().Field("UpdatedAt").From(t0s)).Search("_exists_:ID")
	search := search.Search("controlplane").Type(kind).Size("50000").Query(elasticQuery)
	results, err := q.Execute(search)
	if err != nil {
		return nil, err
	}
	// First get the list of updated services from Elastic.
	svcs, err := s.convert(results)
	if err != nil {
		return nil, err
	}
	// Then add updated services from the cache
	return s.addUpdatedServicesFromCache(ctx, svcs, t0)
}
846675
func (self *Service) Update(createRequest ServiceCreateRequest) error {

	url := "service/" + self.Uuid + "/"
	request := "PATCH"

	updatedService, err := json.Marshal(createRequest)
	if err != nil {
		return err
	}

	_, err = TutumCall(url, request, updatedService)
	if err != nil {
		return err
	}

	return nil
}
376984
func (s *GetServiceOutput) SetService(v *Service) *GetServiceOutput {
	s.Service = v
	return s
}
168348
func (c *FakeServiceAccounts) Update(serviceAccount *corev1.ServiceAccount) (result *corev1.ServiceAccount, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewUpdateAction(serviceaccountsResource, c.ns, serviceAccount), &corev1.ServiceAccount{})

	if obj == nil {
		return nil, err
	}
	return obj.(*corev1.ServiceAccount), err
}
1044903
func (s *ServiceCache) UpdateService(k8sSvc *types.Service) ServiceID {
	svcID, newService := ParseService(k8sSvc)
	if newService == nil {
		return svcID
	}

	s.mutex.Lock()
	defer s.mutex.Unlock()

	if oldService, ok := s.services[svcID]; ok {
		if oldService.DeepEquals(newService) {
			return svcID
		}
	}

	s.services[svcID] = newService

	// Check if the corresponding Endpoints resource is already available
	endpoints, serviceReady := s.correlateEndpoints(svcID)
	if serviceReady {
		s.Events <- ServiceEvent{
			Action:    UpdateService,
			ID:        svcID,
			Service:   newService,
			Endpoints: endpoints,
		}
	}

	return svcID
}
212163
func (s *Service) UpdateService(w http.ResponseWriter, r *http.Request) {
	id, err := paramID("kid", r)
	if err != nil {
		Error(w, http.StatusUnprocessableEntity, err.Error(), s.Logger)
		return
	}

	srcID, err := paramID("id", r)
	if err != nil {
		Error(w, http.StatusUnprocessableEntity, err.Error(), s.Logger)
		return
	}

	ctx := r.Context()
	srv, err := s.Store.Servers(ctx).Get(ctx, id)
	if err != nil || srv.SrcID != srcID || srv.Type == "" {
		notFound(w, id, s.Logger)
		return
	}

	var req patchServiceRequest
	if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
		invalidJSON(w, s.Logger)
		return
	}

	if err := req.Valid(); err != nil {
		invalidData(w, err, s.Logger)
		return
	}

	if req.Name != nil {
		srv.Name = *req.Name
	}
	if req.Type != nil {
		srv.Type = *req.Type
	}
	if req.URL != nil {
		srv.URL = *req.URL
	}
	if req.Password != nil {
		srv.Password = *req.Password
	}
	if req.Username != nil {
		srv.Username = *req.Username
	}
	if req.InsecureSkipVerify != nil {
		srv.InsecureSkipVerify = *req.InsecureSkipVerify
	}
	if req.Metadata != nil {
		srv.Metadata = *req.Metadata
	}

	if srv.Type == "flux" {
		err := pingFlux(ctx, srv.URL, srv.InsecureSkipVerify)
		if err != nil {
			msg := fmt.Sprintf("Unable to reach flux %s: %v", srv.URL, err)
			Error(w, http.StatusGatewayTimeout, msg, s.Logger)
			return
		}
	}

	if err := s.Store.Servers(ctx).Update(ctx, srv); err != nil {
		msg := fmt.Sprintf("Error updating service ID %d", id)
		Error(w, http.StatusInternalServerError, msg, s.Logger)
		return
	}

	res := newService(srv)
	encodeJSON(w, http.StatusOK, res, s.Logger)
}
1294455
func (s *UpdateServiceOutput) SetService(v *Service) *UpdateServiceOutput {
	s.Service = v
	return s
}