HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/jboss7.cpython-310.pyc
o

�N�g�_�@s�dZddlZddlZddlZddlZddlmmZddlm	Z	e�
e�Z	d%dd�Z
dd�Zd	d
�Zd&dd�Zd&d
d�Zd&dd�Zdd�Zdd�Zd&dd�Zdd�Zd'dd�Zd(dd �Zd)d!d"�Zd#d$�ZdS)*ab
Manage JBoss 7 Application Server via CLI interface

.. versionadded:: 2015.5.0

This state uses the jboss-cli.sh script from a JBoss or Wildfly installation and parses its output to determine the execution result.

In order to run each state, a jboss_config dictionary with the following properties must be passed:

.. code-block:: yaml

   jboss:
      cli_path: '/opt/jboss/jboss-7.0/bin/jboss-cli.sh'
      controller: 10.11.12.13:9999
      cli_user: 'jbossadm'
      cli_password: 'jbossadm'

If the controller doesn't require a password, then the cli_user and cli_password parameters are optional.

Since same dictionary with configuration will be used in all the states, it may be more convenient to move JBoss configuration and other properties
to the pillar.

Example of application deployment from local filesystem:

.. code-block:: yaml

     application_deployed:
       jboss7.deployed:
         - salt_source:
             target_file: '/tmp/webapp.war'
         - jboss_config: {{ pillar['jboss'] }}

For the sake of brevity, examples for each state assume that jboss_config is contained in the pillar.


�N)�CommandExecutionErrorFcCs�t�d|�|didd�}d}i}td|||d�}|dr�|d	}|r�td
|||d�}	|	dr8||dd<nd|d	<d
|	d|d<|Sd}td||||d�}
|
dr]||dd<nd|d	<d|
d|d<|Std|||d�}|dr}|d	}nwd|d	<d|d|d<|Std||||d�}
|
ds�d|d	<d|
d|d<nd|d<td|||d�}|d	}n<|ddvr�td||||d�}
|
dr�td|||d�}|d	}d|d<nd|d	<d|
d|d<n	td�|d���|d	�rWt�d|�t�d|�t�||�}|��}t|�d k�r"d}t	|||�|dd!<|�
�}t|�d k�r9d}t	|||�|dd<|��}t|�d k�rPd}t	|||�|dd"<|�sWd#|d<|S)$a�
    Ensures that a datasource with given properties exist on the jboss instance.
    If datasource doesn't exist, it is created, otherwise only the properties that are different will be updated.

    name
        Datasource property name
    jboss_config
        Dict with connection properties (see state description)
    datasource_properties
        Dict with datasource properties
    recreate : False
        If set to True and datasource exists it will be removed and created again. However, if there are deployments that depend on the datasource, it will not me possible to remove it.
    profile : None
        The profile name for this datasource (domain mode only)

    Example:

    .. code-block:: yaml

        sampleDS:
          jboss7.datasource_exists:
           - recreate: False
           - datasource_properties:
               driver-name: mysql
               connection-url: 'jdbc:mysql://localhost:3306/sampleDatabase'
               jndi-name: 'java:jboss/datasources/sampleDS'
               user-name: sampleuser
               password: secret
               min-pool-size: 3
               use-java-context: True
           - jboss_config: {{ pillar['jboss'] }}
           - profile: full-ha

    zE ======================== STATE: jboss7.datasource_exists (name: %s) T���name�result�changes�commentFzjboss7.read_datasource)�jboss_configr�profile�successrzjboss7.remove_datasourcer�removedz%Could not remove datasource. Stdout: �stdoutrzjboss7.create_datasource)r	r�datasource_propertiesr
�createdz%Could not create datasource. Stdout: z#Could not read datasource. Stdout: zjboss7.update_datasource)r	rZnew_propertiesr
zCould not update datasource. zDatasource updated.�err_code�Z
JBAS014807ZWFLYCTL0216zDatasource created.zUnable to handle error: {}�failure-descriptionzds_new_properties=%szds_current_properties=%sr�added�changedzDatasource not changed.)�log�debug�__salt__r�format�
dictdiffer�diffr�len�__format_ds_changesrr)rr	rZrecreater
�ret�has_changedZds_current_propertiesZ	ds_resultZ
remove_result�
create_resultZread_resultZds_new_properties�
update_resultrrrr�r!�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/jboss7.py�datasource_exists1s�%���
��
��

��
��
��

