Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 1ec1ff3

Browse files
ilayaperumalgghillert
authored andcommitted
Add stream/task logs REST endpoints to API guide
- Add Stream/Task logs documentation tests - Update REST API guide with stream/task logs REST endpoints Resolves #3322
1 parent 02ba9ce commit 1ec1ff3

File tree

3 files changed

+321
-67
lines changed

3 files changed

+321
-67
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.dataflow.server.rest.documentation;
18+
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
22+
import org.junit.FixMethodOrder;
23+
import org.junit.Test;
24+
import org.junit.runners.MethodSorters;
25+
26+
import org.springframework.cloud.skipper.domain.LogInfo;
27+
28+
import static org.mockito.Mockito.when;
29+
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
30+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
31+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
32+
33+
/**
34+
* Documentation for the {@code /streams/logs} endpoint.
35+
*
36+
* @author Ilayaperumal Gopinathan
37+
*/
38+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
39+
public class StreamLogsDocumentation extends BaseDocumentation {
40+
41+
@Test
42+
public void getLogsByStreamName() throws Exception {
43+
LogInfo logInfo = new LogInfo();
44+
Map<String, String> logs = new HashMap<>();
45+
logs.put("ticktock-log-v1", "Logs-log");
46+
logs.put("ticktock-time-v1", "Logs-time");
47+
logInfo.setLogs(logs);
48+
when(springDataflowServer.getSkipperClient().getLog("ticktock")).thenReturn(logInfo);
49+
this.mockMvc.perform(
50+
get("/streams/logs/ticktock"))
51+
.andDo(print())
52+
.andExpect(status().isOk())
53+
.andDo(this.documentationHandler.document());
54+
}
55+
56+
@Test
57+
public void getLogsByAppName() throws Exception {
58+
LogInfo logInfo = new LogInfo();
59+
Map<String, String> logs = new HashMap<>();
60+
logs.put("ticktock-log-v1", "Logs-log");
61+
logInfo.setLogs(logs);
62+
when(springDataflowServer.getSkipperClient().getLog("ticktock", "ticktock-log-v1")).thenReturn(logInfo);
63+
this.mockMvc.perform(
64+
get("/streams/logs/ticktock/ticktock-log-v1"))
65+
.andDo(print())
66+
.andExpect(status().isOk())
67+
.andDo(this.documentationHandler.document());
68+
}
69+
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.dataflow.server.rest.documentation;
18+
19+
import org.junit.FixMethodOrder;
20+
import org.junit.Test;
21+
import org.junit.runners.MethodSorters;
22+
23+
import org.springframework.cloud.dataflow.core.ApplicationType;
24+
import org.springframework.cloud.dataflow.server.repository.TaskDeploymentRepository;
25+
26+
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
27+
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
28+
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
29+
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
30+
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
31+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
32+
33+
/**
34+
* Documentation for the {@code /tasks/logs} endpoint.
35+
*
36+
* @author Ilayaperumal Gopinathan
37+
*/
38+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
39+
public class TaskLogsDocumentation extends BaseDocumentation {
40+
41+
@Test
42+
public void getLogsByTaskId() throws Exception {
43+
registerApp(ApplicationType.task, "timestamp", "1.2.0.RELEASE");
44+
String taskName = "taskA";
45+
documentation.dontDocument( () -> this.mockMvc.perform(
46+
post("/tasks/definitions")
47+
.param("name", taskName)
48+
.param("definition", "timestamp --format='yyyy MM dd'"))
49+
.andExpect(status().isOk()));
50+
this.mockMvc.perform(
51+
post("/tasks/executions")
52+
.param("name", taskName))
53+
.andExpect(status().isCreated());
54+
TaskDeploymentRepository taskDeploymentRepository =
55+
springDataflowServer.getWebApplicationContext().getBean(TaskDeploymentRepository.class);
56+
Thread.sleep(30000);
57+
this.mockMvc.perform(
58+
get("/tasks/logs/"+taskDeploymentRepository.findTopByTaskDefinitionNameOrderByCreatedOnAsc(taskName)
59+
.getTaskDeploymentId()).param("platformName", "default"))
60+
.andDo(print())
61+
.andExpect(status().isOk())
62+
.andDo(this.documentationHandler.document(
63+
requestParameters(
64+
parameterWithName("platformName").description("The name of the platform the task is launched."))
65+
));
66+
}
67+
68+
}

0 commit comments

Comments
 (0)