# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.
from advanced_cubes import (RandomMolRecordGeneratorCube,
                            RecordsToBatchesCube,
                            ParallelBatchesToShardsCube)
from floe.api import WorkFloe
from orionplatform.cubes import (CreateCollectionCube,
                                 ParallelCloseShardsCube,
                                 CloseCollectionCube)
# Declare WorkFloe
job = WorkFloe("Collection Writing Example (Advanced)")
job.title = "Collection Writing Example (Advanced)"
job.description = "Advanced Example of Writing Records To Shards in a Collection"
job.classification = [["Educational", "Example", "Cube Development", "I/O", "Record", "Shard", "Collection"]]
job.tags = ["Educational", "Example", "Cube Development", "I/O", "Record", "Shard", "Collection"]
# Declare Cubes
generator = RandomMolRecordGeneratorCube("generator")
batcher = RecordsToBatchesCube("batcher")
writer = ParallelBatchesToShardsCube("write_collection")
make_collection = CreateCollectionCube("make_collection")
close_shards = ParallelCloseShardsCube("close_shards")
close_collection = CloseCollectionCube("close_collection")
close_collection.modify_parameter(close_collection.close_shards, default=False)
# Add Cubes to WorkFloe
job.add_cubes(generator, batcher, writer, make_collection, close_shards, close_collection)
# Promote Parameters
generator.promote_parameter("record_number",
                            promoted_name="record_number",
                            default=100000)
make_collection.promote_parameter("collection_name",
                                  promoted_name="collection",
                                  default="advanced_example")
batcher.promote_parameter("records_per_batch",
                          promoted_name="records_per_batch",
                          default=500)
# Connect Cubes
generator.success.connect(batcher.intake)
make_collection.success.connect(writer.init)
batcher.success.connect(writer.intake)
writer.success.connect(close_shards.intake)
close_shards.success.connect(close_collection.intake)
if __name__ == "__main__":
    job.run()
