I want to figure out the order of deployment of mi...
# community-support
v
I want to figure out the order of deployment of microservices, i.e. if I'm service A, that depends on B, to make sure B is deployed (B is managed by other team, deploying themselves) Naive way I'm thinking of is to read the build graph, and figure it out, get the toposorted list, and check it against some sort of registry of deployed services how do I do that? (also, is this a good idea?)
t
seems reasonable. Dependency Analysis Gradle Plugin has some facilities that almost meet your needs
The
generateProjectGraph<source-set>
task generates a topological sort of the project graph. Could alter that to get the same thing (and revsered) for external modules
v
why alter? sounds exactly what i want, no?
t
or you could fully roll your own and use the
com.autonomousapps:graph-support
package, which has a
Graphs.topological()
function that you can play with
oh, I may have misunderstood you. Are all the microservices in the same repo?
if so, then it's what you want
I thought they might be in other repos
v
does it matter?
t
yes
v
i was thinking just checking against "-api" suffix or something like that specifically
t
I wrote that task specifically for helping to visualize the local project graph, so it doesn't care about external modules
v
I see, and I'd then parse that as a string? Or would you suggest some more structured way?
t
it has a variety of outputs. • gv (graphviz) files • a json output • simple txt files that just list the project paths in topological order
apply the plugin, run the task, take a look at the outputs
v
great ill look into it btw how are you doing that? gradle tooling api?
I could walk the project graph but I think I was yelled at as that's not IP compatible
t
no just standard gradle APIs.
you can resolve the graph as a graph and walk it
if you look at the repo on github, go to the
GraphViewBuilder
class and you'll see
oh heh, that class even has a
private val localOnly: Boolean = false
parameter, so apparently it'll do whatever
v
but now you're describing a way where I'm depending on the jar that powers your plugin, not somehow consuming the tasks of that plugin?
--btw I was thinking of having a lifecycle task "markedAsApi" and then
tasks.named
it it in respective api projects and then run
./gradlew markedAsApi
and it should be ordered in the order of project dependencies no?
t
but now you're describing a way where I'm depending on the jar that powers your plugin, not somehow consuming the tasks of that plugin?
I think the first thing you should try is apply the plugin and run the task if you find it doesn't meet your needs, some options: 1. If you think you have a generally useful idea, you could contribute it back to the plugin 2. If you think your use-case is too narrow, then you can use an artifact I publish along with the plugin that provides support for what you need
I don't really understand your
markedAsApi
idea
v
yep will do, sounds most same I'm just thinking about the idea with the lifecycle task way I was naively thinking that the order of execution of the
markedAsApi
tasks will be the toposort
but idk if that's the case
t
that's kind of clever. Not sure it'll work, but might. You'd have to parse the gradle console output though, so it's not great
v
yea, regexes will lead to tears
how would you however mark that this project is an rest api I'm looking for? even 3rd party things could use the
-api
suffix, and I probably don't want to have some sort of cryptic suffix just to hope to be unique
t
are all your micoservices local to the repo?
v
lets say no
or maybe yes, either way
t
do they have a known group or groups?
v
this is a hypothetical future architecture
yep if they are remote then yes they'd have a group and I can grep against that yea, nice
what if it were local?
t
then you can filter for only local instead
v
hmm i see
but you'd still somehow match the name somehow? or is there some sort of more durable marker?
t
you also have access to the full dep graph here. So if you have to you could crack open the jars and look inside
v
could I mark such projects with my custom plugin and look for that?
t
put something in
META-INF
for example
in the manifest, etc
v
neat however if your library gives me projects, I could interrogate applied plugins, no? sounds faster?
t
short answer: no
v
why?
project.pluginManager.hasPlugin("api-marker")
or is that a different project type?
t
1) the code I'm referring to doesn't give you access to the
project
instance 2) doing what you suggest violates IP
v
hmm true, but how do you even looks at the graph without violating IP if touching other projects is illegal
t
it's the dependency graph
that's basically the one blessed way to interact with other projects
you ask gradle to resolve the graph and it does
touching other projects is illegal
that's not the right way to think about it
obviously you have to be able to interact with other projects in a build. If for no other reason than you need to build them and you need their class files or jar files on the classpath of your running app
v
yea I probably dont know enough gradle primitives is that the issue is - I hear what you say but cant map it onto gradle apis
since yea I do mess around with project graph but I turned on IP and it fails so I'm assuming im doing it wrong 😄
t
I'd suggest cloning the plugin I referenced above and looking at its code. There are a lot of examples there
v
yep sounds great maybe one freebie before that please, is this api reachable when writing the normalne project build.gradle? or do I have to be a plugin, or rather only reachable from within a plugin subclass
t
GraphViewBuilder
is internal to my plugin. The
graph-support
lib is public, however. So it depends on what you're asking about
v
btw I'm playing with
./gradlew :client:projectGraphMain
and it works, but can I also get a graphviz for the whole build?
I tried ` ./gradlew :projectGraphMain`but no dice
t
the closest way to achieve that is to run the task against the "entry point" or highest-level project in your build
v
which is what, not root build.gradle?
(say I have two apps)
about our previos conversation is this what you meant to consume? (task is called
projectGraphMain
, I couldnt find the
generateProjectGraph<source-set>
one you mentioned in the beginning
t
the runtime classpath might be more interesting, but yes
thank you 1
v
is this api reachable when writing the normalne project build.gradle? or do I have to be a plugin, or rather only reachable from within a plugin subclass
Anything you can do in a plugin you can do in the normal build script too, it's just not too idiomatic to do imperative logic in the build script.
(say I have two apps)
Then those two are your entrypoints. If you don't have one entrypoint that depends on the apps at least.