Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Populate services.yaml in CDK for ECS RFS backfill #734

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ There is also a block that specifies the deployment type. Exactly one of the fol
- `socket`: optional, path to mounted docker socket, defaults to `/var/run/docker.sock`

- `ecs`:
- `cluster_name`: required, name of the ECS cluster containing the RFS service
- `service_name`: required, name of the ECS service for RFS
- `aws_region`: optional. if not provided, the usual rules are followed for determining aws region. (`AWS_DEFAULT_REGION`, `~/.aws/config`, etc.)

Expand All @@ -132,6 +133,7 @@ backfill:
snapshot_name: "def"
scale: 3
ecs:
cluster_name: migration-aws-integ-ecs-cluster
service_name: migration-aws-integ-reindex-from-snapshot
aws-region: us-east-1
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ECS_RFS_SCHEMA = {
"type": "dict",
"schema": {
"cluster_name": {"type": "string", "required": True},
"service_name": {"type": "string", "required": True},
"aws_region": {"type": "string", "required": False}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def test_get_backfill_valid_ecs_rfs():
ecs_rfs_config = {
"reindex_from_snapshot": {
"ecs": {
"cluster_name": "migration-aws-integ-ecs-cluster",
"service_name": "migration-aws-integ-reindex-from-snapshot"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def ecs_rfs_backfill() -> ECSRFSBackfill:
ecs_rfs_config = {
"reindex_from_snapshot": {
"ecs": {
"cluster_name": "migration-aws-integ-ecs-cluster",
"service_name": "migration-aws-integ-reindex-from-snapshot"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,50 @@ export class MetricsSourceYaml {
cloudwatch? : object | null = null;
}

export class ECSService {
cluster_name: string | undefined;
service_name: string | undefined;
aws_region: string | undefined;
constructor() {
this.cluster_name = undefined;
this.service_name = undefined;
this.aws_region = undefined;
}
}

export class RFSBackfillYaml {
ecs: ECSService;
constructor() {
this.ecs = new ECSService();
}

toDict() {
return {
reindex_from_snapshot: {ecs: this.ecs}
};
}
}

export class OSIBackfillYaml {
toDict() {
return {
opensearch_ingestion: null
};
}
}

export class ServicesYaml {
source_cluster: ClusterYaml;
target_cluster: ClusterYaml;
metrics_source: MetricsSourceYaml = new MetricsSourceYaml();
backfill: RFSBackfillYaml | OSIBackfillYaml;

stringify(): string {
return yaml.stringify({
source_cluster: this.source_cluster,
target_cluster: this.target_cluster,
metrics_source: this.metrics_source
metrics_source: this.metrics_source,
backfill: this.backfill?.toDict()
},
{
'nullStr': ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
createOpenSearchIAMAccessPolicy,
createOpenSearchServerlessIAMAccessPolicy
} from "../common-utilities";
import { RFSBackfillYaml } from "../migration-services-yaml";


export interface ReindexFromSnapshotProps extends StackPropsExt {
Expand All @@ -21,6 +22,7 @@ export interface ReindexFromSnapshotProps extends StackPropsExt {
}

export class ReindexFromSnapshotStack extends MigrationServiceCore {
rfsBackfillYaml: RFSBackfillYaml;

constructor(scope: Construct, id: string, props: ReindexFromSnapshotProps) {
super(scope, id, props)
Expand Down Expand Up @@ -60,6 +62,11 @@ export class ReindexFromSnapshotStack extends MigrationServiceCore {
taskMemoryLimitMiB: 4096,
...props
});

this.rfsBackfillYaml = new RFSBackfillYaml();
this.rfsBackfillYaml.ecs.cluster_name = `migration-${props.stage}-ecs-cluster`;
this.rfsBackfillYaml.ecs.service_name = `migration-${props.stage}-reindex-from-snapshot`;

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ export class StackComposer {
})
this.addDependentStacks(reindexFromSnapshotStack, [migrationStack, openSearchStack, osContainerStack])
this.stacks.push(reindexFromSnapshotStack)
servicesYaml.backfill = reindexFromSnapshotStack.rfsBackfillYaml;

}

let captureProxyESStack
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClusterYaml, ServicesYaml } from "../lib/migration-services-yaml"
import { ClusterYaml, RFSBackfillYaml, ServicesYaml } from "../lib/migration-services-yaml"

test('Test default servicesYaml can be stringified', () => {
const servicesYaml = new ServicesYaml();
Expand All @@ -8,7 +8,7 @@ test('Test default servicesYaml can be stringified', () => {
expect(yaml).toBe("metrics_source:\n cloudwatch:\n");
})

test('Test servicesYaml with cluster can be stringified', () => {
test('Test servicesYaml with target cluster can be stringified', () => {
let servicesYaml = new ServicesYaml();
const cluster: ClusterYaml = { 'endpoint': 'https://abc.com', 'no_auth': '' };
servicesYaml.target_cluster = cluster;
Expand All @@ -18,7 +18,7 @@ test('Test servicesYaml with cluster can be stringified', () => {
expect(yaml).toBe(`target_cluster:\n endpoint: ${cluster.endpoint}\n no_auth: ""\nmetrics_source:\n cloudwatch:\n`);
})

test('Test servicesYaml with cluster can be stringified', () => {
test('Test servicesYaml with source and target cluster can be stringified', () => {
let servicesYaml = new ServicesYaml();
const targetCluster: ClusterYaml = { 'endpoint': 'https://abc.com', 'no_auth': '' };
servicesYaml.target_cluster = targetCluster;
Expand All @@ -33,3 +33,28 @@ test('Test servicesYaml with cluster can be stringified', () => {
const sourceClusterYaml = `source_cluster:\n endpoint: ${sourceCluster.endpoint}\n basic_auth:\n user: ${sourceClusterUser}\n password: ${sourceClusterPassword}\n`
expect(yaml).toBe(`${sourceClusterYaml}target_cluster:\n endpoint: ${targetCluster.endpoint}\n no_auth: ""\nmetrics_source:\n cloudwatch:\n`);
})

test('Test servicesYaml with rfs backfill can be stringified', () => {
const clusterName = "migration-cluster-name";
const serviceName = "rfs-service-name";
const region = "us-east-1"
let servicesYaml = new ServicesYaml();
let rfsBackfillYaml = new RFSBackfillYaml();
rfsBackfillYaml.ecs.cluster_name = clusterName;
rfsBackfillYaml.ecs.service_name = serviceName;
rfsBackfillYaml.ecs.aws_region = region;
servicesYaml.backfill = rfsBackfillYaml;


expect(servicesYaml.backfill).toBeDefined();
expect(servicesYaml.backfill).toBeDefined();
expect(servicesYaml.backfill instanceof RFSBackfillYaml).toBeTruthy();
const yaml = servicesYaml.stringify();
expect(yaml).toBe(`metrics_source:\n cloudwatch:\nbackfill:\n reindex_from_snapshot:\n ecs:\n cluster_name: ${clusterName}\n service_name: ${serviceName}\n aws_region: ${region}\n`);
})

test('Test servicesYaml without backfill does not include backend section', () => {
let servicesYaml = new ServicesYaml();
const yaml = servicesYaml.stringify();
expect(yaml).toBe(`metrics_source:\n cloudwatch:\n`);
})
Loading