検索

Article
· Juil 30, 2024 4m de lecture

Puesta en funcionamiento de Databricks para InterSystems Cloud SQL

 

Un inicio rápido para los datos de InterSystems Cloud SQL en Databricks

La puesta en funcionamiento de Databricks para InterSystems Cloud SQL consta de cuatro partes.

  • Obtención de certificado y controlador JDBC para InterSystems IRIS
  • Añadir un script init y una librería externa a vuestro Databricks Compute Cluster
  • Obtención de Datos
  • Colocación de datos

 

Descargar Certificado X.509/Controlador JDBC de Cloud SQL

Navegad a la página de vista general de vuestro despliegue. Si no tenéis habilitadas las conexiones externas, hacedlo y descargad vuestro certificado y el controlador JDBC desde la página de vista general.

 

He utilizado `intersystems-jdbc-3.8.4.jar` e `intersystems-jdbc-3.7.1.jar` con éxito en Databricks desde Driver Distribution.

Script de inicio para vuestro clúster Databricks

La manera más fácil de importar uno o más certificados CA personalizados a vuestro clúster de Databricks es crear un script de inicio que añada toda la cadena de certificados CA tanto al almacén de certificados predeterminado de Linux SSL como al de Java, y que establezca la propiedad `REQUESTS_CA_BUNDLE`. Pegad el contenido de vuestro certificado X.509 descargado en el bloque superior del siguiente script:

import_cloudsql_certficiate.sh
#!/bin/bash

cat << 'EOF' > /usr/local/share/ca-certificates/cloudsql.crt
-----BEGIN CERTIFICATE-----
<PASTE>
-----END CERTIFICATE-----
EOF

update-ca-certificates

PEM_FILE="/etc/ssl/certs/cloudsql.pem"
PASSWORD="changeit"
JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
KEYSTORE="$JAVA_HOME/lib/security/cacerts"
CERTS=$(grep 'END CERTIFICATE' $PEM_FILE| wc -l)

# To process multiple certs with keytool, you need to extract
# each one from the PEM file and import it into the Java KeyStore.
for N in $(seq 0 $(($CERTS - 1))); do
  ALIAS="$(basename $PEM_FILE)-$N"
  echo "Adding to keystore with alias:$ALIAS"
  cat $PEM_FILE |
    awk "n==$N { print }; /END CERTIFICATE/ { n++ }" |
    keytool -noprompt -import -trustcacerts \
            -alias $ALIAS -keystore $KEYSTORE -storepass $PASSWORD
done
echo "export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt" >> /databricks/spark/conf/spark-env.sh
echo "export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt" >> /databricks/spark/conf/spark-env.sh

Ahora que tenéis el script de inicio, subid el script a Unity Catalog en un Volumen.

Una vez que el script esté en un volumen, podéis añadir el script de inicio al clúster desde el volumen en las Propiedades avanzadas de vuestro clúster.

En segundo lugar, añadid el controlador/biblioteca JDBC de InterSystems al clúster...

...y luego iniciad o reiniciad vuestro compute cluster.

Databricks Station - Entrada InterSystems IRIS Cloud SQL

 

Cread un cuaderno de Python en vuestro espacio de trabajo, adjuntadlo a vuestro clúster y probad la importación de datos a Databricks. En el fondo, Databricks va a estar utilizando pySpark, si eso no es inmediatamente obvio.

La siguiente construcción de dataframe de Spark es todo lo que necesitaréis; podéis obtener vuestra información de conexión desde la página de vista general como antes.

df = (spark.read
  .format("jdbc")
  .option("url", "jdbc:IRIS://k8s-05868f04-a4909631-ac5e3e28ef-6d9f5cd5b3f7f100.elb.us-east-1.amazonaws.com:443/USER")
  .option("driver", "com.intersystems.jdbc.IRISDriver")
  .option("dbtable", "(SELECT name,category,review_point FROM SQLUser.scotch_reviews) AS temp_table;") 
  .option("user", "SQLAdmin")
  .option("password", "REDACTED")
  .option("driver", "com.intersystems.jdbc.IRISDriver")\
  .option("connection security level","10")\
  .option("sslConnection","true")\
  .load())

df.show()

Ilustrando la salida del dataframe con datos de Cloud SQL... ¡boom!

Databricks Station - Salida de InterSystems IRIS Cloud SQL

 

Ahora, tomad lo que hemos leído de IRIS y escribidlo de vuelta con Databricks. Si recordáis, solo leímos 3 campos en nuestro dataframe, así que escribidlo de vuelta inmediatamente y especificad el modo "overwrite".

