Ejemplo n.º 1
0
 def getService(self, name):
     try:
         service = Service(name, blockingConnect=False)
         service.connectThroughLocator(self.locator, self.timeout, blocking=True)
         return service
     except Exception as err:
         raise ToolsError(err)
Ejemplo n.º 2
0
 def getService(self, name):
     try:
         service = Service(name, blockingConnect=False)
         service.connectThroughLocator(self.locator,
                                       self.timeout,
                                       blocking=True)
         return service
     except Exception as err:
         raise ToolsError(err)
Ejemplo n.º 3
0
    def execute(self):
        log.info('Checking "%s"... ', self.name)
        apps = yield List(self.storage).execute()
        if self.name not in apps:
            raise ToolsError('not available')

        app = Service(self.name, blockingConnect=False)
        try:
            yield app.connectThroughLocator(self.locator)
            info = yield app.info()
            log.info(info['state'])
        except (LocatorResolveError, ServiceError):
            raise ToolsError('stopped')
Ejemplo n.º 4
0
    def execute(self):
        log.info('Checking "%s"... ', self.name)
        apps = yield List(self.storage).execute()
        if self.name not in apps:
            raise ToolsError('not available')

        app = Service(self.name, blockingConnect=False)
        try:
            yield app.connectThroughLocator(self.locator)
            info = yield app.info()
            log.info(info['state'])
        except (LocatorResolveError, ServiceError):
            raise ToolsError('stopped')
Ejemplo n.º 5
0
def apps(request):
    node = Service('node')
    list_ = yield node.list()
    yield render(request, 'list.html', {
        'apps': list_
    })
Ejemplo n.º 6
0
import json
from django.http import HttpResponse
from django.shortcuts import render
from cocaine.tools.actions import common
from cocaine.asio.service import Service, Locator


locator = Locator()
locator.connect('localhost', 10053, 1.0, blocking=True)
node = Service('node')


def apps(request):
    node = Service('node')
    list_ = yield node.list()
    yield render(request, 'list.html', {
        'apps': list_
    })


def info(request):
    info = yield common.NodeInfo(node, locator).execute()
    yield HttpResponse(json.dumps(info))
Ejemplo n.º 7
0
import subprocess
import sys
from cocaine.futures import chain
import msgpack
from tornado.ioloop import IOLoop
from cocaine.asio.service import Service
from cocaine.exceptions import ChokeEvent

__author__ = 'Evgeny Safronov <*****@*****.**>'

ticks = 1
num = '1000000'

s = Service('Chunker')


def ideal():
    for _ in s.perform_sync('enqueue', 'chunkMe', num):
        pass


def collect_all(future):
    try:
        msgpack.loads(future.get())
    except ChokeEvent:
        IOLoop.current().stop()


def then_api():
    c = s.enqueue('chunkMe', num)
    c.then(collect_all)
Ejemplo n.º 8
0
import json
import time

from cocaine.asio.service import Service

__author__ = 'Evgeny Safronov <*****@*****.**>'


__doc__ = '''ELASTICSEARCH SERVICE USAGE EXAMPLE.
Elasticsearch must be started. Also elasticsearch cocaine plugin must be properly configured.
'''

now = time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime(time.time()))

elastic = Service('elasticsearch')

##### INDEX #####
print('Index simple message with index "/twitter/tweet/1"')
data = {
    'user': '******',
    'post_date': now,
    'message': 'Hello, Elasticsearch!'
}
print('Result:', elastic.index(json.dumps(data), 'twitter', 'tweet', '1').get())
print('')

##### GET #####
print('And now get it')
print(elastic.get('twitter', 'tweet', '1').get())
print('')