I want to create a service in Java which will take a yaml file and create whatever object is in there on a Kubernetes cluster.
Somewhat like how kubectl create -f file.yaml does.
The yaml file can contain a pod, service or deployment.
Can this be done in either official Kubernetes Java Client or fabric8 Kubernetes Java Client? How can it be achieved?
You can use Kubernetes REST API
Example create new deployment:
curl -X POST -d #deployment.json -H "Content-Type: application/json" -H "Authorization: Bearer ${ACCESS_TOKEN}" ${API}/apis/extensions/v1beta1/namespaces/${namespace}/deployments
Related
I have developed one web service for order management. This web service takes many complex objects as input parameters. I used curl to test and it works fine. Now I am writing a client but having issue when for ArrayList (e.g. the items are coming as ArrayList) objects. It's sending as String. It's seems the limitation the client framework I am using. I have tried one or two open frameworks but they are not working as expected. It will be great if you can suggest some framework with some examples.
Below is the sample curl request, I have removed some extra parameters to keep it simple.
curl -L -v -b agent_cookies.txt -H "Content-Type: application/json" -d
"{"items":{"atg-rest-class-type":"java.util.ArrayList","atg-rest-values":
[{"atg-rest-class-type":"com.bean.CommerceItemInfo","tinSkuNumber":"41589367","itemNumber":
280594,"color": 9,"size":
94,"salePrice":50.00,"taxAmount":3.5,"stateTax":0.48,"countyTax":0.08,"currencyCode":"USD"},{"atg-rest-class-type":"com..bean.CommerceItemInfo",
"tinSkuNumber":"41589375","itemNumber": 280594,"color": 9,"size":
96,"salePrice":100.00,"taxAmount":7,"stateTax":0.96,"countyTax":0.16,"currencyCode":"USD"}]},orderInfo:{...},"clientAddress":{"atg-rest-class-type":"java.util.ArrayList","atg-rest-values":
[{"atg-rest-class-type":"com.bean.ClientAddress",\"firstName\":\"John\",\"lastName\":\"Dao\",\"state\":\"FL\",\"country\":\"US\",\"postalCode\":\"33606\",\"address1\":\"100
S Edison Avenue\",\"address2\":\"Suite
D\",\"city\":\"Tampa\",\"addressType\":\"BOTH\"}]},{......}}"
http://localhost:8080/rest/model/com/web/actor/CartActor/testOrder
Thank you
After some research I found the limitation of ATG client and no way we can send List.I changed the arguments to accept individual beans only.
How to use the cURl command
curl https://na1.salesforce.com/services/data/v20.0/query?q=SELECT+name+from+Account
-H "Authorization: Bearer access_token" -H "X-PrettyPrint:1"
in java to call sales force rest web services
Java has an URLConnection Class that has similar functions as cURL.
For interacting with the salesforce API, it is best to use a client library and not implement it all by yourself, see http://blog.palominolabs.com/2011/03/03/a-new-java-salesforce-api-library/ for an example.
Easiest way is to download cURL java wrapper like https://github.com/pjlegato/curl-java and use cURL directly in your code.
Second way is to use Runtime.getRuntime().exec("crul...") "pattern" and run curl as a normal process.
I'm really new to APIs and POST or PUT or DELETE. I'm also new to running APIs using POST or other.
I have given a document which says
Function :- Add new Item
URI :- qtp/qtps
ACTION :- POST
REQUEST :- <n1:qtp xmlns:n1="http://www.mac.com/qts/xml/ns/qtm/qtpManagement"><name>rosa qtp 3</name><ipAddress>171.68.121.232</ipAddress><macAddress>10:0t:24:03:r7:57</macAddress><description>this is rosa qtp </description></n1:qtp>
I have absolutely no idea how to proceed further, But I know that by executing the request I need to Add a new Item in the application server, I tried something with browser myself but it did not work.
Can someone show me how can I work with this or explain me more about this or at-least give me a clue
One of the most useful tools for testing and debugging HTTP requests, in my experience, is cURL (http://curl.haxx.se/).
cURL is actually the under-the-hood library used for HTTP requests by a majority of PHP apps; the command-line version lets you do virtually anything that HTTP can do, and get great debugging data.
In the scenario you describe above, after downloading and installing cURL you'd likely use a command like:
curl --header "Content-Type: application/xml" --data '<XML YOU WANT TO SEND>' -X POST <URL TO WHICH DATA SHOULD BE SENT>
It's not clear from your question what the destination host+url is, but using the specific sample data you provide this would probably look like:
curl --header "Content-Type: application/xml" --data '<n1:qtp xmlns:n1="http://www.mac.com/qts/xml/ns/qtm/qtpManagement"><name>rosa qtp 3</name><ipAddress>171.68.121.232</ipAddress><macAddress>10:0t:24:03:r7:57</macAddress><description>this is rosa qtp </description></n1:qtp>' -X POST http://www.mac.com/qtp/qtps
Install a firebug plugin for that. You can use SOA client.
This is the second part of my question on converting cURL to Java
The first part is titled:
Converting cURL authentication to Java and retrieving & updating data using REST XML (Pt.1)
Third, how can I implement update, create, and delete for the api in Java? For example:
Update: curl -i -X PUT -H "Content-Type:application/xml" -H "Accept: application/xml" -d "<ticket><description>Take this description</description></ticket>" http://user:password#www.assembla.com/spaces/my_space_id/tickets/1
Delete" curl -i -X DELETE -H "Accept: application/xml" http://user:password#www.assembla.com/spaces/my_space_id/tickets/1
Create: curl -i -X POST -H "Content-Type:application/xml" -H "Accept: application/xml" -d "<ticket><summary>This is a Summary</summary><priority>3</priority></ticket>" the weblink
In other words, how can I convert these cURL code into Java?
I would really appreciate your help. Also, a good reference to do such stuff in Java will be awesome too.
Thanks.
Well, the official API usually helps: Assembla REST API
There is says that you need to use basic authentication.
For accessing REST in Java: Rest clients for Java?
you should be looking out for Apache HttpClient tutorials.
There's some Samplecode of a Android Rest Client application around, try searching for it. Also, I just discovered "resting". I haven't tried it, but might be worth a look.
Also watching the Developing Android REST client applications video from Google.io is recommended, as it is teaching some very important architectural basics and hints.
I placed a similar question some time ago, and got an answer here at Stackoverflow.
I want to make a multi-user client-server solution with Java Swing thick client as a front-end and Google AppEngine (Java one) as a back-end.
The problem is that GAE provides only web-based forms for logging in and out, so there's no trivial way to employ Google Accounts features in a thick client.
Can you give some advices/hints/ideas on how to allow a thick client login to and logout from a GAE webapp?
There is a way for client apps to authenticate against Google Accounts, but I don't know if the token you receive can be passed back to AppEngine. See: ClientLogin for Installed Applications
I am sorry, I can only answer you indirectly. It is possible to log in to an app on appspot.com with a Google account. You just have to do everything a browser would, including keeping some cookies and contacting several servers as they bounce you around.
I played around with this for a stillborn project a couple of months ago and ended up with a shell script that mostly runs cURL to log in. Perhaps you could take from it what you need.
#!/bin/bash
my_app="set-this-to-my-app-id"
url="http://$my_app.appspot.com"
curl='curl --cookie-jar cookies'
if [ -z "$EMAIL" -o -z "$PASS" ]; then
echo -n 'Email: '
read EMAIL
echo -n 'Pass: '
read PASS
fi
rm -f cookies auth
echo 'Login'
$curl https://www.google.com/accounts/ClientLogin --output auth \
-d "Email=$EMAIL" -d "Passwd=$PASS" \
-d accountType=HOSTED_OR_GOOGLE \
-d source=$my_app \
-d service=ah
. auth # XXX Be careful here. The output of the above
# command happens to be Bash syntax too!
rm -f auth
echo 'Logging into app and getting cookie'
$curl "$url/_ah/login?continue=$url/console/&auth=$Auth"
echo
echo 'Example POST query'
$curl -X POST --cookie cookies "$url/some/path" -d 'foo=bar'
echo
rm -f cookies
as suggested by #Jason DeFontes the ClientLogin authorization process is addressing this issue.
as a minimal-effort alternative approach, you could embed the web-based (html) forms into your thick client, i.e. use a java component that supports html-rendering (like a JEditorPane with an HTMLEditorKit installed) and present this component inside your swing app -- at least users would not need to switch back-and-forth between your app and the browser this way.