Skip to content

Commit

Permalink
perform product refresh on peripheral after registration
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed Feb 22, 2025
1 parent cec6e39 commit 4a3d0e6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
11 changes: 11 additions & 0 deletions java/code/src/com/redhat/rhn/taskomatic/TaskomaticApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions java/code/src/com/suse/manager/hub/HubController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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",
Expand All @@ -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<String, String> data = GSON.fromJson(request.body(), Map.class);

Expand Down
5 changes: 5 additions & 0 deletions java/code/src/com/suse/manager/hub/HubInternalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions java/code/src/com/suse/manager/hub/HubManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a3d0e6

Please sign in to comment.