Monday, 22 July 2013

Converting a VirtualBox VM to a VMWare Workstation 7.0.1 VM

To successfully convert a VirtualBox (latest version) vm to VMWare Workstation 7.0.1 vm one should do the following:
1. In VirtualBox export vm as ovf virtual appliance without manifest file (don't forget to check 'ovf version 0.9').
2. Ensure that VMWare will understand newly generated ovf file. To do it:
2.1 Edit ovf file so 'rasd' elements are sorted in the following order:
  <Item>
    <rasd:Caption>Some caption</rasd:Caption>
    <rasd:Description>Some description</rasd:Description>
    <rasd:InstanceId>0</rasd:InstanceId>
    <rasd:ResourceType>1</rasd:ResourceType>
    <rasd:ResourceSubType>2</rasd:ResourceSubType>
  </Item>
2.2 Ensure that rasd:Parent elements precede rasd:AdressOnParent elements.
2.3 Change the extension of original vmdk disk files to something like '~vmdk'.
2.4 Check that conversion is possible using VMWare OVF Tool with the following command:
"C:\Program Files\VMware\VMware OVF Tool\ovftool.exe" --noDisks "ODD - Source.ovf" "ODD - Source.vmx"
You should see the following output:
Opening OVF source: ODD - Source.ovf
Opening VMX target: ODD - Source.vmx
Writing VMX file: ODD - Source.vmx
Transfer Completed
Warning:
 - No manifest file found.
 - No manifest entry found for: 'ODD - Source-disk1.vmdk'.
 - No manifest entry found for: 'ODD - Source-disk2.vmdk'.
Completed successfully
If not, the tool will report error lines. So correct errors and rerun.
2.5 Delete vmdk files generated by ovftool and change back the extension of original files.

Pitiful but OVF Tool alone cannot properly convert ovf to vmx. Disk partitions will remain read only as made by VirtualBox export process.
3. So the last thing to do is to use VMWare Converter 4.0.1 (can be downloaded following links in this post) to convert ovf to vmx changing disks types to 2 GB Split pre-allocated.

Thursday, 4 July 2013

On database link naming

Name dblinks as a site it refers.
For example name it 'subdomain.somesite.com' and then create synonyms to objects on the site:
create synonym some_table for some_table@subdomain.somesite.com
Doing so you help other developers to decipher the site particular database link refers to without consulting all_db_links system view.

Friday, 7 June 2013

Perl script to extract and present hex colors found in arbitrary text

The following script searches STDIN for 3 or 6 symbol hex values and prints a html structure that represents those values as colors on page.
#!/usr/bin/perl -w
use Set::Scalar;

$uniqueColors = Set::Scalar->new;
while( defined( $_ = <STDIN> ) ){
 while ( $_ =~/(#[a-fA-F0-9]{1,6})/g ){
  $uniqueColors->insert( $1 )
 }
}
print <<HEADER;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
   <HEAD>
      <TITLE>Found HEX colors</TITLE>
   </HEAD>
   <BODY>
HEADER
while ( defined( my $color = $uniqueColors->each ) ){
 print "<p style=\"background: " . $color . "\">" . $color . "</p>\n"
}
print "</BODY>
</HTML>"
Used this one to parse color-theme-tangotango.el emacs color theme file.
To view example output hit "read more".

Interesting remarks on using standard libraries

While searching for implementation of Sets in Perl bumped into these interesting arguments for using standard libraries on StackOverflow.

Use one of the many Set modules on CPAN. Judging from your example, Set::Light or Set::Scalar seem appropriate.


I can defend this advice with the usual arguments pro CPAN (disregarding possible synergy effects).

  1. How can we know that look-up is all that is needed, both now and in the future? Experience teaches that even the simplest programs expand and sprawl. Using a module would anticipate that.
  2. An API is much nicer for maintenance, or people who need to read and understand the code in general, than an ad-hoc implementation as it allows to think about partial problems at different levels of abstraction.
  3. Related to that, if it turns out that the overhead is undesirable, it is easy to go from a module to a simple by removing indirections or paring data structures and source code. But on the other hand, if one would need more features, it is moderately more difficult to achieve the other way around.
  4. CPAN modules are already tested and to some extent thoroughly debugged, perhaps also the API underwent improvement steps over the time, whereas with ad-hoc, programmers usually implement the first design that comes to mind.

Rarely it turns out that picking a module at the beginning is the wrong choice.

Thursday, 6 June 2013

Oracle SQL selects to get familiar with table naming standard and to find junk tables in scheme

Run following selects to discover prefix and suffix hierarchies and to get count of particular prefix/suffix occurrences. That will help you become familiar with naming standard and to find suspicious prefixes/suffixes that belong to tables that probably store junk data.

Wednesday, 5 June 2013

Highlight empty tables in PowerDesigner model with VB Script

The wonderful thing about PowerDesigner automation is that you can actually connect to database from VB Script to get some crucial information that is unavailable (or was not captured) at a reverse engineering phase.
The following script queries Oracle ALL_TABLES system view to find out if table in the model stores any data. Then those tables that are empty are highlighted with thick maroon frame.

Monday, 3 June 2013

Working with PowerDesigner models through VB interface

PowerDesigner has great automation abilities. The easiest way to work with a model programmatically is to use PowerDesigner's embedded Visual Basic script interface and to run scripts through 'Edit/Run script' window.
Here's an example script that uses given color to highlight tables that have comments or that have at least one column with a comment:
Dim model
Set model = ActiveModel
For each table in model.Tables
   doPaint = false
   tableComment = Trim( table.Comment )
   if ( "" <> tableComment ) then
      doPaint = true
   end if

   if ( not doPaint ) then
      For each column in table.Columns
         comment = Trim( column.Comment )
         if ( "" <> comment ) then
            doPaint = true
            Exit For
         end if
      Next   
   end if
   
   if ( doPaint ) then
      For each symbol in table.Symbols
         symbol.BrushStyle = 6 'Gradient 
         symbol.GradientFillMode = 64
         symbol.FillColor = RGB( 252, 178, 104 ) 
         symbol.GradientEndColor = RGB( 255, 255, 255 )
      Next
   end if
Next
More info about PowerDesigner automation at SyBooks and PowerDesigner's 'Metadata Objects' help file.
Tip: when reverse engineering big unfamiliar scheme you can easily select and move apart particular symbols by adjusting their 'Position' property. For example you can select and move tables with particular prefix:
Dim model
Set model = ActiveModel
PREFIX = "hh_"
For each table in model.Tables
   tableName = LCase( Trim( table.Name ) )
   if ( PREFIX = Left( tableName, Len( prefix) ) ) then
      For each symbol in table.Symbols
         symbol.Position = NewPoint( 0, 0 )
      Next
   end if
Next
After desired symbols are moved to the (0,0) position they can be selected and arranged with 'Symbol->Auto layout command'.
This simple solution of how to distill big scheme came to me after I had reversed database with 2K of tables with a few foreign key constants defined. I faced a brick wall of tables arranged by their column count. All semantics were encoded in table names so I just had to set apart tables with equal prefixes. I've searched for a function to add symbols to selection but with no success. So I decided to move desired symbols to the center of workspace and then to select them with single mouse movement. That's when 'Auto layout' command came in very handy.