// UpdateServiceProfile updates the given service-profile.
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
}
1177683
func (f *Facade) UpdateServiceConfig(ctx datastore.Context, fileID string, conf servicedefinition.ConfigFile) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.UpdateServiceConfig"))
	logger := plog.WithFields(log.Fields{
		"fileid":   fileID,
		"filename": conf.Filename,
	})

	alog := f.auditLogger.Message(ctx, "Updating Service Configuration").
		Action(audit.Update).ID(fileID).Type(servicedefinition.GetConfigFileType()).
		WithField("path", conf.Filename)

	file := &serviceconfigfile.SvcConfigFile{}
	if err := f.configStore.Get(ctx, serviceconfigfile.Key(fileID), file); err != nil {
		logger.WithError(err).Debug("Could not get service config file")
		return alog.Error(err)
	}

	alog = alog.WithField("servicepath", file.ServicePath)

	// update the database record for the file
	file.ConfFile = conf

	// write the record into the database
	if err := f.configStore.Put(ctx, serviceconfigfile.Key(fileID), file); err != nil {
		logger.WithError(err).Debug("Could not update record in database")
		return alog.Error(err)
	}

	logger.Debug("Updated service config file")
	alog.Succeeded()
	return nil
}
144983
func UpdateRoutingProfile(db sqlx.Execer, rp *RoutingProfile) error {
	rp.UpdatedAt = time.Now()
	res, err := db.Exec(`
		update routing_profile set
			updated_at = $2,
			as_id = $3,
			ca_cert = $4,
			tls_cert = $5,
			tls_key = $6
		where
			routing_profile_id = $1`,
		rp.ID,
		rp.UpdatedAt,
		rp.ASID,
		rp.CACert,
		rp.TLSCert,
		rp.TLSKey,
	)
	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", rp.ID).Info("routing-profile updated")
	return nil
}
923593
func UpdateServices(conn client.Connection, svcs []*service.Service, setLockOnCreate, setLockOnUpdate bool) error {
	poolLogger := plog.WithFields(log.Fields{
		"poolid":       svcs[0].PoolID,
		"servicecount": len(svcs),
	})

	// create the /services path if it doesn't exist
	if err := conn.CreateIfExists("/services", &client.Dir{}); err != nil && err != client.ErrNodeExists {
		poolLogger.WithError(err).Error("Could not initialize services path in zookeeper")
		return &ServiceError{
			Action:  "update",
			Message: "could not initialize services path in zookeeper",
		}
	}

	for _, svc := range svcs {
		pth := path.Join("/services", svc.ID)
		logger := poolLogger.WithFields(log.Fields{
			"zkpath": pth,
		})
		//
		// create the service if it doesn't exist
		// setLockOnCreate sets the lock as the node is created
		sn, err := NewServiceNodeFromService(svc)
		if err != nil {
			logger.WithError(err).Error("Could not create service node from service")
			return &ServiceError{
				Action:    "update",
				ServiceID: svc.ID,
				Message:   "could not create service node from service",
			}
		}

		sn.Locked = setLockOnCreate
		if err := conn.CreateIfExists(pth, sn); err == client.ErrNodeExists {

			// the node exists so get it and update it
			node := &ServiceNode{}
			if err := conn.Get(pth, node); err != nil && err != client.ErrEmptyNode {
				logger.WithError(err).Error("Could not get service entry from zookeeper")
				return &ServiceError{
					Action:    "update",
					ServiceID: svc.ID,
					Message:   "could not get service for update",
				}
			}

			// setLockOnUpdate sets the lock to true if enabled, otherwise it uses
			// whatever existing value was previously set on the node.
			if setLockOnUpdate {
				node.Locked = true
			}
			sn.SetVersion(node.Version())
			if err := conn.Set(pth, sn); err != nil {
				logger.WithError(err).Error("Could not update service entry in zookeeper")
				return &ServiceError{
					Action:    "update",
					ServiceID: svc.ID,
					Message:   "could not update service",
				}
			}

			logger.Debug("Updated entry for service in zookeeper")
		} else if err != nil {
			logger.WithError(err).Error("Could not create service entry in zookeeper")
			return &ServiceError{
				Action:    "update",
				ServiceID: svc.ID,
				Message:   "could not create service",
			}
		}

	}

	poolLogger.Debug("Created entry for service in zookeeper")
	return nil
}
898275
func Profile(serviceName string,
	serviceDescription string,
	s3Bucket string,
	httpPort int,
	logger *logrus.Logger) error {
	return errors.New("Profile not supported for this binary")
}
82860
func (_m *FacadeInterface) UpdateServiceTemplate(ctx datastore.Context, template servicetemplate.ServiceTemplate, reloadLogstashConfig bool) error {
	ret := _m.Called(ctx, template, reloadLogstashConfig)

	var r0 error
	if rf, ok := ret.Get(0).(func(datastore.Context, servicetemplate.ServiceTemplate, bool) error); ok {
		r0 = rf(ctx, template, reloadLogstashConfig)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
1254394
func (a *Facade) UpdateApplicationsService(args params.UpdateApplicationServiceArgs) (params.ErrorResults, error) {
	result := params.ErrorResults{
		Results: make([]params.ErrorResult, len(args.Args)),
	}
	if len(args.Args) == 0 {
		return result, nil
	}
	for i, appUpdate := range args.Args {
		appTag, err := names.ParseApplicationTag(appUpdate.ApplicationTag)
		if err != nil {
			result.Results[i].Error = common.ServerError(err)
			continue
		}
		app, err := a.state.Application(appTag.Id())
		if err != nil {
			result.Results[i].Error = common.ServerError(err)
			continue
		}
		if err := app.UpdateCloudService(appUpdate.ProviderId, params.NetworkAddresses(appUpdate.Addresses...)); err != nil {
			result.Results[i].Error = common.ServerError(err)
		}
	}
	return result, nil
}
1334098
func (mr *MockCommonAPIClientMockRecorder) ServiceUpdate(ctx, serviceID, version, service, options interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ServiceUpdate", reflect.TypeOf((*MockCommonAPIClient)(nil).ServiceUpdate), ctx, serviceID, version, service, options)
}
808918
func (s *ServiceOfferingService) NewUpdateServiceOfferingParams(id string) *UpdateServiceOfferingParams {
	p := &UpdateServiceOfferingParams{}
	p.p = make(map[string]interface{})
	p.p["id"] = id
	return p
}
849518
func (e Endpoints) PatchProfile(ctx context.Context, id string, p Profile) error {
	request := patchProfileRequest{ID: id, Profile: p}
	response, err := e.PatchProfileEndpoint(ctx, request)
	if err != nil {
		return err
	}
	resp := response.(patchProfileResponse)
	return resp.Err
}
784981
func (c *HyperClient) UpdateService(podID string, services []*types.UserService) error {
	_, err := c.client.ServiceUpdate(
		c.ctx,
		&types.ServiceUpdateRequest{PodID: podID, Services: services},
	)
	if err != nil {
		return err
	}

	return nil
}
738858
func (_m *API) UpdateService(_a0 io.Reader) (*service.ServiceDetails, error) {
	ret := _m.Called(_a0)

	var r0 *service.ServiceDetails
	if rf, ok := ret.Get(0).(func(io.Reader) *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(io.Reader) error); ok {
		r1 = rf(_a0)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}
1178688
func updateServiceLastReported(ds models.DeviceService, lr int64, w http.ResponseWriter) error {
	ds.LastReported = lr
	if err := dbClient.UpdateDeviceService(ds); err != nil {
		http.Error(w, err.Error(), http.StatusServiceUnavailable)
		return err
	}

	return nil
}
426366
func (zk *zkf) UpdateServices(ctx datastore.Context, tenantID string, svcs []*service.Service, setLockOnCreate, setLockOnUpdate bool) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("zzk.UpdateServices"))

	servicesByPool := make(map[string]*[]*service.Service)
	for _, svc := range svcs {
		if poolSvcs, ok := servicesByPool[svc.PoolID]; ok {
			*poolSvcs = append(*poolSvcs, svc)
		} else {
			poolSvcs = &([]*service.Service{svc})
			servicesByPool[svc.PoolID] = poolSvcs
		}
	}

	for poolID, poolSvcs := range servicesByPool {
		poolLogger := plog.WithFields(log.Fields{
			"tenantid":     tenantID,
			"poolid":       poolID,
			"servicecount": len(*poolSvcs),
		})
		// get the pool-based connection to update the service
		poolconn, err := getLocalConnection(ctx, path.Join("/pools", poolID))
		if err != nil {
			poolLogger.WithError(err).Debug("Could not acquire a pool-based connection to update the service in zookeeper")
			return err
		}
		if err := zk.syncServiceRegistry(ctx, tenantID, *poolSvcs); err != nil {
			poolLogger.WithError(err).Debug("Could not sync public endpoints in zookeeper")
			return err
		}
		if err := updateServices(ctx, poolconn, *poolSvcs, setLockOnCreate, setLockOnUpdate); err != nil {
			poolLogger.WithError(err).Debug("Could not update the services in zookeeper")
			return err
		}
		poolLogger.Debug("Updated the pool service(s) in zookeeper")
	}

	return nil
}
660646
func CreateServiceProfile(db sqlx.Execer, sp *ServiceProfile) error {
	now := time.Now()

	if sp.ID == uuid.Nil {
		var err error
		sp.ID, err = uuid.NewV4()
		if err != nil {
			return errors.Wrap(err, "new uuid v4 error")
		}
	}

	sp.CreatedAt = now
	sp.UpdatedAt = now

	_, err := db.Exec(`
		insert into service_profile (
			created_at,
			updated_at,

			service_profile_id,
			ul_rate,
			ul_bucket_size,
			ul_rate_policy,
			dl_rate,
			dl_bucket_size,
			dl_rate_policy,
			add_gw_metadata,
			dev_status_req_freq,
			report_dev_status_battery,
			report_dev_status_margin,
			dr_min,
			dr_max,
			channel_mask,
			pr_allowed,
			hr_allowed,
			ra_allowed,
			nwk_geo_loc,
			target_per,
			min_gw_diversity
		) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)`,
		sp.CreatedAt,
		sp.UpdatedAt,
		sp.ID,
		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, "insert error")
	}

	log.WithFields(log.Fields{
		"id": sp.ID,
	}).Info("service-profile created")

	return nil
}
598053
func (s *storeImpl) updateServiceFromVolatileService(svc *Service, cacheEntry volatileService) {
	svc.DesiredState = cacheEntry.DesiredState
	svc.CurrentState = cacheEntry.CurrentState
}
738941
func FlushServiceProfileCache(p *redis.Pool, id uuid.UUID) error {
	key := fmt.Sprintf(ServiceProfileKeyTempl, id)
	c := p.Get()
	defer c.Close()

	_, err := c.Do("DEL", key)
	if err != nil {
		return errors.Wrap(err, "delete error")
	}
	return nil
}