Example #1
0
            log.error("message got here without the later-init")
        sleepsecs = int(content['work_amount'])
        extradict = {
            "batchid": content['batchid'],
            "jobid": content['jobid'],
            "work_amount": sleepsecs
        }
        cei_events.event("worker", "job_begin", extra=extradict)
        log.info("WORK: sleeping for %d seconds ---" % sleepsecs)
        yield pu.asleep(sleepsecs)
        yield self.reply(msg, 'result', {'result': 'work_complete'}, {})
        cei_events.event("worker", "job_end", extra=extradict)


# Direct start of the service as a process with its default name
factory = ProcessFactory(EPUWorkerService)


@defer.inlineCallbacks
def start(container, starttype, *args, **kwargs):
    log.info('EPU Worker starting, startup type "%s"' % starttype)

    conf = ioninit.config(__name__)
    spawnargs = {'queue_name_work': conf['queue_name_work']}

    # Required services.
    proc = [{
        'name': 'epu_worker',
        'module': __name__,
        'class': EPUWorkerService.__name__,
        'spawnargs': spawnargs
Example #2
0
def read_cookie(path=None):
    """Reads Erlang cookie file
    """
    cookie_path = path or DEFAULT_COOKIE_PATH
    log.debug('Reading erlang cookie from ' + cookie_path)
    f = open(os.path.expanduser(cookie_path))
    try:
        return f.read().strip()
    finally:
        if f:
            f.close()


# Direct start of the service as a process with its default name
factory = ProcessFactory(QueueStatService)


@defer.inlineCallbacks
def start(container, starttype, *args, **kwargs):
    log.info('EPU Queuestat starting, startup type "%s"' % starttype)

    conf = ioninit.config(__name__)

    proc = [
        {
            'name': 'queuestat',
            'module': __name__,
            'class': QueueStatService.__name__,
            'spawnargs': {
                'interval_seconds': conf.getValue('interval_seconds')
Example #3
0
        See the NPreservingEngine class notes for reconfiguration details.
        """
        pass

    def op_find_workers(self, content, headers, msg):
        """Interact with the provisioner to discover any new worker nodes
        that were launched in the system since the last query.

        Input: optionally filter by a particular HA service.

        Returns the newest workers, before return it has updated the
        datastore with any new information.
        """
        pass

    def op_service_status(self, content, headers, msg):
        """Return the status of one or more services.  Each service status
        will list the:

        1) Known workers, past and present.  Instance information, time of
        launch (and failure/termination if applicable), hostnames.

        2) Worker status: IaaS status as well as the more "semantic" knowledge
        of health that is acquired via heartbeats (or the lack thereof).
        """
        pass


# Direct start of the service as a process with its default name
factory = ProcessFactory(EPUManagementService)
        Note it does not update the SQL files on disk, so if the AppControllerService is
        restarted, it will need to be updated with the current defs again.

        This method expects that the only key in content, also named content, is a full 
        SQL definition (the concatenation of "catalog.sqlt" and "detections.sqlt") with
        Python string.Template vars as substitution points for the following variables:

        * inp_queue                 - The input queue name to read messages from.
        * inp_queue_autodelete      - The input queue's auto_delete setting.
        * inp_queue_durable         - The input queue's durable setting.
        * inp_exchange              - The exchange where the input queue resides.
        * inp_exchange_type         - The exchange's type (topic/fanout/direct).
        * inp_exchange_durable      - The exchange's durable setting.
        * inp_exchange_autodelete   - The exchange's auto_delete setting.
        * det_topic                 - The topic string that should be used for detections.
        * det_exchange              - The exchange where detections should be published.
        * det_exchange_type         - The detection exchange's type (topic/fanout/direct).
        * det_exchange_durable      - The detection exchange's durable setting.
        * det_exchange_autodelete   - The detection exchange's auto_delete setting.

        If these variables are not present, no error is thrown - it will use whatever you
        gave it. So your updated SQL definitions may hardcode the variables above.
        """
        defs = content['content']
        self.attribute_store_client.put(SQLTDEFS_KEY, defs)
        self.reply_ok(msg, {'value': 'ok'}, {})


# Spawn of the process using the module name
factory = ProcessFactory(AppControllerService)
Example #5
0
            # must simulate processEnded callback value
            cba = {
                'exitcode': 0,
                'outlines': self.outlines,
                'errlines': self.errlines
            }

            self.ready_deferred.callback(cba)
            #yield self.ready_callback(**self.ready_callbackargs)

    def processEnded(self, reason):
        # Process ended override.
        # This override is to signal ready deferred if we never did, just in case.
        if self.ready_deferred and not self.ready_deferred.called:

            # must simulate processEnded callback value
            cba = {
                'exitcode': 0,
                'outlines': self.outlines,
                'errlines': self.errlines
            }

            self.ready_deferred.callback(cba)

        EnvOSProcess.processEnded(self, reason)


# Spawn of the process using the module name
factory = ProcessFactory(AppAgent)
Example #6
0
                      e,
                      exc_info=True)

    @defer.inlineCallbacks
    def _do_query(self):
        log.debug("Sending query request to provisioner")
        yield self.client.query()

        # This is an unfortunate hack to work around a memory leak in ion.
        # Some caches are only cleared after a received message is handled.
        # Since this process sends messages "spontaneously" -- triggered by a
        # LoopingCall -- we must manually clear the cache.
        self.message_client.workbench.manage_workbench_cache('Default Context')


factory = ProcessFactory(ProvisionerQueryService)


@defer.inlineCallbacks
def start(container, starttype, *args, **kwargs):
    proc = [{
        'name': 'provisioner',
        'module': __name__,
        'class': ProvisionerQueryService.__name__,
        'spawnargs': {}
    }]

    app_supv_desc = ProcessDesc(name='Provisioner Query app supervisor',
                                module=app_supervisor.__name__,
                                spawnargs={'spawn-procs': proc})
Example #7
0
        (content, headers, msg) = yield self.rpc_send('node_error', node_id)
        defer.returnValue(content)


class EPUControllerClientSample(ServiceProcess):

    declare = ServiceProcess.service_declare(name='epu_reconfigure_sample',
                                             version='0.1.0',
                                             dependencies=[])

    def slc_init(self, proc=None, **kwargs):
        self.client = EPUControllerClient()
        reactor.callLater(5, self.send_reconfigure)

    @defer.inlineCallbacks
    def send_reconfigure(self):
        newconf = {}
        newconf["preserve_n"] = "%s" % self.spawn_args["preserve_n"]
        newconf["unique_instances"] = {
            'b2db408e': {
                'some_unique_name': 'some_unique_value123'
            },
            '3633541e': {
                'some_unique_name': 'some_other_unique_value456'
            }
        }
        self.client.reconfigure(newconf)


factory = ProcessFactory(EPUControllerClientSample)
Example #8
0
        """
        log.debug('Sending state %s record for node %s to %s', record['state'],
                  record['node_id'], repr(subscribers))
        for sub in subscribers:
            yield self.process.send(sub, operation, record)

    @defer.inlineCallbacks
    def send_records(self, records, subscribers, operation='instance_state'):
        """Send a set of node records to all subscribers.
        """
        for rec in records:
            yield self.send_record(rec, subscribers, operation)


# Spawn of the process using the module name
factory = ProcessFactory(ProvisionerService)


@defer.inlineCallbacks
def start(container, starttype, *args, **kwargs):
    log.info('EPU Provisioner starting, startup type "%s"' % starttype)

    conf = ioninit.config(__name__)

    proc = [{
        'name': 'provisioner',
        'module': __name__,
        'class': ProvisionerService.__name__,
        'spawnargs': {
            'query_period': conf.getValue('query_period'),
            'store': get_provisioner_store(conf),
Example #9
0
                # This is an unfortunate hack to work around a memory leak in ion.
                # Some caches are only cleared after a received message is handled.
                # Since this process sends messages "spontaneously" -- triggered by a
                # LoopingCall -- we must manually clear the cache.
                self.message_client.workbench.manage_workbench_cache(
                    'Default Context')

        except Queue.Empty:
            return
        except Exception, e:
            # unhandled exceptions will terminate the LoopingCall
            log.error("Error adding work: %s", e, exc_info=True)


# Direct start of the service as a process with its default name
factory = ProcessFactory(EPUWorkProducer)


class SleepJob:
    def __init__(self, jobid, batchid, length):
        self.jobid = jobid
        self.batchid = batchid
        self.length = int(length)


# Sidechannel access to tell service what to do
class Sidechannel(resource.Resource):
    isLeaf = True

    def __init__(self):
        self.queue = Queue.Queue()
        
        @return: a list with expected id's that have not been received.
        """
        # note: we pass the timeout as it is directly to our own payload:
        payload = {'timeout':timeout}
        
        # but we need to explicitly indicate it for purposes of ION processing:
        if timeout is None:
            timeout = 15.0
            
        (content, headers, payload) = yield self.rpc_send('getExpected', payload, timeout=timeout)
        log.debug('getExpected service reply: ' + str(content))
        defer.returnValue(content)
        
    @defer.inlineCallbacks
    def getAccepted(self, publish_id):
        """
        Returns the content received for a given publish_id; None if not received yet.
        """
        if publish_id is None:
            raise Exception("publish_id cannot be None")
        payload = {'publish_id':publish_id}
        (content, headers, payload) = yield self.rpc_send('getAccepted', payload)
        log.debug('getAccepted service reply: ' + str(content))
        defer.returnValue(content)
        

# Spawn of the process using the module name
factory = ProcessFactory(SiamCiReceiverService)

Example #11
0
File: dtrs.py Project: timf/epu
            })
        except ReceivedError, re:
            raise DeployableTypeLookupError(re.msg_content)

        defer.returnValue({
            'document' : content.get('document'),
            'nodes' : content.get('nodes')
            })

