Skip to content

Commit

Permalink
Import changes.
Browse files Browse the repository at this point in the history
  - 508945e57836dd9413411b8ed56c68430319773d

GitOrigin-RevId: 508945e57836dd9413411b8ed56c68430319773d
  • Loading branch information
Aalyria Technologies, Inc committed Oct 18, 2024
1 parent 6fe77f6 commit 009bb7f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/nbictl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ Insert the model NMTS Relationship contained within the file provided on the com

Delete the model NMTS Relationship contained within the file provided on the command line ('-' reads from stdin).

### upsert-fragment

Upsert the model NMTS Fragment contained within the file provided on the command line ('-' reads from stdin).

### list-elements

List all model elements (NMTS Entities and Relationships).
Expand Down
40 changes: 40 additions & 0 deletions tools/nbictl/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,46 @@ func ModelDeleteRelationship(appCtx *cli.Context) error {
return err
}

// TODO: turn these into one atomic RPC call in the modelfe.
func ModelUpsertFragment(appCtx *cli.Context) error {
nmtsFragment := &nmtspb.Fragment{}
if err := readProtoFromCommandLineFilenameArgument(appCtx, nmtsFragment); err != nil {
return err
}

conn, err := openAPIConnection(appCtx, modelAPISubDomain)
if err != nil {
return err
}
defer conn.Close()
modelClient := modelpb.NewModelClient(conn)

for _, nmtsEntity := range nmtsFragment.GetEntity() {
_, err = modelClient.UpsertEntity(
appCtx.Context,
&modelpb.UpsertEntityRequest{
Entity: nmtsEntity,
})
if err != nil {
return err
}
}

for _, nmtsRelationship := range nmtsFragment.GetRelationship() {
_, err = modelClient.InsertRelationship(
appCtx.Context,
&modelpb.InsertRelationshipRequest{
Relationship: nmtsRelationship,
})
if err != nil {
return err
}
}

fmt.Fprintln(appCtx.App.ErrWriter, "# OK")
return nil
}

func ModelGetEntity(appCtx *cli.Context) error {
if appCtx.Args().Len() != 1 {
return fmt.Errorf("need one and only one Entity ID argument")
Expand Down
6 changes: 6 additions & 0 deletions tools/nbictl/nbictl.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ func App() *cli.App {
Category: "model relationships",
Action: ModelDeleteRelationship,
},
{
Name: "upsert-fragment",
Usage: "Upsert the model NMTS Fragment contained within the file provided on the command line ('-' reads from stdin).",
Category: "model relationships",
Action: ModelUpsertFragment,
},
{
Name: "list-elements",
Usage: "List all model elements (NMTS Entities and Relationships).",
Expand Down

0 comments on commit 009bb7f

Please sign in to comment.