|
POST
|
I have a Python script running on a 64-bit Windows Server 2012r2 machine with ArcGIS Server 10.2.2. The script has a list of twelve services (stored as a Python dictionary) that it stops and starts. 90% of the time all services in the list stop and start successfully. The other ten percent: not so much. The JSON error message returned says Could not undeploy services from one or more machines. 'com.esri.arcgis.discovery.admin.AdminException'. The log message in ArcGIS Server Manager shows up as Severe level and says pretty much the same thing. I haven't been able to notice a pattern in how often or which service it fails on. Sometimes (like this most recent time) it failed to stop a service in the middle of the list, then continued on to successfully stop the rest of the services. Later on in the script the same services are started and all started successfully. So I know the script works but it's just sometimes that it fails. My script does the following: Copy feature classes from SDE to staging file geodatabase on server Compact staging geodatabase Stop related services Delete production geodatabase Copy staging gdb to production gdb Start services The code I use to stop and start services is based on this work from Kevin Hibma: ArcGIS Server Administration Toolkit - 10.1+ AdministeringArcGISServerwithPython_DS2014 Here are the Python functions I came up with: getToken() def getToken(adminUser, adminPass, server, port, expiration):
# Build URL
url = "http://{}:{}/arcgis/admin/generateToken?f=json".format(server, port)
# Encode the query string
query_dict = {
'username': adminUser,
'password': adminPass,
'expiration': str(expiration), ## Token timeout in minutes; default is 60 minutes.
'client': 'requestip'
}
query_string = urllib.urlencode(query_dict)
try:
# Request the token
with contextlib.closing(urllib2.urlopen(url, query_string)) as jsonResponse:
getTokenResult = json.loads(jsonResponse.read())
## Validate result
if "token" not in getTokenResult or getTokenResult == None:
raise Exception("Failed to get token: {}".format(getTokenResult['messages']))
else:
return getTokenResult['token']
except urllib2.URLError, e:
raise Exception("Could not connect to machine {} on port {}\n{}".format(server, port, e)) serviceStartStop() def serviceStartStop(server, port, svc, action, token):
# Build URL
url = "http://{}:{}/arcgis/admin".format(server, port)
requestURL = url + "/services/{}/{}".format(svc, action)
# Encode the query string
query_dict = {
"token": token,
"f": "json"
}
query_string = urllib.urlencode(query_dict)
# Send the server request and return the JSON response
with contextlib.closing(urllib.urlopen(requestURL, query_string)) as jsonResponse:
return json.loads(jsonResponse.read()) I get the token once at the beginning of the main script and call the serviceStartStop() function repeatedly in a for loop iterating through a list of services.
... View more
12-26-2014
08:05 AM
|
0
|
6
|
6806
|
|
POST
|
Make sure everything is the same 32-bit or 64-bit version.
... View more
12-26-2014
07:50 AM
|
0
|
4
|
1962
|
|
POST
|
I have a mosaic dataset with tiled imagery that has an infrared band. How can I publish an image service on ArcGIS Server 10.2.2 so the published image uses the correct bands to display it as infrared instead of just regular RGB? Previously we published it as a map service but I'd like to do it as an image service if possible.
... View more
12-11-2014
02:32 PM
|
0
|
1
|
2487
|
|
POST
|
Just came across this mention of returning values in a Python style guide and thought it would be relevant to post. Code Style — The Hitchhiker's Guide to Python (Returning values) It confirms what you said, Joshua: using one main exit point is preferred.
... View more
10-17-2014
01:13 PM
|
0
|
1
|
2585
|
|
POST
|
If you use the syntax highlighting feature (under the advanced editor) of the forums here, it helps present your code in a more readable way. (see above - cp)
... View more
10-14-2014
09:37 AM
|
0
|
1
|
1602
|
|
POST
|
Would it make sense to eliminate the assignment to the risk variable and just return the desired value instead?
def CalcField(zone):
if zone in ('A', 'AE', 'AH', 'AO'):
return 'High'
elif zone in ('Whatever', 'Whatever2'):
return 'Moderate'
elif zone in ('X', 0.2):
return 'Low'
else:
return 'somedefaultvalue'
... View more
10-14-2014
08:41 AM
|
0
|
3
|
2585
|
|
POST
|
Greg, you forgot the == comparison on the elif statements. Jake, using Greg's updated Python code in the Calculate Field tool with Model Builder, complete the fields like this... Field Name FLD_RISK Expression
CalcField(!FLD_ZONE!)
Expression Type PYTHON_9.3 Code Block
def CalcField(zone):
risk = ''
if zone in ('A', 'AE', 'AH', 'AO'): risk = 'High'
elif zone == 'Whatever': risk = 'Moderate'
elif zone == 'X': risk = 'Low'
else: risk = 'somedefaultvalue'
return risk
... View more
10-13-2014
09:30 AM
|
0
|
1
|
2585
|
|
POST
|
Previously, I had created a Python script that used ArcSDESQLExecute to query the SDE.PROCESS_INFORMATION table to get detailed connection information. Something like
SELECT UPPER(NODENAME) AS COMPUTER, COUNT(NODENAME) AS CONNECTIONS
FROM SDE.PROCESS_INFORMATION
GROUP BY NODENAME
ORDER BY CONNECTIONS DESC, NODENAME
and
SELECT UPPER(NODENAME) AS COMPUTER, OWNER AS USERNAME, COUNT(OWNER) AS USERCONNS
FROM SDE.PROCESS_INFORMATION
GROUP BY NODENAME, OWNER
ORDER BY NODENAME, USERCONNS DESC, OWNER
Between the two, I was able to get the total number of connections for each computer, which users that computer was connecting with, and how many connections of each user were open. Since then, I stumbled across ListUsers and thought maybe I should be using it instead of the SQL. On a mission to conquer ListUsers and get the same SDE connections "report" I came up with this:
import arcpy
from operator import itemgetter
#Get all connections and print the total
GPRO_Connections = arcpy.ListUsers("Database Connections/SDE@GPRO.sde")
print "{} total connections:".format(len(GPRO_Connections))
#Get and count unique computer connections and sort by number of connections
AllClients = [conn.ClientName for conn in GPRO_Connections] ##Use list comprehension to get all ClientName values
Clients = [(client, AllClients.count(client)) for client in set(AllClients)] ##Use list comprehension to get unique tuples of ClientName and number of connections
#Get and count unique user connections for each computer and print results
for c in sorted(Clients, key=itemgetter(1), reverse=True): ##Sort the unique computers by descending connections and print results
print "{} ({})".format(c[0], c[1])
## Get and count unique user connections for the computer
AllClientUsers = [user.Name for user in GPRO_Connections if user.ClientName == c[0]] ##Use list comprehension to get all users on the computer
ClientUsers = [(usr, AllClientUsers.count(usr)) for usr in set(AllClientUsers)] ## Use list comprehension to get unique tuples of users on the computer and number of connections
## Sort the computer's users by descending connections and print results
for u in sorted(set(ClientUsers), key=itemgetter(1), reverse=True):
print "\t{} ({})".format(u[0], u[1])
# Cleanup
del GPRO_Connections
arcpy.ClearWorkspaceCache_management()
The ouput looks something like this
43 total connections:
CC1WA125 (9)
SDE (4)
JTX (2)
GBATASKS (2)
GBAVIEWER (1)
8GK69Y1 (3)
GBAVIEWER (1)
WARRENW (1)
KURTHO (1)
8GZ59Y1 (3)
GISVIEWER (1)
RANDYE (1)
GBATASKS (1)
1HTX8Y1 (3)
GBAVIEWER (1)
GISVIEWER (1)
KURTHO (1)
8H269Y1 (2)
JESSEF (1)
GISVIEWER (1)
1HSZ8Y1 (2)
GBAVIEWER (1)
GISVIEWER (1)
1NGY8Y1 (2)
GISVIEWER (1)
SDE (1)
6IKSA69716 (2)
WS (2)
D2P3JF1 (2)
CHRISSI (1)
GBATASKS (1)
1HWZ8Y1 (2)
JASONT (1)
GBATASKS (1)
1K1Z8Y1 (2)
GBAVIEWER (1)
KRISTYN (1)
1MRX8Y1 (2)
GBAVIEWER (1)
GISVIEWER (1)
HGL7XL1 (1)
WS (1)
75L7XL1 (1)
WS (1)
8JKSB95938 (1)
WS (1)
6JKSA78574 (1)
WS (1)
2M068Y1 (1)
SDE (1)
VM1WA91 (1)
GISVIEWER (1)
8GS49Y1 (1)
GISVIEWER (1)
1K1X8Y1 (1)
ERIKS (1)
46L27W1 (1)
WS (1)
I've been learning Python from scratch over the past couple months and I'm pretty proud of how far I've come. However, I know there are a lot of nifty ways to do things and thought maybe the Python wizards here could offer some insight on the problem and my solution. At the very least, maybe someone else can get some use out of this code.
... View more
10-10-2014
10:45 AM
|
0
|
0
|
1324
|
|
POST
|
I think that clears it up pretty well. thanks Xander. While reading documentation about using in_memory for working space for local geoprocessing tasks, I also stumbled across the Feature Set and thought they seemed similar. Especially since they are both used in the example they have on the Feature Set page. I think I will be using in_memory for everything unless I'm dealing with a geprocessing service.
... View more
10-10-2014
10:33 AM
|
0
|
0
|
1050
|
|
POST
|
It looks like FeatureSet is a more specific type of an in_memory feature class that is used to communicate with a server geoprocessor. Can someone clear this up?
... View more
10-08-2014
04:51 PM
|
0
|
2
|
1659
|
|
POST
|
Not sure why that would be truncating the names. I would do something more simple. Instead of writing to a text file, it just prints the results in the Python interpreter window where you can copy it wherever you want. From my testing in ArcGIS 10.2.2, it successfully prints feature class names longer than 26 characters.
import arcpy
# specify the geodatabase you want to retrieve feature classes from
gdb = r"c:\temp\Tracks.gdb"
# set your environment workspace
arcpy.env.workspace = gdb
# List all of the feature datasets and their feature classes
for ds in arcpy.ListDatasets():
print ds
for fc in arcpy.ListFeatureClasses("","",ds):
print "\t", fc
# List all of the other feature classes outside the feature datasets
for fc in arcpy.ListFeatureClasses():
print fc
EDIT: Another solution would be this:
import arcpy
# Specify the geodatabase you want to retrieve feature classes from
gdb = r"c:\temp\Tracks.gdb"
# Set environment workspace
arcpy.env.workspace = gdb
# Get list of datasets
datasetList = arcpy.ListDatasets()
datasetList.append("") ##Add blank list item to catch feature classes not in a dataset
for ds in datasetList:
for fc in arcpy.ListFeatureClasses("","",ds):
print "{}\{}".format(ds, fc)
... View more
10-08-2014
04:14 PM
|
2
|
0
|
1525
|
|
POST
|
We are in the midst of trying to upgrade everyone in our organization from ArcGIS 10.0 to ArcGIS 10.2.2. We have several ArcPy scripts that copy and merge feature classes from our 10.0 SDE and output to a file geodatabases. As we recode some of the older scripts to work with our new ArcGIS 10.2.2 setup, I've found that the feature class outputs from the scripts running from 10.2.2 are not readable by ArcGIS 10.0. The geodatabase was created in 10.0. ArcCatalog 10.0 can open the geodatabase, view properties of the geodatabase and feature class, but it can't preview it; ArcCatalog straight-up crashes. Even stranger is that existing feature classes in the same geodatabase that weren't updated by the script will preview fine. Unfortunately, we aren't quite ready to retire these scripts. Any ideas on how to make this all play nice together?
... View more
10-08-2014
08:54 AM
|
0
|
0
|
822
|
|
POST
|
The person in my position before me used this (Oracle) SQL to view replicas and deal with orphans but I'm not exactly sure how. From what I can see, it only returns the versions that have a matching replica. So if there is a version missing, it does not have a replica and may be considered orphaned. Maybe you can refine it for your needs.
SELECT EXTRACTVALUE(XMLType(Definition), '/GPReplica/Name') AS "Replica Names", EXTRACTVALUE(XMLType(Definition), '/GPReplica/ID') AS "ReplicaID"
FROM sde.GDB_ITEMS_VW ITEMS INNER JOIN sde.GDB_ITEMTYPES ITEMTYPES ON ITEMS.Type = ITEMTYPES.UUID
WHERE ITEMTYPES.Name = 'Replica';
... View more
10-02-2014
11:53 AM
|
0
|
0
|
4231
|
|
POST
|
You can move it into another geodatabase and ArcGIS should also copy the associated domains with it. Like you discovered, Shapefiles do not support field domains; it needs to be in a geodatabase (File or Personal). And, as Leo D. mentioned, a feature class can only exist in a geodatabase. If you need to deliver the data to someone in a format other than a geodatabase, you have two obvious options: Include the domain values as a table that can be joined. Field calc the exported data to replace the domain code with the domain description for easier interpretation.
... View more
10-02-2014
11:05 AM
|
0
|
0
|
474
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | a week ago | |
| 1 | 07-31-2025 11:59 AM | |
| 1 | 07-31-2025 09:12 AM | |
| 2 | 06-18-2025 03:00 PM | |
| 1 | 06-18-2025 02:50 PM |