-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Session info #230
Merged
Merged
Session info #230
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e1bafa
Session info: creating SessionInfo, implementing peersZid() and route…
DariusIMP 7167e88
Session info: adding id() function, returning Results.
DariusIMP 40550e3
Session info: adding kdocs + cargo clippy
DariusIMP 57abe17
Session info: renaming functions
DariusIMP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ tasks { | |
"ZBytes", | ||
"ZDelete", | ||
"ZGet", | ||
"ZInfo", | ||
"ZPub", | ||
"ZPubThr", | ||
"ZPut", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <zenoh@zettascale.tech> | ||
// | ||
|
||
package io.zenoh | ||
|
||
import com.github.ajalt.clikt.core.CliktCommand | ||
import com.github.ajalt.clikt.parameters.options.* | ||
|
||
class ZInfo(private val emptyArgs: Boolean) : CliktCommand( | ||
help = "Zenoh Info example" | ||
) { | ||
override fun run() { | ||
val config = loadConfig(emptyArgs, configFile, connect, listen, noMulticastScouting, mode) | ||
|
||
Zenoh.initLogFromEnvOr("error") | ||
|
||
println("Opening session...") | ||
Zenoh.open(config).onSuccess { session -> | ||
session.use { | ||
val info = session.info() | ||
println("zid: ${info.zid().getOrThrow()}") | ||
|
||
println("routers zid: ${info.routersZid().getOrThrow()}") | ||
|
||
println("peers zid: ${info.peersZid().getOrThrow()}") | ||
} | ||
}.onFailure { exception -> println(exception.message) } | ||
} | ||
|
||
|
||
private val configFile by option("-c", "--config", help = "A configuration file.", metavar = "config") | ||
private val connect: List<String> by option( | ||
"-e", "--connect", help = "Endpoints to connect to.", metavar = "connect" | ||
).multiple() | ||
private val listen: List<String> by option( | ||
"-l", "--listen", help = "Endpoints to listen on.", metavar = "listen" | ||
).multiple() | ||
private val mode by option( | ||
"-m", | ||
"--mode", | ||
help = "The session mode. Default: peer. Possible values: [peer, client, router]", | ||
metavar = "mode" | ||
).default("peer") | ||
private val noMulticastScouting: Boolean by option( | ||
"--no-multicast-scouting", help = "Disable the multicast-based scouting mechanism." | ||
).flag(default = false) | ||
} | ||
|
||
fun main(args: Array<String>) = ZInfo(args.isEmpty()).main(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
zenoh-kotlin/src/commonMain/kotlin/io/zenoh/SessionInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <zenoh@zettascale.tech> | ||
// | ||
|
||
package io.zenoh | ||
|
||
import io.zenoh.protocol.ZenohID | ||
|
||
/** | ||
* Class allowing to obtain the information of a [Session]. | ||
*/ | ||
class SessionInfo(private val session: Session) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll let @wyfo and @DariusIMP decide if this comment is a blocker for this PR. Otherwise it LGTM. |
||
|
||
/** | ||
* Return the [ZenohID] of the current Zenoh [Session] | ||
*/ | ||
fun zid(): Result<ZenohID> { | ||
return session.zid() | ||
} | ||
|
||
/** | ||
* Return the [ZenohID] of the zenoh peers the session is currently connected to. | ||
*/ | ||
fun peersZid(): Result<List<ZenohID>> { | ||
return session.getPeersId() | ||
} | ||
|
||
/** | ||
* Return the [ZenohID] of the zenoh routers the session is currently connected to. | ||
*/ | ||
fun routersZid(): Result<List<ZenohID>> { | ||
return session.getRoutersId() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
zenoh-kotlin/src/commonTest/kotlin/io/zenoh/SessionInfoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// Copyright (c) 2023 ZettaScale Technology | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// | ||
// Contributors: | ||
// ZettaScale Zenoh Team, <zenoh@zettascale.tech> | ||
// | ||
|
||
package io.zenoh | ||
|
||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
class SessionInfoTest { | ||
|
||
@Test | ||
fun `peersZid test`() { | ||
val jsonConfig = """ | ||
{ | ||
mode: "peer", | ||
connect: { | ||
endpoints: ["tcp/localhost:7450"], | ||
}, | ||
} | ||
""".trimIndent() | ||
|
||
val listenConfig = Config.fromJson(""" | ||
{ | ||
mode: "peer", | ||
listen: { | ||
endpoints: ["tcp/localhost:7450"], | ||
}, | ||
} | ||
""".trimIndent()).getOrThrow() | ||
|
||
val sessionC = Zenoh.open(listenConfig).getOrThrow() | ||
val sessionA = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() | ||
val sessionB = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() | ||
|
||
val idA = sessionA.info().zid().getOrThrow() | ||
val idB = sessionB.info().zid().getOrThrow() | ||
val peers = sessionC.info().peersZid().getOrThrow() | ||
assertTrue(peers.contains(idA)) | ||
assertTrue(peers.contains(idB)) | ||
|
||
sessionA.close() | ||
sessionB.close() | ||
sessionC.close() | ||
} | ||
|
||
|
||
@Test | ||
fun `routersZid test`() { | ||
val jsonConfig = """ | ||
{ | ||
mode: "router", | ||
connect: { | ||
endpoints: ["tcp/localhost:7450"], | ||
}, | ||
listen: { | ||
endpoints: ["tcp/localhost:7452"], | ||
}, | ||
} | ||
""".trimIndent() | ||
|
||
val listenConfig = Config.fromJson(""" | ||
{ | ||
mode: "router", | ||
listen: { | ||
endpoints: ["tcp/localhost:7450"], | ||
}, | ||
} | ||
""".trimIndent()).getOrThrow() | ||
|
||
val sessionC = Zenoh.open(listenConfig).getOrThrow() | ||
val sessionA = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() | ||
val sessionB = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() | ||
|
||
val idA = sessionA.info().zid().getOrThrow() | ||
val idB = sessionB.info().zid().getOrThrow() | ||
val routers = sessionC.info().routersZid().getOrThrow() | ||
assertTrue(routers.contains(idA)) | ||
assertTrue(routers.contains(idB)) | ||
|
||
sessionA.close() | ||
sessionB.close() | ||
sessionC.close() | ||
} | ||
|
||
@Test | ||
fun `zid test`() { | ||
val jsonConfig = """ | ||
{ | ||
id: "123456", | ||
} | ||
""".trimIndent() | ||
|
||
val session = Zenoh.open(Config.fromJson(jsonConfig).getOrThrow()).getOrThrow() | ||
assertEquals("123456", session.info().zid().getOrThrow().toString()) | ||
session.close() | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ZenohID
should be renamedZenohId
to alignThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened PR #233 for this, to be merged after this one.