示例#1
0
    def _extract_graph_action(self, entity_event):
        """Extract graph action.

        Decides what action (from constants.GraphAction) the processor need
        to perform according to the data received from the event.

        :param entity_event: event that returns from the driver
        :return: the action that the processor needs to perform
        :rtype: str
        """
        if DSProps.EVENT_TYPE in entity_event and \
                entity_event[DSProps.EVENT_TYPE] in vars(GraphAction).values():
            return entity_event[DSProps.EVENT_TYPE]

        datasource_action = entity_event[DSProps.DATASOURCE_ACTION]

        if DatasourceAction.UPDATE == datasource_action:
            return self.GRAPH_ACTION_MAPPING.get(
                entity_event.get(DSProps.EVENT_TYPE, None),
                GraphAction.UPDATE_ENTITY)

        if DatasourceAction.SNAPSHOT == datasource_action:
            return GraphAction.UPDATE_ENTITY

        if DatasourceAction.INIT_SNAPSHOT == datasource_action:
            return GraphAction.CREATE_ENTITY

        raise VitrageTransformerError('Invalid action type: (%s)' %
                                      datasource_action)
示例#2
0
    def _extract_action_type(self, entity_event):
        """Extract action type.

        Decides what action (from constants.EventAction) the processor need
        to perform according to the data received from the event.

        :param entity_event: event that returns from the driver
        :return: the action that the processor needs to perform
        :rtype: str
        """

        sync_mode = entity_event[DSProps.SYNC_MODE]

        if SyncMode.UPDATE == sync_mode:
            return self.UPDATE_EVENT_TYPES.get(
                entity_event.get(DSProps.EVENT_TYPE, None),
                EventAction.UPDATE_ENTITY)

        if SyncMode.SNAPSHOT == sync_mode:
            return EventAction.UPDATE_ENTITY

        if SyncMode.INIT_SNAPSHOT == sync_mode:
            return EventAction.CREATE_ENTITY

        raise VitrageTransformerError('Invalid sync mode: (%s)' % sync_mode)
    def _extract_action_type(self, event):
        event_type = event[EVALUATOR_EVENT_TYPE]

        try:
            return self.actions[event_type]
        except Exception:
            raise VitrageTransformerError(
                'Invalid Evaluator event type: (%s)' % event_type)
示例#4
0
    def get_transformer(self, key):
        try:
            transformer = self.transformers[key]
        except KeyError:
            raise VitrageTransformerError(
                'Could not get transformer instance for %s' % key)

        return transformer
示例#5
0
 def _extract_action_type(self, entity_event):
     sync_mode = entity_event[DSProps.SYNC_MODE]
     if sync_mode in (SyncMode.UPDATE, SyncMode.SNAPSHOT):
         return EventAction.DELETE_ENTITY if self._ok_status(entity_event) \
             else EventAction.UPDATE_ENTITY
     if SyncMode.INIT_SNAPSHOT == sync_mode:
         return EventAction.CREATE_ENTITY
     raise VitrageTransformerError('Invalid sync mode: (%s)' % sync_mode)
    def _extract_action_type(self, entity_event):
        # TODO(ifat_afek): this method should reside together with the cache,
        # in the transformer code
        if DSProps.EVENT_TYPE in entity_event:
            return entity_event[DSProps.EVENT_TYPE]

        sync_mode = entity_event[DSProps.SYNC_MODE]
        if sync_mode in (SyncMode.UPDATE, SyncMode.SNAPSHOT):
            return EventAction.DELETE_ENTITY if self._ok_status(entity_event) \
                else EventAction.UPDATE_ENTITY
        if SyncMode.INIT_SNAPSHOT == sync_mode:
            return EventAction.CREATE_ENTITY
        raise VitrageTransformerError('Invalid sync mode: (%s)' % sync_mode)
示例#7
0
    def _extract_graph_action(self, entity_event):

        if DSProps.EVENT_TYPE in entity_event and \
           entity_event[DSProps.EVENT_TYPE] == GraphAction.DELETE_ENTITY:
            return entity_event[DSProps.EVENT_TYPE]

        datasource_action = entity_event[DSProps.DATASOURCE_ACTION]

        if datasource_action in \
            (DatasourceAction.UPDATE, DatasourceAction.SNAPSHOT):
            return GraphAction.DELETE_ENTITY if self._ok_status(entity_event) else \
                self.GRAPH_ACTION_MAPPING.get(
                entity_event.get(DSProps.EVENT_TYPE, None),
                GraphAction.UPDATE_ENTITY)

        if DatasourceAction.INIT_SNAPSHOT == datasource_action:
            return GraphAction.CREATE_ENTITY

        raise VitrageTransformerError('Invalid datasource action: (%s)'
                                      % datasource_action)
示例#8
0
 def get_entity_type(entity_event):
     try:
         return entity_event[DSProps.ENTITY_TYPE]
     except KeyError:
         raise VitrageTransformerError(
             'Entity Event must contains entity_type field.')