Esri / solution.js

TypeScript wrappers running in Node.js and modern browsers for transferring ArcGIS Online items from one organization to another.
https://esri.github.io/solution.js/
Apache License 2.0
38 stars 11 forks source link

Add support for Workflow Manager items #875

Open chris-fox opened 1 year ago

chris-fox commented 1 year ago

Workflow Manager is now available in Online an Enterprise. Workflow Manager has a REST api to query and create the required items. The root url is a little different for Online and Enterprise so we will want to account for this in creation and deployment: https://developers.arcgis.com/workflow-manager/

I have looked through the api doc and create some test items and this is how I would suggest we approach creating and deploying these items:

Creation

Deployment

Deleting

I have created some sample items that can be used in testing. The group below contains a workflow, survey123 form and web application. The survey123 form and web application are both referenced in the workflow so it is a good test that they are templatized properly and swizzled on deployment.

6d45ec5c65464b20aaa5ac9ea4b55579

chris-fox commented 11 months ago

@MikeTschudi, Looking through the api, I think there might be an easier approach to this. There is an exportWorkflowConfiguration and importWorkflowConfiguration.

The export creates a .wmc file and will contain all the diagrams, jobTemplates and several other properties configured in the workflow. This could be a much simpler approach than having to handle every property individually. What is not clear to me is what kind of file is the .wmc file. Is it a json file? We need to be able to templatize properties in the diagrams so if it is not a file type that we can look for itemId references than this approach may not work for us.

There is no UI to get a wmc file in Workflow Manager and I have tried to use the python api to get it but I am having trouble authenticating. If you could get a sample .wmc file form the example workflow referenced in the comment above I would like to take a look to see if it might be a viable approach.

MikeTschudi commented 11 months ago

Sample .wmc file; it's a zip with a renamed extension. Because GitHub doesn't support ".wmc", the file is attached with the ".zip" extension. workflow_configuration_1691603968445.zip

MikeTschudi commented 10 months ago

Within the .wmc file, there appears to be just three files that need to be templatized:

chris-fox commented 10 months ago

@MikeTschudi, would it hurt to just templatize all the files. If there ends up being nothing in the file to templatize than it shouldn't hurt anything, but I guess my concern is I don't know enough yet to say which files might have other item references. Also if things change over time we are more likely to just handle the additional cases we are not aware of yet.

MikeTschudi commented 10 months ago

@chris-fox, it's a good idea--can't guarantee contents of file.

chris-fox commented 5 months ago

@MikeTschudi, I have been testing this today and have found workflow manager items are failing to deploy. I have been testing with this Workflow item:

https://localdeployment.maps.arcgis.com/home/item.html?id=661e0e38d4ad4a8f97731b22cb6c95dd

It creates successfully, but when I deploy it fails. Looking at the network traffic I am finding it is failing on the import command with the following error:

{
    "error": {
        "message": "Feature layer call failed with 400: Invalid URL",
        "type": "WorkflowDataStoreException"
    }
}

I believe the issue is earlier in the logic we are using addItem to add the new workflow item. However for Workflows there also need to be the supporting feature services and views for the import to work.

I believe instead need to call the createWorkflowItem api to create a new workflow item in the users content at the root folder. This handles creating the workflow item, supporting feature layers/view and the associated group.

After this we could do things like update the item details of the workflow and thumbnail and move the items to the solution contents folder. Then we could use the import api to import the configuration.

chris-fox commented 3 months ago

@MikeTschudi, I tested this out and found I was able to successfully package and deploy a workflow item. In the resulting workflow I was able to create new jobs and run through them. I also had a survey with webhook configured to create jobs in the workforce project and this deployed successfully as well and was able to create the job correctly.

The issue I am seeing is references to items contained within the workflow are not being swizzled. For example in am embedding a web app (that is also in the group), but the portalBaseUrl and item id variables are not being applied. Below is a screenshot from the json for the "diagrams.json" property under the workflow template:

Image

In addition, I am also referencing the survey in the workflow and it is not swapped with the variable for in the "jobExtPropertyTableDefinitions.json" property:

Image

I would expect these items be discovered in the group and for them to be swapped out for variables in the workflow json property files so that they can be swizzled on deployment. We will also want to look for any feature service url references included in the solution. I would then expect these to be added as dependencies of the workflow template to ensure the items are created first and the variables can be resolved.

I am using this group to test:

https://localdeployment.maps.arcgis.com/home/group.html?id=d6888336943548e58bf7f40e7cf824e9#overview

MikeTschudi commented 3 months ago

@chris-fox, all of the swapping occurs during deployment: for each id recognized, it is replaced if it is found in the solution. This can be changed to templatizing.

I'll look into discovering the feature services that are missing from the group but should be added.

chris-fox commented 3 months ago

@MikeTschudi, thanks I would prefer to go the templatizing route as it is consistent with other item types and makes it easier for us to manually modify the definition in the template if we want to add or remove replacements.

With regard to the feature services, I don’t think you need to auto discover feature services that were not shared with the group.

I was just saying if there was a feature service included in the group or a dependency of another item like a web map and that same feature service url was referenced in any of the json files of the workflow item that we should also templatize those.

MikeTschudi commented 3 months ago

Sounds good. It appears to be much easier than I expected: I more-or-less moved the code from deploy to create.

Thanks regarding discovery. By having the service in the group, it gets an entry in the template dictionary. Thus, when I discover what looks like an AGO id in the workflow config and it's in the dictionary, I can templatize it and add it to the workflow's dependencies.

chris-fox commented 3 months ago

@MikeTschudi, I was testing this morning with group https://localdeployment.maps.arcgis.com/home/group.html?id=d6888336943548e58bf7f40e7cf824e9#overview and it is working almost perfect. The only issue I noticed is the portal base url in an app url reference is not being replaced with the {{portalBaseUrl}} variable:

Image

I would expect it look like below similar to how we are doing this in the corresponding Web Mapping Application item url in the group:

Image

There is also another reference to 'https://localdeployment.maps.arcgis.com' in one of the json files for a path to the workflow itself:

Image

We should find any references to the portal base url and replace with the {{portalBaseUrl}} variable. If I manually edit the solution item to make these replacements and deploy everything works perfectly.

chris-fox commented 3 months ago

We discovered during testing that we were not providing the correct root url for enterprise. At this point in the release we have decided we will not be able to support workflow manager for Enterprise 11.3. Things are working well for AGOL, I will update the milestone to the AGOL release and we can work on addressing this for Enterprise so it is available for 11.4.

https://developers.arcgis.com/workflow-manager/api-reference/rest/

chris-fox commented 3 months ago

See the comment below to dynamically get the root url for the workflow manager api for both ArcGIS Online (prod, qa and dev) and ArcGIS Enterprise

https://devtopia.esri.com/WebGIS/solution-deployment-apps/issues/64#issuecomment-4705767

chris-fox commented 2 months ago

@MikeTschudi, I attempted to package this group this morning with the latest create solution demo app from the develop branch but it failed with a console error on the workflow item. This was working previously and wondering if there was a regression with the workflow root url updates.

https://localdeployment.maps.arcgis.com/home/group.html?id=d6888336943548e58bf7f40e7cf824e9

chris-fox commented 2 months ago

Verified that I was able to create a solution from a workflow and deploy it in production. Everything was swizzled properly and behaved as expected. I also verified that the root url was properly updated for devext for both creation and deployment in solution.js.

Everything is looking good. I have asked some team members to test with their solutions as well.