Search in sources :

Example 16 with DiscoveryEntry

use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.

the class CapabilitiesRegistrarTest method registerWithCapRegistrar.

@SuppressWarnings("unchecked")
@Test
public void registerWithCapRegistrar() {
    JoynrVersion currentJoynrVersion = (JoynrVersion) TestProvider.class.getAnnotation(JoynrVersion.class);
    Version testVersion = new Version(currentJoynrVersion.major(), currentJoynrVersion.minor());
    when(providerContainer.getInterfaceName()).thenReturn(TestProvider.INTERFACE_NAME);
    RequestCaller requestCallerMock = mock(RequestCaller.class);
    when(providerContainer.getRequestCaller()).thenReturn(requestCallerMock);
    when(providerContainer.getSubscriptionPublisher()).thenReturn(subscriptionPublisher);
    when(participantIdStorage.getProviderParticipantId(eq(domain), eq(TestProvider.INTERFACE_NAME))).thenReturn(participantId);
    when(providerContainerFactory.create(testProvider)).thenReturn(providerContainer);
    ArgumentCaptor<DiscoveryEntry> discoveryEntryCaptor = ArgumentCaptor.forClass(DiscoveryEntry.class);
    registrar.registerProvider(domain, testProvider, providerQos);
    verify(localDiscoveryAggregator).add(any(Callback.class), discoveryEntryCaptor.capture());
    DiscoveryEntry actual = discoveryEntryCaptor.getValue();
    Assert.assertEquals(actual.getProviderVersion(), testVersion);
    Assert.assertEquals(actual.getDomain(), domain);
    Assert.assertEquals(actual.getInterfaceName(), TestProvider.INTERFACE_NAME);
    Assert.assertEquals(actual.getParticipantId(), participantId);
    Assert.assertEquals(actual.getQos(), providerQos);
    Assert.assertTrue((System.currentTimeMillis() - actual.getLastSeenDateMs()) < 5000);
    Assert.assertTrue((actual.getExpiryDateMs() - expiryDateMs) < 5000);
    Assert.assertEquals(actual.getPublicKeyId(), publicKeyId);
    verify(providerDirectory).add(eq(participantId), eq(providerContainer));
}
Also used : RequestCaller(io.joynr.dispatching.RequestCaller) DiscoveryEntry(joynr.types.DiscoveryEntry) Callback(io.joynr.proxy.Callback) JoynrVersion(io.joynr.JoynrVersion) JoynrVersion(io.joynr.JoynrVersion) Version(joynr.types.Version) Test(org.junit.Test)

Example 17 with DiscoveryEntry

use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.

the class ClusterController method main.

