diff --git a/java/code/src/com/redhat/rhn/taskomatic/TaskomaticApi.java b/java/code/src/com/redhat/rhn/taskomatic/TaskomaticApi.java index f2298a7d5be..1c36d7b9bb9 100644 --- a/java/code/src/com/redhat/rhn/taskomatic/TaskomaticApi.java +++ b/java/code/src/com/redhat/rhn/taskomatic/TaskomaticApi.java @@ -870,4 +870,15 @@ public void scheduleSingleGpgKeyImport(String gpgKey) throws TaskomaticApiExcept } invoke("tasko.scheduleSingleSatBunchRun", "custom-gpg-key-import-bunch", Map.of("gpg-key", gpgKey)); } + + /** + * Schedule a product refresh via taskomatic + * @param earliest earliest execution + * @param withReposync perform also a repo-sync + * @throws TaskomaticApiException if there is an error + */ + public void scheduleProductRefresh(Date earliest, boolean withReposync) throws TaskomaticApiException { + invoke("tasko.scheduleSingleSatBunchRun", "mgr-sync-refresh-bunch", + Map.of("noRepoSync", !withReposync), earliest); + } } diff --git a/java/code/src/com/suse/manager/hub/DefaultHubInternalClient.java b/java/code/src/com/suse/manager/hub/DefaultHubInternalClient.java index 2f852a8d956..94d6afa5bdf 100644 --- a/java/code/src/com/suse/manager/hub/DefaultHubInternalClient.java +++ b/java/code/src/com/suse/manager/hub/DefaultHubInternalClient.java @@ -92,6 +92,11 @@ public String replaceTokens(String newHubToken) throws IOException { return invokePost("hub/sync", "replaceTokens", newHubToken, String.class); } + @Override + public void scheduleProductRefresh() throws IOException { + invokePost("hub", "scheduleProductRefresh", Map.of()); + } + @Override public void deregister() throws IOException { invokePost("hub/sync", "deregister", null); diff --git a/java/code/src/com/suse/manager/hub/HubController.java b/java/code/src/com/suse/manager/hub/HubController.java index bd6b1bdbcd3..284f8b77189 100644 --- a/java/code/src/com/suse/manager/hub/HubController.java +++ b/java/code/src/com/suse/manager/hub/HubController.java @@ -29,6 +29,7 @@ import com.redhat.rhn.common.hibernate.ConnectionManager; import com.redhat.rhn.common.hibernate.ConnectionManagerFactory; import com.redhat.rhn.common.hibernate.ReportDbHibernateFactory; +import com.redhat.rhn.taskomatic.TaskomaticApi; import com.redhat.rhn.taskomatic.TaskomaticApiException; import com.redhat.rhn.taskomatic.task.ReportDBHelper; @@ -52,6 +53,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -97,6 +100,8 @@ public void initRoutes() { post("/hub/sync/storeCredentials", asJson(usingTokenAuthentication(onlyFromHub(this::storeCredentials)))); post("/hub/sync/setHubDetails", asJson(usingTokenAuthentication(onlyFromHub(this::setHubDetails)))); get("/hub/managerinfo", asJson(usingTokenAuthentication(onlyFromHub(this::getManagerInfo)))); + post("/hub/scheduleProductRefresh", + asJson(usingTokenAuthentication(onlyFromHub(this::scheduleProductRefresh)))); post("/hub/storeReportDbCredentials", asJson(usingTokenAuthentication(onlyFromHub(this::setReportDbCredentials)))); post("/hub/removeReportDbCredentials", @@ -121,6 +126,19 @@ public void initRoutes() { asJson(usingTokenAuthentication(onlyFromHub(this::synchronizeSubscriptions)))); } + private String scheduleProductRefresh(Request request, Response response, IssAccessToken issAccessToken) { + try { + Date earliest = Date.from(Instant.now().plus(10, ChronoUnit.SECONDS)); + TaskomaticApi taskomaticApi = new TaskomaticApi(); + taskomaticApi.scheduleProductRefresh(earliest, false); + } + catch (TaskomaticApiException ex) { + LOGGER.error("Scheduling a product refresh failed. ", ex); + internalServerError(response, "Scheduling product refresh failed"); + } + return success(response); + } + private String setHubDetails(Request request, Response response, IssAccessToken accessToken) { Map data = GSON.fromJson(request.body(), Map.class); diff --git a/java/code/src/com/suse/manager/hub/HubInternalClient.java b/java/code/src/com/suse/manager/hub/HubInternalClient.java index 1102c30d070..d57458b06b2 100644 --- a/java/code/src/com/suse/manager/hub/HubInternalClient.java +++ b/java/code/src/com/suse/manager/hub/HubInternalClient.java @@ -67,4 +67,9 @@ public interface HubInternalClient { */ String replaceTokens(String newHubToken) throws IOException; + /** + * Schedule a product refresh on the remote peripheral server + * @throws IOException when the communication fails + */ + void scheduleProductRefresh() throws IOException; } diff --git a/java/code/src/com/suse/manager/hub/HubManager.java b/java/code/src/com/suse/manager/hub/HubManager.java index 6d465f138e3..e56a184f225 100644 --- a/java/code/src/com/suse/manager/hub/HubManager.java +++ b/java/code/src/com/suse/manager/hub/HubManager.java @@ -646,6 +646,7 @@ private void registerToRemote(User user, IssServer remoteServer, String remoteTo if (changed) { setReportDbUser(user, peripheralServer, false); } + internalApi.scheduleProductRefresh(); } catch (Exception ex) { // cleanup the remote side