forked from parseablehq/parseable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use MinIO play instance, so no need to run local MinIO for testing. - Add post_event handler - Rename config packages - Organize functions little better
- Loading branch information
Showing
6 changed files
with
62 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[s3] | ||
aws_access_key_id="Q3AM3UQ867SPQQA43P2F" | ||
aws_secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" | ||
aws_default_region="us-east-1" | ||
aws_endpoint_url="https://play.minio.io/" | ||
aws_bucket_name="67111b0f870e443ca59200b51221243b" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,57 @@ | ||
|
||
use std::env; | ||
use aws_sdk_s3::{Error}; | ||
use actix_web::{HttpRequest, HttpResponse}; | ||
use crate::config; | ||
|
||
#[tokio::main] | ||
pub async fn create_stream(s3_client: Option<aws_sdk_s3::Client>,stream_name: String) -> Result<(), Error> { | ||
match s3_client { | ||
Some(client) => { | ||
let resp = client | ||
.put_object() | ||
.bucket(env::var("AWS_BUCKET_NAME").unwrap().to_string()) | ||
.key(format!("{}{}", stream_name, "/.schema")) | ||
.send() | ||
.await?; | ||
println!("Upload success. Version: {:?}", resp.version_id); | ||
Ok(()) | ||
}, | ||
_ => { | ||
Ok(()) | ||
}, | ||
pub async fn put_stream(req: HttpRequest) -> HttpResponse { | ||
let stream_name: String = req.match_info().get("stream").unwrap().parse().unwrap(); | ||
let s3_client = config::ConfigToml::s3client(); | ||
match stream_exists(&s3_client, &stream_name) { | ||
Ok(_) => HttpResponse::Ok().body(format!("Stream {} already exists, please create a Stream with unique name", stream_name)), | ||
Err(_) => { | ||
match create_stream(&s3_client, &stream_name) { | ||
Ok(_) => HttpResponse::Ok().body(format!("Created Stream {}", stream_name)), | ||
Err(_) => HttpResponse::Ok().body(format!("Failed to create Stream {}", stream_name)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/* | ||
#[tokio::main] | ||
pub async fn bucket_exists(s3_client: Option<aws_sdk_s3::Client>,bucket_name: String, stream_name: String) -> bool { | ||
match s3_client { | ||
Some(client) => { | ||
let resp = client | ||
.get_object() | ||
.bucket(bucket_name) | ||
.key(format!("{}{}", stream_name, "/.schema")) | ||
.send(); | ||
println!("Bucket {:?} Exists", bucket_name); | ||
return true; | ||
}, | ||
None => { | ||
return false; | ||
}, | ||
pub async fn post_event(req: HttpRequest) -> HttpResponse { | ||
let stream_name: String = req.match_info().get("stream").unwrap().parse().unwrap(); | ||
let s3_client = config::ConfigToml::s3client(); | ||
match stream_exists(&s3_client, &stream_name) { | ||
Ok(_) => HttpResponse::Ok().body(format!("Uploading event to Stream {} ", stream_name)), | ||
Err(_) => HttpResponse::Ok().body(format!("Stream {} doesn't exist", stream_name)) | ||
} | ||
// TODO | ||
// 1. Check if this is the first event in the stream | ||
// a. If yes, create a schema and upload the schema file to <bucket>/<stream_prefix>/.schema. | ||
// b. If no, validate if the schema of new event matches existing schema. Fail with invalid schema, if no match. | ||
// 2. Add the event to existing Arrow RecordBatch. | ||
// 3. Check if event count threshold is reached, convert record batch to parquet and push to S3. | ||
// 4. Init new RecordBatch if previos record batch was pushed to S3. | ||
} | ||
|
||
#[tokio::main] | ||
pub async fn create_stream(s3_client: &aws_sdk_s3::Client, stream_name: &String) -> Result<(), Error> { | ||
let _resp = s3_client | ||
.put_object() | ||
.bucket(env::var("AWS_BUCKET_NAME").unwrap().to_string()) | ||
.key(format!("{}{}", stream_name, "/.schema")) | ||
.send() | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
pub async fn stream_exists(s3_client: &aws_sdk_s3::Client, stream_name: &String) -> Result<(), Error> { | ||
let _resp = s3_client | ||
.get_object() | ||
.bucket(env::var("AWS_BUCKET_NAME").unwrap().to_string()) | ||
.key(format!("{}{}", stream_name, "/.schema")) | ||
.send() | ||
.await?; | ||
Ok(()) | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters