Jelastic Cloud API
This guide has been reviewed and reformatted for Ruk-Com Cloud PaaS. Screens may vary slightly by platform version.
Click or tap a screenshot to view it at its original size.
Objective
This guide explains how to use Jelastic Cloud API on Ruk-Com Cloud PaaS, with ordered procedures and practical verification points.
Before you begin
- Sign in with an account permitted to manage the relevant environment.
- Confirm the target environment, region and resources before saving changes.
- Create a backup or rollback plan before changing a production system.
Jelastic Cloud APIHelps developers complete the required settings for application's lifecycle and extend the functionality of our platform by integrating other services. Using the API, you can program environments, deploy apps, and perform other tasks that were previously possible through the dashboard.
Jelastic API follows REST theory;REST APIIt defines a set of functions that developers can request and receive responses to. Interactions are performed over the HTTPS protocol. The advantage of this approach is the broadening of the HTTPS protocol, which makes the REST API applicable to almost any programming language.
Jelastic API Request
All API method requests are GET or POST HTTPS-requests to a URL with a set of parameters:
https://{hoster-api-host}/1.0/
The type of URL that should be used is specified in each method in the REST field.
The request data can be sent as a query string (after the “?”) while using the GET method or in the body of a POST request. In the case of a GET request, the parameters must be percentage-encoded (URL encoding).
Note:As of Jalastic 5.1, the GET method is not supported within API requests due to security reasons:
Signin-https://[hoster-api-host]/1.0/users/authentication/rest/signin?login=[string]&password=[string]
Signup-https://reg.[hoster-domain]/signup?email=[string]
Change password-https://[hoster-api-host]/1.0/users/account/rest/changepassword?oldPassword=[string]&newPassword=[string]session=[string]
As a reminder, there is a URL request length limit of 2048 characters, so we recommend using:
- GET request to get data from the database to display
- POST requests are used for data changes (creating an environment, changing configuration files, etc.).
This way you are not limited in the length of your request. Additionally, such implementations are more relevant to HTTPS protocol specifications. All Jelastic API methods require authentication and execution target details. which is provided through parameterssessionandenvNamerespectively
Note:If there is no argumentenvNameIn the method description, it will be applied to all accounts/platforms without deprecation.appidwhich were previously used to target actions should be ignored.
The text value of the parameter should be specified in UTF-8 code. The order of the parameters in the requset is not important.
Jelastic API Response
requests and responses are encoded in UTF-8. For responses, API functions are provided in the formatJSONAn example of how to do this is in the document below.
Jelastic API Operations
To start Jelastic API process automation, you must meet the following requirements:
- You must register with a hosting provider.
- You must downloadJelastic Client Libraryappropriate (according to the platform version used) and add it to the classpath.
If you are using Maven, add the following dependencies topom.xml
<dependency>
<groupId>com.jelastic</groupId>
<artifactId>jelastic-public-j2se</artifactId>
<version>3.1</version>
</dependency>
To call API functions, you need to check the "session" parameter. It is responsible for authentication. For example, specify a user with a request, whose session can be achieved using the method:Users > Authentication > Signin
https://{hoster-api-host}/1.0/users/authentication/rest/signin?login=[string]&password=[string]
By login and password is your Ruk-Com Cloud account.
Calls to API functions should be executed with the received session value. To complete a working session with the API, go toUsers > Authentication > Signout
https://{hoster-api-host}/1.0/users/authentication/rest/signout?session=[string]
With the help of Jelastic Java Client Library, you can automate various operations connected to application lifecycle management, such as environment creation, state changes, deletions, node restarts, application deployment, etc.
So let's look at how to create an environment with a custom topology and settings using the Jelastic Java Client Library.
Creating the environment
A full version example of creating an environment in a document.Jelastic API(Jelastic Java Examples Tab) We will explain the main steps as follows:
1. Create a new public class environment that will include all of the following blocks and parameters. The first block of parameters should contain this string:
private final static String HOSTER_URL = "<hoster-url>";
private final static String USER_EMAIL = "<email>";
private final static String USER_PASSWORD = "<password>";
private final static String ENV_NAME = "test-api-environment-" + new Random().nextInt(100);
where:
- <hoster-url>- Hoster's URL / API such asapp.manage.Ruk-Com.cloud
- <email>- The email address you registered with Ruk-Com Cloud (login)
- <password>- Your password for your Ruk-Com Cloud account.
2. Then configure authentication, which will use the login and password you specified above.
public static void main(String[] args) {
System.out.println("Authenticate user...");
AuthenticationResponse authenticationResponse = authenticationService.signin(USER_EMAIL, USER_PASSWORD);
System.out.println("Signin response: " + authenticationResponse);
if (!authenticationResponse.isOK()) {
System.exit(authenticationResponse.getResult());
}
final String session = authenticationResponse.getSession();
After authentication, a new unique session is created which is used to perform necessary operations within the user account. All additional API function calls should be made within this session, which will remain available to you until the Signout method call.
3. The next step is to get the list of engines available for identification.<engine_type>(It can be java, php, ruby, js etc.)
System.out.println("Getting list of engines...");
ArrayResponse arrayResponse = environmentService.getEngineList(session, "<engine_type>");
System.out.println("GetEngineList response: " + arrayResponse);
if (!arrayResponse.isOK()) {
System.exit(arrayResponse.getResult());
}
4. After receiving the list of all available node templates for identification.<templates_type>which can be:
- ALL - All available template platforms such as native and cartridges.
- NATIVE - The default node template.
- CARTRIDGE - A custom template that the hosting provider adds to the platform as a cartridge.
System.out.println("Getting list of templates...");
arrayResponse = environmentService.getTemplates(session, "<templates_type>", false);
System.out.println("GetTemplates response: " + arrayResponse);
if (!arrayResponse.isOK()) {
System.exit(arrayResponse.getResult());
}
5. The next block is for the configuration and custom settings of the new environment and server. You can see more details about the JSON parameters used to define the environment topology.here:
JSONObject env = new JSONObject()
.put("ishaenabled", false)
.put("engine", "php5.5")
.put("shortdomain", ENV_NAME);
JSONObject apacheNode = new JSONObject()
.put("nodeType", "apache2")
.put("extip", false)
.put("count", 1)
.put("fixedCloudlets", 1)
.put("flexibleCloudlets", 4);
JSONObject mysqlNode = new JSONObject()
.put("nodeType", "mysql5")
.put("extip", false)
.put("fixedCloudlets", 1)
.put("flexibleCloudlets", 4);
JSONObject memcachedNode = new JSONObject()
.put("nodeType", "memcached");
JSONArray nodes = new JSONArray()
.put(apacheNode)
.put(mysqlNode)
.put(memcachedNode);
6. Finally, create a new environment by specifying all settings:
System.out.println("Creating environment...");
ScriptEvalResponse scriptEvalResponse = environmentService.createEnvironment(session,
"createenv", env.toString(), nodes.toString());
System.out.println("CreateEnvironment response: " + scriptEvalResponse);