Skip to content

Commit

Permalink
modern sync: Boiler plate for edenapi client
Browse files Browse the repository at this point in the history
Summary: WTTS

Reviewed By: clara-9

Differential Revision: D66559348

fbshipit-source-id: c59c70ddc763b3476788277452a08041c684e501
  • Loading branch information
lmvasquezg authored and facebook-github-bot committed Nov 28, 2024
1 parent 418b651 commit b19357f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
3 changes: 3 additions & 0 deletions eden/mononoke/modern_sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct ModernSyncArgs {

#[clap(flatten)]
pub repo: RepoArgs,

#[clap(long, hide = true)] // To be used only in integration tests
pub dest_socket: Option<u64>,
}

#[facet::container]
Expand Down
17 changes: 13 additions & 4 deletions eden/mononoke/modern_sync/src/sender/edenapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,39 @@
use anyhow::Result;
use edenapi::Client;
use edenapi::HttpClientBuilder;
use edenapi::SaplingRemoteApi;
use slog::info;
use slog::Logger;
use url::Url;

use crate::sender::ModernSyncSender;

#[allow(dead_code)]
pub struct EdenapiSender {
client: Client,
logger: Logger,
}

impl EdenapiSender {
pub fn new(url: Url, reponame: String) -> Result<Self> {
pub async fn new(url: Url, reponame: String, logger: Logger) -> Result<Self> {
info!(logger, "Connectign to {}", url.to_string());

let client = HttpClientBuilder::new()
.repo_name(&reponame)
.server_url(url)
.build()?;
Ok(Self { client })

let res = client.health().await;
info!(logger, "Health check outcome: {:?}", res);
Ok(Self { client, logger })
}
}
impl ModernSyncSender for EdenapiSender {
fn upload_content(
&self,
_content_id: mononoke_types::ContentId,
content_id: mononoke_types::ContentId,
_blob: mononoke_types::FileContents,
) {
eprintln!("not implemented yet")
info!(&self.logger, "Uploading content with id: {:?}", content_id)
}
}
9 changes: 8 additions & 1 deletion eden/mononoke/modern_sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::bul_util;
use crate::sender::dummy::DummySender;
use crate::sender::edenapi::EdenapiSender;
use crate::sender::ModernSyncSender;
use crate::ModernSyncArgs;
use crate::Repo;
const MODERN_SYNC_COUNTER_NAME: &str = "modern_sync";

Expand Down Expand Up @@ -96,7 +97,13 @@ pub async fn sync(
let sender: Arc<dyn ModernSyncSender + Send + Sync> = if dry_run {
Arc::new(DummySender::new(logger.clone()))
} else {
Arc::new(EdenapiSender::new(Url::parse(&config.url)?, repo_name)?)
let url = if let Some(socket) = app.args::<ModernSyncArgs>()?.dest_socket {
// Only for integration tests
format!("{}:{}/edenapi/", &config.url, socket)
} else {
format!("{}/edenapi/", &config.url)
};
Arc::new(EdenapiSender::new(Url::parse(&url)?, repo_name, logger.clone()).await?)
};

bul_util::read_bookmark_update_log(
Expand Down
4 changes: 2 additions & 2 deletions eden/mononoke/tests/integration/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ function mononoke_modern_sync {
"${COMMON_ARGS[@]}" \
--repo-id "$REPOID" \
--mononoke-config-path "$TESTTMP/mononoke-config" \
sync-once --start-id "$START_ID" \
--dry-run
--dest-socket $MONONOKE_SOCKET \
sync-once --start-id "$START_ID"
}

function mononoke_admin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
Sync all bookmarks moves
$ with_stripped_logs mononoke_modern_sync 0
Running sync-once loop
Connectign to https://localhost:$LOCAL_PORT/edenapi/
Health check outcome: Err(Http(Tls(TlsError { source: Error { description: "SSL peer certificate or SSH remote key was not OK", code: 60, extra: Some("SSL certificate problem: self signed certificate in certificate chain") }, kind: CaCert })))
Found commit ChangesetId(Blake2(53b034a90fe3002a707a7da9cdf6eac3dea460ad72f7c6969dfb88fd0e69f856))
Commit info ChangesetInfo { changeset_id: ChangesetId(Blake2(53b034a90fe3002a707a7da9cdf6eac3dea460ad72f7c6969dfb88fd0e69f856)), parents: [], author: "test", author_date: DateTime(1970-01-01T00:00:00+00:00), committer: None, committer_date: None, message: Message("A"), hg_extra: {}, git_extra_headers: None }
File change Change(TrackedFileChange { inner: BasicFileChange { content_id: ContentId(Blake2(eb56488e97bb4cf5eb17f05357b80108a4a71f6c3bab52dfcaec07161d105ec9)), file_type: Regular, size: 1, git_lfs: FullContent }, copy_from: None })
Expand Down
3 changes: 1 addition & 2 deletions eden/scm/sapling/testing/ext/mononoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,10 @@ def append_def_config(content: str, mode: str = "a"):
"""
)

mononoke_socket = env.getenv("MONONOKE_SOCKET")
append_config(
f"""
[modern_sync_config]
url=\"https://localhost:{mononoke_socket}/edenapi/\"
url=\"https://localhost\"
"""
)

Expand Down

0 comments on commit b19357f

Please sign in to comment.