Skip to content

Commit 9c3eefd

Browse files
committed
Add deployment lifecycle commands
1 parent 254475a commit 9c3eefd

13 files changed

Lines changed: 588 additions & 4 deletions

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,36 +174,66 @@ $deployment->writeIndexes(); // ['posts_search']
174174
Once the candidate has been inspected, begin backfilling before importing historical documents. This enables concurrent writes and deletions to the candidate:
175175

176176
```php
177-
$deployment = $deployer->beginBackfill('posts');
177+
$deployment = $deployer->backfill('posts');
178178

179179
$deployment->writeIndexes();
180180
```
181181

182+
The same transition is available from the command line:
183+
184+
```bash
185+
php artisan opensearch:deploy:backfill posts
186+
```
187+
182188
After application-specific validation succeeds, mark the candidate ready and atomically move the alias:
183189

184190
```php
185191
$deployer->markReady('posts');
186192
$deployer->cutover('posts');
187193
```
188194

195+
```bash
196+
php artisan opensearch:deploy:ready posts
197+
php artisan opensearch:deploy:cutover posts
198+
```
199+
189200
Cancel and delete a candidate that should not be promoted:
190201

191202
```php
192203
$deployer->cancel('posts');
193204
```
194205

206+
```bash
207+
php artisan opensearch:deploy:cancel posts
208+
```
209+
195210
The previous index remains in the deployment's write indexes during the rollback window:
196211

197212
```php
198213
$deployer->rollback('posts');
199214
```
200215

216+
```bash
217+
php artisan opensearch:deploy:rollback posts
218+
```
219+
201220
Once the new index is verified in production, delete the previous physical index and complete the deployment:
202221

203222
```php
204223
$deployer->retire('posts');
205224
```
206225

226+
```bash
227+
php artisan opensearch:deploy:retire posts
228+
```
229+
230+
Inspect one or every deployment at any point in the lifecycle:
231+
232+
```bash
233+
php artisan opensearch:deploy:status
234+
php artisan opensearch:deploy:status posts
235+
```
236+
207237
`opensearch:migrate:fresh` deletes all deployment records because it drops all physical indexes. Migration reset and refresh commands refuse to run while managed deployments exist.
208238

