Skip to content

Commit a90168e

Browse files
authored
PCBC-832: Management API - Analytics Management (#177)
* Implement analytics index management * missing declare strict types * fix autoload failure * add retries to dataverse creation for analytics temp unavailable
1 parent e603525 commit a90168e

32 files changed

+3587
-171
lines changed

Couchbase/Cluster.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,11 @@ public function users(): UserManager
265265
* Creates a new manager object for managing analytics query indexes.
266266
*
267267
* @return AnalyticsIndexManager
268-
* @throws UnsupportedOperationException
269268
* @since 4.0.0
270269
*/
271270
public function analyticsIndexes(): AnalyticsIndexManager
272271
{
273-
throw new UnsupportedOperationException();
272+
return new AnalyticsIndexManager($this->core);
274273
}
275274

276275
/**
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2014-Present Couchbase, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace Couchbase\Management;
22+
23+
class AnalyticsDataset
24+
{
25+
private string $name;
26+
private string $dataverseName;
27+
private string $linkName;
28+
private string $bucketName;
29+
30+
/**
31+
* @internal
32+
* @since 4.2.4
33+
*/
34+
private function __construct(
35+
string $name,
36+
string $dataverseName,
37+
string $linkName,
38+
string $bucketName
39+
)
40+
{
41+
$this->name = $name;
42+
$this->dataverseName = $dataverseName;
43+
$this->linkName = $linkName;
44+
$this->bucketName = $bucketName;
45+
}
46+
47+
/**
48+
* Static helper to keep code more readable.
49+
*
50+
* @param string $name
51+
* @param string $dataverseName
52+
* @param string $linkName
53+
* @param string $bucketName
54+
*
55+
* @return AnalyticsDataset
56+
* @since 4.2.4
57+
*/
58+
public static function build(
59+
string $name,
60+
string $dataverseName,
61+
string $linkName,
62+
string $bucketName
63+
)
64+
{
65+
return new AnalyticsDataset($name, $dataverseName, $linkName, $bucketName);
66+
}
67+
68+
/**
69+
* Gets the name of the analytics dataset (or collection)
70+
*
71+
* @return string
72+
* @since 4.2.4
73+
*/
74+
public function name(): string
75+
{
76+
return $this->name;
77+
}
78+
79+
/**
80+
* Gets the name of the dataverse in which this dataset is stored.
81+
*
82+
* @return string
83+
* @since 4.2.4
84+
*/
85+
public function dataverseName(): string
86+
{
87+
return $this->dataverseName;
88+
}
89+
90+
/**
91+
* Gets the name of the link that is associated with this dataset.
92+
*
93+
* @return string
94+
* @since 4.2.4
95+
*/
96+
public function linkName(): string
97+
{
98+
return $this->linkName;
99+
}
100+
101+
/**
102+
* Gets the name of the bucket that this dataset includes.
103+
*
104+
* @return string
105+
* @since 4.2.4
106+
*/
107+
public function bucketName(): string
108+
{
109+
return $this->bucketName;
110+
}
111+
112+
/**
113+
* @internal
114+
*/
115+
public static function import(array $data): AnalyticsDataset
116+
{
117+
return AnalyticsDataset::build(
118+
$data["name"] ?? "",
119+
$data["dataverseName"] ?? "",
120+
$data["linkName"] ?? "",
121+
$data["bucketName"] ?? ""
122+
);
123+
}
124+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Couchbase\Management;
6+
7+
class AnalyticsIndex
8+
{
9+
private string $name;
10+
private string $datasetName;
11+
private string $dataverseName;
12+
private bool $isPrimary;
13+
14+
/**
15+
* @param string $name
16+
* @param string $datasetName
17+
* @param string $dataverseName
18+
* @param bool $isPrimary
19+
*/
20+
public function __construct(string $name, string $datasetName, string $dataverseName, bool $isPrimary)
21+
{
22+
$this->name = $name;
23+
$this->datasetName = $datasetName;
24+
$this->dataverseName = $dataverseName;
25+
$this->isPrimary = $isPrimary;
26+
}
27+
28+
/**
29+
* Static helper to keep code more readable
30+
*
31+
* @param string $name
32+
* @param string $datasetName
33+
* @param string $dataverseName
34+
* @param bool $isPrimary
35+
*
36+
* @return AnalyticsIndex
37+
* @since 4.2.4
38+
*/
39+
public static function build(string $name, string $datasetName, string $dataverseName, bool $isPrimary)
40+
{
41+
return new AnalyticsIndex($name, $datasetName, $dataverseName, $isPrimary);
42+
}
43+
44+
/**
45+
* Gets the name of this index
46+
*
47+
* @return string
48+
* @since 4.2.4
49+
*/
50+
public function name(): string
51+
{
52+
return $this->name;
53+
}
54+
55+
/**
56+
* Gets the name of the analytics dataset in which this index exists
57+
*
58+
* @return string
59+
* @since 4.2.4
60+
*/
61+
public function datasetName(): string
62+
{
63+
return $this->datasetName;
64+
}
65+
66+
/**
67+
* Gets the name of the dataverse in which this index exists.
68+
*
69+
* @return string
70+
* @since 4.2.4
71+
*/
72+
public function dataverseName(): string
73+
{
74+
return $this->dataverseName;
75+
}
76+
77+
/**
78+
* Returns true if this index is a primary index.
79+
*
80+
* @return bool
81+
* @since 4.2.4
82+
*/
83+
public function isPrimary(): bool
84+
{
85+
return $this->isPrimary;
86+
}
87+
88+
/**
89+
* @internal
90+
*/
91+
public static function import(array $data): AnalyticsIndex
92+
{
93+
return AnalyticsIndex::build(
94+
$data["name"] ?? "",
95+
$data["datasetName"] ?? "",
96+
$data["dataverseName"] ?? "",
97+
$data["isPrimary"] ?? false
98+
);
99+
}
100+
}

0 commit comments

Comments
 (0)