Thursday, December 14, 2017

Openshift REST Client API written in Java

https://github.com/openshift/openshift-restclient-java/

immensely more usable than the CLI...

I ask myself who wants to learn by heart the hyper-complicated Openshift command line interface, when you can easily wrap all that crap in a nice fluent Java API....

Life is short, I am too busy, no time to learn all the freaking CLIs of the planet... please give me simple and powerful programming tools... I don't want to type any commands...

To get started, create a Maven Java Project, add this in pom.xml:


  <dependencies>
   <dependency>
    <groupId>com.openshift</groupId>
    <artifactId>openshift-restclient-java</artifactId>
    <version>5.9.3.Final</version>
   </dependency>
 </dependencies>


then run this:

package org.pierre.ocpclient;

import com.openshift.restclient.ClientBuilder;
import com.openshift.restclient.IClient;
import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.model.IProject;
import com.openshift.restclient.model.IResource;

public class CreateProject {
 public static void main(String[] args) {
  IClient client = new ClientBuilder("https://localhost:8443")
    .withUserName("admin")
    .withPassword("admin")
    .build();
  
  IResource request = client.getResourceFactory().stub(ResourceKind.PROJECT_REQUEST, "myfirstproject");
  IProject project =  (IProject)client.create(request);
  
 }

}



No comments: