Skip to content

Commit

Permalink
Add APIs to perform product refresh on the peripheral from the hub
Browse files Browse the repository at this point in the history
  • Loading branch information
CDellaGiusta authored and mcalmer committed Feb 22, 2025
1 parent a9ec011 commit a2ea972
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 15 deletions.
25 changes: 25 additions & 0 deletions java/code/src/com/suse/manager/hub/HubController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static com.suse.manager.webui.utils.SparkApplicationHelper.asJson;
import static com.suse.manager.webui.utils.SparkApplicationHelper.badRequest;
import static com.suse.manager.webui.utils.SparkApplicationHelper.internalServerError;
import static com.suse.manager.webui.utils.SparkApplicationHelper.json;
import static com.suse.manager.webui.utils.SparkApplicationHelper.message;
import static com.suse.manager.webui.utils.SparkApplicationHelper.success;
import static spark.Spark.get;
Expand Down Expand Up @@ -110,6 +111,14 @@ public void initRoutes() {
asJson(usingTokenAuthentication(onlyFromHub(this::addCustomChannels))));
post("/hub/modifyCustomChannels",
asJson(usingTokenAuthentication(onlyFromHub(this::modifyCustomChannels))));
post("/hub/sync/channelfamilies",
asJson(usingTokenAuthentication(onlyFromHub(this::synchronizeChannelFamilies))));
post("/hub/sync/products",
asJson(usingTokenAuthentication(onlyFromHub(this::synchronizeProducts))));
post("/hub/sync/repositories",
asJson(usingTokenAuthentication(onlyFromHub(this::synchronizeRepositories))));
post("/hub/sync/subscriptions",
asJson(usingTokenAuthentication(onlyFromHub(this::synchronizeSubscriptions))));
}

private String setHubDetails(Request request, Response response, IssAccessToken accessToken) {
Expand Down Expand Up @@ -347,4 +356,20 @@ private String modifyCustomChannels(Request request, Response response, IssAcces
.toList();
return success(response, modifiedCustomChannelsInfoList);
}

private String synchronizeChannelFamilies(Request request, Response response, IssAccessToken token) {
return json(response, hubManager.synchronizeChannelFamilies(token));
}

private String synchronizeProducts(Request request, Response response, IssAccessToken token) {
return json(response, hubManager.synchronizeProducts(token));
}

private String synchronizeRepositories(Request request, Response response, IssAccessToken token) {
return json(response, hubManager.synchronizeRepositories(token));
}

private String synchronizeSubscriptions(Request request, Response response, IssAccessToken token) {
return json(response, hubManager.synchronizeSubscriptions(token));
}
}
45 changes: 45 additions & 0 deletions java/code/src/com/suse/manager/hub/HubManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import com.suse.manager.model.hub.ManagerInfoJson;
import com.suse.manager.model.hub.ModifyCustomChannelInfoJson;
import com.suse.manager.model.hub.TokenType;
import com.suse.manager.webui.controllers.ProductsController;
import com.suse.manager.webui.utils.token.IssTokenBuilder;
import com.suse.manager.webui.utils.token.Token;
import com.suse.manager.webui.utils.token.TokenBuildingException;
Expand Down Expand Up @@ -999,4 +1000,48 @@ public List<Channel> modifyCustomChannels(IssAccessToken accessToken,
.filter(e -> modifiedChannelsLabelList.contains(e.getLabel()))
.toList();
}

/**
* Trigger a synchronization of Channel Families on the peripheral
*
* @param accessToken the access token
* @return a boolean flag of the success/failed result
*/
public boolean synchronizeChannelFamilies(IssAccessToken accessToken) {
ensureValidToken(accessToken);
return ProductsController.doSynchronizeChannelFamilies();
}

/**
* Trigger a synchronization of Products on the peripheral
*
* @param accessToken the access token
* @return a boolean flag of the success/failed result
*/
public boolean synchronizeProducts(IssAccessToken accessToken) {
ensureValidToken(accessToken);
return ProductsController.doSynchronizeProducts();
}

/**
* Trigger a synchronization of Repositories on the peripheral
*
* @param accessToken the access token
* @return a boolean flag of the success/failed result
*/
public boolean synchronizeRepositories(IssAccessToken accessToken) {
ensureValidToken(accessToken);
return ProductsController.doSynchronizeRepositories();
}

