def test_create_cluster_snapshot_returns_snapshot_data(self): self._create_clusters() hook = RedshiftHook(aws_conn_id='aws_default') snapshot = hook.create_cluster_snapshot('test_snapshot_2', 'test_cluster') self.assertNotEqual(snapshot, None)
def get_hook(self) -> RedshiftHook: """Create and return a RedshiftHook""" if self.hook: return self.hook self.hook = RedshiftHook(aws_conn_id=self.aws_conn_id) return self.hook
def test_restore_from_cluster_snapshot_returns_dict_with_cluster_data(self): self._create_clusters() hook = RedshiftHook(aws_conn_id='aws_default') hook.create_cluster_snapshot('test_snapshot', 'test_cluster') self.assertEqual( hook.restore_from_cluster_snapshot('test_cluster_3', 'test_snapshot')['ClusterIdentifier'], 'test_cluster_3', )
def execute(self, context): redshift_hook = RedshiftHook(aws_conn_id=self.aws_conn_id) cluster_state = redshift_hook.cluster_status( cluster_identifier=self.cluster_identifier) if cluster_state == 'available': self.log.info("Pausing Redshift cluster %s", self.cluster_identifier) redshift_hook.get_conn().pause_cluster( ClusterIdentifier=self.cluster_identifier) else: self.log.warning( "Unable to pause cluster since cluster is currently in status: %s", cluster_state)
def poke(self, context): self.log.info('Poking for status : %s\nfor cluster %s', self.target_status, self.cluster_identifier) hook = RedshiftHook(aws_conn_id=self.aws_conn_id) return hook.cluster_status( self.cluster_identifier) == self.target_status
def test_cluster_status_returns_cluster_not_found(self): self._create_clusters() hook = RedshiftHook(aws_conn_id='aws_default') status = hook.cluster_status('test_cluster_not_here') self.assertEqual(status, 'cluster_not_found')
def test_delete_cluster_returns_a_dict_with_cluster_data(self): self._create_clusters() hook = RedshiftHook(aws_conn_id='aws_default') cluster = hook.delete_cluster('test_cluster_2') self.assertNotEqual(cluster, None)
def test_cluster_status_returns_available_cluster(self): self._create_clusters() hook = RedshiftHook(aws_conn_id='aws_default') status = hook.cluster_status('test_cluster') self.assertEqual(status, 'available')
def get_hook(self): """Create and return a RedshiftHook""" if not self.hook: self.hook = RedshiftHook(aws_conn_id=self.aws_conn_id) return self.hook