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

Fixed idempotency issue by first checking if table does not exist #1035

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion dlp-cli
Submodule dlp-cli updated 48 files
+7 −0 .goreleaser.yaml
+6 −0 CODEOWNERS
+20 −7 README.md
+3 −4 cmd/backend/add/add.go
+74 −0 cmd/backend/add_param/add-param.go
+5 −0 cmd/backend/backend.go
+48 −0 cmd/backend/build_training_env/build-training-env-file.go
+63 −0 cmd/backend/get_secret/get-secret.go
+1 −3 cmd/backend/id_token/id_token.go
+5 −6 cmd/backend/install/install.go
+54 −0 cmd/backend/pull_config/pull-config.go
+3 −4 cmd/backend/remove/remove.go
+52 −0 cmd/backend/remove_param/remove-param.go
+1 −2 cmd/backend/start/start.go
+1 −2 cmd/backend/uid/uid.go
+1 −2 cmd/backend/uninstall/uninstall.go
+82 −0 cmd/backend/update_param/update-param.go
+1 −2 cmd/frontend/add/add.go
+48 −0 cmd/frontend/build_frontend_env/build-frontend-env-file.go
+5 −0 cmd/frontend/frontend.go
+1 −2 cmd/frontend/install/install.go
+1 −2 cmd/frontend/remove/remove.go
+1 −2 cmd/frontend/start/start.go
+11 −0 cmd/root.go
+38 −0 cmd/serverless/build_serverless_env/build-serverless-env-file.go
+1 −2 cmd/serverless/core/add/add.go
+5 −0 cmd/serverless/core/core.go
+1 −2 cmd/serverless/core/remove/remove.go
+1 −2 cmd/serverless/functions/add/add.go
+5 −0 cmd/serverless/functions/functions.go
+1 −2 cmd/serverless/functions/remove/remove.go
+1 −2 cmd/serverless/install/install.go
+4 −0 cmd/serverless/serverless.go
+1 −2 cmd/serverless/start/start.go
+2 −0 go.mod
+6 −1 go.sum
+8 −0 main.go
+34 −0 manifests/d/DSGT-DLP/dlp-cli/0.1.3/DSGT-DLP.dlp-cli.installer.yaml
+12 −0 manifests/d/DSGT-DLP/dlp-cli/0.1.3/DSGT-DLP.dlp-cli.locale.en-US.yaml
+7 −0 manifests/d/DSGT-DLP/dlp-cli/0.1.3/DSGT-DLP.dlp-cli.yaml
+34 −0 manifests/d/DSGT-DLP/dlp-cli/0.2.0/DSGT-DLP.dlp-cli.installer.yaml
+12 −0 manifests/d/DSGT-DLP/dlp-cli/0.2.0/DSGT-DLP.dlp-cli.locale.en-US.yaml
+7 −0 manifests/d/DSGT-DLP/dlp-cli/0.2.0/DSGT-DLP.dlp-cli.yaml
+31 −0 pkg/exec_bash_cmd_any_os.go
+7 −5 pkg/exec_bash_cmd_unix_os.go
+2 −26 pkg/exec_bash_cmd_windows_os.go
+8 −0 utils/constants.go
+34 −0 utils/envfile.go
22 changes: 22 additions & 0 deletions serverless/packages/functions/src/dbutils/get_all_tablenames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

export async function get_all_tablenames() : Promise<string[]> {
const AWS = require("aws-sdk");
AWS.config.update({region:'us-east-1'});
let dynamodb = new AWS.DynamoDB();

let params =
{
ExclusiveStartTableName: null
};
let tables: string[] = [];
while (true) {
let response = await dynamodb.listTables(params).promise();
tables = tables.concat(response.TableNames);

if (response.LastEvaluatedTableName === undefined) {
break;
}
params.ExclusiveStartTableName = response.LastEvaluatedTableName;
}
return tables;
}
6 changes: 6 additions & 0 deletions serverless/packages/functions/src/dbutils/table_exists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { get_all_tablenames } from "./get_all_tablenames";

export async function table_exists(table_name: string) : Promise<boolean> {
const tableNames: string[] = await get_all_tablenames();
return tableNames.indexOf(table_name) !== -1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: can you please run Prettier for all changed files? There are some aesthetic issues; for example, each file should end with a blank line.

We'll need to update our checks to also check /serverless in addition to /frontend

2 changes: 1 addition & 1 deletion serverless/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
config(_input) {
return {
name: "dlp-sst-app",
region: "us-west-2",
region: "us-east-1",
};
},
stacks(app) {
Expand Down
46 changes: 25 additions & 21 deletions serverless/stacks/AppStack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Api, Bucket, StackContext, Table } from "sst/constructs";
import { Bucket as s3Bucket } from "aws-cdk-lib/aws-s3";
import { table_exists } from "../packages/functions/src/dbutils/table_exists";

export function AppStack({ stack }: StackContext) {
const bucket = new Bucket(stack, "dlp-upload-bucket", {
Expand All @@ -11,26 +12,29 @@ export function AppStack({ stack }: StackContext) {
),
},
});
const trainspaceRunTable = new Table(stack, "trainspace-run", {
fields: {
runId: "string",
trainspaceId: "string",
userId: "string",
timestamp: "string",
resultCsvUri: "string",
modelPtUri: "string",
onnxUri: "string",
confusionMatrixUri: "string",
aucRocUri: "string"
},
primaryIndex: {
partitionKey: "runId",
},
globalIndexes: {
"TrainspaceIndex": { partitionKey: "trainspaceId", sortKey: "timestamp"},
"UserIndex": {partitionKey: "userId"}
},
});
let trainspaceRunTable = null;
if (!table_exists("trainspace")) {
trainspaceRunTable = new Table(stack, "trainspace-run", {
fields: {
runId: "string",
trainspaceId: "string",
userId: "string",
timestamp: "string",
resultCsvUri: "string",
modelPtUri: "string",
onnxUri: "string",
confusionMatrixUri: "string",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this code work for if I want to update fields of a dynamo table?

aucRocUri: "string"
},
primaryIndex: {
partitionKey: "runId",
},
globalIndexes: {
"TrainspaceIndex": { partitionKey: "trainspaceId", sortKey: "timestamp"},
"UserIndex": {partitionKey: "userId"}
},
});
}
const api = new Api(stack, "Api", {
authorizers: {
FirebaseAuthorizer: {
Expand Down Expand Up @@ -71,7 +75,7 @@ export function AppStack({ stack }: StackContext) {
api.getFunction("GET /datasets/user/{type}/{filename}/columns")
?.functionName ?? "",
TrainspaceRunTableName: {
value: trainspaceRunTable.tableName
value: "trainspace"
}
});
}
Loading