df = (spark.read
  .format("jdbc")
  .option("url", "jdbc:IRIS://k8s-05868f04-a4909631-ac5e3e28ef-6d9f5cd5b3f7f100.elb.us-east-1.amazonaws.com:443/USER")
  .option("driver", "com.intersystems.jdbc.IRISDriver")
  .option("dbtable", "(SELECT TOP 3 name,category,review_point FROM SQLUser.scotch_reviews) AS temp_table;") 
  .option("user", "SQLAdmin")
  .option("password", "REDACTED")
  .option("driver", "com.intersystems.jdbc.IRISDriver")\
  .option("connection security level","10")\
  .option("sslConnection","true")\
  .load())

df.show()

mode = "overwrite"
properties = {
    "user": "SQLAdmin",
    "password": "REDACTED",
    "driver": "com.intersystems.jdbc.IRISDriver",
    "sslConnection": "true",
    "connection security level": "10",
}

df.write.jdbc(url="jdbc:IRIS://k8s-05868f04-a4909631-ac5e3e28ef-6d9f5cd5b3f7f100.elb.us-east-1.amazonaws.com:443/USER", table="databricks_scotch_reviews", mode=mode, properties=properties)

Ejecutando el cuaderno

 ¡Ilustrando los datos en InterSystems Cloud SQL!

Cosas a considerar

  • Por defecto, PySpark escribe datos usando múltiples tareas concurrentes, lo que puede resultar en escrituras parciales si una de las tareas falla.
  • Para asegurar que la operación de escritura es atómica y consistente, podéis configurar PySpark para que escriba los datos utilizando una única tarea (es decir, establecer el número de particiones en 1) o utilizar una característica específica de iris como las transacciones.
  • Además, podéis utilizar la API DataFrame de PySpark para realizar operaciones de filtrado y agregación antes de leer los datos de la base de datos, lo que puede reducir la cantidad de datos que es necesario transferir a través de la red.
Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer
Question
· Juil 30, 2024

Mirror Configuration Using ^Mirror Routine

I want to use ^Mirror routine to configure mirroring. Can someone please tell what classes and methods I need to use with syntax for configuring the mirroring please OR please point me to any tutorial where ^Mirror routine is used to configure mirror.

2 Comments
Discussion (2)2
Connectez-vous ou inscrivez-vous pour continuer
Article
· Juil 30, 2024 2m de lecture

Reviews on Open Exchange - #46

If one of your packages on OEX receives a review you get notified by OEX only of YOUR own package.   
The rating reflects the experience of the reviewer with the status found at the time of review.   
It is kind of a snapshot and might have changed meanwhile.   
Reviews by other members of the community are marked by * in the last column.

I also placed a bunch of Pull Requests on GitHub when I found a problem I could fix.    
Some were accepted and merged, and some were just ignored.     
So if you made a major change and expect a changed review just let me know.

# Package Review Stars IPM Docker *
1 ServiceInspection 6* super tool for sys managers 6.0 y y  
2 iris-RAG-Gen fast & easy to follow 5.3 y y  
3 Webinar-Leveraging-Embedded-Python low risk starter with Docker 5.0   y  
4 cache-iat-pubsub Impressive in IRIS on Docker 5.0   y  
5 Caché Simple Rule Engine Example in IRIS & Docker 5.0   y  
6 iris-bi-utils your tool to move analytics 5.0 y y  
7 irislab clean and efficient 5.0 y y  
8 sheltershare clean implemented package 5.0   y  
9 sqlzilla professional package 5.0   y  
10 iris-email-analyzer-app more FLASK, AI, PY 4.5 y y  
11 IRIS-production-chat-robot technical ckeck OK 4.5 y y  
12 IRIS-RAG-App might be working 4.5   y  
13 iris-django-template INSTALL FAILS in Windows 3.5   y  
14 iris-fastapi-template installation suspicious 3.5   y  
15 iris-flask-template installation is broken 3.5   y  
Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer
Question
· Juil 30, 2024

Generate JWT token

Hi there,

My purpose is to encrypt a communication using JWT tokens.  I am developing on IRIS and my purpose is to generate a JWT token that will run on an older version of Cache (so I have to use functions that are compatible with the older version, Cache).

I wrote this code in IRIS:

s username = "user-test123"
set st = ##class(%OAuth2.Utils).TimeInSeconds($ztimestamp,0)
set et = ##class(%OAuth2.Utils).TimeInSeconds($ztimestamp, 60*15)

