#NEWLINE# @ classmethod #NEWLINE# def validate_update( cls , data , instance ) : #NEWLINE# #INDENT# d = cls . validate_json ( data ) #NEWLINE# cls . _validate_common ( d ) #NEWLINE# if db ( ) . query ( models . Release ) . filter_by ( name = d . get ( 'name' , instance . name ) , version = d . get ( 'version' , instance . version ) ) . filter ( sa . not_ ( ( models . Release . id == instance . id ) ) ) . first ( ) : #NEWLINE# #INDENT# raise errors . AlreadyExists ( 'Release with the same name and version already exists' , log_message = True ) #NEWLINE# #UNINDENT# if ( 'roles_metadata' in d ) : #NEWLINE# #INDENT# new_roles = set ( d [ 'roles_metadata' ] ) #NEWLINE# clusters = [ cluster . id for cluster in instance . clusters ] #NEWLINE# new_roles_array = sa . cast ( psql . array ( new_roles ) , psql . ARRAY ( sa . String ( consts . ROLE_NAME_MAX_SIZE ) ) ) #NEWLINE# node = db ( ) . query ( models . Node ) . filter ( models . Node . cluster_id . in_ ( clusters ) ) . filter ( sa . not_ ( sa . and_ ( models . Node . roles . contained_by ( new_roles_array ) , models . Node . pending_roles . contained_by ( new_roles_array ) ) ) ) . first ( ) #NEWLINE# if node : #NEWLINE# #INDENT# used_role = set ( ( node . roles + node . pending_roles ) ) #NEWLINE# used_role -= new_roles #NEWLINE# raise errors . CannotDelete ( 'Cannot delete roles already assigned to nodes: {0}' . format ( ',' . join ( used_role ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# return d