Upgrade R2-2021 auf R3-2021 "Kiwi"

Upgrade FOLIO R2-2021 "Juniper" => R3-2021 "Kiwi"
*************************************************
Installationsnotizen von Ingolf. DurchgefĂźhrt zwischen 01.02. und 21.02.2022 auf hbz-Testrechner folio-hbz5 (10.9.2.86) + DB-Server (hbz-Test, 10.9.2.65)

Auf Basis von "platform-complete"
Mit automatischer Migration der Datenbankinhalte
Deployment mit Okapi, "Single Server" auf BS Ubuntu 20.04.2 LTS

# BenĂśtigt fĂźr den Upgrade werden:
 8 CPUs
 40 GB RAM
 empfohlen: 350 GB SSD HD

# Ubuntu Updates installieren
  sudo apt-get update
  sudo apt-get upgrade
  sudo reboot
  # Sind alle Services wieder angestartet ? (Okapi, postgres, docker)

# Kiwi Versionshinweise:
https://folio-org.atlassian.net/wiki/display/REL/Kiwi+%28R3+2021%29+Release+Notes

# Daraus abgeleitete erforderliche Aktionen vor dem Upgrade (Ingolf):

I.) Vorbereitende Arbeiten
# ************************
i.) Vor dem Upgrade: Ändern Sie alle doppelten Artikel-Barcodes.
Finden Sie sie mit diesem SQL:
pslq folio
SET search_path TO diku_mod_inventory_storage;
SELECT lower(jsonb->>'barcode')
FROM item
GROUP BY 1
HAVING count(*) > 1;
 lower
-------
(0 rows)
# Verwenden Sie die Barcode-Suche nach Inventarartikeln, um den doppelten Barcode zu bearbeiten. (gibt keine)

ii.) DB-Tabellen kÜnnen Bestandsdatensätze mit falschem Quellwert enthalten.
siehe hier https://folio-org.atlassian.net/wiki/pages/viewpage.action?pageId=1390748 :
# Select Holdings where sourceName are not FOLIO and MARC
SELECT
*
FROM ${tenant}_mod_inventory_storage.holdings_record
WHERE ${tenant}_mod_inventory_storage.holdings_record.jsonb ->> 'sourceId' = (
SELECT
id::text
FROM ${tenant}_mod_inventory_storage.holdings_records_source
WHERE ${tenant}_mod_inventory_storage.holdings_records_source.jsonb ->> 'name' != 'FOLIO' AND
${tenant}_mod_inventory_storage.holdings_records_source.jsonb ->> 'name' != 'MARC');
(0 rows)

(END)
# If the holdings source is anything other than FOLIO or MARC (e.g. -), then change to FOLIO. (is nich)

# iii)[ Erstinstallation Elasticsearch (fĂźr mod_search, folio_inventory-es), wenn man es in Juniper noch nicht installiert hatte.
 Wenn man in Juniper Elasticsearch schon installiert hat (PoC), kann iii) ßbersprungen werden.

