Ejemplo n.º 1
0
def create_post_delete(queue_name, messages):
    """Creates a queue, posts messages to it and finally deletes it with
    keystone auth strategy enabled on Zaqar server side.

    :params queue_name: The name of the queue
    :type queue_name: `six.text_type`
    :params messages: Messages to post.
    :type messages: list
    """
    conf = {
        'auth_opts': {
            'backend': 'keystone',
            'options': {
                'os_username': '******',
                'os_password': '******',
                'os_project_id': 'ccad479c402f43a2994f6e372ab3f8fe',
                'os_project_name': '',
                'os_auth_url': 'http://127.0.0.1:5000/v2.0/',
                'insecure': ''
            }
        }
    }
    cli = client.Client(URL, conf=conf)
    queue = cli.queue(queue_name)
    queue.post(messages)

    for msg in queue.messages(echo=True):
        print(msg.body)
        msg.delete()

    queue.delete()
Ejemplo n.º 2
0
def producer(stats, test_duration):
    """Producer Worker

    The Producer Worker continuously post messages for
    the specified duration. The time taken for each post
    is recorded for calculating throughput and latency.
    """

    cli = client.Client(URL)
    queue = cli.queue(QUEUE_PREFIX + '1')

    total_requests = 0
    total_elapsed = 0
    end = time.time() + test_duration

    while time.time() < end:
        marktime.start('post message')

        # TODO(TheSriram): Track/report errors
        try:
            queue.post(choose_message())

        except TransportError as ex:
            print("Could not post a message : {0}".format(ex))

        else:
            total_elapsed += marktime.stop('post message').seconds
            total_requests += 1

    stats.put({
        'total_requests': total_requests,
        'total_elapsed': total_elapsed
    })
Ejemplo n.º 3
0
    def test_signal_queues(self):
        stack_identifier = self.stack_create(template=self.template,
                                             expected_status=None)
        self._wait_for_resource_status(stack_identifier, 'wait_handle',
                                       'CREATE_COMPLETE')
        resource = self.client.resources.get(stack_identifier, 'wait_handle')
        signal = json.loads(resource.attributes['signal'])
        ks = keystoneclient.Client(auth_url=signal['auth_url'],
                                   user_id=signal['user_id'],
                                   password=signal['password'],
                                   project_id=signal['project_id'])
        endpoint = ks.service_catalog.url_for(service_type='messaging',
                                              endpoint_type='publicURL')
        conf = {
            'auth_opts': {
                'backend': 'keystone',
                'options': {
                    'os_auth_token': ks.auth_token,
                    'os_project_id': signal['project_id']
                }
            }
        }

        zaqar = zaqarclient.Client(endpoint, conf=conf, version=1.1)

        queue = zaqar.queue(signal['queue_id'])
        queue.post({'body': {'data': 'here!', 'id': 'data_id'}, 'ttl': 600})
        self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE')
        stack = self.client.stacks.get(stack_identifier)
        self.assertEqual('here!', stack.outputs[0]['output_value'])
