Skip to content

Commit

Permalink
Merge pull request #4916 from systeminit/zack/mgmt-connect-components
Browse files Browse the repository at this point in the history
feat: connect components in management functions
  • Loading branch information
zacharyhamm authored Nov 4, 2024
2 parents dbf7d79 + 278c5a6 commit 3f9cf17
Show file tree
Hide file tree
Showing 8 changed files with 766 additions and 139 deletions.
9 changes: 9 additions & 0 deletions lib/dal-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ pub use signup::WorkspaceSignup;
pub use telemetry;
pub use tracing_subscriber;

pub use test_exclusive_schemas::{
SCHEMA_ID_BAD_VALIDATIONS, SCHEMA_ID_DUMMY_SECRET, SCHEMA_ID_ETOILES, SCHEMA_ID_FAKE_BUTANE,
SCHEMA_ID_FAKE_DOCKER_IMAGE, SCHEMA_ID_FALLOUT, SCHEMA_ID_KATY_PERRY,
SCHEMA_ID_LARGE_EVEN_LEGO, SCHEMA_ID_LARGE_ODD_LEGO, SCHEMA_ID_MEDIUM_EVEN_LEGO,
SCHEMA_ID_MEDIUM_ODD_LEGO, SCHEMA_ID_MORNINGSTAR, SCHEMA_ID_PET_SHOP, SCHEMA_ID_PIRATE,
SCHEMA_ID_PRIVATE_LANGUAGE, SCHEMA_ID_SMALL_EVEN_LEGO, SCHEMA_ID_SMALL_ODD_LEGO,
SCHEMA_ID_STARFIELD, SCHEMA_ID_SWIFTY, SCHEMA_ID_VALIDATED_INPUT, SCHEMA_ID_VALIDATED_OUTPUT,
};

