Skip to content

Commit a2ea972

Browse files
CDellaGiustamcalmer
authored andcommitted
Add APIs to perform product refresh on the peripheral from the hub
1 parent a9ec011 commit a2ea972

File tree

4 files changed

+125
-15
lines changed

4 files changed

+125
-15
lines changed

java/code/src/com/suse/manager/hub/HubController.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static com.suse.manager.webui.utils.SparkApplicationHelper.asJson;
1919
import static com.suse.manager.webui.utils.SparkApplicationHelper.badRequest;
2020
import static com.suse.manager.webui.utils.SparkApplicationHelper.internalServerError;
21+
import static com.suse.manager.webui.utils.SparkApplicationHelper.json;
2122
import static com.suse.manager.webui.utils.SparkApplicationHelper.message;
2223
import static com.suse.manager.webui.utils.SparkApplicationHelper.success;
2324
import static spark.Spark.get;
@@ -110,6 +111,14 @@ public void initRoutes() {
110111
asJson(usingTokenAuthentication(onlyFromHub(this::addCustomChannels))));
111112
post("/hub/modifyCustomChannels",
112113
asJson(usingTokenAuthentication(onlyFromHub(this::modifyCustomChannels))));
114+
post("/hub/sync/channelfamilies",
115+
asJson(usingTokenAuthentication(onlyFromHub(this::synchronizeChannelFamilies))));
116+
post("/hub/sync/products",
117+
asJson(usingTokenAuthentication(onlyFromHub(this::synchronizeProducts))));
118+
post("/hub/sync/repositories",
119+
asJson(usingTokenAuthentication(onlyFromHub(this::synchronizeRepositories))));
120+
post("/hub/sync/subscriptions",
121+
asJson(usingTokenAuthentication(onlyFromHub(this::synchronizeSubscriptions))));
113122
}
114123

115124
private String setHubDetails(Request request, Response response, IssAccessToken accessToken) {
@@ -347,4 +356,20 @@ private String modifyCustomChannels(Request request, Response response, IssAcces
347356
.toList();
348357
return success(response, modifiedCustomChannelsInfoList);
349358
}
359+
360+
private String synchronizeChannelFamilies(Request request, Response response, IssAccessToken token) {
361+
return json(response, hubManager.synchronizeChannelFamilies(token));
362+
}
363+
364+
private String synchronizeProducts(Request request, Response response, IssAccessToken token) {
365+
return json(response, hubManager.synchronizeProducts(token));
366+
}
367+
368+
private String synchronizeRepositories(Request request, Response response, IssAccessToken token) {
369+
return json(response, hubManager.synchronizeRepositories(token));
370+
}
371+
372+
private String synchronizeSubscriptions(Request request, Response response, IssAccessToken token) {
373+
return json(response, hubManager.synchronizeSubscriptions(token));
374+
}
350375
}

java/code/src/com/suse/manager/hub/HubManager.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import com.suse.manager.model.hub.ManagerInfoJson;
5656
import com.suse.manager.model.hub.ModifyCustomChannelInfoJson;
5757
import com.suse.manager.model.hub.TokenType;
58+
import com.suse.manager.webui.controllers.ProductsController;
5859
import com.suse.manager.webui.utils.token.IssTokenBuilder;
5960
import com.suse.manager.webui.utils.token.Token;
6061
import com.suse.manager.webui.utils.token.TokenBuildingException;
@@ -999,4 +1000,48 @@ public List<Channel> modifyCustomChannels(IssAccessToken accessToken,
9991000
.filter(e -> modifiedChannelsLabelList.contains(e.getLabel()))
10001001
.toList();
10011002
}
1003+
1004+
/**
1005+
* Trigger a synchronization of Channel Families on the peripheral
1006+
*
1007+
* @param accessToken the access token
1008+
* @return a boolean flag of the success/failed result
1009+
*/
1010+
public boolean synchronizeChannelFamilies(IssAccessToken accessToken) {
1011+
ensureValidToken(accessToken);
1012+
return ProductsController.doSynchronizeChannelFamilies();
1013+
}
1014+
1015+
/**
1016+
* Trigger a synchronization of Products on the peripheral
1017+
*
1018+
* @param accessToken the access token
1019+
* @return a boolean flag of the success/failed result
1020+
*/
1021+
public boolean synchronizeProducts(IssAccessToken accessToken) {
1022+
ensureValidToken(accessToken);
1023+
return ProductsController.doSynchronizeProducts();
1024+
}
1025+
1026+
/**
1027+
* Trigger a synchronization of Repositories on the peripheral
1028+
*
1029+
* @param accessToken the access token
1030+
* @return a boolean flag of the success/failed result
1031+
*/
1032+
public boolean synchronizeRepositories(IssAccessToken accessToken) {
1033+
ensureValidToken(accessToken);
1034+
return ProductsController.doSynchronizeRepositories();
1035+
}
1036+
1037+
/**
1038+
* Trigger a synchronization of Subscriptions on the peripheral
1039+
*
1040+
* @param accessToken the access token
1041+
* @return a boolean flag of the success/failed result
1042+
*/
1043+
public boolean synchronizeSubscriptions(IssAccessToken accessToken) {
1044+
ensureValidToken(accessToken);
1045+
return ProductsController.doSynchronizeSubscriptions();
1046+
}
10021047
}

