Exemplo n.º 1
0
 def onstart(self, sender, **kwargs):
     _log.debug("VERSION IS: {}".format(self.core.version()))
     if self._heartbeat_period != 0:
         _log.debug(f"Heartbeat starting for {self.core.identity}, published every {self._heartbeat_period}s")
         self.vip.heartbeat.start_with_period(self._heartbeat_period)
         self.vip.health.set_status(STATUS_GOOD, self._message)
     query = Query(self.core)
     _log.info('query: %r', query.query('serverkey').get())
Exemplo n.º 2
0
def test_agent_can_get_platform_version(volttron_instance):
    agent = volttron_instance.build_agent()
    query = Query(agent.core)
    response = subprocess.check_output(['volttron', "--version"],
                                       stderr=subprocess.STDOUT)
    assert response.strip()
    _, version = response.strip().split(" ")

    platform_version = query.query("platform-version")
    assert version == platform_version.get(timeout=2)
Exemplo n.º 3
0
def test_agent_can_get_platform_version(volttron_instance):
    agent = volttron_instance.build_agent()
    query = Query(agent.core)
    response = subprocess.check_output(['volttron', "--version"],
                                       stderr=subprocess.STDOUT)
    assert response.strip()
    _, version = response.strip().split(" ")

    platform_version = query.query("platform-version")
    assert version == platform_version.get(timeout=2)
Exemplo n.º 4
0
    def _started(self, sender, **kwargs):

        # Created a link to the control agent on this platform.
        self._control_connection = Connection(address=self.core.address,
                                              peer='control')

        _log.debug('Querying router for addresses and serverkey.')
        q = Query(self.core)

        self._external_addresses = q.query('addresses').get(timeout=2)
        _log.debug('External addresses are: {}'.format(
            self._external_addresses))

        self._local_serverkey = q.query('serverkey').get(timeout=2)
        _log.debug('serverkey is: {}'.format(self._local_serverkey))

        vc_http_address = q.query('volttron-central-address').get(timeout=2)
        _log.debug('vc address is {}'.format(vc_http_address))

        self._local_instance_name = q.query('instance-name').get(timeout=2)
        _log.debug('instance-name is {}'.format(self._local_instance_name))

        if vc_http_address is not None:
            parsed = urlparse.urlparse(vc_http_address)
            if parsed.scheme in ('https', 'http'):
                self._volttron_central_http_address = vc_http_address
            elif parsed.scheme == 'ipc':
                self._volttron_central_ipc_address = vc_http_address
            elif parsed.scheme == 'tcp':
                self._volttron_central_tcp_address = vc_http_address
                vc_serverkey = q.query('volttron-central-serverkey').get(
                    timeout=2)
                if vc_serverkey is None:
                    raise ValueError(
                        'volttron-central-serverkey is not set with tcp address'
                    )
                self._volttron_central_serverkey = vc_serverkey
            else:
                raise ValueError('invalid scheme for volttron-central-address')

        self._agent_started = True

        _log.debug('Starting the period registration attempts.')
        # Start the process of attempting registration with a VOLTTRON central.
        self._periodic_attempt_registration()

        try:
            _log.debug('Starting stats publisher.')
            self._start_stats_publisher()
        except ValueError as e:
            _log.error(e)
Exemplo n.º 5
0
    def _configure_main(self, config_name, action, contents):
        """
        This is the main configuration point for the agent.

        :param config_name:
        :param action:
        :param contents:
        :return:
        """
        self.enable_registration = False
        # If we are updating the main configuration we need to reset the
        # connection to vc if present and initialize the state for reconnection.
        if self.vc_connection is not None:
            self.vc_connection.kill()
            self.vc_connection = None
        self.registration_state = RegistrationStates.NotRegistered

        if config_name == 'default_config':
            # we know this came from the config file that was specified
            # with the agent
            config = self.default_config.copy()

        elif config_name == 'config':
            config = self.default_config.copy()
            config.update(contents)

        else:
            _log.error('Invalid configuration name!')
            sys.exit(INVALID_CONFIGURATION_CODE)

        _log.debug('Querying router for addresses and serverkey.')
        q = Query(self.core)

        external_addresses = q.query('addresses').get(timeout=5)
        local_serverkey = q.query('serverkey').get(timeout=5)
        vc_address = q.query('volttron-central-address').get(timeout=5)
        vc_serverkey = q.query('volttron-central-serverkey').get(timeout=5)
        instance_name = q.query('instance-name').get(timeout=5)
        bind_web_address = q.query('bind-web-address').get(timeout=5)
        address_hash = hashlib.md5(external_addresses[0]).hexdigest()

        updates = dict(bind_web_address=bind_web_address,
                       volttron_central_address=vc_address,
                       volttron_central_serverkey=vc_serverkey,
                       instance_name=instance_name,
                       address_hash=address_hash,
                       local_serverkey=local_serverkey,
                       local_external_addresses=external_addresses)

        if config_name == 'default_config':
            for k, v in updates.items():
                if v:
                    config[k] = v
        elif config_name == 'config':
            for k, v in updates.items():
                # Only update from the platform's configuration file if the
                # value doesn't exist in the config or if it is empty.
                if k not in config:
                    config[k] = v
                elif not config[k]:
                    config[k] = v

        self.current_config = config.copy()

        vc_address = self.current_config['volttron_central_address']
        vc_serverkey = self.current_config['volttron_central_serverkey']

        if vc_address:
            parsed = urlparse.urlparse(vc_address)

            if parsed.scheme in ('http', 'https'):
                _log.debug('vc_address is {}'.format(vc_address))
                info = None
                while info is None:
                    try:
                        info = DiscoveryInfo.request_discovery_info(vc_address)
                    except DiscoveryError as e:
                        _log.error(
                            "Unable to retrieve discovery info from volttron central."
                        )
                        gevent.sleep(10)

                self.current_config['vc_connect_address'] = info.vip_address
                self.current_config['vc_connect_serverkey'] = info.serverkey
            else:
                self.current_config['vc_connect_address'] = vc_address
                self.current_config['vc_connect_serverkey'] = vc_serverkey
        else:
            if bind_web_address:
                info = DiscoveryInfo.request_discovery_info(bind_web_address)
                # This will allow us to register with the current instance if
                # there is an http server running here.
                self.current_config['vc_connect_address'] = info.vip_address
                self.current_config['vc_connect_serverkey'] = info.serverkey

        # Address hash that uniquely defines this instance in the network.
        # Note: if there isn't a true tcp address then external_address[0] is
        # going to be the ipc address
        address_hash = hashlib.md5(external_addresses[0]).hexdigest()
        _log.debug(
            'External hash is set using external_addresses[0] {}'.format(
                external_addresses[0]))
        self.current_config['address_hash'] = address_hash
        self.current_config['instance_id'] = 'vcp-{}'.format(address_hash)
        self.current_config['host'] = platform.uname()[1]

        # Connect to volttron central instance.
        self._establish_connection_to_vc()
        # Start publishing stats to the local bus.
        self._start_stats_publisher()
