Managing project environments

An environment is a set of variables that Cloudera SQL Stream Builder (SSB) substitutes into the properties of tables, data sources, and catalogs. Use environments to run the same project in development, staging, and production with different values.

Environments work like configuration files that adapt a project to a target cluster. For example, you might keep one environment for each of your development, staging, and production clusters, with different hostnames, databases, service URLs, and credentials.

A project can have several environments, but only one is active at a time. You can export an environment to a file and import it into another project or deployment.

Environments belong to the project, but they are not exported to Git with it, and importing a project does not change them. This keeps secrets out of the repository.

  1. In the Streaming SQL Console, click Projects in the left navigation pane, and click the name of your project.
    The project opens, with the Explorer panel on the left. To open the Streaming SQL Console, see Accessing Cloudera SQL Stream Builder.
  2. Expand the Details panel on the right, and click the SSB Environment icon.
    The list of environments is displayed.
  3. Click the New Environment icon.
  4. Enter an Environment Name.
  5. Add a Key and a Value for each variable.
  6. Optional: Optional: Turn on Secure for a variable to mask its value in the Streaming SQL Console.
    When you turn off Secure for a variable, SSB asks you to confirm.
  7. Click Create.
    The environment is displayed in the list.
  8. Click the Activate icon of the environment.
    The environment becomes active, and its name is displayed in a tag in the workspace, next to Search in Project.

Using environment variables

Reference a variable of the active environment as ${ssb.env.[***KEY***]}. You can use variables in the following places:

  • The WITH properties of CREATE TABLE statements, for example:
    CREATE TABLE orders (...) WITH (
      'connector' = 'kafka',
      'properties.bootstrap.servers' = '${ssb.env.kafka_brokers}',
      ...
    );
  • The properties of Kafka data sources, such as the bootstrap servers and the truststore location.
  • The properties of catalogs, such as the Kudu masters or the URI of a Cloudera Harmony catalog.

You can combine literal text and variables in one value:

'url' = 'https://${ssb.env.connector_host}:${ssb.env.connector_port}'

You can also set a variable for your session only, with SET_VAR. Session variables are not saved, and you reference them without the ssb.env prefix. They are displayed on the User Defined Variables tab of your SSB session.

SET_VAR 'topic_name' = 'orders';
CREATE TABLE orders (...) WITH ('topic' = '${topic_name}', ...);

To remove a session variable, run RESET_VAR 'topic_name';. To remove all session variables, run RESET_VAR;.

Environment administration

In the list of environments, you can do the following:

  • Click the Deactivate icon to stop using the active environment.
  • Click the Import icon to import an environment file from your computer.
  • Open the More menu of an environment, and click Export to download it as a file, or Delete to remove it. You cannot delete the active environment.

To change an environment, click its name, edit the variables, and click Apply Changes. When you change the active environment, SSB asks you to confirm with Update and Apply.