Using fabric8 API to check kubernetes cron jobs - java

I'm trying to create a java test to check the status of cron jobs on a kubernetes, however I'm having trouble with the fabric8 imports.
I've tried
import io.fabric8.kubernetes.api.model.batch.Job;
import io.fabric8.kubernetes.api.model.batch.JobList;
However this throws an error. For some reason, java cannot resolve the 'batch' symbol. This tells me there is probably something missing in my ivy.xml dependencies.
I have the following dependencies already in my ivy.xml
<dependency org="io.fabric8" name="kubernetes-client" rev="3.1.12"/>
<dependency org="io.fabric8" name="kubernetes-api" rev="2.0.9"/>
<dependency org="io.fabric8" name="kubernetes-model" rev="3.1.12"/>
Am I missing a dependency? Or is there another problem?

The problem was the dependencies were out of date.
The dependency for JobList wasn't added until several versions later. Apparently, nobody on our team has updated those dependencies in our ivy file for almost a year.
In other words, to avoid issues like this, one should always keep there dependencies up to date.

Related

Spring-webflux application startup failures

The application is failing during the startup with this error:
The bean 'requestDataValueProcessor', defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebMvcSecurityConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfiguration.class] and overriding is disabled.
All team members have the same problem and it seems that even if we're checking out an old git tag, the same problem persist. We've checked all the build files and dependencies, and nothing seemed to be changed in the last period of time. What's even more interesting is that the Bamboo seemed to run the build and the IT's pack with success with a day before, but today's morning it seem that the same issue is replicated there.
Not sure exactly why is complaining about WebMvcSecurityConfiguration, since we're using only reactive security in our project. So at this point we don't have any spring-mvc dependencies..
Does anyone have any clue ? Thx
So after we've enabled debug level logs on spring and force spring app to use only the reactive configurations like this:
spring:
main:
web-application-type: reactive
it seemed that the springfox dependencies were failing with:
java.lang.NoSuchMethodError: org.springframework.util.MultiValueMap.addIfAbsent(Ljava/lang/Object;Ljava/lang/Object;)V
at springfox.documentation.spring.web.scanners.ModelSpecificationRegistryBuilder.lambda$add$0(ModelSpecificationRegistryBuilder.java:37)
at java.base/java.util.Optional.ifPresent(Optional.java:183)
at springfox.documentation.spring.web.scanners.ModelSpecificationRegistryBuilder.add(ModelSpecificationRegistryBuilder.java:34)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
at
So that error ^^^ point us towards sprinfox dependencies which were:
compile ("io.springfox:springfox-swagger-ui:3.0.0-SNAPSHOT")
compile ("io.springfox:springfox-swagger2:3.0.0-SNAPSHOT")
compile ("io.springfox:springfox-spring-webflux:3.0.0-SNAPSHOT")
After furthermore investigation, it seemed that some of those contains the spring-mvc dependency and that interfere with the spring-webflux one, and the application got confused which beans to inject.
We've downgrade those dependencies to 2.10.0, and everything seems to work now. My guess is that they've made some releases with that snapshot version and that include spring mvc, but until now it was absent. Lesson learned, never use some external libraries snapshots versions, otherwise you could end up in a very bad situation.
X.X.X-SNAPSHOT Dependencies are not the stable ones.
we were using <springfox.version>3.0.0-SNAPSHOT</springfox.version> which suddenly stopped working.
So below solution worked for us.
<springfox.version>2.10.5</springfox.version>
Cheers!!

Use Ivy API to obtain latest version of a dependency?

