検索

記事
· 2025年2月11日 4m read

%Status e Exceptions do IRIS

Você pode encontrar erros durante qualquer ponto da execução do programa, e existem várias maneiras de levantar e tratar essas exceções. Neste artigo, exploraremos como as exceções são tratadas de forma eficiente no IRIS.

Um dos tipos de retorno mais comumente usados é %Status, que é usado por métodos para indicar sucesso ou falha. Vamos começar discutindo os valores de %Status.

Trabalhando com %Status

O tipo de retorno %Status é usado para representar erros ou sucesso. Muitos métodos do sistema retornam %Status quando ocorre um erro. Você pode criar uma estrutura semelhante para os erros do seu aplicativo ou converter para %Status, mesmo quando você levantou exceções em seu código.

Vamos começar a criar os erros.

Macros

Quando falamos sobre erros, as Macros são essenciais e facilitam a criação de valores de Status no código. O IRIS fornece várias macros para criar e tratar erros dentro do código do seu aplicativo.

A macro mais comumente usada é $$$ERROR.

$$$ERROR

A macro $$$ERROR é especificamente projetada para gerar e retornar um valor %Library.%Status. É sua responsabilidade verificar o status antes de continuar a execução do seu programa. Esta macro está intimamente ligada a erros gerais do sistema. Tenha os seguintes pontos em mente ao usar esta macro:

-O primeiro argumento (códigos de erro) se refere aos códigos de erro gerais dentro do arquivo include %occErrors.
-Se você estiver usando erros predefinidos desse arquivo include, você pode usar a macro diretamente, com ou sem argumentos adicionais.

Observação: Antes de prosseguir, $SYSTEM.OBJ.DisplayError(status) ou $SYSTEM.Status.DisplayError(status)eram usados para exibir o(s) erro(s) e oferecem suporte à localização de strings. 

Set sc = $$$ERROR($$$NamespaceDoesNotExist,"TEST")
Do $SYSTEM.OBJ.DisplayError(sc)

output: ERROR #5015: Namespace 'TEST' does not exist1
Set sc = $$$ERROR($$$UserCTRLC)
Do $SYSTEM.OBJ.DisplayError(sc)

ouput: ERROR #834: Login aborted1

Se você usar qualquer outro código de erro que não esteja listado em %occErrors, um erro "Código de status desconhecido" será retornado. Sempre use o código de erro predefinido $$$GeneralError == 5001 para mensagens de erro gerais.

Exemplo de código de status desconhecido

Set sc = $$$ERROR(95875,"TEST Error")
Do $SYSTEM.Status.DisplayError(sc)

output: ERROR #95875: Unknown status code: 95875 (TEST Error)
Set sc = $$$ERROR($$$GeneralError,"TEST Error")
Do $SYSTEM.OBJ.DisplayError(sc)

output: ERROR #5001: TEST Error

$$$ADDSC

O %Status não contém necessariamente apenas um erro. Seu programa pode validar várias condições e manter o controle de todos os erros em um único status, e então usar a macro $$$ADDSC. Por exemplo, o método %ValidateObject() pode retornar múltiplos erros em uma única resposta, que usa essa funcionalidade.

A macro $$$ADDSC anexa um status a outro, e o método $SYSTEM.Status.AppendStatus executa a mesma função.

$$$ADDSC(sc1,sc2) / $SYSTEM.Status.AppendStatus(s1,s2) - anexa sc2 a sc1 e retorna um novo código de status.

ClassMethod AppendErrors()
{
    Set sc1 = $$$ERROR($$$UserCTRLC) 
    Set sc2 = $$$ERROR($$$NamespaceDoesNotExist,"TEST")
    Set sc = $$$ADDSC(sc1,sc2)
    Do $SYSTEM.Status.DisplayError(sc)
    Write !
    Set sc = $$$ADDSC(sc1,sc2)
    Do $SYSTEM.Status.DisplayError(sc)
}
output
LEARNING>do ##class(Learning.ErrorHandling).AppendErrors()
 
ERROR #834: Login aborted
ERROR #5015: Namespace 'TEST' does not exist
 
ERROR #834: Login aborted
ERROR #5015: Namespace 'TEST' does not exist

ambos os resultados são iguaias!

$$$GETERRORCODE

$$$GETERRORCODE(status) - Retorna o valor do código de erro do Status. Esta macro pertence ao arquivo %occStatus.inc

    Set status = $$$ERROR($$$UserCTRLC) 
    Write $$$GETERRORCODE(status),!
    #;output: 834
    Set status = $$$ERROR($$$GeneralError,"TEST Error")
    Write $$$GETERRORCODE(status)
    #;output: 5001

$$$GETERRORMESSAGE
$$$GETERRORMESSAGE(sc,num) - Esta macro retorna a parte do erro baseada no número (num) no %Status.
Aqui está um exemplo.

