---
layout: article
title: DC SAS Viya Deployment
description: How to deploy Data Controller in a production SAS Viya environment
og_image: https://docs.datacontroller.io/img/dci_deploymentdiagramviya.png
---

# SAS Viya Deployment

## Overview
Data Controller for SAS Viya consists of a static web frontend, a set of Viya Jobs, a staging area (physical directory), a Compute Context, and a Library.

## Prerequisites

### System Account

Data Controller makes use of a system account for performing backend data updates and writing to the staging area.  This needs to be provisioned in advance using the Viya admin-cli.  The process is well described here:  [https://communities.sas.com/t5/SAS-Communities-Library/SAS-Viya-3-5-Compute-Server-Service-Accounts/ta-p/620992](https://communities.sas.com/t5/SAS-Communities-Library/SAS-Viya-3-5-Compute-Server-Service-Accounts/ta-p/620992)

### Library
Currently, all of our customers are using the standard BASE engine library for the control tables.  However it is possible to use a database instead.   To migrate the control library to a database, first perform a regular deployment, and afterwards you can generate the DDL. For this, use the DDL exporter as described [here](/admin-services/#export-database).  If you need a flavour of DDL that is not yet supported, [contact us](https://datacontroller.io/contact/).

Make sure the system account (see above) has full read / write access.

!!! note
    "Modify schema" privileges are not required.

### Staging Directory
All deployments of Data Controller make use of a physical staging directory.  This is used to store logs, as well as CSV and Excel files uploaded by end users.  This directory should NOT be accessible by end users - only the SAS system account requires access to this directory.
A typical small deployment will grow by a 5-10 mb each month.  A very large enterprise customer, with 100 or more editors, might generate up to 0.5 GB or so per month, depending on the size and frequency of the Excel EUCs and CSVs being uploaded.  Web modifications are restricted only to modified rows, so are typically just a few kb in size.

## Deployment Diagram

The below areas of the SAS Viya platform are modified when deploying Data Controller:

<img src="/img/dci_deploymentdiagramviya.svg" height="350" style="border:3px solid black" >

!!! note
    The "streaming" version of Viya uses the files API for web content, so there is no need for the web server component.


## Deployment
Data Controller deployment is split between 2 deployment types:

* Streaming (web content served from SAS Drive)
* Separated (web content served from dedicated web server)

For most customers, the streaming approach is preferred, as it makes the deployment much simpler.


There are several parts to this proces:

1.  Create the Compute Context
2.  Deploy Services
3.  Configure Frontend
4.  First Launch
5.  Optmisation


### Create Shared Compute Context

We strongly recommend a dedicated compute context for running Data Controller.  The setup requires an Administrator account.

* Log onto SASEnvironment Manager, select Contexts, View Compute Contexts, and click the Create icon.
* In the New Compute Context dialog, enter the following attributes:
    * Context Name
    * Launcher Context
    * Attribute pairs:
        * reuseServerProcesses: true
        * runServerAs: {{the account set up [earlier](#system-account)}}
* Save and exit

!!! note
    XCMD is NOT required to use Data Controller.

A group should be defined in Environment Manager that has the "create session" permission on this context.

To avoid giving users the ability to run code on that context (and shared system account) in SAS Studio and other apps, this permission should have the following condition attached:  `clientId() == 'sas.jobExecution'`

### Deploy Services

Services are deployed by running a SAS program.

**Streaming Deploy (BACKEND + FRONTEND):**

Run the following in SAS Studio:

```sas
%let apploc=/Public/DataController; /* desired SAS Drive location */
filename dc url "https://git.datacontroller.io/dc/dc/releases/download/latest/viya.sas";
%inc dc;
```

**Separated Deploy (BACKEND ONLY):**

Run the following in SAS Studio:

```sas
%let apploc=/Public/DataController; /* desired SAS Drive location */
filename dc url "https://git.datacontroller.io/dc/dc/releases/download/latest/viya_noweb.sas";
%inc dc;
```

### Configure Frontend

**Streaming Deploy:**

At the end of the SAS log from Step 2, there will be a link (`YOURSAS.SERVER/SASJobExecution?_file=/YOUR/APPLOC/services/DC.html`). Open this in **SASJobExecution** (not SAS Studio) to perform the configuration (below).

**Separated Deploy:**

Unzip the frontend into your chosen directory (eg `/var/www/html/DataController`) on the SAS Web Server.  Edit `index.html` to perform the configuration (below).

**index.html**

The following attributes may be updated in the index.html file.  For streaming deploy, be sure to use the JobExecution app (not SAS Studio) for correct file type handling.

- `appLoc` - the root folder where the Jobs were deployed in step 2
- `contextName` - here you should put the name of the compute context you created in step 1
- `servertype` - should be SASVIYA
- `debug` - can stay as `false` for performance, but could be switched to `true` for debugging startup issues
- `useComputeApi` - Setting `true` will give the best performance due to the use of [hot sessions](https://github.com/sasjs/adapter#using-the-compute-api) created client-side by the SASjs adapter.  This is great for demo purposes, or when running a single user DC instance, however for typical enterprise use we recommend `false` or `null` so that the compute context usage can be restricted as described [above](/deploy-viya/#create-shared-compute-context)
- `runAsTask` - setting `true` will trigger jobs as Viya Compute Tasks.  Be sure to increase the default expiry to 30 seconds (it is 5 by default) and set `useComputeApi` to `null`.  For scaling options, see [SAS docs](https://documentation.sas.com/doc/en/sasadmincdc/v_074/calsrvpgm/p059rp0q82tvpzn1hk9x26486do5.htm#p1ktrn1coq0rx1n1ux8bjqh8jx4h).


### First Launch

Now the services are deployed (including the service which creates the staging area) we can open the Data Controller web interface and make the necessary configurations:

* dcpath - physical path for deployment (will contain SAS datasets and a subfolder for staged content)
* Admin Group - the members of this group will have full access to Data Controller
* Compute Context - the context configured in Step 1


### Optimisation

At this point, every DC request will read the `services/public/settings.sas` file to get the DC library (and other) settings.  To avoid these API calls (which will speed up the app) we can simply move this code to the autoexec.  Steps as follows:

First, open the `$(appLoc)/services/settings.sas` file in SAS Studio, and copy the code.

Then, open SASEnvironment Manager, select Contexts, View Compute Contexts, and open the context we created earlier.

Switch to the Advanced tab and paste in the SAS code copied from SAS Studio above.

It will look similar to:

```
%let DC_LIBREF=DCDBVIYA;
%let DC_ADMIN_GROUP={{YOUR DC ADMIN GROUP}};
%let DC_STAGING_AREA={{YOUR DEDICATED FILE SYSTEM DRIVE}};
libname &dc_libref {{YOUR DC DATABASE}};
```

To explain each of these lines:

* `DC_LIBREF` can be any valid 8 character libref.
* `DC_ADMIN_GROUP` is the name of the group which will have unrestricted access to Data Controller
* `DC_STAGING_AREA` should point to the location on the filesystem where the staging files and logs are be stored
* The final libname statement can also be configured to point at a database instead of a BASE engine directory (contact us for DDL)

If you have additional libraries that you would like to use in Data Controller, they should also be defined here.

## Redeployment

To update DC, just deploy it as a fresh instance, then move the new config across, as follows:

1.  Do a full deploy to a completely new location
2.  Copy the contents of the old `$(appLoc)/services/settings.sas` file to the new SAS Folder location
3.  Delete the new physical directory (just created) as it is now replaced with the old one (per step 2)
4.  Either delete or rename the old SAS Folder location (appLoc), and rename the new SAS Folder location to equal the old one
5.  If using a dedicated web frontend, backup/rename so that the new web server location matches the old one
6.  Run any migrations relevant to the release, as defined [here](https://git.datacontroller.io/dc/dc/src/branch/main/sas/sasjs/db/migrations)

## Visual Analytics

It is possible to embed a Data Controller table within SAS Visual Analytics by simply pasting the URL.

To make the portlet more visually appealing, the Data Controller title bar can be removed by adding `?embed=true` to the URL.  When opening in a new window, the title bar will be gone.