Book a Demo

Author Topic: Automation of  Update from VersionControl  (Read 4396 times)

doctor_uv

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Automation of  Update from VersionControl
« on: June 27, 2007, 08:39:45 am »
Hi there,

I am searching for a while now trying to find a nice way to automate the update of the server model file from the Version Control Repository.
(before dumping daily an HTML export into the project webserver doctree ....)

I cannot find any automation API that does the GetAllLatest functionality.... only version control ci, co, add, etc.....
Do I have to program the walk through the project packages and call the VersionControl functions explicitly on every package after updating the working copy externally ???

Also I could not find a way to access a database hosted repository..... Is that intentionally so?
Dr. UV
Software Architect
Alcatel-Lucent IPTV

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Automation of  Update from VersionControl
« Reply #1 on: June 27, 2007, 06:35:19 pm »
Unfortunately there is no GetLatest functionality available in the Automation Interface at this time.

There is a Project.LoadControlledPackage(PackageGUID) function, but this is only designed for a single package and only uses package control (not the same as version control).  This function simply re-imports the local copy of the associated xml file into your model.

To perform the equivelent of a GetLatest call, you will need to manually get the latest versions of the xml files from version control, overwriting the copies in your working directory.  After you have the latest version of the xml files on your system, you should be able to call LoadControlledPackage to import these latest versions into your model.

To connect to a dbms repository from automation, you can either pass the full connection string into Repository.OpenFile, or you can create a shortcut eap file containing the connection string, and simply open the eap file (see below for details).

Example:
bSuccess = repository.OpenFile("OraEATest --- DBType=3;Connect=Provider=OraOLEDB.Oracle.1;Password=tiger;Persist Security Info=True;User ID=scott;Data Source=OraEATest")

The easiest way to obtain a copy of the connection string is from the "Open Project" dialog (File | Open Project).  Select the connection from the recent list, then copy the text in the "Project to Open" field.

To Save a shortcut eap file to your repository:
- Open you DBMS repository in EA
- File | Save Project As
- Specify a new filename and Save

HTH.

mark.myers

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
Re: Automation of  Update from VersionControl
« Reply #2 on: September 26, 2007, 06:56:11 pm »
Aaron,

there also appears to be no equivalent of a "GetPackage".
The scenario I am considering is two EA repositories (EA_Prod & EA_Dev) configured to use the same SVN source control repository (EA_SVN) and pointing to the same working copy (SVN_WC).

If I checkin a package from EA_DEV I could programmatically connect to EA_Prod and call Project.LoadControlledPackage(PackageGUID) to force an update in EA_Prod which is fine. However, if I ADD a new package in EA_DEV and put it under source control and check it in then how can I make it available to EA_Prod?

The only thing I can think of immeadiately is to call Project.ImportPackageXMI() passing the PackageGUID of the parent package and the location of the SVN_WC xmi file. Will this also establish the source control links for future LoadControlledPackage calls?

Regards,
Mark.
Cheers, Mark

doctor_uv

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re:Automation of Update from VersionControl inPERL
« Reply #3 on: October 05, 2007, 10:56:43 am »
#!/cygwin/bin/perl -W
####################################################
#  updateDBModel.pl
#  Update the Oracle model from subversion repository
#  this can runs as a cgi-script....
#  important is to check the permissions for the
#  executing user on the DCOM object EA
#  Created on:      06-Jul-2007 13:28:22
#  Original author: Dr. UV Wildner
####################################################
#
# set autoflush and provide an html header....
$|=1;
print "Content-type: multipart/x-mixed-replace;boundary=BOUNDARY\n\n--BOUNDARY\n";

