-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: rearrange examples to dedicated files
- Loading branch information
Showing
22 changed files
with
316 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
|
||
from google.protobuf.wrappers_pb2 import Int64Value | ||
|
||
from doublecloud.clickhouse.v1.cluster_pb2 import ClusterResources | ||
from doublecloud.clickhouse.v1.cluster_service_pb2 import CreateClusterRequest | ||
from doublecloud.clickhouse.v1.cluster_service_pb2_grpc import ClusterServiceStub | ||
|
||
|
||
def create_cluster(sdk, project_id, region_id, name, network_id): | ||
cluster_service = sdk.client(ClusterServiceStub) | ||
operation = cluster_service.Create( | ||
CreateClusterRequest( | ||
project_id=project_id, | ||
cloud_type="aws", | ||
region_id=region_id, | ||
name=name, | ||
resources=ClusterResources( | ||
clickhouse=ClusterResources.Clickhouse( | ||
resource_preset_id="s1-c2-m4", | ||
disk_size=Int64Value(value=32 * 2**30), | ||
replica_count=Int64Value(value=1), | ||
) | ||
), | ||
network_id=network_id, | ||
) | ||
) | ||
logging.info("Creating initiated") | ||
return operation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from doublecloud.clickhouse.v1.cluster_service_pb2 import DeleteClusterRequest | ||
from doublecloud.clickhouse.v1.cluster_service_pb2_grpc import ClusterServiceStub | ||
|
||
|
||
def delete_cluster(sdk, cluster_id): | ||
cluster_service = sdk.client(ClusterServiceStub) | ||
return cluster_service.Delete(DeleteClusterRequest(cluster_id=cluster_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import logging | ||
|
||
from google.protobuf.wrappers_pb2 import Int64Value | ||
|
||
from doublecloud.kafka.v1.cluster_pb2 import ClusterResources | ||
from doublecloud.kafka.v1.cluster_service_pb2 import CreateClusterRequest | ||
from doublecloud.kafka.v1.cluster_service_pb2_grpc import ClusterServiceStub | ||
|
||
|
||
def create_cluster(sdk, project_id, region_id, name, network_id): | ||
cluster_service = sdk.client(ClusterServiceStub) | ||
operation = cluster_service.Create( | ||
CreateClusterRequest( | ||
project_id=project_id, | ||
cloud_type="aws", | ||
region_id=region_id, | ||
name=name, | ||
resources=ClusterResources( | ||
kafka=ClusterResources.Kafka( | ||
resource_preset_id="s1-c2-m4", | ||
disk_size=Int64Value(value=32 * 2**30), | ||
broker_count=Int64Value(value=1), | ||
zone_count=Int64Value(value=1), | ||
) | ||
), | ||
network_id=network_id, | ||
) | ||
) | ||
logging.info("Creating initiated") | ||
return operation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from doublecloud.kafka.v1.cluster_service_pb2 import DeleteClusterRequest | ||
from doublecloud.kafka.v1.cluster_service_pb2_grpc import ClusterServiceStub | ||
|
||
|
||
def delete_cluster(sdk, cluster_id): | ||
cluster_service = sdk.client(ClusterServiceStub) | ||
return cluster_service.Delete(DeleteClusterRequest(cluster_id=cluster_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from doublecloud.transfer.v1.transfer_service_pb2 import ActivateTransferRequest | ||
|
||
|
||
def activate_transfer(svc, transfer_id: str): | ||
return svc.Activate(ActivateTransferRequest(transfer_id=transfer_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from doublecloud.transfer.v1.transfer_pb2 import TransferType | ||
from doublecloud.transfer.v1.transfer_service_pb2 import CreateTransferRequest | ||
|
||
|
||
def create_transfer(svc, project_id: str, name: str, src_id: str, dst_id: str): | ||
return svc.Create( | ||
CreateTransferRequest( | ||
source_id=src_id, target_id=dst_id, name=name, project_id=project_id, type=TransferType.SNAPSHOT_ONLY | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from doublecloud.transfer.v1.transfer_service_pb2 import DeactivateTransferRequest | ||
|
||
|
||
def deactivate_transfer(svc, transfer_id: str): | ||
return svc.Deactivate(DeactivateTransferRequest(transfer_id=transfer_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from doublecloud.transfer.v1.transfer_service_pb2 import DeleteTransferRequest | ||
|
||
|
||
def delete_transfer(svc, transfer_id: str): | ||
return svc.Delete(DeleteTransferRequest(transfer_id=transfer_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from doublecloud.transfer.v1.endpoint.airbyte.s3_source_pb2 import S3Source | ||
from doublecloud.transfer.v1.endpoint.clickhouse_pb2 import ( | ||
ClickhouseConnection, | ||
ClickhouseConnectionOptions, | ||
ClickhouseTarget, | ||
) | ||
from doublecloud.transfer.v1.endpoint.common_pb2 import Secret | ||
from doublecloud.transfer.v1.endpoint_pb2 import EndpointSettings | ||
from doublecloud.transfer.v1.endpoint_service_pb2 import ( | ||
CreateEndpointRequest, | ||
DeleteEndpointRequest, | ||
) | ||
|
||
|
||
def create_s3_src_endpoint(svc, project_id: str, name: str): | ||
return svc.Create( | ||
CreateEndpointRequest( | ||
project_id=project_id, | ||
name=f"s3-src-{name}", | ||
settings=EndpointSettings( | ||
s3_source=S3Source( | ||
dataset="test", | ||
path_pattern="test", | ||
schema="test", | ||
format=S3Source.Format(csv=S3Source.Csv()), | ||
provider=S3Source.Provider(bucket="test"), | ||
) | ||
), | ||
) | ||
) | ||
|
||
|
||
def create_ch_dst_endpoint(svc, project_id: str, name: str): | ||
return svc.Create( | ||
CreateEndpointRequest( | ||
project_id=project_id, | ||
name=f"ch-dst-{name}", | ||
settings=EndpointSettings( | ||
clickhouse_target=ClickhouseTarget( | ||
connection=ClickhouseConnection( | ||
connection_options=ClickhouseConnectionOptions( | ||
mdb_cluster_id="xoxo", | ||
database="default", | ||
user="user", | ||
password=Secret(raw="98s*%^P!3Bw38"), | ||
) | ||
) | ||
) | ||
), | ||
) | ||
) | ||
|
||
|
||
def delete_endpoint(svc, endpoint_id: str): | ||
return svc.Delete(DeleteEndpointRequest(endpoint_id=endpoint_id)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from doublecloud.visualization.v1.workbook_pb2 import Dataset | ||
from doublecloud.visualization.v1.workbook_service_pb2 import AdviseDatasetFieldsRequest | ||
|
||
|
||
def advise_dataset_fields(svc, workbook_id: str, sources: list, connection_name: str): | ||
""" | ||
Function helps to define automatically all fields, their names/IDs and types | ||
based on underlying datasource (table, view, SQL query, etc.). | ||
ID of fields will be equals to column names. | ||
You can use define them manually or use this handler to simplifying for popular cases | ||
""" | ||
dataset = Dataset() | ||
dataset.config.struct_value.update( | ||
{ | ||
"fields": [], | ||
"avatars": None, | ||
"sources": sources, | ||
} | ||
) | ||
|
||
return svc.AdviseDatasetFields( | ||
AdviseDatasetFieldsRequest( | ||
workbook_id=workbook_id, | ||
connection_name=connection_name, | ||
partial_dataset=dataset, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from doublecloud.v1.operation_pb2 import Operation | ||
from doublecloud.visualization.v1.workbook_service_pb2 import CreateWorkbookRequest | ||
|
||
|
||
def create_workbook(svc, project_id: str, name: str) -> Operation: | ||
""" | ||
Function creates an empty workbook | ||
We will fill it with other functions | ||
""" | ||
return svc.Create(CreateWorkbookRequest(project_id=project_id, workbook_title=name)) |
Oops, something went wrong.