209239
## Credits
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace DirectoryTree\OpenSearchMigrations\Console;
4+
5+
use DirectoryTree\OpenSearchMigrations\Deployer;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Console\ConfirmableTrait;
8+
9+
/**
10+
* Begin backfilling an OpenSearch deployment.
11+
*/
12+
class DeploymentBackfillCommand extends Command
13+
{
14+
use ConfirmableTrait;
15+
16+
/**
17+
* The name and signature of the console command.
18+
*
19+
* @var string
20+
*/
21+
protected $signature = 'opensearch:deploy:backfill
22+
{name : The logical index name}
23+
{--force : Force the operation to run when in production}';
24+
25+
/**
26+
* The console command description.
27+
*
28+
* @var string
29+
*/
30+
protected $description = 'Enable candidate writes before backfilling an index';
31+
32+
/**
33+
* Execute the console command.
34+
*/
35+
public function handle(Deployer $deployer): int
36+
{
37+
if (! $this->confirmToProceed()) {
38+
return static::FAILURE;
39+
}
40+
41+
$deployer->backfill($this->argument('name'));
42+
43+
$this->components->info("Deployment [{$this->argument('name')}] is ready to be backfilled.");
44+
45+
return static::SUCCESS;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace DirectoryTree\OpenSearchMigrations\Console;
4+
5+
use DirectoryTree\OpenSearchMigrations\Deployer;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Console\ConfirmableTrait;
8+
9+
/**
10+
* Cancel an OpenSearch deployment.
11+
*/
12+
class DeploymentCancelCommand extends Command
13+
{
14+
use ConfirmableTrait;
15+
16+
/**
17+
* The name and signature of the console command.
18+
*
19+
* @var string
20+
*/
21+
protected $signature = 'opensearch:deploy:cancel
22+
{name : The logical index name}
23+
{--force : Force the operation to run when in production}';
24+
25+
/**
26+
* The console command description.
27+
*
28+
* @var string
29+
*/
30+
protected $description = 'Cancel an index deployment and delete its candidate';
31+
32+
/**
33+
* Execute the console command.
34+
*/
35+
public function handle(Deployer $deployer): int
36+
{
37+
if (! $this->confirmToProceed()) {
38+
return static::FAILURE;
39+
}
40+
41+
$deployer->cancel($this->argument('name'));
42+
43+
$this->components->info("Deployment [{$this->argument('name')}] was cancelled.");
44+
45+
return static::SUCCESS;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace DirectoryTree\OpenSearchMigrations\Console;
4+
5+
use DirectoryTree\OpenSearchMigrations\Deployer;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Console\ConfirmableTrait;
8+
9+
/**
10+
* Cut over an OpenSearch deployment.
11+
*/
12+
class DeploymentCutoverCommand extends Command
13+
{
14+
use ConfirmableTrait;
15+
16+
/**
17+
* The name and signature of the console command.
18+
*
19+
* @var string
20+
*/
21+
protected $signature = 'opensearch:deploy:cutover
22+
{name : The logical index name}
23+
{--force : Force the operation to run when in production}';
24+
25+
/**
26+
* The console command description.
27+
*
28+
* @var string
29+
*/
30+
protected $description = 'Switch an index alias to its ready candidate';
31+
32+
/**
33+
* Execute the console command.
34+
*/
35+
public function handle(Deployer $deployer): int
36+
{
37+
if (! $this->confirmToProceed()) {
38+
return static::FAILURE;
39+
}
40+
41+
$deployer->cutover($this->argument('name'));
42+
43+
$this->components->info("Deployment [{$this->argument('name')}] was cut over.");
44+
45+
return static::SUCCESS;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace DirectoryTree\OpenSearchMigrations\Console;
4+
5+
use DirectoryTree\OpenSearchMigrations\Deployer;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Console\ConfirmableTrait;
8+
9+
/**
10+
* Mark an OpenSearch deployment as ready.
11+
*/
12+
class DeploymentReadyCommand extends Command
13+
{
14+
use ConfirmableTrait;
15+
16+
/**
17+
* The name and signature of the console command.
18+
*
19+
* @var string
20+
*/
21+
protected $signature = 'opensearch:deploy:ready
22+
{name : The logical index name}
23+
{--force : Force the operation to run when in production}';
24+
25+
/**
26+
* The console command description.
27+
*
28+
* @var string
29+
*/
30+
protected $description = 'Mark an index deployment as ready for cutover';
31+
32+
/**
33+
* Execute the console command.
34+
*/
35+
public function handle(Deployer $deployer): int
36+
{
37+
if (! $this->confirmToProceed()) {
38+
return static::FAILURE;
39+
}
40+
41+
$deployer->markReady($this->argument('name'));
42+
43+
$this->components->info("Deployment [{$this->argument('name')}] is ready for cutover.");
44+
45+
return static::SUCCESS;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace DirectoryTree\OpenSearchMigrations\Console;
4+
5+
use DirectoryTree\OpenSearchMigrations\Deployer;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Console\ConfirmableTrait;
8+
9+
/**
10+
* Retire an OpenSearch deployment.
11+
*/
12+
class DeploymentRetireCommand extends Command
13+
{
14+
use ConfirmableTrait;
15+
16+
/**
17+
* The name and signature of the console command.
18+
*
19+
* @var string
20+
*/
21+
protected $signature = 'opensearch:deploy:retire
22+
{name : The logical index name}
23+
{--force : Force the operation to run when in production}';
24+
25+
/**
26+
* The console command description.
27+
*
28+
* @var string
29+
*/
30+
protected $description = 'Delete the previous index and complete a deployment';
31+
32+
/**
33+
* Execute the console command.
34+
*/
35+
public function handle(Deployer $deployer): int
36+
{
37+
if (! $this->confirmToProceed()) {
38+
return static::FAILURE;
39+
}
40+
41+
$deployer->retire($this->argument('name'));
42+
43+
$this->components->info("Deployment [{$this->argument('name')}] was retired.");
44+
45+
return static::SUCCESS;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace DirectoryTree\OpenSearchMigrations\Console;
4+
5+
use DirectoryTree\OpenSearchMigrations\Deployer;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Console\ConfirmableTrait;
8+
9+
/**
10+
* Roll back an OpenSearch deployment.
11+
*/
12+
class DeploymentRollbackCommand extends Command
13+
{
14+
use ConfirmableTrait;
15+
16+
/**
17+
* The name and signature of the console command.
18+
*
19+
* @var string
20+
*/
21+
protected $signature = 'opensearch:deploy:rollback
22+
{name : The logical index name}
23+
{--force : Force the operation to run when in production}';
24+
25+
/**
26+
* The console command description.
27+
*
28+
* @var string
29+
*/
30+
protected $description = 'Restore the previous index behind an alias';
31+
32+
/**
33+
* Execute the console command.
34+
*/
35+
public function handle(Deployer $deployer): int
36+
{
37+
if (! $this->confirmToProceed()) {
38+
return static::FAILURE;
39+
}
40+
41+
$deployer->rollback($this->argument('name'));
42+
43+
$this->components->info("Deployment [{$this->argument('name')}] was rolled back.");
44+
45+
return static::SUCCESS;
46+
}
47+
}

0 commit comments

Comments
 (0)