Ejemplo n.º 4
0
    def test_events(self):
        queue_id = str(uuid.uuid4())
        environment = {
            'event_sinks': [{
                'type': 'zaqar-queue',
                'target': queue_id,
                'ttl': 120
            }]
        }
        stack_identifier = self.stack_create(template=self.template,
                                             environment=environment)
        stack_name, stack_id = stack_identifier.split('/')
        conf = {
            'auth_opts': {
                'backend': 'keystone',
                'options': {
                    'os_username': self.conf.username,
                    'os_password': self.conf.password,
                    'os_project_name': self.conf.project_name,
                    'os_auth_url': self.conf.auth_url,
                    'os_user_domain_id': self.conf.user_domain_id,
                    'os_project_domain_id': self.conf.project_domain_id,
                    'os_user_domain_name': self.conf.user_domain_name,
                    'os_project_domain_name': self.conf.project_domain_name
                }
            }
        }

        zaqar = zaqarclient.Client(conf=conf, version=1.1)
        queue = zaqar.queue(queue_id)

        def validate_messages():
            messages = list(queue.messages())
            if len(messages) < 4:
                return False

            types = [m.body['type'] for m in messages]
            self.assertEqual(['os.heat.event'] * 4, types)
            resources = set(
                [m.body['payload']['resource_name'] for m in messages])
            self.assertEqual(set([stack_name, 'test_resource']), resources)
            stack_ids = [m.body['payload']['stack_id'] for m in messages]
            self.assertEqual([stack_id] * 4, stack_ids)
            statuses = [m.body['payload']['resource_status'] for m in messages]
            statuses.sort()
            self.assertEqual(
                ['COMPLETE', 'COMPLETE', 'IN_PROGRESS', 'IN_PROGRESS'],
                statuses)
            actions = [m.body['payload']['resource_action'] for m in messages]
            self.assertEqual(['CREATE'] * 4, actions)
            return True

        self.assertTrue(test.call_until_true(20, 0, validate_messages))
Ejemplo n.º 5
0
def claim_delete(stats, test_duration, ttl, grace, limit):
    """Consumer Worker

    The Consumer Worker continuously claims and deletes messages
    for the specified duration. The time taken for each claim and
    delete is recorded for calculating throughput and latency.
    """

    cli = client.Client(URL)
    queue = cli.queue(QUEUE_PREFIX + '1')
    end = time.time() + test_duration
    total_elapsed = 0
    total_requests = 0
    claim_total_requests = 0
    delete_total_requests = 0

    while time.time() < end:
        marktime.start('claim_message')
        try:
            claim = queue.claim(ttl=ttl, grace=grace, limit=limit)

        except TransportError as ex:
            print("Could not claim messages : {0}".format(ex))

        else:
            total_elapsed += marktime.stop('claim_message').seconds
            total_requests += 1
            claim_total_requests += 1

            try:
                marktime.start('delete_message')

                for msg in claim:
                    # TODO(TheSriram): Simulate actual work before deletion
                    msg.delete()

                total_elapsed += marktime.stop('delete_message').seconds
                delete_total_requests += 1
                total_requests += 1
                stats.put({
                    'total_requests': total_requests,
                    'claim_total_requests': claim_total_requests,
                    'delete_total_requests': delete_total_requests,
                    'total_elapsed': total_elapsed
                })

            except TransportError as ex:
                print("Could not claim and delete : {0}".format(ex))
Ejemplo n.º 6
0
    def __init__(self, conf):
        if conf is not None:
            self.config = conf
        '''
		LOG.debug(self.config.os_auth_url)
		LOG.debug(self.config.clientuuid)
		LOG.debug(self.config.os_project_name)
		LOG.debug(self.config.os_project_id)
		LOG.debug(self.config.zaqar_endpoint)
		'''
        self.zqc = client.Client(
            self.config.zaqar_endpoint,
            conf={'auth_opts': {
                'options': self.config.zaqar_conf
            }},
            version=2)
Ejemplo n.º 7
0
def create_post_delete(queue_name, messages):
    """Creates a queue, posts messages to it
    and finally deletes it.

    :params queue_name: The name of the queue
    :type queue_name: `six.text_type`
    :params messages: Messages to post.
    :type messages: list
    """
    cli = client.Client(URL)
    queue = cli.queue(queue_name)
    queue.post(messages)

    for msg in queue.messages(echo=True):
        print(msg.body)
        msg.delete()

    queue.delete()
Ejemplo n.º 8
0
    def create_for_tenant(self, tenant_id):
        con = self.context
        if self.auth_token is None:
            LOG.error(_LE("Zaqar connection failed, no auth_token!"))
            return None

        opts = {
            'os_auth_token': con.auth_token,
            'os_auth_url': con.auth_url,
            'os_project_id': tenant_id,
            'os_service_type': 'messaging',
        }
        auth_opts = {'backend': 'keystone', 'options': opts}
        conf = {'auth_opts': auth_opts}
        endpoint = self.url_for(service_type='messaging')

        client = zaqarclient.Client(url=endpoint, conf=conf, version=1.1)

        return client
