forked from vmware-archive/admiral
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VBV-2022] [BE] Populate favorite images on startup
+ Add method to return all FavorteImage states from json file + Add states to ComputeInitialBootService ++ Create condition to not populate favorite images if it is a test case ++ Rewrite tests for FavoriteImagesService so they conform to the initial population of the default images ++ Implement test case for the initial population of favorite images +++ Fix checkstyle issues +++ Generate default images self link based on name and registry +++ Remove unneeded tests Change-Id: I8bf71aeaa1dd075d0fc5b832393fd92c74de577c Reviewed-on: https://bellevue-ci.eng.vmware.com:8080/35885 Upgrade-Verified: jenkins <[email protected]> Closures-Verified: jenkins <[email protected]> Bellevue-Verified: jenkins <[email protected]> CS-Verified: jenkins <[email protected]> Reviewed-by: Georgi Muleshkov <[email protected]>
- Loading branch information
1 parent
d3d10de
commit 21cb8f4
Showing
10 changed files
with
319 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
compute/src/main/java/com/vmware/admiral/image/service/FavoriteImagePopulateFlagService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2018 VMware, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product may include a number of subcomponents with separate copyright notices | ||
* and license terms. Your use of these subcomponents is subject to the terms and | ||
* conditions of the subcomponent's license, as noted in the LICENSE file. | ||
*/ | ||
|
||
package com.vmware.admiral.image.service; | ||
|
||
import com.vmware.admiral.common.ManagementUriParts; | ||
import com.vmware.xenon.common.LocalizableValidationException; | ||
import com.vmware.xenon.common.Operation; | ||
import com.vmware.xenon.common.ServiceDocument; | ||
import com.vmware.xenon.common.StatefulService; | ||
import com.vmware.xenon.common.UriUtils; | ||
|
||
public class FavoriteImagePopulateFlagService extends StatefulService { | ||
public static final String FACTORY_LINK = ManagementUriParts.FAVORITE_IMAGES_FLAG; | ||
public static final String FAVORITE_IMAGE_POPULATE_FLAG_ID = "flag"; | ||
public static final String FAVORITE_IMAGE_POPULATE_FLAG_LINK = UriUtils | ||
.buildUriPath(FACTORY_LINK, FAVORITE_IMAGE_POPULATE_FLAG_ID); | ||
|
||
public FavoriteImagePopulateFlagService() { | ||
super(FavoriteImagePopulateFlag.class); | ||
super.toggleOption(ServiceOption.PERSISTENCE, true); | ||
super.toggleOption(ServiceOption.REPLICATION, true); | ||
super.toggleOption(ServiceOption.OWNER_SELECTION, true); | ||
super.toggleOption(ServiceOption.IDEMPOTENT_POST, true); | ||
} | ||
|
||
public static FavoriteImagePopulateFlag buildDefaultStateInstance() { | ||
FavoriteImagePopulateFlag state = new FavoriteImagePopulateFlag(); | ||
state.documentSelfLink = FAVORITE_IMAGE_POPULATE_FLAG_LINK; | ||
state.shouldPopulate = Boolean.TRUE; | ||
state.shouldPopulateInEmbedded = Boolean.TRUE; | ||
return state; | ||
} | ||
|
||
public static class FavoriteImagePopulateFlag extends ServiceDocument { | ||
public Boolean shouldPopulate; | ||
public Boolean shouldPopulateInEmbedded; | ||
} | ||
|
||
@Override | ||
public void handlePost(Operation post) { | ||
if (!post.hasBody()) { | ||
post.fail(new IllegalArgumentException("body is required")); | ||
return; | ||
} | ||
|
||
FavoriteImagePopulateFlag initState = post.getBody(FavoriteImagePopulateFlag.class); | ||
if (initState.documentSelfLink == null | ||
|| !initState.documentSelfLink | ||
.endsWith(FAVORITE_IMAGE_POPULATE_FLAG_ID)) { | ||
post.fail(new LocalizableValidationException( | ||
"Only one instance of favorite image populate shouldPopulate can be started", | ||
"compute.should-populte-flag.single")); | ||
return; | ||
} | ||
|
||
post.setBody(initState).complete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.