Пример #1
0
    def testCreateFrameworkAutoStart(self):
        """
        Tests create_framework(), with specified bundles and auto-start
        """
        # Without bundles
        self.framework = pelix.create_framework([], auto_start=True)
        self.assertEqual(self.framework.get_state(), pelix.Bundle.ACTIVE,
                         "Framework hasn't been started")
        self.assertEqual(self.framework.get_bundles(), [],
                         'Framework is not empty')
        # Clean up
        FrameworkFactory.delete_framework()

        # With bundles
        self.framework = pelix.create_framework([self.test_bundle_name],
                                                auto_start=True)
        self.assertEqual(self.framework.get_state(), pelix.Bundle.ACTIVE,
                         "Framework hasn't been started")
        self.assertEqual(len(self.framework.get_bundles()), 1,
                         'Framework should only have 1 bundle')

        bundle = self.framework.get_bundle_by_id(1)
        self.assertEqual(bundle.get_symbolic_name(), self.test_bundle_name,
                         "The test bundle hasn't been installed correctly")
        self.assertEqual(bundle.get_state(), pelix.Bundle.ACTIVE,
                         "Bundle hasn't been started")
Пример #2
0
    def testCreateFrameworkAutoStart(self):
        """
        Tests create_framework(), with specified bundles and auto-start
        """
        # Without bundles
        self.framework = pelix.create_framework([], auto_start=True)
        self.assertEqual(self.framework.get_state(), pelix.Bundle.ACTIVE,
                         "Framework hasn't been started")
        self.assertEqual(self.framework.get_bundles(), [],
                         'Framework is not empty')
        # Clean up
        FrameworkFactory.delete_framework(self.framework)

        # With bundles
        self.framework = pelix.create_framework([self.test_bundle_name],
                                                auto_start=True)
        self.assertEqual(self.framework.get_state(), pelix.Bundle.ACTIVE,
                         "Framework hasn't been started")
        self.assertEqual(len(self.framework.get_bundles()), 1,
                         'Framework should only have 1 bundle')

        bundle = self.framework.get_bundle_by_id(1)
        self.assertEqual(bundle.get_symbolic_name(), self.test_bundle_name,
                         "The test bundle hasn't been installed correctly")
        self.assertEqual(bundle.get_state(), pelix.Bundle.ACTIVE,
                         "Bundle hasn't been started")
Пример #3
0
def main():
    """
    Entry point
    """
    # Use the utility method to create, run and delete the framework
    pelix.create_framework(('pelix.ipopo.core', 'pelix.shell.core',
                            'pelix.shell.console', 'pelix.shell.ipopo'),
                           None, True, True, True)
Пример #4
0
def main():
    """
    Entry point
    """
    # Use the utility method to create, run and delete the framework
    pelix.create_framework(('pelix.ipopo.core', 'pelix.shell.core',
                            'pelix.shell.console', 'pelix.shell.ipopo'), None,
                           True, True, True)
Пример #5
0
def main():
    """
    Runs the framework
    """
    # Create the framework
    fw = create_framework(
        ('pelix.ipopo.core', 'pelix.shell.core', 'pelix.shell.ipopo',
         'pelix.shell.console', 'dataclass_bundle'))

    # Start the framework and wait for it to stop
    fw.start()

    # Register a service
    ctx = fw.get_bundle_context()
    test_svc = object()
    ctx.register_service("dataclass.check", test_svc, {})

    # Start components
    with use_ipopo(ctx) as ipopo:
        before = ipopo.instantiate("dataclass.before", "before", {})
        after = ipopo.instantiate("dataclass.after", "after", {})

    print("CHECK 'before' injection:", before.requirement is test_svc)
    print("CHECK 'after' injection:", after.requirement is test_svc)

    print("before:")
    print(repr(before))

    print()
    print("after:")
    print(repr(after))

    fw.wait_for_stop()
Пример #6
0
def main(argv=None):
    """
    Entry point

    :param argv: Script arguments (None for sys.argv)
    :return: An exit code or None
    """
    # Parse arguments
    parser = argparse.ArgumentParser(
        prog="pelix.shell.console", parents=[make_common_parser()],
        description="Pelix Shell Console")

    # Parse arguments
    args = parser.parse_args(argv)

    # Handle arguments
    init = handle_common_arguments(args)

    # Set the initial bundles
    bundles = ['pelix.ipopo.core', 'pelix.shell.core', 'pelix.shell.ipopo',
               'pelix.shell.console']
    bundles.extend(init.bundles)

    # Use the utility method to create, run and delete the framework
    framework = pelix.create_framework(
        remove_duplicates(bundles), init.properties)
    framework.start()

    # Instantiate components
    init.instantiate_components(framework.get_bundle_context())

    try:
        framework.wait_for_stop()
    except KeyboardInterrupt:
        framework.stop()
Пример #7
0
def load_framework(transport, components):
    """
    Starts a Pelix framework in the local process

    :param transport: Name of the transport bundle to install
    :param components: Tuples (factory, name) of instances to start
    """
    all_bundles = [
        'pelix.ipopo.core', 'pelix.http.basic', 'pelix.remote.dispatcher',
        'pelix.remote.registry', 'pelix.remote.discovery.multicast', transport
    ]

    # Start the framework
    framework = create_framework(all_bundles)
    framework.start()

    with use_ipopo(framework.get_bundle_context()) as ipopo:
        # Start a HTTP service on a random port
        ipopo.instantiate(pelix.http.FACTORY_HTTP_BASIC, "http-server",
                          {pelix.http.HTTP_SERVICE_PORT: 0})

        ipopo.instantiate(pelix.remote.FACTORY_REGISTRY_SERVLET,
                          "dispatcher-servlet",
                          {pelix.http.HTTP_SERVICE_PORT: 0})

        # Start the multicast discovery
        ipopo.instantiate(pelix.remote.FACTORY_DISCOVERY_MULTICAST,
                          "multicast-discovery")

        # Start other components
        for factory, name in components:
            ipopo.instantiate(factory, name)

    return framework
