Remove the producer user

Change-Id: I1011a946dc0cf7191a5207eafc478511f5aedece
This commit is contained in:
Christian Berendt 2015-04-01 05:22:25 +02:00
parent 3d9df2977b
commit 6e278ec95a
11 changed files with 196 additions and 429 deletions

View File

@ -1,10 +0,0 @@
[DEFAULT]
database_url = mysql://faafo:secretsecret@127.0.0.1:3306/faafo
endpoint_url = http://127.0.0.1:5000
transport_url = rabbit://faafo:secretsecret@localhost:5672/
verbose = True
[glance_store]
default_store = file
filesystem_store_datadir = /home/vagrant

View File

@ -3,12 +3,5 @@
with_items: with_items:
- rabbitmq-server - rabbitmq-server
- service: name=rabbitmq-server state=started enabled=yes - service: name=rabbitmq-server state=started enabled=yes
- rabbitmq_user: user=faafo
password=secretsecret
vhost=/
configure_priv=.*
read_priv=.*
write_priv=.*
state=present
- rabbitmq_plugin: names=rabbitmq_management state=enabled - rabbitmq_plugin: names=rabbitmq_management state=enabled
- service: name=rabbitmq-server state=restarted - service: name=rabbitmq-server state=restarted

View File

@ -59,11 +59,10 @@ the application itself.
$ pip install -r requirements.txt $ pip install -r requirements.txt
$ python setup.py install $ python setup.py install
Open a new screen or tmux session. Aftwards run the api, worker, and producer Open a new screen or tmux session. Aftwards run the api and worker
services in the foreground, each service in a separate window. services in the foreground, each service in a separate window.
.. code:: .. code::
$ source .venv/bin/activate; faafo-api $ source .venv/bin/activate; faafo-api
$ source .venv/bin/activate; faafo-worker $ source .venv/bin/activate; faafo-worker
$ source .venv/bin/activate; faafo-producer

View File