Ejemplo n.º 9
0
    def zaqar(self):
        if self._zaqar:
            return self._zaqar

        endpoint_type = get_client_option('zaqar', 'endpoint_type')
        region_name = get_client_option('zaqar', 'region_name')
        endpoint_url = self.url_for(service_type='queuing',
                                    endpoint_type=endpoint_type,
                                    region_name=region_name)
        conf = {'auth_opts':
                {'backend': 'keystone',
                 'options': {'os_auth_token': self.auth_token,
                             'os_auth_url': self.auth_url,
                             'insecure': get_client_option('zaqar',
                                                           'insecure')}
                 }
                }
        self._zaqar = zaqarclient.Client(endpoint_url, conf=conf)
        return self._zaqar
Ejemplo n.º 10
0
    def _create(self):

        con = self.context
        if self.auth_token is None:
            LOG.error(_("Zaqar connection failed, no auth_token!"))
            return None

        opts = {
            'os_auth_token': con.auth_token,
            'os_auth_url': con.auth_url,
            'os_project_id': con.tenant,
            'os_service_type': 'queuing',
        }
        auth_opts = {'backend': 'keystone', 'options': opts}
        conf = {'auth_opts': auth_opts}
        endpoint = self.url_for(service_type='queuing')

        client = zaqarclient.Client(url=endpoint, conf=conf)

        return client
Ejemplo n.º 11
0
    def poll(self):
        keystone_cred = self._get_keystone_auth_cred()
        keystone_cli = keystone.Client(**keystone_cred)

        messaging_endpoint = keystone_cli.service_catalog.url_for(
            service_type=self._config['messaging']['service_type'],
            endpoint_type='publicURL')

        messaging_cli = zaqar.Client(messaging_endpoint,
                                     conf=self._get_zaqar_auth_config(
                                         keystone_cli.auth_token),
                                     version=2)

        claim_options = self._get_claim_options()
        claim_ttl = claim_options['ttl']
        claim_grace = claim_options['grace']

        for queue_name in self._config['messaging']['queues']:
            self.logger.debug('Claiming from queue "%s"...' % queue_name)
            queue = messaging_cli.queue(queue_name)
            for message in queue.claim(ttl=claim_ttl, grace=claim_grace):
                self._dispatch_message(queue_name, message.body)
                message.delete()
Ejemplo n.º 12
0
#
#    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.
from zaqarclient.queues.v1 import client

client = client.Client('http://localhost:8888',
                       conf={
                           'auth_opts': {
                               'options': {
                                   'client_uuid':
                                   '355186cd-d1e8-4108-a3ac-a2183697232a',
                                   'os_auth_token':
                                   '8444886dd9b04a1b87ddb502b508261c',
                                   'os_auth_url':
                                   'http://localhost:5000/v3.0/',
                                   'os_project_id':
                                   '7530fad032ca431e9dc8ed4a5de5d99c'
                               }
                           }
                       },
                       version=2)

queue = client.queue('SampleQueue')

queue.post([{'body': 'Zaqar Sample'}])
Ejemplo n.º 13
0
#    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 time

from zaqarclient.queues.v1 import client

URL = 'http://localhost:8888'

cli = client.Client(URL)
queue = cli.queue('worker-jobs')


def send_jobs():
    jobs = [{'name': 'fluffy'}, {'name': 'scout'}, {'name': 'jo'}]
    queue.post([{'body': j, 'ttl': 360} for j in jobs])


def process_jobs():
    claim1 = queue.claim(ttl=500, grace=900, limit=2)
    for msg in claim1:
        claim_id = msg.claim_id
        print('{claim_id} =? {id}'.format(claim_id=claim_id, id=claim1.id))
        print('processing job %s' % (msg))
        msg.delete()