Пример #8
0
def main():
    # Set the initial bundles
    bundles = (
        "pelix.ipopo.core",
        "pelix.shell.core",
        "pelix.shell.ipopo",
        "pelix.shell.console",
        # RSA implementation
        "pelix.rsa.remoteserviceadmin",
        # Basic topology manager (opt)
        "pelix.rsa.topologymanagers.basic",
        # RSA shell commands (opt)
        "pelix.rsa.shell",
        "pelix.rsa.providers.distribution.py4j",
        "samples.rsa.helloconsumer",
        # Example helloconsumer.  Only uses remote proxies
        "samples.rsa.pbhelloconsumer",
    )

    # Use the utility method to create, run and delete the framework
    framework = pelix.create_framework(
        bundles, {"ecf.py4j.javaport": 25333, "ecf.py4j.pythonport": 25334}
    )
    framework.start()

    try:
        framework.wait_for_stop()
    except KeyboardInterrupt:
        framework.stop()
Пример #9
0
def main():
    # Set the initial bundles
    bundles = (
        "pelix.ipopo.core",
        "pelix.shell.core",
        "pelix.shell.ipopo",
        "pelix.shell.console",
        # RSA implementation
        "pelix.rsa.remoteserviceadmin",
        # Basic topology manager (opt)
        "pelix.rsa.topologymanagers.basic",
        # RSA shell commands (opt)
        "pelix.rsa.shell",
        "pelix.rsa.providers.distribution.py4j",
        "samples.rsa.helloconsumer",
        # Example helloconsumer.  Only uses remote proxies
        "samples.rsa.pbhelloconsumer",
    )

    # Use the utility method to create, run and delete the framework
    framework = pelix.create_framework(bundles, {
        "ecf.py4j.javaport": 25333,
        "ecf.py4j.pythonport": 25334
    })
    framework.start()

    try:
        framework.wait_for_stop()
    except KeyboardInterrupt:
        framework.stop()
Пример #10
0
def load_framework(app_id, transport, components):
    """
    Starts a Pelix framework in the local process

    :param app_id: Application ID
    :param transport: Name of the transport bundle to install
    :param components: Tuples (factory, name) of instances to start
    """
    all_bundles = ['pelix.ipopo.core',
                   'pelix.remote.dispatcher',
                   'pelix.remote.registry',
                   'pelix.remote.discovery.mqtt',
                   transport]

    # Start the framework
    framework = create_framework(all_bundles)
    framework.start()

    with use_ipopo(framework.get_bundle_context()) as ipopo:
        # Start the MQTT discovery
        ipopo.instantiate(pelix.remote.FACTORY_DISCOVERY_MQTT,
                          "mqtt-discovery", {"mqtt.host": MQTT_SERVER,
                                             "application.id": app_id})

        # Start other components
        for factory, name in components:
            ipopo.instantiate(factory, name, {"mqtt.host": MQTT_SERVER})

    return framework
Пример #11
0
def load_framework(app_id, transport, components):
    """
    Starts a Pelix framework in the local process

    :param app_id: Application ID
    :param transport: Name of the transport bundle to install
    :param components: Tuples (factory, name) of instances to start
    """
    all_bundles = ['pelix.ipopo.core',
                   'pelix.remote.dispatcher',
                   'pelix.remote.registry',
                   'pelix.remote.discovery.mqtt',
                   transport]

    # Start the framework
    framework = create_framework(all_bundles)
    framework.start()

    with use_ipopo(framework.get_bundle_context()) as ipopo:
        # Start the MQTT discovery
        ipopo.instantiate(pelix.remote.FACTORY_DISCOVERY_MQTT,
                          "mqtt-discovery", {"mqtt.host": MQTT_SERVER,
                                             "application.id": app_id})

        # Start other components
        for factory, name in components:
            ipopo.instantiate(factory, name, {"mqtt.host": MQTT_SERVER})

    return framework
Пример #12
0
def main():
    """
    Runs the framework
    """
    # Create the framework
    fw = create_framework(
        ('pelix.ipopo.core', 'pelix.shell.core',
         'pelix.shell.ipopo', 'pelix.shell.console',
         'dataclass_bundle'))

    # Start the framework and wait for it to stop
    fw.start()

    # Register a service
    ctx = fw.get_bundle_context()
    test_svc = object()
    ctx.register_service("dataclass.check", test_svc, {})

    # Start components
    with use_ipopo(ctx) as ipopo:
        before = ipopo.instantiate("dataclass.before", "before", {})
        after = ipopo.instantiate("dataclass.after", "after", {})

    print("CHECK 'before' injection:", before.requirement is test_svc)
    print("CHECK 'after' injection:", after.requirement is test_svc)

    print("before:")
    print(repr(before))

    print()
    print("after:")
    print(repr(after))

    fw.wait_for_stop()
