aws_metrics_waiters.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import botocore.client
  7. import logging
  8. from datetime import timedelta
  9. from AWS.common.custom_waiter import CustomWaiter, WaitState
  10. logging.getLogger('boto').setLevel(logging.CRITICAL)
  11. class KinesisAnalyticsApplicationUpdatedWaiter(CustomWaiter):
  12. """
  13. Subclass of the base custom waiter class.
  14. Wait for the Kinesis analytics application being updated to a specific status.
  15. """
  16. def __init__(self, client: botocore.client, status: str):
  17. """
  18. Initialize the waiter.
  19. :param client: Boto3 client to use.
  20. :param status: Expected status.
  21. """
  22. super().__init__(
  23. 'KinesisAnalyticsApplicationUpdated',
  24. 'DescribeApplication',
  25. 'ApplicationDetail.ApplicationStatus',
  26. {status: WaitState.SUCCESS},
  27. client)
  28. def wait(self, application_name: str):
  29. """
  30. Wait for the expected status.
  31. :param application_name: Name of the Kinesis analytics application.
  32. """
  33. self._wait(ApplicationName=application_name)
  34. class GlueCrawlerReadyWaiter(CustomWaiter):
  35. """
  36. Subclass of the base custom waiter class.
  37. Wait for the Glue crawler to finish its processing. Return when the crawler is in the "Stopping" status
  38. to avoid wasting too much time in the automation tests on its shutdown process.
  39. """
  40. def __init__(self, client: botocore.client):
  41. """
  42. Initialize the waiter.
  43. :param client: Boto3 client to use.
  44. """
  45. super().__init__(
  46. 'GlueCrawlerReady',
  47. 'GetCrawler',
  48. 'Crawler.State',
  49. {'STOPPING': WaitState.SUCCESS},
  50. client)
  51. def wait(self, crawler_name):
  52. """
  53. Wait for the expected status.
  54. :param crawler_name: Name of the Glue crawler.
  55. """
  56. self._wait(Name=crawler_name)
  57. class DataLakeMetricsDeliveredWaiter(CustomWaiter):
  58. """
  59. Subclass of the base custom waiter class.
  60. Wait for the expected directory being created in the S3 bucket.
  61. """
  62. def __init__(self, client: botocore.client):
  63. """
  64. Initialize the waiter.
  65. :param client: Boto3 client to use.
  66. """
  67. super().__init__(
  68. 'DataLakeMetricsDelivered',
  69. 'ListObjectsV2',
  70. 'KeyCount > `0`',
  71. {True: WaitState.SUCCESS},
  72. client)
  73. def wait(self, bucket_name, prefix):
  74. """
  75. Wait for the expected directory being created.
  76. :param bucket_name: Name of the S3 bucket.
  77. :param prefix: Name of the expected directory prefix.
  78. """
  79. self._wait(Bucket=bucket_name, Prefix=prefix)
  80. class CloudWatchMetricsDeliveredWaiter(CustomWaiter):
  81. """
  82. Subclass of the base custom waiter class.
  83. Wait for the expected metrics being delivered to CloudWatch.
  84. """
  85. def __init__(self, client: botocore.client):
  86. """
  87. Initialize the waiter.
  88. :param client: Boto3 client to use.
  89. """
  90. super().__init__(
  91. 'CloudWatchMetricsDelivered',
  92. 'GetMetricStatistics',
  93. 'length(Datapoints) > `0`',
  94. {True: WaitState.SUCCESS},
  95. client)
  96. def wait(self, namespace, metrics_name, dimensions, start_time):
  97. """
  98. Wait for the expected metrics being delivered.
  99. :param namespace: Namespace of the metrics.
  100. :param metrics_name: Name of the metrics.
  101. :param dimensions: Dimensions of the metrics.
  102. :param start_time: Start time for generating the metrics.
  103. """
  104. self._wait(
  105. Namespace=namespace,
  106. MetricName=metrics_name,
  107. Dimensions=dimensions,
  108. StartTime=start_time,
  109. EndTime=start_time + timedelta(0, self.timeout),
  110. Period=60,
  111. Statistics=[
  112. 'SampleCount'
  113. ],
  114. Unit='Count'
  115. )