Select to view content in your preferred language

Publish Map service on federated portal

1756
11
09-15-2022 12:56 PM
GuillaumeArnaud
Frequent Contributor

Hi !

I need to run a script to deploy many mapservice on arcgis service and portal. They are federated. Is there any sample yo do this ?

This script may also be used to update mapservice.

Thanks for your help

Guillaume 

 

 

0 Kudos
11 Replies
forestknutsen1
MVP Regular Contributor

I have script that publishes a service to Arc server that is federated with portal. I posted the two functions that do most of the work. I hope it helps.

def build_connection(locator_specs, working_dir):
    """
    builds AGS connection
    :param working_dir: script working path
    :param locator_specs: instance of Specs class
    :return: AGS connection
    """
    out_folder_path = 'ags_connections'
    clean_dir(out_folder_path, working_dir)
    use_arcgis_desktop_staging_folder = False
    staging_folder_path = out_folder_path
    server_info = locator_specs.get_arc_gis_servers()
    server = server_info.server
    out_name = '{}.ags'.format(server)
    server_url = 'https://{}:6443/arcgis/admin'.format(server)
    print server_url
    username = server_info.admin_user
    password = xxxx.security.get_password(server, username)
    logger.info(xxxx.indent('Making sever connection: {}'.format(out_name), 2))
    arcpy.mapping.CreateGISServerConnectionFile("ADMINISTER_GIS_SERVICES",
                                                out_folder_path,
                                                out_name,
                                                server_url,
                                                "ARCGIS_SERVER",
                                                use_arcgis_desktop_staging_folder,
                                                staging_folder_path,
                                                username,
                                                password,
                                                "SAVE_USERNAME")
    return os.path.join(out_folder_path, out_name)


def publish_service(gis_server_connection_file, working_dir, location_dir):
    """
    creates sd file and publishes it to server
    :param gis_server_connection_file: AGS connection
    :param working_dir: script directory
    :return: None
    """
    gis_server_connection_file = os.path.join(working_dir, gis_server_connection_file)
    out_sd_folder = 'sd'
    clean_dir(out_sd_folder, working_dir)
    service_name = 'CW_Composite'
    locator_path = os.path.join(location_dir, service_name)
    sddraft_file = os.path.join(working_dir, out_sd_folder, 'cw_composite.sddraft')
    sd_file = os.path.join(working_dir, out_sd_folder, 'cw_composite.sd')
    summary = 'CEA address locator'
    tags = 'address, locator, geocode'
    folder_name = 'Locator'
    logger.info(xxxx.indent('Building SDDraft: {}'.format(sddraft_file), 2))
    analyze_messages = arcpy.CreateGeocodeSDDraft(locator_path, sddraft_file, service_name,
                                                  connection_file_path=gis_server_connection_file,
                                                  summary=summary,
                                                  tags=tags,
                                                  max_result_size=20,
                                                  max_batch_size=500,
                                                  suggested_batch_size=150,
                                                  folder_name=folder_name,
                                                  copy_data_to_server=True)
    if analyze_messages['errors'] == {}:
        logger.info(xxxx.indent('Staging service {}:'.format(sd_file), 2))
        arcpy.server.StageService(sddraft_file, sd_file)
        logger.info(xxxx.indent('Uploading sd: {}'.format(sd_file), 2))
        arcpy.server.UploadServiceDefinition(sd_file, gis_server_connection_file)
        logger.info(xxxx.indent(arcpy.GetMessages(), 2))
        logger.info(xxxx.indent('Success: service published', 2))
    else:
        logger.error(xxxx.indent(analyze_messages['errors'], 2))
        logger.error(xxxx.indent('Failure: service was not published'))

 

0 Kudos
GuillaumeArnaud
Frequent Contributor

Hi,

I try to use this help : MapServiceDraft—ArcGIS Pro | Documentation but i have this error : 

GuillaumeArnaud_0-1663310496707.png

It could be an error with certificate.

0 Kudos
forestknutsen1
MVP Regular Contributor

1. First, off I used python 2.7 to create mine not python 3.x. But I would think they are close to each other.

2. A bad certificate will definitely break things. But I am not certain it is the source of your issues. Normally when I have a certificate issues I get an error with a reference to SSL in it. 

3. It looks like the issue is with the server connection parameter (If I am reading the French right?). I would test my server connection with ArcCatalog. You should be able to navigate to it and open it with ArcCatalog.

forestknutsen1_0-1663345857878.png

 

 

0 Kudos
GuillaumeArnaud
Frequent Contributor

Hi,

Thanks for your reply, I just found that is an error when ags con is allready open.

Yes it's a french arcgis pro.

When I launch the script first time when arcgis pro open, it ask me for trust certificate and deploy mapservice, when I launch it again (or after click on ags connexion to view it's content), I have the error.

sharing.py", line 91, in exportToSDDraft
return _convertArcObjectToPythonObject(self._arc_object.exportToSDDraft(out_sddraft,self))
ValueError: Target server is not a standalone server or is inaccessible.

Thanks for your time.

Guillaume 

0 Kudos
forestknutsen1
MVP Regular Contributor

hmmm.... normally ArcMap only asks me to trust the certificate if there is an issue with it. I wonder if you are using a self signed certificate or maybe one that has expired. You can check your certificate in chrome.

Click on the little lock thing to get the info:

forestknutsen1_1-1663700602163.png

This is one of mine:

forestknutsen1_0-1663700449047.png

Or you may see something like this:

forestknutsen1_2-1663700819731.png

Of course you need to check the one on the ArcGIS Server, not the Portal one.

 

0 Kudos
GuillaumeArnaud
Frequent Contributor

It's a dev server so certificate is auto sign so not secure.

I want to publish it from arcgis pro.

As I say before, it work first time :

GuillaumeArnaud_0-1664260861336.png

But not when i relaunch it :

GuillaumeArnaud_2-1664260964273.png

If i restart arcgis pro, i can run script 1 time without craches

0 Kudos
forestknutsen1
MVP Regular Contributor

I see, that is weird. But it asks you if you want to trust the machine the first time?

0 Kudos
GuillaumeArnaud
Frequent Contributor

Yes it ask me and i approve.

0 Kudos
forestknutsen1
MVP Regular Contributor

Yes, I think it is your self-signed certificate. My guess is the first time is asks you and runs fine. The next time it does not ask (for whatever reason) and fails. We used put self signed certificates on our dev and test machines, but now we put "real" ones on all of our servers. Situations like this was one of the motivating factors. Can you put a singed certificate on the server?

0 Kudos