
    !                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ ej                   G d
 dej                               Zy)zGImplementation of update command for updating Anywhere Cache instances.    )arg_parsers)base)flags)progress_callbacks)task_executor)task_graph_executor)task_status)patch_anywhere_cache_taskc                   6    e Zd ZdZdddZed        Zd Zd Zy)	Updatez Update Anywhere Cache instances.z

      Update one or more Anywhere Cache instances. A cache instance can be
      updated if its state is created or pending creation.
      a=  

      The following command updates cache entry's ttl, and admisson policy of
      anywhere cache instance in bucket ``my-bucket'' having anywhere_cache_id
      ``my-cache-id'':

        $ {command} my-bucket/my-cache-id --ttl=6h --admission-policy='ADMIT_ON_SECOND_MISS'

      The following command updates cache entry's ttl of anywhere cache
      instances in bucket ``bucket-1'' and ``bucket-2'' having anywhere_cache_id
      ``my-cache-id-1'', and ``my-cache-id-2'' respectively:

        $ {command} bucket-1/my-cache-id-1 bucket-2/my-cache-id-2 --ttl=6h
      )DESCRIPTIONEXAMPLESc                     |j                  dt        dd       |j                  dt        j                         d       t	        j
                  |       y )Nid+zIdentifiers for a Anywhere Cache Instance.They are combination of bucket_name/anywhere_cache_id. For example : test-bucket/my-cache-id.)typenargshelpz--ttlz9Cache entry time-to-live. Default to 24h if not provided.)r   r   )add_argumentstrr   Durationr   add_admission_policy_flag)clsparsers     5lib/surface/storage/buckets/anywhere_caches/update.pyArgszUpdate.Args5   sZ    
(  	 !!#H   
##F+    c              #   @  K   t        j                  |t        |j                               |j                  rt        |j                        dz   nd }|j                  D ]<  }|j                  d      \  }}}t        j                  |||j                  |       > y w)Ns/)admission_policyttl)
r   workload_estimator_callbacklenr   r"   r   
rpartitionr
   PatchAnywhereCacheTaskr!   )selfargstask_status_queuer"   id_strbucket_name_anywhere_cache_ids           r   get_task_iteratorzUpdate.get_task_iteratorJ   s     223tww< "&#dhh-#
tC''*0*;*;C*@'k1'%<<

00	  s   BBc           	          t         j                  j                         }| j                  ||      }t	        j
                  |d|t        j                  t        j                  j                  d             | _
        y )NT)increment_typemanifest_path)parallelizabler)   progress_manager_args)r   multiprocessing_contextQueuer.   r   execute_tasksr	   ProgressManagerArgsIncrementTypeINTEGER	exit_code)r'   r(   r)   task_iterators       r   Runz
Update.RunZ   sd    +CCIIK**41BCM"00+)==&44<<D
	DNr   N)	__name__
__module____qualname____doc__detailed_helpclassmethodr   r.   r<    r   r   r   r      s4    (


-, , ,( r   r   N)r@   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.storager   r   (googlecloudsdk.command_lib.storage.tasksr   r   r	   @googlecloudsdk.command_lib.storage.tasks.buckets.anywhere_cachesr
   DefaultUniverseOnlyUpdateCommandr   rC   r   r   <module>rJ      sM    N / ( 4 A B H @ f IT I Ir   