Skip to content

Commit 9201b7d

Browse files
committed
feat: add spark history server api
Add api methods for managing spark history server. Add submissionTime and autoTerminationTime fields to Application response models. BREAKING CHANGE: Type of timestamp fields in Application response models has been changed to `Date`. The type of timestamp fields like startTime, endTime in `ApplicationGetStateResponse` and `Application` models has been changed from `String` to `Date`. Signed-off-by: Subin Shekhar <[email protected]>
1 parent d9e4585 commit 9201b7d

23 files changed

+1072
-77
lines changed

modules/examples/src/main/java/com/ibm/cloud/iaesdk/ibm_analytics_engine_api/v3/IbmAnalyticsEngineApiExamples.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.GetLogForwardingConfigOptions;
3333
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.GetLoggingConfigurationOptions;
3434
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.GetResourceConsumptionLimitsOptions;
35+
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.GetSparkHistoryServerOptions;
3536
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.Instance;
3637
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.InstanceGetStateResponse;
3738
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.InstanceHomeResponse;
@@ -44,6 +45,9 @@
4445
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.ResourceConsumptionLimitsResponse;
4546
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.Runtime;
4647
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.SetInstanceHomeOptions;
48+
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.SparkHistoryServerResponse;
49+
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.StartSparkHistoryServerOptions;
50+
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.StopSparkHistoryServerOptions;
4751
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.UpdateInstanceDefaultConfigsOptions;
4852
import com.ibm.cloud.sdk.core.http.Response;
4953
import com.ibm.cloud.sdk.core.service.exception.ServiceResponseException;
@@ -241,9 +245,9 @@ public static void main(String[] args) throws Exception {
241245
CreateApplicationOptions createApplicationOptions = new CreateApplicationOptions.Builder()
242246
.instanceId("dc0e9889-eab2-4t9e-9441-566209499546")
243247
.applicationDetails(new ApplicationRequestApplicationDetails.Builder()
244-
.application("/opt/ibm/spark/examples/src/main/python/wordcount.py")
248+
.application("/opt/ibm/spark/examples/src/main/python/wordcount.py")
245249
.addArguments("/opt/ibm/spark/examples/src/main/resources/people.txt")
246-
.runtime(runtimeModel)
250+
.runtime(runtimeModel)
247251
.build())
248252
.build();
249253

@@ -263,8 +267,6 @@ public static void main(String[] args) throws Exception {
263267
ListApplicationsOptions listApplicationsOptions = new ListApplicationsOptions.Builder()
264268
.instanceId("dc0e9889-eab2-4t9e-9441-566209499546")
265269
.addState("accepted")
266-
.addState("submitted")
267-
.addState("waiting")
268270
.addState("running")
269271
.addState("finished")
270272
.addState("failed")
@@ -420,6 +422,54 @@ public static void main(String[] args) throws Exception {
420422
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
421423
}
422424

425+
try {
426+
System.out.println("startSparkHistoryServer() result:");
427+
// begin-start_spark_history_server
428+
StartSparkHistoryServerOptions startSparkHistoryServerOptions = new StartSparkHistoryServerOptions.Builder()
429+
.instanceId("dc0e9889-eab2-4t9e-9441-566209499546")
430+
.build();
431+
432+
Response<SparkHistoryServerResponse> response = ibmAnalyticsEngineApiService.startSparkHistoryServer(startSparkHistoryServerOptions).execute();
433+
SparkHistoryServerResponse sparkHistoryServerResponse = response.getResult();
434+
435+
System.out.println(sparkHistoryServerResponse);
436+
// end-start_spark_history_server
437+
} catch (ServiceResponseException e) {
438+
logger.error(String.format("Service returned status code %s: %s%nError details: %s",
439+
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
440+
}
441+
442+
try {
443+
System.out.println("getSparkHistoryServer() result:");
444+
// begin-get_spark_history_server
445+
GetSparkHistoryServerOptions getSparkHistoryServerOptions = new GetSparkHistoryServerOptions.Builder()
446+
.instanceId("dc0e9889-eab2-4t9e-9441-566209499546")
447+
.build();
448+
449+
Response<SparkHistoryServerResponse> response = ibmAnalyticsEngineApiService.getSparkHistoryServer(getSparkHistoryServerOptions).execute();
450+
SparkHistoryServerResponse sparkHistoryServerResponse = response.getResult();
451+
452+
System.out.println(sparkHistoryServerResponse);
453+
// end-get_spark_history_server
454+
} catch (ServiceResponseException e) {
455+
logger.error(String.format("Service returned status code %s: %s%nError details: %s",
456+
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
457+
}
458+
459+
try {
460+
// begin-stop_spark_history_server
461+
StopSparkHistoryServerOptions stopSparkHistoryServerOptions = new StopSparkHistoryServerOptions.Builder()
462+
.instanceId("dc0e9889-eab2-4t9e-9441-566209499546")
463+
.build();
464+
465+
Response<Void> response = ibmAnalyticsEngineApiService.stopSparkHistoryServer(stopSparkHistoryServerOptions).execute();
466+
// end-stop_spark_history_server
467+
System.out.printf("stopSparkHistoryServer() response status code: %d%n", response.getStatusCode());
468+
} catch (ServiceResponseException e) {
469+
logger.error(String.format("Service returned status code %s: %s%nError details: %s",
470+
e.getStatusCode(), e.getMessage(), e.getDebuggingInfo()), e);
471+
}
472+
423473
try {
424474
// begin-delete_application
425475
DeleteApplicationOptions deleteApplicationOptions = new DeleteApplicationOptions.Builder()

modules/ibm-analytics-engine-api/src/main/java/com/ibm/cloud/iaesdk/ibm_analytics_engine_api/v3/IbmAnalyticsEngineApi.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.GetLogForwardingConfigOptions;
3838
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.GetLoggingConfigurationOptions;
3939
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.GetResourceConsumptionLimitsOptions;
40+
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.GetSparkHistoryServerOptions;
4041
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.Instance;
4142
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.InstanceGetStateResponse;
4243
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.InstanceHomeResponse;
@@ -49,6 +50,9 @@
4950
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.ResourceConsumptionLimitsResponse;
5051
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.Runtime;
5152
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.SetInstanceHomeOptions;
53+
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.SparkHistoryServerResponse;
54+
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.StartSparkHistoryServerOptions;
55+
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.StopSparkHistoryServerOptions;
5256
import com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model.UpdateInstanceDefaultConfigsOptions;
5357
import com.ibm.cloud.sdk.core.http.RequestBuilder;
5458
import com.ibm.cloud.sdk.core.http.ResponseConverter;
@@ -601,6 +605,7 @@ public ServiceCall<LogForwardingConfigResponse> getLogForwardingConfig(GetLogFor
601605
* Enable or disable log forwarding.
602606
*
603607
* Enable or disable log forwarding from IBM Analytics Engine to IBM Log Analysis server.
608+
* *Note:* Deprecated. Use the log forwarding config api instead.
604609
*
605610
* @param configurePlatformLoggingOptions the {@link ConfigurePlatformLoggingOptions} containing the options for the call
606611
* @return a {@link ServiceCall} with a result of type {@link LoggingConfigurationResponse}
@@ -630,6 +635,7 @@ public ServiceCall<LoggingConfigurationResponse> configurePlatformLogging(Config
630635
* Retrieve the logging configuration for a given instance id.
631636
*
632637
* Retrieve the logging configuration of a given Analytics Engine instance.
638+
* *Note:* Deprecated. Use the log forwarding config api instead.
633639
*
634640
* @param getLoggingConfigurationOptions the {@link GetLoggingConfigurationOptions} containing the options for the call
635641
* @return a {@link ServiceCall} with a result of type {@link LoggingConfigurationResponse}
@@ -650,4 +656,74 @@ public ServiceCall<LoggingConfigurationResponse> getLoggingConfiguration(GetLogg
650656
return createServiceCall(builder.build(), responseConverter);
651657
}
652658

659+
/**
660+
* Start Spark history server.
661+
*
662+
* Start the Spark history server for the given Analytics Engine instance.
663+
*
664+
* @param startSparkHistoryServerOptions the {@link StartSparkHistoryServerOptions} containing the options for the call
665+
* @return a {@link ServiceCall} with a result of type {@link SparkHistoryServerResponse}
666+
*/
667+
public ServiceCall<SparkHistoryServerResponse> startSparkHistoryServer(StartSparkHistoryServerOptions startSparkHistoryServerOptions) {
668+
com.ibm.cloud.sdk.core.util.Validator.notNull(startSparkHistoryServerOptions,
669+
"startSparkHistoryServerOptions cannot be null");
670+
Map<String, String> pathParamsMap = new HashMap<String, String>();
671+
pathParamsMap.put("instance_id", startSparkHistoryServerOptions.instanceId());
672+
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/analytics_engines/{instance_id}/spark_history_server", pathParamsMap));
673+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("ibm_analytics_engine_api", "v3", "startSparkHistoryServer");
674+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
675+
builder.header(header.getKey(), header.getValue());
676+
}
677+
builder.header("Accept", "application/json");
678+
ResponseConverter<SparkHistoryServerResponse> responseConverter =
679+
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SparkHistoryServerResponse>() { }.getType());
680+
return createServiceCall(builder.build(), responseConverter);
681+
}
682+
683+
/**
684+
* Get Spark history server details.
685+
*
686+
* Get the details of the Spark history server of the given Analytics Engine instance.
687+
*
688+
* @param getSparkHistoryServerOptions the {@link GetSparkHistoryServerOptions} containing the options for the call
689+
* @return a {@link ServiceCall} with a result of type {@link SparkHistoryServerResponse}
690+
*/
691+
public ServiceCall<SparkHistoryServerResponse> getSparkHistoryServer(GetSparkHistoryServerOptions getSparkHistoryServerOptions) {
692+
com.ibm.cloud.sdk.core.util.Validator.notNull(getSparkHistoryServerOptions,
693+
"getSparkHistoryServerOptions cannot be null");
694+
Map<String, String> pathParamsMap = new HashMap<String, String>();
695+
pathParamsMap.put("instance_id", getSparkHistoryServerOptions.instanceId());
696+
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/analytics_engines/{instance_id}/spark_history_server", pathParamsMap));
697+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("ibm_analytics_engine_api", "v3", "getSparkHistoryServer");
698+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
699+
builder.header(header.getKey(), header.getValue());
700+
}
701+
builder.header("Accept", "application/json");
702+
ResponseConverter<SparkHistoryServerResponse> responseConverter =
703+
ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SparkHistoryServerResponse>() { }.getType());
704+
return createServiceCall(builder.build(), responseConverter);
705+
}
706+
707+
/**
708+
* Stop Spark history server.
709+
*
710+
* Stop the Spark history server of the given Analytics Engine instance.
711+
*
712+
* @param stopSparkHistoryServerOptions the {@link StopSparkHistoryServerOptions} containing the options for the call
713+
* @return a {@link ServiceCall} with a void result
714+
*/
715+
public ServiceCall<Void> stopSparkHistoryServer(StopSparkHistoryServerOptions stopSparkHistoryServerOptions) {
716+
com.ibm.cloud.sdk.core.util.Validator.notNull(stopSparkHistoryServerOptions,
717+
"stopSparkHistoryServerOptions cannot be null");
718+
Map<String, String> pathParamsMap = new HashMap<String, String>();
719+
pathParamsMap.put("instance_id", stopSparkHistoryServerOptions.instanceId());
720+
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/analytics_engines/{instance_id}/spark_history_server", pathParamsMap));
721+
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("ibm_analytics_engine_api", "v3", "stopSparkHistoryServer");
722+
for (Entry<String, String> header : sdkHeaders.entrySet()) {
723+
builder.header(header.getKey(), header.getValue());
724+
}
725+
ResponseConverter<Void> responseConverter = ResponseConverterUtils.getVoid();
726+
return createServiceCall(builder.build(), responseConverter);
727+
}
728+
653729
}

modules/ibm-analytics-engine-api/src/main/java/com/ibm/cloud/iaesdk/ibm_analytics_engine_api/v3/model/Application.java

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2022.
2+
* (C) Copyright IBM Corp. 2023.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -12,6 +12,8 @@
1212
*/
1313
package com.ibm.cloud.iaesdk.ibm_analytics_engine_api.v3.model;
1414

15+
import java.util.Date;
16+
1517
import com.google.gson.annotations.SerializedName;
1618
import com.ibm.cloud.sdk.core.service.model.GenericModel;
1719

@@ -30,16 +32,8 @@ public interface State {
3032
String RUNNING = "running";
3133
/** failed. */
3234
String FAILED = "failed";
33-
/** error. */
34-
String ERROR = "error";
3535
/** accepted. */
3636
String ACCEPTED = "accepted";
37-
/** submitted. */
38-
String SUBMITTED = "submitted";
39-
/** waiting. */
40-
String WAITING = "waiting";
41-
/** unknown. */
42-
String UNKNOWN = "unknown";
4337
/** stopped. */
4438
String STOPPED = "stopped";
4539
/** auto_terminated. */
@@ -56,12 +50,18 @@ public interface State {
5650
@SerializedName("spark_application_name")
5751
protected String sparkApplicationName;
5852
protected String state;
53+
@SerializedName("spark_ui")
54+
protected String sparkUi;
55+
@SerializedName("submission_time")
56+
protected Date submissionTime;
5957
@SerializedName("start_time")
60-
protected String startTime;
58+
protected Date startTime;
6159
@SerializedName("end_time")
62-
protected String endTime;
60+
protected Date endTime;
6361
@SerializedName("finish_time")
64-
protected String finishTime;
62+
protected Date finishTime;
63+
@SerializedName("auto_termination_time")
64+
protected Date autoTerminationTime;
6565

6666
/**
6767
* Gets the id.
@@ -129,14 +129,36 @@ public String getState() {
129129
return state;
130130
}
131131

132+
/**
133+
* Gets the sparkUi.
134+
*
135+
* URL of the Apache Spark web UI that is available when the application is running.
136+
*
137+
* @return the sparkUi
138+
*/
139+
public String getSparkUi() {
140+
return sparkUi;
141+
}
142+
143+
/**
144+
* Gets the submissionTime.
145+
*
146+
* Time when the application was submitted.
147+
*
148+
* @return the submissionTime
149+
*/
150+
public Date getSubmissionTime() {
151+
return submissionTime;
152+
}
153+
132154
/**
133155
* Gets the startTime.
134156
*
135157
* Time when the application was started.
136158
*
137159
* @return the startTime
138160
*/
139-
public String getStartTime() {
161+
public Date getStartTime() {
140162
return startTime;
141163
}
142164

@@ -147,19 +169,30 @@ public String getStartTime() {
147169
*
148170
* @return the endTime
149171
*/
150-
public String getEndTime() {
172+
public Date getEndTime() {
151173
return endTime;
152174
}
153175

154176
/**
155177
* Gets the finishTime.
156178
*
157-
* Time when the application was completed.
179+
* (deprecated) Time when the application was completed.
158180
*
159181
* @return the finishTime
160182
*/
161-
public String getFinishTime() {
183+
public Date getFinishTime() {
162184
return finishTime;
163185
}
186+
187+
/**
188+
* Gets the autoTerminationTime.
189+
*
190+
* Time when the application will be automatically stopped by the service.
191+
*
192+
* @return the autoTerminationTime
193+
*/
194+
public Date getAutoTerminationTime() {
195+
return autoTerminationTime;
196+
}
164197
}
165198

0 commit comments

Comments
 (0)