Skip to content

Improve onboarding performance #11682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 42 additions & 0 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,28 @@ paths:
$ref: "#/components/schemas/WebBackendConnectionReadList"
"422":
$ref: "#/components/responses/InvalidInputResponse"
/v1/web_backend/workspace/state:
post:
tags:
- web_backend
summary: Returns the current state of a workspace
operationId: webBackendGetWorkspaceState
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/WebBackendWorkspaceState"
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/WebBackendWorkspaceStateResult"
"404":
$ref: "#/components/responses/NotFoundResponse"
"422":
$ref: "#/components/responses/InvalidInputResponse"
/v1/jobs/list:
post:
tags:
Expand Down Expand Up @@ -2418,6 +2440,26 @@ components:
properties:
workspaceId:
$ref: "#/components/schemas/WorkspaceId"
WebBackendWorkspaceState:
type: object
required:
- workspaceId
properties:
workspaceId:
$ref: "#/components/schemas/WorkspaceId"
WebBackendWorkspaceStateResult:
type: object
required:
- hasConnections
- hasSources
- hasDestinations
properties:
hasConnections:
type: boolean
hasSources:
type: boolean
hasDestinations:
type: boolean
# SLUG
SlugRequestBody:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
import io.airbyte.api.model.WebBackendConnectionRequestBody;
import io.airbyte.api.model.WebBackendConnectionSearch;
import io.airbyte.api.model.WebBackendConnectionUpdate;
import io.airbyte.api.model.WebBackendWorkspaceState;
import io.airbyte.api.model.WebBackendWorkspaceStateResult;
import io.airbyte.api.model.WorkspaceCreate;
import io.airbyte.api.model.WorkspaceGiveFeedback;
import io.airbyte.api.model.WorkspaceIdRequestBody;
Expand Down Expand Up @@ -242,7 +244,8 @@ public ConfigurationApi(final ConfigRepository configRepository,
schedulerHandler,
operationsHandler,
featureFlags,
eventRunner);
eventRunner,
configRepository);
healthCheckHandler = new HealthCheckHandler();
archiveHandler = new ArchiveHandler(
airbyteVersion,
Expand Down Expand Up @@ -817,6 +820,11 @@ public WebBackendConnectionRead webBackendGetConnection(final WebBackendConnecti
return execute(() -> webBackendConnectionsHandler.webBackendGetConnection(webBackendConnectionRequestBody));
}

@Override
public WebBackendWorkspaceStateResult webBackendGetWorkspaceState(WebBackendWorkspaceState webBackendWorkspaceState) {
return execute(() -> webBackendConnectionsHandler.getWorkspaceState(webBackendWorkspaceState));
}

@Override
public WebBackendConnectionRead webBackendCreateConnection(final WebBackendConnectionCreate webBackendConnectionCreate) {
return execute(() -> webBackendConnectionsHandler.webBackendCreateConnection(webBackendConnectionCreate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@
import io.airbyte.api.model.WebBackendConnectionSearch;
import io.airbyte.api.model.WebBackendConnectionUpdate;
import io.airbyte.api.model.WebBackendOperationCreateOrUpdate;
import io.airbyte.api.model.WebBackendWorkspaceState;
import io.airbyte.api.model.WebBackendWorkspaceStateResult;
import io.airbyte.api.model.WorkspaceIdRequestBody;
import io.airbyte.commons.features.FeatureFlags;
import io.airbyte.commons.json.Jsons;
import io.airbyte.commons.lang.MoreBooleans;
import io.airbyte.config.persistence.ConfigNotFoundException;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.scheduler.client.EventRunner;
import io.airbyte.validation.json.JsonValidationException;
import java.io.IOException;
Expand Down Expand Up @@ -72,6 +75,19 @@ public class WebBackendConnectionsHandler {
private final OperationsHandler operationsHandler;
private final FeatureFlags featureFlags;
private final EventRunner eventRunner;
private final ConfigRepository configRepository;

public WebBackendWorkspaceStateResult getWorkspaceState(final WebBackendWorkspaceState webBackendWorkspaceState) throws IOException {
final var workspaceId = webBackendWorkspaceState.getWorkspaceId();
final var connectionCount = configRepository.countConnectionsForWorkspace(workspaceId);
final var destinationCount = configRepository.countDestinationsForWorkspace(workspaceId);
final var sourceCount = configRepository.countSourcesForWorkspace(workspaceId);

return new WebBackendWorkspaceStateResult()
.hasConnections(connectionCount > 0)
.hasDestinations(destinationCount > 0)
.hasSources(sourceCount > 0);
}

public WebBackendConnectionReadList webBackendListConnectionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody)
throws ConfigNotFoundException, IOException, JsonValidationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package io.airbyte.server.handlers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -55,6 +57,7 @@
import io.airbyte.api.model.WebBackendConnectionSearch;
import io.airbyte.api.model.WebBackendConnectionUpdate;
import io.airbyte.api.model.WebBackendOperationCreateOrUpdate;
import io.airbyte.api.model.WebBackendWorkspaceState;
import io.airbyte.api.model.WorkspaceIdRequestBody;
import io.airbyte.commons.enums.Enums;
import io.airbyte.commons.features.FeatureFlags;
Expand All @@ -64,6 +67,7 @@
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSync;
import io.airbyte.config.persistence.ConfigNotFoundException;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.protocol.models.CatalogHelpers;
import io.airbyte.protocol.models.Field;
import io.airbyte.protocol.models.JsonSchemaType;
Expand Down Expand Up @@ -103,6 +107,7 @@ class WebBackendConnectionsHandlerTest {
private FeatureFlags featureFlags;
private EventRunner eventRunner;
private ConnectionHelper connectionHelper;
private ConfigRepository configRepository;

@BeforeEach
public void setup() throws IOException, JsonValidationException, ConfigNotFoundException {
Expand All @@ -111,6 +116,7 @@ public void setup() throws IOException, JsonValidationException, ConfigNotFoundE
final SourceHandler sourceHandler = mock(SourceHandler.class);
final DestinationHandler destinationHandler = mock(DestinationHandler.class);
final JobHistoryHandler jobHistoryHandler = mock(JobHistoryHandler.class);
configRepository = mock(ConfigRepository.class);
schedulerHandler = mock(SchedulerHandler.class);
featureFlags = mock(FeatureFlags.class);
eventRunner = mock(EventRunner.class);
Expand All @@ -122,7 +128,8 @@ public void setup() throws IOException, JsonValidationException, ConfigNotFoundE
schedulerHandler,
operationsHandler,
featureFlags,
eventRunner);
eventRunner,
configRepository);

final StandardSourceDefinition standardSourceDefinition = SourceDefinitionHelpers.generateSourceDefinition();
final SourceConnection source = SourceHelpers.generateSource(UUID.randomUUID());
Expand Down Expand Up @@ -234,6 +241,32 @@ public void setup() throws IOException, JsonValidationException, ConfigNotFoundE
.thenReturn(new JobInfoRead().job(new JobRead().status(JobStatus.SUCCEEDED)));
}

@Test
public void testGetWorkspaceState() throws IOException {
final UUID uuid = UUID.randomUUID();
final WebBackendWorkspaceState request = new WebBackendWorkspaceState().workspaceId(uuid);
when(configRepository.countSourcesForWorkspace(uuid)).thenReturn(5);
when(configRepository.countDestinationsForWorkspace(uuid)).thenReturn(2);
when(configRepository.countConnectionsForWorkspace(uuid)).thenReturn(8);
final var actual = wbHandler.getWorkspaceState(request);
assertTrue(actual.getHasConnections());
assertTrue(actual.getHasDestinations());
assertTrue((actual.getHasSources()));
}

@Test
public void testGetWorkspaceStateEmpty() throws IOException {
final UUID uuid = UUID.randomUUID();
final WebBackendWorkspaceState request = new WebBackendWorkspaceState().workspaceId(uuid);
when(configRepository.countSourcesForWorkspace(uuid)).thenReturn(0);
when(configRepository.countDestinationsForWorkspace(uuid)).thenReturn(0);
when(configRepository.countConnectionsForWorkspace(uuid)).thenReturn(0);
final var actual = wbHandler.getWorkspaceState(request);
assertFalse(actual.getHasConnections());
assertFalse(actual.getHasDestinations());
assertFalse(actual.getHasSources());
}

@Test
public void testWebBackendListConnectionsForWorkspace() throws ConfigNotFoundException, IOException, JsonValidationException {
final WorkspaceIdRequestBody workspaceIdRequestBody = new WorkspaceIdRequestBody();
Expand Down
6 changes: 6 additions & 0 deletions airbyte-webapp/src/core/domain/workspace/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ export interface Workspace {
displaySetupWizard: boolean;
notifications: Notification[];
}

export interface WorkspaceState {
hasSources: boolean;
hasDestinations: boolean;
hasConnections: boolean;
}
8 changes: 7 additions & 1 deletion airbyte-webapp/src/core/domain/workspace/WorkspaceService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AirbyteRequestService } from "core/request/AirbyteRequestService";
import { Workspace } from "./Workspace";
import { Workspace, WorkspaceState } from "./Workspace";

class WorkspaceService extends AirbyteRequestService {
get url() {
Expand All @@ -19,6 +19,12 @@ class WorkspaceService extends AirbyteRequestService {
public async update(payload: Record<string, unknown>): Promise<Workspace> {
return await this.fetch<Workspace>(`${this.url}/update`, payload);
}

public async getState(workspaceId: string): Promise<WorkspaceState> {
return await this.fetch<WorkspaceState>(`web_backend/workspace/state`, {
workspaceId,
});
}
}

export { WorkspaceService };
Loading