Exemplo n.º 6
0
    def configure_main(self, config_name, action, contents):
        """
        The main configuration for volttron central.  This is where validation
        will occur.

        Note this method is called:

            1. When the agent first starts (with the params from packaged agent
               file)
            2. When 'store' is called through the volttron-ctl config command
               line with 'config' as the name.

        Required Configuration:

        The volttron central requires a user mapping.

        :param config_name:
        :param action:
        :param contents:
        """

        _log.debug('Main config updated')
        _log.debug('ACTION IS {}'.format(action))
        _log.debug('CONTENT IS {}'.format(contents))
        if action == 'DELETE':
            # Remove the registry and keep the service running.
            self.runtime_config = None
            # Now stop the exposition of service.
        else:
            self.runtime_config = self.default_config.copy()
            self.runtime_config.update(contents)

            problems = self._validate_config_params(self.runtime_config)

            if len(problems) > 0:
                _log.error(
                    "The following configuration problems were detected!")
                for p in problems:
                    _log.error(p)
                sys.exit(INVALID_CONFIGURATION_CODE)
            else:
                _log.info('volttron central webroot is: {}'.format(
                    self.runtime_config.get('webroot')))

                users = self.runtime_config.get('users')
                self.web_sessions = SessionHandler(Authenticate(users))

            _log.debug('Querying router for addresses and serverkey.')
            q = Query(self.core)

            external_addresses = q.query('addresses').get(timeout=5)
            self.runtime_config['local_external_address'] = external_addresses[
                0]

        self.vip.web.register_websocket(r'/vc/ws',
                                        self.open_authenticate_ws_endpoint,
                                        self._ws_closed, self._ws_received)
        self.vip.web.register_endpoint(r'/jsonrpc', self.jsonrpc)
        self.vip.web.register_path(r'^/.*', self.runtime_config.get('webroot'))

        # Start scanning for new platforms connections as well as for
        # disconnects that happen.
        self._scan_for_platforms()
Exemplo n.º 7
0
    def configure_main(self, config_name, action, contents):
        """
        The main configuration for volttron central.  This is where validation
        will occur.

        Note this method is called:

            1. When the agent first starts (with the params from packaged agent
               file)
            2. When 'store' is called through the volttron-ctl config command
               line with 'config' as the name.

        Required Configuration:

        The volttron central requires a user mapping.

        :param config_name:
        :param action:
        :param contents:
        """

        _log.debug('Main config updated')
        _log.debug('ACTION IS {}'.format(action))
        _log.debug('CONTENT IS {}'.format(contents))
        if action == 'DELETE':
            # Remove the registry and keep the service running.
            self.runtime_config = None
            # Now stop the exposition of service.
        else:
            self.runtime_config = self.default_config.copy()
            self.runtime_config.update(contents)

            problems = self._validate_config_params(self.runtime_config)

            if len(problems) > 0:
                _log.error(
                    "The following configuration problems were detected!")
                for p in problems:
                    _log.error(p)
                sys.exit(INVALID_CONFIGURATION_CODE)
            else:
                _log.info('volttron central webroot is: {}'.format(
                    self.runtime_config.get('webroot')
                ))

                users = self.runtime_config.get('users')
                self.web_sessions = SessionHandler(Authenticate(users))

            _log.debug('Querying router for addresses and serverkey.')
            q = Query(self.core)

            external_addresses = q.query('addresses').get(timeout=5)
            self.runtime_config['local_external_address'] = external_addresses[0]

        self.vip.web.register_websocket(r'/vc/ws',
                                        self.open_authenticate_ws_endpoint,
                                        self._ws_closed,
                                        self._ws_received)
        self.vip.web.register_endpoint(r'/jsonrpc', self.jsonrpc)
        self.vip.web.register_path(r'^/.*',
                                   self.runtime_config.get('webroot'))

        # Start scanning for new platforms connections as well as for
        # disconnects that happen.
        self._scan_for_platforms()