-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add /v1/web_backend/check_updates (#20041)
* Add /v1/web_backend/check_updates * Add constant for fallback cases
- Loading branch information
Showing
8 changed files
with
396 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
airbyte-server/src/main/java/io/airbyte/server/handlers/WebBackendCheckUpdatesHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.handlers; | ||
|
||
import io.airbyte.api.model.generated.WebBackendCheckUpdatesRead; | ||
import io.airbyte.config.StandardDestinationDefinition; | ||
import io.airbyte.config.StandardSourceDefinition; | ||
import io.airbyte.config.persistence.ConfigRepository; | ||
import io.airbyte.server.services.AirbyteGithubStore; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@AllArgsConstructor | ||
@Slf4j | ||
public class WebBackendCheckUpdatesHandler { | ||
|
||
private static final int NO_CHANGES_FOUND = 0; | ||
|
||
final ConfigRepository configRepository; | ||
final AirbyteGithubStore githubStore; | ||
|
||
public WebBackendCheckUpdatesRead checkUpdates() { | ||
|
||
final int destinationDiffCount = getDestinationDiffCount(); | ||
final int sourceDiffCount = getSourceDiffCount(); | ||
|
||
return new WebBackendCheckUpdatesRead() | ||
.destinationDefinitions(destinationDiffCount) | ||
.sourceDefinitions(sourceDiffCount); | ||
} | ||
|
||
private int getDestinationDiffCount() { | ||
final List<Entry<UUID, String>> currentActorDefToDockerImageTag; | ||
final Map<UUID, String> newActorDefToDockerImageTag; | ||
|
||
try { | ||
currentActorDefToDockerImageTag = configRepository.listStandardDestinationDefinitions(false) | ||
.stream() | ||
.map(def -> Map.entry(def.getDestinationDefinitionId(), def.getDockerImageTag())) | ||
.toList(); | ||
} catch (final IOException e) { | ||
log.error("Failed to get current list of standard destination definitions", e); | ||
return NO_CHANGES_FOUND; | ||
} | ||
|
||
try { | ||
newActorDefToDockerImageTag = githubStore.getLatestDestinations() | ||
.stream() | ||
.collect(Collectors.toMap(StandardDestinationDefinition::getDestinationDefinitionId, StandardDestinationDefinition::getDockerImageTag)); | ||
} catch (final InterruptedException e) { | ||
log.error("Failed to get latest list of standard destination definitions", e); | ||
return NO_CHANGES_FOUND; | ||
} | ||
|
||
return getDiffCount(currentActorDefToDockerImageTag, newActorDefToDockerImageTag); | ||
} | ||
|
||
private int getSourceDiffCount() { | ||
final List<Entry<UUID, String>> currentActorDefToDockerImageTag; | ||
final Map<UUID, String> newActorDefToDockerImageTag; | ||
|
||
try { | ||
currentActorDefToDockerImageTag = configRepository.listStandardSourceDefinitions(false) | ||
.stream() | ||
.map(def -> Map.entry(def.getSourceDefinitionId(), def.getDockerImageTag())) | ||
.toList(); | ||
} catch (final IOException e) { | ||
log.error("Failed to get current list of standard source definitions", e); | ||
return NO_CHANGES_FOUND; | ||
} | ||
|
||
try { | ||
newActorDefToDockerImageTag = githubStore.getLatestSources() | ||
.stream() | ||
.collect(Collectors.toMap(StandardSourceDefinition::getSourceDefinitionId, StandardSourceDefinition::getDockerImageTag)); | ||
} catch (final InterruptedException e) { | ||
log.error("Failed to get latest list of standard source definitions", e); | ||
return NO_CHANGES_FOUND; | ||
} | ||
|
||
return getDiffCount(currentActorDefToDockerImageTag, newActorDefToDockerImageTag); | ||
} | ||
|
||
private int getDiffCount(final List<Entry<UUID, String>> initialSet, final Map<UUID, String> newSet) { | ||
int diffCount = 0; | ||
for (final Entry<UUID, String> kvp : initialSet) { | ||
final String newDockerImageTag = newSet.get(kvp.getKey()); | ||
if (newDockerImageTag != null && !kvp.getValue().equals(newDockerImageTag)) { | ||
++diffCount; | ||
} | ||
} | ||
return diffCount; | ||
} | ||
|
||
} |
Oops, something went wrong.