Exemplo n.º 1
0
    def loadComponent(self, identity, componentType, componentId,
                      componentLabel, properties, workerName,
                      plugs, eaters, isClockMaster, virtualFeeds):
        """
        Load a component into the manager configuration.

        See L{flumotion.manager.admin.AdminAvatar.perspective_loadComponent}
        for a definition of the argument types.
        """
        self.debug('loading %s component %s on %s',
                   componentType, componentId, workerName)
        parentName, compName = common.parseComponentId(componentId)

        if isClockMaster:
            raise NotImplementedError("Clock master components are not "
                                      "yet supported")
        if worker is None:
            raise errors.ConfigError("Component %r needs to specify the"
                                     " worker on which it should run"
                                     % componentId)

        state = self.state
        compState = None

        compConf = config.ConfigEntryComponent(compName, parentName,
                                               componentType,
                                               componentLabel,
                                               properties,
                                               plugs, workerName,
                                               eaters, isClockMaster,
                                               None, None, virtualFeeds)

        if compConf.defs.getNeedsSynchronization():
            raise NotImplementedError("Components that need "
                                      "synchronization are not yet "
                                      "supported")

        if parentName == 'atmosphere':
            parentState = state.get('atmosphere')
        else:
            flows = dict([(x.get('name'), x) for x in state.get('flows')])
            if parentName in flows:
                parentState = flows[parentName]
            else:
                self.info('creating flow %r', parentName)
                parentState = planet.ManagerFlowState(name=parentName,
                                                      parent=state)
                state.append('flows', parentState)

        components = [x.get('name') for x in parentState.get('components')]
        if compName in components:
            self.debug('%r already has component %r', parentName, compName)
            raise errors.ComponentAlreadyExistsError(compName)

        compState = self._addComponent(compConf, parentState, identity)

        self._startComponents([compState], identity)

        return compState
Exemplo n.º 2
0
    def pollData(self, managerId, componentId, uiStateKey, dsName,
                 rrdFile):

        def stateListToDict(l):
            return dict([(x.get('name'), x) for x in l])

        if managerId in self.multi.admins:
            admin = self.multi.admins[managerId]

            flowName, componentName = common.parseComponentId(componentId)

            flows = stateListToDict(admin.planet.get('flows'))
            if flowName not in flows:
                self.warning('not polling %s%s:%s: no such flow %s',
                             managerId, componentId, uiStateKey,
                             flowName)
                return

            components = stateListToDict(flows[flowName].get('components'))
            if componentName not in components:
                self.warning('not polling %s%s:%s: no such component %s',
                             managerId, componentId, uiStateKey,
                             componentId)
                return

            state = components[componentName]

            def gotUIState(uiState):
                if not uiState.hasKey(uiStateKey):
                    self.warning('while polling %s%s:%s: uiState has no '
                                 'key %s', managerId, componentId,
                                 uiStateKey, uiStateKey)
                else:
                    try:
                        value = '%d:%s' % (int(time.time()),
                                           uiState.get(uiStateKey))
                        self.log("polled %s%s:%s, updating ds %s = %s",
                                 managerId, componentId, uiStateKey,
                                 dsName, value)
                        rrdtool.update(rrdFile, "-t", dsName, value)
                    except rrdtool.error, e:
                        self.warning('error updating rrd file %s for '
                                     '%s%s:%s', rrdFile, managerId,
                                     componentId, uiStateKey)
                        self.debug('error reason: %s',
                                   log.getExceptionMessage(e))

            def errback(failure):
                self.warning('not polling %s%s:%s: failed to get ui '
                             'state')
                self.debug('reason: %s', log.getFailureMessage(failure))

            d = admin.componentCallRemote(state, 'getUIState')
            d.addCallbacks(gotUIState, errback)