We have a simple Ivy repository we host off of an in-house server (Apache httpd serving up JARs and their XML Ivy descriptors).
I now have a need to programmatically determine what the latest version of a dependency is in our repo. Thus if we have two versions of Mockito, our repo might look like:
mockito/ ==> organisation
mockito-all ==> module
1.9.4/ ==> revision #
mockito-all-1.9.4.jar
mockito-all-1.9.4-ivy.xml
1.9.5/
mockito-all-1.9.5.jar
mockito-all-1.9.5-ivy.xml
It would be nice if, from Java, I can use Ivy to determine that "1.9.5" is the latest version of the mockito/mockito-all module that we have.
This would likely not be an Ant task, and instead would likely be some custom Java code using the classes that exist inside ivy.jar.
Any ideas? Thanks in advance!
I believe you can use latest.integration revision value to specify the absolute latest version needed. For example, specify your Ivy dependency like so:
<dependency org="mockito" name="mockito-all" rev="latest.integration" />
You can also specify latest.milestone or latest.release if you don't want the "edge" version. Here is a good explanation on the rev value: http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html
So I found your question looking to do the same thing and after some research found that in Ivy 2.4, such a thing exists.
http://ant.apache.org/ivy/history/latest-milestone/use/checkdepsupdate.html
Here is a sample step:
<target name="ivy.outdated" description="Check ivy for outdated jars">
<ivy:resolve/>
<ivy:checkdepsupdate showTransitive="false" revisionToCheck="latest.release"/>
</target>

using IVY dependencies manager programmatically

i need help using IVY as dependencies manager
my application need to load plug-ins at RUN-TIME
means while the core application is running ,user can request for a new plug-in
and install them ,
i wish to manage all installed plug-ins using the core application DB.
i want to get a pom from my plug-ins server (or some other descriptor),
and ask IVY to tell me what are the dependencies OR let IVY
install the plug-in and dependencies ,
based on the current state of my application.
( what do i have right now ,
1.jar's used by core application
2.jar's used by current installed plug-ins)
i wish for each plug-in to have independent directory
under some folder where my application is located (not a shared one)
the thing is i don't know where to start
i notice that there is no programming API for that
i located one link over the network of someone who try something similar
but look likes the code is not completed , or some variable are missing
and i dont know how to complete the rest cause lake of programming documentation
http://www.mail-archive.com/ivy-user#ant.apache.org/msg03228.html
(where the variable "art" came for.....)
can you help me please ...
Thank you all
UPDATE
ok this what i am trying now .
i am getting some a error plus i dont know how to define my archiva server
IvySettings settings = new IvySettings();
settings.setDefaultIvyUserDir(new File("D:/programming/eclipse_projects/ivyTest/repo/"));
settings.setDefaultCache(new File("D:/programming/eclipse_projects/ivyTest/repo/cache/"));
settings.setDefaultCacheArtifactPattern("[module]/[revision]/[module]-[revision](-[classifier]");
Ivy ivy = Ivy.newInstance(settings);
ivy.getLoggerEngine().pushLogger(new DefaultMessageLogger(Message.MSG_VERBOSE));
ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(new IvySettings(), new File("src/movies.pom").toURL(), true);
RetrieveOptions retriveOptions = new RetrieveOptions();
retriveOptions.setUseOrigin(true);
retriveOptions.setConfs(md.getConfigurationsNames());
ivy.retrieve(md.getModuleRevisionId(), "lib/[conf]/[artifact].[ext]", etriveOptions);
this is the error i get
:: loading settings :: url = jar:file:/D:/programming/eclipse_projects/ivyTest/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: retrieving :: org.jtpc#movies
checkUpToDate=true
confs: [default, master, compile, provided, runtime, test, system, sources, javadoc, optional]
java.lang.RuntimeException: problem during retrieve of org.jtpc#movies: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:206)
at org.apache.ivy.Ivy.retrieve(Ivy.java:540)
at Test.main(Test.java:52)
Caused by: java.lang.IllegalStateException: Report file 'D:\programming\eclipse_projects\ivyTest\repo\cache\org.jtpc-movies-default.xml' does not exist.
at org.apache.ivy.plugins.report.XmlReportParser.parse(XmlReportParser.java:294)
at org.apache.ivy.core.retrieve.RetrieveEngine.determineArtifactsToCopy(RetrieveEngine.java:288)
at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:104)
... 2 more
Ivy can be used as a standalone java program:
java -jar ivy.jar -retrieve "lib/[conf]/[artifact].[ext]"
The retrieve pattern can be then used to determine where files are installed, based on the ivy configuration settings
$ find lib -type f
lib/core/commons-lang.jar
lib/plugin1/commons-logging.jar
lib/plugin1/commons-codec.jar
lib/plugin2/commons-logging.jar
lib/plugin2/commons-cli.jar
lib/plugin3/commons-logging.jar
Configurations are used as a collective label or grouping of dependencies. They are similar to Maven scopes but much more flexible:
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="core" description="Core application dependencies"/>
<conf name="plugin1" description="Plugin 1 dependencies"/>
<conf name="plugin2" description="Plugin 2 dependencies"/>
<conf name="plugin3" description="Plugin 3 dependencies"/>
</configurations>
<dependencies>
<dependency org="commons-lang" name="commons-lang" rev="2.5" conf="core->default"/>
<dependency org="commons-codec" name="commons-codec" rev="1.4" conf="plugin1->default"/>
<dependency org="commons-cli" name="commons-cli" rev="1.2" conf="plugin2->default"/>
<dependency org="commons-logging" name="commons-logging" rev="1.1.1" conf="plugin1,plugin2,plugin3->default"/>
</dependencies>
</ivy-module>
If you only want to download and install one set of jars, into a specified directory you can use the confs parameter:
java -jar ivy.jar -retrieve "plugin1/[artifact].[ext]" -confs plugin1
Finally, if you still want to use a programming API, you could invoke the run method called by the main class
http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/Main.java?view=markup
Update 1
Groovy has built in support for invoking ivy tasks
import groovy.xml.NamespaceBuilder
def ant = new AntBuilder()
def ivy = NamespaceBuilder.newInstance(ant, 'antlib:org.apache.ivy.ant')
ivy.settings(file:"ivysettings.xml")
ivy.retrieve(pattern:"lib/[conf]/[artifact].[ext]")
ivy.report(toDir:'reports', graph:false)
Update 2
To set the location of your local Maven repository you need to use an ivysettings.xml file.
<ivysettings>
<settings defaultResolver='nexus' />
<resolvers>
<ibiblio name='nexus' root='http://myhost.mydomanin.com:8081/nexus' m2compatible='true' />
</resolvers>
</ivysettings>
Update 3
Just found an article that details how to invoke Ivy from Java

