From 6e278ec95ab1290ebf5a715d49bd961431dfb47e Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 1 Apr 2015 05:22:25 +0200 Subject: [PATCH] Remove the producer user Change-Id: I1011a946dc0cf7191a5207eafc478511f5aedece --- ansible/files/faafo.conf | 10 -- ansible/tasks/messaging.yaml | 7 - doc/source/development.rst | 3 +- etc/faafo.conf | 214 ++++++++++----------------- etc/faafo.conf.sample | 210 ++++++++++---------------- etc/oslo-config-generator/faafo.conf | 2 +- faafo/api/service.py | 10 ++ faafo/producer/__init__.py | 0 faafo/producer/service.py | 141 ------------------ faafo/worker/service.py | 25 ++++ setup.cfg | 3 +- 11 files changed, 196 insertions(+), 429 deletions(-) delete mode 100644 ansible/files/faafo.conf delete mode 100644 faafo/producer/__init__.py delete mode 100644 faafo/producer/service.py diff --git a/ansible/files/faafo.conf b/ansible/files/faafo.conf deleted file mode 100644 index 729584b..0000000 --- a/ansible/files/faafo.conf +++ /dev/null @@ -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 diff --git a/ansible/tasks/messaging.yaml b/ansible/tasks/messaging.yaml index 73f38a7..11f6910 100644 --- a/ansible/tasks/messaging.yaml +++ b/ansible/tasks/messaging.yaml @@ -3,12 +3,5 @@ with_items: - rabbitmq-server - 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 - service: name=rabbitmq-server state=restarted diff --git a/doc/source/development.rst b/doc/source/development.rst index c257c98..c8fd05a 100644 --- a/doc/source/development.rst +++ b/doc/source/development.rst @@ -59,11 +59,10 @@ the application itself. $ pip install -r requirements.txt $ 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. .. code:: $ source .venv/bin/activate; faafo-api $ source .venv/bin/activate; faafo-worker - $ source .venv/bin/activate; faafo-producer diff --git a/etc/faafo.conf b/etc/faafo.conf index fbe1a45..a06da3d 100644 --- a/etc/faafo.conf +++ b/etc/faafo.conf @@ -14,65 +14,11 @@ 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) -#endpoint_url = http://localhost:5000 +endpoint_url = http://localhost:5000 # # From oslo.log @@ -84,7 +30,7 @@ database_url = sqlite:////tmp/sqlite.db # Print more verbose output (set logging level to INFO instead of # default WARNING level). (boolean value) -#verbose = false +verbose = true # The name of a logging configuration file. This file is appended to # 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 # configuration. If not set, we fall back to the rpc_backend option # and driver specific configuration. (string value) -#transport_url = +transport_url = rabbit://guest:guest@localhost:5672/ # The messaging driver to use, defaults to rabbit. Other drivers # include qpid and zmq. (string value) @@ -239,7 +185,7 @@ stores = file # Default scheme to use to store image data. The scheme must be # registered by one of the stores defined by the 'stores' config # option. (string value) -#default_store = file +default_store = file # Minimum interval seconds to execute updating dynamic storage # capabilities based on backend status then. It's not a periodic @@ -253,6 +199,52 @@ stores = file # 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 = + +# 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 +# , a default will be chosen based on the client. section in +# rbd_store_ceph_conf) (string value) +#rbd_store_user = + +# Ceph configuration file path. If , librados will locate the +# default config. If using cephx authentication, this file should +# include a reference to the right keyring in a client. section +# (string value) +#rbd_store_ceph_conf = /etc/ceph/ceph.conf + # The host where the S3 server is listening. (string value) #s3_store_host = @@ -290,24 +282,15 @@ stores = file # (integer value) #s3_store_thread_pools = 10 -# 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 +# 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 -# RADOS pool in which images are stored. (string value) -#rbd_store_pool = images +# Port of sheep daemon. (integer value) +#sheepdog_store_port = 7000 -# RADOS user to authenticate as (only applicable if using Cephx. If -# , a default will be chosen based on the client. section in -# rbd_store_ceph_conf) (string value) -#rbd_store_user = - -# Ceph configuration file path. If , librados will locate the -# default config. If using cephx authentication, this file should -# include a reference to the right keyring in a client. section -# (string value) -#rbd_store_ceph_conf = /etc/ceph/ceph.conf +# IP address of sheep daemon. (string value) +#sheepdog_store_address = localhost # ESX/ESXi or vCenter Server target system. The server value can be an # IP address or a DNS name. (string value) @@ -364,6 +347,28 @@ stores = file # valued) #vmware_datastores = +# Info to match when looking for cinder in the service catalog. Format +# is : separated values of the form: +# :: (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 = + +# Region name of this node (string value) +#os_region_name = + +# Location of ca certicates file to use for cinder client requests. +# (string value) +#cinder_ca_certificates_file = + +# 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 # for keystone and 1 for swauth and rackspace. (deprecated) (string # value) @@ -462,38 +467,6 @@ stores = file # The config file that has the swift account(s)configs. (string value) #swift_store_config_file = -# Info to match when looking for cinder in the service catalog. Format -# is : separated values of the form: -# :: (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 = - -# Region name of this node (string value) -#os_region_name = - -# Location of ca certicates file to use for cinder client requests. -# (string value) -#cinder_ca_certificates_file = - -# 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 # URI, or a list of hostnames / mongodb URIs. If host is an IPv6 # literal it must be enclosed in '[' and ']' characters following the @@ -503,33 +476,6 @@ stores = file # Database to use (string value) #mongodb_store_db = -# 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 = - -# 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] diff --git a/etc/faafo.conf.sample b/etc/faafo.conf.sample index 5d4ff98..bc1beac 100644 --- a/etc/faafo.conf.sample +++ b/etc/faafo.conf.sample @@ -14,63 +14,9 @@ #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) #endpoint_url = http://localhost:5000 @@ -253,6 +199,52 @@ # From glance.store # +# Directory to which the Filesystem backend store writes images. +# (string value) +# Deprecated group/name - [DEFAULT]/filesystem_store_datadir +#filesystem_store_datadir = + +# 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 = + +# 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 +# , a default will be chosen based on the client. section in +# rbd_store_ceph_conf) (string value) +#rbd_store_user = + +# Ceph configuration file path. If , librados will locate the +# default config. If using cephx authentication, this file should +# include a reference to the right keyring in a client. section +# (string value) +#rbd_store_ceph_conf = /etc/ceph/ceph.conf + # The host where the S3 server is listening. (string value) #s3_store_host = @@ -290,32 +282,15 @@ # (integer value) #s3_store_thread_pools = 10 -# Directory to which the Filesystem backend store writes images. -# (string value) -# Deprecated group/name - [DEFAULT]/filesystem_store_datadir -#filesystem_store_datadir = +# 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 -# 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 = +# Port of sheep daemon. (integer value) +#sheepdog_store_port = 7000 -# 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 = - -# 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 +# IP address of sheep daemon. (string value) +#sheepdog_store_address = localhost # ESX/ESXi or vCenter Server target system. The server value can be an # IP address or a DNS name. (string value) @@ -372,24 +347,27 @@ # valued) #vmware_datastores = -# 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 +# Info to match when looking for cinder in the service catalog. Format +# is : separated values of the form: +# :: (string value) +#cinder_catalog_info = volume:cinder:publicURL -# Port of sheep daemon. (integer value) -#sheepdog_store_port = 7000 +# Override service catalog lookup with template for cinder endpoint +# e.g. http://localhost:8776/v1/%(project_id)s (string value) +#cinder_endpoint_template = -# IP address of sheep daemon. (string value) -#sheepdog_store_address = localhost +# Region name of this node (string value) +#os_region_name = -# 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 -# literal it must be enclosed in '[' and ']' characters following the -# RFC2732 URL syntax (e.g. '[::1]' for localhost) (string value) -#mongodb_store_uri = +# Location of ca certicates file to use for cinder client requests. +# (string value) +#cinder_ca_certificates_file = -# Database to use (string value) -#mongodb_store_db = +# 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 # 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) #swift_store_config_file = -# Info to match when looking for cinder in the service catalog. Format -# is : separated values of the form: -# :: (string value) -#cinder_catalog_info = volume:cinder:publicURL +# 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 +# literal it must be enclosed in '[' and ']' characters following the +# RFC2732 URL syntax (e.g. '[::1]' for localhost) (string value) +#mongodb_store_uri = -# Override service catalog lookup with template for cinder endpoint -# e.g. http://localhost:8776/v1/%(project_id)s (string value) -#cinder_endpoint_template = - -# Region name of this node (string value) -#os_region_name = - -# Location of ca certicates file to use for cinder client requests. -# (string value) -#cinder_ca_certificates_file = - -# 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 -# , a default will be chosen based on the client. section in -# rbd_store_ceph_conf) (string value) -#rbd_store_user = - -# Ceph configuration file path. If , librados will locate the -# default config. If using cephx authentication, this file should -# include a reference to the right keyring in a client. section -# (string value) -#rbd_store_ceph_conf = /etc/ceph/ceph.conf +# Database to use (string value) +#mongodb_store_db = [matchmaker_redis] diff --git a/etc/oslo-config-generator/faafo.conf b/etc/oslo-config-generator/faafo.conf index 808f291..74063ae 100644 --- a/etc/oslo-config-generator/faafo.conf +++ b/etc/oslo-config-generator/faafo.conf @@ -1,6 +1,6 @@ [DEFAULT] output_file = etc/faafo.conf.sample -namespace = faafo.producer +namespace = faafo.worker namespace = faafo.api namespace = oslo.messaging namespace = oslo.log diff --git a/faafo/api/service.py b/faafo/api/service.py index afadef4..f7d8bbf 100644 --- a/faafo/api/service.py +++ b/faafo/api/service.py @@ -20,6 +20,7 @@ from flask_bootstrap import Bootstrap import glance_store from oslo_config import cfg from oslo_log import log +import oslo_messaging as messaging from faafo import version @@ -88,6 +89,10 @@ class Fractal(db.Model): db.create_all() 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('/index', methods=['GET']) @@ -114,8 +119,13 @@ def get_fractal(fractalid): return response +def generate_fractal(**kwargs): + client.cast({}, 'process', task=kwargs['result']) + + def main(): manager.create_api(Fractal, methods=['GET', 'POST', 'DELETE', 'PUT'], + postprocessors={'POST': [generate_fractal]}, url_prefix='/v1') app.run(host=CONF.listen_address, port=CONF.bind_port) diff --git a/faafo/producer/__init__.py b/faafo/producer/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/faafo/producer/service.py b/faafo/producer/service.py deleted file mode 100644 index 424f013..0000000 --- a/faafo/producer/service.py +++ /dev/null @@ -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 diff --git a/faafo/worker/service.py b/faafo/worker/service.py index 1f0de4c..9e8547d 100644 --- a/faafo/worker/service.py +++ b/faafo/worker/service.py @@ -17,7 +17,9 @@ import eventlet eventlet.monkey_patch() +import copy import hashlib +import json import os from PIL import Image import random @@ -29,6 +31,7 @@ import glance_store from oslo_config import cfg from oslo_log import log import oslo_messaging as messaging +import requests LOG = log.getLogger('faafo.worker') @@ -36,6 +39,20 @@ CONF = cfg.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): 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] } + # 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 diff --git a/setup.cfg b/setup.cfg index f26e05e..34aa21f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,7 +22,6 @@ packages = faafo scripts = bin/faafo - bin/faafo-producer bin/faafo-worker extra_files = faafo/api/templates/index.html @@ -38,7 +37,7 @@ console_scripts = faafo-api = faafo.api.service:main oslo.config.opts = faafo.api = faafo.api.service:list_opts - faafo.producer = faafo.producer.service:list_opts + faafo.worker = faafo.worker.service:list_opts [build_sphinx] source-dir = doc/source