hoslo commented on code in PR #3564: URL: https://github.com/apache/incubator-opendal/pull/3564#discussion_r1390217530
########## core/src/services/alluxio/core.rs: ########## @@ -0,0 +1,388 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::fmt::Debug; +use std::fmt::Formatter; + +use http::Request; + +use http::header::RANGE; +use http::Response; + +use serde::{Deserialize, Serialize}; + +use crate::raw::*; +use crate::*; + +#[derive(Debug, Serialize)] +struct CreateFileRequest { + #[serde(skip_serializing_if = "Option::is_none")] + recursive: Option<bool>, +} + +#[derive(Debug, Serialize)] +struct CreateDirRequest { + #[serde(skip_serializing_if = "Option::is_none")] + recursive: Option<bool>, +} + +/// Metadata of alluxio object +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub(super) struct FileInfo { + /// The path of the object + pub path: String, + /// The last modification time of the object + pub last_modification_time_ms: i64, + /// Whether the object is a folder + pub folder: bool, + /// The length of the object in bytes + pub length: u64, +} + +impl TryFrom<FileInfo> for Metadata { + type Error = Error; + + fn try_from(file_info: FileInfo) -> Result<Metadata> { + let mut metadata = if file_info.folder { + Metadata::new(EntryMode::DIR) + } else { + Metadata::new(EntryMode::FILE) + }; + metadata + .set_content_length(file_info.length) + .set_last_modified(parse_datetime_from_from_timestamp_millis( + file_info.last_modification_time_ms, + )?); + Ok(metadata) + } +} + +/// the status code of alluxio +#[derive(Debug, Deserialize)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +enum StatusCode { + AlreadyExists, + NotFound, + Internal, + InvalidArgument, +} + +/// the error response of alluxio +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct ErrRsponse { + status_code: StatusCode, + message: String, +} + +fn paese_alluxio_error_response(err_response: ErrRsponse) -> Error { + match err_response.status_code { + StatusCode::AlreadyExists => Error::new(ErrorKind::AlreadyExists, &err_response.message), + StatusCode::NotFound => Error::new(ErrorKind::NotFound, &err_response.message), + StatusCode::Internal => Error::new(ErrorKind::Unexpected, &err_response.message), + StatusCode::InvalidArgument => Error::new(ErrorKind::InvalidInput, &err_response.message), + } +} + +/// Alluxio core +#[derive(Clone)] +pub struct AlluxioCore { + /// path request prefix + pub paths_prefix_request: &'static str, Review Comment: I finished revising. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