Пример #13
0
def main(argv=None):
    """
    Entry point

    :param argv: Script arguments (None for sys.argv)
    :return: An exit code or None
    """
    # Parse arguments
    parser = argparse.ArgumentParser(
        prog="pelix.shell.console", parents=[make_common_parser()],
        description="Pelix Shell Console")

    # Parse arguments
    args = parser.parse_args(argv)

    # Handle arguments
    init = handle_common_arguments(args)

    # Set the initial bundles
    bundles = ['pelix.ipopo.core', 'pelix.shell.core', 'pelix.shell.ipopo',
               'pelix.shell.console']
    bundles.extend(init.bundles)

    # Use the utility method to create, run and delete the framework
    framework = pelix.create_framework(
        remove_duplicates(bundles), init.properties)
    framework.start()

    # Instantiate components
    init.instantiate_components(framework.get_bundle_context())

    try:
        framework.wait_for_stop()
    except KeyboardInterrupt:
        framework.stop()
Пример #14
0
 def setUp(self):
     """
     Sets up the test environment
     """
     # Start a framework
     self.framework = create_framework(['pelix.http.basic'])
     self.framework.start()
     self.ipopo = install_ipopo(self.framework)
     self.http = instantiate_server(self.ipopo)
Пример #15
0
    def setUp(self):
        """
        Starts a framework and install the shell bundle
        """
        # Start the framework
        self.framework = create_framework(['pelix.shell.core'])
        self.framework.start()
        self.context = self.framework.get_bundle_context()

        svc_ref = self.context.get_service_reference(SERVICE_SHELL)
        self.shell = self.context.get_service(svc_ref)
Пример #16
0
    def setUp(self):
        """
        Starts a framework and install the shell bundle
        """
        # Start the framework
        self.framework = create_framework(['pelix.shell.core'])
        self.framework.start()
        self.context = self.framework.get_bundle_context()

        svc_ref = self.context.get_service_reference(SERVICE_SHELL)
        self.shell = self.context.get_service(svc_ref)
Пример #17
0
 def setUp(self):
     """
     Starts a framework and install the shell bundle
     """
     # Start the framework
     self.framework = create_framework(
         ('pelix.ipopo.core', 'pelix.shell.core', 'pelix.shell.remote'))
     self.framework.start()
     context = self.framework.get_bundle_context()
     # Get the core shell service
     svc_ref = context.get_service_reference(SERVICE_SHELL)
     self.shell = context.get_service(svc_ref)
Пример #18
0
    def testCreateFrameworkBasic(self):
        """
        Tests create_framework(), without parameters
        -> creates an empty framework, and doesn't start it
        """
        self.framework = pelix.create_framework([])
        self.assertEqual(self.framework.get_state(), pelix.Bundle.RESOLVED,
                         'Framework has been started')
        self.assertEqual(self.framework.get_bundles(), [],
                         'Framework is not empty')

        # Try to start two framework
        self.assertRaises(ValueError, pelix.create_framework, [])
Пример #19
0
    def testCreateFrameworkBasic(self):
        """
        Tests create_framework(), without parameters
        -> creates an empty framework, and doesn't start it
        """
        self.framework = pelix.create_framework([])
        self.assertEqual(self.framework.get_state(), pelix.Bundle.RESOLVED,
                         'Framework has been started')
        self.assertEqual(self.framework.get_bundles(), [],
                         'Framework is not empty')

        # Try to start two framework
        self.assertRaises(ValueError, pelix.create_framework, [])
Пример #20
0
    def testCreateFrameworkWithBundles(self):
        """
        Tests create_framework(), with specified bundles
        """
        self.framework = pelix.create_framework([self.test_bundle_name])
        self.assertEqual(self.framework.get_state(), pelix.Bundle.RESOLVED,
                         'Framework has been started')

        self.assertEqual(len(self.framework.get_bundles()), 1,
                         'Framework should only have 1 bundle')

        bundle = self.framework.get_bundle_by_id(1)
        self.assertEqual(bundle.get_symbolic_name(), self.test_bundle_name,
                         "The test bundle hasn't been installed correctly")
Пример #21
0
    def testCreateFrameworkWithBundles(self):
        """
        Tests create_framework(), with specified bundles
        """
        self.framework = pelix.create_framework([self.test_bundle_name])
        self.assertEqual(self.framework.get_state(), pelix.Bundle.RESOLVED,
                         'Framework has been started')

        self.assertEqual(len(self.framework.get_bundles()), 1,
                         'Framework should only have 1 bundle')

        bundle = self.framework.get_bundle_by_id(1)
        self.assertEqual(bundle.get_symbolic_name(), self.test_bundle_name,
                         "The test bundle hasn't been installed correctly")
Пример #22
0
def main():
    # Define the initial bundles
    bundles = (
        "pelix.ipopo.core",
        "pelix.shell.core",
        "pelix.shell.ipopo",
        "pelix.shell.console",
        # RSA implementation
        "pelix.rsa.remoteserviceadmin",
        # HTTP Service
        "pelix.http.basic",
        # XML-RPC distribution provider (opt)
        "pelix.rsa.providers.distribution.xmlrpc",
        # etcd discovery provider (opt)
        "pelix.rsa.providers.discovery.discovery_etcd",
        # Basic topology manager (opt)
        "pelix.rsa.topologymanagers.basic",
        # RSA shell commands (opt)
        "pelix.rsa.shell",
        # Example helloconsumer. Only uses remote proxies
        "samples.rsa.helloconsumer_xmlrpc",
    )

    # Use the utility method to create, run and delete the framework
    framework = pelix.create_framework(
        bundles,
        {
            "etcd.hostname": ETCD_HOSTNAME,
            "ecf.xmlrpc.server.hostname": HTTP_HOSTNAME,
        },
    )
    framework.start()

    with use_ipopo(framework.get_bundle_context()) as ipopo:
        ipopo.instantiate(
            "pelix.http.service.basic.factory",
            "http-server",
            {
                "pelix.http.address": HTTP_HOSTNAME,
                "pelix.http.port": HTTP_PORT
            },
        )
    try:
        framework.wait_for_stop()
    except KeyboardInterrupt:
        framework.stop()