public static void main(String[] args) {
    int port = 4242;
    String host = "localhost";
    String transport = null;
    String brokerUri = null;
    Options options = new Options();
    Options helpOptions = new Options();
    setupOptions(options, helpOptions);
    CommandLine line;
    CommandLineParser parser = new DefaultParser();
    // to just get help / usage info.
    try {
        line = parser.parse(helpOptions, args);
        if (line.hasOption('h')) {
            HelpFormatter formatter = new HelpFormatter();
            // use 'options' here to print help about all possible parameters
            formatter.printHelp(ClusterController.class.getName(), options, true);
            System.exit(0);
        }
    } catch (ParseException e) {
    // ignore, since any option except '-h' will cause this exception
    }
    try {
        line = parser.parse(options, args);
        if (line.hasOption('p')) {
            port = Integer.parseInt(line.getOptionValue('p'));
            LOG.info("found port = " + port);
        }
        if (line.hasOption('H')) {
            host = line.getOptionValue('H');
            LOG.info("found host = " + host);
        }
        if (line.hasOption('t')) {
            transport = line.getOptionValue('t').toLowerCase();
            LOG.info("found transport = " + transport);
        }
        if (line.hasOption('b')) {
            brokerUri = line.getOptionValue('b');
            LOG.info("found brokerUri = " + brokerUri);
        }
    } catch (ParseException e) {
        LOG.error("failed to parse command line: " + e);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(ClusterController.class.getName(), options, true);
        System.exit(1);
    }
    webSocketConfig = new Properties();
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_HOST, host);
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PORT, "" + port);
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PROTOCOL, "ws");
    webSocketConfig.setProperty(WebsocketModule.PROPERTY_WEBSOCKET_MESSAGING_PATH, "");
    Properties ccConfig = new Properties();
    ccConfig.putAll(webSocketConfig);
    ccConfig.setProperty(ConfigurableMessagingSettings.PROPERTY_CC_CONNECTION_TYPE, "WEBSOCKET");
    Module runtimeModule = new CCWebSocketRuntimeModule();
    if (transport != null) {
        Module backendTransportModules = Modules.EMPTY_MODULE;
        if (transport.contains("atmosphere") || transport.contains("http")) {
            backendTransportModules = Modules.combine(backendTransportModules, new AtmosphereMessagingModule());
        }
        if (transport.contains("mqtt")) {
            if (brokerUri != null) {
                try {
                    URI uri = new URI(brokerUri);
                    if (uri.getAuthority() == null || uri.getHost() == null || uri.getPort() < 0) {
                        throw new URISyntaxException(brokerUri, "host, authority or port was not set");
                    }
                } catch (URISyntaxException e) {
                    System.err.println(brokerUri + " is not a valid URI for the MQTT broker. Expecting for example: tcp://localhost:1883 Error: " + e.getMessage());
                    System.exit(1);
                }
                ccConfig.put("joynr.messaging.mqtt.brokerUri", brokerUri);
                ccConfig.put("joynr.messaging.primaryglobaltransport", "mqtt");
            }
            backendTransportModules = Modules.combine(backendTransportModules, new MqttPahoModule());
        }
        runtimeModule = Modules.override(runtimeModule).with(backendTransportModules);
    }
    Injector injectorCC = new JoynrInjectorFactory(ccConfig, runtimeModule).getInjector();
    runtime = injectorCC.getInstance(JoynrRuntime.class);
    LocalCapabilitiesDirectory capabilitiesDirectory = injectorCC.getInstance(LocalCapabilitiesDirectory.class);
    Thread shutdownHook = new Thread() {

        @Override
        public void run() {
            LOG.info("executing shutdown hook");
            synchronized (this) {
                LOG.info("notifying any waiting thread from shutdown hook");
                notifyAll();
            }
            LOG.info("shutting down");
            runtime.shutdown(false);
            LOG.info("shutdown completed");
        }
    };
    LOG.info("adding shutdown hook");
    Runtime.getRuntime().addShutdownHook(shutdownHook);
    if (System.console() != null) {
        ConsoleReader console;
        try {
            console = new ConsoleReader();
            String command = "";
            while (!command.equals("q")) {
                command = console.readLine();
                if (command.equals("caps")) {
                    Set<DiscoveryEntry> allLocalDiscoveryEntries = capabilitiesDirectory.listLocalCapabilities();
                    StringBuffer discoveryEntriesAsText = new StringBuffer();
                    for (DiscoveryEntry capability : allLocalDiscoveryEntries) {
                        discoveryEntriesAsText.append(capability.toString()).append('\n');
                    }
                    LOG.info(discoveryEntriesAsText.toString());
                } else {
                    LOG.info("\n\nUSAGE press\n" + " q\tto quit\n caps\tto list registered providers\n");
                }
            }
        } catch (IOException e) {
            LOG.error("error reading input from console", e);
        }
    } else {
        LOG.info("\n\nNon-interactive mode detected.\n" + "This cluster controller will continue to run until its JVM gets terminated\n" + "by the operating system. This can be triggered by sending a SIGTERM signal\n" + "to the process running the JVM.");
        synchronized (shutdownHook) {
            LOG.info("waiting on shutdown hook");
            try {
                shutdownHook.wait();
            } catch (InterruptedException e) {
            // ignore
            }
        }
    }
    System.exit(0);
}
Also used : Options(org.apache.commons.cli.Options) URISyntaxException(java.net.URISyntaxException) Properties(java.util.Properties) URI(java.net.URI) HelpFormatter(org.apache.commons.cli.HelpFormatter) Injector(com.google.inject.Injector) LocalCapabilitiesDirectory(io.joynr.capabilities.LocalCapabilitiesDirectory) CommandLineParser(org.apache.commons.cli.CommandLineParser) DefaultParser(org.apache.commons.cli.DefaultParser) DiscoveryEntry(joynr.types.DiscoveryEntry) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) ConsoleReader(jline.console.ConsoleReader) IOException(java.io.IOException) CommandLine(org.apache.commons.cli.CommandLine) ParseException(org.apache.commons.cli.ParseException) Module(com.google.inject.Module) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule) MqttPahoModule(io.joynr.messaging.mqtt.paho.client.MqttPahoModule) WebsocketModule(io.joynr.messaging.websocket.WebsocketModule) AtmosphereMessagingModule(io.joynr.messaging.AtmosphereMessagingModule)

