Skip to content

Commit

Permalink
Merge pull request #686 from IBM/wxo
Browse files Browse the repository at this point in the history
Add watsonx Orchestrate to deployer
  • Loading branch information
fketelaars authored Apr 15, 2024
2 parents 5adef6a + c14f30b commit 9560797
Show file tree
Hide file tree
Showing 29 changed files with 398 additions and 408 deletions.
2 changes: 1 addition & 1 deletion automation-generators/generic/cp4d/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def preprocessor(attributes=None, fullConfig=None, moduleVariables=None):
check_cp_foundation(c)
if "state" in c:
if c['state'] not in ['installed','removed']:
g.appendError(msg='Cartridge state must be "installed" or "removed"')
g.appendError(msg='Cartridge state {} invalid, must be "installed" or "removed"'.format(c['state']))
if "state" not in c or c['state']=='installed':
# Check if there are dependencies and the depencies will be installed too
if "dependencies" in c:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ for c in $(echo $cartridges | jq -r '.[].name');do
cartridge_internal=$(echo $cartridges | jq -r --arg cn "$c" '.[] | select(.name == $cn ) | .cr_internal // false')
if [[ "$cartridge_internal" == "true" ]];then
continue
fi
fi

cr_cartridge_name=$(echo $cartridges | jq -r --arg cn "$c" '.[] | select(.name == $cn ) | .name')
cr_cr=$(echo $cartridges | jq -r --arg cn "$c" '.[] | select(.name == $cn ) | .cr_cr')
cr_name=$(echo $cartridges | jq -r --arg cn "$c" '.[] | select(.name == $cn ) | .cr_name')
Expand All @@ -98,12 +98,14 @@ for c in $(echo $cartridges | jq -r '.[].name');do
continue
fi

# Check if object exists
oc get --namespace $project $cr_cr $cr_name
if [ $? -ne 0 ];then
log "Error: $cr_cr object $cr_name does not exist in project $project"
exit_code=3
continue
# Check if object exists (only for current cartridge)
if [[ "$c" == "$current_cartridge_name" ]];then
oc get --namespace $project $cr_cr $cr_name
if [ $? -ne 0 ];then
log "Error: $cr_cr object $cr_name does not exist in project $project"
exit_code=3
continue
fi
fi

# TODO: Remove the patching of Db2 statefulsets once tty issue has been resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash

# Parameters
# $1: Status directory
# $2: OpenShift project for Cloud Pak for Data

status_dir=$1
project=$2

exit_code=0

get_logtime() {
echo $(date "+%Y-%m-%d %H:%M:%S")
}

log() {
LOG_TIME=$(get_logtime)
printf "[${LOG_TIME}] ${1}\n" | tee -a ${status_dir}/log/$project-wxo-48-patch.log
}

log "----------"
# Check if the connection to the OpenShift cluster is still valid
log "Info: Checking access to project $project"
oc get project $project
if [ $? -ne 0 ];then
log "Error: Could not access project $project. Has the OpenShift login token expired?"
exit 99
fi

ops_manager_patched=0
rabbit_mq_cluster_patched=0

while true;do
log "----------"
log "Checking OpsManager in project ${project}"
log "----------"

if oc get opsmanagers.mongodb.com -n ${project} mongodb-wo-mongo-ops-manager;then
log "Info: Patching OpsManager mongodb-wo-mongo-ops-manager"
patch_result=$(oc patch opsmanagers.mongodb.com \
-n ${project} mongodb-wo-mongo-ops-manager \
--type merge \
--patch '{
"spec": {
"applicationDatabase":{
"podSpec":{
"podTemplate":{
"metadata":{
"labels":{
"wo.watsonx.ibm.com/external-access":"true"
}
}
}
}
}
}
}' 2>&1 | tee -a ${status_dir}/log/$project-wxo-48-patch.log)
if [[ "$patch_result" != *"(no change)"* ]];then
echo "OpsManager has been patched." | tee -a ${status_dir}/log/$project-wxo-48-patch.log
oc delete sts -n ${project} mongodb-wo-mongo-ops-manager-db --ignore-not-found
fi
ops_manager_patched=1
fi