/**
* Trigger a synchronization of Subscriptions on the peripheral
*
* @param accessToken the access token
* @return a boolean flag of the success/failed result
*/
public boolean synchronizeSubscriptions(IssAccessToken accessToken) {
ensureValidToken(accessToken);
return ProductsController.doSynchronizeSubscriptions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ private static Stream<Arguments> allApiEndpoints() {
Arguments.of(HttpMethod.get, "/hub/listAllPeripheralChannels", IssRole.HUB),
Arguments.of(HttpMethod.post, "/hub/addVendorChannels", IssRole.HUB),
Arguments.of(HttpMethod.post, "/hub/addCustomChannels", IssRole.HUB),
Arguments.of(HttpMethod.post, "/hub/modifyCustomChannels", IssRole.HUB)
Arguments.of(HttpMethod.post, "/hub/modifyCustomChannels", IssRole.HUB),
Arguments.of(HttpMethod.post, "/hub/sync/channelfamilies", IssRole.HUB),
Arguments.of(HttpMethod.post, "/hub/sync/products", IssRole.HUB),
Arguments.of(HttpMethod.post, "/hub/sync/repositories", IssRole.HUB),
Arguments.of(HttpMethod.post, "/hub/sync/subscriptions", IssRole.HUB)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,30 @@ private static ProductsPageMetadataJson getMetadataJson() {
/**
* Trigger a synchronization of Products
*
* @param request the request
* @param request the request
* @param response the response
* @param user the user
* @param user the user
* @return a JSON flag of the success/failed result
*/
public static String synchronizeProducts(Request request, Response response, User user) {
return json(response, doSynchronizeProducts());
}

/**
* Trigger a synchronization of Products
*
* @return a boolean flag of the success/failed result
*/
public static boolean doSynchronizeProducts() {
return FileLocks.SCC_REFRESH_LOCK.withFileLock(() -> {
try {
ContentSyncManager csm = new ContentSyncManager();
csm.updateSUSEProducts(csm.getProducts());
return json(response, true);
return true;
}
catch (Exception e) {
log.fatal(e.getMessage(), e);
return json(response, false);
return false;
}
});
}
Expand All @@ -182,59 +191,86 @@ public static String synchronizeProducts(Request request, Response response, Use
* @return a JSON flag of the success/failed result
*/
public static String synchronizeChannelFamilies(Request request, Response response, User user) {
return json(response, doSynchronizeChannelFamilies());
}

/**
* Trigger a synchronization of Channel Families
*
* @return a boolean flag of the success/failed result
*/
public static boolean doSynchronizeChannelFamilies() {
return FileLocks.SCC_REFRESH_LOCK.withFileLock(() -> {
try {
ContentSyncManager csm = new ContentSyncManager();
csm.updateChannelFamilies(csm.readChannelFamilies());
return json(response, true);
return true;
}
catch (Exception e) {
log.fatal(e.getMessage(), e);
return json(response, false);
return false;
}
});
}

/**
* Trigger a synchronization of Repositories
*
* @param request the request
* @param request the request
* @param response the response
* @param user the user
* @param user the user
* @return a JSON flag of the success/failed result
*/
public static String synchronizeRepositories(Request request, Response response, User user) {
return json(response, doSynchronizeRepositories());
}

/**
* Trigger a synchronization of Repositories
*
* @return a boolean flag of the success/failed result
*/
public static boolean doSynchronizeRepositories() {
return FileLocks.SCC_REFRESH_LOCK.withFileLock(() -> {
try {
ContentSyncManager csm = new ContentSyncManager();
csm.updateRepositories(null);
return json(response, true);
return true;
}
catch (Exception e) {
log.fatal(e.getMessage(), e);
return json(response, false);
return false;
}
});
}

/**
* Trigger a synchronization of Subscriptions
*
* @param request the request
* @param request the request
* @param response the response
* @param user the user
* @param user the user
* @return a JSON flag of the success/failed result
*/
public static String synchronizeSubscriptions(Request request, Response response, User user) {
return json(response, doSynchronizeSubscriptions());
}

/**
* Trigger a synchronization of Subscriptions
*
* @return a boolean flag of the success/failed result
*/
public static boolean doSynchronizeSubscriptions() {
return FileLocks.SCC_REFRESH_LOCK.withFileLock(() -> {
try {
ContentSyncManager csm = new ContentSyncManager();
csm.updateSubscriptions();
return json(response, true);
return true;
}
catch (Exception e) {
log.fatal(e.getMessage(), e);
return json(response, false);
return false;
}
});
}
Expand Down

0 comments on commit a2ea972

Please sign in to comment.