Example 18 with DiscoveryEntry

use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioning method overrideEntriesFromLegacySettings.

private void overrideEntriesFromLegacySettings(LegacyCapabilitiesProvisioning legacyCapabilitiesProvisioning) {
    DiscoveryEntry globalCapabilitiesEntry = legacyCapabilitiesProvisioning.getDiscoveryEntryForInterface(GlobalCapabilitiesDirectory.class);
    if (globalCapabilitiesEntry != null) {
        removeExistingEntryForInterface(GlobalCapabilitiesDirectory.INTERFACE_NAME);
        discoveryEntries.add(globalCapabilitiesEntry);
    }
    DiscoveryEntry domainAccessControllerEntry = legacyCapabilitiesProvisioning.getDiscoveryEntryForInterface(GlobalDomainAccessController.class);
    if (domainAccessControllerEntry != null) {
        removeExistingEntryForInterface(GlobalDomainAccessController.INTERFACE_NAME);
        discoveryEntries.add(domainAccessControllerEntry);
    }
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry)

Example 19 with DiscoveryEntry

use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioningTest method assertContainsEntryFor.

private void assertContainsEntryFor(Collection<DiscoveryEntry> entries, String interfaceName, String participantId, String url) {
    boolean found = false;
    for (DiscoveryEntry entry : entries) {
        if (entry instanceof GlobalDiscoveryEntry) {
            GlobalDiscoveryEntry globalDiscoveryEntry = (GlobalDiscoveryEntry) entry;
            if (globalDiscoveryEntry.getInterfaceName().equals(interfaceName) && (participantId == null || participantId.equals(globalDiscoveryEntry.getParticipantId()))) {
                if (url != null) {
                    Address address = CapabilityUtils.getAddressFromGlobalDiscoveryEntry(globalDiscoveryEntry);
                    assertTrue(address instanceof ChannelAddress);
                    assertEquals(url, ((ChannelAddress) address).getMessagingEndpointUrl());
                }
                found = true;
            }
        }
    }
    assertTrue("Couldn't find " + interfaceName + ((participantId == null ? "" : " / " + participantId)) + " in " + entries, found);
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) MqttAddress(joynr.system.RoutingTypes.MqttAddress) Address(joynr.system.RoutingTypes.Address) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress)

Example 20 with DiscoveryEntry

use of joynr.types.DiscoveryEntry in project joynr by bmwcarit.

the class StaticCapabilitiesProvisioningTest method testIncompleteLegacySettings.

@Test(expected = CreationException.class)
public void testIncompleteLegacySettings() throws IOException {
    LegacyCapabilitiesProvisioning.LegacyProvisioningPropertiesHolder properties = createLegacyProvisioningPropertiesHolder();
    properties.capabilitiesDirectoryParticipantId = "";
    Set<DiscoveryEntry> discoveryEntries = createDiscoveryEntries("io.joynr", GlobalCapabilitiesDirectory.INTERFACE_NAME, GlobalDomainAccessController.INTERFACE_NAME);
    final String serializedDiscoveryEntries = objectMapper.writeValueAsString(discoveryEntries);
    Injector injector = createInjectorForJsonValue(serializedDiscoveryEntries, properties);
    fail("Expecting legacy capabilities provisioning to fail fast.");
}
Also used : DiscoveryEntry(joynr.types.DiscoveryEntry) GlobalDiscoveryEntry(joynr.types.GlobalDiscoveryEntry) Injector(com.google.inject.Injector) Test(org.junit.Test)

Aggregations

DiscoveryEntry (joynr.types.DiscoveryEntry)60 GlobalDiscoveryEntry (joynr.types.GlobalDiscoveryEntry)43 Test (org.junit.Test)30 ProviderQos (joynr.types.ProviderQos)25 Version (joynr.types.Version)22 Callback (io.joynr.proxy.Callback)18 Matchers.anyString (org.mockito.Matchers.anyString)17 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)16 DiscoveryQos (io.joynr.arbitration.DiscoveryQos)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 DeferredVoid (io.joynr.provider.DeferredVoid)7 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)6 MqttAddress (joynr.system.RoutingTypes.MqttAddress)6 Injector (com.google.inject.Injector)5 MessagingQos (io.joynr.messaging.MessagingQos)4 Future (io.joynr.proxy.Future)4 CheckForNull (javax.annotation.CheckForNull)4 ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)4