Unregister All Replicas

429
3
07-11-2020 12:13 PM
Status: Open
GwenWolph1
New Contributor III

ArcGIS Online will not allow you to overwrite an existing hosted feature service if replicas exist.  ArcGIS Online also will not allow you to programatically compile a list of all of the existing replica IDs for a hosted feature service and then use that list to unregister them all.  There needs to be a way to either programatically gather all of the replica IDs and unregister the replicas, or provide an "Unregister All" button on the feature service page so that users do not have to spend hours copying and pasting each individual replica ID into the one-at-a-time "Unregister Replica" tool.

3 Comments
mpc
by

There's a function in the ArcGIS API for Python to list all the replicas and unregister them. Just be aware that doing this will break any outstanding offline maps. After removing the replicas, when a user clicks 'Check for update', for their offline map in ArcGIS Explorer/Collector, they will get a sync failed error as the replica can no longer be found.

featureLayerName = "layername"

featureLayer = gis.content.search(query=featureLayerName + " owner:named_user", item_type='Feature Layer Collection', sort_field='relevance', sort_order='desc', max_items=1)
print(featureLayer)

featureDataset = FeatureLayerCollection.fromitem(featureLayer[0])
print(featureDataset.url)
outstandingReplicas = featureDataset.replicas.get_list()

if outstandingReplicas:
   for replica_dict in outstandingReplicas:
      featureDataset.replicas.unregister(replica_dict['replicaID'])
      print("Unregistered replica: {0}".format(replica_dict['replicaID']))
else:
   print("No replicas present")

mejohnson22

Hi @mpc

It looks like your solution above is what I am looking for. I have gone through the first four lines OK, but I am getting stuck and was hoping for some assistance. 

I get stuck here at this point. I do have USERNAME updated in the actual script

featureLayer = gis.content.search(query= featureLayerName + "owner:USERNAME", item_type='Feature Server', sort_field='relevance', sort_order='desc', max_items=1)
print(featureLayer)

When stepping through, when I hit the print, I return 

[]

Which may be the issue, because then when I continue 

featureDataset = FeatureLayerCollection.fromitem(featureLayer[0])

I receive the error 

Traceback (most recent call last):
File "<string>", line 1, in <module>
IndexError: list index out of range

I've been trying to troubleshoot for a good bit and though I might reach back out to the master for some potential guidance. 

 

Thanks in advance

Mary

mpc
by

Hi @mejohnson22,

I haven't been able to check but suspect the problem is with the item type specified as it doesn't look to be valid - Items and item types—ArcGIS REST APIs | ArcGIS Developers

item_type='Feature Server'

I think it's not returning any results from the search, thus it's returning [] & 'list index out of range'.

As an aside - and it doesn't always work - you can enter * into the unRegisterReplica option for a feature service e.g. https://services3.arcgis.com/AkUq3zcWf7TVqyR9/ArcGIS/rest/services/SERVICE_NAME/FeatureServer/unRegisterReplica and that will try and remove all replicas.