OVERVIEW: Java secondo Microsoft
STRUMENTI:Java nel cloud
MODALITA’: Il Development life cycle secondo Microsoft
APPROCCIO: Stack cloud native basato su JAVA ed Azure
CAMBIAMENTO: Know how necessario per lo sviluppo su AZURE con Java
OPPORTUNITA: Use case di implementazione «first approach»
3. AGENDA
• OVERVIEW: Java secondo Microsoft
• STRUMENTI:Java nel cloud
• MODALITA’: Il Development life cycle secondo Microsoft
• APPROCCIO: Stack cloud native basato su JAVA ed Azure
• CAMBIAMENTO: Know how necessario per lo sviluppo su AZURE con Java
• OPPORTUNITA: Use case di implementazione «first approach»
4. «Sviluppare Java per Azure»
Qual è la
vostra prima
reazione?
«MA SIAMO MATTI !?!?!?» Cit. Riccardo Zamana - 15 Febbraio 2017
6. CAMBIAMENTO
• Sistemi più complessi (molti nodi e più piccoli)
• Molti più dati (qualche gb >> Forse Tb o Pb?)
• Dati cambiano costantemente (non solo notturni)
• 101% SLA (prima era «torna domani»)
• Pazienza diminuita
NECESSITA’
• Avere approccio più snello al deployment
• Avere approccio più veloce al cambiamento nello
sviluppo
Bisogna proprio fare questo passaggio?
Sviluppare in
Java su Azure è:
- comodo
- facile
- veloce
..e anche ADMIN-LESS !!!
7. • Supportate Jdk7, Jdk8, Jdk11
• SpringFramework
• EclipseMicroprofile
• Maven, Gradle
• VSC, STS, Eclipse, IntelliJ,
• CD/CI con Jenkins
• ALM con DevOps
Maturità & Sponsorship
«Arduo da vedere il
Lato Oscuro è.»
Presenti i primi SDK fin dal 2014.
Sponsorizzazione evidente dal 2017.
11. Visual studio Code & Plugins
• Fast and lightweight, free, and open-source
• Supports multiple, or all the programming
language you use
• No complex IDE installation
• Great micro services support
• Include container tooling and cloud integration
12. 10 Estensioni indispensabili:
1. Language Support for Java(TM) by Red Hat
2. Debugger for Java
3. Java Test Runner
4. Maven for Java
5. Java Dependency Viewer
6. Visual Studio IntelliCode
7. Spring Boot Tools
8. Spring Initializr Java Support
9. Spring Boot Dashboard
10. Tomcat
11. Jetty
12. CheckStyle
Visual studio Code & Plugins
Intellicode!?!?
Maven (M2Eclipse)
Gradle (Buildship)
Java Debug Server
Java Test Runner
13. Supporto tradizionale
•quick deployment to an
Azure Web App container
•quick deployments to
Docker containers running
within Azure Docker Host
VMs
•use the Azure Explorer view
to navigate and manage
your Azure storage accounts
•enable automated telemetry
for your applications using
Application Insights
14. Spring Inizializer
Spring & Azure Sponsored Services
• Spring Security Azure AD: Enterprise-grade authentication and authorization for Spring Security.
• Spring Cloud Stream with Azure Event Hub: Message-driven applications with Azure Event Hub service.
• Spring Resource with Azure Storage: Spring Resource abstraction for Azure Storage service.
• Spring Data Azure Cosmos DB SQL API: Spring Data module for NoSQL data access on Azure.
• Spring Data Gremlin: Spring Data module for Graph databases using Gremlin query language.
Spring Boot Starters for Azure:
Azure Key Vault - Manage application secrets and keys.
Azure Active Directory – Wire up enterprise-grade authentication and authorization.
Azure Redis Cache – Build fast and high-performing applications.
15. Spring Init su Azure
Scaffolding avanzato:
• Generazione guidata servizi
• Config Server centrazlizzato
• Discovery & Registry
• API Gateway
• Controllo porte e mapping
• Supporto Docker, e Kubernetes
… e download del progetto!
19. Installazione ambienti
AZURE CLI è uno strumento
comune agli ingegneri del
software, per il
Censimento,
Esplorazione,
Controllo
delle risorse.
• Strumento focalizzato su Text Editor
• Cross platform
• Focalizzato sull'automazione
• Supporta JSON e UNIX-style output
• Processore di Query integrato, basato su JMESPath
• [Clean output right to a $VAR]
• [Transformations and filtering]
• Facile da imparare
20. AZ CLIENT
JMESPATH è un linguaggio di querying JSON, utile
per filtrare e selezionare parte degli attributi di un
DocumentObject complesso.
SVILUPPATORE:
«Devo lavorare con un ambiente
incredibilmente grande e quindi devo avere la
possibilità di crearlo e distruggerlo»
«Devo lavorare con una VM ce va distrutta o
spenta alla sera»
«Devo avviare dei test automatizzati per
cercare di caricare una applicazione»
AMMINISTRATORE:
«Devo creare un ambiente replicabile per ogni
cliente simile»
«Devo fornire risorse ad un gruppo di sviluppo,
che vanno poi tutelate e distrutte»
«Devo provare e riprovare uno script interno ad
una macchina molto potente, che non è
possibile avere in azienda»
21. az functionapp list -g azureday2019rg001 --query
"[].[hostNames[0], repositorySiteName,
outboundIpAddresses, lastModifiedTimeUtc, location]" --
output table
Un esempio veloce
PROVIAMOLO!
22. • Supporto per Java 8 e Java11
• Tomcat 8.5, Tomcat 9 e WildFly 9
Web application
Quali problemi si risolvono semplicemente usando
AZURE al posto di una tradizionale installazione
standard?
1. SCALING
2. MONITORING
3. DEPLOY TIME
23. Quali esigenze copre l’uso di una funzione AL POSTO di
utilizzare un approccio tradizionale?
• Focus sulla funzionalità e non sulla struttura
• Pricing adeguato all’uso discontinuo
• Struttura di deployment semplificata
Da monolite a RETE DI COMPONENTI MESSAGE DRIVEN!
Serverless Function
24. Come cambia la strategia di
progettazione del software
utilizzando sistemi «Azione-
Reazione»?
Event Grid
Origini eventi
• Sottoscrizioni di Azure
(operazioni di gestione)
• Registro Container
• Argomenti personalizzati
• Hub eventi
• Hub IoT
• Servizi multimediali
• Gruppi di risorse (operazioni
di gestione)
• Bus di servizio
• Archiviazione BLOB
• Mappe di Azure
Gestori eventi
• Automazione di Azure
• Funzioni di Azure
• Hub eventi
• Connessioni ibride
• App per la logica
• Microsoft Flow
• Archiviazione code
• Webhook
5 ELEMENTI:
• Eventi: ciò che successo.
• Origini di eventi: dove si è verificato l'evento.
• Argomenti: l'endpoint a cui gli autori inviano gli eventi.
• Sottoscrizioni agli eventi: l'endpoint o il meccanismo predefinito per instradare gli
eventi, a volte a più gestori. Le sottoscrizioni vengono usate dai gestori anche per filtrare
in modo intelligente gli eventi in ingresso.
• Gestori di eventi: l'app o il servizio che reagisce all'evento.
25. Event GRID – Precauzioni per l’uso
• QUESTA E' la chiamata da mettere nel WebHook del EventGrid
• https://{functionappname}.azurewebsites.net/runtime/webhooks/eventgrid?functionName={functionname}&code={systemkey}
• COME SI FA ad ottenere la system key? QUESTA è la chiamata GET per ottenere la SystemKEY
• http://{functionappname}.azurewebsites.net/admin/host/systemkeys/eventgrid_extension?code={masterkey}
• DA DOVE PRENDI LA MASTER KEY? Pubblichi la funzione, vai su MANAGE e trovi la _Master
• ESEMPIO COMPLETO:
• http://FuncAppEventTrigger20190422124458.azurewebsites.net/admin/host/systemkeys/eventgrid_extension?code=Sri9IKxvpb
bpJdFn6dF3dlXZoAuk4DF6URWYf5g1yVGw1A0q0787AQ==
• ECCO LA RISPOSTA:
• QUINDI:
• https://FuncAppEventTrigger20190422124458.azurewebsites.net/runtime/webhooks/eventgrid?functionName=StartSession&co
de=Bks9oZKL9VS9aB2O/Poir073bW671UBZhGc34//vdK9ZtMqw2ZwQiQ==
{
"name": "eventgrid_extension",
"value": "Bks9oZKL9VS9aB2O/Poir073bW671UBZhGc34//vdK9ZtMqw2ZwQiQ==",
"links": [{
"rel": "self",
"href": "https://funcappeventtrigger20190422124458.azurewebsites.net/admin/host/systemkeys/eventgrid_extension"
}]
}
28. • Componentization via Services
• Services Organized around Products NOT Projects
• Smart endpoints and dumb pipes
• Decentralized Data Management (Bounded Context)
• Polyglot Persistence
• Infrastructure Automation (Self-service)
• Design for Failure
• Sophisticated monitoring
8 Aspetti per lo stack moderno
Cross-functional
teams such that a
team owning a
service has
everyone they
need to implement
a new feature.
29. • La granularità è la misura in cui un sistema è suddiviso in piccole parti, o il
sistema stesso o la sua descrizione o osservazione.
• I sistemi a grana grossa sono costituiti da componenti meno numerosi
rispetto ai sistemi a grana fine
• La comunicazione fra i servizi deve essere COURSE-GRAINED (grossi
documenti, strutturati in sottodocumenti), perché…
…LA RETE CONTA, e un sistema con meno «Micro-ASYNC» è più efficace.
Course-grained vs Fine-grained
coarser-grained communication between services
30. CloudEvents is an open standard being collaborated on by
Microsoft as well as a number of other companies to improve
interoperability.
https://docs.microsoft.com/en-us/azure/event-grid/cloudevents-schema
Qual è il messaging corretto?
https://github.com/cncf/landscape
32. Installazione semplice:
• Installato ZULU
• Installato MAVEN
Configurazione «solita»
• MAVEN_HOME
• JAVA_HOME
• aggiornato PATH
Alcuni consigli per cominciare
«MAVEN è TUTTO»
ESEMPIO:
mvn archetype:generate `
"-DarchetypeGroupId=com.microsoft.azure" `
"-DarchetypeArtifactId=azure-functions-archetype"
PER AZURE FUNCTION:
mvn clean package
mvn azure-functions:run
PER SPRING BOOT:
mvn clean package -DskipTests
mvn spring-boot:run
JAR UNICO STANDARD:
mvn clean compile assembly:single
33. • CTRL+SHIFT+P
• Create Function per aggiungere Functions
• Create Function app in azure
• Spring initializ: generate Maven Project
• Maven: Execute commands
• Maven: Generate from Maven Archetype
• CTRL+SHIFT+D (Debug)
• CTRL+SHIFT+N (Nuovo VSC aperto)
• F5 per RUN applicazioni «classic», altrimenti Maven Tasks:
• mvn azure-functions:run
• mvn spring-boot:run
Alcuni consigli per cominciare
34. Authentication per Management API
1. Posizionarsi nella cartella src/main/resources
2. Lanciare “az ad sp create-for-rbac --sdk-auth > my.azureauth”
3. Ricavare I valori
4. Usare
• ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(clientId,
tenantId, clientSecret, AzureEnvironment.AZURE);
• Azure azure = Azure.authenticate(credentials).withSubscription(subscriptionId);
5. Compilo l’applicationProperties ricordando che sono su Spring, per cui posso
ridichiarare/sovrascrivere da codice i parametri di ciò che è implicitamente dichiarato nel
file
Alcuni consigli per cominciare
35. Tre cose da sapere ed usare
• ASYNC: CompletableFuture
• JSON SERDE: GSON
• EXECUTOR: ExecutorService
Elementi necessari per lo sviluppo
Tre oggetti da conoscere
• MAVEN
• AZ CLIENT
• NPM+YEOMAN
Oggi è indispensabile:
- partire con uno scaffolding assistito,
- capirne la forma
- usare UN IDE leggero, in modalità multi window
- Più tastiera, meno mouse possibile
36. • Spring on Azure aka.ms/spring-on-azure
• PCF on Azure aka.ms/pcf-on-azure
• VS Code for Java aka.ms/code-for-java
• K8S Dev Spaces aka.ms/dev-spaces-java
• Azure DevOps dev.azure.com
• Azul OpenJDK on Azure aka.ms/azul-jdk-azure
• Microsoft Learn microsoft.com/learn
• DEMO complessiva:
• https://github.com/microsoft/inventory-hub-java-on-azure
Alcuni link utili
Quanti di voi: 0,5
- programmano in java
- programmano in java e usano azure
- programmo in java, usano azure e hanno cambiato modo di lavorare
AGENDA: 0,5
Passo indietro: 1
chi sono
perchè sono qui
cosa voglio trasmettervi oggi
Qual'è stata la vostra prima reazione? 1
vi racconto la mia, e da dove arrivavo.
Ho dovuto cambiare "parrocchia" per capire il come e il cosa.
SCENARIO: 1 minuto
Oggi azure mette a disposizione
il mondo OSS offre alternative possibili
FACCIAMO UN ESEMPIO: 1
Ho fatto un esercizio: rifare azure onpremise.
Mostro l'architettura di un progetto dove OSS è a confronto con AZURE
Native and idiomatic support for Java applications.
Debugger for Java is a lightweight Java Debugger based on Java Debug Server.
Starting a debugging session is easy, click on the Run|Debug button available at the CodeLens of your main() function, or press F5.
With the support from the Java Test Runner extension, you can easily run, debug, and manage your JUnit and TestNG test cases.
Spring Boot support is provided by Pivotal. There are also Spring Initializr Java Support and Spring Boot
DEMO!!!!
Eureka fa da service registry, abilitando la service discovery tra i servizi del nostro sistema.
Di default, il server dovrebbe essere avviato sulla porta 8761 e i client, se non differentemente configurati, si aspettano di trovarlo su localhost:8761.
Hystrix è un circuit breaker. Che significa? Dobbiamo sempre tenere in mente che in un sistema distribuito una delle sue parti può non essere disponibile in un certo momento
GATEWAY: This project provides a library for building an API Gateway on top of Spring MVC. Spring Cloud Gateway aims to provide a simple.
Config: Accentrare la configurazione di un progetto
A Technology Compatibility Kit (TCK) is a suite of tests that at least nominally checks a particular alleged implementation of a Java Specification Request (JSR) for compliance
Java Flight Recorder (JFR) is a tool for collecting diagnostic and profiling data about a running Java application, integrated into the Java Virtual Machine (JVM).
E’ LTS
Parlare di AZ Client
13
Pensate a tutte le volte in cui avete dovuto tirare su un castello per due «cose semplci» ?
1. Componentization via Services
Component: A component is a unit of software that is independently replaceable and upgradeable.
In a Microservice architecture, each service acts as a component.
PIPPONE sulla modalità CORPO-TESTA
2. Services Organized around Products NOT Projects
Project: A piece of software is delivered then handed over.
vs.
Product: The development team takes ownership of software from design to deployment.
3. Smart endpoints and dumb pipes
Move away from heavyweight ESB towards HTTP and lightweight messaging queues for inter-service communication.
Move towards coarser-grained communication between services to get more work done per message and decrease the total number of messages.
4. Decentralized Data Management
Bounded Context: Method of dealing with large models by dividing them into different contexts with explicitly defined interrelationships.
Each service boundary should correspond with a bounded context.
5. Polyglot Persistence
Each service manages its own database which can be entirely different database systems. e.g. RDMS, noSQL or graph. Each team should be free to select the datastore that best serves their needs.
6. Infrastructure Automation
Self-service: Allow developers to provision their own new servers or VMs.
You definitely need to move towards Continuous Integration/Continuous Delivery and automate deployment to each new environment.
It's also important to run lots of automated tests and static analysis.
You also want to be able to scale your infrastructure automatically.
Design for Failure
Applications need to be designed so that they can tolerate the failure of services. Clients must respond to failure as gracefully as possible.
It's important to be able to detect the failures quickly and, if possible, automatically restore service. e.g. Self-healing services
Sophisticated monitoring and logging is also needed.
Granularity is the extent to which a system is broken down into small parts, either the system itself or its description or observation.
It is the extent to which a larger entity is subdivided.
For example, a yard broken into inches has finer granularity than a yard broken into feet.
1. Esempio num1: Azure Function (api-buyer-datapump)
2. Esempio num2: ACI (api-aci-runner)
3. Esempio num3: (consumer-buyer-tracking) EventHub Consumer TRADIZIONALE
4. Esempio num4: (consumer-alarm-tracker) Spring Boot App con Cosmos Repository pattern (fai vedere le superclassi)
5. Esempio num5: (order-manage) Spring boot App con Accesso lettura scrittura su Topic e Code
6. Esempio num6: (order-sender) Spring boot App con ApplicationCredentials custom + EventHub Source/Sink
7. Esempio num7: nuova function + deploy via maven