Reconcile and Post Conflict Detection Enhancement Please

1079
3
11-27-2012 08:33 AM
Status: Open
Labels (1)
KenCarrier
Regular Contributor
I am really impressed with the amount of functionality added in models and python for database administration in 10.1. One area which I think could still be improved is with the ReconcileVersions_management tool. If I were going to use the example for batch reconcile and post found here. I still have no way of trapping if conflicts were found. I think many of us would want to know within the script if a conflict was found and kick off another function or process. For example;

If conflicts == true:
    send email and attach log file(Conflicts Exist!!!)
    compress database
    resume connections to database
    run analyze
else:
    send email that no conflicts found(Reconcile Post Successful)
    compress database
    recreate versions
    resume connections to database
    run analyze
    start ArcGIS Server/Services

Currently there is no way out of the box to return a variable to know whether conflicts exist. We can tell the tool to abort if conflicts but once the tool has run how do we know or catch if conflicts existed? If there could be a variable returned to let us know, we could parse out the logic in our scripts to account for conflicts. For example, I would not recreate the versions if conflicts were detected because I would not delete those versions until the conflicts were resolved.

The only logic I have been able to come up with currently is to iterate through the versions after the ReconcileVersions_management tool has run, if the count of the list is 1, then I can only assume that this is the default version. If more than 1 version exist I can assume there was a conflict but how do I really know unless the tool can return a boolean variable letting me know. Below is the logic;

versionList = arcpy.ListVersions(InputDBConn)
arcpy.ReconcileVersions_management(InputDBConn, "ALL_VERSIONS", "sde.DEFAULT", versionList, "LOCK_ACQUIRED", "ABORT_CONFLICTS", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "DELETE_VERSION")
print "after reconcile"
versionList = arcpy.ListVersions(InputDBConn)
print versionList
if versionList == 1:
    print "Reconcile and Post Successful"
else:
    print "More than 1 version found conflicts might exist?"

So is it possible to return some type of variable so we can flag if conflicts existed or not after the ReconcileVersions_management tool has run please?

    
3 Comments
RussBell
Great idea!  I also would like a return status for this tool.  My script loops through the versions in an explicit child to parent order and we want to stop posting if a conflict is found.  I had to work around by capturing the log on each r/p and parse it to look for the string 'Conflicts found' in the output log.  Used a function after each call to the tool to append the log output to a single file and check for conflicts at the same time.

#-----------------------------------------
# Function to append temp geoprocessing log to combined one and detect r/p conflict
def AppendGeoLog(filename):

    fin = open(filename, "r")
    ilog = fin.read()
    if 'Conflicts found' in ilog:
        rp_status = 'CONFLICT'
    else:
        rp_status = 'OK'
    fin.close()
    
    fout = open(Geo_Log, "a")
    fout.write("\n")
    fout.write(ilog)
    fout.close()

    return rp_status
#-----------------------------------------

Also, the parameters information in the documentation for ReconcileVersions_management has incorrect data type for many of the parameters.  Many of the booleans should be string.
KenCarrier
@russelbell - Here is a method I am using to check if conflicts exist.
# If this error arises, there were conflicts in the versions.
    if "000084" in arcpy.GetMessages(1):
        print "Reconcile and Post Conflicts"
        SUBJECT = "Reconcile and Post Conflicts"
        # Append contents of RecPostLog to email message
        MSG = "Auto generated Message.\n Reconcile and Post Conflicts.\n\{0}".format(TEXT)
        TO = ('person1@gmail.com','person2@gmail.com',)
        FROM = "fromhere@gmail.com"
        SendEmail(SUBJECT,MSG,TO,FROM)
    else:
        # This assumes the reconcile and post process was successful.
        # Reconcile, Abort if conflicts are found, delete all versions since
        # no conflicts were found in previous reconcile, do not write to log file
        arcpy.ReconcileVersions_management(InputDBConn,
                                           "ALL_VERSIONS",
                                           "sde.DEFAULT",
                                           versionList,
                                           "LOCK_ACQUIRED",
                                           "ABORT_CONFLICTS",
                                           "BY_OBJECT",
                                           "FAVOR_EDIT_VERSION",
                                           "POST",
                                           "DELETE_VERSION")
        print arcpy.GetMessages() + "\n"
        arcpy.Compress_management(InputDBConn)
        print arcpy.GetMessages() + "\n"
        # Allow the database to accept connections again.
        arcpy.AcceptConnections(InputDBConn, True)
        print arcpy.GetMessages() + "\n"
        print "Reconcile and Post Successful {0}\n".format(datetime.now().strftime(TIME))
        SUBJECT = "Reconcile and Post Successful"
        MSG = "Auto generated Message.\n Reconcile and Post Successful.\n{0}".format(TEXT)
        TO = ('person1@gmail.com','person2@gmail.com',)
        FROM = "fromhere@gmail.com"
        SendEmail(SUBJECT,MSG,TO,FROM)
KenCarrier
Here is how I send the email.
def SendEmail(SUBJECT, MSG, TO, FROM):
    # take the email list and use it to send an email to connected users.
    #FROM = "Auditor SDE Admin <kcarrier@clermontcountyohio.gov>"
    COMMASPACE = ', '
    # Prepare actual message
    BODY = string.join((
            "From: %s" % FROM,
            "To: %s" %  COMMASPACE.join(TO),
            "Subject: %s" % SUBJECT ,
            "",
            MSG
            ), "\n")

    # Send the mail
    server = smtplib.SMTP("11.11.11.11",25)
    # If Authentication is required specify in the 2 lines below
    username = 'username'
    password = 'password'
    # Ping the server to do a handshake and authenticate
    server.ehlo()
    server.starttls()
    server.ehlo()
    #server.login(username,password)

    # Send the email and exit connection to smtp server
    server.sendmail(FROM, TO, BODY)
    server.quit()