class DeployableTypeLookupError(Exception):
    """Error resolving or interpolating deployable type
    """
    pass

# Direct start of the service as a process with its default name
factory = ProcessFactory(DeployableTypeRegistryService)

@defer.inlineCallbacks
def start(container, starttype, *args, **kwargs):
    log.info('EPU DTRS starting, startup type "%s"' % starttype)

    conf = ioninit.config(__name__)
    dt_dir = conf.getValue('registry_dir', '/opt/dt-data/dt')

    # Required services.
    proc = [{'name': 'dtrs',
             'module': __name__,
             'class': DeployableTypeRegistryService.__name__,
             'spawnargs': {'registry_dir' : dt_dir}
            }]
Example #12
0
    The client class for the instrument driver. This is the client that the
    instrument agent can use for communicating with the driver.
    
    In this case, this is the driver interface to a SIAM enabled instrument.
    Operations are mainly supported by the SiamCiAdapterProxy class.
    """
    @defer.inlineCallbacks
    def set_publish_stream(self, publish_stream):
        """
        Sets the publish stream.  This is a convenience to allow the testing of 
        reception of asynchronous notifications from the SIAM-CI adapter service.
        The expected mechanism would be that an associated InstrumentAgent 
        would get those notifications directly (eg., via the op_publish operation),
        but this is not clear yet (2011-05-12).
        
        @param publish_stream: the publish stream name.  Can be None.
        """

        log.debug("SiamInstrumentDriverClient set_publish_stream " +
                  str(publish_stream))
        content_outgoing = {'publish_stream': publish_stream}

        (content, headers,
         message) = yield self.rpc_send('set_publish_stream', content_outgoing)

        defer.returnValue(content)


# Spawn of the process using the module name
factory = ProcessFactory(SiamInstrumentDriver)
Example #13
0
                continue
            controller_list.append(name)
        return controller_list

    def plc_terminate(self):
        log.debug('EPU Controller List service: shutdown triggered')

    @defer.inlineCallbacks
    def op_list(self, content, headers, msg):
        """Return a list of zero to N controller names
        """
        yield self.reply_ok(msg, self.controller_list)


# Direct start of the service as a process with its default name
factory = ProcessFactory(EPUControllerListService)


@defer.inlineCallbacks
def start(container, starttype, *args, **kwargs):
    log.info('EPU Controller List service starting, startup type "%s"' %
             starttype)

    conf = ioninit.config(__name__)
    controller_list_path = conf.getValue('controller_list_path', None)

    proc = [
        {
            'name': 'epu_controller_list',
            'module': __name__,
            'class': EPUControllerListService.__name__,