Select to view content in your preferred language

Enhanced Datastore Validation in ArcGIS API for Python

272
2
02-13-2025 09:08 PM
PrathameshDa
Emerging Contributor

I am writing to request an enhancement to the ArcGIS API for Python to include comprehensive validation capabilities for all datastore types, similar to the existing validate_egdb() function.

Currently, the validate_egdb() function provides a valuable service for validating enterprise geodatabases. However, our organization utilizes a variety of datastore types, and we require a consistent method for validating the integrity and connectivity of each.

2 Comments
HaydenWelch

Isn't that already in the API?

 

Spoiler
class PortalDataStore:
    ...
    def validate(self, server_id, item=None, config=None, future=False):
        """
        The ``validate`` method ensures that your ArcGIS Server can connect and use
        use the datasets accessed by a given data store item. The data store
        :class:`~arcgis.gis.Item` can be validated by using either the `id`
        property, or an item object tself as the `item` argument.

        .. note::
            While this operation can be called before or after the data store item
            has been registered, it is recommended to validate before
            registration on the server.

        ==================     ====================================================================
        **Parameter**           **Description**
        ------------------     --------------------------------------------------------------------
        server_id              Required String. The unique id of the server with which you want to
                               register the data store.
        ------------------     --------------------------------------------------------------------
        item                   Optional. The item id or data store
                               :class:`~arcgis.gis.Item` to validate. Required if no ``config``
                               provided.

                               .. note::
                                   A single data store item can be registered on multiple servers.
        ------------------     --------------------------------------------------------------------
        config                 Optional dict. The connection information for a new datastore.
                               Required if no ``item`` provided.
        ------------------     --------------------------------------------------------------------
        future                 Optional bool. Indicates whether to run the validate operation
                               asynchronously. The default is `False`.
        ==================     ====================================================================

        .. code-block:: python

            # Usage Example: Validating an added item against the Enterprise Raster Analytics server

            >>> gis = GIS(url="<url to GIS>", username="<username>", password="<password>")
            >>>
            >>> ds_item = gis.content.search("*", item_type="data store")[0]
            >>>
            >>> server_list = gis.admin.federation.servers["servers]
            >>> raster_id = [srv["id"]
            >>>              for srv in server_list
            >>>              if srv["function"] == "RasterAnalytics"][0]
            >>>
            >>> portal_ds = gis.datastore
            >>> portal_ds.validate(server_id = raster_id,
            >>>                    item = ds_item)

        :return:
            A boolean indicating success (True), or failure (False)

        """

        if item and isinstance(item, Item):
            item_id = item.id
        elif item and isinstance(item, str):
            item_id = item
        else:
            item_id = None

        url = self._url + "/validate"
        params = {"f": "json", "serverId": server_id}
        if item:
            params["datastoreId"] = item_id
        elif config:
            import json

            params["datastore"] = json.dumps(config)
        else:
            raise ValueError("Invalid parameters, an item or config is required.")
        res = self._con.post(url, params)
        if "status" in res:
            if res["status"] == "success":
                return True
            return res["status"]
        return res

it's accessed using

gis = GIS()
gis.datastore.validate(<server>, <item: Item>, <options>, <?async>)
PrathameshDa

Hi

Thank you for your response. The solution you suggested is focused on validating the datastore item type within the portal's content. However, we are looking for a Python function or method that can validate all types of datastores and the data items attached to the hosting server individually, similar to how it works with relational datastores.