can I use 2 ivy files?

I'm creating a build environment for third party developers. I want to provide them with an ivy.xml which a 3rd party shouldn't change and also a ivy-custom.xml which they should change.
<target name="resolve" depends="download-ivy">
<ivy:resolve file="ivy.xml"/>
<ivy:resolve file="ivy-custom.xml"/>
</target>
This doesn't seem to work, though. The ivy-custom.xml seems to usurp the original ivy.xml. Does anyone know of a way to do this? Thanks.
You may consider split it into 2 separate modules. The first one is with dependency of your ivy.xml and publish it into your maven repository. (said org="com.abc", name="your-module", version 1.0)
Then you may let your 3rd party developers use ivy-custom.xml that also resolve "your-module" as one of the dependency.
<dependency org="com.abc" name="your-module" rev="1.0" transitive="true"/>
This assume your developer have access to your repository.

How do you configure Apache Ivy to remove orphan artifacts?

Let's say I have an ivy.xml that contains the following:
<dependency org="checkstyle" name="checkstyle" rev="4.3" />
And then I want to upgrade to Checkstyle 4.4, so I change my ivy.xml to contain:
<dependency org="checkstyle" name="checkstyle" rev="4.4" />
After a retrieve with the first configuration, I have the file checkstyle-4.3.jar. After the second configuration, I also have the file checkstyle-4.4.jar, and the file checkstyle-4.3.jar still exists.
Is there a way to have Ivy realize that the old file is an orphan, and remove it from the lib directory? The idea is that I don't want my developers' disk space usage to drastically increase every time I upgrade a tool.
Ideally I'd also want it removed from the local repository as well. I do realize that the intent of the local repository is that it is shared among projects, so it would not make sense to remove anything, as it would not know if the artifact was still in use in other projects. But there must be some kind of prune procedure...
I've been using Ivy 2.0.0, so I don't know if this applies to the version you're using.
The Ivy retrieve task has a sync attribute. Set this to true and unused/unknown files in your retrieved directory (lib in your case) will be removed. Keep in mind this will mean any manually copied artifacts in this directory which Ivy doesn't specifically resolve will be removed.
Also, note that if you use the sync option but Ivy resolves no dependencies (empty or missing ivy.xml, for example), the retrieve directory will be deleted.

Categories