��
���r#cCs�t�d|||�d}|D]A}t�d|�||vr1||vr1||dt||�dt||�d7}q||vr<||d7}q||vrM||dt||�d7}q|S)Nz6__format_ds_changes(keys=%s, old_dict=%s, new_dict=%s)rzkey=%s�:�->�
)rr�__get_ds_value)�keysZold_dictZnew_dictr�keyr!r!r"r�s:��������rcCs4t�d|�|dkrdS||durdSt||�S)Nz__get_value(dict,%s)�passwordz***Z	undefined)rr�str)�dctr)r!r!r"r'�sr'cCst�d||�t�d|�|didd�}d}|D]l}t||�}td|||d�}|d	rY|d
d}	|	|krXtd||||d
�}
|
d	rRd}t|dd|||	�qt|
d��q|ddvrtd||||d
�}|d	ryd}t|dd||�qt|d��t|d��|r�d|d<|S)a�
    Ensures that given JNDI binding are present on the server.
    If a binding doesn't exist on the server it will be created.
    If it already exists its value will be changed.

    jboss_config:
        Dict with connection properties (see state description)
    bindings:
        Dict with bindings to set.
    profile:
        The profile name (domain mode only)

    Example:

    .. code-block:: yaml

            jndi_entries_created:
              jboss7.bindings_exist:
               - bindings:
                  'java:global/sampleapp/environment': 'DEV'
                  'java:global/sampleapp/configurationFile': '/var/opt/sampleapp/config.properties'
               - jboss_config: {{ pillar['jboss'] }}

    zP ======================== STATE: jboss7.bindings_exist (name: %s) (profile: %s) zbindings=%sTzBindings not changed.rFzjboss7.read_simple_binding)�binding_namer	r
rr�valuezjboss7.update_simple_binding)r-r.r	r
rrrrrzjboss7.create_simple_bindingrzBindings changed.r)rrr+r�__log_binding_changer)rr	Zbindingsr
rrr)r.Zquery_resultZ
current_valuer rr!r!r"�bindings_exist�s`�������r0cCs`||vrd||<|dur|||d|d7<dS|||d|d|d7<dS)Nrr$r&r%r!)rZtype_r)�new�oldr!r!r"r/Ts
 (r/cCs�t�d|�|didd�}d}t||�\}}|st||�St|�\}}}	t�d|�t�d|�t||d�}|dur?t||�St||�\}
}}|
sNt||�Sd}
t�d	|�|dur�d
|vr�|d
rlt||�|dd<n!|	rxt||�|dd<nd
}
td�|�|d�}n	t||�|dd<|
r�t	d||d�}t�dt
|��|dr�td|d�}||dd<ntdjdi|��|d�}t||�||d<|S)a�	Ensures that the given application is deployed on server.

    jboss_config:
        Dict with connection properties (see state description)
    salt_source:
        How to find the artifact to be deployed.
            target_file:
                Where to look in the minion's file system for the artifact to be deployed (e.g. '/tmp/application-web-0.39.war').  When source is specified,  also specifies where to save the retrieved file.
            source:
                (optional) File on salt master (e.g. salt://application-web-0.39.war).  If absent, no files will be retrieved and the artifact in target_file will be used for the deployment.
            undeploy:
                (optional) Regular expression to match against existing deployments.  When present, if there is a deployment that matches the regular expression, it will be undeployed before the new artifact is deployed.
            undeploy_force:
                (optional) If True, the artifact will be undeployed although it has not changed.

    Examples:

    Deployment of a file from minion's local file system:

    .. code-block:: yaml

        application_deployed:
          jboss7.deployed:
            - salt_source:
                target_file: '/tmp/webapp.war'
            - jboss_config: {{ pillar['jboss'] }}

    It is assumed that /tmp/webapp.war was made available by some
    other means.  No applications will be undeployed; if an existing
    deployment that shares that name exists, then it will be replaced
    with the updated version.

    Deployment of a file from the Salt master's file system:

    .. code-block:: yaml

        application_deployed:
          jboss7.deployed:
           - salt_source:
                source: salt://application-web-0.39.war
                target_file: '/tmp/application-web-0.39.war'
                undeploy: 'application-web-.*'
           - jboss_config: {{ pillar['jboss'] }}

    Here, application-web-0.39.war file is downloaded from Salt file system to /tmp/application-web-0.39.war file on minion.
    Existing deployments are checked if any of them matches 'application-web-.*' regular expression, and if so then it
    is undeployed before deploying the application. This is useful to automate deployment of new application versions.

    If the source parameter of salt_source is specified, it can use
    any protocol that the file states use.  This includes not only
    downloading from the master but also HTTP, HTTPS, FTP,
    Amazon S3, and OpenStack Swift.

    z< ======================== STATE: jboss7.deployed (name: %s) Trrzresolved_source=%szget_artifact_comment=%s�Znew_commentZcurrent_commentNz
deployment=%sZundeploy_forcerZ
undeployedFz$The artifact {} was already deployedz
jboss7.deploy)r	Zsource_filezdeploy_result=%srzDeployment completed.�deployedzJDeployment failed
return code={retcode}
stdout='{stdout}'
stderr='{stderr}rr!)rr�__validate_arguments�_error�__get_artifact�__append_comment�__find_deployment�
__undeployrrr+)rr	�salt_sourcerrZvalidate_successZvalidate_comment�resolved_sourceZget_artifact_commentrZfind_success�
deploymentZfind_commentZrequire_deploymentZ
deploy_resultr!r!r"r4]sl7
�

�
������
r4cCstd||�|S)Nzjboss7.undeploy)r)r	r=r!r!r"r:�sr:cCsHt|dddg�\}}|durd}td|�}t|ddg||�\}}||fS)Nr	Zcli_pathZ
controllerF�No salt_source definedr;�target_file)�__check_dict_containsr8)r	r;rrr!r!r"r5�s
�
�r5cCs�d}d}d}td|�}|dur=d|vr=|dr=t�|d�}|D]}|�|�r<|dur:d}d�|dd�|��}q!|}q!|||fS)NTrzjboss7.list_deploymentsZundeployFz�More than one deployment matches regular expression: {}. 
For deployments from Salt file system deployments on JBoss are searched to find one that matches regular expression in 'undeploy' parameter.
Existing deployments: {}�,)r�re�compile�matchr�join)r	r;rrrZdeploymentsZ
deployment_rer=r!r!r"r9�s*�
��	�
r9c	Csjd}d}d}|durt�d�d}n�t|t�r�t�d�d|vr�zktd|dd|dddddddtddddd�\}}}td	did
|d�d|�dd�d|d�d
|�dd�dd�dd�dd�dt�dd�dd�dd�dd�dd�dd��}|dr�|d}n|d}|dr�d}Wn$ty�}zt�t���d|��}WYd}~nd}~ww|d}d}|||fS) NFzsalt_source == Noner>zfile from salt master�sourcezfile.get_managedr?)r�templaterF�source_hashZsource_hash_name�user�group�mode�attrs�saltenv�context�defaultsZskip_verify�kwargszfile.manage_filer�sfnr�
source_sumrIrJrKrLrMZbackup�makedirsrGZ	show_diffT�contentsZdir_moderrrzUnable to manage file: rr!)	rr�
isinstance�dictrZ__env__�	Exception�	traceback�
format_exc)	r;r<rrrQrRZcomment_Z
manage_result�er!r!r"r7	s�


���������	�
���
����
���
r7�<�cCs�t�d|�|didd�}td|�}|dr|ddvr'd	|d<d
|d<|Std|�}|ds=d
|dvs=d|dvr�d}d}|dusO|drO|ddkrt||krtt�|�||7}td|�}|dusp|drp|ddkrt||ksS|dr�|ddkr�d|d<d|d<d|dd<|Sd	|d<d�|�|d<|ds�td|d�|d<|Std�|d�|d�|d<|Sd	|d<d|d|d<|S)a�
    Reloads configuration of jboss server.

    jboss_config:
        Dict with connection properties (see state description)
    timeout:
        Time to wait until jboss is back in running state. Default timeout is 60s.
    interval:
        Interval between state checks. Default interval is 5s. Decreasing the interval may slightly decrease waiting time
        but be aware that every status check is a call to jboss-cli which is a java process. If interval is smaller than
        process cleanup time it may easily lead to excessive resource consumption.

    This step performs the following operations:

    * Ensures that server is in running or reload-required state (by reading server-state attribute)
    * Reloads configuration
    * Waits for server to reload and be in running state

    Example:

    .. code-block:: yaml

        configuration_reloaded:
           jboss7.reloaded:
            - jboss_config: {{ pillar['jboss'] }}
    z< ======================== STATE: jboss7.reloaded (name: %s) Trrz
jboss7.statusrr)�runningzreload-requiredFz`Cannot reload server configuration, it should be up and in 'running' or 'reload-required' state.rz
jboss7.reloadz Operation failed: Channel closedr
zNCommunication error: java.util.concurrent.ExecutionException: Operation failedrNr]zConfiguration reloadedZ
configurationr�reloadedz=Could not reload the configuration. Timeout ({} s) exceeded. z&Could not connect to JBoss controller.zServer is in {} statez+Could not reload the configuration, stdout:)rrr�time�sleeprr8)rr	�timeout�intervalr�statusrZ	wait_timer!r!r"r^Ns^���
�����
��	�
�r^rTcCs8|D]}||��vrd}td|�d|��|�}q||fS)NFzMissing z in )r(r8)r,Z	dict_namer(rrr)r!r!r"r@�s�r@cCs8|dur
|dur
dS|dur|S|dur|S|d|S)Nrr&r!r3r!r!r"r8�sr8cCsd|d<||d<|S)NFrrr!)r�err_msgr!r!r"r6�sr6)FN)N)r[r\)rT)r)�__doc__�loggingrBr_rXZsalt.utils.dictdiffer�utilsrZsalt.exceptionsr�	getLogger�__name__rr#rr'r0r/r4r:r5r9r7r^r@r8r6r!r!r!r"�<module>s0%

�+


U
	}


E
S