@ -14,65 +14,11 @@
database_url = sqlite:////tmp/sqlite.db database_url = sqlite:////tmp/sqlite.db
# #
# From faafo.producer # From faafo.worker
# #
# Generate one set of tasks and exit. (boolean value)
#one_shot = false
# The maximum height of the generate image. (integer value)
#max_height = 1024
# The maximum width of the generated image. (integer value)
#max_width = 1024
# The maximum value for the parameter 'xa'. (floating point value)
#max_xa = -4.0
# The maximum value for the parameter 'xb'. (floating point value)
#max_xb = 4.0
# The maximum value for the parameter 'ya'. (floating point value)
#max_ya = -3
# The maximum value for the parameter 'yb'. (floating point value)
#max_yb = 3
# The maximum number of iterations. (integer value)
#max_iterations = 512
# The minimum height of the generate image. (integer value)
#min_height = 256
# The minimum width of the generated image. (integer value)
#min_width = 256
# The minimum value for the parameter 'xa'. (floating point value)
#min_xa = -1.0
# The minimum value for the parameter 'xb'. (floating point value)
#min_xb = 1.0
# The minimum value for the parameter 'ya'. (floating point value)
#min_ya = -0.5
# The minimum value for the parameter 'yb'. (floating point value)
#min_yb = 0.5
# The minimum number of iterations. (integer value)
#min_iterations = 128
# The minimum number of generated tasks. (integer value)
#min_tasks = 1
# The maximum number of generated tasks. (integer value)
#max_tasks = 10
# Interval in seconds. (integer value)
#interval = 10
# API connection URL (string value) # API connection URL (string value)
#endpoint_url = http://localhost:5000 endpoint_url = http://localhost:5000
# #
# From oslo.log # From oslo.log
@ -84,7 +30,7 @@ database_url = sqlite:////tmp/sqlite.db
# Print more verbose output (set logging level to INFO instead of # Print more verbose output (set logging level to INFO instead of
# default WARNING level). (boolean value) # default WARNING level). (boolean value)
#verbose = false verbose = true
# The name of a logging configuration file. This file is appended to # The name of a logging configuration file. This file is appended to
# any existing logging configuration files. For details about logging # any existing logging configuration files. For details about logging
@ -215,7 +161,7 @@ database_url = sqlite:////tmp/sqlite.db
# A URL representing the messaging driver to use and its full # A URL representing the messaging driver to use and its full
# configuration. If not set, we fall back to the rpc_backend option # configuration. If not set, we fall back to the rpc_backend option
# and driver specific configuration. (string value) # and driver specific configuration. (string value)
#transport_url = <None> transport_url = rabbit://guest:guest@localhost:5672/
# The messaging driver to use, defaults to rabbit. Other drivers # The messaging driver to use, defaults to rabbit. Other drivers
# include qpid and zmq. (string value) # include qpid and zmq. (string value)
@ -239,7 +185,7 @@ stores = file
# Default scheme to use to store image data. The scheme must be # Default scheme to use to store image data. The scheme must be
# registered by one of the stores defined by the 'stores' config # registered by one of the stores defined by the 'stores' config
# option. (string value) # option. (string value)
#default_store = file default_store = file
# Minimum interval seconds to execute updating dynamic storage # Minimum interval seconds to execute updating dynamic storage
# capabilities based on backend status then. It's not a periodic # capabilities based on backend status then. It's not a periodic
@ -253,6 +199,52 @@ stores = file
# From glance.store # From glance.store
# #
# Directory to which the Filesystem backend store writes images.
# (string value)
# Deprecated group/name - [DEFAULT]/filesystem_store_datadir
filesystem_store_datadir = /tmp
# List of directories and its priorities to which the Filesystem
# backend store writes images. (multi valued)
# Deprecated group/name - [DEFAULT]/filesystem_store_datadirs
#filesystem_store_datadirs =
# The path to a file which contains the metadata to be returned with
# any location associated with this store. The file must contain a
# valid JSON object. The object should contain the keys 'id' and
# 'mountpoint'. The value for both keys should be 'string'. (string
# value)
# Deprecated group/name - [DEFAULT]/filesystem_store_metadata_file
#filesystem_store_metadata_file = <None>
# The required permission for created image file. In this way the user
# other service used, e.g. Nova, who consumes the image could be the
# exclusive member of the group that owns the files created. Assigning
# it less then or equal to zero means don't change the default
# permission of the file. This value will be decoded as an octal
# digit. (integer value)
# Deprecated group/name - [DEFAULT]/filesystem_store_file_perm
#filesystem_store_file_perm = 0
# RADOS images will be chunked into objects of this size (in
# megabytes). For best performance, this should be a power of two.
# (integer value)
#rbd_store_chunk_size = 8
# RADOS pool in which images are stored. (string value)
#rbd_store_pool = images
# RADOS user to authenticate as (only applicable if using Cephx. If
# <None>, a default will be chosen based on the client. section in
# rbd_store_ceph_conf) (string value)
#rbd_store_user = <None>
# Ceph configuration file path. If <None>, librados will locate the
# default config. If using cephx authentication, this file should
# include a reference to the right keyring in a client.<USER> section
# (string value)
#rbd_store_ceph_conf = /etc/ceph/ceph.conf
# The host where the S3 server is listening. (string value) # The host where the S3 server is listening. (string value)
#s3_store_host = <None> #s3_store_host = <None>
@ -290,24 +282,15 @@ stores = file
# (integer value) # (integer value)
#s3_store_thread_pools = 10 #s3_store_thread_pools = 10
# RADOS images will be chunked into objects of this size (in # Images will be chunked into objects of this size (in megabytes). For
# megabytes). For best performance, this should be a power of two. # best performance, this should be a power of two. (integer value)
# (integer value) #sheepdog_store_chunk_size = 64
#rbd_store_chunk_size = 8
# RADOS pool in which images are stored. (string value) # Port of sheep daemon. (integer value)
#rbd_store_pool = images #sheepdog_store_port = 7000
# RADOS user to authenticate as (only applicable if using Cephx. If # IP address of sheep daemon. (string value)
# <None>, a default will be chosen based on the client. section in #sheepdog_store_address = localhost
# rbd_store_ceph_conf) (string value)
#rbd_store_user = <None>
# Ceph configuration file path. If <None>, librados will locate the
# default config. If using cephx authentication, this file should
# include a reference to the right keyring in a client.<USER> section
# (string value)
#rbd_store_ceph_conf = /etc/ceph/ceph.conf
# ESX/ESXi or vCenter Server target system. The server value can be an # ESX/ESXi or vCenter Server target system. The server value can be an
# IP address or a DNS name. (string value) # IP address or a DNS name. (string value)
@ -364,6 +347,28 @@ stores = file
# valued) # valued)
#vmware_datastores = #vmware_datastores =
# Info to match when looking for cinder in the service catalog. Format
# is : separated values of the form:
# <service_type>:<service_name>:<endpoint_type> (string value)
#cinder_catalog_info = volume:cinder:publicURL
# Override service catalog lookup with template for cinder endpoint
# e.g. http://localhost:8776/v1/%(project_id)s (string value)
#cinder_endpoint_template = <None>
# Region name of this node (string value)
#os_region_name = <None>
# Location of ca certicates file to use for cinder client requests.
# (string value)
#cinder_ca_certificates_file = <None>
# Number of cinderclient retries on failed http calls (integer value)
#cinder_http_retries = 3
# Allow to perform insecure SSL requests to cinder (boolean value)
#cinder_api_insecure = false
# Version of the authentication service to use. Valid versions are 2 # Version of the authentication service to use. Valid versions are 2
# for keystone and 1 for swauth and rackspace. (deprecated) (string # for keystone and 1 for swauth and rackspace. (deprecated) (string
# value) # value)
@ -462,38 +467,6 @@ stores = file
# The config file that has the swift account(s)configs. (string value) # The config file that has the swift account(s)configs. (string value)
#swift_store_config_file = <None> #swift_store_config_file = <None>
# Info to match when looking for cinder in the service catalog. Format
# is : separated values of the form:
# <service_type>:<service_name>:<endpoint_type> (string value)
#cinder_catalog_info = volume:cinder:publicURL
# Override service catalog lookup with template for cinder endpoint
# e.g. http://localhost:8776/v1/%(project_id)s (string value)
#cinder_endpoint_template = <None>
# Region name of this node (string value)
#os_region_name = <None>
# Location of ca certicates file to use for cinder client requests.
# (string value)
#cinder_ca_certificates_file = <None>
# Number of cinderclient retries on failed http calls (integer value)
#cinder_http_retries = 3
# Allow to perform insecure SSL requests to cinder (boolean value)
#cinder_api_insecure = false
# Images will be chunked into objects of this size (in megabytes). For
# best performance, this should be a power of two. (integer value)
#sheepdog_store_chunk_size = 64
# Port of sheep daemon. (integer value)
#sheepdog_store_port = 7000
# IP address of sheep daemon. (string value)
#sheepdog_store_address = localhost
# Hostname or IP address of the instance to connect to, or a mongodb # Hostname or IP address of the instance to connect to, or a mongodb
# URI, or a list of hostnames / mongodb URIs. If host is an IPv6 # URI, or a list of hostnames / mongodb URIs. If host is an IPv6
# literal it must be enclosed in '[' and ']' characters following the # literal it must be enclosed in '[' and ']' characters following the
@ -503,33 +476,6 @@ stores = file
# Database to use (string value) # Database to use (string value)
#mongodb_store_db = <None> #mongodb_store_db = <None>
# Directory to which the Filesystem backend store writes images.
# (string value)
# Deprecated group/name - [DEFAULT]/filesystem_store_datadir
filesystem_store_datadir = /tmp
# List of directories and its priorities to which the Filesystem
# backend store writes images. (multi valued)
# Deprecated group/name - [DEFAULT]/filesystem_store_datadirs
#filesystem_store_datadirs =
# The path to a file which contains the metadata to be returned with
# any location associated with this store. The file must contain a
# valid JSON object. The object should contain the keys 'id' and
# 'mountpoint'. The value for both keys should be 'string'. (string
# value)
# Deprecated group/name - [DEFAULT]/filesystem_store_metadata_file
#filesystem_store_metadata_file = <None>
# The required permission for created image file. In this way the user
# other service used, e.g. Nova, who consumes the image could be the
# exclusive member of the group that owns the files created. Assigning
# it less then or equal to zero means don't change the default
# permission of the file. This value will be decoded as an octal
# digit. (integer value)
# Deprecated group/name - [DEFAULT]/filesystem_store_file_perm
#filesystem_store_file_perm = 0
[matchmaker_redis] [matchmaker_redis]

