Пример #1
0
void RobustnessTestProvider::ping(
        std::function<void()> onSuccess,
        std::function<void(const exceptions::ProviderRuntimeException&)> onError)
{
    std::ignore = onError;
    JOYNR_LOG_INFO(logger(), "***********************");
    JOYNR_LOG_INFO(logger(), "* ping called.");
    JOYNR_LOG_INFO(logger(), "***********************");

    onSuccess();
}
Пример #2
0
void RobustnessTestProvider::methodWithStringParameters(
        const std::string& stringArg,
        std::function<void(const std::string& stringOut)> onSuccess,
        std::function<void(const joynr::exceptions::ProviderRuntimeException&)> onError)
{
    std::ignore = onError;
    JOYNR_LOG_INFO(logger(), "***********************");
    JOYNR_LOG_INFO(logger(), "* methodWithStringParameters called. stringArg: {}", stringArg);
    JOYNR_LOG_INFO(logger(), "***********************");
    std::string stringOut = "received stringArg: " + stringArg;
    onSuccess(stringOut);
}
Пример #3
0
void RobustnessTestProvider::stopFireBroadcastWithSingleStringParameter(
        std::function<void()> onSuccess,
        std::function<void(const joynr::exceptions::ProviderRuntimeException&)> onError)
{
    std::ignore = onError;
    std::string stringOut = "BroadcastWithSingleStringParameter_stringOut";
    JOYNR_LOG_INFO(logger(), "***********************");
    JOYNR_LOG_INFO(logger(), "* stopFireBroadcastWithSingleStringParameter called.");
    JOYNR_LOG_INFO(logger(), "***********************");

    stopBroadcastWithSingleStringParameter = true;
    onSuccess();
}
Пример #4
0
void RobustnessTestProvider::startFireBroadcastWithSingleStringParameter(
        std::function<void()> onSuccess,
        std::function<void(const joynr::exceptions::ProviderRuntimeException&)> onError)
{
    std::ignore = onError;
    auto stringOut = std::make_shared<std::string>("BroadcastWithSingleStringParameter_stringOut");
    JOYNR_LOG_INFO(logger(), "***********************");
    JOYNR_LOG_INFO(logger(),
                   "* startFireBroadcastWithSingleStringParameter called. stringOut: {}",
                   *stringOut);
    JOYNR_LOG_INFO(logger(), "***********************");

    stopBroadcastWithSingleStringParameter = false;
    std::int64_t period_ms = 250;
    std::int64_t validity_ms = 60000;
    broadcastThread =
            std::thread(&RobustnessTestProvider::fireBroadcastWithSingleStringParameterInternal,
                        this,
                        period_ms,
                        validity_ms,
                        stringOut);
    onSuccess();
}
void LongPollingMessageReceiver::checkServerTime()
{
    std::string timeCheckUrl = bounceProxyUrl.getTimeCheckUrl().toString();

    std::shared_ptr<IHttpGetBuilder> timeCheckRequestBuilder(
            HttpNetworking::getInstance()->createHttpGetBuilder(timeCheckUrl));
    std::shared_ptr<HttpRequest> timeCheckRequest(
            timeCheckRequestBuilder->addHeader("Accept", "text/plain")
                    ->withTimeout(settings.bounceProxyTimeout)
                    ->build());
    JOYNR_LOG_DEBUG(logger, "CheckServerTime: sending request to Bounce Proxy ({})", timeCheckUrl);
    std::chrono::system_clock::time_point localTimeBeforeRequest = std::chrono::system_clock::now();
    HttpResult timeCheckResult = timeCheckRequest->execute();
    std::chrono::system_clock::time_point localTimeAfterRequest = std::chrono::system_clock::now();
    std::uint64_t localTime = (TypeUtil::toMilliseconds(localTimeBeforeRequest) +
                               TypeUtil::toMilliseconds(localTimeAfterRequest)) /
                              2;
    if (timeCheckResult.getStatusCode() != 200) {
        JOYNR_LOG_ERROR(logger,
                        "CheckServerTime: Bounce Proxy not reached [statusCode={}] [body={}]",
                        timeCheckResult.getStatusCode(),
                        QString(timeCheckResult.getBody()).toStdString());
    } else {
        JOYNR_LOG_TRACE(logger,
                        "CheckServerTime: reply received [statusCode={}] [body={}]",
                        timeCheckResult.getStatusCode(),
                        QString(timeCheckResult.getBody()).toStdString());
        std::uint64_t serverTime =
                TypeUtil::toStdUInt64(QString(timeCheckResult.getBody()).toLongLong());

        auto minMaxTime = std::minmax(serverTime, localTime);
        std::uint64_t diff = minMaxTime.second - minMaxTime.first;

        JOYNR_LOG_INFO(
                logger,
                "CheckServerTime [server time={}] [local time={}] [diff={} ms]",
                TypeUtil::toDateString(JoynrTimePoint(std::chrono::milliseconds(serverTime))),
                TypeUtil::toDateString(JoynrTimePoint(std::chrono::milliseconds(localTime))),
                diff);

        if (diff > 500) {
            JOYNR_LOG_ERROR(logger, "CheckServerTime: time difference to server is {} ms", diff);
        }
    }
}
Пример #6
0
void Dispatcher::handleReplyReceived(const JoynrMessage& message)
{
    // json request
    // lookup necessary data
    std::string jsonReply = message.getPayload();

    // deserialize the jsonReply
    try {
        Reply reply = JsonSerializer::deserialize<Reply>(jsonReply);
        std::string requestReplyId = reply.getRequestReplyId();

        std::shared_ptr<IReplyCaller> caller = replyCallerDirectory.lookup(requestReplyId);
        if (caller == nullptr) {
            // This used to be a fatal error, but it is possible that the replyCallerDirectory
            // removed
            // the caller
            // because its lifetime exceeded TTL
            JOYNR_LOG_INFO(
                    logger,
                    "caller not found in the ReplyCallerDirectory for requestid {}, ignoring",
                    requestReplyId);
            return;
        }

        // Get the reply interpreter - this has to be a reference to support ReplyInterpreter
        // polymorphism
        int typeId = caller->getTypeId();
        IReplyInterpreter& interpreter = MetaTypeRegistrar::instance().getReplyInterpreter(typeId);

        // pass reply
        interpreter.execute(caller, reply);

        // Clean up
        removeReplyCaller(requestReplyId);
    } catch (const std::invalid_argument& e) {
        JOYNR_LOG_ERROR(logger,
                        "Unable to deserialize reply object from: {} - error {}",
                        jsonReply,
                        e.what());
    }
}
void LongPollingMessageReceiver::run()
{
    checkServerTime();
    std::string createChannelUrl = bounceProxyUrl.getCreateChannelUrl(channelId).toString();
    JOYNR_LOG_INFO(logger, "Running lpmr with channelId {}", channelId);
    std::shared_ptr<IHttpPostBuilder> createChannelRequestBuilder(
            HttpNetworking::getInstance()->createHttpPostBuilder(createChannelUrl));
    std::shared_ptr<HttpRequest> createChannelRequest(
            createChannelRequestBuilder->addHeader("X-Atmosphere-tracking-id", receiverId)
                    ->withContentType("application/json")
                    ->withTimeout(settings.bounceProxyTimeout)
                    ->build());

    std::string channelUrl;
    while (channelUrl.empty() && !isInterrupted()) {
        JOYNR_LOG_DEBUG(logger, "sending create channel request");
        HttpResult createChannelResult = createChannelRequest->execute();
        if (createChannelResult.getStatusCode() == 201) {
            channelUrl = *createChannelResult.getHeaders().find("Location");
            JOYNR_LOG_INFO(logger, "channel creation successfull; channel url: {}", channelUrl);
            channelCreatedSemaphore->notify();
        } else {
            JOYNR_LOG_INFO(logger,
                           "channel creation failed); status code: {}",
                           createChannelResult.getStatusCode());
            std::unique_lock<std::mutex> lock(interruptedMutex);
            interruptedWait.wait_for(lock, settings.createChannelRetryInterval);
        }
    }
    /**
      * register the channelUrl with the ChannelUrlDirectory (asynchronously)
      */
    assert(channelUrlDirectory != nullptr);
    types::ChannelUrlInformation urlInformation;
    std::vector<std::string> urls = {channelUrl};
    urlInformation.setUrls(urls);
    JOYNR_LOG_INFO(
            logger,
            "Adding channelId and Url of cluster controller to remote ChannelUrlDirectory {}",
            channelUrl);
    channelUrlDirectory->registerChannelUrlsAsync(channelId, urlInformation);

    while (!isInterrupted()) {

        std::shared_ptr<IHttpGetBuilder> longPollRequestBuilder(
                HttpNetworking::getInstance()->createHttpGetBuilder(channelUrl));

        std::shared_ptr<HttpRequest> longPollRequest(
                longPollRequestBuilder->acceptGzip()
                        ->addHeader("Accept", "application/json")
                        ->addHeader("X-Atmosphere-tracking-id", receiverId)
                        ->withTimeout(settings.longPollTimeout)
                        ->build());

        JOYNR_LOG_DEBUG(logger, "sending long polling request; url: {}", channelUrl);
        HttpResult longPollingResult = longPollRequest->execute();
        if (!isInterrupted()) {
            // TODO: remove HttpErrorCodes and use constants.
            // there is a bug in atmosphere, which currently gives back 503 instead of 200 as a
            // result to longpolling.
            // Accepting 503 is a temporary workaround for this bug. As soon as atmosphere is fixed,
            // this should be removed
            // 200 does nott refect the state of the message body! It could be empty.
            if (longPollingResult.getStatusCode() == 200 ||
                longPollingResult.getStatusCode() == 503) {
                Util::logSerializedMessage(logger,
                                           "long polling successful; contents: ",
                                           longPollingResult.getBody().data());
                processReceivedInput(longPollingResult.getBody());
                // Atmosphere currently cannot return 204 when a long poll times out, so this code
                // is currently never executed (2.2.2012)
            } else if (longPollingResult.getStatusCode() == 204) {
                JOYNR_LOG_DEBUG(logger, "long polling successfull);full; no data");
            } else {
                std::string body("NULL");
                if (!longPollingResult.getBody().isNull()) {
                    body = QString(longPollingResult.getBody().data()).toStdString();
                }
                JOYNR_LOG_ERROR(logger,
                                "long polling failed; error message: {}; contents: {}",
                                longPollingResult.getErrorMessage(),
                                body);
                std::unique_lock<std::mutex> lock(interruptedMutex);
                interruptedWait.wait_for(lock, settings.createChannelRetryInterval);
            }
        }
    }
}
void JoynrClusterControllerRuntime::initializeAllDependencies()
{
    /**
      * libjoynr side skeleton & dispatcher
      * This needs some preparation of libjoynr and clustercontroller parts.
      */
    messagingSettings = new MessagingSettings(*settings);
    messagingSettings->printSettings();
    libjoynrSettings = new LibjoynrSettings(*settings);
    libjoynrSettings->printSettings();
    wsSettings.printSettings();

    // Initialise security manager
    securityManager = new DummyPlatformSecurityManager();

    // CAREFUL: the factory creates an old style dispatcher, not the new one!

    inProcessDispatcher = new InProcessDispatcher();
    /* CC */
    // create the messaging stub factory
    MessagingStubFactory* messagingStubFactory = new MessagingStubFactory();
#ifdef USE_DBUS_COMMONAPI_COMMUNICATION
    messagingStubFactory->registerStubFactory(new DbusMessagingStubFactory());
#endif // USE_DBUS_COMMONAPI_COMMUNICATION
    messagingStubFactory->registerStubFactory(new InProcessMessagingStubFactory());
    // init message router
    messageRouter = std::shared_ptr<MessageRouter>(
            new MessageRouter(messagingStubFactory, securityManager));
    // provision global capabilities directory
    std::shared_ptr<joynr::system::RoutingTypes::Address> globalCapabilitiesDirectoryAddress(
            new system::RoutingTypes::ChannelAddress(
                    messagingSettings->getCapabilitiesDirectoryChannelId()));
    messageRouter->addProvisionedNextHop(messagingSettings->getCapabilitiesDirectoryParticipantId(),
                                         globalCapabilitiesDirectoryAddress);
    // provision channel url directory
    std::shared_ptr<joynr::system::RoutingTypes::Address> globalChannelUrlDirectoryAddress(
            new system::RoutingTypes::ChannelAddress(
                    messagingSettings->getChannelUrlDirectoryChannelId()));
    messageRouter->addProvisionedNextHop(messagingSettings->getChannelUrlDirectoryParticipantId(),
                                         globalChannelUrlDirectoryAddress);

    // setup CC WebSocket interface
    WebSocketMessagingStubFactory* wsMessagingStubFactory = new WebSocketMessagingStubFactory();
    messagingStubFactory->registerStubFactory(wsMessagingStubFactory);
    system::RoutingTypes::WebSocketAddress wsAddress =
            wsSettings.createClusterControllerMessagingAddress();

    wsCcMessagingSkeleton =
            new WebSocketCcMessagingSkeleton(*messageRouter, *wsMessagingStubFactory, wsAddress);

    /* LibJoynr */
    assert(messageRouter);
    joynrMessageSender = new JoynrMessageSender(messageRouter);
    joynrDispatcher = new Dispatcher(joynrMessageSender);
    joynrMessageSender->registerDispatcher(joynrDispatcher);

    /* CC */
    // TODO: libjoynrmessagingskeleton now uses the Dispatcher, should it use the
    // InprocessDispatcher?
    libJoynrMessagingSkeleton = std::shared_ptr<InProcessMessagingSkeleton>(
            new InProcessLibJoynrMessagingSkeleton(joynrDispatcher));
    // EndpointAddress to messagingStub is transmitted when a provider is registered
    // messagingStubFactory->registerInProcessMessagingSkeleton(libJoynrMessagingSkeleton);

    /**
      * ClusterController side
      *
      */
    if (!messageReceiver) {
        JOYNR_LOG_INFO(
                logger,
                "The message receiver supplied is NULL, creating the default MessageReceiver");
        messageReceiver = std::shared_ptr<IMessageReceiver>(
                new HttpReceiver(*messagingSettings, messageRouter));
    }

    std::string channelId = messageReceiver->getReceiveChannelId();

    // create message sender
    if (!messageSender) {
        JOYNR_LOG_INFO(
                logger, "The message sender supplied is NULL, creating the default MessageSender");
        messageSender = std::shared_ptr<IMessageSender>(new HttpSender(
                messagingSettings->getBounceProxyUrl(),
                std::chrono::milliseconds(messagingSettings->getSendMsgMaxTtl()),
                std::chrono::milliseconds(messagingSettings->getSendMsgRetryInterval())));
    }
    messagingStubFactory->registerStubFactory(
            new JoynrMessagingStubFactory(messageSender, messageReceiver->getReceiveChannelId()));

    // joynrMessagingSendSkeleton = new DummyClusterControllerMessagingSkeleton(messageRouter);
    // ccDispatcher = DispatcherFactory::createDispatcherInSameThread(messagingSettings);

    // we currently have to use the fake client, because JAVA side is not yet working for
    // CapabilitiesServer.
    bool usingRealCapabilitiesClient =
            /*when switching this to true, turn on the UUID in systemintegrationtests again*/ true;
    capabilitiesClient = new CapabilitiesClient(channelId); // ownership of this is not transferred
    // try using the real capabilitiesClient again:
    // capabilitiesClient = new CapabilitiesClient(channelId);// ownership of this is not
    // transferred

    localCapabilitiesDirectory = std::make_shared<LocalCapabilitiesDirectory>(
            *messagingSettings, capabilitiesClient, *messageRouter);
#ifdef USE_DBUS_COMMONAPI_COMMUNICATION
    dbusSettings = new DbusSettings(*settings);
    dbusSettings->printSettings();
    // register dbus skeletons for capabilities and messaging interfaces
    std::string ccMessagingAddress(dbusSettings->createClusterControllerMessagingAddressString());
    ccDbusMessageRouterAdapter = new DBusMessageRouterAdapter(*messageRouter, ccMessagingAddress);
#endif // USE_DBUS_COMMONAPI_COMMUNICATION

    /**
      * libJoynr side
      *
      */
    publicationManager = new PublicationManager();
    subscriptionManager = new SubscriptionManager();
    inProcessPublicationSender = new InProcessPublicationSender(subscriptionManager);
    std::shared_ptr<joynr::system::RoutingTypes::Address> libjoynrMessagingAddress(
            new InProcessMessagingAddress(libJoynrMessagingSkeleton));
    // subscriptionManager = new SubscriptionManager(...)
    inProcessConnectorFactory = new InProcessConnectorFactory(
            subscriptionManager,
            publicationManager,
            inProcessPublicationSender,
            dynamic_cast<IRequestCallerDirectory*>(inProcessDispatcher));
    joynrMessagingConnectorFactory =
            new JoynrMessagingConnectorFactory(joynrMessageSender, subscriptionManager);

    connectorFactory =
            createConnectorFactory(inProcessConnectorFactory, joynrMessagingConnectorFactory);

    proxyFactory = new ProxyFactory(libjoynrMessagingAddress, connectorFactory, &cache);

    dispatcherList.push_back(joynrDispatcher);
    dispatcherList.push_back(inProcessDispatcher);

    // Set up the persistence file for storing provider participant ids
    std::string persistenceFilename = libjoynrSettings->getParticipantIdsPersistenceFilename();
    participantIdStorage =
            std::shared_ptr<ParticipantIdStorage>(new ParticipantIdStorage(persistenceFilename));

    dispatcherAddress = libjoynrMessagingAddress;
    discoveryProxy = new LocalDiscoveryAggregator(
            *dynamic_cast<IRequestCallerDirectory*>(inProcessDispatcher), systemServicesSettings);

    std::string discoveryProviderParticipantId(
            systemServicesSettings.getCcDiscoveryProviderParticipantId());
    std::shared_ptr<RequestCaller> discoveryRequestCaller(
            new joynr::system::DiscoveryRequestCaller(localCapabilitiesDirectory));
    std::shared_ptr<InProcessAddress> discoveryProviderAddress(
            new InProcessAddress(discoveryRequestCaller));
    joynr::system::DiscoveryInProcessConnector* discoveryInProcessConnector =
            InProcessConnectorFactoryHelper<joynr::system::IDiscoveryConnector>().create(
                    subscriptionManager,
                    publicationManager,
                    inProcessPublicationSender,
                    std::string(), // can be ignored
                    discoveryProviderParticipantId,
                    discoveryProviderAddress);

    discoveryProxy->setDiscoveryProxy(discoveryInProcessConnector);

    capabilitiesRegistrar = new CapabilitiesRegistrar(dispatcherList,
                                                      *discoveryProxy,
                                                      libjoynrMessagingAddress,
                                                      participantIdStorage,
                                                      dispatcherAddress,
                                                      messageRouter);

    joynrDispatcher->registerPublicationManager(publicationManager);
    joynrDispatcher->registerSubscriptionManager(subscriptionManager);

    /**
     * Finish initialising Capabilitiesclient by building a Proxy and passing it
     */
    std::int64_t discoveryMessagesTtl = messagingSettings->getDiscoveryMessagesTtl();

    if (usingRealCapabilitiesClient) {
        ProxyBuilder<infrastructure::GlobalCapabilitiesDirectoryProxy>* capabilitiesProxyBuilder =
                createProxyBuilder<infrastructure::GlobalCapabilitiesDirectoryProxy>(
                        messagingSettings->getDiscoveryDirectoriesDomain());
        DiscoveryQos discoveryQos(10000);
        discoveryQos.setArbitrationStrategy(
                DiscoveryQos::ArbitrationStrategy::HIGHEST_PRIORITY); // actually only one provider
                                                                      // should be available
        std::shared_ptr<infrastructure::GlobalCapabilitiesDirectoryProxy> capabilitiesProxy(
                capabilitiesProxyBuilder->setMessagingQos(MessagingQos(discoveryMessagesTtl))
                        ->setCached(true)
                        ->setDiscoveryQos(discoveryQos)
                        ->build());
        ((CapabilitiesClient*)capabilitiesClient)->init(capabilitiesProxy);
    }

    ProxyBuilder<infrastructure::ChannelUrlDirectoryProxy>* channelUrlDirectoryProxyBuilder =
            createProxyBuilder<infrastructure::ChannelUrlDirectoryProxy>(
                    messagingSettings->getDiscoveryDirectoriesDomain());

    DiscoveryQos discoveryQos(10000);
    discoveryQos.setArbitrationStrategy(
            DiscoveryQos::ArbitrationStrategy::HIGHEST_PRIORITY); // actually only one provider
                                                                  // should be available
    channelUrlDirectoryProxy = std::shared_ptr<infrastructure::ChannelUrlDirectoryProxy>(
            channelUrlDirectoryProxyBuilder->setMessagingQos(MessagingQos(discoveryMessagesTtl))
                    ->setCached(true)
                    ->setDiscoveryQos(discoveryQos)
                    ->build());

    channelUrlDirectory = std::shared_ptr<ILocalChannelUrlDirectory>(
            new LocalChannelUrlDirectory(*messagingSettings, channelUrlDirectoryProxy));
    messageReceiver->init(channelUrlDirectory);
    messageSender->init(channelUrlDirectory, *messagingSettings);
}