Пример #23
0
    def setUp(self):
        """
        Starts a framework in separate process to advertise a helloimpl
        remote service.  Then starts a local framework to register the
        TestEndpointEventListener
        """
        print(
            "EtcdDiscoveryListenerTest etcd_hostname={0},toppath={1}".format(
                TEST_ETCD_HOSTNAME, TEST_ETCD_TOPPATH
            )
        )
        # start external framework that publishes remote service
        self.status_queue = Queue()
        self.publisher_process = WrappedProcess(
            target=start_framework_for_advertise, args=[self.status_queue]
        )
        self.publisher_process.start()
        state = self.status_queue.get(10)
        self.assertEqual(state, "ready")

        # start a local framework
        self.framework = create_framework(
            [
                "pelix.ipopo.core",
                "pelix.rsa.remoteserviceadmin",  # RSA implementation
                "tests.rsa.endpoint_event_listener",
                "pelix.rsa.providers.discovery.discovery_etcd",
            ],
            {
                "etcd.hostname": TEST_ETCD_HOSTNAME,
                "etcd.toppath": TEST_ETCD_TOPPATH,
            },
        )
        self.framework.start()
        # Start the framework and return TestEndpointEventListener
        context = self.framework.get_bundle_context()
        # Start an HTTP server, required by XML-RPC
        with use_ipopo(context) as ipopo:
            #  create endpoint event listener
            self.listener = ipopo.instantiate(
                "etcd-test-endpoint-event-listener-factory",
                "etcd-test-endpoint-event-listener",
                {
                    TopologyManager.ENDPOINT_LISTENER_SCOPE: ENDPOINT_LISTENER_SCOPE
                },
            )
Пример #24
0
    def test_service_import(self):
        """
        Tests the import of a service from Py4J
        """
        bundles = [
            "pelix.ipopo.core",
            "pelix.rsa.remoteserviceadmin",
            "pelix.rsa.topologymanagers.basic",
            "pelix.rsa.providers.distribution.py4j",
            "samples.rsa.helloconsumer",
        ]

        with use_karaf():
            # Start the framework
            fw = create_framework(
                bundles,
                {
                    "ecf.py4j.javaport": 25333,
                    "ecf.py4j.pythonport": 25334
                },
            )

            try:
                fw.start()
                bc = fw.get_bundle_context()

                for _ in range(10):
                    # Check if we find the Hello world service
                    svc_ref = bc.get_service_reference(
                        "org.eclipse.ecf.examples.hello.IHello",
                        "(service.imported=*)",
                    )
                    if svc_ref is not None:
                        # Found the service reference: service imported
                        break

                    time.sleep(.5)
                else:
                    # Service not found after 5 seconds
                    self.fail("Py4J service not found")
            finally:
                # Clean up the framework
                fw.delete(True)
Пример #25
0
    def setUp(self):
        """
        Starts a framework in separate process to advertise a helloimpl
        remote service.  Then starts a local framework to register the
        TestEndpointEventListener
        """
        print("EtcdDiscoveryListenerTest etcd_hostname={0},toppath={1}".format(
            TEST_ETCD_HOSTNAME, TEST_ETCD_TOPPATH))
        # start external framework that publishes remote service
        self.status_queue = Queue()
        self.publisher_process = WrappedProcess(
            target=start_framework_for_advertise, args=[self.status_queue])
        self.publisher_process.start()
        state = self.status_queue.get(10)
        self.assertEqual(state, "ready")

        # start a local framework
        self.framework = create_framework(
            [
                "pelix.ipopo.core",
                "pelix.rsa.remoteserviceadmin",  # RSA implementation
                "tests.rsa.endpoint_event_listener",
                "pelix.rsa.providers.discovery.discovery_etcd",
            ],
            {
                "etcd.hostname": TEST_ETCD_HOSTNAME,
                "etcd.toppath": TEST_ETCD_TOPPATH,
            },
        )
        self.framework.start()
        # Start the framework and return TestEndpointEventListener
        context = self.framework.get_bundle_context()
        # Start an HTTP server, required by XML-RPC
        with use_ipopo(context) as ipopo:
            #  create endpoint event listener
            self.listener = ipopo.instantiate(
                "etcd-test-endpoint-event-listener-factory",
                "etcd-test-endpoint-event-listener",
                {
                    TopologyManager.ENDPOINT_LISTENER_SCOPE:
                    ENDPOINT_LISTENER_SCOPE
                },
            )
Пример #26
0
def main():
    # Define the initial bundles
    bundles = (
        "pelix.ipopo.core",
        "pelix.shell.core",
        "pelix.shell.ipopo",
        "pelix.shell.console",
        # RSA implementation
        "pelix.rsa.remoteserviceadmin",
        # HTTP Service
        "pelix.http.basic",
        # XML-RPC distribution provider (opt)
        "pelix.rsa.providers.distribution.xmlrpc",
        # etcd discovery provider (opt)
        "pelix.rsa.providers.discovery.discovery_etcd",
        # Basic topology manager (opt)
        "pelix.rsa.topologymanagers.basic",
        # RSA shell commands (opt)
        "pelix.rsa.shell",
        # Example helloconsumer. Only uses remote proxies
        "samples.rsa.helloconsumer_xmlrpc",
    )

    # Use the utility method to create, run and delete the framework
    framework = pelix.create_framework(
        bundles,
        {
            "etcd.hostname": ETCD_HOSTNAME,
            "ecf.xmlrpc.server.hostname": HTTP_HOSTNAME,
        },
    )
    framework.start()

    with use_ipopo(framework.get_bundle_context()) as ipopo:
        ipopo.instantiate(
            "pelix.http.service.basic.factory",
            "http-server",
            {"pelix.http.address": HTTP_HOSTNAME, "pelix.http.port": HTTP_PORT},
        )
    try:
        framework.wait_for_stop()
    except KeyboardInterrupt:
        framework.stop()
