Can we create an HBase namespace through REST api? - rest

We can create an HBase table through REST api (i.e., http://{hbase-rest-server-ip:port}/{table-name}/schema), but I haven't found a REST api through which we can create an HBase namespace. Is there such an api ?

As far as I know, you can't yet.
As it happens, Last day a bug was raised in the HBase jira for it!
HBASE-14147

POST http://{hbase-rest-server-ip:port}/namespaces/{new namespace name}
(No body required)
This should return HTTP/1.1 201 Created and not a lot else. If it returns 401 try using PUT instead!
Tables without a namespace (and colon) go into the 'default' namespace
To create or access a table in a specific namespace use a colon eg. {namespace name}:{table name}
To list all namespaces GET{hbase-rest-server-ip:port}/namespaces/
To list tables within a namespace GET
http://{hbase-rest-server-ip:port}/namespaces/tester/tables
Note: Default port seems to be 8070
Example: using curl for hbase server on 10.10.10.1 port 8070
Create new namespace "new_name_space":
curl -vi -X POST "http://10.10.10.1:8070/namespaces/new_name_space"
Create new table in namespace "new_table" with column families "family1" and "family2" namespace "new_name_space":
curl -vi -X POST \
-H "Content-Type: application/json" \
-d '{"name":"new_name_space:new_table","ColumnSchema":[{"name":"family1"},{"name":"family2"}]}"' \
"http://10.10.10.1:8070/new_name_space:new_table/schema"
More info: https://www.cloudera.com/documentation/enterprise/latest/topics/admin_hbase_rest_api.html

Related

Kubernetes REST API - how to get pod logs when more than one container is running?

Forgive me for asking a stupid question but I can't seem to find anywhere in the Kubernetes API reference how to query logs via the REST API if there's more than one container running inside the pod?
cURL -k -H Authorization: Bearer my-super-secret-token https://kubernetes/api/v1/namespaces/default/pods/my-app-1/log
Returns:
{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"a
container name must be specified for pod my-app-1,
choose one of: [nginx php-fpm]","reason":"BadRequest","code":400}
I tried:
cURL -k -H Authorization: Bearer my-super-secret-token https://kubernetes/api/v1/namespaces/default/pods/my-app-1/nginx/log
and it results in an error that the resource can't be found.
How do I specify the container name when making an HTTP request to the API?
Figured it out - I needed to add container using a query parameter:
?container=nginx
Working Example:
cURL -k -H Authorization: Bearer my-super-secret-token https://kubernetes/api/v1/namespaces/default/pods/my-app-1/log?container=nginx

How to access Kubernetes API from node directly

From a Kubernetes node, how can I access API server, how can I find out the API endpoint and handle authentication? It is a Windows node by the way.
I'm surprised that there is not much information I could find on the Internet about this, is accessing Kubernetes API from node directly a bad design?
"From the node" sound like a fringe use case, like addons, which are usually covered by using the "admin.conf" file that was deployed during node attachement and contains whatever you would need to connect to the api server.
A more usual approach would be to deploy your workload in a Pod which service account would have the proper role binding to access the API server.
How to access Kubernetes API from node directly?
There are multiple ways , one of the way is from master node
# Get API Server URL:
kubectl cluster-info
#access it using the curl
curl https://<api serverIP>:6443/api/v1/nodes --cacert /etc/srv/kubernetes/pki/ca-certificates.crt --cert /var/lib/kubelet/pki/kubelet-client.crt --key /var/lib/kubelet/pki/kubelet-client.key
how can I find out the API endpoint and handle authentication?
One technique i use is using --v=11 with kubectl commands , it will give endpoints of the kubernetes resources
#example :
kubectl get pods --v=11 2>&1 | grep GET
I1229 10:20:41.098241 42907 round_trippers.go:423] curl -k -v -XGET -H "Accept: application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json" -H "User-Agent: kubectl/v1.19.4 (linux/amd64) kubernetes/d360454" 'https://10.157.160.165:6443/api/v1/namespaces/default/pods?limit=500'
I1229 10:20:41.116964 42907 round_trippers.go:443] GET https://<apiserver>:6443/api/v1/namespaces/default/pods?limit=500 200 OK in 18 milliseconds
It is a Windows node by the way
Ideally above steps should work , May be you need to find out equivalent commands for grep & curl. change location of the certs to appropriate locations. you can find the location of certs from admin.conf file.

