Skip to content

Commit

Permalink
Added Viz lab and automation
Browse files Browse the repository at this point in the history
Added automated Viz setup - alpha
Added images for Lab 6 instructions
Added images for streaming lite labs
Change Lab 6 from Hue to CDP Data Visualization
Enabled unauthenticated app access. Added viz app status / health check.
Fixed a typo ("yum" -> "git")
Fixing Kudu timestamp column issue
Merging addional images for streaming lite workshop from zBrainiac/edge2ai-workshop
Merging streaming_flink and streaming_lite content from zBrainiac/edge2ai-workshop
Modified source topic name from iot_enriched to iot (for lite labs)
Resolving conflicts with upstream
Typo fix
Update README.adoc
Update streaming_lite.adoc
Updated Lab 6 instructions for CDV
Updated Lab 7 instructions for lite workshop
Updated images for Lab 7 instructions
Updated web forms to improve registration process, fixed small issue in cdsw setup script.

"This commit does not contain secrets"
  • Loading branch information
balazsgaspar authored and asdaraujo committed Oct 27, 2021
1 parent fa9a1cc commit ba2f90e
Show file tree
Hide file tree
Showing 40 changed files with 1,651 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
.idea/
__pycache__/
.vscode/
edge2ai.code-workspace
Binary file added images/FLINK_running_jobs_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/add_ConsumeMQTT_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/add_updateattribute_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/additional_controller_services_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/create_pgroup_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/flink_ssl_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/from_kafka_to_kudu_flow_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/hue_timestamp_fixed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/hue_timestamp_issue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/kafka_success_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/kudu_success_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/publishKafka_flow_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ssb-sql-results-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/table_select_lite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_add_expression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_clone_field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_connection_explorer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_connection_explorer_table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_create_dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_dashboard_add_dimensions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_dashboard_add_measures.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_dashboard_auto_refresh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_dashboard_view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_new_connection_advanced.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_new_connection_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/viz_new_dashboard.png
Binary file added images/viz_new_dataset.png
Binary file added images/viz_save_dataset.png
115 changes: 115 additions & 0 deletions sensor_enhanced.avsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"type": "record",
"name": "SensorReading",
"namespace": "com.cloudera.example",
"doc": "This is a sample sensor reading",
"fields": [
{
"name": "sensor_id",
"doc": "Sensor identification number.",
"type": "int"
},
{
"name": "sensor_ts",
"doc": "Timestamp of the collected readings.",
"type": "long"
},
{
"name": "is_healthy",
"doc": "Flag indicating health (healthy == 1)",
"type": "int"
},
{
"name": "response",
"doc": "response record",
"type": {
"type": "record",
"name": "CDSWResponse",
"namespace": "com.cloudera.example",
"doc": "This is a CDSW Model response",
"fields": [
{
"name": "result",
"doc": "Result",
"type": "int"
}
]
}
},
{
"name": "sensor_0",
"doc": "Reading #0.",
"type": "int"
},
{
"name": "sensor_1",
"doc": "Reading #1.",
"type": "int"
},
{
"name": "sensor_2",
"doc": "Reading #2.",
"type": "int"
},
{
"name": "sensor_3",
"doc": "Reading #3.",
"type": "int"
},
{
"name": "sensor_4",
"doc": "Reading #4.",
"type": "int"
},
{
"name": "sensor_5",
"doc": "Reading #5.",
"type": "int"
},
{
"name": "sensor_6",
"doc": "Reading #6.",
"type": "int"
},
{
"name": "sensor_7",
"doc": "Reading #7.",
"type": "int"
},
{
"name": "sensor_8",
"doc": "Reading #8.",
"type": "int"
},
{
"name": "sensor_9",
"doc": "Reading #9.",
"type": "int"
},
{
"name": "sensor_10",
"doc": "Reading #10.",
"type": "int"
},
{
"name": "sensor_11",
"doc": "Reading #11.",
"type": "int"
},
{
"name": "city",
"doc": "closest city",
"type": "string"
},
{
"name": "lat",
"doc": "geo location",
"type": "double"
},
{
"name": "lon",
"doc": "geo location",
"type": "double"
}
]
}
5 changes: 3 additions & 2 deletions setup/terraform/check-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fi
NAMESPACE=$1
load_env $NAMESPACE

printf "%-30s %-30s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %s\n" "instance" "ip address" "WEB" "CM" "CEM" "NIFI" "NREG" "SREG" "SMM" "HUE" "CDSW" "Model Status"
printf "%-30s %-20s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-14s %s\n" "instance" "ip address" "WEB" "CM" "CEM" "NIFI" "NREG" "SREG" "SMM" "HUE" "CDSW" "Model Status" "Viz Status"
ensure_tf_json_file
if [ -s $TF_JSON_FILE ]; then
cat $TF_JSON_FILE | \
Expand All @@ -50,7 +50,8 @@ if [ -s $TF_JSON_FILE ]; then
(("${CURL[@]}" http://$host:8888/ ; "${CURL[@]}" https://$host:8889/) 2>/dev/null | grep "<title>Hue" > /dev/null 2>&1 && echo Ok) > .curl.hue.$$ &
(("${CURL[@]}" http://cdsw.$ip.nip.io/ || "${CURL[@]}" https://cdsw.$ip.nip.io/) 2>/dev/null | egrep "(Cloudera Machine Learning|Cloudera Data Science Workbench)" > /dev/null 2>&1 && echo Ok) > .curl.cml.$$ &
(get_model_status $ip) > .curl.model.$$ &
("${CURL[@]}" http://viz.cdsw.$ip.nip.io/arc/adminapi/users 2>/dev/null | grep 'user' > /dev/null 2>&1 && echo running) > .curl.viz.$$ &
wait
printf "%-30s %-30s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %s\n" "$instance" "$ip" "$(cat .curl.web.$$)" "$(cat .curl.cm.$$)" "$(cat .curl.cem.$$)" "$(cat .curl.nifi.$$)" "$(cat .curl.nifireg.$$)" "$(cat .curl.schreg.$$)" "$(cat .curl.smm.$$)" "$(cat .curl.hue.$$)" "$(cat .curl.cml.$$)" "$(cat .curl.model.$$)"
printf "%-30s %-20s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-14s %s\n" "$instance" "$ip" "$(cat .curl.web.$$)" "$(cat .curl.cm.$$)" "$(cat .curl.cem.$$)" "$(cat .curl.nifi.$$)" "$(cat .curl.nifireg.$$)" "$(cat .curl.schreg.$$)" "$(cat .curl.smm.$$)" "$(cat .curl.hue.$$)" "$(cat .curl.cml.$$)" "$(cat .curl.model.$$)" "$(cat .curl.viz.$$)"
done | sort -t\[ -k1,1r -k2,2n
fi
98 changes: 90 additions & 8 deletions setup/terraform/resources/cdsw_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
else:
print('Waiting for CDSW to be ready... (connection timed out)')
time.sleep(10)

print('# Authenticate')
r = s.post(CDSW_API + '/authenticate', json={'login': USERNAME, 'password': PASSWORD})
s.headers.update({'Authorization': 'Bearer ' + r.json()['auth_token']})
Expand All @@ -71,8 +71,8 @@
models = [m for m in r.json() if m['name'] == model_name]
if models and models[0]['latestModelDeployment']['status'] == 'deployed':
print('Model is already deployed!! Skipping.')
exit(0)

#exit(0)
print('# Add engine')
r = s.post(CDSW_API + '/site/engine-profiles', json={'cpu': 1, 'memory': 4})
engine_id = r.json()['id']
Expand All @@ -99,11 +99,11 @@

print('# Upload setup script')
setup_script = """!pip3 install --upgrade pip scikit-learn
!HADOOP_USER_NAME=hdfs hdfs dfs -mkdir /user/$HADOOP_USER_NAME
!HADOOP_USER_NAME=hdfs hdfs dfs -chown $HADOOP_USER_NAME:$HADOOP_USER_NAME /user/$HADOOP_USER_NAME
!hdfs dfs -put data/historical_iot.txt /user/$HADOOP_USER_NAME
!hdfs dfs -ls -R /user/$HADOOP_USER_NAME
"""
!HADOOP_USER_NAME=hdfs hdfs dfs -mkdir /user/$HADOOP_USER_NAME
!HADOOP_USER_NAME=hdfs hdfs dfs -chown $HADOOP_USER_NAME:$HADOOP_USER_NAME /user/$HADOOP_USER_NAME
!hdfs dfs -put data/historical_iot.txt /user/$HADOOP_USER_NAME
!hdfs dfs -ls -R /user/$HADOOP_USER_NAME
"""
r = s.put(CDSW_API + '/projects/admin/edge2ai-workshop/files/setup_workshop.py', files={'name': setup_script})

print('# Upload model')
Expand Down Expand Up @@ -174,6 +174,71 @@
model_id = r.json()['id']
print('Model ID: %s' % (model_id,))

# ================================================================================

# See https://docs.cloudera.com/cdsw/latest/analytical-apps/topics/cdsw-application-limitations.html

print('# Allow applications to be configured with unauthenticated access')
r = s.patch(CDSW_API + '/site/config', json={"allow_unauthenticated_access_to_app": True})
print('Set unauthenticated access flag to: %s'% (r.json()["allow_unauthenticated_access_to_app"],))

print('# Add project for Data Visualization server')
project_name = 'viz'
viz_project_id = None
r = s.get(CDSW_API + '/users/admin/projects')
for project in r.json():
if project['name'] == project_name:
viz_project_id = project['id']
break
if not viz_project_id:
r = s.post(CDSW_API + '/users/admin/projects', json={'template': 'blank',
'project_visibility': 'private',
'name': project_name})
viz_project_id = r.json()['id']
print('Viz project ID: %s'% (viz_project_id,))

print('# Add custom engine for Data Visualization server')
params = {
"engineImage": {
"description": "dataviz-623",
"repository": "docker.repository.cloudera.com/cloudera/cdv/cdswdataviz",
"tag": "6.2.3-b18"}
}
r = s.post(CDSW_API + '/engine-images', json=params)
engine_image_id = r.json()['id']
print('Engine Image ID: %s'% (engine_image_id,))

print('# Set new engine image as default for the viz project')
r = s.patch(CDSW_API + '/projects/admin/viz/engine-images',
json={'engineImageId': engine_image_id})
r = s.get(CDSW_API + '/projects/admin/viz/engine-images')
project_engine_image_id = r.json()['id']
print('Project image default engine Image ID set to: %s'% (project_engine_image_id))

print('# Create application with Data Visualization server')
application_name = 'viz'

params = {
'bypass_authentication': True,
'cpu': 1,
'environment': {},
'description': 'viz server app',
'kernel': 'python3',
'memory': 2,
'name': 'viz-server',
'nvidia_gpu': 0,
'script': '/opt/vizapps/tools/arcviz/startup_app.py',
'subdomain': 'viz',
'type': 'manual'
}

r = s.post(CDSW_API + '/projects/admin/viz/applications', json=params)
r = s.get(CDSW_API + '/projects/admin/viz/applications')
r.json()


# ================================================================================

while True:
r = s.post(CDSW_ALTUS_API + '/models/list-models', json={
'project': str(project_id),
Expand All @@ -198,6 +263,23 @@
elif build_status == 'failed' or deployment_status == 'failed':
raise RuntimeError('Model deployment failed')
time.sleep(10)

while True:
r = s.get(CDSW_API + '/projects/admin/viz/applications')
app_status = r.json()[0]['status']
print('Data Visualization app status: %s' % (app_status))
if app_status == 'running':
print('# Viz server app is running. CDSW setup complete!')
break
elif build_status == 'stopped':
# Additional error handling - if the app exists and is stopped, start it?
break
elif build_status == 'failed':
raise RuntimeError('Application deployment failed')
time.sleep(10)

# Connect to Viz App API, validate status

except Exception as e:
if r:
print(r.text)
Expand Down
1 change: 1 addition & 0 deletions setup/terraform/resources/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ function get_service_urls() {
fi
if [[ ${HAS_CDSW:-0} == 1 ]]; then
echo "CDSW=${protocol}://cdsw.{ip_address}.nip.io/"
echo "CDP Data Visualization=${protocol}://viz.cdsw.{ip_address}.nip.io/"
fi
) | sort
) | tr "\n" "," | sed 's/,$//'
Expand Down
4 changes: 2 additions & 2 deletions setup/terraform/web/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class LoginForm(FlaskForm):
"""Login form
"""
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
login_submit = SubmitField('Sign In')
password = PasswordField('Registration code / Password', validators=[DataRequired()])
login_submit = SubmitField('Submit')

class RegistrationForm(FlaskForm):
"""Registration form for new users
Expand Down
3 changes: 2 additions & 1 deletion setup/terraform/web/app/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
{% import 'bootstrap/wtf.html' as wtf %}

{% block app_content %}
<h1>Sign In</h1>
<h1>Register new user / Log in</h1>
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form, button_map={'login_submit': 'primary'}) }}
</div>
</div>

{% endblock %}
2 changes: 1 addition & 1 deletion setup/terraform/web/app/templates/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% import 'bootstrap/wtf.html' as wtf %}

{% block app_content %}
<h1>Register</h1>
<h1>Register new user</h1>
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form, button_map={'register_submit': 'primary'}) }}
Expand Down
Loading

0 comments on commit ba2f90e

Please sign in to comment.