{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Picasso Demo\n", "\n", "## Reference (Picasso):\n", "* https://wiki.openstack.org/wiki/Picasso\n", "* https://github.com/openstack/picasso/blob/master/devstack/README.md\n", "\n", "## Reference (Iron.io):\n", "* https://github.com/iron-io/functions\n", "\n", "## Prerequisite:\n", "- Vagrant\n", "- devstack\n", "\n", "Example configuration of Vagrantfile:\n", "\n", "```:Vagrantfile\n", "Vagrant.configure(\"2\") do |config|\n", " config.vm.box = \"ubuntu/xenial64\"\n", "\n", " # config.vm.box_check_update = false\n", "\n", " config.vm.network \"forwarded_port\", guest: 80, host: 8080\n", " config.vm.network \"forwarded_port\", guest: 8888, host: 18888\n", "\n", " config.vm.network \"private_network\", ip: \"192.168.33.10\"\n", "\n", " config.vm.provider \"virtualbox\" do |vb|\n", " # # Display the VirtualBox GUI when booting the machine\n", " # vb.gui = true\n", " #\n", " # # Customize the amount of memory on the VM:\n", " vb.memory = \"8192\"\n", " end\n", "end\n", "```\n", "\n", "### Install glide, dep, devstack with picasso\n", "\n", "Download devstack.\n", "\n", "```\n", "sudo add-apt-repository ppa:masterminds/glide && sudo apt-get update\n", "sudo apt install glide\n", "\n", "export GOPATH=$HOME/go\n", "export PATH=$PATH:$GOPATH/bin\n", "\n", "# To build 'dep'\n", "# (workaround the toml issue)\n", "sudo tar -C /usr/local -xzf go1.7.linux-amd64.tar.gz\n", "mkdir -p ~/go/bin\n", "go get -u github.com/golang/dep/...\n", "\n", "cd $GOPATH/src/github.com/golang/dep\n", "git checkout 8cdbc074c229c0e225a1a37a88fbadef5d988595\n", "go get github.com/golang/dep/...\n", "rm -rf /usr/local/go\n", "unet GOPATH\n", "\n", "cd ~\n", "git clone https://git.openstack.org/openstack-dev/devstack.git $DEVSTACK_DIR\n", "cd devstack\n", "cp samples/local.conf ./\n", "```\n", "\n", "As a next step, edit local.conf as follows.\n", "\n", "Note: You have to enable aodh and ceilometer to confirm alarm notification.\n", "\n", "```\n", "GIT_BASE=https://git.openstack.org\n", "\n", "HOST_IP=192.168.33.10\n", "\n", "enable_plugin aodh https://git.openstack.org/openstack/aodh\n", "enable_plugin picasso https://github.com/openstack/picasso.git\n", "\n", "CEILOMETER_BACKEND=mongodb\n", "enable_plugin ceilometer https://git.openstack.org/openstack/ceilometer\n", "\n", "# Picasso configuration\n", "PICASSO_REPO=${PICASSO_REPO:-https://github.com/openstack/picasso.git}\n", "PICASSO_BRANCH=${PICASSO_BRANCH:-master}\n", "PICASSO_DIR=${PICASSO_DIR:-${DEST}/picasso}\n", "PICASSO_PORT=${PICASSO_PORT:-10001}\n", "PICASSO_LOG_LEVEL=${PICASSO_LOG_LEVEL:-DEBUG}\n", "PICASSO_LOG_FILE=${PICASSO_LOG_FILE:-/var/log/picasso-api.log}\n", "\n", "# Picasso client configuration\n", "PICASSO_CLIENT_REPO=${PICASSO_CLIENT_REPO:-https://github.com/openstack/python-picassoclient.git}\n", "PICASSO_CLIENT_DIR=${PICASSO_CLIENT_DIR:-${DEST}/python-picassoclient}\n", "PICASSO_CLIENT_BRANCH=${PICASSO_CLIENT_BRANCH:-master}\n", "\n", "# Functions parameters\n", "FUNCTIONS_REPO=${FUNCTIONS_REPO:-https://github.com/iron-io/functions.git}\n", "FUNCTIONS_BRANCH=${FUNCTIONS_BRANCH:-master}\n", "FUNCTIONS_PORT=${FUNCTIONS_PORT:-10501}\n", "FUNCTIONS_DB=${FUNCTIONS_DBPATH:-bolt://$FUNCTIONS_DIR/devstack.functions.storage.db?bucket=funcs}\n", "FUNCTIONS_MQ=${FUNCTIONS_DBPATH:-bolt://$FUNCTIONS_DIR/devstack.functions.queue.db}\n", "FUNCTIONS_LOG_LEVEL=${FUNCTIONS_LOG_LEVEL:-DEBUG}\n", "\n", "DOCKER_OPTS=${DOCKER_OPTS:---dns 8.8.8.8 --storage-driver=overlay2 -H fd://}\n", "```\n", "\n", "Then, invoke stack.sh\n", "\n", "```\n", "# For small disk instances:\n", "sudo apt install mongodb-server\n", "sudo vi /etc/mongodb.conf\n", "----\n", "#journal = true\n", "nojournal = true\n", "----\n", "```\n", "\n", "```\n", "./stack.sh\n", "```\n", "\n", "# Issues / Workarounds\n", "\n", "## aiohttp\n", "\n", "vi /opt/stack/picasso/Dockerfile\n", "\n", "```\n", "RUN pip3 install aiohttp==1.3.0\n", "```\n", "\n", "## build error of 'functions'\n", "Revert to March/2017 version of 'functions'.\n", "\n", "vi /opt/stack/picasso/devstack/plugin.sh\n", "\n", "```\n", "function install_functions {\n", " echo_summary \"Pulling Functions sources\"\n", " git_clone $FUNCTIONS_REPO $GOPATH/src/github.com/iron-io/functions $FUNCTIONS_BRANCH\n", " (cd $GOPATH/src/github.com/iron-io/functions && git checkout 90f93706f229c90d6465be743e23b40492462831)\n", " pushd $FUNCTIONS_DIR && GOPATH=${GOPATH} make all; popd\n", "}\n", "```" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "WARNING: setting legacy OS_TENANT_NAME to support cli tools.\n" ] } ], "source": [ "source ~/devstack/openrc admin" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "openstack fn apps list" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+-------------+--------------------------------------------------+\n", "| Field | Value |\n", "+-------------+--------------------------------------------------+\n", "| name | alarm-notifier-app-89acd99a48a |\n", "| created_at | 2017-04-19 02:13:11.814701 |\n", "| updated_at | 2017-04-19 02:13:11.814715 |\n", "| project_id | 89acd99a48a0452b898b3e4f690a5b80 |\n", "| config | None |\n", "| id | 26c3911622a84e729e8df793126443da |\n", "| description | App for project 89acd99a48a0452b898b3e4f690a5b80 |\n", "+-------------+--------------------------------------------------+\n", "alarm-notifier-app-89acd99a48a\n" ] } ], "source": [ "openstack fn apps create alarm-notifier-app\n", "func_name=`openstack fn apps list | grep alarm-notifier-app | awk '{print $2}'`\n", "echo $func_name" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+-----------------+------------+\n", "| Field | Value |\n", "+-----------------+------------+\n", "| image | iron/hello |\n", "| memory | 128 |\n", "| is_public | True |\n", "| timeout | 30 |\n", "| path | /hello |\n", "| max_concurrency | 1 |\n", "| type | async |\n", "+-----------------+------------+\n" ] } ], "source": [ "openstack fn routes create $func_name /hello async iron/hello --is-public" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/usr/local/lib/python2.7/dist-packages/novaclient/client.py:278: UserWarning: The 'tenant_id' argument is deprecated in Ocata and its use may result in errors in future releases. As 'project_id' is provided, the 'tenant_id' argument will be ignored.\n", " warnings.warn(msg)\n", "+--------------------------------------+-----------------------------------------------------------------+\n", "| Property | Value |\n", "+--------------------------------------+-----------------------------------------------------------------+\n", "| OS-DCF:diskConfig | MANUAL |\n", "| OS-EXT-AZ:availability_zone | |\n", "| OS-EXT-SRV-ATTR:host | - |\n", "| OS-EXT-SRV-ATTR:hostname | test-alarms |\n", "| OS-EXT-SRV-ATTR:hypervisor_hostname | - |\n", "| OS-EXT-SRV-ATTR:instance_name | |\n", "| OS-EXT-SRV-ATTR:kernel_id | |\n", "| OS-EXT-SRV-ATTR:launch_index | 0 |\n", "| OS-EXT-SRV-ATTR:ramdisk_id | |\n", "| OS-EXT-SRV-ATTR:reservation_id | r-mx9oafnh |\n", "| OS-EXT-SRV-ATTR:root_device_name | - |\n", "| OS-EXT-SRV-ATTR:user_data | - |\n", "| OS-EXT-STS:power_state | 0 |\n", "| OS-EXT-STS:task_state | scheduling |\n", "| OS-EXT-STS:vm_state | building |\n", "| OS-SRV-USG:launched_at | - |\n", "| OS-SRV-USG:terminated_at | - |\n", "| accessIPv4 | |\n", "| accessIPv6 | |\n", "| adminPass | JQUoefbd2g8S |\n", "| config_drive | |\n", "| created | 2017-04-19T02:13:34Z |\n", "| description | - |\n", "| flavor | m1.nano (42) |\n", "| hostId | |\n", "| host_status | |\n", "| id | 49f6c81a-12ad-49bf-9199-6c9ed190cc91 |\n", "| image | cirros-0.3.5-x86_64-disk (3628bb95-0c01-44f7-ba1c-2b13199eeb62) |\n", "| key_name | - |\n", "| locked | False |\n", "| metadata | {} |\n", "| name | test_alarms |\n", "| os-extended-volumes:volumes_attached | [] |\n", "| progress | 0 |\n", "| security_groups | default |\n", "| status | BUILD |\n", "| tags | [] |\n", "| tenant_id | 89acd99a48a0452b898b3e4f690a5b80 |\n", "| updated | 2017-04-19T02:13:34Z |\n", "| user_id | 6f7eae51aaaa4a868c23e2fb736c87a4 |\n", "+--------------------------------------+-----------------------------------------------------------------+\n" ] } ], "source": [ "nova boot --image $(glance image-list | awk '/cirros-0.3.5-x86_64-disk / {print $2}') --flavor 42 test_alarms" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/usr/local/lib/python2.7/dist-packages/novaclient/client.py:278: UserWarning: The 'tenant_id' argument is deprecated in Ocata and its use may result in errors in future releases. As 'project_id' is provided, the 'tenant_id' argument will be ignored.\n", " warnings.warn(msg)\n", "+---------------------------+--------------------------------------------------+\n", "| Field | Value |\n", "+---------------------------+--------------------------------------------------+\n", "| alarm_actions | [u'http://192.168.33.10:10001/r/alarm-notifier- |\n", "| | app-89acd99a48a/hello'] |\n", "| alarm_id | 268618b5-4b6f-4141-8124-0b4a8c726b6d |\n", "| comparison_operator | gt |\n", "| description | instance running hot |\n", "| enabled | True |\n", "| evaluation_periods | 1 |\n", "| exclude_outliers | False |\n", "| insufficient_data_actions | [] |\n", "| meter_name | cpu_util |\n", "| name | cpu_high |\n", "| ok_actions | [] |\n", "| period | 600 |\n", "| project_id | 89acd99a48a0452b898b3e4f690a5b80 |\n", "| query | resource_id = 49f6c81a-12ad- |\n", "| | 49bf-9199-6c9ed190cc91 |\n", "| repeat_actions | False |\n", "| severity | low |\n", "| state | insufficient data |\n", "| state_timestamp | 2017-04-19T02:15:12.240495 |\n", "| statistic | max |\n", "| threshold | 20.0 |\n", "| time_constraints | [] |\n", "| timestamp | 2017-04-19T02:15:12.240495 |\n", "| type | threshold |\n", "| user_id | 6f7eae51aaaa4a868c23e2fb736c87a4 |\n", "+---------------------------+--------------------------------------------------+\n" ] } ], "source": [ "aodh alarm create \\\n", " --type threshold \\\n", " --name cpu_high \\\n", " --description 'instance running hot' \\\n", " --meter-name cpu_util \\\n", " --threshold 20.0 \\\n", " --comparison-operator gt \\\n", " --statistic max \\\n", " --period 600 \\\n", " --evaluation-periods 1 \\\n", " --alarm-action $(openstack fn routes expose-url $func_name /hello) \\\n", " --query resource_id=$(nova list | grep test_alarms | awk '{print $2}')" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Place a load on the instance\n", "\n", "As a first step, log in to the instance.\n", "\n", "Then, invoke dd command so that aodh alarm is going to be fired.\n", "\n", "```\n", "openstack security group rule create default --protocol icmp --remote-ip 0.0.0.0/0\n", "openstack security group rule create default --protocol tcp --dst-port 22:22 --remote-ip 0.0.0.0/0\n", "\n", "ns_rq=`ip netns show | grep qrouter`\n", "sudo ip netns exec $ns_rq bash\n", "ssh cirros@10.0.0.6\n", "dd if=/dev/zero of=/dev/null\n", "```" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+-------------------+-------------------+------------------+-------------------+\n", "| alarm_id | timestamp | type | detail |\n", "+-------------------+-------------------+------------------+-------------------+\n", "| 268618b5-4b6f-414 | 2017-04-19T02:30: | state transition | {\"transition_reas |\n", "| 1-8124-0b4a8c726b | 16.202627 | | on\": \"Transition |\n", "| 6d | | | to alarm due to 1 |\n", "| | | | samples outside |\n", "| | | | threshold, most |\n", "| | | | recent: |\n", "| | | | 38.3480281761\", |\n", "| | | | \"state\": \"alarm\"} |\n", "| 268618b5-4b6f-414 | 2017-04-19T02:15: | creation | {\"alarm_actions\": |\n", "| 1-8124-0b4a8c726b | 12.240495 | | [\"http://192.168. |\n", "| 6d | | | 33.10:10001/r |\n", "| | | | /alarm-notifier- |\n", "| | | | app-89acd99a48a/h |\n", "| | | | ello\"], |\n", "| | | | \"user_id\": \"6f7ea |\n", "| | | | e51aaaa4a868c23e2 |\n", "| | | | fb736c87a4\", |\n", "| | | | \"name\": |\n", "| | | | \"cpu_high\", |\n", "| | | | \"state\": |\n", "| | | | \"insufficient |\n", "| | | | data\", |\n", "| | | | \"timestamp\": \"201 |\n", "| | | | 7-04-19T02:15:12. |\n", "| | | | 240495\", |\n", "| | | | \"description\": |\n", "| | | | \"instance running |\n", "| | | | hot\", \"enabled\": |\n", "| | | | true, \"state_time |\n", "| | | | stamp\": \"2017-04- |\n", "| | | | 19T02:15:12.24049 |\n", "| | | | 5\", \"rule\": |\n", "| | | | {\"meter_name\": |\n", "| | | | \"cpu_util\", \"eval |\n", "| | | | uation_periods\": |\n", "| | | | 1, \"period\": 600, |\n", "| | | | \"statistic\": |\n", "| | | | \"max\", |\n", "| | | | \"threshold\": |\n", "| | | | 20.0, \"query\": |\n", "| | | | [{\"field\": |\n", "| | | | \"resource_id\", |\n", "| | | | \"type\": \"\", |\n", "| | | | \"value\": |\n", "| | | | \"49f6c81a-12ad-49 |\n", "| | | | bf-9199-6c9ed190c |\n", "| | | | c91\", \"op\": |\n", "| | | | \"eq\"}], \"comparis |\n", "| | | | on_operator\": |\n", "| | | | \"gt\", \"exclude_ou |\n", "| | | | tliers\": false}, |\n", "| | | | \"alarm_id\": \"2686 |\n", "| | | | 18b5-4b6f-4141-81 |\n", "| | | | 24-0b4a8c726b6d\", |\n", "| | | | \"time_constraints |\n", "| | | | \": [], \"insuffici |\n", "| | | | ent_data_actions\" |\n", "| | | | : [], |\n", "| | | | \"repeat_actions\": |\n", "| | | | false, |\n", "| | | | \"ok_actions\": [], |\n", "| | | | \"project_id\": \"89 |\n", "| | | | acd99a48a0452b898 |\n", "| | | | b3e4f690a5b80\", |\n", "| | | | \"type\": |\n", "| | | | \"threshold\", |\n", "| | | | \"severity\": |\n", "| | | | \"low\"} |\n", "+-------------------+-------------------+------------------+-------------------+\n" ] } ], "source": [ "aodh alarm-history search" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to check log of execution\n", "\n", "It seems that Iron.io does not support convenient way to check execution history so far.\n", "You can track history on syslog." ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=debug msg=\"Finding route on datastore\" action=\"server.handleRunnerRequest)-fm\" app=alarm-notifier-app-89acd99a48a call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 path=\"/hello\" route=\"/hello\"\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=debug msg=\"Got routes from datastore\" action=\"server.handleRunnerRequest)-fm\" app=alarm-notifier-app-89acd99a48a call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 route=\"/hello\" routes=1\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=info msg=\"Pushed to MQ\" call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=info msg=\"Added new task to queue\" action=\"server.handleRunnerRequest)-fm\" app=alarm-notifier-app-89acd99a48a call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 image=\"iron/hello\" route=\"/hello\"\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=info msg=Reserved call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=debug msg=\"Running task:07713835-50e5-5c9a-bd7f-ee661d0fd5c5\" call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 runner=async\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=debug msg=\"Processed task\" call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 runner=async\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=info call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 name=run.alarm-notifier-app-89acd99a48a.requests runner=async type=count value=1\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=info call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 name=run.alarm-notifier-app-89acd99a48a.waittime runner=async type=time value=0s\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=info msg=Deleted call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5\n", "Apr 19 02:30:16 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:16Z\" level=info msg=\"Task complete\" call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 runner=async\n", "Apr 19 02:30:17 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:17Z\" level=debug msg=\"Starting container execution\" call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 container=task-1492569016991038844-07713835-50e5-5c9a-bd7f-ee661d0fd5c5 runner=async\n", "Apr 19 02:30:17 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:17Z\" level=info msg=\"Hello World!\" app_name=alarm-notifier-app-89acd99a48a call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 image=\"iron/hello\" path= runner=async user_log=true\n", "Apr 19 02:30:17 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:17Z\" level=info msg=\"container status\" call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 container_error= container_finished=2017-04-19 02:30:17.340404294 +0000 UTC container_running=false container_status=exited exit_code=0 runner=async\n", "Apr 19 02:30:17 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:17Z\" level=info call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 name=run.alarm-notifier-app-89acd99a48a.succeeded runner=async type=count value=1\n", "Apr 19 02:30:17 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:17Z\" level=info call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 name=run.alarm-notifier-app-89acd99a48a.time runner=async type=time value=440.736062ms\n", "Apr 19 02:30:17 ubuntu-xenial \u001b[01;31m\u001b[Kfunctions\u001b[m\u001b[K[23573]: time=\"2017-04-19T02:30:17Z\" level=info call_id=07713835-50e5-5c9a-bd7f-ee661d0fd5c5 name=\"run.exec_time\" runner=async type=time value=440.736062ms\n" ] } ], "source": [ "grep \"Apr 19 02:30\" /var/log/syslog | grep functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to display apps / routes by using openstack CLI" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+-------+--------+----------+--------+---------+-----------------+-----------+--------+\n", "| type | path | image | memory | timeout | max_concurrency | is_public | config |\n", "+-------+--------+----------+--------+---------+-----------------+-----------+--------+\n", "| async | /hello | iron/hel | 128 | 30 | 1 | True | |\n", "| | | lo | | | | | |\n", "+-------+--------+----------+--------+---------+-----------------+-----------+--------+\n" ] } ], "source": [ "openstack fn routes list $func_name" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "+-----------------+------------+\n", "| Field | Value |\n", "+-----------------+------------+\n", "| image | iron/hello |\n", "| memory | 128 |\n", "| is_public | True |\n", "| timeout | 30 |\n", "| path | /hello |\n", "| max_concurrency | 1 |\n", "| type | async |\n", "+-----------------+------------+\n" ] } ], "source": [ "openstack fn routes show $func_name /hello" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to display apps / routes by using iron.io CLI\n", "\n", "Operators can also be accessd to iron.io via native API or fn-CLI directly.\n", "\n", "To install 'fn' command, invoke following url.\n", "```\n", "curl -LSs https://goo.gl/VZrL8t | sh\n", "```" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true }, "outputs": [], "source": [ "export API_URL=http://localhost:10501" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "alarm-notifier-app-89acd99a48a\n" ] } ], "source": [ "fn apps list" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "path\timage\tendpoint\n", "/hello\tiron/hello\n" ] } ], "source": [ "fn routes list $func_name" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\"call_id\":\"71c8630b-f2fb-5bce-b022-62e635247df8\"}\n" ] } ], "source": [ "fn routes call $func_name /hello" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Apr 19 02:35:07 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:07Z\" level=debug msg=\"Finding route on datastore\" action=\"server.handleRunnerRequest)-fm\" app=alarm-notifier-app-89acd99a48a call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K path=\"/hello\" route=\"/hello\"\n", "Apr 19 02:35:07 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:07Z\" level=debug msg=\"Got routes from datastore\" action=\"server.handleRunnerRequest)-fm\" app=alarm-notifier-app-89acd99a48a call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K route=\"/hello\" routes=1\n", "Apr 19 02:35:07 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:07Z\" level=info msg=\"Pushed to MQ\" call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K\n", "Apr 19 02:35:07 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:07Z\" level=info msg=\"Added new task to queue\" action=\"server.handleRunnerRequest)-fm\" app=alarm-notifier-app-89acd99a48a call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K image=\"iron/hello\" route=\"/hello\"\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info msg=Reserved call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=debug msg=\"Running task:\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K\" call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K runner=async\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=debug msg=\"Processed task\" call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K runner=async\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K name=run.alarm-notifier-app-89acd99a48a.requests runner=async type=count value=1\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K name=run.alarm-notifier-app-89acd99a48a.waittime runner=async type=time value=0s\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info msg=Deleted call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info msg=\"Task complete\" call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K runner=async\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=debug msg=\"Starting container execution\" call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K container=task-1492569308306242597-\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K runner=async\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info msg=\"Hello World!\" app_name=alarm-notifier-app-89acd99a48a call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K image=\"iron/hello\" path= runner=async user_log=true\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info msg=\"container status\" call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K container_error= container_finished=2017-04-19 02:35:08.556707421 +0000 UTC container_running=false container_status=exited exit_code=0 runner=async\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K name=run.alarm-notifier-app-89acd99a48a.succeeded runner=async type=count value=1\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K name=run.alarm-notifier-app-89acd99a48a.time runner=async type=time value=334.906475ms\n", "Apr 19 02:35:08 ubuntu-xenial functions[23573]: time=\"2017-04-19T02:35:08Z\" level=info call_id=\u001b[01;31m\u001b[K71c8630b-f2fb-5bce-b022-62e635247df8\u001b[m\u001b[K name=\"run.exec_time\" runner=async type=time value=334.906475ms\n" ] } ], "source": [ "grep 71c8630b-f2fb-5bce-b022-62e635247df8 /var/log/syslog " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to create functions\n", "\n", "```\n", "export DOCKER_HOST=tcp://localhost:2375\n", "\n", "mkdir ~/picasso-func ; cd ~/picasso-func\n", "vi func.go\n", "```\n", "\n", "func.go:\n", "```\n", "package main\n", "\n", "import (\n", " \"encoding/json\"\n", " \"fmt\"\n", " \"os\"\n", ")\n", "\n", "type Person struct {\n", " Name string\n", "}\n", "\n", "func main() {\n", " p := &Person{Name: \"World\"}\n", " json.NewDecoder(os.Stdin).Decode(p)\n", " fmt.Printf(\"Hello %v!\", p.Name)\n", "}\n", "```\n", "\n", "```\n", "fn init testuser/hello\n", "fn build\n", "fn run\n", "fn build && fn push\n", "fn apps create myapp\n", "fn routes create myapp /hello\n", "```" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "REPOSITORY TAG IMAGE ID CREATED SIZE\n", "testuser/hello 0.0.1 d2a63df5a52d 5 minutes ago 12.6 MB\n", "picasso-api latest f8aa15239468 2 hours ago 791 MB\n", " 60be38a5d6e7 20 hours ago 791 MB\n", " dbf4f0595bb5 24 hours ago 791 MB\n", " 42a97c056272 26 hours ago 791 MB\n", " d719aa45609a 26 hours ago 791 MB\n", "python 3.5 4e5ed9f6613e 8 days ago 687 MB\n", "iron/go dev 3d25645a73f8 2 weeks ago 857 MB\n", "iron/hello latest f4dd2a73dac8 4 months ago 12.1 MB\n", "iron/go latest c05f82fa066a 12 months ago 10.5 MB\n" ] } ], "source": [ "export DOCKER_HOST=tcp://localhost:2375\n", "docker images" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello World!" ] } ], "source": [ "curl $API_URL/r/myapp/hello" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "alarm-notifier-app-5811d3471a5\n", "alarm-notifier-app-db507b128d5\n", "myapp\n" ] } ], "source": [ "fn apps list" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "path\timage\tendpoint\n", "/hello\ttestuser/hello:0.0.1\n" ] } ], "source": [ "fn routes list myapp" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Bash", "language": "bash", "name": "bash" }, "language_info": { "codemirror_mode": "shell", "file_extension": ".sh", "mimetype": "text/x-sh", "name": "bash" } }, "nbformat": 4, "nbformat_minor": 2 }