Пример #27
0
    def setUp(self):
        """
        Starts a framework and install the shell bundle
        """
        # Start the framework
        self.framework = create_framework(
            ('pelix.ipopo.core', 'pelix.shell.core', 'pelix.shell.remote'))
        self.framework.start()
        context = self.framework.get_bundle_context()
        # Get the core shell service
        svc_ref = context.get_service_reference(SERVICE_SHELL)
        self.shell = context.get_service(svc_ref)

        # Start the remote shell
        with use_ipopo(context) as ipopo:
            self.remote = ipopo.instantiate(
                FACTORY_REMOTE_SHELL, "remoteShell", {
                    'pelix.shell.address': '127.0.0.1',
                    'pelix.shell.port': 9000
                })
Пример #28
0
    def setUp(self):
        """
        Starts a framework and install the shell bundle
        """
        # Start the framework
        self.framework = create_framework(('pelix.ipopo.core',
                                           'pelix.shell.core',
                                           'pelix.shell.remote'))
        self.framework.start()
        context = self.framework.get_bundle_context()
        # Get the core shell service
        svc_ref = context.get_service_reference(SERVICE_SHELL)
        self.shell = context.get_service(svc_ref)

        # Start the remote shell
        with use_ipopo(context) as ipopo:
            self.remote = ipopo.instantiate(
                FACTORY_REMOTE_SHELL, "remoteShell",
                {'pelix.shell.address': '127.0.0.1',
                 'pelix.shell.port': 9000})
Пример #29
0
def load_framework(transport, discovery, components):
    """
    Starts a Pelix framework in the local process

    :param transport: Name of the transport bundle to install
    :param discovery: Name of the discovery bundle to install
    :param components: Tuples (factory, name) of instances to start
    """
    all_bundles = ['pelix.ipopo.core',
                   'pelix.http.basic',
                   'pelix.remote.dispatcher',
                   'pelix.remote.registry',
                   discovery,
                   transport]

    # Start the framework
    framework = create_framework(all_bundles)
    framework.start()

    with use_ipopo(framework.get_bundle_context()) as ipopo:
        # Start a HTTP service on a random port
        ipopo.instantiate(pelix.http.FACTORY_HTTP_BASIC,
                          "http-server",
                          {pelix.http.HTTP_SERVICE_ADDRESS: "0.0.0.0",
                           pelix.http.HTTP_SERVICE_PORT: 0})

        ipopo.instantiate(pelix.remote.FACTORY_REGISTRY_SERVLET,
                          "dispatcher-servlet")

        # Start other components
        for component in components:
            try:
                factory, name, opts = component
            except ValueError:
                factory, name = component
                opts = {}

            ipopo.instantiate(factory, name, opts)

    return framework
Пример #30
0
def load_framework(transport, discovery, components):
    """
    Starts a Pelix framework in the local process

    :param transport: Name of the transport bundle to install
    :param discovery: Name of the discovery bundle to install
    :param components: Tuples (factory, name) of instances to start
    """
    all_bundles = [
        'pelix.ipopo.core', 'pelix.http.basic', 'pelix.remote.dispatcher',
        'pelix.remote.registry', discovery, transport
    ]

    # Start the framework
    framework = create_framework(all_bundles)
    framework.start()

    with use_ipopo(framework.get_bundle_context()) as ipopo:
        # Start a HTTP service on a random port
        ipopo.instantiate(
            pelix.http.FACTORY_HTTP_BASIC, "http-server", {
                pelix.http.HTTP_SERVICE_ADDRESS: "0.0.0.0",
                pelix.http.HTTP_SERVICE_PORT: 0
            })

        ipopo.instantiate(pelix.remote.FACTORY_REGISTRY_SERVLET,
                          "dispatcher-servlet")

        # Start other components
        for component in components:
            try:
                factory, name, opts = component
            except ValueError:
                factory, name = component
                opts = {}

            ipopo.instantiate(factory, name, opts)

    return framework
Пример #31
0
    def setUp(self):
        """
        Starts a framework and install the shell bundle
        """
        # Start the framework
        self.framework = create_framework(
            ['pelix.shell.core', 'pelix.shell.report'])
        self.framework.start()
        self.context = self.framework.get_bundle_context()

        # Shell service
        svc_ref = self.context.get_service_reference(SERVICE_SHELL)
        self.shell = self.context.get_service(svc_ref)

        # Report service
        svc_ref = self.context.get_service_reference(SERVICE_SHELL_REPORT)
        self.report = self.context.get_service(svc_ref)

        # Output file
        self.out_file = 'report_output.js'
        if os.path.exists(self.out_file):
            os.remove(self.out_file)
Пример #32
0
def load_framework(transport, components, start_server=True):
    """
    Starts a Pelix framework in the local process

    :param transport: Name of the transport bundle to install
    :param components: Tuples (factory, name) of instances to start
    """
    all_bundles = ['pelix.ipopo.core',
                   'pelix.http.basic',
                   'pelix.remote.dispatcher',
                   'pelix.remote.registry',
                   'pelix.remote.discovery.multicast',
                   transport]

    # Start the framework
    framework = create_framework(all_bundles)
    framework.start()

    with use_ipopo(framework.get_bundle_context()) as ipopo:
        if start_server:
            # Start a HTTP service on a random port
            ipopo.instantiate(pelix.http.FACTORY_HTTP_BASIC,
                              "http-server",
                              {pelix.http.HTTP_SERVICE_ADDRESS: "0.0.0.0",
                               pelix.http.HTTP_SERVICE_PORT: 0})

        ipopo.instantiate(pelix.remote.FACTORY_REGISTRY_SERVLET,
                          "dispatcher-servlet")

        # Start the multicast discovery
        ipopo.instantiate(pelix.remote.FACTORY_DISCOVERY_MULTICAST,
                          "multicast-discovery")

        # Start other components
        for factory, name in components:
            ipopo.instantiate(factory, name)

    return framework