s payload = {"id": "test-id-123", "username": "test-username"}
s payload.exp = et
s payload.time = st

s alg = "HS256"
s JOSE("sigalg") = alg

s secret = "Dw/G:+@%VR[a$LV,D4L{5+(4I}+zf+ER" // $system.Encryption.GenCryptRand(32)
s secret = $System.Encryption.Base64Encode(secret)

s jwks = { "keys": [{ "alg": (alg), "k": (secret) }] }
s jwks = jwks.%ToJSON()

d ##class(%OAuth2.JWKS).AddOct("HS256",secret,.jwks)

s jwks =  ##class(%DynamicAbstractObject).%FromJSON(jwks)

This code works and the output is so:

 USER>zw
 
JOSE("sigalg")="HS256"
alg="HS256"
et=1722327153
jwks=<OBJECT REFERENCE>[38@%Library.DynamicObject]
payload=<OBJECT REFERENCE>[1@%Library.DynamicObject]
secret="RHcvRzorQCVWUlthJExWLEQ0THs1Kyg0SX0remYrRVI="
st=1722326253
username="user-test123"

USER>zw jwks
jwks={"keys":[{"alg":"HS256","k":"RHcvRzorQCVWUlthJExWLEQ0THs1Kyg0SX0remYrRVI="},{"kty":"oct","k":"UkhjdlJ6b3JRQ1ZXVWx0aEpFeFdMRVEwVEhzMUt5ZzBTWDByZW1ZclJWST0","alg":"HS256"}]}  ; <DYNAMIC OBJECT>

%OAuth2.JWKS.AddOct  generated a key in the 3rd argument, "jwks".   In the same argument I passed the input key, that is jwks.keys.k = "...secret...".

I discovered this by chance, trying many possibilities.   There is no place where I could find a working example that generated a pool of keys of type OAuth2.JWKS.

My first question is, why does it work in this form and, is there a simpler way to generate the JWKS ?

Next, the purpose is to encode a json.  In order for OAuth2.JWT.ObjectToJWT to work, I had to remove the key {"alg":"HS256","k":"RHcvRzorQCVWUlthJExWLEQ0THs1Kyg0SX0remYrRVI="}  that I initially inserted in jwks and keep only the key generated by OAuth2.JWKS.AddOct.  So I did so:

s newjwks = {}
s newjwks.keys=[]
d newjwks.keys.%Push(jwks.%Get("keys").%Get(1))
s newjwks = newjwks.%ToJSON()

d ##class(%OAuth2.JWT).ObjectToJWT(.JOSE, payload, newjwks, newjwks, .JWT)

This indeed worked , the output is so:

USER>w newjwks
{"keys":[{"kty":"oct","k":"UkhjdlJ6b3JRQ1ZXVWx0aEpFeFdMRVEwVEhzMUt5ZzBTWDByZW1ZclJWST0","alg":"HS256"}]} 

USER>w JWT
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InRlc3QtaWQtMTIzIiwidXNlcm5hbWUiOiJ0ZXN0LXVzZXJuYW1lIiwiZXhwIjoxNzIyMzI3MTUzLCJ0aW1lIjoxNzIyMzI2MjUzfQ.dEqq_RHJ_1GEjTLFaklNSfAAAZP9B_PgXbUD1aH2Vkk
USER>

Here, I do not understand why I had to remove the initial key and keep only {"kty":"oct","k":"UkhjdlJ6b3JRQ1ZXVWx0aEpFeFdMRVEwVEhzMUt5ZzBTWDByZW1ZclJWST0","alg":"HS256"} in newjwks.

Discussion (0)1
Connectez-vous ou inscrivez-vous pour continuer
Annonce
· Juil 30, 2024

[Vidéo] Prendre en charge la santé populationnelle et la prévention sur un territoire

Salut la Communauté!

Profitez de regarder la nouvelle vidéo sur la chaîne Youtube d'InterSystems France :

📺 Prendre en charge la santé populationnelle et la prévention sur un territoire

Intervenants : 
🗣 @Francois Le Floch, Ingénieur Solutions Internationales, InterSystems
🗣 @Florence Cureau, Solution Architect, InterSystems

Découvrez comment améliorer la santé d'un territoire et prévenir les risques afin d'agir en amont et fournir une prise en charge ciblée pour chaque patient. Apprenez les facteurs de succès en matière de responsabilité populationnelle et la manière dont InterSystems y contribue.

Abonnez-vous à notre chaîne youtube pour plus de vidéos et restez à l'écoute !

Discussion (0)0
Connectez-vous ou inscrivez-vous pour continuer