services/api/app/controllers/arvados/v1/users_controller.rb
# Internal API used by controller to update local cache of user
# records from LoginCluster.
Internal API used by controller to update local cache of user
records from LoginCluster.
Internal API used by controller to update local cache of user records from LoginCluster .
def batch_update
    @objects = []
    params[:updates].andand.each do |uuid, attrs|
      begin
        u = User.find_or_create_by(uuid: uuid)
      rescue ActiveRecord::RecordNotUnique
        retry
      end
      needupdate = {}
      nullify_attrs(attrs).each do |k,v|
        if !v.nil? && u.send(k) != v
          needupdate[k] = v
        end
      end
      if needupdate.length > 0
        begin
          u.update_attributes!(needupdate)
        rescue ActiveRecord::RecordInvalid
          loginCluster = Rails.configuration.Login.LoginCluster
          if u.uuid[0..4] == loginCluster && !needupdate[:username].nil?
            local_user = User.find_by_username(needupdate[:username])
            if local_user.andand.uuid[0..4] == loginCluster && local_user.uuid != u.uuid
              new_username = "#{needupdate[:username]}conflict#{rand(99999999)}"
              Rails.logger.warn("cached username '#{needupdate[:username]}' collision with user '#{local_user.uuid}' - renaming to '#{new_username}' before retrying")
              local_user.update_attributes!({username: new_username})
              retry
            end
          end
          raise 
        end
      end
      @objects << u
    end
    @offset = 0
    @limit = -1
    render_list
  end
def batch_update @objects = [ ] params [ :updates ] . andand . each do | uuid , attrs | begin u = User . find_or_create_by ( uuid : uuid ) rescue ActiveRecord :: RecordNotUnique retry end needupdate = { } nullify_attrs ( attrs ) . each do | k , v | if ! v . nil? && u . send ( k ) != v needupdate [ k ] = v end end if needupdate . length > 0 begin u . update_attributes! ( needupdate ) rescue ActiveRecord :: RecordInvalid loginCluster = Rails . configuration . Login . LoginCluster if u . uuid [ 0 .. 4 ] == loginCluster && ! needupdate [ :username ] . nil? local_user = User . find_by_username ( needupdate [ :username ] ) if local_user . andand . uuid [ 0 .. 4 ] == loginCluster && local_user . uuid != u . uuid new_username = "#{needupdate[:username]}conflict#{rand(99999999)}" Rails . logger . warn ( "cached username '#{needupdate[:username]}' collision with user '#{local_user.uuid}' - renaming to '#{new_username}' before retrying" ) local_user . update_attributes! ( { username : new_username } ) retry end end raise end end @objects << u end @offset = 0 @limit = - 1 render_list end
Internal API used by controller to update local cache of user
records from LoginCluster.
Internal API used by controller to update local cache of user records from LoginCluster .
# A cached user record from the LoginCluster is stale, reset its username # and retry the update operation. # Not the issue we're handling above