Пример #33
0
def start_framework_for_advertise(state_queue):
    """
    Starts a Pelix framework to advertise (via etcd) a helloimpl_xmlrpc
    remote service instance.  The tests can/will then discover this
    service advertisement and test the EndpointEventListener notification

    :param state_queue: Queue to communicate status and terminate
    """
    try:
        # Start the framework
        framework = create_framework(
            [
                "pelix.ipopo.core",
                "pelix.rsa.remoteserviceadmin",  # RSA implementation
                "pelix.http.basic",  # httpservice
                # xmlrpc distribution provider (opt)
                "pelix.rsa.providers.distribution.xmlrpc",
                # etcd discovery provider (opt)
                "pelix.rsa.providers.discovery.discovery_etcd",
                "pelix.rsa.topologymanagers.basic",
                "samples.rsa.helloimpl_xmlrpc",
            ],
            {
                "ecf.xmlrpc.server.hostname": "localhost",
                "etcd.hostname": TEST_ETCD_HOSTNAME,
                "etcd.toppath": TEST_ETCD_TOPPATH,
            },
        )
        framework.start()

        context = framework.get_bundle_context()
        # Start an HTTP server, required by XML-RPC
        with use_ipopo(context) as ipopo:
            ipopo.instantiate(
                "pelix.http.service.basic.factory",
                "http-server",
                {"pelix.http.address": "localhost", "pelix.http.port": 0},
            )

        bc = framework.get_bundle_context()
        rsa = bc.get_service(
            bc.get_service_reference("pelix.rsa.remoteserviceadmin", None)
        )
        # export the hello remote service via rsa
        # with the BasicTopologyManager, this will result
        # in publish via etcd
        rsa.export_service(
            bc.get_service_reference("org.eclipse.ecf.examples.hello.IHello"),
            {
                "service.exported.interfaces": "*",
                "service.exported.configs": "ecf.xmlrpc.server",
            },
        )
        # Send that we are now ready
        state_queue.put("ready")
        # Loop until ready processed
        while True:
            if state_queue.empty():
                break
        # Loop until we receive done message
        while True:
            state = state_queue.get()
            if state is None:
                break
        # stop the framework gracefully
        framework.stop()
    except Exception as ex:
        state_queue.put("Error: {0}".format(ex))
Пример #34
0
def main(argv=None):
    """
    Entry point

    :param argv: Script arguments (None for sys.argv)
    :return: An exit code (0 by default)
    """
    # Parse arguments
    parser = argparse.ArgumentParser(description="Pelix Shell Console")

    # Version number
    parser.add_argument("--version",
                        action="version",
                        version="Pelix {0} from {1}".format(
                            pelix.__version__, pelix.__file__))

    # Framework options
    group = parser.add_argument_group("Framework options")
    group.add_argument("-D",
                       nargs="+",
                       dest="properties",
                       metavar="KEY=VALUE",
                       help="Sets framework properties")
    group.add_argument("-v",
                       "--verbose",
                       action="store_true",
                       dest="verbose",
                       help="Set loggers to DEBUG level")

    # Initial script
    group = parser.add_argument_group("Script execution arguments")
    group.add_argument(
        "--init",
        action="store",
        dest="init_script",
        metavar="SCRIPT",
        help="Runs the given shell script before starting the console")
    group.add_argument(
        "--run",
        action="store",
        dest="run_script",
        metavar="SCRIPT",
        help="Runs the given shell script then stops the framework")

    # Parse arguments
    args = parser.parse_args(argv)

    # Setup the logger
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    # Compute framework properties
    fw_props = {}
    if args.properties:
        for prop_def in args.properties:
            key, value = prop_def.split('=', 1)
            fw_props[key] = value

    # Check initial script(s)
    if args.init_script:
        init_file_path = _resolve_file(args.init_script)
        if not init_file_path:
            sys.stderr.write("Initial script file not found: {0}\n".format(
                args.init_script))
            sys.stderr.flush()
            return 1
        else:
            fw_props[PROP_INIT_FILE] = init_file_path

    if args.run_script:
        run_file_path = _resolve_file(args.run_script)
        if not run_file_path:
            sys.stderr.write("Script file not found: {0}\n".format(
                args.run_script))
            sys.stderr.flush()
            return 1
        else:
            fw_props[PROP_RUN_FILE] = run_file_path

    # Use the utility method to create, run and delete the framework
    framework = pelix.create_framework(
        ('pelix.ipopo.core', 'pelix.shell.core', 'pelix.shell.console',
         'pelix.shell.ipopo'), fw_props)
    framework.start()

    try:
        framework.wait_for_stop()
    except KeyboardInterrupt:
        framework.stop()
    return 0