- Installiere Elasticsearch mit Docker: https://www.elastic.co/guide/en/elasticsearch/reference/7.5/docker.html
  docker pull docker.elastic.co/elasticsearch/elasticsearch:7.5.2
  # Start eines ES-Clusters mit 3 Knoten:
  mkdir /usr/share/elasticsearch/data
  sysctl -w vm.max_map_count=262144
  cd ~/upgrade/elasticsearch
  vim docker-compose.yml
  docker-compose up -d
  docker run --rm centos:7 /bin/bash -c 'ulimit -Hn && ulimit -Sn && ulimit -Hu && ulimit -Su'
    1048576
    1048576
    unlimited
    unlimited
  Jetzt geht:
   http://folio-hbz5.hbz-nrw.de:9200/   --> "Weißt Du, für die Suche"
  # ENDE Start von ES im Cluster-Modus
  curl -X GET "localhost:9200/_cat/nodes?v&pretty"
  [ folge jetzt hier: https://github.com/folio-org/mod-search#configuring-elasticsearch ]
  in einen ES-Container einloggen: docker exec -it <containerid> sh
  Im Container: cd /usr/share/elasticsearch
  Plugins der Reihe nach installieren:
  elasticsearch-plugin install --batch analysis-icu
  elasticsearch-plugin install --batch analysis-kuromoji
  elasticsearch-plugin install --batch analysis-smartcn
  elasticsearch-plugin install --batch analysis-nori
  elasticsearch-plugin install --batch analysis-phonetic
  Das fßr die anderen beiden Elasticsearch-Container auch machen.
  # bei stop|start der Container werden die Pluigns erneut geladen :-)
  Jetzt mal mod-search mit Umgebungsvariablen, die auf elasticsearch zeigen, "hochfahren"
  https://github.com/folio-org/mod-search#environment-variables
  cd ~/folio-install
  curl -X GET -o mod-search-1.4.4-module-descriptor.json -D - -w '\n' http://localhost:9130/_/proxy/modules/mod-search-1.4.4
  vim mod-search-1.4.4-module-descriptor.json
      "name" : "ELASTICSEARCH_HOST"
      "value" : "10.9.2.86"  # Die IP des Single Servers, oder wo man Elasticsearch installiert hat
      "name" : "ELASTICSEARCH_URL",
      "value" : "http://10.9.2.86:9200"
      "name" : "ELASTICSEARCH_USERNAME",
      "value" : "elastic"
      "name" : "ELASTICSEARCH_PASSWORD",
      "value" : "s3cret" # Oder ein sichereres wählen
      "name" : "INITIAL_LANGUAGES",
      "value" : "ger"
      "name" : "SYSTEM_USER_PASSWORD",
      "value" : "*******" # Dasselbe wie fßr pubsub verwenden !
  curl -X DELETE -D - -w '\n' http://localhost:9130/_/proxy/modules/mod-search-1.4.4
  curl -i -w '\n' -X POST -H 'Content-type: application/json' -d @mod-search-1.4.4-module-descriptor.json http://localhost:9130/_/proxy/modules
  ./deploy-backend-module.sh mod-search-1.4.4 10.9.2.86
  # Aktiviere mod-search fßr den Mandanten:
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @/usr/folio/platform-complete/search-install.json http://localhost:9130/_/proxy/tenants/diku/install?simulate=true\&preRelease=false
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @/usr/folio/platform-complete/search-install.json http://localhost:9130/_/proxy/tenants/diku/install?deploy=false\&preRelease=false\&tenantParameters=loadReference%3Dtrue%2CloadSample%3Dfalse

# GehĂśrt noch zu "Installation Elasticsearch"
# Das Frontend neu installieren; ui-inventory-es und ui-search mĂźssen hinzugefĂźgt werden.
# Anschließend auch die Stripes-Module für den Mandanten aktivieren !!
#
  cd ~/platform-complete
  # Fßge mod-search-1.4.4, folio_search und folio_inventory-es zu install.json wieder hinzu:
  git restore install.json
  # Fßge mod-search-1.4.4 zu okapi-install.json wieder hinzu:
  git restore okapi-install.json
  # Fßge foilo_search und folio_inventory-es zu stripes-install.json wieder hinzu:
  git restore stripes-install.json
  # Fßge @folio/search und @folio/inventory-es zu package.json wieder hinzu:
  git restore package.json
  # Fßge @folio/search und @folio/inventory-es zu stripes.config.js wieder hinzu.
  Manuell machen; kein Restore, da sich URL und Branding geändert hat.

# Melde die Frontend-Module folio_search und folio_inventory_es an, um sie fĂźr den Mandanten zu aktivieren (aber nicht bereitzustellen; es sind ja keine Container)
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @/usr/folio/platform-complete/search-ui-install.json http://localhost:9130/_/proxy/tenants/diku/install?simulate=true\&preRelease=false
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @/usr/folio/platform-complete/search-ui-install.json http://localhost:9130/_/proxy/tenants/diku/install?preRelease=false

# Die FOLIO Stripes-Plattform neu erstellen (mit folio_search und folio_inventory-es)
# Installation von Stripes und nginx in einem Docker-Container
  cd ~/platform-complete
  vim docker/Dockerfile
    ARG OKAPI_URL=http://folio-hbz5.hbz-nrw.de/okapi
    ARG TENANT_ID=diku

  vim docker/nginx.conf
    server_name folio-hbz5.hbz-nrw.de;
    ...
    # back-end requests:
    location /okapi {
      rewrite ^/okapi/(.*) /$1 break;
      proxy_pass http://10.9.2.86:9130/;

  vim stripes.config.js
    Mandant (tenant) und Okapi-URL anpassen:
      okapi: { 'url':'http://folio-hbz5.hbz-nrw.de/okapi', 'tenant':'diku' },
      ...
      Logo und Favoriten-Bildchen anpassen

  # Den Docker-Container bauen
  cd ~/platform-complete
  sudo su
  docker build -f docker/Dockerfile --build-arg OKAPI_URL=http://10.9.2.86:9130 --build-arg TENANT_ID=diku -t stripes .
Step 1/19 : FROM node:15-alpine as stripes_build
...
Step 19/19 : ENTRYPOINT ["/usr/bin/entrypoint.sh"]
 ---> Running in a47dce4e3b3e
Removing intermediate container a47dce4e3b3e
 ---> 48a532266f21
Successfully built 48a532266f21
Successfully tagged stripes:latest

# Läuft ca. 15 Minuten lang.
  # Den Docker-Container starten. Dabei Port 80 von außen auf Port 80 des Containers umleiten. Für SSL muss auch der Port 443 umgeleitet werden (ist nicht Teil dieser Doku):
  # Achtung ! Alter Stripes-Container wurde automatisch gestoppt und entfernt.
  Der Port 80 muss aber noch wieder frei gegeben werden:
  netstat -taupn | grep 80
  tcp6       0      0 :::80                   :::*                    LISTEN      216581/docker-proxy
  tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      216573/docker-proxy
  kill 216581
  kill 216573
  # nginx auf dem Server anhalten: sudo service nginx stop
  nohup docker run -d -p 80:80 stripes

  # Einloggen in den Docker Container
  docker exec -it <id> sh
  ßberprufen, ob die Konf.datei richtig angekommen ist:
  vi /etc/nginx/conf.d/default.conf
  # das Webserver-Log in dem Container verfolgen
  tail -f /var/log/nginx/host.access.log

  # gehÜrt noch zu Erstinstallation Elasticsearch
   # Jetzt hier mal weiter gucken, was man mit mod-search jetzt schon anfangen kann:
     https://github.com/folio-org/mod-search#recreating-elasticsearch-index
  # Neuindexierung (bzw. Erstindexierung)
  Folgende Berechtigung an diku_admin vergeben:
    search.index.inventory.reindex.post (Search - starts inventory reindex operation)
  Ein neues Token holen:
   export TOKEN=$( curl -s -S -D - -H "X-Okapi-Tenant: diku" -H "Content-type: application/json" -H "Accept: application/json" -d '{ "tenant" : "diku", "username" : "diku_admin", "password" : "admin" }' http://localhost:9130/authn/login | grep -i "^x-okapi-token: " )
  curl -w '\n' -D - -X POST -H "$TOKEN" -H "X-Okapi-Tenant: diku" -H "Content-type: application/json" -d '{ "recreateIndex": true, "resourceName": "instance" }' http://localhost:9130/search/index/inventory/reindex
HTTP/1.1 200 OK
vary: origin
Content-Type: application/json
Date: Tue, 08 Feb 2022 10:52:12 GMT
transfer-encoding: chunked

{"id":"02c8e76a-0606-43f2-808e-86f3c48b65c6","jobStatus":"In progress","submittedDate":"2022-02-08T10:52:12.466+00:00"}

  okapi.log rasselt nun wie blÜde durch: /inventory-view RES 200 mod-inventory-storage
  Der Endpoint /search/index/inventory/reindex bewirkt bei allen 3 Elastic-Containern was. Der Endpoint ist also richtig angebunden.
  Wird nach 5-6 Min. fertig.

   # Monitoring reindex process ( https://github.com/folio-org/mod-search#monitoring-reindex-process )
There is no end-to-end monitoring implemented yet, however it is possible to monitor it partially. In order to check how many records published to Kafka topic use inventory API:
    curl -w '\n' -D - -X GET -H "$TOKEN" -H "X-Okapi-Tenant: diku" -H "Content-type: application/json" http://localhost:9130/instance-storage/reindex/02c8e76a-0606-43f2-808e-86f3c48b65c6
HTTP/1.1 200 OK
vary: origin
Content-Type: application/json
transfer-encoding: chunked

{
  "id" : "02c8e76a-0606-43f2-808e-86f3c48b65c6",
  "published" : 224823,
  "jobStatus" : "Ids published",
  "submittedDate" : "2022-02-08T10:52:12.466+00:00"
}
  Yej, richtig !

  # Gucken, was wirklich zum Elastic-Index hinzugefßgt wurde:
  # In order to estimate total records that actually added to the index, you can send a "match all" search query and check totalRecords
  curl -w '\n' -D - -X GET -H "$TOKEN" -H "X-Okapi-Tenant: diku" -H "Content-type: application/json" http://localhost:9130/search/instances?query=id="*"
 {"totalRecords":224823,"instances":[{"id":"1399845b-6d1f-50fd-9ffc-5d94e06f550d","title":"Molekulare Motoren und kßnstliche Nanomaschinen : Energiewandlung in Polymeren ; Moritz Mickler ; Thorsten Hugel , Physik in unserer Zeit","contributors":[{"name":"Mickler, Moritz","primary":false},{"name":"Hugel, Thorsten","primary":false}]}, ...]}

  # Eine bestimmte ID aus dem Elastic-Index holen:
curl -w '\n' -D - -X GET -H "$TOKEN" -H "X-Okapi-Tenant: diku" -H "Content-type: application/json" http://localhost:9130/search/instances?query=id="365e1e50-5ae5-590c-913a-e15c0fb45dd6"
HTTP/1.1 200 OK
transfer-encoding: chunked

{"totalRecords":1,"instances":[{"id":"365e1e50-5ae5-590c-913a-e15c0fb45dd6","title":"Wie klein ist klein : Eine kurze Geschichte der Quanten ; Aus d. Amerikan. von Michael Schmidt","contributors":[{"name":"Ford, Kenneth W.","primary":false}],"publication":[{"publisher":"Ullstein","dateOfPublication":"2008"}]}]}

  # The main endpoint that provides search capabilities is GET /search/instances.
  curl -w '\n' -D - -X GET -H "$TOKEN" -H "X-Okapi-Tenant: diku" -H "Content-type: application/json" http://localhost:9130/search/instances?query=title+all+"semantic web"
  Eine Beispielsuche: "semantic" und "web" mßssen beide im Titel sein:
  curl -w '\n' -D - -X GET -H "$TOKEN" -H "X-Okapi-Tenant: diku" -H "Content-type: application/json" http://localhost:9130/search/instances?query=title+all+"semantic+web"    => 1 Treffer
  Eine Beispielsuche: "semantic" oder "web" mßssen im Titel sein:
  curl -w '\n' -D - -X GET -H "$TOKEN" -H "X-Okapi-Tenant: diku" -H "Content-type: application/json" http://localhost:9130/search/instances?query=title+any+"semantic+web"  => 174 Treffer
  Ebenso : Katalog - Instanz -CQL-Suche 'title any "semantic web"' => 174 Treffer.

#] Ende Erstinstallation Elasticsearch; Ende iii)


# ******************************************************************
# II. BEGINN Hauptverarbeitung Upgrade Juniper HF3 => Kiwi (R3-2021)
# ******************************************************************

# ******************************************
# II.i)
# Upgrade der Okapi-Version / Neustart Okapi
# Das muss man machen, sonst kann man die neuen Module nicht ziehen
# ******************************************
# Installation und Konfiguration Okapi
# Die Okapi-Version steht in platform-complete/install.json,
# also muss zunächst das heruntergeladen werden:
# Klone das Repositorium platform-complete, wechsle in das Verzeichnis
# git clone https://github.com/folio-org/platform-complete
  cd ~/platform-complete
  git fetch
# neuer Branch R3-2021-hotfix-1
# Leihe den Branch aus.
# Lokale Änderungen zwischenspeichern. Das sollte nur stripes.config.js betreffen.
# Verwerfe Änderungen an install.json etc:
  git restore install.json
  git restore okapi-install.json
  git restore stripes-install.json
  git restore package.json

  git stash save
  git checkout master
  git pull
  git checkout R3-2021-hotfix-1
  git stash pop
  # Lies R3-Okapi-Version aus install.json: okapi-4.11.1

  # Okapi als Debian-Paket von repository.folio.org holen
# Importieren Sie den FOLIO-SignaturschlĂźssel, fĂźgen Sie das FOLIO apt-Repository hinzu und installieren Sie Okapi (dieser Version).
# okapi.conf sichern:
  sudo su
  cp -p /etc/folio/okapi/okapi.conf /usr/folio/upgrade/
#
  wget --quiet -O - https://repository.folio.org/packages/debian/folio-apt-archive-key.asc | sudo apt-key add -
OK
  sudo add-apt-repository "deb https://repository.folio.org/packages/ubuntu focal/"
  sudo apt-get update
  sudo apt-get -y --allow-change-held-packages install okapi=4.11.1-1 # R3-2021 Okapi Version

  # Okapi im Cluster-Modus installieren
  # Port-Bereich in okapi.conf ändern (Elasticsearch ist auf 9200, 9300!)
  vim /usr/folio/upgrade/okapi.conf
      - role="cluster"
      - cluster_config="-hazelcast-config-file /etc/folio/okapi/hazelcast.xml"
      - cluster_port="9001"
      - port_start="9301"
      - port_end="9520"
  # Auch den nodename setzen:
  vim /usr/folio/upgrade/okapi.conf
     nodename="10.9.2.86"
# Den nodename kann man so raus kriegen (Dank an Jason): curl -X GET http://localhost:9130/_/discovery/nodes
[ {
  "nodeId" : "70484de6-fb16-4be1-9efb-10a2a37b76bf",
  "url" : "http://10.9.2.86:9130",
  "nodeName" : "10.9.2.86"
} ]
# siehe in https://github.com/folio-org/okapi/blob/master/doc/guide.md#running-in-cluster-mode
# okapi.conf zurĂźckspielen:
  sudo cp -p /usr/folio/upgrade/okapi.conf /etc/folio/okapi/okapi.conf

   in hazelcast.xml setzen:
     <tcp-ip enabled="true">
                <interface>10.9.2.86</interface>
                <member-list>
                    <member>10.9.2.86</member>
                </member-list>
            </tcp-ip>

  # Neue Umgebungsvariablen fßr Hazelcast an Okapi senden (wenn man Hazelcast bisher nicht verwendet hat):
  curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"OKAPI_CLUSTERHOST\",\"value\":\"10.9.2.86\"}" http://localhost:9130/_/env
  curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"HAZELCAST_IP\",\"value\":\"10.9.2.86\"}" http://localhost:9130/_/env
  curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"HAZELCAST_PORT\",\"value\":\"5701\"}" http://localhost:9130/_/env
  curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"HAZELCAST_FILE\",\"value\":\"/etc/folio/okapi/hazelcast.xml\"}" http://localhost:9130/_/env

# Neustart Okapi:
  sudo systemctl daemon-reload
  sudo systemctl restart okapi.service
# in /var/log/folio/okapi/okapi.log muss kommen:
INFO DeploymentManager fast shutdown
# und direkt im Anschluss
INFO InternalModule InternalModule starting okapiversion=4.8.2
...
INFO MainVerticle Deploy completed succesfully
# Jetzt startet es die Module wieder an.
  docker ps --all | grep "mod-" | wc

# Hole die Liste der Module fĂźr diesen Mandanten (rein informativ)
curl -w '\n' -XGET http://localhost:9130/_/proxy/tenants/diku/modules
...
}, {
  "id" : "okapi-4.8.2"
} ]
# 9x edge, 52x folio_ (Frontend), 62x mod- (Backend) = die R2-Module + das R3-Okapi


# ENDE Upgrade Okapi-Version; weiter "Upgrade auf Kiwi":

# II.ii)
# Moduldeskriptoren aus dem zentralen Register abrufen:
  cd ~/folio-install
  cat << END > okapi-pull.json
> {
>     "urls": [
>         "https://folio-registry.dev.folio.org"
>       ]
> }
> END
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @okapi-pull.json http://localhost:9130/_/proxy/pull/modules

2022-02-18T09:46:33,188 INFO  ProxyContext         272340/proxy REQ 127.0.0.1:60464 supertenant POST /_/proxy/pull/modules  okapi-4.11.1
2022-02-18T09:46:34,691 INFO  PullManager          Remote registry at https://folio-registry.dev.folio.org is version 4.11.1
2022-02-18T09:46:34,692 INFO  PullManager          pull smart
2022-02-18T09:46:37,248 INFO  PullManager          pull: 177 MDs to insert
2022-02-18T09:46:37,919 INFO  ProxyContext         272340/proxy RES 200 4730306us okapi-4.11.1 /_/proxy/pull/modules


# II.iii)
# Ein kompatibles FOLIO-Backend bereitstellen (deploy)

# 1. Umgebungsvariablen zur Verwendung durch die bereitgestellten Module :
  Neue Umgebungsvariablen fßr mod-search / Elasticsearch an /env senden:
  curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"ELASTICSEARCH_HOST\",\"value\":\"10.9.2.86\"}" http://localhost:9130/_/env;
  curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"ELASTICSEARCH_URL\",\"value\":\"http://10.9.2.86:9200\"}" http://localhost:9130/_/env;
  curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"ELASTICSEARCH_USERNAME\",\"value\":\"elastic\"}" http://localhost:9130/_/env;
  curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"ELASTICSEARCH_PASSWORD\",\"value\":\"s3cret\"}" http://localhost:9130/_/env;
  curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"INITIAL_LANGUAGES\",\"value\":\"ger\"}" http://localhost:9130/_/env;
  Das Environment sollte jetzt ungefähr so aussehen:
  curl -X GET http://localhost:9130/_/env
[ {
  "name" : "DB_DATABASE",
  "value" : "folio"
}, {
  "name" : "DB_HOST",
  "value" : "10.9.2.65"
}, {
  "name" : "DB_PASSWORD",
  "value" : "folio123"
}, {
  "name" : "DB_PORT",
  "value" : "5432"
}, {
  "name" : "DB_USERNAME",
  "value" : "folio"
}, {
  "name" : "ELASTICSEARCH_HOST",
  "value" : "10.9.2.86"
}, {
  "name" : "ELASTICSEARCH_PASSWORD",
  "value" : "s3cret"
}, {
  "name" : "ELASTICSEARCH_URL",
  "value" : "http://10.9.2.86:9200"
}, {
  "name" : "ELASTICSEARCH_USERNAME",
  "value" : "elastic"
}, {
  "name" : "HAZELCAST_FILE",
  "value" : "/etc/folio/okapi/hazelcast.xml"
}, {
  "name" : "HAZELCAST_IP",
  "value" : "10.9.2.86"
}, {
  "name" : "HAZELCAST_PORT",
  "value" : "5701"
}, {
  "name" : "INITIAL_LANGUAGES",
  "value" : "ger"
}, {
  "name" : "KAFKA_HOST",
  "value" : "10.9.2.86"
}, {
  "name" : "KAFKA_PORT",
  "value" : "9092"
}, {
  "name" : "OKAPI_CLUSTERHOST",
  "value" : "10.9.2.86"
}, {
  "name" : "OKAPI_URL",
  "value" : "http://10.9.2.86:9130"
}, {
  "name" : "SYSTEM_USER_PASSWORD",
  "value" : "*******"
} ]


# Die Backend-Module bereitstellen (Deploy)
# Das zieht auch die Docker-Abbilder von folioci.

# Rein informativ: Schauen, wie viele Docker-Container jetzt schon laufen:
sudo docker ps | grep -v "^CONTAINER" | wc -l
# 68 Container laufen:
# - 62 Backend-Module R2-2021
# - Stripes
# - 3 Nodes Elasticsearch
# - Kafka & Zookeeper

# Zuerst mod-pubsub hochziehen und aktivieren:
  Die R3-Version von mod-pubsub steht in ~/platform-complete/okapi-install.json: mod-pubsub-2.4.2
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d '[ { "id" : "mod-pubsub-2.4.2", "action" : "enable" } ]' http://localhost:9130/_/proxy/tenants/diku/install?simulate=true
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d '[ { "id" : "mod-pubsub-2.4.2", "action" : "enable" } ]' http://localhost:9130/_/proxy/tenants/diku/install?deploy=true\&preRelease=false\&tenantParameters=loadReference%3Dtrue
HTTP/1.1 200 OK
  # mod-pubsub-2.3.5 wurde dabei am Ende automatisch undeployed:
2022-02-18T10:03:30,873 INFO  DiscoveryManager     autoUndeploy mod-pubsub-2.3.5
2022-02-18T10:03:30,874 INFO  DiscoveryManager     callUndeploy srvcId=mod-pubsub-2.3.5 instId=8fc4a72f-6a89-4e71-a202-70832313a418 node=10.9.2.86
2022-02-18T10:03:30,875 INFO  DeploymentManager    undeploy instId 8fc4a72f-6a89-4e71-a202-70832313a418
2022-02-18T10:03:30,877 INFO  DockerModuleHandle   stop container 724a6897b6e1a6b9162bc46917473689d33448a42e135be4bb880e330b8504a0 image folioorg/mod-pubsub:2.3.5
2022-02-18T10:03:30,884 INFO  TenantManager        job complete
2022-02-18T10:03:31,617 INFO  DockerModuleHandle   delete container 724a6897b6e1a6b9162bc46917473689d33448a42e135be4bb880e330b8504a0 image folioorg/mod-pubsub:2.3.5


# Schließlich alle Backend-Module bereitstellen

# *********************************************************************************************************
# Die Module einzeln bereitstellen. FĂźr jedes Modul wird ein Container hochgefahren.
# *********************************************************************************************************
  # *******************************************************
  # Alles deployen, was noch nicht deplyoed ist:
  # Die Liste okapi-install.json Modul fßr Modul durch gehen.
  # *******************************************************

# FĂźr ein einzelnes Modul geht es so:
  cat > circulation-deployment-descriptor.json <<END
{
  "srvcId": "mod-circulation-22.0.4",
  "nodeId": "10.9.2.86"
}
END
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @circulation-deployment-descriptor.json http://localhost:9130/_/discovery/modules


  mod-pusbsub aus der Liste okapi-install.json entfernen:
  vim ~/platform-complete/okapi-install.json
  entferne mod-pubsub-2.4.2
  Alle Module mit einem einzigen Skript deployen. Das Skript geht die Liste Modul fßr Modul durch.
  cd ~/folio-install
  ./deploy-all-backend-modules.sh ~/platform-complete/okapi-install.json 10.9.2.86
  das läuft ca. 15 Minuten.

  => Jetzt sind die R3-Container deployed, aber noch nicht aktiviert.
     Außerdem laufen auf dem System noch die R2-Container. Diese sind aktiviert. D.h. aktuell ist das System noch im Zustand "R2-2021", bis auf das Okapi (das aber abwärtskompatibel auf R2 ist) und mod-pubsub.
  Es laufen 61 R2-Backend-Module (alle außer pubsub) und alle 65 R3-Backend-Module:
  docker ps --all | grep "mod-" | wc
    126    1537   31418

   # mod-eusage-reports-1.1.0 zusätzlich deployen, da es von einem der R3-2021-hotfix-1 Frontend-Module benÜtigt wird:
  cat > mod-eusage-reports-1.1.0-deployment-descriptor.json <<END
{
  "srvcId": "mod-eusage-reports-1.1.0",
  "nodeId": "10.9.2.86"
}
END
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @mod-eusage-reports-1.1.0-deployment-descriptor.json http://localhost:9130/_/discovery/modules

# II.iv) Aktivieren der Module fĂźr den Mandanten.
# a) Aktiviere die R3-Frontend-Module an fĂźr den Mandanten.
  zunächst simulieren:
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @/usr/folio/platform-complete/stripes-install.json http://localhost:9130/_/proxy/tenants/diku/install?simulate=true\&preRelease=false
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @/usr/folio/platform-complete/stripes-install.json http://localhost:9130/_/proxy/tenants/diku/install?preRelease=false\&tenantParameters=loadReference%3Dtrue


# b) Die R3-Backend-Module fĂźr den Mandanten aktivieren
  Auch in okapi-install.json korrigieren: mod-eusage-reports-1.0.4 --> mod-eusage-reports-1.1.0 !!
  # Jetzt nur aktivieren, nicht deployen, da der Container schon läuft:
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @/usr/folio/platform-complete/okapi-install.json http://localhost:9130/_/proxy/tenants/diku/install?simulate=true\&preRelease=false
  curl -w '\n' -D - -X POST -H "Content-type: application/json" -d @/usr/folio/platform-complete/okapi-install.json http://localhost:9130/_/proxy/tenants/diku/install?deploy=false\&preRelease=false\&tenantParameters=loadReference%3Dtrue


# Rein informativ: Bereitgestellte Module auflisten lassen
  curl -w '\n' -D - http://localhost:9130/_/discovery/modules | grep srvcId | wc
  127
# Rein informativ: Aktivierte Module auflisten lassen
  curl -w '\n' -XGET http://localhost:9130/_/proxy/tenants/diku/modules | grep id | wc
  132
  - 56 Frontend-Module
  - 10 edge-Module
  - 65 R3-2021 Backend-Module
  - 1 Okapi-Modul (4.11.1)


# II.v)
# Eine R3-Version der FOLIO Stripes-Plattform erstellen
# Installation von Stripes und nginx in einem Docker-Container
# Quelle: https://github.com/folio-org/platform-complete
  cd ~/platform-complete
  vim docker/Dockerfile
    ARG OKAPI_URL=http://folio-hbz5.hbz-nrw.de/okapi
    ARG TENANT_ID=diku
  vim docker/nginx.conf
server {
  listen 80;
  server_name folio-hbz5.hbz-nrw.de;
  charset utf-8;
  access_log  /var/log/nginx/host.access.log  combined;

  # front-end requests:
  # Serve index.html for any request not found
  location / {
    # Set path
    root        /usr/share/nginx/html;
    index       index.html index.htm;
    include mime.types;
    types {
      text/plain lock;
    }
    try_files $uri /index.html;
  }

  # back-end requests:
  location /okapi {
    rewrite ^/okapi/(.*) /$1 break;
    proxy_pass http://10.9.2.86:9130/;
  }
}
  vim stripes.config.js
    Mandant (tenant) und Okapi-URL anpassen:
      okapi: { 'url':'http://folio-hbz5.hbz-nrw.de/okapi', 'tenant':'diku' },
      Die URL muss von außen erreichbar sein, als vom Browser. Der Endpoint /okapi wird in der nginx.conf auf den internen Port 9130 umgeleitet.
    Zeile wieder hinzufßgen (falls noch nicht vorhanden):
          '@folio/search' : {},
# in stripes.config.js Logo und Favoriten-Bildchen anpassen
  # Den Docker-Container bauen
  sudo su
  docker build -f docker/Dockerfile --build-arg OKAPI_URL=http://10.9.2.86:9130 --build-arg TENANT_ID=diku -t stripes .
Sending build context to Docker daemon  1.138GB
Step 1/19 : FROM node:15-alpine as stripes_build
...
Step 19/19 : ENTRYPOINT ["/usr/bin/entrypoint.sh"]
 ---> Running in 519f63f13e99
Removing intermediate container 519f63f13e99
 ---> dacd966c64e1
Successfully built dacd966c64e1
Successfully tagged stripes:latest

# Läuft ca. 15 Minuten lang.
  # Den Docker-Container starten. Dabei Port 80 von außen auf Port 80 des Containers umleiten. Für SSL muss auch der Port 443 umgeleitet werden (ist nicht Teil dieser Doku):
  Den alten stripes-Container anhalten: docker stop <containerid>
  Den Port 80 vollständig befreien: netstat -taupn | grep 80. Noch laufende Prozesse auf diesem Port, z.B. docker-proxy, entfernen.
  nohup docker run -d -p 80:80 stripes
  # Einloggen in den Docker Container
  docker exec -it <id> sh
  ßberprufen, ob die Konf.datei richtig angekommen ist:
  vi /etc/nginx/conf.d/default.conf
  # das Webserver-Log in dem Container verfolgen
  tail -f /var/log/nginx/host.access.log
# Auf Frontend einloggen
  http://folio-hbz5.hbz-nrw.de
  Sind die R3-Module zu sehen ? Sieht in "Einstellungen - Installationsdetails" alles gut aus ? Richtige Okapi-Version ?
  Die alten stripes-Container ("Exited" ... ago) entfernen: docker rm <containerid>

# II.vi) Aufräumen
# Aufräumen. Nicht mehr benutzte Container zurßckziehen (undeploy)
  cd ~/upgrade
  # Welche Container sind jetzt aktiviert ?
  curl -w '\n' -XGET http://localhost:9130/_/proxy/tenants/supertenant/modules
    nur aktuelles Okapi. (rein informativ)
  curl -w '\n' -XGET http://localhost:9130/_/proxy/tenants/diku/modules
    nur die R3-Module (rein informativ)

  # Welche Container sind im Discovery und laufen ?
  cd ~/folio-install
  curl -w '\n' -XGET http://localhost:9130/_/discovery/modules | jq '.[] | .srvcId + "/" + .instId' > dockerps.sh
  # Das sollte noch die Modulversionen des alten Releases enthalten
  # => Backend-Module (mod-*) des alten Releases + Backend-Module des neuen Releases (127 Module).
  # Von den 127 deployten Modulen mßssen jetzt noch 62 entfernt werden:
    - alle R2-Module bis auf mod-pubsub. Achtung !!! Teilweise sind es die gleichen wie in R2 !!!  Gucken, welches entfernt werden muss !!!
    - mod-eusage-reports-1.0.4
  sort dockerps.sh > dockerps.todelete.sh
  # Vergleiche mit ~/platform-complete/okapi-install-sh (R3-Module)
  # Alles, was in Kiwi R3 benÜtigt wird, aus der Liste dockerps.todelete.sh entfernen.
  => 62 Zeilen
  # Nicht mehr benutzte, also nicht aktivierte, Versionen so lÜschen:
  curl -w '\n' -D - -XDELETE http://localhost:9130/_/discovery/modules/mod-agreements-4.1.1/<instId>
  ...
  ./dockerps.todelete.sh
  wird jeweils mit "HTTP/1.1 204 No Content" quittiert.

# Jetzt noch einmal die bereitgestellten Module auflisten lassen:
  curl -w '\n' -D - http://localhost:9130/_/discovery/modules | grep srvcId | wc
  65
  # Das sollte nur die Modulversionen des neuen Releases enthalten (65 Module fßr R3-2021)

  # Vergleich mit der Anzahl laufenden Docker-Containern:
  docker ps --all | grep "mod-" | wc
    65
  docker ps --all | wc
     73
  # ziehe stripes, 4x Elasticsearch, Kafka, Zookeeper und die Überschriftszeile ab => 65 Container mit Backend-Modulen (Summen stimmen überein).

* *** FERTIG
*** Melden Sie sich als "diku_admin:admin" (oder Ihr Systemadministrator-Login) auf http://folio-hbz2.hbz-nrw.de (durch Ihren Server-Namen ersetzen) an.

# II.vii) Nachbereitung: Manuelle Tests:
- PrĂźfen, ob die alten Daten noch da sind ! Z.B im Katalog, unter Benutzerverwaltung etc. (Ja)
- sind die Reference Data bei der Migration richtig mitgekommen ? (Martina: Bei den Settings/Einstellungen konnten wir feststellen, dass zwar beim Katalog alles ok scheint (sehr gut), aber bei Ausleihe und Personen und an 2 anderen Stellen die Beispieleinträge wieder „reinkopiert“ wurden und geringfügig wurde etwas überschrieben. (Ingolf: siehe https://folio-org.atlassian.net/browse/UXPROD-3111))