File tree Expand file tree Collapse file tree
tests/Integration/Endpoints/Collections Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111
1212use Qdrant \Endpoints \AbstractEndpoint ;
1313use Qdrant \Exception \InvalidArgumentException ;
14+ use Qdrant \Models \Request \UpdateCollectionCluster ;
1415use Qdrant \Response ;
1516
1617class Cluster extends AbstractEndpoint
@@ -33,13 +34,14 @@ public function info(): Response
3334 *
3435 * @throws InvalidArgumentException
3536 */
36- public function update (array $ params , array $ queryParams = []): Response
37+ public function update (UpdateCollectionCluster $ params , array $ queryParams = []): Response
3738 {
3839 return $ this ->client ->execute (
3940 $ this ->createRequest (
4041 'POST ' ,
4142 '/collections/ ' . $ this ->getCollectionName () . '/cluster ' . $ this ->queryBuild ($ queryParams ),
42- $ params )
43+ $ params ->toArray ()
44+ )
4345 );
4446 }
4547}
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @since Mar 2023
4+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+ */
6+
7+ namespace Qdrant \Models \Request \CollectionUpdate ;
8+
9+ class AbortTransferOperation extends MoveShardOperation
10+ {
11+ public function getKey (): string
12+ {
13+ return 'abort_transfer ' ;
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @since Mar 2023
4+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+ */
6+
7+ namespace Qdrant \Models \Request \CollectionUpdate ;
8+
9+ class CreateShardingKeyOperation implements Operation
10+ {
11+ protected string $ shardKey ;
12+ protected ?int $ shardsNumber = null ;
13+ protected ?int $ replicationFactor = null ;
14+ protected ?int $ placement = null ;
15+
16+ public function __construct (string $ shardKey )
17+ {
18+ $ this ->shardKey = $ shardKey ;
19+ }
20+
21+ public function getKey (): string
22+ {
23+ return 'create_sharding_key ' ;
24+ }
25+
26+ public function toArray (): array
27+ {
28+ return array_filter ([
29+ 'shard_key ' => $ this ->shardKey ,
30+ 'shards_number ' => $ this ->shardsNumber ,
31+ 'replication_factor ' => $ this ->replicationFactor ,
32+ 'placement ' => $ this ->placement ,
33+ ]);
34+ }
35+
36+ public function setShardsNumber (int $ shardsNumber ): CreateShardingKeyOperation
37+ {
38+ $ this ->shardsNumber = $ shardsNumber ;
39+
40+ return $ this ;
41+ }
42+
43+ public function setPlacement (int $ placement ): CreateShardingKeyOperation
44+ {
45+ $ this ->placement = $ placement ;
46+
47+ return $ this ;
48+ }
49+
50+ public function setReplicationFactor (int $ replicationFactor ): CreateShardingKeyOperation
51+ {
52+ $ this ->replicationFactor = $ replicationFactor ;
53+
54+ return $ this ;
55+ }
56+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @since Mar 2023
4+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+ */
6+
7+ namespace Qdrant \Models \Request \CollectionUpdate ;
8+
9+ class DropReplicaOperation implements Operation
10+ {
11+ public function __construct (
12+ protected int $ shardId ,
13+ protected int $ peerId
14+ ) {}
15+
16+ public function toArray (): array
17+ {
18+ return [
19+ 'shard_id ' => $ this ->shardId ,
20+ 'peer_id ' => $ this ->peerId ,
21+ ];
22+ }
23+
24+ public function getKey (): string
25+ {
26+ return 'drop_replica ' ;
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @since Mar 2023
4+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+ */
6+
7+ namespace Qdrant \Models \Request \CollectionUpdate ;
8+
9+ class DropShardingKeyOperation implements Operation
10+ {
11+ public function __construct (protected string $ shardKey )
12+ {}
13+
14+ public function getKey (): string
15+ {
16+ return 'drop_sharding_key ' ;
17+ }
18+
19+ public function toArray (): array
20+ {
21+ return [
22+ 'shard_key ' => $ this ->shardKey ,
23+ ];
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @since Mar 2023
4+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+ */
6+
7+ namespace Qdrant \Models \Request \CollectionUpdate ;
8+
9+ class MoveShardOperation implements Operation
10+ {
11+ protected ?string $ method = null ;
12+
13+ public function __construct (
14+ protected int $ shardId ,
15+ protected int $ toPeerId ,
16+ protected int $ fromPeerId ,
17+ ) {}
18+
19+ public function getKey (): string
20+ {
21+ return 'move_shard ' ;
22+ }
23+
24+ public function toArray (): array
25+ {
26+ return array_filter ([
27+ 'shard_id ' => $ this ->shardId ,
28+ 'to_peer_id ' => $ this ->toPeerId ,
29+ 'from_peer_id ' => $ this ->fromPeerId ,
30+ 'method ' => $ this ->method ,
31+ ]);
32+ }
33+
34+ public function setMethod (string $ method ): MoveShardOperation
35+ {
36+ $ this ->method = $ method ;
37+
38+ return $ this ;
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * Operation
4+ *
5+ * @since Oct 2023
6+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
7+ */
8+
9+ namespace Qdrant \Models \Request \CollectionUpdate ;
10+
11+ interface Operation
12+ {
13+ public function getKey (): string ;
14+ public function toArray (): array ;
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * @since Mar 2023
4+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
5+ */
6+
7+ namespace Qdrant \Models \Request \CollectionUpdate ;
8+
9+ class ReplicateShardOperation extends MoveShardOperation
10+ {
11+ public function getKey (): string
12+ {
13+ return 'replicate_shard ' ;
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * UpdateCollectionCluster
4+ *
5+ * @since Mar 2023
6+ * @author Haydar KULEKCI <haydarkulekci@gmail.com>
7+ */
8+
9+ namespace Qdrant \Models \Request ;
10+
11+ use Qdrant \Models \Request \CollectionUpdate \Operation ;
12+
13+ class UpdateCollectionCluster implements RequestModel
14+ {
15+ /**
16+ * @param Operation $operation
17+ */
18+ public function __construct (protected Operation $ operation )
19+ {
20+ }
21+
22+ public function toArray (): array
23+ {
24+ return [
25+ $ this ->operation ->getKey () => $ this ->operation ->toArray (),
26+ ];
27+ }
28+ }
Original file line number Diff line number Diff line change 77
88use Qdrant \Endpoints \Collections ;
99use Qdrant \Exception \InvalidArgumentException ;
10+ use Qdrant \Models \Request \CollectionUpdate \MoveShardOperation ;
1011use Qdrant \Tests \Integration \AbstractIntegration ;
1112
1213class ClusterTest extends AbstractIntegration
@@ -40,13 +41,9 @@ public function testClusterUpdate(): void
4041 $ this ->createCollections ('sample-collection ' );
4142 $ cluster ->setCollectionName ('sample-collection ' );
4243
43- $ response = $ cluster ->update ([
44- "move_shard " => [
45- "shard_id " => 0 ,
46- "to_peer_id " => 1 ,
47- "from_peer_id " => 0
48- ]
49- ]);
44+ $ operation = new MoveShardOperation (0 , 1 , 0 );
45+
46+ $ response = $ cluster ->update ($ operation );
5047 }
5148
5249 protected function tearDown (): void
You can’t perform that action at this time.
0 commit comments