Access Keys:
Skip to content (Access Key - 0)

Knowledgebase

Part 5 : Sync With Trust Fabric


Table of Contents

Step 1: Set up the Index page

Add the Index method

  1. Open GridClient/thewebapp/views.py
  2. Add the index method
    # Create your views here.
    from django.http import HttpResponse
    
    def index(request):
        return HttpResponse("Hello, you're at the index :)")
    

Set up the index URL

  1. Open GridClient/urls.py
  2. Add the index URL and associate it with the index method in views.py
    urlpatterns = patterns('',
    (r'^index/$', 'thewebapp.views.index'),
    )
    
  3. Save the file

Start the server

  1. Go to run -> run configuration
  2. Select PyDev Django and then press the New button
  3. Give a name to the run operation, for this example we chose GridClient
    1. Select GridClient as the project
    2. Select GridClient/manage.py file as the Main Module
  4. Select the Arguments tab
    1. In Program arguments type runserver
    2. By default Django will have the server on localhost:8000
      1. To change the port number, in Program Arguments give runserver <port_number>
      2. To change the host to an ip address, in Program Arguments give runserver <server_ip>:<port_number>
  5. Select Apply, then select Run
  6. The console will show the following
    Validating models...
    0 errors found
    
    Django version 1.2.5, using settings 'GridClient.settings'
    Development server is running at http://127.0.0.1:8000/
    Quit the server with CONTROL-C.
    
  7. go to http://localhost:8000/index/ on your browser

Step 2: Implement Sync With Trust Fabric

  1. Edit GridClient/thewebapp/views.py
  2. Add imports, don't worry if eclipse complains about the imports
    from java.util import Properties
    from java.io import FileInputStream
    
    from gov.nih.nci.cagrid.common import Utils
    
    from gov.nih.nci.cagrid.syncgts.bean import SyncDescription
    from gov.nih.nci.cagrid.syncgts.core import SyncGTS
    
    import time
    import thread
  3. Add public variables
    #for reading client.properties
    CLIENT_PROPERTIES="conf/client.properties"
    SYNC_DESCRIPTION="sync.description"
    DEFAULT_DORIAN_SERVICE_URL_PROP = "default.dorian.service.url"
    DEFAULT_INDEX_SERVICE_URL_PROP = "default.index.service.url";
    
    props=None
  4. Implement the readProperties method
    #load client.properties and return as properties object
    def readProperties():   
        try: 
            tempprop=Properties()
            tempprop.load(FileInputStream(CLIENT_PROPERTIES))
            return tempprop
        except Exception, e:
            print "Exception while accessing %s %s" % (CLIENT_PROPERTIES,e)
  5. Implement the syncTrust method
    #sync with the trust fabric, every 15 minutes
    def syncTrust():
        while(1):
            print "Synchronizing Trust Fabric"
            try:
                description = Utils.deserializeDocument(props.getProperty(SYNC_DESCRIPTION), SyncDescription)
                SyncGTS.getInstance().syncOnce(description)
                print "Synchronizing Complete"
            except Exception,e:
                print "SyncGridTrust %s" % e
                print "Failed to Synchronize" 
            time.sleep(15*60)  
    
  6. load the client.properties file and start a thread to sync with the trust fabric
    #load client.properties into props
    if(props==None):props=readProperties()
    
    #start a thread to sync with the trust fabric
    thread.start_new_thread(syncTrust, ())
  7. save the file

Step 3: Test Sync With Trust Fabric

  1. refresh http://localhost/8000/index/
  2. You'll see on the eclipse console that the application synced with the trust fabric
    Synchronizing Trust Fabric
    Synchronizing Complete
  3. While you're developing your web application, comment out the thread line, you can uncomment it when you've finished developing your code
    #thread.start_new_thread(syncTrust, ())
Last edited by
Saba Bokhari (555 days ago)
Adaptavist Theme Builder Powered by Atlassian Confluence