зеркало из https://github.com/Azure/Feathr.git
Return id and version on creating
This commit is contained in:
Родитель
3ba545b36a
Коммит
76ae9a4ec4
|
@ -65,7 +65,7 @@ impl FeathrApiV1 {
|
|||
data.0
|
||||
.request(None, FeathrApiRequest::CreateProject { definition })
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ impl FeathrApiV1 {
|
|||
},
|
||||
)
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
@ -208,7 +208,7 @@ impl FeathrApiV1 {
|
|||
},
|
||||
)
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ impl FeathrApiV1 {
|
|||
},
|
||||
)
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
@ -304,7 +304,7 @@ impl FeathrApiV1 {
|
|||
},
|
||||
)
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ impl FeathrApiV2 {
|
|||
FeathrApiRequest::CreateProject { definition },
|
||||
)
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
@ -201,7 +201,7 @@ impl FeathrApiV2 {
|
|||
},
|
||||
)
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
@ -339,7 +339,7 @@ impl FeathrApiV2 {
|
|||
},
|
||||
)
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ impl FeathrApiV2 {
|
|||
},
|
||||
)
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
@ -619,7 +619,7 @@ impl FeathrApiV2 {
|
|||
},
|
||||
)
|
||||
.await
|
||||
.into_uuid()
|
||||
.into_uuid_and_version()
|
||||
.map(|v| Json(v.into()))
|
||||
}
|
||||
|
||||
|
|
|
@ -449,6 +449,7 @@ impl TryInto<registry_provider::DerivedFeatureDef> for DerivedFeatureDef {
|
|||
#[derive(Clone, Debug, Serialize, Object)]
|
||||
pub struct CreationResponse {
|
||||
pub guid: String,
|
||||
pub version: u64,
|
||||
}
|
||||
|
||||
impl TryInto<Uuid> for CreationResponse {
|
||||
|
@ -459,10 +460,11 @@ impl TryInto<Uuid> for CreationResponse {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Uuid> for CreationResponse {
|
||||
fn from(id: Uuid) -> Self {
|
||||
impl From<(Uuid, u64)> for CreationResponse {
|
||||
fn from((id, version): (Uuid, u64)) -> Self {
|
||||
Self {
|
||||
guid: id.to_string(),
|
||||
version,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ pub enum FeathrApiResponse {
|
|||
Error(ApiError),
|
||||
|
||||
Unit,
|
||||
Uuid(Uuid),
|
||||
UuidAndVersion(Uuid, u64),
|
||||
EntityNames(Vec<String>),
|
||||
Entity(Entity),
|
||||
Entities(Entities),
|
||||
|
@ -170,10 +170,10 @@ pub enum FeathrApiResponse {
|
|||
}
|
||||
|
||||
impl FeathrApiResponse {
|
||||
pub fn into_uuid(self) -> poem::Result<Uuid> {
|
||||
pub fn into_uuid_and_version(self) -> poem::Result<(Uuid, u64)> {
|
||||
match self {
|
||||
FeathrApiResponse::Error(e) => Err(e.into()),
|
||||
FeathrApiResponse::Uuid(v) => Ok(v),
|
||||
FeathrApiResponse::UuidAndVersion(id, version) => Ok((id, version)),
|
||||
_ => panic!("Shouldn't reach here"),
|
||||
}
|
||||
}
|
||||
|
@ -222,9 +222,9 @@ impl From<()> for FeathrApiResponse {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Uuid> for FeathrApiResponse {
|
||||
fn from(v: Uuid) -> Self {
|
||||
Self::Uuid(v)
|
||||
impl From<(Uuid, u64)> for FeathrApiResponse {
|
||||
fn from((id, version): (Uuid, u64)) -> Self {
|
||||
Self::UuidAndVersion(id, version)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ where
|
|||
/**
|
||||
* Create new project
|
||||
*/
|
||||
async fn new_project(&mut self, definition: &ProjectDef) -> Result<Uuid, RegistryError>;
|
||||
async fn new_project(&mut self, definition: &ProjectDef) -> Result<(Uuid, u64), RegistryError>;
|
||||
|
||||
/**
|
||||
* Create new source under specified project
|
||||
|
@ -118,7 +118,7 @@ where
|
|||
&mut self,
|
||||
project_id: Uuid,
|
||||
definition: &SourceDef,
|
||||
) -> Result<Uuid, RegistryError>;
|
||||
) -> Result<(Uuid, u64), RegistryError>;
|
||||
|
||||
/**
|
||||
* Create new anchor under specified project
|
||||
|
@ -127,7 +127,7 @@ where
|
|||
&mut self,
|
||||
project_id: Uuid,
|
||||
definition: &AnchorDef,
|
||||
) -> Result<Uuid, RegistryError>;
|
||||
) -> Result<(Uuid, u64), RegistryError>;
|
||||
|
||||
/**
|
||||
* Create new anchor feature under specified anchor
|
||||
|
@ -137,7 +137,7 @@ where
|
|||
project_id: Uuid,
|
||||
anchor_id: Uuid,
|
||||
definition: &AnchorFeatureDef,
|
||||
) -> Result<Uuid, RegistryError>;
|
||||
) -> Result<(Uuid, u64), RegistryError>;
|
||||
|
||||
/**
|
||||
* Create new derived feature under specified project
|
||||
|
@ -146,7 +146,7 @@ where
|
|||
&mut self,
|
||||
project_id: Uuid,
|
||||
definition: &DerivedFeatureDef,
|
||||
) -> Result<Uuid, RegistryError>;
|
||||
) -> Result<(Uuid, u64), RegistryError>;
|
||||
|
||||
async fn delete_entity(&mut self, id: Uuid) -> Result<(), RegistryError>;
|
||||
|
||||
|
|
|
@ -166,12 +166,12 @@ where
|
|||
}
|
||||
|
||||
// Create new project
|
||||
async fn new_project(&mut self, definition: &ProjectDef) -> Result<Uuid, RegistryError> {
|
||||
async fn new_project(&mut self, definition: &ProjectDef) -> Result<(Uuid, u64), RegistryError> {
|
||||
// TODO: Pre-flight validation
|
||||
let mut prop = EntityProp::new_project(definition)?;
|
||||
match self.get_all_versions(&definition.qualified_name).last() {
|
||||
// It makes no sense to create a new version of a project
|
||||
Some(e) => Ok(e.id),
|
||||
Some(e) => Ok((e.id, e.version)),
|
||||
None => {
|
||||
prop.set_version(1);
|
||||
let project_id = self
|
||||
|
@ -184,7 +184,7 @@ where
|
|||
)
|
||||
.await?;
|
||||
self.index_entity(project_id, true)?;
|
||||
Ok(project_id)
|
||||
Ok((project_id, 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,18 +194,19 @@ where
|
|||
&mut self,
|
||||
project_id: Uuid,
|
||||
definition: &SourceDef,
|
||||
) -> Result<Uuid, RegistryError> {
|
||||
) -> Result<(Uuid, u64), RegistryError> {
|
||||
// TODO: Pre-flight validation
|
||||
let mut prop = EntityProp::new_source(definition)?;
|
||||
|
||||
for v in self.get_all_versions(&definition.qualified_name) {
|
||||
if v.properties == prop {
|
||||
// Found an existing version that is same as the requested one
|
||||
return Ok(v.id);
|
||||
return Ok((v.id, v.version));
|
||||
}
|
||||
}
|
||||
|
||||
prop.set_version(self.get_next_version_number(&definition.qualified_name));
|
||||
let version = self.get_next_version_number(&definition.qualified_name);
|
||||
prop.set_version(version);
|
||||
|
||||
let source_id = self
|
||||
.insert_entity(
|
||||
|
@ -221,7 +222,7 @@ where
|
|||
.await?;
|
||||
|
||||
self.index_entity(source_id, true)?;
|
||||
Ok(source_id)
|
||||
Ok((source_id, version))
|
||||
}
|
||||
|
||||
// Create new anchor under specified project
|
||||
|
@ -229,7 +230,7 @@ where
|
|||
&mut self,
|
||||
project_id: Uuid,
|
||||
definition: &AnchorDef,
|
||||
) -> Result<Uuid, RegistryError> {
|
||||
) -> Result<(Uuid, u64), RegistryError> {
|
||||
if self.get_entity_by_id(definition.source_id).is_none() {
|
||||
debug!(
|
||||
"Source {} not found, cannot create anchor",
|
||||
|
@ -258,12 +259,13 @@ where
|
|||
})
|
||||
{
|
||||
// Found existing anchor with same name and source
|
||||
return Ok(e.id);
|
||||
return Ok((e.id, e.version));
|
||||
}
|
||||
|
||||
// Create new version
|
||||
let mut prop = EntityProp::new_anchor(definition)?;
|
||||
prop.set_version(self.get_next_version_number(&definition.qualified_name));
|
||||
let version = self.get_next_version_number(&definition.qualified_name);
|
||||
prop.set_version(version);
|
||||
|
||||
let anchor_id = self
|
||||
.insert_entity(
|
||||
|
@ -282,7 +284,7 @@ where
|
|||
.await?;
|
||||
|
||||
self.index_entity(anchor_id, true)?;
|
||||
Ok(anchor_id)
|
||||
Ok((anchor_id, version))
|
||||
}
|
||||
|
||||
// Create new anchor feature under specified anchor
|
||||
|
@ -291,7 +293,7 @@ where
|
|||
project_id: Uuid,
|
||||
anchor_id: Uuid,
|
||||
definition: &AnchorFeatureDef,
|
||||
) -> Result<Uuid, RegistryError> {
|
||||
) -> Result<(Uuid, u64), RegistryError> {
|
||||
// TODO: Pre-flight validation
|
||||
let mut prop = EntityProp::new_anchor_feature(definition)?;
|
||||
|
||||
|
@ -309,10 +311,11 @@ where
|
|||
})
|
||||
{
|
||||
// Found existing anchor with same name and source
|
||||
return Ok(e.id);
|
||||
return Ok((e.id, e.version));
|
||||
}
|
||||
|
||||
prop.set_version(self.get_next_version_number(&definition.qualified_name));
|
||||
let version = self.get_next_version_number(&definition.qualified_name);
|
||||
prop.set_version(version);
|
||||
let feature_id = self
|
||||
.insert_entity(
|
||||
definition.id,
|
||||
|
@ -336,7 +339,7 @@ where
|
|||
}
|
||||
|
||||
self.index_entity(feature_id, true)?;
|
||||
Ok(feature_id)
|
||||
Ok((feature_id, version))
|
||||
}
|
||||
|
||||
// Create new derived feature under specified project
|
||||
|
@ -344,7 +347,7 @@ where
|
|||
&mut self,
|
||||
project_id: Uuid,
|
||||
definition: &DerivedFeatureDef,
|
||||
) -> Result<Uuid, RegistryError> {
|
||||
) -> Result<(Uuid, u64), RegistryError> {
|
||||
let input: HashSet<Uuid> = definition
|
||||
.input_anchor_features
|
||||
.iter()
|
||||
|
@ -382,10 +385,11 @@ where
|
|||
upstream == input && prop == e.properties
|
||||
})
|
||||
{
|
||||
return Ok(e.id);
|
||||
return Ok((e.id, e.version));
|
||||
}
|
||||
|
||||
prop.set_version(self.get_next_version_number(&definition.qualified_name));
|
||||
let version = self.get_next_version_number(&definition.qualified_name);
|
||||
prop.set_version(version);
|
||||
let feature_id = self
|
||||
.insert_entity(
|
||||
definition.id,
|
||||
|
@ -408,7 +412,7 @@ where
|
|||
}
|
||||
|
||||
self.index_entity(feature_id, true)?;
|
||||
Ok(feature_id)
|
||||
Ok((feature_id, version))
|
||||
}
|
||||
|
||||
async fn delete_entity(&mut self, id: Uuid) -> Result<(), RegistryError> {
|
||||
|
|
Загрузка…
Ссылка в новой задаче