Пример #35
0
def main(argv=None):
    """
    Entry point

    :param argv: Script arguments (None for sys.argv)
    :return: An exit code (0 by default)
    """
    # Parse arguments
    parser = argparse.ArgumentParser(description="Pelix Shell Console")

    # Version number
    parser.add_argument(
        "--version", action="version",
        version="Pelix {0} from {1}".format(pelix.__version__, pelix.__file__))

    # Framework options
    group = parser.add_argument_group("Framework options")
    group.add_argument(
        "-D", nargs="+", dest="properties", metavar="KEY=VALUE",
        help="Sets framework properties")
    group.add_argument(
        "-v", "--verbose", action="store_true", dest="verbose",
        help="Set loggers to DEBUG level")

    # Initial script
    group = parser.add_argument_group("Script execution arguments")
    group.add_argument(
        "--init", action="store", dest="init_script", metavar="SCRIPT",
        help="Runs the given shell script before starting the console")
    group.add_argument(
        "--run", action="store", dest="run_script", metavar="SCRIPT",
        help="Runs the given shell script then stops the framework")

    # Parse arguments
    args = parser.parse_args(argv)

    # Setup the logger
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    # Compute framework properties
    fw_props = {}
    if args.properties:
        for prop_def in args.properties:
            key, value = prop_def.split('=', 1)
            fw_props[key] = value

    # Check initial script(s)
    if args.init_script:
        init_file_path = _resolve_file(args.init_script)
        if not init_file_path:
            sys.stderr.write("Initial script file not found: {0}\n"
                             .format(args.init_script))
            sys.stderr.flush()
            return 1
        else:
            fw_props[PROP_INIT_FILE] = init_file_path

    if args.run_script:
        run_file_path = _resolve_file(args.run_script)
        if not run_file_path:
            sys.stderr.write("Script file not found: {0}\n"
                             .format(args.run_script))
            sys.stderr.flush()
            return 1
        else:
            fw_props[PROP_RUN_FILE] = run_file_path

    # Use the utility method to create, run and delete the framework
    framework = pelix.create_framework(
        ('pelix.ipopo.core', 'pelix.shell.core',
         'pelix.shell.console', 'pelix.shell.ipopo'),
        fw_props)
    framework.start()

    try:
        framework.wait_for_stop()
    except KeyboardInterrupt:
        framework.stop()
    return 0
Пример #36
0
def main(pip, pport):
    """
    Main entry point
    """
    # We need this broker to be able to construct
    # NAOqi modules and subscribe to other modules
    # The broker must stay alive until the program exists
    al_broker = ALBroker(
        "myBroker",
        "0.0.0.0",  # listen to anyone
        0,  # find a free port and use it
        pip,  # parent broker IP
        pport)  # parent broker port

    # Create the Pelix framework
    framework = create_framework((
        # iPOPO
        'pelix.ipopo.core',

        # Shell bundles
        'pelix.shell.core',
        'pelix.shell.console',
        'pelix.shell.remote',
        'pelix.shell.ipopo',

        # ConfigurationAdmin
        'pelix.services.configadmin',
        'pelix.shell.configadmin',

        # EventAdmin,
        'pelix.services.eventadmin',
        'pelix.shell.eventadmin',

        # Nao Internals
        'internals.mqtt',
        'internals.speech',
        'internals.touch',
        'internals.tts',

        # Nao Demo
        'nao.behaviour',
        'nao.hue',
        'nao.leds',
        'nao.radio',
        'nao.teller',

        # Shell
        'shell.behaviour',
        'shell.hue',
        'shell.speech',
        'shell.teller'))

    # Start the framework
    framework.start()

    # Instantiate EventAdmin
    with use_ipopo(framework.get_bundle_context()) as ipopo:
        ipopo.instantiate(pelix.services.FACTORY_EVENT_ADMIN, 'event-admin', {})

    try:
        # Wait for the framework to stop
        framework.wait_for_stop()
    except KeyboardInterrupt:
        print("Interrupted by user, shutting down")
        framework.stop()
        al_broker.shutdown()
        sys.exit(0)
Пример #37
0
def init(root_dir=None, port=9000):
    """ """
    global item_manager
    global context

    # Create the Pelix framework
    framework = create_framework((
        # iPOPO
        'pelix.ipopo.core',

        # Shell bundles
        'pelix.shell.core',
        'pelix.shell.console',
        'pelix.shell.remote',
        'pelix.shell.ipopo',

        # ConfigurationAdmin
        'pelix.services.configadmin',
        'pelix.shell.configadmin',

        # EventAdmin,
        'pelix.services.eventadmin',
        'pelix.shell.eventadmin',
        'ycappuccino.core.bundles.managers',
        'ycappuccino.core.bundles.item_manager',
        'ycappuccino.core.bundles.configuration',
        'ycappuccino.core.bundles.jwt',
        'ycappuccino.core.bundles.endpoints',
        'ycappuccino.core.bundles.indexEndpoint',
        'ycappuccino.core.bundles.activity_logger',
        'ycappuccino.core.bundles.proxy',
        'ycappuccino.core.bundles.core_bootstrap',

        # bundle core model
        'ycappuccino.core.model.account',
        'ycappuccino.core.model.login',
        'ycappuccino.core.model.role',
        'ycappuccino.core.model.model'))

    # Start the framework
    framework.start()

    # Instantiate EventAdmin
    with use_ipopo(framework.get_bundle_context()) as ipopo:
        ipopo.instantiate(pelix.services.FACTORY_EVENT_ADMIN, 'event-admin',
                          {})

    context = framework.get_bundle_context()

    # retrieve item_manager

    # install custom
    # load ycappuccino
    w_root = ""
    if root_dir is None:
        root_dir = os.getcwd()
    for w_elem in root_dir.split("/"):
        w_root = w_root + "/" + w_elem

    utils.find_and_install_bundle(w_root, "", context)

    # Install & start iPOPO
    context.install_bundle('pelix.ipopo.core').start()

    # Install & start the basic HTTP service
    context.install_bundle('pelix.http.basic').start()

    # Instantiate a HTTP service component
    with use_ipopo(context) as ipopo:
        ipopo.instantiate('pelix.http.service.basic.factory', 'http-server',
                          {'pelix.http.port': port})

    item_manager.load_item()
    w_finder.set_context(context)
    try:
        # Wait for the framework to stop
        framework.wait_for_stop()
    except KeyboardInterrupt:
        print("Interrupted by user, shutting down")
        framework.stop()
        sys.exit(0)