java/code/src/com/suse/manager/hub/test/HubControllerTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ private static Stream<Arguments> allApiEndpoints() {
117117
Arguments.of(HttpMethod.get, "/hub/listAllPeripheralChannels", IssRole.HUB),
118118
Arguments.of(HttpMethod.post, "/hub/addVendorChannels", IssRole.HUB),
119119
Arguments.of(HttpMethod.post, "/hub/addCustomChannels", IssRole.HUB),
120-
Arguments.of(HttpMethod.post, "/hub/modifyCustomChannels", IssRole.HUB)
120+
Arguments.of(HttpMethod.post, "/hub/modifyCustomChannels", IssRole.HUB),
121+
Arguments.of(HttpMethod.post, "/hub/sync/channelfamilies", IssRole.HUB),
122+
Arguments.of(HttpMethod.post, "/hub/sync/products", IssRole.HUB),
123+
Arguments.of(HttpMethod.post, "/hub/sync/repositories", IssRole.HUB),
124+
Arguments.of(HttpMethod.post, "/hub/sync/subscriptions", IssRole.HUB)
121125
);
122126
}
123127

java/code/src/com/suse/manager/webui/controllers/ProductsController.java

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,30 @@ private static ProductsPageMetadataJson getMetadataJson() {
154154
/**
155155
* Trigger a synchronization of Products
156156
*
157-
* @param request the request
157+
* @param request the request
158158
* @param response the response
159-
* @param user the user
159+
* @param user the user
160160
* @return a JSON flag of the success/failed result
161161
*/
162162
public static String synchronizeProducts(Request request, Response response, User user) {
163+
return json(response, doSynchronizeProducts());
164+
}
165+
166+
/**
167+
* Trigger a synchronization of Products
168+
*
169+
* @return a boolean flag of the success/failed result
170+
*/
171+
public static boolean doSynchronizeProducts() {
163172
return FileLocks.SCC_REFRESH_LOCK.withFileLock(() -> {
164173
try {
165174
ContentSyncManager csm = new ContentSyncManager();
166175
csm.updateSUSEProducts(csm.getProducts());
167-
return json(response, true);
176+
return true;
168177
}
169178
catch (Exception e) {
170179
log.fatal(e.getMessage(), e);
171-
return json(response, false);
180+
return false;
172181
}
173182
});
174183
}
@@ -182,59 +191,86 @@ public static String synchronizeProducts(Request request, Response response, Use
182191
* @return a JSON flag of the success/failed result
183192
*/
184193
public static String synchronizeChannelFamilies(Request request, Response response, User user) {
194+
return json(response, doSynchronizeChannelFamilies());
195+
}
196+
197+
/**
198+
* Trigger a synchronization of Channel Families
199+
*
200+
* @return a boolean flag of the success/failed result
201+
*/
202+
public static boolean doSynchronizeChannelFamilies() {
185203
return FileLocks.SCC_REFRESH_LOCK.withFileLock(() -> {
186204
try {
187205
ContentSyncManager csm = new ContentSyncManager();
188206
csm.updateChannelFamilies(csm.readChannelFamilies());
189-
return json(response, true);
207+
return true;
190208
}
191209
catch (Exception e) {
192210
log.fatal(e.getMessage(), e);
193-
return json(response, false);
211+
return false;
194212
}
195213
});
196214
}
197215

198216
/**
199217
* Trigger a synchronization of Repositories
200218
*
201-
* @param request the request
219+
* @param request the request
202220
* @param response the response
203-
* @param user the user
221+
* @param user the user
204222
* @return a JSON flag of the success/failed result
205223
*/
206224
public static String synchronizeRepositories(Request request, Response response, User user) {
225+
return json(response, doSynchronizeRepositories());
226+
}
227+
228+
/**
229+
* Trigger a synchronization of Repositories
230+
*
231+
* @return a boolean flag of the success/failed result
232+
*/
233+
public static boolean doSynchronizeRepositories() {
207234
return FileLocks.SCC_REFRESH_LOCK.withFileLock(() -> {
208235
try {
209236
ContentSyncManager csm = new ContentSyncManager();
210237
csm.updateRepositories(null);
211-
return json(response, true);
238+
return true;
212239
}
213240
catch (Exception e) {
214241
log.fatal(e.getMessage(), e);
215-
return json(response, false);
242+
return false;
216243
}
217244
});
218245
}
219246

220247
/**
221248
* Trigger a synchronization of Subscriptions
222249
*
223-
* @param request the request
250+
* @param request the request
224251
* @param response the response
225-
* @param user the user
252+
* @param user the user
226253
* @return a JSON flag of the success/failed result
227254
*/
228255
public static String synchronizeSubscriptions(Request request, Response response, User user) {
256+
return json(response, doSynchronizeSubscriptions());
257+
}
258+
259+
/**
260+
* Trigger a synchronization of Subscriptions
261+
*
262+
* @return a boolean flag of the success/failed result
263+
*/
264+
public static boolean doSynchronizeSubscriptions() {
229265
return FileLocks.SCC_REFRESH_LOCK.withFileLock(() -> {
230266
try {
231267
ContentSyncManager csm = new ContentSyncManager();
232268
csm.updateSubscriptions();
233-
return json(response, true);
269+
return true;
234270
}
235271
catch (Exception e) {
236272
log.fatal(e.getMessage(), e);
237-
return json(response, false);
273+
return false;
238274
}
239275
});
240276
}

0 commit comments

Comments
 (0)