mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-26 09:22:14 +00:00
parent
ec3eb297f5
commit
10f9fe82a6
@ -610,6 +610,7 @@
|
|||||||
<phase>test</phase>
|
<phase>test</phase>
|
||||||
<configuration>
|
<configuration>
|
||||||
<includes>
|
<includes>
|
||||||
|
<include>**/*Test.java</include>
|
||||||
<include>**/*ResourceTest.java</include>
|
<include>**/*ResourceTest.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -649,6 +650,7 @@
|
|||||||
<phase>test</phase>
|
<phase>test</phase>
|
||||||
<configuration>
|
<configuration>
|
||||||
<includes>
|
<includes>
|
||||||
|
<include>**/*Test.java</include>
|
||||||
<include>**/*ResourceTest.java</include>
|
<include>**/*ResourceTest.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -455,11 +455,14 @@ public class AirflowRESTClient extends PipelineServiceClient {
|
|||||||
String.format("Failed to get last ingestion logs due to %s", response.body()));
|
String.format("Failed to get last ingestion logs due to %s", response.body()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private URIBuilder buildURI(String path) {
|
public URIBuilder buildURI(String path) {
|
||||||
try {
|
try {
|
||||||
List<String> pathInternal = new ArrayList<>(API_ENDPOINT_SEGMENTS);
|
List<String> pathInternal = new ArrayList<>(API_ENDPOINT_SEGMENTS);
|
||||||
pathInternal.add(path);
|
pathInternal.add(path);
|
||||||
return new URIBuilder(String.valueOf(serviceURL)).setPathSegments(pathInternal);
|
URIBuilder builder = new URIBuilder(String.valueOf(serviceURL));
|
||||||
|
List<String> segments = new ArrayList<>(builder.getPathSegments());
|
||||||
|
segments.addAll(pathInternal);
|
||||||
|
return builder.setPathSegments(segments);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw clientException(String.format("Failed to built request URI for path [%s].", path), e);
|
throw clientException(String.format("Failed to built request URI for path [%s].", path), e);
|
||||||
}
|
}
|
||||||
|
@ -13,56 +13,44 @@
|
|||||||
package org.openmetadata.service.pipelineService.airflow;
|
package org.openmetadata.service.pipelineService.airflow;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
import static org.openmetadata.service.resources.services.ingestionpipelines.IngestionPipelineResourceTest.DATABASE_METADATA_CONFIG;
|
|
||||||
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.joda.time.DateTime;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
import org.openmetadata.schema.api.configuration.pipelineServiceClient.Parameters;
|
import org.openmetadata.schema.api.configuration.pipelineServiceClient.Parameters;
|
||||||
import org.openmetadata.schema.api.configuration.pipelineServiceClient.PipelineServiceClientConfiguration;
|
import org.openmetadata.schema.api.configuration.pipelineServiceClient.PipelineServiceClientConfiguration;
|
||||||
import org.openmetadata.schema.entity.services.ingestionPipelines.AirflowConfig;
|
|
||||||
import org.openmetadata.schema.entity.services.ingestionPipelines.IngestionPipeline;
|
|
||||||
import org.openmetadata.schema.entity.services.ingestionPipelines.PipelineType;
|
|
||||||
import org.openmetadata.sdk.exception.PipelineServiceClientException;
|
|
||||||
import org.openmetadata.service.clients.pipeline.airflow.AirflowRESTClient;
|
import org.openmetadata.service.clients.pipeline.airflow.AirflowRESTClient;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
class AirflowRESTClientTest {
|
||||||
class AirflowRESTClientIntegrationTest {
|
|
||||||
|
|
||||||
private static final String DAG_NAME = "test_dag";
|
@Test
|
||||||
private static final String URI_TO_HANDLE_REQUEST = "/";
|
void test_buildUri() throws KeyStoreException {
|
||||||
|
// We build the right URI for a simple url
|
||||||
|
PipelineServiceClientConfiguration config = getPipelineServiceConfiguration();
|
||||||
|
AirflowRESTClient restClient = new AirflowRESTClient(config);
|
||||||
|
assertEquals(
|
||||||
|
"http://localhost:8080/api/v1/openmetadata/last_dag_logs",
|
||||||
|
restClient.buildURI("last_dag_logs").toString());
|
||||||
|
|
||||||
public static final IngestionPipeline INGESTION_PIPELINE =
|
// We build the right URI for a service URLs with paths
|
||||||
new IngestionPipeline()
|
config.setApiEndpoint("http://localhost:8080/airflow");
|
||||||
.withName(DAG_NAME)
|
restClient = new AirflowRESTClient(config);
|
||||||
.withId(UUID.randomUUID())
|
assertEquals(
|
||||||
.withPipelineType(PipelineType.METADATA)
|
"http://localhost:8080/airflow/api/v1/openmetadata/last_dag_logs",
|
||||||
.withSourceConfig(DATABASE_METADATA_CONFIG)
|
restClient.buildURI("last_dag_logs").toString());
|
||||||
.withAirflowConfig(
|
|
||||||
new AirflowConfig()
|
|
||||||
.withStartDate(new DateTime("2022-06-10T15:06:47+00:00").toDate()));
|
|
||||||
|
|
||||||
@RegisterExtension
|
// The same works with more segments
|
||||||
private static final HttpServerExtension httpServerExtension = new HttpServerExtension();
|
config.setApiEndpoint("http://localhost:8080/airflow/foo");
|
||||||
|
restClient = new AirflowRESTClient(config);
|
||||||
AirflowRESTClient airflowRESTClient;
|
assertEquals(
|
||||||
|
"http://localhost:8080/airflow/foo/api/v1/openmetadata/health",
|
||||||
@BeforeEach
|
restClient.buildURI("health").toString());
|
||||||
void setUp() throws URISyntaxException, KeyStoreException {
|
}
|
||||||
|
|
||||||
|
private PipelineServiceClientConfiguration getPipelineServiceConfiguration() {
|
||||||
PipelineServiceClientConfiguration pipelineServiceClientConfiguration =
|
PipelineServiceClientConfiguration pipelineServiceClientConfiguration =
|
||||||
new PipelineServiceClientConfiguration();
|
new PipelineServiceClientConfiguration();
|
||||||
pipelineServiceClientConfiguration.setHostIp("111.11.11.1");
|
pipelineServiceClientConfiguration.setHostIp("111.11.11.1");
|
||||||
pipelineServiceClientConfiguration.setApiEndpoint(HttpServerExtension.getUriFor("").toString());
|
pipelineServiceClientConfiguration.setApiEndpoint("http://localhost:8080");
|
||||||
|
|
||||||
Parameters params = new Parameters();
|
Parameters params = new Parameters();
|
||||||
params.setAdditionalProperty("username", "user");
|
params.setAdditionalProperty("username", "user");
|
||||||
@ -71,47 +59,6 @@ class AirflowRESTClientIntegrationTest {
|
|||||||
|
|
||||||
pipelineServiceClientConfiguration.setParameters(params);
|
pipelineServiceClientConfiguration.setParameters(params);
|
||||||
|
|
||||||
airflowRESTClient = new AirflowRESTClient(pipelineServiceClientConfiguration);
|
return pipelineServiceClientConfiguration;
|
||||||
httpServerExtension.unregisterHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testLastIngestionLogsAreRetrievedWhenStatusCodesAre200() {
|
|
||||||
Map<String, String> expectedMap = Map.of("key1", "value1", "key2", "value2");
|
|
||||||
|
|
||||||
registerMockedEndpoints(200);
|
|
||||||
|
|
||||||
assertEquals(expectedMap, airflowRESTClient.getLastIngestionLogs(INGESTION_PIPELINE, "after"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testLastIngestionLogsExceptionWhenStatusCode404() {
|
|
||||||
registerMockedEndpoints(404);
|
|
||||||
|
|
||||||
Exception exception =
|
|
||||||
assertThrows(
|
|
||||||
PipelineServiceClientException.class,
|
|
||||||
() -> airflowRESTClient.getLastIngestionLogs(INGESTION_PIPELINE, "after"));
|
|
||||||
|
|
||||||
String expectedMessage = "Failed to get last ingestion logs due to 404 - Not Found";
|
|
||||||
String actualMessage = exception.getMessage();
|
|
||||||
|
|
||||||
assertEquals(expectedMessage, actualMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerMockedEndpoints(int lastDagLogStatusCode) {
|
|
||||||
String jsonResponse = "{ \"key1\": \"value1\", \"key2\": \"value2\" }";
|
|
||||||
if (lastDagLogStatusCode == 404) {
|
|
||||||
jsonResponse = "404 - Not Found";
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, MockResponse> pathResponses = new HashMap<>();
|
|
||||||
pathResponses.put(
|
|
||||||
"/api/v1/openmetadata/last_dag_logs?dag_id="
|
|
||||||
+ DAG_NAME
|
|
||||||
+ "&task_id=ingestion_task&after=after",
|
|
||||||
new MockResponse(jsonResponse, "application/json", lastDagLogStatusCode));
|
|
||||||
|
|
||||||
httpServerExtension.registerHandler(URI_TO_HANDLE_REQUEST, new JsonHandler(pathResponses));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user