Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

MySQL tables_rows → SysML Blocks_Instances

The objective of this exercise is to generate Rhapsody SysML blocks and instances from a MySQL database. Many organizations store data about products in such databases and it is desirable to be able to import this data into the SysML model. In this exercise, we will use the MySQL table created in the previous example and import this information back into an empty model in Rhapsody.

  1. As in tutorials 2.3 and 2.5, create a new Rhapsody SysML project with an empty package and the Syndeia profile.
  2. Name the empty package Tutorial_2_07.
  3. Right-click on Tutorial_2_07 and open the Syndeia dashboard.
  4. Expand Component database in the Connection Manager tab to show the databases and tables within the database. In this example, we are using the component table in the test_demo database, as shown in Figure 59.


     Figure 59 Syndeia Dashboard, Connection Manager tab, showing MySQl repository Component


    Figure 60 Dialog box

  5. In the first exercise, we will Create a block in SysML linked to the table component in MySQL. Set the Connection Type to Model Transform. Drag the table component (see red arrow in Figure 59) into the Tutorial_2_07 package in the SysML model. Click Yes on the dialog box (Figure 60). When complete, component appears as a block in the SysML model panel as in Figure 61. Note that while the component block contains the structure of the component table (this can be seen in Rhapsody), it does not contain any of the data about specific components. This is the object of the next step.
     

    Figure 61 Syndeia Dashboard, Connection Manager tab, showing MySQl table component and the SysML block component


     

    Figure 62 Instance generation dialog box

  6. Set the Connection Type to Data Map. Select several of the individual records under the component table in the right-hand panel. Drag them into the Tutorial_2_07 package in the left panel. A dialog box as in Figure 62 will appear. Leave the "As Specialization" checkbox unchecked and click Yes. The new SysML instances are shown in Figure 63.

     
    Figure 63 Syndeia Dashboard, Connection Manager tab, showing new SysML instance created 

  7. Explore other options for creating transferring MySQL records to the SysML model
    1. Create a new package in the SysML project and drag some MySQL records into it. They will still be treated as instances (or specializations) of the component block even if they are not in the same package.
    2. In the Filter query box (upper left corner) of the Connection Manager., enter a valid MySQL syntax query, for example, Select * from test_demo.component where Mass < '3'. Only those records satisfying the query will be displayed and can be dragged into the SysML model.
    3. Erase the current contents of the Tutorial_2_07 package in Rhapsody, including all connections. Drag some MySQL records into it. Note that a component block is created automatically, along with the specializations corresponding to the individual records.
  8. In the next part of the exercise, we will make change to the data in the database and update the SysML model from MySQL. Go to the MySQL Workbench and modify some details of the connected rows. For example, see Figure 64 where the left side shows the components table before making changes and the right side show the changes. The cost of the Communication Controller was increased from 25 to 50 and the mass of the Payload Controller was increased from 1.5 to 2.5.


    Figure 64 Modify contents of database in MySQL Workbench

     
  9. Now multiple select (using Ctrl key) connections C2 and C6 that correspond to the 2 modified rows. Right click and select Sync Target → SysML, as shown in Figure 65.


    Figure 65Multiple select connections, right click, and select Sync Target → SysML

  10. The Syndeia log window will show messages similar to below:

    16:57:19] INFO Processing 2 connections...
    [16:57:19] INFO Updating SysML block from MySQL table row for connection C2.
    [16:57:19] DEBUG GID of source: GUID 9e4c94e6-6344-4ea5-a8dd-25f28a3ddc0d | GUID a2f00ea8-6d04-44f1-bdae-cd993895cd41
    [16:57:19] DEBUG GID of target: Component database | {"database":"test_demo","table":"component","row":"Payload Controller","column":null}
    [16:57:19] DEBUG Setting real number 2.5 as the default value for property Mass. Creating a LiteralReal.
    [16:57:19] INFO Default value of value property Mass is changed from 1.5 to 2.5
    [16:57:19] INFO C2 connected sources (SysML) updated.
    [16:57:19] INFO Updating SysML block from MySQL table row for connection C6.

     

    Figure 66 Updated values from MySQL

     
  11. In the Rhapsody Features windows, you can see that the appropriate initial values have been updated, as shown in Figure 66.
  12. Similarly, you can change the SysML instance slot value or block (default) value in Rhapsody and sync to MySQL by right-clicking the appropriate connection and selecting Sync SysML → Target.