const DEFAULT_TEST_PG_USER: &str = "si_test";
const DEFAULT_TEST_PG_PORT_STR: &str = "6432";
const DEFAULT_TEST_MODULE_INDEX_URL: &str = "http://localhost:5157";
Expand Down
103 changes: 103 additions & 0 deletions lib/dal-test/src/test_exclusive_schemas/legos/small.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,87 @@ pub(crate) async fn migrate_test_exclusive_schema_small_odd_lego(
let update_mgmt_func_name = "test:updateManagedComponent";
let update_mgmt_func = build_management_func(update_managed_func_code, update_mgmt_func_name)?;

let create_and_connect_from_self_func_code = r#"
async function main({ thisComponent, components }: Input): Promise<Output> {
const thisName = thisComponent.properties?.si?.name ?? "unknown";
let count = parseInt(thisComponent.properties?.si?.resourceId);
if (isNaN(count) || count < 1) {
count = 1;
}
const create: { [key: string]: unknown } = {};
const names = [];
for (let i = 0; i < count; i++) {
let name = `clone_${i}`;
names.push(name);
create[name] = {
kind: "small even lego",
properties: { si: { name } },
};
}
return {
status: "ok",
ops: {
create,
update: {
self: {
connect: {
add: names.map(name => ({ from: "two", to: { component: name, socket: "two" }}))
}
}
}
},
message: `created ${names.join(", ")}`,
}
}
"#;
let create_and_connect_from_self_name = "test:createAndConnectFromSelf";
let create_and_connect_from_self_func = build_management_func(
create_and_connect_from_self_func_code,
create_and_connect_from_self_name,
)?;

let create_and_connect_to_self_func_code = r#"
async function main({ thisComponent, components }: Input): Promise<Output> {
const thisName = thisComponent.properties?.si?.name ?? "unknown";
let count = parseInt(thisComponent.properties?.si?.resourceId);
if (isNaN(count) || count < 1) {
count = 1;
}
let create: { [key: string]: unknown } = {};
for (let i = 0; i < count; i++) {
let name = `clone_${i}`;
create[name] = {
kind: "small even lego",
properties: { si: { name } },
connect: [{
from: "one",
to: {
component: "self",
socket: "one",
}
}]
};
}
return {
status: "ok",
ops: {
create,
};
}
}
"#;
let create_and_connect_to_self_name = "test:createAndConnectToSelf";
let create_and_connect_to_self_func = build_management_func(
create_and_connect_to_self_func_code,
create_and_connect_to_self_name,
)?;

let fn_name = "test:deleteActionSmallLego";
let delete_action_func = build_action_func(delete_action_code, fn_name)?;

Expand Down Expand Up @@ -185,7 +266,9 @@ pub(crate) async fn migrate_test_exclusive_schema_small_odd_lego(
.domain_prop(bricks.domain_name_prop)
.domain_prop(bricks.domain_one_prop)
.domain_prop(bricks.domain_two_prop)
// Input socket "one"
.socket(bricks.socket_one)
// Output socket "two"
.socket(bricks.socket_two)
.action_func(
ActionFuncSpec::builder()
Expand Down Expand Up @@ -235,6 +318,24 @@ pub(crate) async fn migrate_test_exclusive_schema_small_odd_lego(
.func_unique_id(&update_mgmt_func.unique_id)
.build()?,
)
.management_func(
ManagementFuncSpec::builder()
.name("Create and Connect From Self")
.managed_schemas(Some(HashSet::from([
SCHEMA_ID_SMALL_EVEN_LEGO.to_string()
])))
.func_unique_id(&create_and_connect_from_self_func.unique_id)
.build()?,
)
.management_func(
ManagementFuncSpec::builder()
.name("Create and Connect To Self")
.managed_schemas(Some(HashSet::from([
SCHEMA_ID_SMALL_EVEN_LEGO.to_string()
])))
.func_unique_id(&create_and_connect_to_self_func.unique_id)
.build()?,
)
.build()?,
)
.build()?;
Expand All @@ -250,6 +351,8 @@ pub(crate) async fn migrate_test_exclusive_schema_small_odd_lego(
.func(import_management_func)
.func(clone_me_mgmt_func)
.func(update_mgmt_func)
.func(create_and_connect_from_self_func)
.func(create_and_connect_to_self_func)
.schema(small_lego_schema)
.build()?;

Expand Down
63 changes: 42 additions & 21 deletions lib/dal-test/src/test_exclusive_schemas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,48 @@ mod swifty;
const PKG_VERSION: &str = "2019-06-03";
const PKG_CREATED_BY: &str = "System Initiative";

const SCHEMA_ID_STARFIELD: &str = "01JARFRNN5VV1NMM0H5M63K3PY";
const SCHEMA_ID_PRIVATE_LANGUAGE: &str = "01JARFRNN5VV1NMM0H5M63K3PZ";
const SCHEMA_ID_ETOILES: &str = "01JARFRNN5VV1NMM0H5M63K3Q0";
const SCHEMA_ID_MORNINGSTAR: &str = "01JARFRNN5VV1NMM0H5M63K3Q1";
const SCHEMA_ID_FALLOUT: &str = "01JARFRNN5VV1NMM0H5M63K3Q2";
const SCHEMA_ID_DUMMY_SECRET: &str = "01JARFRNN5VV1NMM0H5M63K3Q3";
const SCHEMA_ID_SWIFTY: &str = "01JARFRNN5VV1NMM0H5M63K3Q4";
const SCHEMA_ID_KATY_PERRY: &str = "01JARFRNN5VV1NMM0H5M63K3Q5";
const SCHEMA_ID_PIRATE: &str = "01JARFRNN5VV1NMM0H5M63K3Q6";
const SCHEMA_ID_PET_SHOP: &str = "01JARFRNN5VV1NMM0H5M63K3Q7";
const SCHEMA_ID_VALIDATED_INPUT: &str = "01JARFRNN5VV1NMM0H5M63K3Q8";
const SCHEMA_ID_VALIDATED_OUTPUT: &str = "01JARFRNN5VV1NMM0H5M63K3Q9";
const SCHEMA_ID_BAD_VALIDATIONS: &str = "01JARFRNN5VV1NMM0H5M63K3QA";
const SCHEMA_ID_LARGE_ODD_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QB";
const SCHEMA_ID_LARGE_EVEN_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QC";
const SCHEMA_ID_MEDIUM_EVEN_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QD";
const SCHEMA_ID_MEDIUM_ODD_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QE";
const SCHEMA_ID_SMALL_ODD_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QF";
const SCHEMA_ID_SMALL_EVEN_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QG";
const SCHEMA_ID_FAKE_DOCKER_IMAGE: &str = "01JARFRNN5VV1NMM0H5M63K3QH";
const SCHEMA_ID_FAKE_BUTANE: &str = "01JARH2BTA5DK4J9Q4Q0XH46SR";
/// Schema id for the `starfield` schema variant
pub const SCHEMA_ID_STARFIELD: &str = "01JARFRNN5VV1NMM0H5M63K3PY";
/// Schema id for the `private language` schema varitn
pub const SCHEMA_ID_PRIVATE_LANGUAGE: &str = "01JARFRNN5VV1NMM0H5M63K3PZ";
/// Schema id for the `etoiles` schema variant
pub const SCHEMA_ID_ETOILES: &str = "01JARFRNN5VV1NMM0H5M63K3Q0";
/// Schema id for the `morningstar` schema variant
pub const SCHEMA_ID_MORNINGSTAR: &str = "01JARFRNN5VV1NMM0H5M63K3Q1";
/// Schema id for the `fallout` schema variant
pub const SCHEMA_ID_FALLOUT: &str = "01JARFRNN5VV1NMM0H5M63K3Q2";
/// Schema id for the `dummy secret` schema variant
pub const SCHEMA_ID_DUMMY_SECRET: &str = "01JARFRNN5VV1NMM0H5M63K3Q3";
/// Schema id for the `swifty` schema variant
pub const SCHEMA_ID_SWIFTY: &str = "01JARFRNN5VV1NMM0H5M63K3Q4";
/// Schema id for the `katy perry` schema variant
pub const SCHEMA_ID_KATY_PERRY: &str = "01JARFRNN5VV1NMM0H5M63K3Q5";
/// Schema id for the `pirate` schema variant
pub const SCHEMA_ID_PIRATE: &str = "01JARFRNN5VV1NMM0H5M63K3Q6";
/// Schema id for the `pet shop` schema variant
pub const SCHEMA_ID_PET_SHOP: &str = "01JARFRNN5VV1NMM0H5M63K3Q7";
/// Schema id for the `validated input` schema variant
pub const SCHEMA_ID_VALIDATED_INPUT: &str = "01JARFRNN5VV1NMM0H5M63K3Q8";
/// Schema id for the `validated output` schema variant
pub const SCHEMA_ID_VALIDATED_OUTPUT: &str = "01JARFRNN5VV1NMM0H5M63K3Q9";
/// Schema id for the `bad validations` schema variant
pub const SCHEMA_ID_BAD_VALIDATIONS: &str = "01JARFRNN5VV1NMM0H5M63K3QA";
/// Schema id for the `large odd lego` schema variant
pub const SCHEMA_ID_LARGE_ODD_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QB";
/// Schema id for the `large even lego` schema variant
pub const SCHEMA_ID_LARGE_EVEN_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QC";
/// Schema id for the `medium odd lego` schema variant
pub const SCHEMA_ID_MEDIUM_EVEN_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QD";
/// Schema id for the `medium even lego` schema variant
pub const SCHEMA_ID_MEDIUM_ODD_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QE";
/// Schema id for the `small odd lego` schema variant
pub const SCHEMA_ID_SMALL_ODD_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QF";
/// Schema id for the `small even lego` schema variant
pub const SCHEMA_ID_SMALL_EVEN_LEGO: &str = "01JARFRNN5VV1NMM0H5M63K3QG";
/// Schema id for the `fake docker image` schema variant
pub const SCHEMA_ID_FAKE_DOCKER_IMAGE: &str = "01JARFRNN5VV1NMM0H5M63K3QH";
/// Schema id for the `fake butane` schema variant
pub const SCHEMA_ID_FAKE_BUTANE: &str = "01JARH2BTA5DK4J9Q4Q0XH46SR";

// allow expect here for the Ulid conversion. These will never panic.
#[allow(clippy::expect_used)]
Expand Down
14 changes: 14 additions & 0 deletions lib/dal/src/diagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ pub struct SummaryDiagramEdge {
}

impl SummaryDiagramEdge {
pub fn assemble_just_added(incoming_connection: IncomingConnection) -> ComponentResult<Self> {
Ok(SummaryDiagramEdge {
from_component_id: incoming_connection.from_component_id,
from_socket_id: incoming_connection.from_output_socket_id,
to_component_id: incoming_connection.to_component_id,
to_socket_id: incoming_connection.to_input_socket_id,
change_status: ChangeStatus::Added,
created_info: serde_json::to_value(incoming_connection.created_info)?,
deleted_info: serde_json::to_value(incoming_connection.deleted_info)?,
to_delete: false,
from_base_change_set: false,
})
}

pub fn assemble(
incoming_connection: IncomingConnection,
from_component: &Component,
Expand Down
19 changes: 16 additions & 3 deletions lib/dal/src/func/binding/management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,15 @@ impl ManagementBinding {
r#"
{{
kind: {name},
properties: {sv_type},
geometry: Geometry,
properties?: {sv_type},
geometry?: Geometry,
connect?: {{
from: string,
to: {{
component: string;
socket: string;
}}
}}[],
}}
"#
);
Expand Down Expand Up @@ -115,7 +122,13 @@ type Output = {{
status: 'ok' | 'error';
ops?: {{
create?: {{ [key: string]: {component_types} }},
update?: {{ [key: string]: {{ properties?: {{ [key: string]: unknown }}, geometry: Geometry, }} }};
update?: {{ [key: string]: {{
properties?: {{ [key: string]: unknown }}, geometry?: Geometry, }},
connect?: {{
add?: {{ from: string, to: {{ component: string; socket: string; }} }}[],
remove?: {{ from: string, to: {{ component: string; socket: string; }} }}[],
}},
}},
actions?: {{ [key: string]: {{
add?: ("create" | "update" | "refresh" | "delete" | string)[];
remove?: ("create" | "update" | "refresh" | "delete" | string)[];
Expand Down
Loading

0 comments on commit 3f9cf17

Please sign in to comment.