ClassMethod GetErrorMsgMacro()
{
	Set status = $$$ERROR($$$GeneralError,"TEST Error",1,$$$ERROR($$$GeneralError,"TEST Error2"))
	write $$$GETERRORMESSAGE(status),! ; It prints "TEST Error"
	#;
	Set st = $$$GETERRORMESSAGE(status,3) ; it get the "$$$ERROR($$$GeneralError,"TEST Error2")" in 3rd position based on the 2nd argument 
	write $$$GETERRORMESSAGE(st),! ; it prints TEST Error2
}

LEARNING>Do ##class(Learning.myexcept).GetErrorMsgMacro()
TEST Error
TEST Error2

 

Validar Status de Retorno

Agora que você criou o erro e o retornou para o seu programa, o próximo passo é validar se a resposta de retorno é bem-sucedida ou errônea.

A macro $$$ISERR verifica se o status representa um erro. Ela retorna 1 se o status indicar um erro, caso contrário, retorna 0. Existe outra macro, $$$ISOK, que retorna 1 quando o status é bem-sucedido.

Exibindo Erros

Se o seu programa apresentar erros inesperadamente (sempre espere o inesperado), você precisa exibir a mensagem de erro. A classe %SYSTEM.Status é especificamente projetada para visualizar ou criar valores %Status (se você preferir não usar macros) e já vimos os exemplos acima.

Aqui estão os métodos equivalentes em %SYSTEM.Status que substituem as macros:

Macro Methods
$$$ISERR $SYSTEM.Status.IsError()
$$$ISOK $SYSTEM.Status.IsOK()
$$$ADDSC $SYSTEM.Status.AppendStatus()
$$$ERROR $SYSTEM.Status.Error()
$$$OK $SYSTEM.Status.OK()
$$$GETERRORCODE $SYSTEM.Status.GetErrorCodes()

As exceções continuarão no próximo artigo.

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
記事
· 2025年2月11日 5m read

Getting Started Using Istio Service Mesh with Mirrored IRIS Environment in Kubernetes

The Istio Service Mesh is commonly used to monitor communication between services in applications. The "battle-tested" sidecar mode is its most common implementation. It will add a sidecar container to each pod you have in your namespace that has Istio sidecar injection enabled.

It's quite easy to get started with, just put the istioctl executable in your PATH, and label your namespace such that it tells Istio to acitvate side car injection there.

>> kubectl get po -n iris
NAME                                              READY   STATUS    RESTARTS        AGE
intersystems-iris-operator-amd-8588f64559-xqsfz   1/1     Running   0               52s
>> istioctl install
This will install the Istio 1.22.2 "default" profile (with components: Istio core, Istiod, and Ingress gateways) into the cluster. Proceed? (y/N) y
✔ Istio core installed
✔ Istiod installed
✔ Ingress gateways installed
✔ Installation complete                                                                                                                                     Made this installation the default for injection and validation.
>> kubectl label namespace iris istio-injection=enabled
namespace/iris labeled
>> kubectl delete po intersystems-iris-operator-amd-8588f64559-xqsfz -n iris
pod "intersystems-iris-operator-amd-8588f64559-xqsfz" deleted
>> kubectl get po -n iris
NAME                                              READY   STATUS    RESTARTS     AGE
intersystems-iris-operator-amd-8588f64559-c4gfh   2/2     Running   1 (8s ago)   12s

For example, if our pods previously had ready: 1/1 you will now see 2/2, the second pod being the sidecar (note that this will require a pod restart if the pod was up before the namespace was labeled).
See Open Exchange App for GitHub Repo and find irisSimple.yaml to understand this deployment.

>> kubectl get po -n iris
NAME                                              READY   STATUS    RESTARTS        AGE
intersystems-iris-operator-amd-8588f64559-c4gfh   2/2     Running   1 (9m10s ago)   9m14s
iris-data-0                                       2/2     Running   0               64s
iris-webgateway-0                                 2/2     Running   0               28s

Similarly, if I were to have had a WebGateway sidecar, we would see the data node have 3 pods in the container (IRIS, WG, Istio):

See Open Exchange App for GitHub Repo and find irisSimpleSideCar.yaml to understand this deployment

>> kubectl get po -n iris
NAME                                              READY   STATUS    RESTARTS      AGE
intersystems-iris-operator-amd-8588f64559-c4gfh   2/2     Running   1 (11m ago)   11m
iris-data-0                                       3/3     Running   0             35s
iris-webgateway-0                                 2/2     Running   0             2m43s

The idea is that Istio will receive and forward all communication without needing user intervention. The problem with such black boxes, is that when something goes wrong it can be difficult to understand why.

Let's set up a mirrored architecture and see what happens.

First thing you will notice is that iris-data-0-1 will take an extremely long time to start-up. In my tests is is about ~65 minutes. This is because it is attempting to connect to the arbiter and other data node but is not succeeding. There is a timer that is out of the scope of this article that says "after one hour go up with or without mirror setup".