SysML Blocks_Instances → MySQL tables_rows

The objective of this exercise is to generate a table in a MySQL database from a collection of blocks in Rhapsody and then update that table when values change in the SysML model. The following exercise shows this process in reverse. We will use the collection of blocks in the Tutorial_2_06 package in the Rhapsody model supplied, Syndeia Tutorial Testbed. We see a component block with 12 specializations. We will use the parent component block to generate the table structure, using the value properties as column headers, and the specialized blocks to generate the table rows, with the default values as the column entries in each row.

The same process works if the 12 blocks are instances rather than specializations of the component block. Whether the modeler uses instances or specializations to capture actual parameter values is a methodology question; Rhapsody and Syndeia support both.

For users unfamiliar with MySQL databases, Appendix 3 describes how to access the databases directly using the MySQL Workbench, where the user can create, modify, and view schemas, tables and table rows directly. 

Image Added
Figure 48 Contents of Tutorial_2_06 package in Syndeia Tutorial Testbed

  1. Launch the Syndeia dashboard from the Tutorial_2_06 package in the SysML model.
  2. Set up the repository link to the MySQL repository using the Repository Manager, if this was not completed in Tutorial 2.1. The MySQL repository should contain a schema to which you have write privileges. In our example, this is named demo_tutorial. See Appendix 3 for more information on creating schemas in MySQL.
  3. The first step is to create the table in MySQL. Go to the Connection Manager tab. Set the Connection Type to Model Transform, as shown in Figure 59 Syndeia Dashboard, Connection Manager tab, showing MySQl repository . Drag the parent block, component, from SysML to demo_tutorial in MySQL.

    Image Added
    Figure 49 Contents of Tutorial_2_06 package in Syndeia Tutorial Testbed

    Image Added
    Figure 50 Confirming table generation

     
  4. Confirm table generation as shown in Figure 50.
  5. When complete, the Connection Manager should show a new table, component, under demo_tutorial, as shown in Figure 59

    Image Added
    Figure 51 Connection Manager after generation of new table, component 

    Image Added

    Figure 52 Connection Summary tab shows link between SysML block and MySQL table

     
  6. The Connection Summary, as shown in Figure 50, shows the connection created between the SysML block and the MySQL table.
  7. The next step is to create a row in the table in MySQL. Set the Connection Type to Data Map, as shown in Figure 61. Drag the child block, Atmospheric Sensor, from SysML to component in MySQL.

    Image Added
    Figure 53 Generating a table row from the Atmospheric Sensor block
     
  8. When complete, the Connection Manager will appear as shown in Figure 54

    Image Added
     Figure 54 Generating a table row from the Atmospheric Sensor block (final) 

    Image Added 

    The table viewed in the MySQL database through the MySQL Workbench appear as in Figure 55.

  9. Before completing the table, we will demonstrate how to compare and synchronize the parameter values between the SysML model and the MySQL database. In Rhapsody, modify the default value of the cost value property of the Atmospheric Sensor block, from 100 to 50. In the Connection Browser, right click on the connection from the Atmospheric Sensor block and select Compare SysML & Target, as shown in Figure 56.

    Image Added
     Figure 56 Creating a Comparison Summary between SysML and MySQL parameter values

  10. To update the parameter value in MySQL, right-click on the same connection and select Synch SysML to Target and confirm. When complete, the Comparison Summary will appear as shown in Figure 57. The changed value of Atmospheric Sensor.Mass can also be observed directly using the MySQL Workbench.

     Image Added
    Figure 57 Comparison Summary after updating SysML value to MySQL table
     

  11. The remaining SysML specialized blocks can be dragged over in one step my multiple-selecting the blocks on the left side of the Connection Manager tab and dragging them onto the component table on the right. When complete, the Connection Manager will appear as shown in Figure 58.

    Image Added
     Figure 58 Connection Browser after dragging all components to MySQL table