View File

@ -14,63 +14,9 @@
#database_url = sqlite:////tmp/sqlite.db #database_url = sqlite:////tmp/sqlite.db
# #
# From faafo.producer # From faafo.worker
# #
# Generate one set of tasks and exit. (boolean value)
#one_shot = false
# The maximum height of the generate image. (integer value)
#max_height = 1024
# The maximum width of the generated image. (integer value)
#max_width = 1024
# The maximum value for the parameter 'xa'. (floating point value)
#max_xa = -4.0
# The maximum value for the parameter 'xb'. (floating point value)
#max_xb = 4.0
# The maximum value for the parameter 'ya'. (floating point value)
#max_ya = -3
# The maximum value for the parameter 'yb'. (floating point value)
#max_yb = 3
# The maximum number of iterations. (integer value)
#max_iterations = 512
# The minimum height of the generate image. (integer value)
#min_height = 256
# The minimum width of the generated image. (integer value)
#min_width = 256
# The minimum value for the parameter 'xa'. (floating point value)
#min_xa = -1.0
# The minimum value for the parameter 'xb'. (floating point value)
#min_xb = 1.0
# The minimum value for the parameter 'ya'. (floating point value)
#min_ya = -0.5
# The minimum value for the parameter 'yb'. (floating point value)
#min_yb = 0.5
# The minimum number of iterations. (integer value)
#min_iterations = 128
# The minimum number of generated tasks. (integer value)
#min_tasks = 1
# The maximum number of generated tasks. (integer value)
#max_tasks = 10
# Interval in seconds. (integer value)
#interval = 10
# API connection URL (string value) # API connection URL (string value)
#endpoint_url = http://localhost:5000 #endpoint_url = http://localhost:5000
@ -253,6 +199,52 @@
# From glance.store # From glance.store
# #
# Directory to which the Filesystem backend store writes images.
# (string value)
# Deprecated group/name - [DEFAULT]/filesystem_store_datadir
#filesystem_store_datadir = <None>
# List of directories and its priorities to which the Filesystem
# backend store writes images. (multi valued)
# Deprecated group/name - [DEFAULT]/filesystem_store_datadirs
#filesystem_store_datadirs =
# The path to a file which contains the metadata to be returned with
# any location associated with this store. The file must contain a
# valid JSON object. The object should contain the keys 'id' and
# 'mountpoint'. The value for both keys should be 'string'. (string
# value)
# Deprecated group/name - [DEFAULT]/filesystem_store_metadata_file
#filesystem_store_metadata_file = <None>
# The required permission for created image file. In this way the user
# other service used, e.g. Nova, who consumes the image could be the
# exclusive member of the group that owns the files created. Assigning
# it less then or equal to zero means don't change the default
# permission of the file. This value will be decoded as an octal
# digit. (integer value)
# Deprecated group/name - [DEFAULT]/filesystem_store_file_perm
#filesystem_store_file_perm = 0
# RADOS images will be chunked into objects of this size (in
# megabytes). For best performance, this should be a power of two.
# (integer value)
#rbd_store_chunk_size = 8
# RADOS pool in which images are stored. (string value)
#rbd_store_pool = images
# RADOS user to authenticate as (only applicable if using Cephx. If
# <None>, a default will be chosen based on the client. section in
# rbd_store_ceph_conf) (string value)
#rbd_store_user = <None>
# Ceph configuration file path. If <None>, librados will locate the
# default config. If using cephx authentication, this file should
# include a reference to the right keyring in a client.<USER> section
# (string value)
#rbd_store_ceph_conf = /etc/ceph/ceph.conf
# The host where the S3 server is listening. (string value) # The host where the S3 server is listening. (string value)
#s3_store_host = <None> #s3_store_host = <None>
@ -290,32 +282,15 @@
# (integer value) # (integer value)
#s3_store_thread_pools = 10 #s3_store_thread_pools = 10
# Directory to which the Filesystem backend store writes images. # Images will be chunked into objects of this size (in megabytes). For
# (string value) # best performance, this should be a power of two. (integer value)
# Deprecated group/name - [DEFAULT]/filesystem_store_datadir #sheepdog_store_chunk_size = 64
#filesystem_store_datadir = <None>
# List of directories and its priorities to which the Filesystem # Port of sheep daemon. (integer value)
# backend store writes images. (multi valued) #sheepdog_store_port = 7000
# Deprecated group/name - [DEFAULT]/filesystem_store_datadirs
#filesystem_store_datadirs =
# The path to a file which contains the metadata to be returned with # IP address of sheep daemon. (string value)
# any location associated with this store. The file must contain a #sheepdog_store_address = localhost
# valid JSON object. The object should contain the keys 'id' and
# 'mountpoint'. The value for both keys should be 'string'. (string
# value)
# Deprecated group/name - [DEFAULT]/filesystem_store_metadata_file
#filesystem_store_metadata_file = <None>
# The required permission for created image file. In this way the user
# other service used, e.g. Nova, who consumes the image could be the
# exclusive member of the group that owns the files created. Assigning
# it less then or equal to zero means don't change the default
# permission of the file. This value will be decoded as an octal
# digit. (integer value)
# Deprecated group/name - [DEFAULT]/filesystem_store_file_perm
#filesystem_store_file_perm = 0
# ESX/ESXi or vCenter Server target system. The server value can be an # ESX/ESXi or vCenter Server target system. The server value can be an
# IP address or a DNS name. (string value) # IP address or a DNS name. (string value)
@ -372,24 +347,27 @@
# valued) # valued)
#vmware_datastores = #vmware_datastores =
# Images will be chunked into objects of this size (in megabytes). For # Info to match when looking for cinder in the service catalog. Format
# best performance, this should be a power of two. (integer value) # is : separated values of the form:
#sheepdog_store_chunk_size = 64 # <service_type>:<service_name>:<endpoint_type> (string value)
#cinder_catalog_info = volume:cinder:publicURL
# Port of sheep daemon. (integer value) # Override service catalog lookup with template for cinder endpoint
#sheepdog_store_port = 7000 # e.g. http://localhost:8776/v1/%(project_id)s (string value)
#cinder_endpoint_template = <None>
# IP address of sheep daemon. (string value) # Region name of this node (string value)
#sheepdog_store_address = localhost #os_region_name = <None>
# Hostname or IP address of the instance to connect to, or a mongodb # Location of ca certicates file to use for cinder client requests.
# URI, or a list of hostnames / mongodb URIs. If host is an IPv6 # (string value)
# literal it must be enclosed in '[' and ']' characters following the #cinder_ca_certificates_file = <None>
# RFC2732 URL syntax (e.g. '[::1]' for localhost) (string value)
#mongodb_store_uri = <None>
# Database to use (string value) # Number of cinderclient retries on failed http calls (integer value)
#mongodb_store_db = <None> #cinder_http_retries = 3
# Allow to perform insecure SSL requests to cinder (boolean value)
#cinder_api_insecure = false
# Version of the authentication service to use. Valid versions are 2 # Version of the authentication service to use. Valid versions are 2
# for keystone and 1 for swauth and rackspace. (deprecated) (string # for keystone and 1 for swauth and rackspace. (deprecated) (string
@ -489,46 +467,14 @@
# The config file that has the swift account(s)configs. (string value) # The config file that has the swift account(s)configs. (string value)
#swift_store_config_file = <None> #swift_store_config_file = <None>
# Info to match when looking for cinder in the service catalog. Format # Hostname or IP address of the instance to connect to, or a mongodb
# is : separated values of the form: # URI, or a list of hostnames / mongodb URIs. If host is an IPv6
# <service_type>:<service_name>:<endpoint_type> (string value) # literal it must be enclosed in '[' and ']' characters following the
#cinder_catalog_info = volume:cinder:publicURL # RFC2732 URL syntax (e.g. '[::1]' for localhost) (string value)
#mongodb_store_uri = <None>
# Override service catalog lookup with template for cinder endpoint # Database to use (string value)
# e.g. http://localhost:8776/v1/%(project_id)s (string value) #mongodb_store_db = <None>
#cinder_endpoint_template = <None>
# Region name of this node (string value)
#os_region_name = <None>
# Location of ca certicates file to use for cinder client requests.
# (string value)
#cinder_ca_certificates_file = <None>
# Number of cinderclient retries on failed http calls (integer value)
#cinder_http_retries = 3
# Allow to perform insecure SSL requests to cinder (boolean value)
#cinder_api_insecure = false
# RADOS images will be chunked into objects of this size (in
# megabytes). For best performance, this should be a power of two.
# (integer value)
#rbd_store_chunk_size = 8
# RADOS pool in which images are stored. (string value)
#rbd_store_pool = images
# RADOS user to authenticate as (only applicable if using Cephx. If
# <None>, a default will be chosen based on the client. section in
# rbd_store_ceph_conf) (string value)
#rbd_store_user = <None>
# Ceph configuration file path. If <None>, librados will locate the
# default config. If using cephx authentication, this file should
# include a reference to the right keyring in a client.<USER> section
# (string value)
#rbd_store_ceph_conf = /etc/ceph/ceph.conf
[matchmaker_redis] [matchmaker_redis]

View File

@ -1,6 +1,6 @@
[DEFAULT] [DEFAULT]
output_file = etc/faafo.conf.sample output_file = etc/faafo.conf.sample
namespace = faafo.producer namespace = faafo.worker
namespace = faafo.api namespace = faafo.api
namespace = oslo.messaging namespace = oslo.messaging
namespace = oslo.log namespace = oslo.log

View File

@ -20,6 +20,7 @@ from flask_bootstrap import Bootstrap
import glance_store import glance_store
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log from oslo_log import log
import oslo_messaging as messaging
from faafo import version from faafo import version
@ -88,6 +89,10 @@ class Fractal(db.Model):
db.create_all() db.create_all()
manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db) manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)
transport = messaging.get_transport(CONF)
target = messaging.Target(topic='tasks')
client = messaging.RPCClient(transport, target)
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
@app.route('/index', methods=['GET']) @app.route('/index', methods=['GET'])
@ -114,8 +119,13 @@ def get_fractal(fractalid):
return response return response
def generate_fractal(**kwargs):
client.cast({}, 'process', task=kwargs['result'])
def main(): def main():
manager.create_api(Fractal, methods=['GET', 'POST', 'DELETE', 'PUT'], manager.create_api(Fractal, methods=['GET', 'POST', 'DELETE', 'PUT'],
postprocessors={'POST': [generate_fractal]},
url_prefix='/v1') url_prefix='/v1')
app.run(host=CONF.listen_address, port=CONF.bind_port) app.run(host=CONF.listen_address, port=CONF.bind_port)

