Maestro API: Reporting Without Mediators

by Svitlana Ostnek

EPAM Cloud is rapidly developing, and it includes not only new features and tools, but also the development of API which enables direct interaction with Orchestration. As API is developing rather rapidly, documentation cannot keep up with all the changes. However, we believe that there are cases when a clear peace of code can be more explanatory than pages of text. We are going to prove it with a simple example of a code aimed to retrieve billing reports.

In Maestro CLI, the reports are retrived by or2report command, followed by a set of parameters that specify the report details and type:



On the screenshot, we highlighted the most essential report parameters, necessary to get a report.

To request a report programmatically, you need to use the following class entities

  • To get a project total report:

    GetProjectSubTotal(project, year, month, day)
  • To get a project subtotal report:

    GetProjectTotal(project, year, month, day)
  • To get a report by instance:

    GetInstanceReport(project, year, month, day)

To download and use Maestro SDK, address EPAM Artificatory. In EPM-CIT folder, you can find the latest maestro-sdk sources and use them with your build tool.

Our code example will use the following imports from Maestro SDK:

import com.maestro.sdk.client.MaestroApiClient;
import com.maestro.sdk.client.command.Command;
import com.maestro.sdk.client.command.report.*;
import com.maestro.sdk.client.config.Configuration;
import com.maestro.sdk.client.config.Protocol;
import com.maestro.sdk.client.exception.MaestroApiException;
import com.maestro.sdk.client.impl.MaestroApiClientImpl;
import com.maestro.sdk.http.rpc.Result;

  • 1. The code will use constants that define target project name, region name, and instance ID.

      public static final String PROJECT = "DEMOPRO";
      public static final String REGION = "EPAM-BY1";
      public static final String INSTANCE = "i-1234abcd";

  • 2. Create properties object and add HTTP client configuration file name to it

        Properties properties = new Properties();
        // add optional HTTP client configuration file name
        properties.put(Configuration.CLIENT_CONFIG_FILENAME, "cli-http-client.properties");
  • 3. Set up Maestro API client with the configuration, that includes the previously created properties. Set client credentials that will be used to access Orchestrator. These are your id and the token created in the default.cr file by or2access command run.

        MaestroApiClient client = new MaestroApiClientImpl(
          new Configuration(
            Protocol.JSON_RPC,
            "http://localhost:8080",
            null,
            properties));

        client.setCredentials(
          "user@epam.com",
          "faa312aa-1e5f-40e2-942b-99e7a91faaac");

  • 4. Prepare a batch of requests. In the example below, it is designed to retrieve total project report for the first 6 months of 2013.

        GetProjectTotal req1 = new GetProjectTotal(PROJECT, 2013, 1, null);
        GetProjectTotal req2 = new GetProjectTotal(PROJECT, 2013, 2, null);
        GetProjectTotal req3 = new GetProjectTotal(PROJECT, 2013, 3, null);
        GetProjectTotal req4 = new GetProjectTotal(PROJECT, 2013, 4, null);
        GetProjectTotal req5 = new GetProjectTotal(PROJECT, 2013, 5, null);
        GetProjectTotal req6 = new GetProjectTotal(PROJECT, 2013, 6, null);
  • 5. Execute the batch of requests using the client created on step 3.

        List<Result<?>> results = client.execute(Arrays.<Command<?>>asList(req1, req2, req3, req4, req5, req6));

  • 6.Process the resuls of the requests execution

        for (Result<?> result : results) {
         if (result.getError() == null) {
          GetProjectTotalResult totalResult = (GetProjectTotalResult) result.getResult();
          System.out.println(totalResult.getYear() + "-" + totalResult.getMonth() + ":" + totalResult.getTotalPrice().toPlainString());
         } else {
          System.out.println("Error: " + result.getError().getCode());
         }
        }

    //
  • 7. Below you can see similar example of subtotal reports retrieving and processing.

        GetProjectSubTotal reqSubTotal1 = new GetProjectSubTotal(PROJECT, 2013, 1, null);
        GetProjectSubTotal reqSubTotal2 = new GetProjectSubTotal(PROJECT, 2013, 2, null);
        results = client.execute(Arrays.<Command<?>>asList(reqSubTotal1, reqSubTotal2));

        for (Result<?> result : results) {
         if (result.getError() == null) {
          GetProjectSubTotalResult subTotalResult = (GetProjectSubTotalResult) result.getResult();
          System.out.println(subTotalResult.getYear() + "-" + subTotalResult.getMonth() + ":" + subTotalResult.getTotalPrice().toPlainString());
         } else {
          System.out.println("Error: " + result.getError().getCode());
         }
        }
    //
  • 8. The other example shows reports for a specific instance.

        GetInstanceReport instanceReport1 = new GetInstanceReport(REGION, PROJECT, INSTANCE, 2013, 1, null);
        GetInstanceReport instanceReport2 = new GetInstanceReport(REGION, PROJECT, INSTANCE, 2013, 2, null);
        results = client.execute(Arrays.<Command<?>>asList(instanceReport1, instanceReport2));

        for (Result<?> result : results) {
         if (result.getError() == null) {
          GetInstanceReportResult totalResult = (GetInstanceReportResult) result.getResult();
          System.out.println(totalResult.getYear() + "-" + totalResult.getMonth() + ":" + totalResult.getTotalPrice().toPlainString());
         } else {
          System.out.println("Error: " + result.getError().getCode());
         }
        }

Maestro API is rapidly developing, and we keep on getting "how-to" requests from our users. Keep track of our blog updates: new API tips are coming soon!