Keycloak Admin REST API: query more than 100 resource objects

I have a client in Keycloak with more than 100 resources.
And I am trying to query the id of a resource with the Keycloak Admin REST API the following way:
RESOURCE_ID=$(curl -k -s -H "Authorization: bearer $ACCESS_TOKEN" "$KEYCLOAK_URL/auth/admin/realms/$REALM/clients/$CLIENT_ID/authz/resource-server/resource" | jq -r '.[] | select(.name=="xy resource")._id')
Unfortunatelly "xy resource" is at the end of the alphabetically ordered list and the curl gives back only th first 100 resource objects.
Is there a way to query more than 100 records with the Keycloak Admin REST API or query directly the one with the given name?
I use Keycloak 12.0.4.
Please check REST API documentation, there are a lot of Query optional parameter 'max'
Maximum results size (defaults to 100) integer(int32)
https://www.keycloak.org/docs-api/7.0/rest-api/

Jenkins REST API: Create new Job View

I am using the Jenkins REST API to automate our CI process.
The last thing that is missing in the automatization pipeline is the creation of a view if theuser-defined view does not exist.
So far I used:
jenkins_alias/createView?name=My-Test-View
but it is somehow incomplete and returns the error that:
the viewtype should be defined
how can I define this viewtype from the RESTAPI? Should I send it in the Url or in the request body?
thanks
Per this post, this is apparently (a) possible with the REST API and (b) without referencing any weird Hudson stuff.
# create the view
curl -vvv -X POST -d #view.xml -H "Content-Type: text/xml" http://localhost:8080/createView?name=MyView
# get the configuration
curl http://localhost:8080/view/MyView/config.xml
# update the view
curl -X POST -d #view.xml -H "Content-Type: text/xml" http://localhost:8080/view/MyView/config.xml
Caveat emptor - I believe this is undocumented. According to the Jenkins REST API documentation, all the REST API can do is:
retrieve information from Jenkins for programmatic consumption
trigger a new build
create/copy jobs
Please try this request as an example:
curl -X POST -H 'Jenkins-Crumb:<JENKINS-CRUMB>' --form name=test --form mode=hudson.model.ListView --form json='{"name": "test", "mode": "hudson.model.ListView"}' https://<Jenkins-URL>/createView
View types:
ListView: hudson.model.ListView
Dashboard (if plugin Dashboard View is installed): hudson.plugins.view.dashboard.Dashboard
MyView: hudson.model.MyView

running a rundeck job from a rest api

I would like to allow anyone to trigger a job I've created in Rundeck.
I can't understand from the API documentation how to do that.
Any one knows, and can give simple examples (my understanding of the subject is minimal to none)?
What I've found is of the sort:
POST /api/1/job/[ID]/run
In order to use the Rundeck API, you need to authenticate first.
Authentication can be done in two different ways:
Using a Token
Using a username and a password
Here is an example of running a Rundeck job using its API (Token based authentication)
curl -X POST http://rundeck_server:port/api/19/job/87bdc26ce-9893-49bd-ad7a-97f4c4a39196/run?authtoken=AVy8jZdcpTYOyPcOVbfcfOQmB6b92zRu --header "Content-Type:text/xml"
Explanation:
19: the API version or Rundeck installation version (19 matchs
Rundeck 2.8.2)
87bdc26ce-9893-49bd-ad7a-97f4c4a39196: Job UUID
run: Runs a job
PS: To obtain an API Token, you must first log in to the Rundeck GUI using a user account. Click on your username in the header of the page, and you will be shown your User Profile page. From this page you can manage your API Tokens.
To update the answer above, this is an example of running a job and feeding it arguments
You will need to replace hostname/API version/job UID/token
Also the current version can be used with JSON only
curl -X POST https://rundeck-hostname.com/api/41/job/7087d3b7-e454-4983-abd5-a211d21d6f27/run?authtoken=[redacted] -H "Accept: application/json" -H "Content-Type: application/json" -d '{
"options": {
"optionName":"optionValue",
}
}
'
And if you need additional arguments for running a job you can find the updated documentation at https://docs.rundeck.com/docs/api/rundeck-api.html#running-a-job