log "----------"
log "Checking RabbitMQCluster in project ${project}"
log "----------"

if oc get rabbitmqclusters.rabbitmq.opencontent.ibm.com -n ${project} wo-rabbitmq;then
log "Info: Patching RabbitMQCluster wo-rabbitmq"
patch_result=$(oc patch rabbitmqclusters.rabbitmq.opencontent.ibm.com \
-n ${project} wo-rabbitmq \
--type merge \
--patch '{
"metadata":{
"annotations":{
"wo.watsonx.ibm.com/hands-off":"true"
}
},
"spec":{
"global":{
"podLabels":{
"wo.watsonx.ibm.com/external-access":"true"
}
}
}
}' 2>&1 | tee -a ${status_dir}/log/$project-wxo-48-patch.log)
if [[ "$patch_result" != *"(no change)"* ]];then
echo "RabbitMQCluster has been patched." | tee -a ${status_dir}/log/$project-wxo-48-patch.log
oc delete job -n ${project} wo-rabbitmq-orchestrate-backup-label --ignore-not-found
fi
rabbit_mq_cluster_patched=1
fi

if [[ ${ops_manager_patched} -eq 1 && ${rabbit_mq_cluster_patched} -eq 1 ]];then
log "Both OpsManager and RabbitMQCluster have been patched, exiting"
exit 0
fi

log "----------"
log "Finished checks, sleeping for 2 minutes"
sleep 120
done
exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
debug:
msg: ""

- set_fact:
_apply_cr_cartridges: >-
{{ _cartridges_to_install |
rejectattr('olm_utils_name','==','scheduler') |
selectattr('separate_install','undefined') |
union(_cartridges_to_install | selectattr('separate_install','defined') | selectattr('separate_install','!=',True)) }}
- set_fact:
_apply_cr_cartridges_list: >-
{{ _apply_cr_cartridges |
map(attribute='olm_utils_name') |
join(',')}}
- name: Run pre-processing scripts
include_tasks: cp4d-install-cr-pre-processing.yml
loop: "{{ _apply_cr_cartridges | default([]) }}"
loop_control:
loop_var: _current_cp4d_cartridge

# Always generate the preview script to log what will be done
- name: Generate command preview script to install cartridges
set_fact:
Expand Down Expand Up @@ -65,4 +84,10 @@
- name: Run shell script to install cartridges, logs are in {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-apply-cr-cartridges.log
shell: |
{{ status_dir }}/cp4d/{{ _p_current_cp4d_cluster.project }}-apply-cr-cartridges.sh >> {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-apply-cr-cartridges.log 2>&1
when: not _sequential_install
when: not _sequential_install

- name: Wait for cartridges to finish installation
include_tasks: cp4d-wait-cartridges-ready.yml
loop: "{{ _apply_cr_cartridges | default([]) }}"
loop_control:
loop_var: _current_cp4d_cartridge
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
include_tasks: "{{ _current_cp4d_cartridge.cr_preprocessing_script }}"
when:
- (_current_cp4d_cartridge.cr_preprocessing_script | default('')) != ''
- (_current_cp4d_cartridge.state | default('installed')) == 'installed'
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
- block:

- name: Run pre-processing script
include_tasks: cp4d-install-cr-pre-processing.yml

- ansible.builtin.stat:
path: "{{ role_path }}/tasks/cp4d-install-cr-{{ _current_cp4d_cartridge.olm_utils_name }}.yml"
register: _install_cr_script
Expand All @@ -13,5 +17,4 @@
when: _install_cr_script.stat.exists

when:
- (_current_cp4d_cartridge.state | default('installed')) == 'installed'
- (_current_cp4d_cartridge.separate_install | default(False) | bool)
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
- name: Check if Watson Assistant has been installed {{ _p_current_cp4d_cluster.project }}
shell: |
oc get WatsonAssistant wa -n {{ _p_current_cp4d_cluster.project }}
failed_when: False
register: _wa_installed

- name: Fail if Watson Assistant has not been installed in project {{ _p_current_cp4d_cluster.project }}
fail:
msg: Watson Assistant has not been installed in project {{ _p_current_cp4d_cluster.project }}
when: _wa_installed.rc != 0

- name: Generate OLM utils command to create watsonx Orchestrate subscription
set_fact:
_apply_olm_wxo_command: "{{ lookup('template', 'apply-olm-cartridge-wxo.j2') }}"

- name: Show apply-olm command to create watsonx Orchestrate subscription
debug:
var: _apply_olm_wxo_command

- name: Run apply-olm command to install watsonx Orchestrate subscriptions, logs are in {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-apply-olm-wxo.log
shell: |
{{ _apply_olm_wxo_command }} > {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-apply-olm-wxo.log 2>&1
retries: 2
delay: 10
until: _apply_olm_wxo_result.rc==0
register: _apply_olm_wxo_result

- set_fact:
_app_connect: "{{ _current_cp4d_cartridge.app_connect }}"

- name: Download IBM App Connect case file version {{ _app_connect.app_connect_case_version }}
get_url:
url: "https://github.com/IBM/cloud-pak/raw/master/repo/case/ibm-appconnect/{{ _app_connect.app_connect_case_version }}/ibm-appconnect-{{ _app_connect.app_connect_case_version }}.tgz"
dest: "{{ status_dir }}/cp4d/ibm-app-connect-{{ _app_connect.app_connect_case_version }}.tar.gz"
owner: root
mode: 0644
register: _case_download_result
until: _case_download_result is succeeded
retries: 5
delay: 30

- name: Unpack IBM App Connect case file {{ status_dir }}/cp4d/ibm-app-connect-{{ _app_connect.app_connect_case_version }}.tar.gz to /tmp
unarchive:
src: "{{ status_dir }}/cp4d/ibm-app-connect-{{ _app_connect.app_connect_case_version }}.tar.gz"
dest: /tmp
remote_src: True

- name: Create OpenShift Project {{ _app_connect.app_connect_project }}
shell:
oc new-project {{ _app_connect.app_connect_project }} || true

- name: Create IBM App Connect catalog source
shell: |
oc patch --filename=/tmp/ibm-appconnect/inventory/ibmAppconnect/files/op-olm/catalog_source.yaml \
--type=merge \
-o yaml \
--patch='{"metadata": {"namespace": "{{ _app_connect.app_connect_project }}"}}' \
--dry-run=client | oc apply -n {{ _app_connect.app_connect_project }} -f -
- name: Generate yaml for IBM App Connect operator
template:
src: ibm-app-connect.j2
dest: "{{ status_dir }}/cp4d/{{ _p_current_cp4d_cluster.project }}-ibm-app-connect.yaml"

- name: Create IBM App Connect operator
shell: |
oc apply -f {{ status_dir }}/cp4d/{{ _p_current_cp4d_cluster.project }}-ibm-app-connect.yaml
- name: Wait for IBM App Connect operator to be installed
shell: |
oc wait csv --namespace={{ _app_connect.app_connect_project }} \
-l=operators.coreos.com/ibm-appconnect.{{ _app_connect.app_connect_project }}='' \
--for='jsonpath={.status.phase}'=Succeeded --timeout=30s
register: _ibm_app_connect_csv
retries: 20
delay: 10
until: _ibm_app_connect_csv.rc == 0

- name: Create IBM App Connect instance for watsonx watsonx.orchestrate
shell: |
setup-appconnect \
--appconnect_ns={{ _app_connect.app_connect_project }} \
--cpd_instance_ns={{ _p_current_cp4d_cluster.project }} \
--release={{ _p_current_cp4d_cluster.cp4d_version }} \
--components=watsonx_orchestrate \
--file_storage_class={{ ocp_storage_class_file }}
- set_fact:
_cp4d_admin_password_vault_key_name: "cp4d_admin_{{ _p_current_cp4d_cluster.project| replace('-','_') }}_{{ _p_current_cp4d_cluster.openshift_cluster_name| replace('-','_') }}"

- name: Retrieve CP4D admin password from vault secret {{ _cp4d_admin_password_vault_key_name }}
include_role:
name: vault-get-secret
vars:
secret_name: "{{ _cp4d_admin_password_vault_key_name }}"
secret_group: "{{ environment_name }}"
_p_secret_variable: _cp4d_admin_password_vault

- name: Setup watsonx Assistant instances for watsonx watsonx.orchestrate
shell: |
setup-wxo-assistant \
--cpd_instance_ns={{ _p_current_cp4d_cluster.project }} \
--create_assistants=true \
--user={{ _cp4d_user }} \
--password={{ _cp4d_admin_password_vault }} \
--auth_type=password
register: _setup_wxo_assistant
retries: 5
delay: 10
until: _setup_wxo_assistant.rc == 0

- block:
- name: Starting background task to patch OpsManager and RabbitMQCluster. Logs are in {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-wxo-48-patch.log
shell: |
{{ role_path }}/files/temp-patch-wxo.sh \
{{ status_dir }} \
{{ _p_current_cp4d_cluster.project }}
async: 86400
poll: 0
register: _patch_wxo_48

- name: Show details of background task to patch watsonx Orchestrate
debug:
var: _patch_wxo_48
when: _p_current_cp4d_cluster.cp4d_version == "4.8.4"
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
---
- block:
- name: Write status of cartridges to {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-cartridges-status.csv
shell: |
get-cr-status --cpd_instance_ns={{ _p_current_cp4d_cluster.project }} > {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-cartridges-status.csv
- name: Write cartridge information to file {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-cartridges.json
copy:
content: "{{ _cartridges_to_install | default([]) | to_json }}"
Expand Down Expand Up @@ -35,6 +39,5 @@
- not (cpd_test_cartridges | default(False) | bool)

when:
- (_current_cp4d_cartridge.state | default('installed')) == 'installed'
- not _current_cp4d_cartridge.name in ['cpfs','cp-foundation','cpd_platform','lite','scheduler']
- not (_current_cp4d_cartridge.cr_internal | default(False) | bool)
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
cloudpakfordata: true
iamIntegration: {{ _p_current_cp4d_cluster.use_fs_iam | default(False) | bool }}
- name: Run pre-processing scripts
include_tasks: cp4d-install-cr-pre-processing.yml
loop: "{{ _cartridges_to_install | default([]) }}"
loop_control:
loop_var: _current_cp4d_cartridge

- name: Starting background task to patch Db2U clusters. Logs are in {{ status_dir }}/log/{{ _p_current_cp4d_cluster.project }}-db2u-temp-patch.log
shell: |
{{ role_path }}/files/temp-patch-db2u.sh \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
-v \
--cpd_instance_ns={{ _p_current_cp4d_cluster.project }} \
--param-file={{ status_dir }}/cp4d/{{ _p_current_cp4d_cluster.project }}-install-options.yml \
--components={% for c in _cartridges_to_install -%}
{%- if (c.state | default('installed')) == 'installed' and (not c.separate_install | default(False | bool) and (c.olm_utils_name != 'scheduler')) -%}
{%- if not loop.first -%},{% endif -%}
{{ c.olm_utils_name }}
{%- endif -%}
{%- endfor %} \
--components={{ _apply_cr_cartridges_list }} \
{%- if _storage_type == "pwx" -%}
--storage_vendor=portworx
{%- else -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/opt/ansible/bin/apply-olm \
--release={{ _p_current_cp4d_cluster.cp4d_version }} \
--case_download=false \
--catsrc=false --sub=true \
--cpd_operator_ns={{ _p_current_cp4d_cluster.operators_project | default('cpd-operators') }} \
--upgrade={%- if _upgrade_cp4d -%}true{%- else -%}false{%- endif %} \
--components=watsonx_orchestrate
Loading

0 comments on commit 9560797

Please sign in to comment.