Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
I modelli Dataflow consentono di pacchettizzare una pipeline Dataflow per il deployment.
Chiunque disponga delle autorizzazioni corrette puรฒ quindi utilizzare il modello per eseguire il deployment della pipeline in pacchetto.
Puoi creare modelli Dataflow personalizzati e Google fornisce
modelli predefiniti per scenari comuni.
Vantaggi
I modelli presentano diversi vantaggi rispetto al deployment diretto di una pipeline in Dataflow:
I modelli separano la progettazione della pipeline dal deployment. Ad esempio, uno sviluppatore puรฒ creare un modello e un data scientist puรฒ eseguirne il deployment in un secondo momento.
I modelli possono avere parametri che ti consentono di personalizzare la pipeline quando esegui il deployment del
modello.
Puoi eseguire il deployment di un modello utilizzando la console Google Cloud , Google Cloud CLI o chiamate API REST. Non รจ necessario installare un ambiente di sviluppo o dipendenze della pipeline sulla tua macchina locale.
Un modello รจ un artefatto di codice che puรฒ essere archiviato in un repository di controllo del codice sorgente e utilizzato nelle pipeline di integrazione continua (CI/CD).
Modelli forniti da Google
Google fornisce una serie di modelli Dataflow open source predefiniti che puoi utilizzare per scenari comuni. Per ulteriori informazioni sui modelli disponibili, consulta
Modelli forniti da Google.
Confronta i modelli flessibili e i modelli classici
Dataflow supporta due tipi di modelli: i modelli flessibili, che sono piรน recenti, e i
modelli classici. Se stai creando un nuovo modello Dataflow, ti consigliamo di crearlo come modello flessibile.
Con un modello flessibile, la pipeline viene pacchettizzata come immagine Docker in
Artifact Registry, insieme a un file di specifica del modello in Cloud Storage. La specifica del modello contiene un puntatore all'immagine Docker. Quando esegui il modello, il
servizio Dataflow avvia una VM di avvio, recupera l'immagine Docker ed esegue la
pipeline. Il grafico di esecuzione viene creato dinamicamente in base ai parametri di runtime forniti dall'utente. Per utilizzare l'API per avviare un job che utilizza un modello flessibile, utilizza il metodo
projects.locations.flexTemplates.launch.
Un modello classico contiene la serializzazione JSON di un grafico dei job Dataflow. Il
codice della pipeline deve racchiudere tutti i parametri di runtime nell'interfaccia ValueProvider. Questa interfaccia consente agli utenti di specificare i valori dei parametri quando distribuiscono il modello. Per utilizzare l'API per lavorare con i modelli classici, consulta la
documentazione di riferimento dell'API
projects.locations.templates.
I modelli flessibili offrono i seguenti vantaggi rispetto ai modelli classici:
A differenza dei modelli classici, i modelli flessibili non richiedono l'interfaccia ValueProvider
per i parametri di input. Non tutte le origini e i sink Dataflow supportano
ValueProvider.
Mentre i modelli classici hanno un grafico dei job statico, i modelli flessibili possono costruire dinamicamente
il grafico dei job. Ad esempio, il modello potrebbe selezionare un connettore I/O diverso in base ai parametri di input.
Un modello flessibile puรฒ eseguire il pre-elaborazione su una macchina virtuale (VM) durante la costruzione della pipeline. Ad esempio, potrebbe convalidare i valori dei parametri di input.
Workflow del modello
L'utilizzo dei modelli Dataflow prevede i seguenti passaggi di alto livello:
Gli sviluppatori configurano un ambiente di sviluppo e sviluppano la pipeline. L'ambiente
include l'SDK Apache Beam e altre dipendenze.
A seconda del tipo di modello (flessibile o classico):
Per i modelli flessibili, gli sviluppatori pacchettizzano la pipeline in un'immagine Docker, eseguono il push
dell'immagine in Artifact Registry e caricano un file di specifiche del modello
in Cloud Storage.
Per i modelli classici, gli sviluppatori eseguono la pipeline, creano un file modello e lo eseguono
in Cloud Storage.
Gli altri utenti inviano una richiesta al servizio Dataflow per eseguire il modello.
Dataflow crea una pipeline dal modello. L'avvio della pipeline puรฒ richiedere
fino a 5-7 minuti.
Imposta autorizzazioni IAM
I job Dataflow, inclusi quelli eseguiti dai modelli, utilizzano due service account IAM:
Il servizio Dataflow utilizza un
service account Dataflow
per manipolare le risorse Google Cloud , ad esempio la creazione di VM.
Le VM worker Dataflow utilizzano un
account di servizio worker
per accedere ai file e ad altre risorse della pipeline. Questo account di servizio
deve accedere a tutte le risorse a cui fa riferimento il job della pipeline, incluse l'origine e il sink utilizzati dal modello. Per saperne di piรน, consulta
Risorse Google Cloud di accesso.
Per creare i tuoi modelli, assicurati che la versione dell'SDK Apache Beam supporti la creazione di modelli.
Java
Per creare modelli con l'SDK Apache Beam 2.x per Java, devi disporre della versione
2.0.0-beta3 o successive.
Python
Per creare modelli con l'SDK Apache Beam 2.x per Python, devi disporre della versione 2.0.0 o successive.
Per eseguire i modelli con Google Cloud CLI, devi disporre di Google Cloud CLI
versione 138.0.0 o successive.
Estendere i modelli
Puoi creare i tuoi modelli estendendo i modelli Dataflow open source. Ad esempio, per un modello che utilizza una durata della finestra fissa, i dati
che arrivano al di fuori della finestra potrebbero essere eliminati. Per evitare questo comportamento, utilizza il codice
del modello come base e modificalo per richiamare
l'operazione .withAllowedLateness.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema รจ stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-02 UTC."],[[["\u003cp\u003eDataflow templates allow you to package a Dataflow pipeline for deployment, enabling users with permissions to deploy the packaged pipeline.\u003c/p\u003e\n"],["\u003cp\u003eFlex templates are recommended over classic templates for new Dataflow template creation due to their advantages, such as not requiring the \u003ccode\u003eValueProvider\u003c/code\u003e interface and allowing for dynamic job graph construction.\u003c/p\u003e\n"],["\u003cp\u003eDataflow templates separate pipeline design from deployment, allowing customization through parameters and offering deployment via the Google Cloud console, CLI, or REST API without a development environment.\u003c/p\u003e\n"],["\u003cp\u003eUsing Dataflow templates involves developers packaging the pipeline and other users submitting a request to run it, with Dataflow then creating a pipeline from the template, which can take several minutes to start.\u003c/p\u003e\n"],["\u003cp\u003eDataflow jobs run from templates use two IAM service accounts, a Dataflow service account for manipulating resources and a worker service account for accessing pipeline files and resources.\u003c/p\u003e\n"]]],[],null,["# Dataflow templates allow you to package a Dataflow pipeline for deployment.\nAnyone with the correct permissions can then use the template to deploy the packaged pipeline.\nYou can create your own custom Dataflow templates, and Google provides\n[pre-built templates](/dataflow/docs/templates/provided-templates) for common\nscenarios.\n\nBenefits\n--------\n\nTemplates have several advantages over directly deploying a pipeline to Dataflow:\n\n- Templates separate pipeline design from deployment. For example, a developer can create a template, and a data scientist can deploy the template at a later time.\n- Templates can have parameters that let you customize the pipeline when you deploy the template.\n- You can deploy a template by using the Google Cloud console, the Google Cloud CLI, or REST API calls. You don't need a development environment or any pipeline dependencies installed on your local machine.\n- A template is a code artifact that can be stored in a source control repository and used in continuous integration (CI/CD) pipelines.\n\nGoogle-provided templates\n-------------------------\n\nGoogle provides a variety of pre-built, open source Dataflow templates that you\ncan use for common scenarios. For more information about the available templates, see\n[Google-provided templates](/dataflow/docs/templates/provided-templates).\n\nCompare Flex templates and classic templates\n--------------------------------------------\n\nDataflow supports two types of template: Flex templates, which are newer, and\nclassic templates. If you are creating a new Dataflow template, we recommend\ncreating it as a Flex template.\n\nWith a Flex template, the pipeline is packaged as a Docker image in\nArtifact Registry, along with a template specification file in Cloud Storage. The template\nspecification contains a pointer to the Docker image. When you run the template, the\nDataflow service starts a launcher VM, pulls the Docker image, and runs the\npipeline. The execution graph is dynamically built based on runtime parameters provided by the\nuser. To use the API to launch a job that uses a Flex template, use the\n[`projects.locations.flexTemplates.launch`](/dataflow/docs/reference/rest/v1b3/projects.locations.flexTemplates/launch) method.\n\nA classic template contains the JSON serialization of a Dataflow job graph. The\ncode for the pipeline must wrap any runtime parameters in the `ValueProvider`\ninterface. This interface allows users to specify parameter values when they deploy the\ntemplate. To use the API to work with classic templates, see the\n[`projects.locations.templates`](/dataflow/docs/reference/rest/v1b3/projects.locations.templates)\nAPI reference documentation.\n\nFlex templates have the following advantages over classic templates:\n\n- Unlike classic templates, Flex templates don't require the `ValueProvider` interface for input parameters. Not all Dataflow sources and sinks support `ValueProvider`.\n- While classic templates have a static job graph, Flex templates can dynamically construct the job graph. For example, the template might select a different I/O connector based on input parameters.\n- A Flex template can perform preprocessing on a virtual machine (VM) during pipeline construction. For example, it might validate input parameter values.\n\nTemplate workflow\n-----------------\n\nUsing Dataflow templates involves the following high-level steps:\n\n1. Developers set up a development environment and develop their pipeline. The environment includes the Apache Beam SDK and other dependencies.\n2. Depending on the template type (Flex or classic):\n - For Flex templates, the developers package the pipeline into a Docker image, push the image to Artifact Registry, and upload a template specification file to Cloud Storage.\n - For classic templates, developers run the pipeline, create a template file, and stage the template to Cloud Storage.\n3. Other users submit a request to the Dataflow service to run the template.\n4. Dataflow creates a pipeline from the template. The pipeline can take as much as five to seven minutes to start running.\n\nSet IAM permissions\n-------------------\n\nDataflow jobs, including jobs run from templates, use two IAM service accounts:\n\n- The Dataflow service uses a [Dataflow service account](/dataflow/docs/concepts/security-and-permissions#service_account) to manipulate Google Cloud resources, such as creating VMs.\n- The Dataflow worker VMs use a [worker service account](/dataflow/docs/concepts/security-and-permissions#worker-service-account) to access your pipeline's files and other resources. This service account needs access to any resources that the pipeline job references, including the source and sink that the template uses. For more information, see [Access Google Cloud resources](/dataflow/docs/concepts/security-and-permissions#access-resources).\n\nEnsure that these two service accounts have appropriate roles. For more\ninformation, see\n[Dataflow security and permissions](/dataflow/docs/concepts/security-and-permissions).\n\nApache Beam SDK version requirements\n------------------------------------\n\nTo create your own templates, make sure your Apache Beam SDK version supports template\ncreation. \n\n### Java\n\nTo create templates with the Apache Beam SDK 2.x for Java, you must have version\n2.0.0-beta3 or higher.\n\n### Python\n\nTo create templates with the Apache Beam SDK 2.x for Python, you must have version 2.0.0\nor higher.\n\nTo run templates with Google Cloud CLI, you must have [Google Cloud CLI](/sdk/downloads)\nversion 138.0.0 or higher.\n\nExtend templates\n----------------\n\nYou can build your own templates by extending the\n[open source](https://github.com/GoogleCloudPlatform/DataflowTemplates)\nDataflow templates. For example, for a template that uses a fixed window duration, data\nthat arrives outside of the window might be discarded. To avoid this behavior, use the template\ncode as a base, and modify the code to invoke the\n[`.withAllowedLateness`](https://beam.apache.org/documentation/programming-guide/#managing-late-data) operation.\n\nWhat's next\n-----------\n\n- [Google-provided templates](/dataflow/docs/templates/provided-templates)\n- [Creating classic templates](/dataflow/docs/templates/creating-templates)\n- [Running classic templates](/dataflow/docs/templates/executing-templates)\n- [Build and run Flex Templates](/dataflow/docs/guides/templates/using-flex-templates)\n- [Troubleshoot Flex Templates](/dataflow/docs/guides/troubleshoot-templates)"]]