You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/03/30 14:39:41 UTC
[5/5] incubator-ariatosca git commit:
ARIA-86-Create-a-basic-Hello-World-blueprint-example
ARIA-86-Create-a-basic-Hello-World-blueprint-example
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/1f708484
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1f708484
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1f708484
Branch: refs/heads/ARIA-86-Create-a-basic-Hello-World-blueprint-example
Commit: 1f7084848d2b903fa02827f6834eac51c05cb34e
Parents: 4400e30
Author: max-orlov <ma...@gigaspaces.com>
Authored: Thu Mar 30 17:29:17 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Thu Mar 30 17:37:45 2017 +0300
----------------------------------------------------------------------
examples/hello-world/helloworld.yaml | 33 ++++++++++++++++
examples/hello-world/images/aria-logo.png | Bin 0 -> 23601 bytes
examples/hello-world/index.html | 14 +++++++
examples/hello-world/scripts/configure.sh | 23 +++++++++++
examples/hello-world/scripts/start.sh | 52 +++++++++++++++++++++++++
examples/hello-world/scripts/stop.sh | 15 +++++++
6 files changed, 137 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f708484/examples/hello-world/helloworld.yaml
----------------------------------------------------------------------
diff --git a/examples/hello-world/helloworld.yaml b/examples/hello-world/helloworld.yaml
new file mode 100644
index 0000000..73b6bc0
--- /dev/null
+++ b/examples/hello-world/helloworld.yaml
@@ -0,0 +1,33 @@
+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
+ interfaces:
+ Standard:
+ configure: {}
+ start: {}
+ stop: {}
+
+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
+
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f708484/examples/hello-world/images/aria-logo.png
----------------------------------------------------------------------
diff --git a/examples/hello-world/images/aria-logo.png b/examples/hello-world/images/aria-logo.png
new file mode 100644
index 0000000..3505844
Binary files /dev/null and b/examples/hello-world/images/aria-logo.png differ
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f708484/examples/hello-world/index.html
----------------------------------------------------------------------
diff --git a/examples/hello-world/index.html b/examples/hello-world/index.html
new file mode 100644
index 0000000..dd3dd58
--- /dev/null
+++ b/examples/hello-world/index.html
@@ -0,0 +1,14 @@
+<html>
+ <header>
+ <title>Cloudify 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>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f708484/examples/hello-world/scripts/configure.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/configure.sh b/examples/hello-world/scripts/configure.sh
new file mode 100755
index 0000000..b55ec17
--- /dev/null
+++ b/examples/hello-world/scripts/configure.sh
@@ -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}
+
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f708484/examples/hello-world/scripts/start.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/start.sh b/examples/hello-world/scripts/start.sh
new file mode 100755
index 0000000..96298c5
--- /dev/null
+++ b/examples/hello-world/scripts/start.sh
@@ -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
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f708484/examples/hello-world/scripts/stop.sh
----------------------------------------------------------------------
diff --git a/examples/hello-world/scripts/stop.sh b/examples/hello-world/scripts/stop.sh
new file mode 100755
index 0000000..5461caf
--- /dev/null
+++ b/examples/hello-world/scripts/stop.sh
@@ -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}