See Open Exchange App for GitHub Repo and find irisMirrorSideCar.yaml to understand this deployment.

kubectl get po -w -n iris
NAME                                              READY   STATUS    RESTARTS       AGE
intersystems-iris-operator-amd-8588f64559-c4gfh   2/2     Running   1 (117m ago)   117m
iris-arbiter-0                                    2/2     Running   0              61m
iris-data-0-0                                     3/3     Running   0              61m
iris-data-0-1                                     2/3     Running   0              60m

Eventually (a bit more than 60 minutes after) we get the following:

>> kubectl get po -n iris
NAME                                              READY   STATUS    RESTARTS        AGE
intersystems-iris-operator-amd-8588f64559-c4gfh   2/2     Running   1 (3h26m ago)   3h26m
iris-arbiter-0                                    2/2     Running   0               150m
iris-data-0-0                                     3/3     Running   0               149m
iris-data-0-1                                     3/3     Running   0               149m
iris-webgateway-0                                 2/2     Running   0               87m

Looking into the logs we see:

2 [Utility.Event] Error creating MirrorSet 'irismirror1' member 'backup': ERROR #2087: Mirror member IRIS-DATA-0-0 is unreachable with IRIS-DATA-0-0.IRIS-SVC.DEFAULT.SVC.CLUSTER.LOCAL,1972

Istio's automatic service and endpoint detection has failed to pass on communications between the arbiter, backup, and primary.

It identifies, by default, that mTLS is being used even though it is not (at least in this situation). In order to get around this we can explicitly tell Istio not to use mTLS. We do this as follows:

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  name: disable-mtls
  namespace: default
spec:
  mtls:
    mode: DISABLE

Once we unblock the communications we get a properly configured mirror:

And finally, we can properly harness the power of Istio, for example with View The Dashboard

Istio has many Custom Resource Definitions, and Peer Authentication is not the only one you may want to look deeper into. Virtual Services and Destination Rule also warrant a look.

 

If you do want to set up mTLS I would point you to these three sources:

1) InterSystems Official mTLS documentation

2) Steve Pisani's great step-by-step explainer

3) IKO Docs - TLS Security (note that some connections here are mTLS while some are only TLS)

1 Comment
ディスカッション (1)1
続けるにはログインするか新規登録を行ってください
お知らせ
· 2025年2月11日

VS Code release January 2025 (version 1.97)

Visual Studio Code releases new updates every month with new features and bug fixes, and the January 2025 release is now available. 

This release enhances AI-assisted editing, customization and security as well as improvements for debugging and log management for a more seamless development experience. If you need help migrating from InterSystems Studio to VS Code, or want to advance your knowledge of VS Code, take a look at the training courses George James Software offers > georgejames.com/vscode-training/

Version 1.97 now includes: 

The release also includes contributions from our very own @John Murray through pull requests that address open issues. 

Find out more about these features in the release notes here > https://code.visualstudio.com/updates/v1_97

For those with VS Code, your environment should auto-update. You can manually check for updates by running Help > Check for Updates on Linux and Windows or running Code > Check for Updates on macOS.

ディスカッション (0)2
続けるにはログインするか新規登録を行ってください
InterSystems公式
· 2025年2月11日

¿Qué hay de nuevo en InterSystems Language Server 2.7?

Primero, ¡queremos desearos un Feliz Año Nuevo a toda la comunidad de desarrolladores! Esperamos traer muchas cosas buenas este año, y hoy queremos presentaros la última versión de la extensión Intersystems Language Server para VS Code. La mayoría de las mejoras del Language Server se experimentan a través de la interfaz de la extensión ObjectScript, por lo que es posible que no hayáis notado los avances en áreas como IntelliSense y las ayudas emergentes que se han lanzado a lo largo de 2024. Os animamos a echar un vistazo rápido al CHANGELOG del Language Server para descubrir lo que os habéis podido perder. La versión más reciente, 2.7.0, trae compatibilidad con la plataforma Windows ARM, así que si tenéis un dispositivo como el Surface Pro 11 (desde el que estamos escribiendo este post con mucha satisfacción), ahora podéis disfrutar de una gran experiencia de desarrollo en ObjectScript en vuestro equipo.

¡Probadlo y contadnos qué os parece en los comentarios!

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
お知らせ
· 2025年2月11日

¿Qué tal con la IA de la Comunidad?

¡Hola! 

¿Conocéis ya la IA de la Comunidad? ¿Qué os parece? 

 

Este año intentaremos potenciar mucho esta herramienta. Pronto veréis mejoras en la misma, y espero que le hayáis dado una oportunidad. Sentíos libres de comentar cualquier cosa acerca de ella (o preguntarme por privado si tenéis dudas de cómo usarla). 

¿Os resultan útiles sus respuestas? 

¡Que tengáis muy buen día! 

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください