diff --git a/smartgears/resource_updater/defaults/main.yml b/smartgears/resource_updater/defaults/main.yml new file mode 100644 index 00000000..6d3d2c6f --- /dev/null +++ b/smartgears/resource_updater/defaults/main.yml @@ -0,0 +1,43 @@ +--- +# +# org.gcube.resources +# resource-updater-cli +# 0.0.1-SNAPSHOT +# + +# per prod dovrebbe essere questo: +# java -cp ".:./resource-updater-cli-0.0.1-SNAPSHOT-jar-with-dependencies.jar" org.gcube.resourcemanagement.updater.AccessPointUpdater /d4science.research-infrastructures.eu DataAnalysis DataMiner dataminer.garr.d4science.org environment.properties + +# per il cluster di proto: +# java -cp ".:./resource-updater-cli-0.0.1-SNAPSHOT-jar-with-dependencies.jar" org.gcube.resourcemanagement.updater.AccessPointUpdater /d4science.research-infrastructures.eu DataAnalysis DataMiner dataminer-prototypes.d4science.org environment.properties + +# per i gw di proto: +# java -cp ".:./resource-updater-cli-0.0.1-SNAPSHOT-jar-with-dependencies.jar" org.gcube.resourcemanagement.updater.AccessPointUpdater /d4science.research-infrastructures.eu DataAnalysis DataMinerWorkers dataminer-genericworkers-proto.d4science.org environment.properties + +# per i gw di produzione: +# java -cp ".:./resource-updater-cli-0.0.1-SNAPSHOT-jar-with-dependencies.jar" org.gcube.resourcemanagement.updater.AccessPointUpdater /d4science.research-infrastructures.eu DataAnalysis DataMinerWorkers dataminer-genericworkers.d4science.org environment.properties + +# per dataminer preprod: +# java -cp ".:./resource-updater-cli-0.0.1-SNAPSHOT-jar-with-dependencies.jar" org.gcube.resourcemanagement.updater.AccessPointUpdater /gcube/preprod DataAnalysis DataMiner dataminer1-pre.d4science.org environment.properties + +# per gw di preprod: +# java -cp ".:./resource-updater-cli-0.0.1-SNAPSHOT-jar-with-dependencies.jar" org.gcube.resourcemanagement.updater.AccessPointUpdater /gcube/preprod DataAnalysis DataMinerWorkers dataminer1-pre.d4science.org environment.properties + +resource_updater_install: False +resource_updater_master: False +resource_updater_name: resource-updater-cli +resource_updater_group_id: org.gcube.resources +resource_updater_extension: jar +resource_updater_version: latest +resource_updater_classifier: jar-with-dependencies +resource_updater_deps_file: '{{ resource_updater_name }}-{{ resource_updater_version }}-{{ resource_updater_classifier }}.{{ resource_updater_extension }}' +resource_updater_file: '{{ resource_updater_name }}.{{ resource_updater_extension }}' +smartgears_resource_updater_base_url: 'http://maven.research-infrastructures.eu/nexus/content/repositories/gcube-snapshots' +resource_updater_dest_dir: '{{ smartgears_user_home }}/resource_updater' + +# resource_updater_properties: +# - { key: 'python2', value: '2.7.6' } +# - { key: 'python3', value: '3.4.3' } +# - { key: 'R', value: '3.4.4' } +# - { key: 'Java', value: '8' } +# - { key: 'KNIME', value: '3.6.1' } diff --git a/smartgears/resource_updater/tasks/main.yml b/smartgears/resource_updater/tasks/main.yml new file mode 100644 index 00000000..af7a445a --- /dev/null +++ b/smartgears/resource_updater/tasks/main.yml @@ -0,0 +1,60 @@ +--- +- block: + - name: Remove the resources updater + file: path={{ resource_updater_dest_dir }} state=absent + + - name: Remove the cron job that runs the resources updater script where is not needed + cron: name="Resources Updater" special_time=daily job="/usr/local/bin/resources_updater > {{ resource_updater_dest_dir }}/resources_updater.log 2>&1" state=absent + + - name: Remove the resources updater script + become_user: root + file: dest=/usr/local/bin/resources_updater state=absent + + become: True + become_user: '{{ d4science_user }}' + when: not resource_updater_install + tags: [ 'smartgears', 'resource_updater' ] + +- block: + - name: Get the resource updater jar file + maven_artifact: artifact_id={{ resource_updater_name }} version={{ resource_updater_version }} group_id={{ resource_updater_group_id }} classifier={{ resource_updater_classifier }} extension={{ resource_updater_extension }} repository_url={{ smartgears_resource_updater_base_url }} dest={{ smartgears_downloads_dir }}/{{ resource_updater_deps_file }} verify_checksum=always + register: resource_updater_download + + - name: Remove the old resources updater files + file: path={{ resource_updater_dest_dir }} state=absent + when: resource_updater_download is changed + + - name: Create the resources updater destination directory + file: dest={{ resource_updater_dest_dir }} state=directory + when: resource_updater_download is changed + + - name: Copy the resources updater jar file + copy: src={{ smartgears_downloads_dir }}/{{ resource_updater_deps_file }} dest={{ resource_updater_dest_dir }}/{{ resource_updater_file }} remote_src=yes force=yes + + - name: Install the resources updater properties + template: src=resources_updater.properties dest={{ resource_updater_dest_dir }}/resources_updater.properties + register: resource_data_changes + + - name: Install the resources updater script + become_user: root + template: src=resources_updater.sh dest=/usr/local/bin/resources_updater owner=root group=root mode=0755 + register: resource_data_changes + + - name: Install a cron job that runs the resources updater script + cron: name="Resources Updater" special_time=daily job="/usr/local/bin/resources_updater > {{ resource_updater_dest_dir }}/resources_updater.log 2>&1" state=present + when: resource_updater_master + + - name: Remove the cron job that runs the resources updater script where is not needed + cron: name="Resources Updater" special_time=daily job="/usr/local/bin/resources_updater > {{ resource_updater_dest_dir }}/resources_updater.log 2>&1" state=absent + when: not resource_updater_master + + - name: Run the resources_updater script if the properties file changed + shell: /usr/local/bin/resources_updater > {{ resource_updater_dest_dir }}/resources_updater.log 2>&1 + when: + - resource_updater_master + - resource_data_changes is changed + + become: True + become_user: '{{ d4science_user }}' + when: resource_updater_install + tags: [ 'smartgears', 'resource_updater', 'tomcat' ] diff --git a/smartgears/resource_updater/templates/resources_updater.properties b/smartgears/resource_updater/templates/resources_updater.properties new file mode 100644 index 00000000..b8db588c --- /dev/null +++ b/smartgears/resource_updater/templates/resources_updater.properties @@ -0,0 +1,3 @@ +{% for property in resource_updater_properties %} +{{ property.key }}={{ property.value }} +{% endfor %} diff --git a/smartgears/resource_updater/templates/resources_updater.sh b/smartgears/resource_updater/templates/resources_updater.sh new file mode 100644 index 00000000..9f02087c --- /dev/null +++ b/smartgears/resource_updater/templates/resources_updater.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +RES_UPDATER_DIR="{{ resource_updater_dest_dir }}" +#RES_UPDATER_PROPERTIES_FILE="{{ resource_updater_dest_dir }}/resources_updater.properties" +RES_UPDATER_PROPERTIES_FILE="resources_updater.properties" +SM_INFRA_NAME="/{{ smartgears_infrastructure_name }}" +SM_SERVICE_ENDPOINT_GROUP="{{ smartgears_service_endpoint_group }}" +SM_SERVICE_ENDPOINT_NAME="{{ smartgears_service_endpoint_name }}" +SM_SERVICE_ENDPOINT_HOST="{{ smartgears_service_endpoint_host }}" + +cd "$RES_UPDATER_DIR" +java -cp ".:./resource-updater-cli.jar" org.gcube.resourcemanagement.updater.AccessPointUpdater "$SM_INFRA_NAME" "$SM_SERVICE_ENDPOINT_GROUP" "$SM_SERVICE_ENDPOINT_NAME" "$SM_SERVICE_ENDPOINT_HOST" "$RES_UPDATER_PROPERTIES_FILE" +