View File

@ -1,141 +0,0 @@
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import json
import random
import uuid
from oslo_config import cfg
from oslo_log import log
import oslo_messaging as messaging
import requests
from faafo.openstack.common import periodic_task
from faafo.openstack.common import service
LOG = log.getLogger('faafo.producer')
CONF = cfg.CONF
producer_opts = [
cfg.BoolOpt("one-shot", default=False,
help="Generate one set of tasks and exit."),
cfg.IntOpt("max-height", default=1024,
help="The maximum height of the generate image."),
cfg.IntOpt("max-width", default=1024,
help="The maximum width of the generated image."),
cfg.FloatOpt("max-xa", default=-4.0,
help="The maximum value for the parameter 'xa'."),
cfg.FloatOpt("max-xb", default=4.0,
help="The maximum value for the parameter 'xb'."),
cfg.FloatOpt("max-ya", default=-3,
help="The maximum value for the parameter 'ya'."),
cfg.FloatOpt("max-yb", default=3,
help="The maximum value for the parameter 'yb'."),
cfg.IntOpt("max-iterations", default=512,
help="The maximum number of iterations."),
cfg.IntOpt("min-height", default=256,
help="The minimum height of the generate image."),
cfg.IntOpt("min-width", default=256,
help="The minimum width of the generated image."),
cfg.FloatOpt("min-xa", default=-1.0,
help="The minimum value for the parameter 'xa'."),
cfg.FloatOpt("min-xb", default=1.0,
help="The minimum value for the parameter 'xb'."),
cfg.FloatOpt("min-ya", default=-0.5,
help="The minimum value for the parameter 'ya'."),
cfg.FloatOpt("min-yb", default=0.5,
help="The minimum value for the parameter 'yb'."),
cfg.IntOpt("min-iterations", default=128,
help="The minimum number of iterations."),
cfg.IntOpt("min-tasks", default=1,
help="The minimum number of generated tasks."),
cfg.IntOpt("max-tasks", default=10,
help="The maximum number of generated tasks."),
cfg.IntOpt("interval", default=10, help="Interval in seconds."),
cfg.StrOpt('endpoint-url',
default='http://localhost:5000',
help='API connection URL')
]
CONF.register_opts(producer_opts)
def list_opts():
"""Entry point for oslo-config-generator."""
return [(None, copy.deepcopy(producer_opts))]
class ProducerService(service.Service, periodic_task.PeriodicTasks):
def __init__(self):
super(ProducerService, self).__init__()
self._periodic_last_run = {}
transport = messaging.get_transport(CONF)
target = messaging.Target(topic='tasks')
self._client = messaging.RPCClient(transport, target)
@periodic_task.periodic_task(spacing=CONF.interval,
run_immediately=False)
def generate_task(self, ctxt):
ctxt = {}
random.seed()
number = random.randint(CONF.min_tasks, CONF.max_tasks)
LOG.info("generating %d task(s)" % number)
for i in xrange(0, number):
task = self.get_random_task()
# NOTE(berendt): only necessary when using requests < 2.4.2
headers = {'Content-type': 'application/json',
'Accept': 'text/plain'}
requests.post("%s/v1/fractal" % CONF.endpoint_url,
json.dumps(task), headers=headers)
LOG.info("generated task: %s" % task)
result = self._client.call(ctxt, 'process', task=task)
LOG.info("task %s processed: %s" % (task['uuid'], result))
requests.put("%s/v1/fractal/%s" %
(CONF.endpoint_url, str(task['uuid'])),
json.dumps(result), headers=headers)
self.add_periodic_task(generate_task)
self.tg.add_dynamic_timer(self.periodic_tasks)
def periodic_tasks(self):
"""Tasks to be run at a periodic interval."""
return self.run_periodic_tasks(None)
@staticmethod
def get_random_task():
random.seed()
width = random.randint(CONF.min_width, CONF.max_width)
height = random.randint(CONF.min_height, CONF.max_height)
iterations = random.randint(CONF.min_iterations,
CONF.max_iterations)
xa = random.uniform(CONF.min_xa, CONF.max_xa)
xb = random.uniform(CONF.min_xb, CONF.max_xb)
ya = random.uniform(CONF.min_ya, CONF.max_ya)
yb = random.uniform(CONF.min_yb, CONF.max_yb)
task = {
'uuid': str(uuid.uuid4()),
'width': width,
'height': height,
'iterations': iterations,
'xa': xa,
'xb': xb,
'ya': ya,
'yb': yb
}
return task

