Example #1
0
    def configure(self, configuration):
        """
        The expectation that configuration will have at least the following
        items
        
        .. code: python
        
            {
                "connection": {
                    "params": {
                        "host": "http://localhost:4200"
                    }
                }
            }
        
        :param configuration: 
        """
        connection = configuration.get("connection", {})
        params = connection.get("params", {})
        if not isinstance(params, dict):
            _log.error("Invalid params...must be a dictionary.")
            raise ValueError("params must be a dictionary.")

        schema = connection.get("schema", "historian")
        host = params.get("host", None)
        error_trace = params.get("error_trace", False)

        if host is None:
            _log.error("Invalid configuration for params...must have host.")
            raise ValueError("invalid params['host'] value")
        elif host != self._host:
            _log.info("Changing host to {}".format(host))
        
        self._host = host
        
        client = self.get_client(host)
        if client is None:
            _log.error("Couldn't reach host: {}".format(host))
            raise ValueError("Connection to host not made!")

        # Store class variables to be used later.
        if schema != self._schema:
            _log.info("Changing schema to: {}".format(schema))
            self._schema = schema

        if error_trace != self._error_trace:
            _log.info("Changing error trace to: {}".format(error_trace))
            self._error_trace = error_trace

        # Close and reconnect the client or connect to different hosts.
        if self._client is not None:
            try:
                self._client.close()
            except:
                _log.warning("Closing of non-null client failed.")
            finally:
                self._client = None

        self._client = crate_client.connect(servers=self._host,
                                            error_trace=self._error_trace)

        # Attempt to create the schema
        create_schema(self._client, self._schema)

        topics = self.get_topic_list()
        peers = self.vip.peerlist().get(timeout=5)
        if VOLTTRON_CENTRAL_PLATFORM in peers:
            topic_replace_map_vcp = self.vip.rpc.call(VOLTTRON_CENTRAL_PLATFORM,
                                                      method="get_replace_map").get(timeout=5)
            # Always use VCP instead of local
            self._topic_replace_map = topic_replace_map_vcp

        for t in topics:
            self._topic_set.add(self.get_renamed_topic(t))

        self.vip.pubsub.subscribe(peer='pubsub',
                                  prefix="platform/config_updated",
                                  callback=self._peer_config_update)
Example #2
0
    def configure(self, configuration):
        """
        The expectation that configuration will have at least the following
        items
        
        .. code: python
        
            {
                "connection": {
                    "params": {
                        "host": "http://localhost:4200"
                    }
                }
            }
        
        :param configuration: 
        """
        connection = configuration.get("connection", {})
        tables_def, table_names = self.parse_table_def(configuration.get("tables_def"))

        self._data_table = table_names['data_table']
        self._topic_table = table_names['topics_table']

        params = connection.get("params", {})
        if not isinstance(params, dict):
            _log.error("Invalid params...must be a dictionary.")
            raise ValueError("params must be a dictionary.")

        schema = configuration.get("schema", "historian")
        host = params.get("host", None)
        error_trace = params.get("error_trace", False)

        if host is None:
            _log.error("Invalid configuration for params...must have host.")
            raise ValueError("invalid params['host'] value")
        elif host != self._host:
            _log.info("Changing host to {}".format(host))

        self._host = host

        client = CrateHistorian.get_client(host)
        if client is None:
            _log.error("Couldn't reach host: {}".format(host))
            raise ValueError("Connection to host not made!")

        self._schema = schema

        if error_trace != self._error_trace:
            _log.info("Changing error trace to: {}".format(error_trace))
            self._error_trace = error_trace

        # Close and reconnect the client or connect to different hosts.
        if self._client is not None:
            try:
                self._client.close()
            except:
                _log.warning("Closing of non-null client failed.")
            finally:
                self._client = None

        self._client = crate_client.connect(servers=self._host,
                                            error_trace=self._error_trace)

        # Attempt to create the schema
        create_schema(self._client, self._schema, table_names)

        # Cache topic and metadata
        self.load_topic_meta()
Example #3
0
    def configure(self, configuration):
        """
        The expectation that configuration will have at least the following
        items
        
        .. code: python
        
            {
                "connection": {
                    "params": {
                        "host": "http://localhost:4200"
                    }
                }
            }
        
        :param configuration: 
        """
        connection = configuration.get("connection", {})
        params = connection.get("params", {})
        if not isinstance(params, dict):
            _log.error("Invalid params...must be a dictionary.")
            raise ValueError("params must be a dictionary.")

        schema = connection.get("schema", "historian")
        host = params.get("host", None)
        error_trace = params.get("error_trace", False)

        if host is None:
            _log.error("Invalid configuration for params...must have host.")
            raise ValueError("invalid params['host'] value")
        elif host != self._host:
            _log.info("Changing host to {}".format(host))

        self._host = host

        client = self.get_client(host)
        if client is None:
            _log.error("Couldn't reach host: {}".format(host))
            raise ValueError("Connection to host not made!")

        # Store class variables to be used later.
        if schema != self._schema:
            _log.info("Changing schema to: {}".format(schema))
            self._schema = schema

        if error_trace != self._error_trace:
            _log.info("Changing error trace to: {}".format(error_trace))
            self._error_trace = error_trace

        # Close and reconnect the client or connect to different hosts.
        if self._client is not None:
            try:
                self._client.close()
            except:
                _log.warning("Closing of non-null client failed.")
            finally:
                self._client = None

        self._client = crate_client.connect(servers=self._host,
                                            error_trace=self._error_trace)

        # Attempt to create the schema
        create_schema(self._client, self._schema)

        topics = self.get_topic_list()
        peers = self.vip.peerlist().get(timeout=5)
        if VOLTTRON_CENTRAL_PLATFORM in peers:
            topic_replace_map_vcp = self.vip.rpc.call(
                VOLTTRON_CENTRAL_PLATFORM,
                method="get_replace_map").get(timeout=5)
            # Always use VCP instead of local
            self._topic_replace_map = topic_replace_map_vcp

        for t in topics:
            self._topic_set.add(self.get_renamed_topic(t))

        self.vip.pubsub.subscribe(peer='pubsub',
                                  prefix="platform/config_updated",
                                  callback=self._peer_config_update)