Пример #38
0
def start_framework_for_advertise(state_queue):
    """
    Starts a Pelix framework to advertise (via etcd) a helloimpl_xmlrpc
    remote service instance.  The tests can/will then discover this
    service advertisement and test the EndpointEventListener notification

    :param state_queue: Queue to communicate status and terminate
    """
    try:
        # Start the framework
        framework = create_framework(
            [
                "pelix.ipopo.core",
                "pelix.rsa.remoteserviceadmin",  # RSA implementation
                "pelix.http.basic",  # httpservice
                # xmlrpc distribution provider (opt)
                "pelix.rsa.providers.distribution.xmlrpc",
                # etcd discovery provider (opt)
                "pelix.rsa.providers.discovery.discovery_etcd",
                "pelix.rsa.topologymanagers.basic",
                "samples.rsa.helloimpl_xmlrpc",
            ],
            {
                "ecf.xmlrpc.server.hostname": "localhost",
                "etcd.hostname": TEST_ETCD_HOSTNAME,
                "etcd.toppath": TEST_ETCD_TOPPATH,
            },
        )
        framework.start()

        context = framework.get_bundle_context()
        # Start an HTTP server, required by XML-RPC
        with use_ipopo(context) as ipopo:
            ipopo.instantiate(
                "pelix.http.service.basic.factory",
                "http-server",
                {
                    "pelix.http.address": "localhost",
                    "pelix.http.port": 0
                },
            )

        bc = framework.get_bundle_context()
        rsa = bc.get_service(
            bc.get_service_reference("pelix.rsa.remoteserviceadmin", None))
        # export the hello remote service via rsa
        # with the BasicTopologyManager, this will result
        # in publish via etcd
        rsa.export_service(
            bc.get_service_reference("org.eclipse.ecf.examples.hello.IHello"),
            {
                "service.exported.interfaces": "*",
                "service.exported.configs": "ecf.xmlrpc.server",
            },
        )
        # Send that we are now ready
        state_queue.put("ready")
        # Loop until ready processed
        while True:
            if state_queue.empty():
                break
        # Loop until we receive done message
        while True:
            state = state_queue.get()
            if state is None:
                break
        # stop the framework gracefully
        framework.stop()
    except Exception as ex:
        state_queue.put("Error: {0}".format(ex))
Пример #39
0
def main(pip, pport):
    """
    Main entry point
    """
    # We need this broker to be able to construct
    # NAOqi modules and subscribe to other modules
    # The broker must stay alive until the program exists
    myBroker = ALBroker("myBroker",
       "0.0.0.0",  # listen to anyone
       0,  # find a free port and use it
       pip,  # parent broker IP
       pport)  # parent broker port

    # Warning: HumanGreeter must be a global variable
    # The name given to the constructor must be the name of the
    # variable
    global HumanGreeter
    HumanGreeter = NaoTouchModule("HumanGreeter")

    # Create the Pelix framework
    framework = create_framework((# iPOPO
                                  'pelix.ipopo.core',

                                  # Shell bundles
                                  'pelix.shell.core',
                                  'pelix.shell.console',
                                  'pelix.shell.remote',
                                  'pelix.shell.ipopo',

                                  # HTTP Service
                                  'pelix.http.basic',

                                  # Remote Services
                                  'pelix.remote.dispatcher',
                                  'pelix.remote.registry',
                                  'pelix.remote.discovery.multicast',
                                  'pelix.remote.json_rpc',

                                  # ConfigurationAdmin
                                  'pelix.services.configadmin',
                                  'pelix.shell.configadmin',

                                  # MQTT
                                  'pelix.services.mqtt',

                                  # Nao
                                  'nao.shell',
                                  'nao.hue',
                                  'nao.teller',
                                  'nao.binder'))
    framework.start()
    context = framework.get_bundle_context()

    # Register the ALModule as a service
    context.register_service("nao.core", HumanGreeter, {})

    # Instantiate basic components
    with use_ipopo(context) as ipopo:
        # ... Remote Shell
        ipopo.instantiate("ipopo-remote-shell-factory",
                          "ipopo-remote-shell",
                          {"pelix.shell.port": 9000})

        # ... HTTP Service on a random port
        ipopo.instantiate("pelix.http.service.basic.factory",
                          "pelix-http-basic",
                          {"pelix.http.port": 0})

        # Dispatcher servlet (for the multicast discovery)
        ipopo.instantiate("pelix-remote-dispatcher-servlet-factory",
                          "pelix-remote-dispatcher-servlet", {})

        # Multicast discovery
        ipopo.instantiate('pelix-remote-discovery-multicast-factory',
                          'pelix-remote-discovery-multicast', {})

        # JSON-RPC transport
        ipopo.instantiate("pelix-jsonrpc-exporter-factory",
                          "pelix-jsonrpc-exporter", {})
        ipopo.instantiate("pelix-jsonrpc-importer-factory",
                          "pelix-jsonrpc-importer", {})

    try:
        # Wait for the framework to stop
        framework.wait_for_stop()

    except KeyboardInterrupt:
        print("Interrupted by user, shutting down")
        framework.stop()
        myBroker.shutdown()
        sys.exit(0)