View File

@ -17,7 +17,9 @@
import eventlet import eventlet
eventlet.monkey_patch() eventlet.monkey_patch()
import copy
import hashlib import hashlib
import json
import os import os
from PIL import Image from PIL import Image
import random import random
@ -29,6 +31,7 @@ import glance_store
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log from oslo_log import log
import oslo_messaging as messaging import oslo_messaging as messaging
import requests
LOG = log.getLogger('faafo.worker') LOG = log.getLogger('faafo.worker')
@ -36,6 +39,20 @@ CONF = cfg.CONF
glance_store.register_opts(CONF) glance_store.register_opts(CONF)
worker_opts = {
cfg.StrOpt('endpoint-url',
default='http://localhost:5000',
help='API connection URL')
}
CONF.register_opts(worker_opts)
def list_opts():
"""Entry point for oslo-config-generator."""
return [(None, copy.deepcopy(worker_opts))]
class JuliaSet(object): class JuliaSet(object):
def __init__(self, width, height, xa=-2.0, xb=2.0, ya=-1.5, yb=1.5, def __init__(self, width, height, xa=-2.0, xb=2.0, ya=-1.5, yb=1.5,
@ -121,6 +138,14 @@ class WorkerEndpoint(object):
'size': glance[1] 'size': glance[1]
} }
# NOTE(berendt): only necessary when using requests < 2.4.2
headers = {'Content-type': 'application/json',
'Accept': 'text/plain'}
requests.put("%s/v1/fractal/%s" %
(CONF.endpoint_url, str(task['uuid'])),
json.dumps(result), headers=headers)
return result return result

View File

@ -22,7 +22,6 @@ packages =
faafo faafo
scripts = scripts =
bin/faafo bin/faafo
bin/faafo-producer
bin/faafo-worker bin/faafo-worker
extra_files = extra_files =
faafo/api/templates/index.html faafo/api/templates/index.html
@ -38,7 +37,7 @@ console_scripts =
faafo-api = faafo.api.service:main faafo-api = faafo.api.service:main
oslo.config.opts = oslo.config.opts =
faafo.api = faafo.api.service:list_opts faafo.api = faafo.api.service:list_opts
faafo.producer = faafo.producer.service:list_opts faafo.worker = faafo.worker.service:list_opts
[build_sphinx] [build_sphinx]
source-dir = doc/source source-dir = doc/source