Select to view content in your preferred language

Asynchronous Geoprocessing App

6006
16
05-09-2012 01:31 PM
LukeCatania
Occasional Contributor
I am trying to write an app to display results from an Asynchronous GP Task.  I looked at the Viewshed Example and tried to change that, but that is synchronous and changing the parameters passed and the URL to access my Asynchronous GP Tool results in an "execute operation is not allowed on this service" error, which I found is the result of calling the Asynchronous GP Tool using the .execute method rather than the .submitJob method. 


Other things need to be changed in the code to get check the status of the job and get the results and display them, but I don't really know what to change.  Has anyone done anything like this and would you please post some code?
0 Kudos
16 Replies
AndyGup
Esri Regular Contributor
RE: debugging HTTP requests on Android here's a blog post that may help: http://www.andygup.net/?p=695

-Andy
0 Kudos
LukeCatania
Occasional Contributor
@lcatania You may have already done this, did you compare the parameters set in your code with the parameters documented in your Geoprocessing Service REST endpoint?

As a second suggestion, do you have another working sample that uses the same service that you can compare the HTTP request against?

-Andy



Yes.  The first time, I found I forgot to change one of the parameter names, but after I fixed it, I still have the same issues.  Since viewshed has multiple parameters in as attributes, I created a simpler service the GP Service, Buffer Points.  I followed the example
from:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/GP_service_step_by_step_Buffer_points/...

It works fine in the desktop as a local tool and fine when I publish it and it is initially Asynchronous, but when I change it to synchronous, the service runs and the status bar at bottom of window shows that it is running, but it runs forever.  The GP messages says it succedded, though it has 3 messages stating it succeeded, nothing shows up.  When I called the service from my device, I get the "com.esri.core.io.EsriServiceException: Error executing task 'Buffer Points'. Please check your parameters." Message.  I attached the messages from the tool when calling it in the desktop.  Don't know why it shows the tool as storing output in the jobs directory since the tool is published as synchronous.
0 Kudos
AndyGup
Esri Regular Contributor
Do you have any messages in the ArcGIS Server log?

Here is a similar post with information that might help: http://forums.arcgis.com/threads/27763-Problem-with-Geoprocessing-Service

-Andy
0 Kudos
LukeCatania
Occasional Contributor
Do you have any messages in the ArcGIS Server log?

Here is a similar post with information that might help: http://forums.arcgis.com/threads/27763-Problem-with-Geoprocessing-Service

-Andy


I did come across that in my search for answers.  Other than the correction to use a file system output rather than in memory, nothing else applies.  I already use a file system.  As in a previous post in this thread, I create a simple buffer model using the exact steps outlined by ESRI's tutorial.  That is teh one I publish and try to hit through my tablet device.  I would like to see someone from ESRI successfully provide example code to do that.  Or provide the model that the android Viewshed example hits.  The code is provided for that, but the service is on an ESRI server and I don't know what the model looks like.

I have many services I need to access in this project I am working on and hope once I get one to work, implementing the others will be simple, but I am stuck at the moment.
0 Kudos
LukeCatania
Occasional Contributor
In addition to Mark's code snippet, here's some additional code taken from a Clip and Ship demo that shows another pattern for coding against an asynchronous GP service. The full sample code will be included with the v3 release of our SDK later this year. Or, if you want to see the full app sooner then ping me: agup at esri dot com.

strmv.setParamName("Layers_to_Clip");

strmv.setValues(arrayList);

final ArrayList<GPParameter> paramlist = new ArrayList<GPParameter>();
paramlist.add(strmv);
paramlist.add(areaofinterest);
paramlist.add(featureformat);

handler = new Handler();
submitJobandPolling(gp, paramlist);


 /**
  * Method submitJobandPolling.
  * @param gp Geoprocessor
  * @param params List<GPParameter>
  */
 void submitJobandPolling(final Geoprocessor gp,
   List<GPParameter> params) {
  try {
   GPJobResource gpjr1 = gp.submitJob(params);
   JobStatus jobstatus = gpjr1.getJobStatus();
   final String jobid = gpjr1.getJobID();
   Log.d("Test", "jobid " + jobid);
   Log.d("Test", "jobstatus " + jobstatus);

   // if (!jobstatus.equals("esriJobSucceeded")) {
   if (jobstatus != JobStatus.succeeded) {

    handler.postDelayed(new Runnable() {

     
     @Override
     public void run() {
      try {
       GPJobResource gpjr2 = gp.checkJobStatus(jobid);  
       GPMessage[] messages = gpjr2.getMessages();
       if ( messages!= null && messages.length > 0) {
        for (int i = 0; i < messages.length; i++) {
         Log.d("Test", "Message: " + messages.getDescription());
        }
       }
       Log.d("Test", "Polling thread is: "
         + Thread.currentThread().getName());
       
       JobStatus status = gpjr2.getJobStatus();
       boolean jobcomplete = false;

       if (status == JobStatus.canceled
         || status == JobStatus.deleted
         || status == JobStatus.failed || status == JobStatus.succeeded
         || status == JobStatus.timedOut) {
        jobcomplete = true;

       }
       if (jobcomplete) {
         if (status == JobStatus.succeeded) {
       
           GPDataFile outputZipfile = (GPDataFile) gp
          .getResultData(jobid, "Output_Zip_File");

           Log.d("Test", "zip file is "
          + outputZipfile.getUrl().toURI()
            .toString());
         }else {
          Log.d("Test", "GP failed");
         }

       } else {
        handler.postDelayed(this, 5000);
       }
      } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }

     }
    }, 4000);

   }
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 }


Are areaofinterest and featureformat declared as GPJobParameters?
0 Kudos
LukeCatania
Occasional Contributor
Do you have any messages in the ArcGIS Server log?

Here is a similar post with information that might help: http://forums.arcgis.com/threads/27763-Problem-with-Geoprocessing-Service

-Andy


No messages at all in the log in regard to this service other then some issues I had initially starting the service.
0 Kudos
LukeCatania
Occasional Contributor
RE: debugging HTTP requests on Android here's a blog post that may help: http://www.andygup.net/?p=695

-Andy


When I run the app in the emulator, I receive errors:

java.lang.IllegalArgumentException: No configs match configSpec
com.esri.android.map.MapSurface$a.chooseConfig(Unknown Source)
android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:1009)
0 Kudos