Skip to content
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

chore: Added checks to only return plugins when new updates are present #27641

Merged
merged 2 commits into from
Sep 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,6 @@ public class FieldNameCE {
public static final String IS_MERGEABLE = "isMergeable";

public static final String FILE_LOCK_DURATION = "fileLockDuration";

public static final String REMOTE_PLUGINS = "remotePlugins";
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ private Mono<Map<PluginScheduledTaskCEImpl.PluginIdentifier, Plugin>> getRemoteP
return Mono.empty();
}

String lastUpdatedAtParam = lastUpdatedAt != null ? "&lastUpdatedAt=" + lastUpdatedAt : "";

return configService.getInstanceId().flatMap(instanceId -> WebClientUtils.create(
baseUrl + "/api/v1/plugins?instanceId=" + instanceId + "&lastUpdatedAt=" + lastUpdatedAt)
baseUrl + "/api/v1/plugins?instanceId=" + instanceId + lastUpdatedAtParam)
.get()
.exchangeToMono(clientResponse ->
clientResponse.bodyToMono(new ParameterizedTypeReference<ResponseDTO<List<Plugin>>>() {}))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.appsmith.server.services;

import com.appsmith.server.repositories.ApplicationRepository;
import com.appsmith.server.repositories.ConfigRepository;
import com.appsmith.server.repositories.DatasourceRepository;
import com.appsmith.server.services.ce.ConfigServiceCEImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -11,11 +9,7 @@
@Service
public class ConfigServiceImpl extends ConfigServiceCEImpl implements ConfigService {

public ConfigServiceImpl(
ConfigRepository repository,
ApplicationRepository applicationRepository,
DatasourceRepository datasourceRepository) {

super(repository, applicationRepository, datasourceRepository);
public ConfigServiceImpl(ConfigRepository repository) {
super(repository);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import com.appsmith.server.domains.User;
import com.appsmith.server.exceptions.AppsmithError;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.repositories.ApplicationRepository;
import com.appsmith.server.repositories.ConfigRepository;
import com.appsmith.server.repositories.DatasourceRepository;
import lombok.extern.slf4j.Slf4j;
import net.minidev.json.JSONObject;
import reactor.core.publisher.Mono;
Expand All @@ -17,23 +15,12 @@

@Slf4j
public class ConfigServiceCEImpl implements ConfigServiceCE {

private static final String TEMPLATE_WORKSPACE_CONFIG_NAME = "template-workspace";

private final ApplicationRepository applicationRepository;
private final DatasourceRepository datasourceRepository;
private final ConfigRepository repository;

// This is permanently cached through the life of the JVM process as this is not intended to change at runtime ever.
private String instanceId = null;

public ConfigServiceCEImpl(
ConfigRepository repository,
ApplicationRepository applicationRepository,
DatasourceRepository datasourceRepository) {

this.applicationRepository = applicationRepository;
this.datasourceRepository = datasourceRepository;
public ConfigServiceCEImpl(ConfigRepository repository) {
this.repository = repository;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ public Flux<Workspace> installDefaultPlugins(List<Plugin> plugins) {
return new WorkspacePlugin(plugin.getId(), WorkspacePluginStatus.ACTIVATED);
})
.collect(Collectors.toList());

if (newWorkspacePlugins.isEmpty()) {
return Flux.empty();
}

return workspaceService.getAll().flatMap(workspace -> {
// Only perform a DB op if plugins associated to this org have changed
if (workspace.getPlugins().containsAll(newWorkspacePlugins)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.appsmith.server.solutions;

import com.appsmith.server.helpers.PluginScheduledTaskUtils;
import com.appsmith.server.services.ConfigService;
import com.appsmith.server.solutions.ce.PluginScheduledTaskCEImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class PluginScheduledTaskImpl extends PluginScheduledTaskCEImpl implements PluginScheduledTask {

public PluginScheduledTaskImpl(PluginScheduledTaskUtils pluginScheduledTaskUtils) {

super(pluginScheduledTaskUtils);
public PluginScheduledTaskImpl(PluginScheduledTaskUtils pluginScheduledTaskUtils, ConfigService configService) {
super(pluginScheduledTaskUtils, configService);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.appsmith.server.solutions.ce;

import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.Config;
import com.appsmith.server.helpers.PluginScheduledTaskUtils;
import com.appsmith.server.services.ConfigService;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.minidev.json.JSONObject;
import org.springframework.scheduling.annotation.Scheduled;
import reactor.core.scheduler.Schedulers;

import java.time.Instant;
import java.util.Date;
import java.util.Map;

/**
* This class represents a scheduled task that pings cloud services for any updates in available plugins.
Expand All @@ -19,18 +25,34 @@
public class PluginScheduledTaskCEImpl implements PluginScheduledTaskCE {

private final PluginScheduledTaskUtils pluginScheduledTaskUtils;

private Instant lastUpdatedAt = null;
private final ConfigService configService;

// Number of milliseconds between the start of each scheduled calls to this method.
@Scheduled(initialDelay = 30 * 1000 /* 30 seconds */, fixedRate = 2 * 60 * 60 * 1000 /* two hours */)
public void updateRemotePlugins() {
// Moving the fetch and update remote plugins to helper classes to have custom implementation for business
// edition
pluginScheduledTaskUtils
.fetchAndUpdateRemotePlugins(lastUpdatedAt)
configService
.getByName(FieldName.REMOTE_PLUGINS)
.onErrorReturn(new Config())
.map(config -> {
JSONObject config1 = config.getConfig();
Instant lastUpdatedAt = null;

if (config1 != null) {
Object tempUpdatedAt = config1.getOrDefault(FieldName.UPDATED_AT, null);
if (tempUpdatedAt != null) {
lastUpdatedAt = ((Date) tempUpdatedAt).toInstant();
}
}
return pluginScheduledTaskUtils.fetchAndUpdateRemotePlugins(lastUpdatedAt);
})
// Set new updated time
.doOnSuccess(success -> this.lastUpdatedAt = Instant.now())
.flatMap(success -> {
Config config = new Config(
new JSONObject(Map.of(FieldName.UPDATED_AT, Instant.now())), FieldName.REMOTE_PLUGINS);
return configService.save(config);
})
.subscribeOn(Schedulers.single())
.subscribe();
}
Expand Down
Loading