Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
ARIA-86-Create-a-basic-Hello-World-blueprint-example
  • Loading branch information
mxmrlv committed Mar 30, 2017
1 parent 4400e30 commit 16ae46a61b01acd2b654acc301e40cc29c683e9a
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
@@ -0,0 +1,27 @@
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0

node_types:
web_app:
derived_from: tosca.nodes.WebApplication
properties:
port:
type: integer
default: 8080

topology_template:

node_templates:
web_server:
type: tosca.nodes.WebServer

web_app:
type: web_app
properties:
port: 9090
requirements:
- host: web_server
interfaces:
Standard:
configure: scripts/configure.sh
start: scripts/start.sh
stop: scripts/stop.sh
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,14 @@
<html>
<header>
<title>ARIA Hello World</title>
</header>
<body>
<h1>Hello, World!</h1>
<p>
blueprint_id = {{ ctx.service_template.name }}<br/>
deployment_id = {{ ctx.service.name }}<br/>
node_id = {{ ctx.node.name }}
</p>
<img src="aria-logo.png">
</body>
</html>
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

TEMP_DIR="/tmp"
PYTHON_FILE_SERVER_ROOT=${TEMP_DIR}/python-simple-http-webserver
if [ -d ${PYTHON_FILE_SERVER_ROOT} ]; then
echo "Removing file server root folder ${PYTHON_FILE_SERVER_ROOT}"
rm -rf ${PYTHON_FILE_SERVER_ROOT}
fi
ctx logger info "Creating HTTP server root directory at ${PYTHON_FILE_SERVER_ROOT}"

mkdir -p ${PYTHON_FILE_SERVER_ROOT}

cd ${PYTHON_FILE_SERVER_ROOT}

index_path="index.html"
image_path="images/aria-logo.png"

ctx logger info "Downloading blueprint resources..."
ctx download-resource-and-render ${PYTHON_FILE_SERVER_ROOT}/index.html ${index_path}
ctx download-resource ${PYTHON_FILE_SERVER_ROOT}/aria-logo.png ${image_path}

@@ -0,0 +1,52 @@
#!/bin/bash

set -e

TEMP_DIR="/tmp"
PYTHON_FILE_SERVER_ROOT=${TEMP_DIR}/python-simple-http-webserver
PID_FILE="server.pid"

ctx logger info "Starting HTTP server from ${PYTHON_FILE_SERVER_ROOT}"

port=$(ctx node properties port)

cd ${PYTHON_FILE_SERVER_ROOT}
ctx logger info "Starting SimpleHTTPServer"
nohup python -m SimpleHTTPServer ${port} > /dev/null 2>&1 &
echo $! > ${PID_FILE}

ctx logger info "Waiting for server to launch on port ${port}"
url="http://localhost:${port}"

server_is_up() {
if which wget >/dev/null; then
if wget $url >/dev/null; then
return 0
fi
elif which curl >/dev/null; then
if curl $url >/dev/null; then
return 0
fi
else
ctx logger error "Both curl, wget were not found in path"
exit 1
fi
return 1
}

STARTED=false
for i in $(seq 1 15)
do
if server_is_up; then
ctx logger info "Server is up."
STARTED=true
break
else
ctx logger info "Server not up. waiting 1 second."
sleep 1
fi
done
if [ ${STARTED} = false ]; then
ctx logger error "Failed starting web server in 15 seconds."
exit 1
fi
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

TEMP_DIR="/tmp"
PYTHON_FILE_SERVER_ROOT=${TEMP_DIR}/python-simple-http-webserver
PID_FILE="server.pid"

PID=`cat ${PYTHON_FILE_SERVER_ROOT}/${PID_FILE}`

ctx logger info "Shutting down file server. pid = ${PID}"
kill -9 ${PID} || exit $?

ctx logger info "Deleting file server root directory (${PYTHON_FILE_SERVER_ROOT})"
rm -rf ${PYTHON_FILE_SERVER_ROOT}

0 comments on commit 16ae46a

Please sign in to comment.