use strict;
use Win32::OLE;
# connection string for the DB model
my $model = "ShareTV --- DBType=3;Connect=Provider=OraOLEDB.Oracle.1;Password=xxx;Persist Security Info=True;User ID=xxx;Data Source=XXXX";
#my $model = "C:/YourModel.eap";  # modify as needed
my $WorkingCopy="C:/YourWorkingCopy";
my $debug=1;
my $verbose=0;
my %PKGSTATES;
#
#########################################################################################
# functions
#########################################################################################
sub printPkgStates
{
   my ($hashref) = @_;
   my $key;
   foreach $key (keys %$hashref)
   {
     print "$key  $$hashref{$key}\n";
   }
}
#########################################################################################
sub getEnumCheckOutStatus
{
   my ($package) = @_;    
   my $i = $package->VersionControlGetStatus();
   return "csUncontrolled                  " if ($i == 0);
   return "csCheckedIn                     " if ($i == 1);
   return "csCheckedOutToThisUser          " if ($i == 2);
   return "csReadOnlyVersion               " if ($i == 3);
   return "csCheckedOutToAnotherUser       " if ($i == 4);
   return "csOfflineCheckedOutToThisUser   " if ($i == 5);
   return "csOfflineNotCheckedOutToThisUser" if ($i ==6);
   return "csDeleted                       " if ($i ==7);
   return "csUnknown                       ";
}
#########################################################################################
# recursive Package traverse using high order functions
sub dumpPackages
{
 my ($pkgCollection,$funcref,@rest) = @_;
 for (my $j=0;$j < $pkgCollection->Count;$j++)
 {
   my $package = $pkgCollection->GetAt($j);
   if ($funcref)
   {
     &$funcref($package,@rest);
   }
   # recurse children
   &dumpPackages($package->Packages,$funcref, @rest);
 }
}
#########################################################
# 2 functions to be passed into recursion                #
#########################################################
my $collectNames =                                       #
sub {                                                   #
 my ($package) = @_;                                    #
 if ($package->isVersionControlled)                    #
 {                                                      #
   my $pkgstate = getEnumCheckOutStatus($package);      #
   $PKGSTATES{$pkgstate}++;    # count states          #
   print "Package =>  ", $package->Name,"  $pkgstate\n";      
 }                                                     #
};                                                      #
#########################################################
my $checkout =                                           #
sub {                                                   #
 my ($package,$projectInterface) = @_;                  #
 if ($package->isVersionControlled)                    #  
 {                                                      #
   my $guid = $package->PackageGUID;                    #
   my $pkgstate = getEnumCheckOutStatus($package);      #
   $PKGSTATES{$pkgstate}++;    # count states          #
   print "\nContent-type: text/plain\n\n";                #
   print "Package =>  ",$package->Name,"  $pkgstate\n";#
   print "--BOUNDARY\n";                                #
   $projectInterface->LoadControlledPackage($guid);    #
 }                                                     #
};                                                      #
#########################################################
sub OleQuit {
   my ($ea) = @_;
   $ea->Exit();    
}
#########################################################
# update working copy from subversion
print "\nContent-type: text/plain\n\n";

die "model file $model not found\n" unless (-f $model || $model =~ /DBType/);
chdir $WorkingCopy;
my $svnCMD = "svn update --username XXX --password YYYY 2>&1 > .svnUpdate.log";
system ($svnCMD) == 0
  or die "system [$svnCMD] failed: $?";
print "svn in $WorkingCopy updated\n" if $debug;
print "--BOUNDARY\n";
#########################################################
# Open the model file
print "\nContent-type: text/plain\n\n";

# this is where the access permission have to be right for the perl script!!! (if run as a batch or as a CGI)
my $repository = Win32::OLE->new('EA.Repository', \&OleQuit) or die "oops cannot access Repository interface\n--BOUNDARY--\n";
$repository->EnableCache;
my $result = $repository->OpenFile($model);
print "file opened\n" if $result;
die $repository->GetLastError ()."\n--BOUNDARY--\n" unless $result;

my $allModels = $repository->Models();
die "no models found in $model\n--BOUNDARY--\n" unless ($allModels);

# get the XML/Report interface
my $projectInterface = $repository->GetProjectInterface();

print "found " , $allModels->Count, " models in file\n";
print "--BOUNDARY\n";

for (my $i=0;$i < $allModels->Count;$i++)
{
 my $model = $allModels->GetAt($i);
 print "\nContent-type: text/plain\n\n";
 print "model ==> ", $model->Name, "\n";
 print "--BOUNDARY\n";
 &dumpPackages($model->Packages,$checkout,$projectInterface);
}

print "\nContent-type: text/plain\n\n";
&printPkgStates(\%PKGSTATES);
print "--BOUNDARY--\n";
Dr. UV
Software Architect
Alcatel-Lucent IPTV

thomaskilian

  • Guest
Re: Automation of  Update from VersionControl
« Reply #4 on: October 05, 2007, 01:34:33 pm »
Ah! Perly White. Thanks Mc The Knife ;D

I wanted to write that piece of code too, but it's definitely easiert to borrow that one :)