Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[artifact-manager] [archetypes/vra] (#210) Cloud Template folder name and the name from details.json mismatch issue fixed in vRA #300

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.LinkedHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.Objects;

public class VraNgBlueprintStore extends AbstractVraNgStore {

Expand Down Expand Up @@ -232,19 +233,25 @@ private void storeBlueprintsOnFilesystem(final Package serverPackage, final VraN
* Handling import of a single blueprint - reading files from a directory, it's name would match
* the blueprint name and contain files describing its details, content and versions.
*
* @param bpDir
* @param bpsOnServerByName
* @param bpDir blueprint folder
* @param bpsOnServerByName existing blueprints from the server
* @throws IllegalStateException if blueprint folder name mismatch with the name from details.json
*/
private void handleBlueprintImport(final File bpDir, final Map<String, VraNgBlueprint> bpsOnServerByName) {
String bpName = bpDir.getName();
logger.info("Attempting to import blueprint \"" + bpDir.getName() + "\"");
VraNgBlueprint bp = loadBlueprintFromFilesystem(bpDir);
String bpID;

// Check the blueprint folder name(bpName) with the name from details.json(bp.getName())
Michaelpalacce marked this conversation as resolved.
Show resolved Hide resolved
if (!Objects.equals(bp.getName(), bpName)) {
Michaelpalacce marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalStateException(String.format("Mismatch between the blueprint folder name and the name from details.json. (%s, %s)", bpName, bp.getName()));
}

// Check if the blueprint exists
VraNgBlueprint existingRecord = null;
if (bpsOnServerByName.containsKey(bpName)) {
existingRecord = bpsOnServerByName.get(bpName);
if (bpsOnServerByName.containsKey(bp.getName())) {
bcpmihail marked this conversation as resolved.
Show resolved Hide resolved
existingRecord = bpsOnServerByName.get(bp.getName());
}

if (existingRecord == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,18 @@ public File getWorkdir() {
* @param blueprint - The blueprint to store
*/
public void addBlueprint(final VraNgBlueprint blueprint) {
File blueprintFolder = Paths.get(this.getWorkdir().getAbsolutePath(),
blueprint.getName()).toFile();
addBlueprint(blueprint, blueprint.getName());
}

/**
* JSON encodes a blueprint and adds it to the blueprint directory.
* This will also create the content.yaml based on the blueprint and alternatively accepts a versions' data containing
* information about the versions.
* @param blueprint - Blueprint to store
* @param folderName - Blueprint folder name
*/
public void addBlueprint(final VraNgBlueprint blueprint, String folderName) {
File blueprintFolder = Paths.get(this.getWorkdir().getAbsolutePath(), folderName).toFile();

if (!blueprintFolder.exists()) {
if (!blueprintFolder.mkdirs()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,25 @@ void testImportContentForNonExistingBlueprintsInConfiguration() throws IOExcepti
// VERIFY
verify(restClient, times(1)).createBlueprint(any());
}

@Test
void testImportContentWithDiffBlueprintFolderName() {
// GIVEN
List<String> blueprintNames = new ArrayList<>();
blueprintNames.add("nginx-blueprint-1");

when(vraNgPackageDescriptor.getBlueprint()).thenReturn(blueprintNames);

// INSIDE THE details.json -> name
BlueprintMockBuilder builder = new BlueprintMockBuilder("nginx-blueprint");
VraNgBlueprint blueprint = builder.build();

fsMocks.blueprintFsMocks().addBlueprint(blueprint, "nginx-blueprint-1");

List<VraNgBlueprint> bluePrintsOnServer = new ArrayList<>();
when(restClient.getAllBlueprints()).thenReturn(bluePrintsOnServer);

// START TEST & VERIFY EXCEPTION
assertThrows(IllegalStateException.class, () -> store.importContent(tempFolder.getRoot()));
}
}
11 changes: 11 additions & 0 deletions docs/versions/latest/Release.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ The `enableConfigManager`, `maximumHardwareVersionKey` and `desiredSoftwareSpec`

<https://github.com/vmware/build-tools-for-vmware-aria/issues/297>

### Cloud Template folder name and details.json->name mismatch issue fixed

#### Previous Behavior

- When the Cloud-Template folder name does not match the name from details.json, folder name is used for validating if the record exists on the server and the name from details.json is used for creating/updating the cloud template on server.

#### Current Behavior

- When the Cloud-Template folder name does not match the name from details.json, now an error throwing explaining the mismatch.
- The name from details.json is now used for both validating and creating/updating cloud template on the server.

## Upgrade Procedure

[//]: # "Explain in details if something needs to be done"
Loading