Exemplo n.º 3
0
 def _getAuthenticatorForFeed(self, eaterAliasOrFeedName):
     # The avatarId on the keycards issued by the authenticator will
     # identify us to the remote component. Attempt to use our
     # fullFeedId, for debugging porpoises.
     if hasattr(self.authenticator, "copy"):
         tup = common.parseComponentId(self.authenticator.avatarId)
         flowName, componentName = tup
         fullFeedId = common.fullFeedId(flowName, componentName, eaterAliasOrFeedName)
         return self.authenticator.copy(fullFeedId)
     else:
         return self.authenticator
Exemplo n.º 4
0
 def _getAuthenticatorForFeed(self, eaterAliasOrFeedName):
     # The avatarId on the keycards issued by the authenticator will
     # identify us to the remote component. Attempt to use our
     # fullFeedId, for debugging porpoises.
     if hasattr(self.authenticator, 'copy'):
         tup = common.parseComponentId(self.authenticator.avatarId)
         flowName, componentName = tup
         fullFeedId = common.fullFeedId(flowName, componentName,
                                        eaterAliasOrFeedName)
         return self.authenticator.copy(fullFeedId)
     else:
         return self.authenticator
Exemplo n.º 5
0
    def pollData(self, managerId, componentId, uiStateKey, dsName, rrdFile):
        def stateListToDict(l):
            return dict([(x.get('name'), x) for x in l])

        if managerId in self.multi.admins:
            admin = self.multi.admins[managerId]

            flowName, componentName = common.parseComponentId(componentId)

            flows = stateListToDict(admin.planet.get('flows'))
            if flowName not in flows:
                self.warning('not polling %s%s:%s: no such flow %s', managerId,
                             componentId, uiStateKey, flowName)
                return

            components = stateListToDict(flows[flowName].get('components'))
            if componentName not in components:
                self.warning('not polling %s%s:%s: no such component %s',
                             managerId, componentId, uiStateKey, componentId)
                return

            state = components[componentName]

            def gotUIState(uiState):
                if not uiState.hasKey(uiStateKey):
                    self.warning(
                        'while polling %s%s:%s: uiState has no '
                        'key %s', managerId, componentId, uiStateKey,
                        uiStateKey)
                else:
                    try:
                        value = '%d:%s' % (int(
                            time.time()), uiState.get(uiStateKey))
                        self.log("polled %s%s:%s, updating ds %s = %s",
                                 managerId, componentId, uiStateKey, dsName,
                                 value)
                        rrdtool.update(rrdFile, "-t", dsName, value)
                    except rrdtool.error, e:
                        self.warning(
                            'error updating rrd file %s for '
                            '%s%s:%s', rrdFile, managerId, componentId,
                            uiStateKey)
                        self.debug('error reason: %s',
                                   log.getExceptionMessage(e))

            def errback(failure):
                self.warning('not polling %s%s:%s: failed to get ui ' 'state')
                self.debug('reason: %s', log.getFailureMessage(failure))

            d = admin.componentCallRemote(state, 'getUIState')
            d.addCallbacks(gotUIState, errback)
Exemplo n.º 6
0
def findComponent(planet, avatarId):
    """
    Finds the component with the given avatarId in the given planet.

    returns: the component state or None.
    """
    flowName, componentName = common.parseComponentId(avatarId)

    if flowName == 'atmosphere':
        for c in planet.get('atmosphere').get('components'):
            if c.get('name') == componentName:
                return c
        return None

    for f in planet.get('flows'):
        if f.get('name') == flowName:
            for c in f.get('components'):
                if c.get('name') == componentName:
                    return c
    return None
Exemplo n.º 7
0
def findComponent(planet, avatarId):
    """
    Finds the component with the given avatarId in the given planet.

    returns: the component state or None.
    """
    flowName, componentName = common.parseComponentId(avatarId)

    if flowName == 'atmosphere':
        for c in planet.get('atmosphere').get('components'):
            if c.get('name') == componentName:
                return c
        return None

    for f in planet.get('flows'):
        if f.get('name') == flowName:
            for c in f.get('components'):
                if c.get('name') == componentName:
                    return c
    return None