Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7f36bd3
[DSIP-23][TaskPlugin] SagemakerTask resource leak repair
Nov 25, 2025
fc1a075
[Improvement-17725][TaskPlugin] SagemakerTask resource leak repair
Nov 25, 2025
9c3bedf
Merge branch 'DSIP-23-SagemakerTask' of github.com:niumy0701/dolphins…
Nov 25, 2025
fbedece
[Improvement-17725][TaskPlugin] SagemakerTask resource leak repair
Nov 26, 2025
9166e4a
[Improvement-17725][TaskPlugin] SagemakerTask resource leak repair
Nov 26, 2025
7c25e45
[Improvement-17725][TaskPlugin] SagemakerTask resource leak repair
Nov 26, 2025
d4b0c6c
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Nov 26, 2025
6b64cd1
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Nov 27, 2025
316571b
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Nov 27, 2025
97286e8
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Nov 28, 2025
903c094
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Nov 28, 2025
b3b2128
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Nov 28, 2025
3a96e4f
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Dec 1, 2025
a0fb913
[Improvement-17725][TaskPlugin] SagemakerTask resource leak repair
Dec 2, 2025
79c0c95
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Dec 3, 2025
dd94c73
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Dec 4, 2025
a589e38
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Dec 4, 2025
7982702
Merge branch 'dev' into DSIP-23-SagemakerTask
niumy0701 Dec 5, 2025
c88d20b
Merge branch 'dev' of github.com:niumy0701/dolphinscheduler into DSIP…
Dec 8, 2025
7a7db72
[Improvement-17725][TaskPlugin] SagemakerTask resource leak repair
Dec 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,42 @@ public void submitApplication() throws TaskException {

@Override
public void cancelApplication() {
initPipelineId();
try {
initPipelineId();
// stop pipeline
utils.stopPipelineExecution(client, pipelineId);
} catch (Exception e) {
throw new TaskException("cancel application error", e);
log.error("SageMaker task cancel application error: {}", e.getMessage(), e);
throw new TaskException("SageMaker task cancel application error: " + e.getMessage(), e);
} finally {
// shutdown client
if (client != null) {
client.shutdown();
}
}
}

@Override
public void trackApplicationStatus() throws TaskException {
initPipelineId();
// Keep checking the health status
exitStatusCode = utils.checkPipelineExecutionStatus(client, pipelineId);
try {
initPipelineId();
// Keep checking the health status
exitStatusCode = utils.checkPipelineExecutionStatus(client, pipelineId);
} catch (Exception e) {
log.error("SageMaker task track application error: {}", e.getMessage(), e);
throw new TaskException("SageMaker task track application error: " + e.getMessage(), e);
} finally {
// shutdown client
if (client != null) {
client.shutdown();
}
}
}

/**
* init sagemaker applicationId if null
*/
private void initPipelineId() {
void initPipelineId() {
if (pipelineId == null) {
if (StringUtils.isNotEmpty(getAppIds())) {
pipelineId = JSONUtils.parseObject(getAppIds(), PipelineUtils.PipelineId.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@

package org.apache.dolphinscheduler.plugin.task.sagemaker;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import org.apache.dolphinscheduler.common.utils.JSONUtils;
import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils;
import org.apache.dolphinscheduler.plugin.datasource.sagemaker.param.SagemakerConnectionParam;
import org.apache.dolphinscheduler.plugin.task.api.TaskException;
import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper;

Expand Down Expand Up @@ -139,4 +145,33 @@ private String buildParameters() {

return JSONUtils.toJsonString(parameters);
}

@Test
public void testTrackApplicationStatus_InitPipelineIdThrowsException() throws Exception {
doThrow(new TaskException("sagemaker applicationID is null")).when(sagemakerTask).initPipelineId();

TaskException exception = assertThrows(TaskException.class, () -> {
sagemakerTask.trackApplicationStatus();
});

assertEquals("sagemaker applicationID is null", exception.getMessage());
verify(client, times(1)).shutdown();
}

@Test
public void testCancelApplication_InitPipelineIdThrowsException() {
// Mock the behavior of initPipelineId to throw an exception
doThrow(new TaskException("sagemaker applicationID is null")).when(sagemakerTask).initPipelineId();

// Call the method under test and expect an exception
TaskException exception = assertThrows(TaskException.class, () -> {
sagemakerTask.cancelApplication();
});

// Verify the exception message
assertEquals("cancel application error", exception.getMessage());

// Verify that client.shutdown() was called
verify(client, times(1)).shutdown();
}
}
Loading