diff --git a/common/artifact-manager/pom.xml b/common/artifact-manager/pom.xml
index d2f2d1bd7..0d0da1ca5 100644
--- a/common/artifact-manager/pom.xml
+++ b/common/artifact-manager/pom.xml
@@ -58,7 +58,7 @@
COVEREDRATIO
- 0.25
+ 0.20
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgFlavorMapping.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgFlavorMapping.java
deleted file mode 100644
index d71092bb2..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgFlavorMapping.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.model.vrang;
-
-public class VraNgFlavorMapping {
-
- private final String name;
- private final String json;
-
- public VraNgFlavorMapping(String name, String json) {
- this.name = name;
- this.json = json;
- }
-
- public String getName() {
- return this.name;
- }
-
- public String getJson() {
- return this.json;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null || !this.getClass().equals(obj.getClass())) {
- return false;
- }
-
- VraNgFlavorMapping other = (VraNgFlavorMapping) obj;
- return this.name.equals(other.getName());
- }
-
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgFlavorProfile.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgFlavorProfile.java
deleted file mode 100644
index 496f8164d..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgFlavorProfile.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.model.vrang;
-
-import java.util.List;
-
-public class VraNgFlavorProfile {
-
- private final String id;
- private List flavorMappings;
-
- public VraNgFlavorProfile(String id, List flavorMappings) {
- this.id = id;
- this.flavorMappings = flavorMappings;
- }
-
- public String getId() {
- return this.id;
- }
-
- public List getFlavorMappings() {
- return flavorMappings;
- }
-
-
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null || !this.getClass().equals(obj.getClass())) {
- return false;
- }
-
- VraNgFlavorProfile other = (VraNgFlavorProfile) obj;
- return this.id.equals(other.getId());
- }
-
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgImageMapping.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgImageMapping.java
deleted file mode 100644
index 180566f99..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgImageMapping.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.model.vrang;
-
-public class VraNgImageMapping {
-
- private final String name;
- private final String json;
-
- public VraNgImageMapping(String name, String json) {
- this.name = name;
- this.json = json;
- }
-
- public String getName() {
- return this.name;
- }
-
- public String getJson() {
- return this.json;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null || !this.getClass().equals(obj.getClass())) {
- return false;
- }
-
- VraNgImageMapping other = (VraNgImageMapping) obj;
- return this.name.equals(other.getName());
- }
-
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgImageProfile.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgImageProfile.java
deleted file mode 100644
index 540d72f9c..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgImageProfile.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.model.vrang;
-
-import java.util.List;
-
-public class VraNgImageProfile {
-
- private final String id;
- private List imageMappings;
-
- public VraNgImageProfile(String id, List imageMappings) {
- this.id = id;
- this.imageMappings = imageMappings;
- }
-
- public String getId() {
- return this.id;
- }
-
- public List getImageMappings() {
- return imageMappings;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null || !this.getClass().equals(obj.getClass())) {
- return false;
- }
-
- VraNgImageProfile other = (VraNgImageProfile) obj;
- return this.id.equals(other.getId());
- }
-
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageContent.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageContent.java
index 2808aa57b..8f606a443 100644
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageContent.java
+++ b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageContent.java
@@ -19,14 +19,15 @@
import com.vmware.pscoe.iac.artifact.model.PackageContent;
/**
- * This class extends the PackageContent class and provides a list of content types specific to VraNg.
+ * This class extends the PackageContent class and provides a list of content
+ * types specific to VraNg.
*/
public class VraNgPackageContent extends PackageContent {
-
+
/**
* This enum represents the various content types that a VraNgPackage can have.
*/
- public enum ContentType implements PackageContent.ContentType {
+ public enum ContentType implements PackageContent.ContentType {
/**
* Content type for blueprints.
*/
@@ -35,22 +36,6 @@ public enum ContentType implements PackageContent.ContentType {
* Content type for subscriptions.
*/
SUBSCRIPTION("subscription"),
- /**
- * Content type for flavor mappings.
- */
- FLAVOR_MAPPING("flavor-mapping"),
- /**
- * Content type for image mappings.
- */
- IMAGE_MAPPING("image-mapping"),
- /**
- * Content type for storage profiles.
- */
- STORAGE_PROFILE("storage-profile"),
- /**
- * Content type for region mappings.
- */
- REGION_MAPPING("region-mapping"),
/**
* Content type for catalog entitlement.
*/
@@ -103,53 +88,53 @@ public enum ContentType implements PackageContent.ContentType {
* Content type for approval policies.
*/
APPROVAL_POLICY("approval");
+
/**
* PackageContent type.
*/
private final String type;
-
- /**
+ /**
* Constructor for ContentType.
*
- * @param type the type of the content.
+ * @param type the type of the content.
*/
ContentType(String type) {
this.type = type;
}
-
- /**
+
+ /**
* Gets the type value.
*
* @return the type value.
*/
- public String getTypeValue() {
+ public String getTypeValue() {
return this.type;
}
-
- /**
+
+ /**
* Returns the ContentType instance corresponding to the given type.
*
- * @param type the type of the content.
+ * @param type the type of the content.
* @return the ContentType instance.
*/
- public static ContentType getInstance(String type) {
- for (ContentType ct: ContentType.values()) {
+ public static ContentType getInstance(String type) {
+ for (ContentType ct : ContentType.values()) {
if (ct.getTypeValue().equalsIgnoreCase(type)) {
return ct;
}
}
return null;
}
-
+
}
- /**
+ /**
* Constructor for VraNgPackageContent.
*
- * @param content the content of the package.
+ * @param content the content of the package.
*/
- public VraNgPackageContent(List> content) {
+ public VraNgPackageContent(List> content) {
super(content);
}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageDescriptor.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageDescriptor.java
index 8ce0ad877..c7793ce62 100644
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageDescriptor.java
+++ b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageDescriptor.java
@@ -46,18 +46,6 @@ public class VraNgPackageDescriptor extends PackageDescriptor {
* List of subscriptions.
*/
private List subscription;
- /**
- * List of flavorMappings.
- */
- private List flavorMapping;
- /**
- * List of imageMappings.
- */
- private List imageMapping;
- /**
- * List of storageProfiles.
- */
- private List storageProfile;
/**
* List of catalogEntitlements.
*/
@@ -66,10 +54,6 @@ public class VraNgPackageDescriptor extends PackageDescriptor {
* List of propertyGroups.
*/
private List propertyGroup;
- /**
- * List of regionMappings.
- */
- private VraNgRegionMapping regionMapping;
/**
* List of customResources.
*/
@@ -93,6 +77,7 @@ public class VraNgPackageDescriptor extends PackageDescriptor {
/**
* Getter.
+ *
* @return propertyGroup list.
*/
public List getPropertyGroup() {
@@ -101,14 +86,16 @@ public List getPropertyGroup() {
/**
* Setter.
+ *
* @param propertyGroup input values.
*/
public void setPropertyGroup(List propertyGroup) {
- this.propertyGroup = propertyGroup;
+ this.propertyGroup = propertyGroup;
}
/**
* Getter.
+ *
* @return blueprints.
*/
@@ -118,6 +105,7 @@ public List getBlueprint() {
/**
* Setter.
+ *
* @param blueprint input values.
*/
public void setBlueprint(List blueprint) {
@@ -126,6 +114,7 @@ public void setBlueprint(List blueprint) {
/**
* Getter.
+ *
* @return catalogItems.
*/
public List getCatalogItem() {
@@ -134,6 +123,7 @@ public List getCatalogItem() {
/**
* Setter.
+ *
* @param catalogItem input values.
*/
public void setCatalogItem(List catalogItem) {
@@ -142,6 +132,7 @@ public void setCatalogItem(List catalogItem) {
/**
* Getter.
+ *
* @return subscriptions.
*/
public List getSubscription() {
@@ -150,6 +141,7 @@ public List getSubscription() {
/**
* Setter.
+ *
* @param subscription input values.
*/
public void setSubscription(List subscription) {
@@ -158,70 +150,7 @@ public void setSubscription(List subscription) {
/**
* Getter.
- * @return flavor mappings.
- */
- public List getFlavorMapping() {
- return this.flavorMapping;
- }
-
- /**
- * Setter.
- * @param flavorMapping input values.
- */
- public void setFlavorMapping(List flavorMapping) {
- this.flavorMapping = flavorMapping;
- }
-
- /**
- * Getter.
- * @return image mappings.
- */
- public List getImageMapping() {
- return this.imageMapping;
- }
-
- /**
- * Setter.
- * @param imageMapping input values.
- */
- public void setImageMapping(List imageMapping) {
- this.imageMapping = imageMapping;
- }
-
- /**
- * Getter.
- * @return storage profiles.
- */
- public List getStorageProfile() {
- return this.storageProfile;
- }
-
- /**
- * Setter.
- * @param storageProfile input values.
- */
- public void setStorageProfile(List storageProfile) {
- this.storageProfile = storageProfile;
- }
-
- /**
- * Getter.
- * @return region mappings.
- */
- public VraNgRegionMapping getRegionMapping() {
- return this.regionMapping;
- }
-
- /**
- * Setter.
- * @param regionMapping input values.
- */
- public void setRegionMapping(VraNgRegionMapping regionMapping) {
- this.regionMapping = regionMapping;
- }
-
- /**
- * Getter.
+ *
* @return catalog entitlements.
*/
public List getCatalogEntitlement() {
@@ -230,6 +159,7 @@ public List getCatalogEntitlement() {
/**
* Setter.
+ *
* @param catalogEntitlement input values.
*/
public void setCatalogEntitlement(List catalogEntitlement) {
@@ -238,6 +168,7 @@ public void setCatalogEntitlement(List catalogEntitlement) {
/**
* Getter.
+ *
* @return policy container.
*/
public VraNgPolicy getPolicy() {
@@ -246,6 +177,7 @@ public VraNgPolicy getPolicy() {
/**
* Setter.
+ *
* @param policy input value.
*/
public void setPolicy(VraNgPolicy policy) {
@@ -255,6 +187,7 @@ public void setPolicy(VraNgPolicy policy) {
/**
* Getter.
+ *
* @return customResources.
*/
public List getCustomResource() {
@@ -263,6 +196,7 @@ public List getCustomResource() {
/**
* Setter.
+ *
* @param customResource input values.
*/
public void setCustomResource(List customResource) {
@@ -271,6 +205,7 @@ public void setCustomResource(List customResource) {
/**
* Getter.
+ *
* @return resource actions.
*/
public List getResourceAction() {
@@ -279,6 +214,7 @@ public List getResourceAction() {
/**
* Setter.
+ *
* @param resourceAction input values.
*/
public void setResourceAction(List resourceAction) {
@@ -287,6 +223,7 @@ public void setResourceAction(List resourceAction) {
/**
* Getter.
+ *
* @return Content sources.
*/
public List getContentSource() {
@@ -295,6 +232,7 @@ public List getContentSource() {
/**
* Setter.
+ *
* @param contentSource input values.
*/
public void setContentSource(List contentSource) {
@@ -313,12 +251,6 @@ public List getMembersForType(VraNgPackageMemberType type) {
return getBlueprint();
case SUBSCRIPTION:
return getSubscription();
- case FLAVOR_PROFILE:
- return getFlavorMapping();
- case IMAGE_PROFILE:
- return getImageMapping();
- case STORAGE_PROFILE:
- return getStorageProfile();
case CATALOG_ENTITLEMENT:
return getCatalogEntitlement();
case PROPERTY_GROUP:
@@ -331,30 +263,28 @@ public List getMembersForType(VraNgPackageMemberType type) {
return getContentSource();
case CATALOG_ITEM:
return getCatalogItem();
- // case REGION_MAPPING:
- // return getRegionMapping().stream().map(rm -> {
- // rm.getCloudAccountTags().keySet();
- // }).collect(Collectors.toList());
default:
throw new RuntimeException("ContentType is not supported!");
}
}
/**
- * List of values, filtered by type.isNativeContent().
+ * List of values, filtered by type.isNativeContent().
+ *
* @return list
*/
public boolean hasNativeContent() {
return Arrays.stream(VraNgPackageMemberType.values())
- .filter(type -> type.isNativeContent())
- .anyMatch(type -> {
- List memberNames = this.getMembersForType(type);
- return memberNames != null && !memberNames.isEmpty();
- });
+ .filter(type -> type.isNativeContent())
+ .anyMatch(type -> {
+ List memberNames = this.getMembersForType(type);
+ return memberNames != null && !memberNames.isEmpty();
+ });
}
/**
* Create a VraNgPackageDescriptor instance from file.
+ *
* @param filesystemPath the file
* @return VraNgPackageDescriptor instance
*/
@@ -368,12 +298,14 @@ public static VraNgPackageDescriptor getInstance(File filesystemPath) {
return pkgDescriptor;
} catch (Exception e) {
- throw new RuntimeException("Unable to load vRA Package Descriptor[" + filesystemPath.getAbsolutePath() + "]", e);
+ throw new RuntimeException(
+ "Unable to load vRA Package Descriptor[" + filesystemPath.getAbsolutePath() + "]", e);
}
}
/**
- * Create a VraNgPackageDescriptor instance from VraNgPackageContent instance.
+ * Create a VraNgPackageDescriptor instance from VraNgPackageContent instance.
+ *
* @param content the package content instance
* @return VraNgPackageDescriptor instance
*/
@@ -390,23 +322,13 @@ public static VraNgPackageDescriptor getInstance(VraNgPackageContent content) {
VraNgPackageDescriptor pd = new VraNgPackageDescriptor();
pd.blueprint = map.get(VraNgPackageContent.ContentType.BLUEPRINT);
pd.subscription = map.get(VraNgPackageContent.ContentType.SUBSCRIPTION);
- pd.flavorMapping = map.get(VraNgPackageContent.ContentType.FLAVOR_MAPPING);
- pd.imageMapping = map.get(VraNgPackageContent.ContentType.IMAGE_MAPPING);
- pd.storageProfile = map.get(VraNgPackageContent.ContentType.STORAGE_PROFILE);
pd.catalogEntitlement = map.get(VraNgPackageContent.ContentType.CATALOG_ENTITLEMENT);
pd.customResource = map.get(VraNgPackageContent.ContentType.CUSTOM_RESOURCE);
pd.resourceAction = map.get(VraNgPackageContent.ContentType.RESOURCE_ACTION);
pd.contentSource = map.get(VraNgPackageContent.ContentType.CONTENT_SOURCE);
pd.catalogItem = map.get(VraNgPackageContent.ContentType.CATALOG_ITEM);
pd.propertyGroup = map.get(VraNgPackageContent.ContentType.PROPERTY_GROUP);
- //pd.policy = map.get(VraNgPackageContent.ContentType.POLICY);
-
- // System.out.println("REGION MAPPINGS ------");
- // map.get(VraNgPackageContent.ContentType.REGION_MAPPING).forEach(e -> {
- // System.out.println(e);
- // });
- // pd.regionMapping = map.get(VraNgPackageContent.ContentType.REGION_MAPPING);
-
+ // pd.policy = map.get(VraNgPackageContent.ContentType.POLICY);
return pd;
}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageMemberType.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageMemberType.java
index 474df4a84..8e4f3a7c9 100644
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageMemberType.java
+++ b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgPackageMemberType.java
@@ -17,10 +17,6 @@
public enum VraNgPackageMemberType {
BLUEPRINT("blueprint"),
SUBSCRIPTION("subscription"),
- FLAVOR_PROFILE("flavor-profile"),
- IMAGE_PROFILE("image-profile"),
- STORAGE_PROFILE("storage-profile"),
- REGION_MAPPING("region-mapping"),
CATALOG_ENTITLEMENT("catalog-entitlement"),
CUSTOM_RESOURCE("custom-resource"),
RESOURCE_ACTION("resource-action"),
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgRegionMapping.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgRegionMapping.java
deleted file mode 100644
index c8624a829..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgRegionMapping.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.model.vrang;
-
-import com.vmware.pscoe.iac.artifact.model.vrang.objectmapping.VraNgCloudAccountTag;
-
-import org.apache.commons.lang3.NotImplementedException;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
-/**
- * This class is used to map the region to the cloud account tags.
- */
-public class VraNgRegionMapping {
- /**
- * @param Prime Number 17.
- */
- private static final int PRIME_NUMBER_17 = 17;
-
- /**
- * @param Prime Number 31.
- */
- private static final int PRIME_NUMBER_31 = 31;
-
- /**
- * @param cloudAccountTags The cloud account tags to be set
- */
- private VraNgCloudAccountTag cloudAccountTags;
-
- /**
- * Default constructor.
- */
- public VraNgRegionMapping() {
- super();
- this.cloudAccountTags = new VraNgCloudAccountTag();
- }
-
- /**
- * Constructor with cloud account tags.
- *
- * @param cloudAccountTags The cloud account tags to be set
- */
- public VraNgRegionMapping(VraNgCloudAccountTag cloudAccountTags) {
- this.cloudAccountTags = cloudAccountTags;
- }
-
- /**
- * Get the cloud account tags.
- *
- * @return The cloud account tags
- */
- public VraNgCloudAccountTag getCloudAccountTags() {
- return this.cloudAccountTags;
- }
-
- /**
- * Check if the object is equal to this object.
- *
- * @param obj The object to compare
- * @return True if the object is equal to this object, false otherwise
- */
- @Override
- public boolean equals(Object obj) {
- throw new NotImplementedException("Not implemented");
- }
-
- /**
- * @return the hash code of the region mapping
- */
- @Override
- public int hashCode() {
- return new HashCodeBuilder(PRIME_NUMBER_17, PRIME_NUMBER_31)
- .append(cloudAccountTags.hashCode())
- .toHashCode();
- }
-
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgStorageProfile.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgStorageProfile.java
deleted file mode 100644
index 3b38aa9ae..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/model/vrang/VraNgStorageProfile.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.model.vrang;
-
-public class VraNgStorageProfile {
-
- private final String name;
- private final String json;
-
- public VraNgStorageProfile(String name, String json) {
- this.name = name;
- this.json = json;
- }
-
- public String getName() {
- return this.name;
- }
-
- public String getJson() {
- return this.json;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null || !this.getClass().equals(obj.getClass())) {
- return false;
- }
-
- VraNgStorageProfile other = (VraNgStorageProfile) obj;
- return this.name.equals(other.getName());
- }
-
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/rest/RestClientVraNg.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/rest/RestClientVraNg.java
index dae6cbb86..d47934e8e 100644
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/rest/RestClientVraNg.java
+++ b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/rest/RestClientVraNg.java
@@ -39,8 +39,6 @@
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgCustomResource;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgDay2ActionsPolicy;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgDeploymentLimitPolicy;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgFlavorMapping;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgImageMapping;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgIntegration;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgLeasePolicy;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgProject;
@@ -49,7 +47,6 @@
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgResourceAction;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgResourceQuotaPolicy;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgSecret;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgStorageProfile;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgSubscription;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgWorkflowContentSource;
@@ -476,212 +473,6 @@ public VraNgRegion getRegion(final String id) {
}
}
- // =================================================
- // FLAVOR PROFILES OPERATIONS
- // =================================================
-
- /**
- * getAllFlavorMappingsByRegion.
- *
- * @return flavorMappings
- */
- public Map> getAllFlavorMappingsByRegion() {
- try {
- return getAllFlavorMappingsByRegionPrimitive();
- } catch (Exception e) {
- throw new RuntimeException("Could not get all flavour mappings by region", e);
- }
- }
-
- /**
- * getAllFlavorProfilesByRegion.
- *
- * @return flavourProfiles
- */
- public Map> getAllFlavorProfilesByRegion() {
- try {
- return getAllFlavorProfilesByRegionPrimitive();
- } catch (Exception e) {
- throw new RuntimeException("Could not get all flavour profiles by region.", e);
- }
- }
-
- /**
- * createFlavor.
- *
- * @param regionId region id
- * @param flavorProfileName flavor name
- * @param flavorMappings flavor mappings
- */
- public void createFlavor(final String regionId, final String flavorProfileName,
- final List flavorMappings) {
- try {
- createFlavorPrimitive(regionId, flavorProfileName, flavorMappings);
- } catch (Exception e) {
- throw new RuntimeException(String.format("Could not create Flavor with name '%s'.", flavorProfileName), e);
- }
- }
-
- /**
- * updateFlavor.
- *
- * @param flavorId flavor id
- * @param flavorMappings flavor mappings
- */
- public void updateFlavor(final String flavorId, final List flavorMappings) {
- try {
- updateFlavorPrimitive(flavorId, flavorMappings);
- } catch (Exception e) {
- throw new RuntimeException(String.format("Could not update Flavor Profile with id '%s'.", flavorId), e);
- }
- }
-
- // =================================================
- // IMAGE PROFILES OPERATIONS
- // =================================================
-
- /**
- * getAllImageMappingsByRegion.
- *
- * @return imageMappings
- */
- public Map> getAllImageMappingsByRegion() {
- try {
- return getAllImageMappingsByRegionPrimitive();
- } catch (Exception e) {
- throw new RuntimeException("Could not get all image mappings by region.", e);
- }
- }
-
- /**
- * getAllImageProfilesByRegion.
- *
- * @return imageProfiles
- */
- public Map> getAllImageProfilesByRegion() {
- try {
- return getAllImageProfilesByRegionPrimitive();
- } catch (Exception e) {
- throw new RuntimeException("Could not get all image profiles by region.", e);
- }
- }
-
- /**
- * createImageProfile.
- *
- * @param regionId region id
- * @param profileName profile name
- * @param imageMappings image mappings
- */
- public void createImageProfile(final String regionId, final String profileName,
- final List imageMappings) {
- try {
- createImageProfilePrimitive(regionId, profileName, imageMappings);
- } catch (Exception e) {
- throw new RuntimeException(String.format("Could not create Image Profile with name '%s'.", profileName), e);
- }
- }
-
- /**
- * updateImageProfile.
- *
- * @param profileId profile id
- * @param imageMappings image mappings
- */
- public void updateImageProfile(final String profileId, final List imageMappings) {
- try {
- updateImageProfilePrimitive(profileId, imageMappings);
- } catch (Exception e) {
- throw new RuntimeException(String.format("Could not update Image Profile with id '%s'.", profileId), e);
- }
- }
-
- // =================================================
- // STORAGE PROFILES OPERATIONS
- // =================================================
-
- /**
- * getAllStorageProfilesByRegion.
- *
- * @return storageProfile
- */
- public Map> getAllStorageProfilesByRegion() {
- try {
- return getAllStorageProfilesByRegionPrimitive();
- } catch (Exception e) {
- throw new RuntimeException("Could not get all storage profiles by region.", e);
- }
- }
-
- /**
- * updateStorageProfile.
- *
- * @param profileId profile id
- * @param profile vra storage profile
- */
- public void updateStorageProfile(final String profileId, final VraNgStorageProfile profile) {
- try {
- updateStorageProfilePrimitive(profileId, profile);
- } catch (Exception e) {
- logger.debug("Could not update Storage Profile with name '{}' and id '{}' using payload\n{}",
- profile.getName(), profileId, profile.getJson());
- throw new RuntimeException(
- String.format("Could not update Storage Profile with name '%s'.", profile.getName()), e);
- }
- }
-
- /**
- * createStorageProfile.
- *
- * @param profile vra storage file
- * @return storageProfile
- */
- public String createStorageProfile(final VraNgStorageProfile profile) {
- try {
- return createStorageProfilePrimitive(profile);
- } catch (Exception e) {
- logger.debug("Could not create Storage Profile with name '{}' using payload\n{}", profile.getName(),
- profile.getJson());
- throw new RuntimeException(
- String.format("Could not create Storage Profile with name '%s'.", profile.getName()), e);
- }
- }
-
- /**
- * getSpecificStorageProfile.
- *
- * @param targetPool target pool
- * @param profileId storage profile id
- * @return storageProfile
- */
- public VraNgStorageProfile getSpecificStorageProfile(final String targetPool, final String profileId) {
- try {
- return getSpecificProfilePrimitive(targetPool, profileId);
- } catch (Exception e) {
- logger.debug("Could not get Storage Profile with id '{}'", profileId);
- throw new RuntimeException(String.format("Could not get Storage Profile with id '%s'.", profileId), e);
- }
- }
-
- /**
- * updateSpecificProfile.
- *
- * @param patchTarget patch target
- * @param profileId storage profile id
- * @param profile storage profile
- */
- public void updateSpecificProfile(final String patchTarget, final String profileId,
- final VraNgStorageProfile profile) {
- try {
- updateSpecificProfilePrimitive(patchTarget, profileId, profile);
- } catch (Exception e) {
- logger.debug("Could not update Storage Profile with name '{}' and id '{}' using payload\n{}",
- profile.getName(), profileId, profile.getJson());
- throw new RuntimeException(
- String.format("Could not update Storage Profile with name '%s'.", profile.getName()), e);
- }
- }
-
/**
* getFabricEntityName.
*
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/rest/RestClientVraNgPrimitive.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/rest/RestClientVraNgPrimitive.java
index 3072a884b..117defc0d 100644
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/rest/RestClientVraNgPrimitive.java
+++ b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/rest/RestClientVraNgPrimitive.java
@@ -21,7 +21,6 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.rmi.UnexpectedException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -56,8 +55,6 @@
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgCustomResource;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgDay2ActionsPolicy;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgDeploymentLimitPolicy;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgFlavorMapping;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgImageMapping;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgIntegration;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgLeasePolicy;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgOrganization;
@@ -68,7 +65,6 @@
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgResourceAction;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgResourceQuotaPolicy;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgSecret;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgStorageProfile;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgSubscription;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgWorkflowContentSource;
@@ -1591,555 +1587,6 @@ private List getTags(final JsonElement tagsElement) {
return tags;
}
- // =================================================
- // FLAVOR PROFILES OPERATIONS
- // =================================================
-
- /**
- * Retrieve a flavor profile by id.
- *
- * @param id profile id
- * @return REST response payload
- * @throws URISyntaxException exception
- */
- protected ResponseEntity getFlavorProfileById(final String id) throws URISyntaxException {
- URI url = getURIBuilder().setPath(SERVICE_FLAVOR_PROFILE + "/" + id)
- .setParameter("apiVersion", this.getVersion()).build();
-
- return restTemplate.exchange(url, HttpMethod.GET, getDefaultHttpEntity(), String.class);
- }
-
- /**
- * Retrieve all flavor mappings grouped by region and group them by region id.
- *
- * @return map with key=region, value=list of VraNgFlavorMapping.
- * @see VraNgFlavorMapping
- */
- protected Map> getAllFlavorMappingsByRegionPrimitive() {
- URI url = getURI(getURIBuilder().setPath(SERVICE_FLAVORS));
-
- ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, getDefaultHttpEntity(),
- String.class);
-
- JsonElement root = JsonParser.parseString(response.getBody());
-
- Map> flavorMappingsByRegion = new HashMap<>();
-
- if (root.isJsonObject()) {
- root.getAsJsonObject().getAsJsonArray("content").forEach(o -> {
- JsonObject ob = o.getAsJsonObject();
- LOGGER.debug("Obtaining data from getAllFlavorMappingsByRegionPrimitive");
- if (!this.jsonObjectValid(ob)) {
- String regionId = this.getLinkRegionId(ob);
- if (!flavorMappingsByRegion.containsKey(regionId)) {
- flavorMappingsByRegion.put(regionId, new ArrayList<>());
- }
-
- JsonObject mappingsJson = ob.get("mapping").getAsJsonObject();
- List mappings = this.getFlavorMappings(mappingsJson);
- flavorMappingsByRegion.get(regionId).addAll(mappings);
- } else {
- LOGGER.warn("Obtaining data from getAllFlavorMappingsByRegionPrimitive returns empty objects.");
- }
- });
- }
-
- return flavorMappingsByRegion;
- }
-
- /**
- * Retrieve all flavor profile IDs grouped by region.
- *
- * @return map with key=region, value=list of flavor profile IDs.
- */
- protected Map> getAllFlavorProfilesByRegionPrimitive() {
- URI url = getURI(getURIBuilder().setPath(SERVICE_FLAVOR_PROFILE));
-
- ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, getDefaultHttpEntity(),
- String.class);
-
- JsonElement root = JsonParser.parseString(response.getBody());
-
- Map> flavorProfileIdsByRegion = new HashMap<>();
-
- if (root.isJsonObject()) {
- root.getAsJsonObject().getAsJsonArray("content").forEach(o -> {
- JsonObject ob = o.getAsJsonObject();
- LOGGER.debug("Obtaining data from getAllFlavorProfilesByRegionPrimitive");
- if (!this.jsonObjectValid(ob)) {
- String regionId = this.getLinkRegionId(ob);
- String flavorProfileId = ob.get("id").getAsString();
-
- if (!flavorProfileIdsByRegion.containsKey(regionId)) {
- flavorProfileIdsByRegion.put(regionId, new ArrayList<>());
- }
-
- flavorProfileIdsByRegion.get(regionId).add(flavorProfileId);
- } else {
- LOGGER.warn("Obtaining data from getAllFlavorProfilesByRegionPrimitive returns empty objects");
- }
- });
- }
-
- return flavorProfileIdsByRegion;
- }
-
- /**
- * Extract flavor mapping definition out of REST response body.
- *
- * @param mappingsJson flavor mapping structure
- * @return Flavor mappings
- */
- private List getFlavorMappings(final JsonObject mappingsJson) {
- List mappings = new ArrayList<>();
- // will return members of your object
- Set> entries = mappingsJson.entrySet();
- for (Map.Entry entry : entries) {
- String name = entry.getKey();
- String json = entry.getValue().getAsJsonObject().toString();
- mappings.add(new VraNgFlavorMapping(name, json));
- }
-
- return mappings;
- }
-
- /**
- * Create a new flavor profile.
- *
- * @param regionId region id
- * @param flavorProfileName profile name
- * @param flavorMappings list of flavor mappings
- * @throws URISyntaxException exception
- */
- protected void createFlavorPrimitive(final String regionId, final String flavorProfileName,
- final List flavorMappings) throws URISyntaxException {
-
- URI url = getURIBuilder().setPath(SERVICE_FLAVOR_PROFILE).setParameter("apiVersion", this.getVersion()).build();
-
- Map map = new HashMap<>();
- Map mappings = new HashMap<>();
- flavorMappings.forEach(fm -> {
- mappings.put(fm.getName(), JsonParser.parseString(fm.getJson()));
- });
-
- map.put("name", flavorProfileName);
- map.put("regionId", regionId);
- map.put("flavorMapping", mappings);
-
- String jsonBody = this.getJsonString(map);
- this.postJsonPrimitive(url, HttpMethod.POST, jsonBody);
- }
-
- /**
- * Update existing flavor profile with flavor mappings.
- *
- * @param flavorProfileId profile id
- * @param flavorMappings list of flavor mappings
- * @throws URISyntaxException exception
- * @throws UnexpectedException exception
- */
- protected void updateFlavorPrimitive(final String flavorProfileId, final List flavorMappings)
- throws URISyntaxException, UnexpectedException {
-
- URI url = getURIBuilder().setPath(SERVICE_FLAVOR_PROFILE + "/" + flavorProfileId)
- .setParameter("apiVersion", this.getVersion()).build();
- List flavorMappingsToImport = this.getFlavorMappingsToImport(flavorProfileId,
- flavorMappings);
-
- if (flavorMappingsToImport.size() == 0) {
- return;
- }
-
- Map map = new HashMap<>();
- Map flavorMapping = new HashMap<>();
- map.put("flavorMapping", new HashMap<>());
- flavorMappingsToImport.forEach(fm -> {
- flavorMapping.put(fm.getName(), JsonParser.parseString(fm.getJson()));
- });
-
- map.put("flavorMapping", flavorMapping);
-
- String jsonBody = this.getJsonString(map);
- this.postJsonPrimitive(url, HttpMethod.PATCH, jsonBody);
- }
-
- /**
- * Flavor mappings reconciliation. Added some extra checks if the
- * getFlavorProfileById returns unexpected response due to NullPointerException
- * (IAC-458)
- *
- * @param flavorProfileId profile id
- * @param flavorMappings list of flavor mappings
- * @return list of flavor mappings
- * @throws JsonSyntaxException exception
- * @throws URISyntaxException exception
- * @throws UnexpectedException exception
- */
- private List getFlavorMappingsToImport(final String flavorProfileId,
- final List flavorMappings)
- throws JsonSyntaxException, URISyntaxException, UnexpectedException {
- ResponseEntity flavorProfileById = this.getFlavorProfileById(flavorProfileId);
-
- if (flavorProfileById == null || !flavorProfileById.hasBody()) {
- throw new UnexpectedException("Invalid flavor profile response.");
- }
-
- JsonElement flavorProfileRoot = JsonParser.parseString(flavorProfileById.getBody());
- JsonObject flavorProfileObject = flavorProfileRoot.getAsJsonObject();
-
- List flavorMappingsOnServer = (
- // If the profile has no flavor mappings yet, it would not have that property at
- // all, so we're
- // checking if it exists, and if not - defining the variable with a default
- // value
- flavorProfileObject.has("flavorMappings")
- && flavorProfileObject.get("flavorMappings").getAsJsonObject().has("mapping"))
- ? (this.getFlavorMappings(flavorProfileObject.get("flavorMappings").getAsJsonObject()
- .get("mapping").getAsJsonObject()))
- : new ArrayList<>();
-
- List flavorMappingsToImport = new ArrayList<>(flavorMappings);
- flavorMappingsOnServer.forEach(fm -> {
- if (!flavorMappingsToImport.contains(fm)) {
- flavorMappingsToImport.add(fm);
- }
- });
-
- return flavorMappingsToImport;
- }
-
- // =================================================
- // IMAGE PROFILES OPERATIONS
- // =================================================
-
- /**
- * Retrieve an image profile by id.
- *
- * @param id profile id
- * @return REST response payload
- * @throws URISyntaxException exception
- */
- protected ResponseEntity getImageProfileById(final String id) throws URISyntaxException {
- URI url = getURIBuilder().setPath(SERVICE_IMAGE_PROFILE + "/" + id)
- .setParameter("apiVersion", this.getVersion()).build();
-
- return restTemplate.exchange(url, HttpMethod.GET, getDefaultHttpEntity(), String.class);
- }
-
- /**
- * Retrieve all image mappings for a given region and group them by region id.
- *
- * @return map with key=region, value=list of VraNgImageMapping.
- * @see VraNgImageMapping
- */
- protected Map> getAllImageMappingsByRegionPrimitive() {
- URI url = getURI(getURIBuilder().setPath(SERVICE_IMAGES));
-
- ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, getDefaultHttpEntity(),
- String.class);
-
- JsonElement root = JsonParser.parseString(response.getBody());
-
- Map> imageMappingsByRegion = new HashMap<>();
-
- if (root.isJsonObject()) {
- root.getAsJsonObject().getAsJsonArray("content").forEach(o -> {
- JsonObject ob = o.getAsJsonObject();
- LOGGER.debug("Obtaining data from getAllImageMappingsByRegionPrimitive");
- if (!this.jsonObjectValid(ob)) {
- String regionId = this.getLinkRegionId(ob);
- if (!imageMappingsByRegion.containsKey(regionId)) {
- imageMappingsByRegion.put(regionId, new ArrayList<>());
- }
-
- JsonObject mappingsJson = ob.get("mapping").getAsJsonObject();
- List mappings = this.getImageMappings(mappingsJson);
- imageMappingsByRegion.get(regionId).addAll(mappings);
- } else {
- LOGGER.warn("Skipped empty data from getAllImageMappingsByRegion. Some items are empty");
- }
- });
- }
-
- return imageMappingsByRegion;
- }
-
- /**
- * Checks JSON Object Validity.
- *
- * @param ob JSON Object
- * @return true if valid else false.
- */
- protected boolean jsonObjectValid(final JsonObject ob) {
- boolean jsonObjectValid = ob.has("mapping") && ob.has("_links")
- && ob.get("mapping").getAsJsonObject().keySet().isEmpty()
- && ob.get("_links").getAsJsonObject().keySet().isEmpty();
-
- LOGGER.debug(String.format("JSON object is valid: %s", jsonObjectValid));
- return jsonObjectValid;
- }
-
- /**
- * Retrieve all image profile IDs grouped by region.
- *
- * @return map with key=region, value=list of image profile IDs.
- */
- protected Map> getAllImageProfilesByRegionPrimitive() {
- URI url = getURI(getURIBuilder().setPath(SERVICE_IMAGE_PROFILE));
-
- ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, getDefaultHttpEntity(),
- String.class);
-
- JsonElement root = JsonParser.parseString(response.getBody());
-
- Map> imageProfileIdsByRegion = new HashMap<>();
-
- if (root.isJsonObject()) {
- root.getAsJsonObject().getAsJsonArray("content").forEach(o -> {
- JsonObject ob = o.getAsJsonObject();
-
- LOGGER.debug("Obtaining data from getAllImageProfilesByRegionPrimitive");
- if (!this.jsonObjectValid(ob)) {
- String regionId = this.getLinkRegionId(ob);
- String imageProfileId = ob.get("id").getAsString();
-
- if (!imageProfileIdsByRegion.containsKey(regionId)) {
- imageProfileIdsByRegion.put(regionId, new ArrayList<>());
- }
-
- imageProfileIdsByRegion.get(regionId).add(imageProfileId);
- } else {
- LOGGER.warn("Obtaining data from getAllImageProfilesByRegionPrimitive returns empty objects");
- }
- });
- }
-
- return imageProfileIdsByRegion;
- }
-
- /**
- * Extract image mapping definition out of REST response body.
- *
- * @param mappingsJson image mapping structure
- * @return List of VraNG Image Mapping
- */
- private List getImageMappings(final JsonObject mappingsJson) {
- List mappings = new ArrayList<>();
- // will return members of your object
- Set> entries = mappingsJson.entrySet();
- for (Map.Entry entry : entries) {
- String name = entry.getKey();
- String json = entry.getValue().getAsJsonObject().toString();
- mappings.add(new VraNgImageMapping(name, json));
- }
-
- return mappings;
- }
-
- /**
- * Create a new image profile.
- *
- * @param regionId region id
- * @param imageProfileName profile name
- * @param imageMappings list of image mappings
- * @throws URISyntaxException exception
- */
- protected void createImageProfilePrimitive(final String regionId, final String imageProfileName,
- final List imageMappings) throws URISyntaxException {
-
- URI url = getURIBuilder().setPath(SERVICE_IMAGE_PROFILE).setParameter("apiVersion", this.getVersion()).build();
-
- Map map = new HashMap<>();
- Map mappings = new HashMap<>();
- imageMappings.forEach(im -> {
- mappings.put(im.getName(), JsonParser.parseString(im.getJson()));
- });
-
- map.put("name", imageProfileName);
- map.put("regionId", regionId);
- map.put("imageMapping", mappings);
-
- String jsonBody = this.getJsonString(map);
- this.postJsonPrimitive(url, HttpMethod.POST, jsonBody);
- }
-
- /**
- * Update existing image profile with image mappings.
- *
- * @param imageProfileId profile id
- * @param imageMappings list of image mappings
- * @throws URISyntaxException exception
- * @throws UnexpectedException exception
- */
- protected void updateImageProfilePrimitive(final String imageProfileId, final List imageMappings)
- throws URISyntaxException, UnexpectedException {
-
- URI url = getURIBuilder().setPath(SERVICE_IMAGE_PROFILE + "/" + imageProfileId)
- .setParameter("apiVersion", this.getVersion()).build();
- List imageMappingsToImport = this.getImageMappingsToImport(imageProfileId, imageMappings);
-
- if (imageMappingsToImport.size() == 0) {
- return;
- }
-
- Map map = new HashMap<>();
- Map imageMapping = new HashMap<>();
- map.put("imageMapping", new HashMap<>());
- imageMappingsToImport.forEach(im -> {
- imageMapping.put(im.getName(), JsonParser.parseString(im.getJson()));
- });
-
- map.put("imageMapping", imageMapping);
-
- String jsonBody = this.getJsonString(map);
- this.postJsonPrimitive(url, HttpMethod.PATCH, jsonBody);
- }
-
- /**
- * Image mappings reconciliation. If the response is empty or contains no
- * mappings, an empty List is returned.
- *
- * @param imageProfileId profile id
- * @param imageMappings list of image mappings
- * @return list of image mappings
- * @throws JsonSyntaxException exception
- * @throws URISyntaxException exception
- * @throws UnexpectedException exception
- */
- private List getImageMappingsToImport(final String imageProfileId,
- final List imageMappings)
- throws JsonSyntaxException, URISyntaxException, UnexpectedException {
- ResponseEntity response = this.getImageProfileById(imageProfileId);
-
- if (response == null || !response.hasBody()) {
- throw new UnexpectedException("Invalid image profile response.");
- }
-
- JsonElement imageProfileRoot = JsonParser.parseString(response.getBody());
- JsonObject imageProfileObject = imageProfileRoot.getAsJsonObject();
-
- List imageMappingsOnServer = (
- // If the profile has no image mappings yet, it would not have that property at
- // all, so we're
- // checking if it exists, and if not - defining the variable with a default
- // value
- imageProfileObject.has("imageMappings")
- && imageProfileObject.get("imageMappings").getAsJsonObject().has("mapping"))
- ? (this.getImageMappings(imageProfileObject.get("imageMappings").getAsJsonObject()
- .get("mapping").getAsJsonObject()))
- : new ArrayList<>();
-
- List imageMappingsToImport = new ArrayList<>(imageMappings);
- imageMappingsOnServer.forEach(im -> {
- if (!imageMappingsToImport.contains(im)) {
- imageMappingsToImport.add(im);
- }
- });
-
- return imageMappingsToImport;
- }
-
- // =================================================
- // STORAGE PROFILES OPERATIONS
- // =================================================
-
- /**
- * Retrieve all storage profiles for a given region and group them by region id.
- *
- * @return map with key=region, value=list of VraNgStorageProfile.
- * @see VraNgStorageProfile
- */
- protected Map> getAllStorageProfilesByRegionPrimitive() {
- URI url = getURI(getURIBuilder().setPath(SERVICE_STORAGE_PROFILE));
-
- ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, getDefaultHttpEntity(),
- String.class);
-
- JsonElement root = JsonParser.parseString(response.getBody());
-
- Map> storageProfilesByRegion = new HashMap<>();
-
- if (root.isJsonObject()) {
- root.getAsJsonObject().getAsJsonArray("content").forEach(o -> {
- JsonObject ob = o.getAsJsonObject();
- LOGGER.debug("Obtaining data from getAllStorageProfilesByRegionPrimitive");
- if (!this.jsonObjectValid(ob)) {
- String regionId = this.getLinkRegionId(ob);
- if (!storageProfilesByRegion.containsKey(regionId)) {
- storageProfilesByRegion.put(regionId, new ArrayList<>());
- }
-
- if (ob.has("name")) {
- String name = ob.get("name").getAsString();
- String json = ob.toString();
- storageProfilesByRegion.get(regionId).add(new VraNgStorageProfile(name, json));
- } else {
- LOGGER.warn("Storage Profile has been skipped because don't contains a name definition");
- if (ob.has("id")) {
- LOGGER.warn(String.format("Id of the storage profile: %s", ob.get("id").getAsString()));
- } else {
- LOGGER.warn("Storage Profile don't have a valid id. Unable to track this object.");
- }
- }
- } else {
- LOGGER.info("Obtaining data from getAllStorageProfilesByRegionPrimitive returns empty objects");
- }
- });
- }
-
- return storageProfilesByRegion;
- }
-
- /**
- * Update existing storage profile.
- *
- * @param profileId profile id
- * @param profile storage profile
- * @throws URISyntaxException exception
- */
- protected void updateStorageProfilePrimitive(final String profileId, final VraNgStorageProfile profile)
- throws URISyntaxException {
- URI url = getURI(getURIBuilder().setPath(SERVICE_STORAGE_PROFILE + "/" + profileId));
- this.putJsonPrimitive(url, profile.getJson());
- }
-
- /**
- * Create a new storage profile returning its id.
- *
- * @param profile storage profile
- * @return profile
- * @throws URISyntaxException exception exception
- */
- protected String createStorageProfilePrimitive(final VraNgStorageProfile profile) throws URISyntaxException {
- URI url = getURI(getURIBuilder().setPath(SERVICE_STORAGE_PROFILE));
- ResponseEntity response = this.postJsonPrimitive(url, HttpMethod.POST, profile.getJson());
- JsonElement root = JsonParser.parseString(response.getBody());
- if (root.isJsonObject()) {
- return root.getAsJsonObject().get("id").getAsString();
- }
- return null;
- }
-
- /**
- * Get specific storage profile.
- *
- * @param targetPool target pool of storage profiles
- * @param profileId profile id
- * @return storage profile
- */
- protected VraNgStorageProfile getSpecificProfilePrimitive(final String targetPool, final String profileId) {
- URI url = getURI(getURIBuilder().setPath(SERVICE_IAAS_BASE + "/" + targetPool + "/" + profileId));
- ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, getDefaultHttpEntity(),
- String.class);
-
- JsonElement root = JsonParser.parseString(response.getBody());
- JsonObject ob = root.getAsJsonObject();
-
- String name = ob.get("name").getAsString();
- String json = ob.toString();
- return new VraNgStorageProfile(name, json);
- }
-
/**
* Alias to getAllPropertyGroupsPrimitive( String nameFilter ) without any
* filter specified.
@@ -2230,20 +1677,6 @@ public void updatePropertyGroupPrimitive(final VraNgPropertyGroup propertyGroup)
this.putJsonPrimitive(url, propertyGroup.getRawData());
}
- /**
- * Update specific storage profile.
- *
- * @param patchTarget patch target
- * @param profileId profile id
- * @param profile storage profile
- * @throws URISyntaxException exception
- */
- protected void updateSpecificProfilePrimitive(final String patchTarget, final String profileId,
- final VraNgStorageProfile profile) throws URISyntaxException {
- URI url = getURI(getURIBuilder().setPath(SERVICE_IAAS_BASE + "/" + patchTarget + "/" + profileId));
- this.postJsonPrimitive(url, HttpMethod.PATCH, profile.getJson());
- }
-
/**
* Retrieve fabric entity name. This method calls a requested URL and returns
* the name property of the response.
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/AbstractVraNgRegionalStore.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/AbstractVraNgRegionalStore.java
deleted file mode 100644
index 23be3d7d5..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/AbstractVraNgRegionalStore.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.store.vrang;
-
-import com.vmware.pscoe.iac.artifact.model.Package;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgCloudAccount;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgPackageDescriptor;
-import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * Abstract class that unify the way the content is exported for all sub-classes
- * that are based on regional stores.
- * When no item ([]) is given, nothing is exported
- * When a list of specific items ([item1, itme2]) are given, only the given
- * itmes are exported
- * When nothing (null) is given, all items from the store are exported
- *
- * TODO: should "extends AbstractVraNgDeleteStore", but not doing it now since
- * regional content is being refactored soon (hopefully)
- */
-public abstract class AbstractVraNgRegionalStore {
- /**
- * the restClient.
- */
- protected RestClientVraNg restClient;
- /**
- * the vraNgPackage.
- */
- protected Package vraNgPackage;
- /**
- * the vraNgPackageDescriptor.
- */
- protected VraNgPackageDescriptor vraNgPackageDescriptor;
- /**
- * the logger.
- */
- protected Logger logger;
-
- /**
- * Initialize the class with the required parameters.
- *
- * @param restClient
- * @param vraNgPackage
- * @param vraNgPackageDescriptor
- */
- private void ini(
- RestClientVraNg restClient,
- Package vraNgPackage,
- VraNgPackageDescriptor vraNgPackageDescriptor) {
- this.restClient = restClient;
- this.vraNgPackage = vraNgPackage;
- this.vraNgPackageDescriptor = vraNgPackageDescriptor;
- }
-
- /**
- * Initialize the class with the required parameters.
- *
- * @param restClient
- * @param vraNgPackage
- * @param vraNgPackageDescriptor
- */
- public void init(
- RestClientVraNg restClient,
- Package vraNgPackage,
- VraNgPackageDescriptor vraNgPackageDescriptor) {
- this.ini(restClient, vraNgPackage, vraNgPackageDescriptor);
- this.logger = LoggerFactory.getLogger(this.getClass());
- }
-
- /**
- * Initialize the class with the required parameters.
- *
- * @param restClient
- * @param vraNgPackage
- * @param vraNgPackageDescriptor
- * @param logger
- */
- public void init(
- RestClientVraNg restClient,
- Package vraNgPackage,
- VraNgPackageDescriptor vraNgPackageDescriptor,
- Logger logger) {
- this.ini(restClient, vraNgPackage, vraNgPackageDescriptor);
- this.logger = logger;
- }
-
- /**
- * The main export method. It unifies the way the vRA NG Regional Stores are
- * exported.
- * When no item ([]) is given, nothing is exported
- * When a list of specific items ([item1, itme2]) are given, only the given
- * itmes are exported
- * When nothing (null) is given, all items from the store within the given
- * region are exported
- *
- * In Sub-classes the abstract methods getItemListFromDescriptor,
- * exportStoreContent should be overwritten
- *
- * @param cloudAccounts list of cloud accounts
- */
- public void exportContent(List cloudAccounts) {
- List itemNames = this.getItemListFromDescriptor();
- List cloudAccountNames = cloudAccounts.stream().map(VraNgCloudAccount::getName)
- .collect(Collectors.toList());
-
- logger.info("Currently exporting regional content from: {}", this.getClass().getSimpleName());
-
- if (itemNames == null) {
- logger.info("Nothing/null passed exporting everything from cloud accounts {}", cloudAccountNames);
- this.exportStoreContent(cloudAccounts);
-
- } else if (!itemNames.isEmpty()) {
- logger.info("Items: {}. Exporting items part of cloud accounts {}", itemNames, cloudAccountNames);
- this.exportStoreContent(cloudAccounts, itemNames);
- } else {
- logger.info("Empty array is passed, not exporting anything");
- }
- }
-
- /**
- * Used to fetch the store's data from the package descriptor.
- *
- * @return list of items
- */
- protected abstract List getItemListFromDescriptor();
-
- /**
- * Called when the List returned from getItemListFromDescriptor is empty.
- *
- * @param cloudAccounts list of cloud accounts
- */
- protected abstract void exportStoreContent(List cloudAccounts);
-
- /**
- * Called when the List returned from getItemListFromDescriptor is not empty.
- *
- * @param cloudAccounts list of cloud accounts
- * @param itemNames list of names
- */
- protected abstract void exportStoreContent(List cloudAccounts, List itemNames);
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgDirs.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgDirs.java
index 82fc361d2..6e5b23f23 100644
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgDirs.java
+++ b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgDirs.java
@@ -14,7 +14,6 @@
*/
package com.vmware.pscoe.iac.artifact.store.vrang;
-
public final class VraNgDirs {
/**
* entitlements folder name.
@@ -44,22 +43,6 @@ public final class VraNgDirs {
* subscriptions folder name.
*/
public static final String DIR_SUBSCRIPTIONS = "subscriptions";
- /**
- * regions folder name.
- */
- public static final String DIR_REGIONS = "regions";
- /**
- * flavor-mappings folder name.
- */
- public static final String DIR_FLAVOR_MAPPINGS = "flavor-mappings";
- /**
- * image-mappings folder name.
- */
- public static final String DIR_IMAGE_MAPPINGS = "image-mappings";
- /**
- * storage-profiles folder name.
- */
- public static final String DIR_STORAGE_PROFILES = "storage-profiles";
/**
* resource-actions folder name.
*/
@@ -72,7 +55,9 @@ public final class VraNgDirs {
/**
* Hiding constructor of utility class.
* Linter quote:
- * Utility classes should not have a public or default constructor. [HideUtilityClassConstructor] .
+ * Utility classes should not have a public or default constructor.
+ * [HideUtilityClassConstructor] .
*/
- private VraNgDirs() { };
+ private VraNgDirs() {
+ };
}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgFlavorMappingStore.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgFlavorMappingStore.java
deleted file mode 100644
index 885f95357..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgFlavorMappingStore.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.store.vrang;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonObject;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgCloudAccount;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgFlavorMapping;
-import com.vmware.pscoe.iac.artifact.model.vrang.objectmapping.VraNgCloudRegionProfile;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.FilenameUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import static com.vmware.pscoe.iac.artifact.store.vrang.VraNgDirs.DIR_FLAVOR_MAPPINGS;
-import static com.vmware.pscoe.iac.artifact.store.vrang.VraNgDirs.DIR_REGIONS;
-
-/**
- * Store for flavor mappings.
- */
-public class VraNgFlavorMappingStore extends AbstractVraNgRegionalStore {
-
- /**
- * @param logger
- */
- private final Logger logger = LoggerFactory.getLogger(VraNgFlavorMappingStore.class);
-
- /**
- * Unused as regional mapping needs refactoring.
- */
- public void deleteContent() {
- throw new RuntimeException("Not implemented");
- }
-
- // =================================================
- // FLAVOR MAPPINGS EXPORT
- // =================================================
-
- /**
- * Used to fetch the store's data from the package descriptor.
- *
- * @return list of flavor mappings
- */
- @Override
- protected List getItemListFromDescriptor() {
- return this.vraNgPackageDescriptor.getFlavorMapping();
- }
-
- /**
- * Called when the List returned from getItemListFromDescriptor is empty.
- *
- * @param cloudAccounts list of cloud accounts
- */
- @Override
- protected void exportStoreContent(List cloudAccounts) {
- Map> flavorsByRegionId = this.restClient.getAllFlavorMappingsByRegion();
-
- cloudAccounts.forEach(cloudAccount -> {
- List regionsInCloudAccount = cloudAccount.getRegionIds()
- .stream()
- .filter(flavorsByRegionId::containsKey)
- .collect(Collectors.toList());
-
- logger.debug("Exporting flavor mappings from cloud account {}", cloudAccount.getName());
-
- regionsInCloudAccount.forEach(regionId -> {
-
- String profileDirName = cloudAccount.getName() + "~" + regionId;
-
- File sourceDir = new File(vraNgPackage.getFilesystemPath());
- VraNgRegionalContentUtils.createCloudRegionProfileFile(cloudAccount, regionId, sourceDir,
- profileDirName);
-
- List flavorMappings = new ArrayList<>(flavorsByRegionId.get(regionId));
-
- logger.info("Flavour mappings to export: {}",
- flavorMappings.stream().map(VraNgFlavorMapping::getName).collect(Collectors.toList()));
-
- flavorMappings.forEach(flavorMapping -> this.exportFlavorMappingToFileSystem(sourceDir, profileDirName,
- flavorMapping));
- });
- });
- }
-
- /**
- * Called when the List returned from getItemListFromDescriptor is not empty.
- *
- * @param cloudAccounts list of cloud accounts
- * @param flavorMappingsToExport list of flavor mappings
- */
- @Override
- protected void exportStoreContent(List cloudAccounts, List flavorMappingsToExport) {
- Map> flavorsByRegionId = this.restClient.getAllFlavorMappingsByRegion();
-
- cloudAccounts.forEach(cloudAccount -> {
- List regionsInCloudAccount = cloudAccount.getRegionIds()
- .stream()
- .filter(flavorsByRegionId::containsKey)
- .collect(Collectors.toList());
-
- logger.debug("Exporting flavor mappings from cloud account {}", cloudAccount.getName());
-
- regionsInCloudAccount.forEach(regionId -> {
- String profileDirName = cloudAccount.getName() + "~" + regionId;
-
- File sourceDir = new File(vraNgPackage.getFilesystemPath());
- VraNgRegionalContentUtils.createCloudRegionProfileFile(cloudAccount, regionId, sourceDir,
- profileDirName);
-
- List flavorMappings = flavorsByRegionId.get(regionId)
- .stream()
- .filter(fm -> flavorMappingsToExport.contains(fm.getName()))
- .collect(Collectors.toList());
-
- logger.info("Flavour mappings to export: {}",
- flavorMappings.stream().map(VraNgFlavorMapping::getName).collect(Collectors.toList()));
-
- flavorMappings.forEach(flavorMapping -> this.exportFlavorMappingToFileSystem(sourceDir, profileDirName,
- flavorMapping));
- });
- });
- }
-
- /**
- * Save a flavor mapping to a JSON file.
- *
- * @param sourceDir source directory
- * @param profileDirName region directory
- * @param flavorMapping flavor mapping
- */
- private void exportFlavorMappingToFileSystem(File sourceDir, String profileDirName,
- VraNgFlavorMapping flavorMapping) {
- File flavorMappingFile = Paths.get(sourceDir.getPath(), DIR_REGIONS, profileDirName, DIR_FLAVOR_MAPPINGS,
- flavorMapping.getName() + ".json").toFile();
-
- flavorMappingFile.getParentFile().mkdirs();
-
- try {
- Gson gson = new GsonBuilder().setLenient().setPrettyPrinting().serializeNulls().create();
- String flavorJson = gson.toJson(gson.fromJson(flavorMapping.getJson(), JsonObject.class));
- logger.info("Created file {}", Files.write(Paths.get(flavorMappingFile.getPath()), flavorJson.getBytes(),
- StandardOpenOption.CREATE));
- } catch (IOException e) {
- logger.error("Unable to store flavor mapping {} {}", flavorMapping.getName(), flavorMappingFile.getPath());
- throw new RuntimeException("Unable to store flavor mapping.", e);
- }
- }
-
- // =================================================
- // FLAVOR MAPPINGS IMPORT
- // =================================================
-
- /**
- * Import all flavor profiles from a package.
- *
- * @param sourceDirectory temporary directory containing the files
- * @param importTags list of tags
- */
- public void importContent(File sourceDirectory, List importTags) {
- File regionsFolder = Paths.get(sourceDirectory.getPath(), DIR_REGIONS).toFile();
- if (!regionsFolder.exists()) {
- logger.debug("Regions directory does not exist. Skipping import of flavor profiles...");
- return;
- }
-
- List cloudAccounts = this.restClient.getCloudAccounts();
-
- Map> flavorProfilesByRegion = this.restClient.getAllFlavorProfilesByRegion();
-
- logger.debug("Flavor profiles by region: {}", flavorProfilesByRegion);
-
- // list all directories in the regions folder
- Arrays.asList(regionsFolder.listFiles(File::isDirectory)).forEach(regionProfileDir -> {
- try {
- VraNgCloudRegionProfile cloudRegionProfile = VraNgRegionalContentUtils
- .getCloudRegionProfile(regionProfileDir);
- cloudAccounts
- .stream()
- .filter(cloudAccount -> VraNgRegionalContentUtils.isIntersecting(cloudAccount.getTags(),
- importTags))
- .filter(cloudAccount -> cloudAccount.getType().equals(cloudRegionProfile.getRegionType()))
- .forEach(cloudAccount -> cloudAccount.getRegionIds()
- .forEach(regionId -> this.importFlavorProfilesInRegion(
- regionId,
- regionProfileDir,
- flavorProfilesByRegion)));
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
- }
-
- /**
- * Create a list of flavor mappings from JSON file representation.
- *
- * @param flavorMappingsDir directory containing the flavor mappings for the
- * region
- * @return list of flavor mappings
- */
- private List getFlavorMappingsFromFileSystem(File flavorMappingsDir) {
- List flavorMappings = new ArrayList<>();
- FileUtils.listFiles(flavorMappingsDir, new String[] { "json" }, false).forEach(fm -> {
- try {
- File fmFile = (File) fm;
- String flavorMappingName = FilenameUtils.removeExtension(fmFile.getName());
- String flavorMappingContent = FileUtils.readFileToString(fmFile, "UTF-8");
- flavorMappings.add(new VraNgFlavorMapping(flavorMappingName, flavorMappingContent));
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
-
- return flavorMappings;
- }
-
- /**
- * Import flavor mappings in a cloud region (cloud zone). If a flavor profile
- * already exists,
- * update it with a new mapping, otherwise create a flavor profile with a single
- * mapping inside.
- *
- * @param regionId region id
- * @param regionProfileDir region directory
- * @param flavorProfilesByRegion list of existing flavor profiles on server
- */
- private void importFlavorProfilesInRegion(
- String regionId, File regionProfileDir, Map> flavorProfilesByRegion) {
-
- File flavorMappingsDir = Paths.get(regionProfileDir.getPath(), DIR_FLAVOR_MAPPINGS).toFile();
- if (!flavorMappingsDir.exists()) {
- logger.debug("Flavor mappings directory {} does not exist in region {}. Skipping...", DIR_FLAVOR_MAPPINGS,
- regionId);
- return;
- }
- List flavorMappings = this.getFlavorMappingsFromFileSystem(flavorMappingsDir);
-
- logger.info("Creating/updating {} flavor mappings: {}",
- flavorMappings.size(),
- flavorMappings.stream().map(VraNgFlavorMapping::getName).collect(Collectors.toList()));
-
- if (flavorProfilesByRegion.containsKey(regionId)) {
- this.updateFlavorProfilesWithMappings(flavorProfilesByRegion.get(regionId), flavorMappings);
- } else {
- this.createFlavorProfilesWithMappings(regionId, flavorMappings);
- }
- }
-
- private void updateFlavorProfilesWithMappings(
- List flavorProfilesToPatch, List flavorMappings) {
-
- flavorProfilesToPatch.forEach(flavorProfileId -> {
- this.restClient.updateFlavor(flavorProfileId, flavorMappings);
- });
- }
-
- private void createFlavorProfilesWithMappings(String regionId, List flavorMappings) {
- this.restClient.createFlavor(regionId, "Auto Generated Profile from Import", flavorMappings);
- }
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgImageMappingStore.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgImageMappingStore.java
deleted file mode 100644
index ead768a40..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgImageMappingStore.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.store.vrang;
-
-import com.google.gson.*;
-import com.vmware.pscoe.iac.artifact.model.vrang.*;
-import com.vmware.pscoe.iac.artifact.model.vrang.objectmapping.VraNgCloudRegionProfile;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.FilenameUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.*;
-import java.util.stream.Collectors;
-
-import static com.vmware.pscoe.iac.artifact.store.vrang.VraNgDirs.DIR_IMAGE_MAPPINGS;
-import static com.vmware.pscoe.iac.artifact.store.vrang.VraNgDirs.DIR_REGIONS;
-
-/**
- * Store for image mappings in vRA NG.
- */
-public class VraNgImageMappingStore extends AbstractVraNgRegionalStore {
-
- /**
- * @param logger
- */
- private final Logger logger = LoggerFactory.getLogger(VraNgImageMappingStore.class);
-
- /**
- * Unused as regional content needs refactoring.
- */
- public void deleteContent() {
- throw new RuntimeException("Not implemented");
- }
-
- // =================================================
- // IMAGE MAPPINGS EXPORT
- // =================================================
-
- /**
- * Used to fetch the store's data from the package descriptor.
- *
- * @return list of image mappings
- */
- @Override
- protected List getItemListFromDescriptor() {
- return this.vraNgPackageDescriptor.getImageMapping();
- }
-
- /**
- * Called when the List returned from getItemListFromDescriptor is empty.
- *
- * @param cloudAccounts list of cloud accounts
- */
- @Override
- protected void exportStoreContent(List cloudAccounts) {
- Map> imagesByRegionId = this.restClient.getAllImageMappingsByRegion();
-
- cloudAccounts.forEach(cloudAccount -> {
-
- List regionsInCloudAccount = cloudAccount.getRegionIds()
- .stream()
- .filter(imagesByRegionId::containsKey)
- .collect(Collectors.toList());
-
- logger.debug("Exporting image mappings from cloud account {}", cloudAccount.getName());
-
- regionsInCloudAccount.forEach(regionId -> {
-
- String profileDirName = cloudAccount.getName() + "~" + regionId;
-
- File sourceDir = new File(vraNgPackage.getFilesystemPath());
- VraNgRegionalContentUtils.createCloudRegionProfileFile(cloudAccount, regionId, sourceDir,
- profileDirName);
-
- List imageMappings = imagesByRegionId.get(regionId)
- .stream()
- .map(this::prepareMappingSerialization)
- .collect(Collectors.toList());
-
- logger.info("Image mappings to export: {}",
- imageMappings.stream().map(VraNgImageMapping::getName).collect(Collectors.toList()));
-
- imageMappings.forEach(imageMapping -> this.exportToFileSystem(sourceDir, profileDirName, imageMapping));
- });
- });
- }
-
- /**
- * Called when the List returned from getItemListFromDescriptor is not empty.
- *
- * @param cloudAccounts list of cloud accounts
- * @param imageMappingsToExport list of image mappings
- */
- @Override
- protected void exportStoreContent(List cloudAccounts, List imageMappingsToExport) {
- Map> imagesByRegionId = this.restClient.getAllImageMappingsByRegion();
-
- cloudAccounts.forEach(cloudAccount -> {
-
- List regionsInCloudAccount = cloudAccount.getRegionIds()
- .stream()
- .filter(imagesByRegionId::containsKey)
- .collect(Collectors.toList());
-
- logger.debug("Exporting image mappings from cloud account {}", cloudAccount.getName());
-
- regionsInCloudAccount.forEach(regionId -> {
-
- String profileDirName = cloudAccount.getName() + "~" + regionId;
-
- File sourceDir = new File(vraNgPackage.getFilesystemPath());
- VraNgRegionalContentUtils.createCloudRegionProfileFile(cloudAccount, regionId, sourceDir,
- profileDirName);
-
- List imageMappings = imagesByRegionId.get(regionId)
- .stream()
- .filter(im -> imageMappingsToExport.contains(im.getName()))
- .map(this::prepareMappingSerialization)
- .collect(Collectors.toList());
-
- logger.info("Image mappings to export: {}",
- imageMappings.stream().map(VraNgImageMapping::getName).collect(Collectors.toList()));
-
- imageMappings.forEach(imageMapping -> this.exportToFileSystem(sourceDir, profileDirName, imageMapping));
- });
- });
- }
-
- /**
- * Save an image mapping to a JSON file.
- *
- * @param sourceDir source directory
- * @param profileDirName region directory
- * @param imageMapping image mapping
- */
- private void exportToFileSystem(File sourceDir, String profileDirName, VraNgImageMapping imageMapping) {
- File imageMappingFile = Paths.get(sourceDir.getPath(), DIR_REGIONS, profileDirName, DIR_IMAGE_MAPPINGS,
- imageMapping.getName() + ".json").toFile();
-
- imageMappingFile.getParentFile().mkdirs();
-
- try {
- Gson gson = new GsonBuilder().setLenient().setPrettyPrinting().serializeNulls().create();
- String imageJson = gson.toJson(gson.fromJson(imageMapping.getJson(), JsonObject.class));
- logger.info("Created file {}", Files.write(Paths.get(imageMappingFile.getPath()), imageJson.getBytes(),
- StandardOpenOption.CREATE));
- } catch (IOException e) {
- logger.error("Unable to store image mapping {} {}", imageMapping.getName(), imageMappingFile.getPath());
- throw new RuntimeException("Unable to store image mapping.", e);
- }
- }
-
- /**
- * Create a new VraNgImageMapping with serializable payload.
- *
- * @param mapping image mapping
- * @return new VraNgStorageProfile
- */
- private VraNgImageMapping prepareMappingSerialization(VraNgImageMapping mapping) {
-
- JsonElement root = new JsonParser().parse(mapping.getJson());
- JsonObject ob = root.getAsJsonObject();
-
- JsonObject cleanedOb = VraNgRegionalContentUtils.cleanJson(ob, null, Arrays.asList(
- "_links", "id", "externalRegionId"));
-
- return new VraNgImageMapping(mapping.getName(), cleanedOb.toString());
-
- }
-
- // =================================================
- // IMAGE MAPPINGS IMPORT
- // =================================================
-
- /**
- * Import all image profiles from a package.
- *
- * @param sourceDirectory temporary directory containing the files
- * @param importTags list of tags
- */
- public void importContent(File sourceDirectory, List importTags) {
- File regionsFolder = Paths.get(sourceDirectory.getPath(), DIR_REGIONS).toFile();
- if (!regionsFolder.exists()) {
- logger.debug("Regions directory does not exist. Skipping import of image profiles...");
- return;
- }
-
- List cloudAccounts = this.restClient.getCloudAccounts();
-
- Map> imageProfilesByRegion = this.restClient.getAllImageProfilesByRegion();
-
- logger.debug("Image profiles by region: {}", imageProfilesByRegion);
-
- // list all directories in the regions folder
- Arrays.asList(regionsFolder.listFiles(File::isDirectory)).forEach(regionProfileDir -> {
- try {
- VraNgCloudRegionProfile cloudRegionProfile = VraNgRegionalContentUtils
- .getCloudRegionProfile(regionProfileDir);
- cloudAccounts
- .stream()
- .filter(cloudAccount -> VraNgRegionalContentUtils.isIntersecting(cloudAccount.getTags(),
- importTags))
- .filter(cloudAccount -> cloudAccount.getType().equals(cloudRegionProfile.getRegionType()))
- .forEach(cloudAccount -> cloudAccount.getRegionIds()
- .forEach(regionId -> this.importImageProfilesInRegion(
- regionId,
- regionProfileDir,
- imageProfilesByRegion)));
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
- }
-
- /**
- * Create a list of image mappings from JSON file representation.
- *
- * @param imageMappingsDir directory containing the image mappings for the
- * region
- * @return list of image mappings
- */
- private List getImageMappingsFromFileSystem(File imageMappingsDir) {
- List imageMappings = new ArrayList<>();
- FileUtils.listFiles(imageMappingsDir, new String[] { "json" }, false).forEach(im -> {
- try {
- File imFile = (File) im;
- String imageMappingName = FilenameUtils.removeExtension(imFile.getName());
- String imageMappingContent = FileUtils.readFileToString(imFile, "UTF-8");
- imageMappings.add(new VraNgImageMapping(imageMappingName, imageMappingContent));
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
-
- return imageMappings;
- }
-
- /**
- * Import image mappings in a cloud region (cloud zone). If an image profile
- * already exists,
- * update it with a new mapping, otherwise create an image profile with a single
- * mapping inside.
- *
- * @param regionId region id
- * @param regionProfileDir region directory
- * @param imageProfilesByRegion list of existing image profiles on server
- */
- private void importImageProfilesInRegion(
- String regionId, File regionProfileDir, Map> imageProfilesByRegion) {
-
- File imageMappingsDir = Paths.get(regionProfileDir.getPath(), DIR_IMAGE_MAPPINGS).toFile();
- if (!imageMappingsDir.exists()) {
- logger.debug("Image mappings directory {} does not exist in region {}. Skipping...", DIR_IMAGE_MAPPINGS,
- regionId);
- return;
- }
- List imageMappings = this.getImageMappingsFromFileSystem(imageMappingsDir);
-
- logger.info("Creating/updating {} image mappings: {}",
- imageMappings.size(),
- imageMappings.stream().map(VraNgImageMapping::getName).collect(Collectors.toList()));
-
- if (imageProfilesByRegion.containsKey(regionId)) {
- this.updateImageProfilesWithMappings(imageProfilesByRegion.get(regionId), imageMappings);
- } else {
- this.createImageProfilesWithMappings(regionId, imageMappings);
- }
- }
-
- private void updateImageProfilesWithMappings(
- List imageProfilesToPatch, List imageMappings) {
-
- List mappingList = imageMappings.stream()
- .map(this::getUpsertPayload)
- .collect(Collectors.toList());
-
- imageProfilesToPatch.forEach(imageProfileId -> {
- this.restClient.updateImageProfile(imageProfileId, mappingList);
- });
- }
-
- private void createImageProfilesWithMappings(String regionId, List imageMappings) {
- List mappingList = imageMappings.stream()
- .map(this::getUpsertPayload)
- .collect(Collectors.toList());
-
- this.restClient.createImageProfile(regionId, "Auto Generated Profile from Import", mappingList);
- }
-
- /**
- * Create API-compliant JSON payload from local image mapping
- * for creating/updating image profiles.
- *
- * @param mapping local image mapping
- * @return image mapping with updated payload
- */
- private VraNgImageMapping getUpsertPayload(VraNgImageMapping mapping) {
- JsonElement root = new JsonParser().parse(mapping.getJson());
- JsonObject ob = root.getAsJsonObject();
-
- String fabricId = this.restClient.getFabricEntityId("fabric-images", ob.get("name").getAsString());
- if (fabricId != null) {
-
- // add fabric entity id
- ob.addProperty("id", fabricId);
- Map payload = new HashMap<>();
- payload.put("id", fabricId);
-
- Gson gson = new GsonBuilder().setLenient().serializeNulls().create();
- return new VraNgImageMapping(mapping.getName(), gson.toJson(payload));
- }
-
- return mapping;
- }
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgRegionalContentStore.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgRegionalContentStore.java
deleted file mode 100644
index 0c831f89a..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgRegionalContentStore.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.store.vrang;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import com.vmware.pscoe.iac.artifact.model.vrang.Identifiable;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgCloudAccount;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgRegionMapping;
-
-import org.yaml.snakeyaml.Yaml;
-
-/**
- * This class is responsible for managing the regional content in vRA NG.
- */
-public class VraNgRegionalContentStore extends AbstractVraNgStore {
-
- /**
- * Need refactoring, intentionally left empty.
- */
- public void deleteContent() {
- }
-
- /**
- * Unused, it's for `deleteContent` method.
- */
- @Override
- protected List getAllServerContents() {
- return null;
- }
-
- /**
- * Unused, it's for `deleteContent` method.
- *
- * @param resId the id of the resource to delete
- */
- @Override
- protected void deleteResourceById(String resId) {
- }
-
- /**
- * Import region-specific content based on region mapping defined in the
- * package.
- *
- * @param sourceDirectory temporary directory containing the files
- */
- @Override
- public void importContent(File sourceDirectory) {
- importRegionalContent(sourceDirectory);
- }
-
- /**
- * The regionalContent exports all flavor mapping, image mapping and storage
- * profile in partucular region.
- */
- @Override
- public void exportContent() {
- VraNgRegionMapping regionMapping = vraNgPackageDescriptor.getRegionMapping();
- if (regionMapping != null) {
- exportRegionalContent(regionMapping);
- } else {
- logger.info("No region mapping found in content.yaml");
- }
- }
-
- /**
- * Unused because the class overwrites directly exportContent.
- */
- @Override
- protected List getItemListFromDescriptor() {
- return null;
- }
-
- /**
- * Unused because the class overwrites directly exportContent.
- */
- @Override
- protected void exportStoreContent() {
- }
-
- /**
- * Unused because the class overwrites directly exportContent.
- *
- * @param itemNames the list of items to export
- */
- @Override
- protected void exportStoreContent(List itemNames) {
-
- }
-
- /**
- * Export region-specific content based on region mappings defined in the
- * package manifest. This includes: * flavor mappings * image mappings * storage
- * profiles.
- *
- * @param regionMapping region mapping structure describing the regions
- * (cloud zones) that have related exportable
- * content defined in the package manifest.
- */
- private void exportRegionalContent(VraNgRegionMapping regionMapping) {
-
- // determine from which cloud account to export the content (based on the export
- // tag)
- String exportTag = regionMapping.getCloudAccountTags().getExportTag();
- List cloudAccounts = this.restClient
- .getCloudAccounts().stream().filter(cloudAccount -> VraNgRegionalContentUtils
- .isIntersecting(cloudAccount.getTags(), new ArrayList(Arrays.asList(exportTag))))
- .collect(Collectors.toList());
-
- logger.info(
- "Found {} cloud accounts from which to export regional content (image mappings, flavor mappings, storage profiles) based on tag {}",
- cloudAccounts.size(), exportTag);
-
- // no need to export regional content when no exportable cloud accounts are
- // found
- if (cloudAccounts.isEmpty()) {
- logger.info(
- "No cloud accounts found based on export tag {}. Skipping export of regional content (image mappings, flavor mappings, storage profiles)",
- exportTag);
- return;
- }
-
- // export flavor mappings
- VraNgFlavorMappingStore flavorMappingStore = new VraNgFlavorMappingStore();
- flavorMappingStore.init(restClient, vraNgPackage, vraNgPackageDescriptor);
- flavorMappingStore.exportContent(cloudAccounts);
-
- // export image mappings
- VraNgImageMappingStore imageMappingStore = new VraNgImageMappingStore();
- imageMappingStore.init(restClient, vraNgPackage, vraNgPackageDescriptor);
- imageMappingStore.exportContent(cloudAccounts);
-
- // export storage profiles
- VraNgStorageProfileStore storageProfileStore = new VraNgStorageProfileStore();
- storageProfileStore.init(restClient, vraNgPackage, vraNgPackageDescriptor);
- storageProfileStore.exportContent(cloudAccounts);
- }
-
- /**
- * Import region-specific content based on region mapping defined in the package
- * manifest. The manifest (content.yaml) is part of the vra-ng package and read
- * on the fly.
- *
- * @param sourceDirectory temporary directory containing the files
- */
- private void importRegionalContent(File sourceDirectory) {
-
- try {
-
- // read content.yaml
- Yaml yaml = new Yaml();
- File content = Paths.get(sourceDirectory.getPath() + File.separator + "content.yaml").toFile();
- Map yamlContent = yaml.load(new FileInputStream(content));
-
- // get region mapping
- if (!yamlContent.containsKey("region-mapping") || yamlContent.get("region-mapping") == null) {
- logger.info(
- "content.yaml does not contain 'region-mapping' entry. Skipping import of regional content...");
- return;
- }
- Map regionMapping = (Map) yamlContent.get("region-mapping");
- logger.debug("Region mapping: {}", regionMapping);
-
- // get cloud-account-tags
- if (!regionMapping.containsKey("cloud-account-tags") || regionMapping.get("cloud-account-tags") == null) {
- logger.warn("region-mapping entry does not contain 'cloud-account-tags");
- return;
- }
- Map cloudAccountTags = (Map) regionMapping.get("cloud-account-tags");
-
- // get import tags
- if (!cloudAccountTags.containsKey("import-tags") || cloudAccountTags.get("import-tags") == null) {
- logger.warn("cloud-account-tags entry does not contain 'import-tags");
- return;
- }
- List importTags = (ArrayList) cloudAccountTags.get("import-tags");
-
- // flavor mappings
- VraNgFlavorMappingStore flavorMappingStore = new VraNgFlavorMappingStore();
- flavorMappingStore.init(restClient, vraNgPackage, vraNgPackageDescriptor);
- flavorMappingStore.importContent(sourceDirectory, importTags);
-
- // image mappings
- VraNgImageMappingStore imageMappingStore = new VraNgImageMappingStore();
- imageMappingStore.init(restClient, vraNgPackage, vraNgPackageDescriptor);
- imageMappingStore.importContent(sourceDirectory, importTags);
-
- // storage profiles
- VraNgStorageProfileStore storageProfileStore = new VraNgStorageProfileStore();
- storageProfileStore.init(restClient, vraNgPackage, vraNgPackageDescriptor);
- storageProfileStore.importContent(sourceDirectory, importTags);
-
- } catch (FileNotFoundException e) {
- logger.info("content.yaml is not part of the package. Skipping import of regional content...");
- }
- }
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgRegionalContentUtils.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgRegionalContentUtils.java
deleted file mode 100644
index 6f4b94f8b..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgRegionalContentUtils.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.store.vrang;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgCloudAccount;
-import com.vmware.pscoe.iac.artifact.model.vrang.objectmapping.VraNgCloudRegionProfile;
-import org.apache.commons.io.FileUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static com.vmware.pscoe.iac.artifact.store.vrang.VraNgDirs.*;
-
-/**
- * Utility class for regional content management.
- */
-public final class VraNgRegionalContentUtils {
- /**
- * Private constructor to prevent instantiation as this is a utility class.
- */
- private VraNgRegionalContentUtils() {
- }
-
- /**
- * @param logger
- */
- private static Logger logger = LoggerFactory.getLogger(VraNgRegionalContentUtils.class);
-
- /**
- * Create the cloud region profile file containing mapping for region tags and
- * region id.
- *
- * @param cloudAccount cloud account
- * @param regionId region id
- * @param srcDir containing directory
- * @param cloudRegionProfileFolderName folder name for the region with
- * region-specific content
- */
- public static void createCloudRegionProfileFile(VraNgCloudAccount cloudAccount, String regionId, File srcDir,
- String cloudRegionProfileFolderName) {
- File cloudRegionProfile = Paths
- .get(srcDir.getPath(), DIR_REGIONS, cloudRegionProfileFolderName, "src-region-profile.json").toFile();
-
- cloudRegionProfile.getParentFile().mkdirs();
-
- Gson gson = new GsonBuilder().setLenient().setPrettyPrinting().serializeNulls().create();
-
- VraNgCloudRegionProfile cloudRegionProfileJson = new VraNgCloudRegionProfile();
- cloudRegionProfileJson.setCloudAccountId(cloudAccount.getId());
- cloudRegionProfileJson.setRegionId(regionId);
- cloudRegionProfileJson.setTags(cloudAccount.getTags());
- cloudRegionProfileJson.setRegionType(cloudAccount.getType());
-
- String regionJson = gson.toJson(cloudRegionProfileJson, VraNgCloudRegionProfile.class);
-
- try {
- logger.info("Created file {} ", Files.write(Paths.get(cloudRegionProfile.getPath()),
- regionJson.getBytes(), StandardOpenOption.CREATE));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Check whether two lists of strings are intersecting, i.e. have
- * at least one common element.
- *
- * @param list1 first list
- * @param list2 second list
- * @return true if lists are intersecting
- */
- public static boolean isIntersecting(List list1, List list2) {
- Set set1 = new HashSet(list1);
- Set set2 = new HashSet(list2);
-
- Set intersection = new HashSet<>(set1);
- intersection.retainAll(set2);
-
- return !intersection.isEmpty();
- }
-
- /**
- * Get cloud region profile from the directory.
- *
- * @param cloudRegionProfileDir directory containing the cloud region profile
- * @return cloud region profile
- * @throws IOException if the file cannot be read
- */
- public static VraNgCloudRegionProfile getCloudRegionProfile(File cloudRegionProfileDir) throws IOException {
- File regionProfile = Paths.get(cloudRegionProfileDir.getPath(), "src-region-profile.json").toFile();
- String regionProfileContent = FileUtils.readFileToString(regionProfile, "UTF-8");
-
- return new ObjectMapper().readValue(regionProfileContent, VraNgCloudRegionProfile.class);
- }
-
- /**
- * Create a new JSON object containing only set of keys.
- *
- * @param ob original JSON object
- * @param keysToKeep list of keys to keep
- * @param keysToRemove list of keys to remove
- * @return cleaned JSON object
- */
- public static JsonObject cleanJson(JsonObject ob, List keysToKeep, List keysToRemove) {
- JsonObject cleanedOb = new JsonObject();
- if (keysToKeep != null) {
- keysToKeep.forEach(key -> {
- if (ob.has(key)) {
- cleanedOb.add(key, ob.get(key));
- }
- });
- }
- if (keysToRemove != null) {
- for (Map.Entry entry : ob.entrySet()) {
- if (!keysToRemove.contains(entry.getKey())) {
- cleanedOb.add(entry.getKey(), entry.getValue());
- }
- }
- }
- return cleanedOb;
- }
-
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgStorageProfileStore.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgStorageProfileStore.java
deleted file mode 100644
index e073c8942..000000000
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgStorageProfileStore.java
+++ /dev/null
@@ -1,565 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.store.vrang;
-
-import com.google.gson.*;
-import com.vmware.pscoe.iac.artifact.model.vrang.*;
-import com.vmware.pscoe.iac.artifact.model.vrang.objectmapping.VraNgCloudRegionProfile;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.FilenameUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.nio.file.StandardOpenOption;
-import java.util.*;
-import java.util.stream.Collectors;
-
-import static com.vmware.pscoe.iac.artifact.store.vrang.VraNgDirs.DIR_STORAGE_PROFILES;
-import static com.vmware.pscoe.iac.artifact.store.vrang.VraNgDirs.DIR_REGIONS;
-
-/**
- * Storage profile store.
- */
-public class VraNgStorageProfileStore extends AbstractVraNgRegionalStore {
-
- /**
- * Index representing the position of the fabric in the storage profile.
- */
- private final int FABRIC_INDEX = 3;
-
- /**
- * @param logger
- */
- private final Logger logger = LoggerFactory.getLogger(VraNgStorageProfileStore.class);
-
- // =================================================
- // STORAGE PROFILES EXPORT
- // =================================================
-
- /**
- * Used to fetch the store's data from the package descriptor.
- *
- * @return list of storage profiles
- */
- @Override
- protected List getItemListFromDescriptor() {
- return this.vraNgPackageDescriptor.getStorageProfile();
- }
-
- /**
- * Called when the List returned from getItemListFromDescriptor is empty.
- *
- * @param cloudAccounts list of cloud accounts
- */
- @Override
- protected void exportStoreContent(List cloudAccounts) {
- Map> storageProfilesByRegionId = this.restClient
- .getAllStorageProfilesByRegion();
-
- cloudAccounts.forEach(cloudAccount -> {
- List regionsInCloudAccount = cloudAccount.getRegionIds()
- .stream()
- .filter(storageProfilesByRegionId::containsKey)
- .collect(Collectors.toList());
-
- logger.debug("Exporting storage profiles from cloud account {}", cloudAccount.getName());
-
- regionsInCloudAccount.forEach(regionId -> {
- // create region directory
- String profileDirName = cloudAccount.getName() + "~" + regionId;
- File sourceDir = new File(vraNgPackage.getFilesystemPath());
-
- VraNgRegionalContentUtils.createCloudRegionProfileFile(cloudAccount, regionId, sourceDir,
- profileDirName);
-
- List storageProfiles = storageProfilesByRegionId.get(regionId)
- .stream()
- .map(profile -> convertToSpecificProfile(profile, cloudAccount))
- .collect(Collectors.toList());
-
- logger.info("Storage profiles to export: {}",
- storageProfiles.stream().map(VraNgStorageProfile::getName).collect(Collectors.toList()));
-
- storageProfiles.forEach(sp -> this.exportToFileSystem(sourceDir, profileDirName, sp));
- });
- });
- }
-
- /**
- * Called when the List returned from getItemListFromDescriptor is not empty.
- *
- * @param cloudAccounts list of cloud accounts
- * @param storageProfilesToExport list of storage profiles
- */
- @Override
- protected void exportStoreContent(List cloudAccounts, List storageProfilesToExport) {
- Map> storageProfilesByRegionId = this.restClient
- .getAllStorageProfilesByRegion();
-
- cloudAccounts.forEach(cloudAccount -> {
- List regionsInCloudAccount = cloudAccount.getRegionIds()
- .stream()
- .filter(storageProfilesByRegionId::containsKey)
- .collect(Collectors.toList());
-
- logger.debug("Exporting storage profiles from cloud account {}", cloudAccount.getName());
-
- regionsInCloudAccount.forEach(regionId -> {
- // create region directory
- String profileDirName = cloudAccount.getName() + "~" + regionId;
- File sourceDir = new File(vraNgPackage.getFilesystemPath());
- VraNgRegionalContentUtils.createCloudRegionProfileFile(cloudAccount, regionId, sourceDir,
- profileDirName);
-
- List storageProfiles = storageProfilesByRegionId.get(regionId)
- .stream()
- .filter(sp -> storageProfilesToExport.contains(sp.getName()))
- .map(profile -> convertToSpecificProfile(profile, cloudAccount))
- .collect(Collectors.toList());
-
- logger.info("Storage profiles to export: {}",
- storageProfiles.stream().map(VraNgStorageProfile::getName).collect(Collectors.toList()));
-
- storageProfiles.forEach(sp -> this.exportToFileSystem(sourceDir, profileDirName, sp));
- });
- });
- }
-
- /**
- * Enum representing different types of storage profiles.
- */
- enum ProfileType {
- /**
- * VSPHERE profile type.
- */
- VSPHERE,
- /**
- * Azure profile type.
- */
- AZURE,
- /**
- * AWS profile type.
- */
- AWS,
- /**
- * Unknown profile type.
- */
- UNKNOWN
- }
-
- /**
- *
- * Save an storage profile to a JSON file.
- *
- * @param sourceDir source directory
- * @param profileDirName region directory
- * @param storageProfile storage profile
- */
- private void exportToFileSystem(File sourceDir, String profileDirName, VraNgStorageProfile storageProfile) {
- File storageProfileFile = Paths.get(sourceDir.getPath(), DIR_REGIONS, profileDirName, DIR_STORAGE_PROFILES,
- storageProfile.getName() + ".json").toFile();
-
- storageProfileFile.getParentFile().mkdirs();
-
- try {
- Gson gson = new GsonBuilder().setLenient().setPrettyPrinting().serializeNulls().create();
- String profileJson = gson.toJson(gson.fromJson(storageProfile.getJson(), JsonObject.class));
- logger.info("Created file {}", Files.write(Paths.get(storageProfileFile.getPath()), profileJson.getBytes(),
- StandardOpenOption.CREATE));
- } catch (IOException e) {
- logger.error("Unable to store storage profile {} {}", storageProfile.getName(),
- storageProfileFile.getPath());
- throw new RuntimeException("Unable to store storage profile.", e);
- }
- };
-
- /**
- * Convert an abstract storage profile to specific storage profile.
- * A specific storage profile is a cloud account-specific profile
- * representation.
- *
- * @param profile storage profile
- * @param cloudAccount cloud account
- * @return storage profile
- */
- private VraNgStorageProfile convertToSpecificProfile(VraNgStorageProfile profile, VraNgCloudAccount cloudAccount) {
-
- // get specific profile
- JsonElement root = new JsonParser().parse(profile.getJson());
- JsonObject ob = root.getAsJsonObject();
- String profileId = ob.get("id").getAsString();
- VraNgStorageProfile specificProfile = this.restClient.getSpecificStorageProfile(
- String.format("storage-profiles-%s", cloudAccount.getType()), profileId);
-
- // create cleaned-up specific profile
- JsonElement cleanRoot = new JsonParser().parse(specificProfile.getJson());
- JsonObject cleanOb = cleanRoot.getAsJsonObject();
- Gson gson = new GsonBuilder().setLenient().serializeNulls().create();
-
- // Check if the disk has diskProperties
- JsonObject diskProperties = ob.has("diskProperties") ? ob.get("diskProperties").getAsJsonObject() : null;
-
- ProfileType profileType = getProfileType(cloudAccount);
- // First check if the disk is a First Class Disk and based on that omit writing
- // diskMode, so we can execute create/patch commands
- switch (profileType) {
- case VSPHERE:
- if (diskProperties != null && diskProperties.has("diskType") && diskProperties != null
- && diskProperties.get("diskType").getAsString().equals("firstClass")) {
- cleanOb = VraNgRegionalContentUtils.cleanJson(cleanOb, Arrays.asList(
- "supportsEncryption", "sharesLevel", "description", "tags",
- "shares", "provisioningType", "diskType", "limitIops", "name", "defaultItem"), null);
- } else {
- cleanOb = VraNgRegionalContentUtils.cleanJson(cleanOb, Arrays.asList(
- "supportsEncryption", "sharesLevel", "description", "diskMode", "tags",
- "shares", "provisioningType", "diskType", "limitIops", "name", "defaultItem"), null);
- }
-
- // create datastore fabric link
- if (ob.has("_links") && ob.get("_links").getAsJsonObject().has("datastore")) {
- Map datastore = new LinkedHashMap<>();
- String datastoreHref = ob.get("_links").getAsJsonObject()
- .get("datastore").getAsJsonObject()
- .get("href").getAsString();
- String datastoreName = this.restClient.getFabricEntityName(datastoreHref);
- datastore.put("name", datastoreName);
- datastore.put("fabric", datastoreHref.split("/")[FABRIC_INDEX]);
- cleanOb.add("_datastore", gson.toJsonTree(datastore));
- }
-
- // create storagePolicy fabric link
- if (ob.has("_links") && ob.get("_links").getAsJsonObject().has("storage-policy")) {
- Map storagePolicy = new LinkedHashMap<>();
- String storagePolicyHref = ob.get("_links").getAsJsonObject()
- .get("storage-policy").getAsJsonObject()
- .get("href").getAsString();
- String storagePolicyName = this.restClient.getFabricEntityName(storagePolicyHref);
- storagePolicy.put("name", storagePolicyName);
- storagePolicy.put("fabric", storagePolicyHref.split("/")[FABRIC_INDEX]);
- cleanOb.add("_storagePolicy", gson.toJsonTree(storagePolicy));
- }
- break;
-
- // intentional fallthrough
- case AWS:
- case AZURE:
- case UNKNOWN:
- default:
- logger.warn("Unsupported storage profile type '{}'", profileType);
- break;
- }
-
- cleanOb.addProperty("_type", cloudAccount.getType());
-
- return new VraNgStorageProfile(profile.getName(), cleanOb.toString());
- }
-
- // =================================================
- // STORAGE PROFILES IMPORT
- // =================================================
-
- /**
- * Import all storage profiles from a package.
- *
- * @param sourceDirectory temporary directory containing the files
- * @param importTags list of tags
- */
- public void importContent(File sourceDirectory, List importTags) {
- File regionsFolder = Paths.get(sourceDirectory.getPath(), DIR_REGIONS).toFile();
- if (!regionsFolder.exists()) {
- logger.debug("Regions directory does not exist. Skipping import of storage profiles...");
- return;
- }
-
- List cloudAccounts = this.restClient.getCloudAccounts();
-
- Map> storageProfilesByRegion = this.restClient
- .getAllStorageProfilesByRegion();
-
- // list all directories in the regions folder
- Arrays.asList(regionsFolder.listFiles(File::isDirectory)).forEach(regionProfileDir -> {
- try {
- VraNgCloudRegionProfile cloudRegionProfile = VraNgRegionalContentUtils
- .getCloudRegionProfile(regionProfileDir);
- cloudAccounts
- .stream()
- .filter(cloudAccount -> VraNgRegionalContentUtils.isIntersecting(cloudAccount.getTags(),
- importTags))
- .filter(cloudAccount -> cloudAccount.getType().equals(cloudRegionProfile.getRegionType()))
- .forEach(cloudAccount -> cloudAccount.getRegionIds()
- .forEach(regionId -> this.importInRegion(
- regionId,
- regionProfileDir,
- storageProfilesByRegion)));
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
-
- }
-
- /**
- * Import storage profiles in a cloud region (cloud zone).
- *
- * @param regionId region id
- * @param regionProfileDir region directory
- * @param remoteProfiles list of existing storage profiles on server grouped
- * by region
- */
- private void importInRegion(String regionId, File regionProfileDir,
- Map> remoteProfiles) {
-
- File storageProfilesDir = Paths.get(regionProfileDir.getPath(), DIR_STORAGE_PROFILES).toFile();
- if (!storageProfilesDir.exists()) {
- logger.debug("Storage profiles directory {} does not exist in region {}. Skipping...", DIR_STORAGE_PROFILES,
- regionId);
- return;
- }
-
- // collect local profiles
- List localProfiles = this.getStorageProfilesFromFileSystem(storageProfilesDir);
-
- // collect remote profiles if there are profiles in the region
- Map regionProfiles;
- if (remoteProfiles.containsKey(regionId)) {
- regionProfiles = remoteProfiles.get(regionId).stream()
- .collect(Collectors.toMap(VraNgStorageProfile::getName, profile -> profile));
- } else {
- regionProfiles = new HashMap<>();
- }
-
- logger.info("Creating/updating {} storage profiles: {}",
- localProfiles.size(),
- localProfiles.stream().map(VraNgStorageProfile::getName).collect(Collectors.toList()));
-
- localProfiles.forEach(localProfile -> {
-
- // for each storage profile check if such profile exists remotely
- String profileId;
- if (regionProfiles.containsKey(localProfile.getName())) {
- logger.debug("Storage profile {} already exists. Recreating...", localProfile.getName());
- profileId = getProfileId(regionProfiles.get(localProfile.getName()));
- this.restClient.updateStorageProfile(profileId, getUpsertPayload(regionId, localProfile));
- } else {
- logger.debug("Creating storage profile {} ...", localProfile.getName());
- profileId = this.restClient.createStorageProfile(getUpsertPayload(regionId, localProfile));
- }
-
- // Update specific profile. A specific profile is a storage profile
- // representation
- // under a specific cloud account type.
- Map.Entry patchProfile = getPatchPayload(regionId, localProfile);
- String patchTarget = patchProfile.getKey();
- VraNgStorageProfile specificProfile = patchProfile.getValue();
- this.restClient.updateSpecificProfile(patchTarget, profileId, specificProfile);
-
- });
-
- }
-
- /**
- * Create a list of storage profiles from JSON file representation.
- *
- * @param storageProfilesDir directory containing the image mappings for the
- * region
- * @return list of storage profiles
- */
- private List getStorageProfilesFromFileSystem(File storageProfilesDir) {
- List storageProfiles = new ArrayList<>();
- FileUtils.listFiles(storageProfilesDir, new String[] { "json" }, false).forEach(im -> {
- try {
- File spFile = (File) im;
- String storageProfileName = FilenameUtils.removeExtension(spFile.getName());
- String storageProfileContent = FileUtils.readFileToString(spFile, "UTF-8");
- storageProfiles.add(new VraNgStorageProfile(storageProfileName, storageProfileContent));
- } catch (IOException e) {
- e.printStackTrace();
- }
- });
-
- return storageProfiles;
- }
-
- /**
- * Extract profile id.
- *
- * @param profile storage profile
- * @return id
- */
- private String getProfileId(VraNgStorageProfile profile) {
- JsonElement root = new JsonParser().parse(profile.getJson());
- return root.getAsJsonObject().get("id").getAsString();
- }
-
- /**
- * Create API-compliant JSON payload from local storage profile
- * for creating/updating storage profiles.
- *
- * @param regiondId region id
- * @param profile local storage profile
- * @return storage profile with updated payload
- */
- private VraNgStorageProfile getUpsertPayload(String regiondId, VraNgStorageProfile profile) {
- JsonElement root = new JsonParser().parse(profile.getJson());
- JsonObject ob = root.getAsJsonObject();
-
- // create simple storage profile which will be updated later with cloud
- // account-specific properties
- JsonObject cleanedOb = VraNgRegionalContentUtils.cleanJson(ob, Arrays.asList("name", "description", "tags"),
- null);
- cleanedOb.addProperty("regionId", regiondId);
-
- Gson gson = new GsonBuilder().setLenient().serializeNulls().create();
- VraNgStorageProfile storageProfile = new VraNgStorageProfile(profile.getName(), gson.toJson(cleanedOb));
- logger.debug("Upsert JSON: {}", storageProfile.getJson());
- return storageProfile;
- }
-
- /**
- * Create API-compliant JSON payload from local storage profile
- * for patching cloud-specific storage profiles.
- *
- * @param regionId the region id
- * @param profile local storage profile
- * @return storage profile with updated payload
- */
- private Map.Entry getPatchPayload(String regionId, VraNgStorageProfile profile) {
- JsonElement root = new JsonParser().parse(profile.getJson());
- JsonObject ob = root.getAsJsonObject();
-
- ob.addProperty("regionId", regionId);
-
- String patchTarget = "storage-profiles";
- ProfileType profileType = getProfileType(profile);
- switch (profileType) {
- case VSPHERE:
- patchTarget = "storage-profiles-vsphere";
- // resolve datastore link
- if (ob.has("_datastore")) {
- String datastoreId = resolveFabricId(ob.get("_datastore").getAsJsonObject());
- if (datastoreId != null) {
- ob.addProperty("datastoreId", datastoreId);
- }
- }
- // resolve storage-policy link
- if (ob.has("_storagePolicy")) {
- String storagePolicyId = resolveFabricId(ob.get("_storagePolicy").getAsJsonObject());
- if (storagePolicyId != null) {
- ob.addProperty("storagePolicyId", storagePolicyId);
- }
- }
- break;
-
- // intentional fallthrough
- case AWS:
- case AZURE:
- case UNKNOWN:
- default:
- logger.warn("Unsupported storage profile type '{}'", profileType);
- break;
- }
-
- JsonObject cleanedOb = VraNgRegionalContentUtils.cleanJson(ob, null,
- Arrays.asList("_type", "_datastore", "_storagePolicy"));
-
- VraNgStorageProfile storageProfile = new VraNgStorageProfile(profile.getName(), cleanedOb.toString());
- logger.debug("Patch JSON: {}", storageProfile.getJson());
- return new AbstractMap.SimpleEntry<>(patchTarget, storageProfile);
- }
-
- // =================================================
- // UTILITY METHODS
- // =================================================
-
- /**
- * Resolve fabric entity id from JSON object.
- *
- * @param ob JSON object
- * @return id
- */
- private String resolveFabricId(JsonObject ob) {
- String fabric = ob.get("fabric").getAsString();
- String name = ob.get("name").getAsString();
- String entityId = this.restClient.getFabricEntityId(fabric, name);
- logger.debug("{} '{}': {}", fabric, name, entityId);
- return entityId;
- }
-
- /**
- * Determine profile type from storage profile.
- *
- * @param profile storage profile
- * @return profile type
- */
- ProfileType getProfileType(VraNgStorageProfile profile) {
-
- JsonElement root = new JsonParser().parse(profile.getJson());
- JsonObject ob = root.getAsJsonObject();
-
- String type = ob.get("_type").getAsString();
- if (type.equals("vsphere")) {
- return ProfileType.VSPHERE;
- } else if (type.equals("aws")) {
- return ProfileType.AWS;
- } else if (type.equals("azure")) {
- return ProfileType.AZURE;
- }
-
- return ProfileType.UNKNOWN;
- }
-
- /**
- * Determine profile type from cloud account.
- *
- * @param cloudAccount cloud account
- * @return profile type
- */
- ProfileType getProfileType(VraNgCloudAccount cloudAccount) {
- String type = cloudAccount.getType();
- if (type.equals("vsphere")) {
- return ProfileType.VSPHERE;
- } else if (type.equals("aws")) {
- return ProfileType.AWS;
- } else if (type.equals("azure")) {
- return ProfileType.AZURE;
- }
-
- return ProfileType.UNKNOWN;
- }
-
- /**
- * Determine profile type from cloud region.
- *
- * @param cloudRegion cloud region
- * @return profile type
- */
- ProfileType getProfileType(VraNgCloudRegionProfile cloudRegion) {
- String type = cloudRegion.getRegionType();
- if (type.equals("vsphere")) {
- return ProfileType.VSPHERE;
- } else if (type.equals("aws")) {
- return ProfileType.AWS;
- } else if (type.equals("azure")) {
- return ProfileType.AZURE;
- }
-
- return ProfileType.UNKNOWN;
- }
-
-}
diff --git a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgTypeStoreFactory.java b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgTypeStoreFactory.java
index 2d1a88eff..66e8b43eb 100644
--- a/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgTypeStoreFactory.java
+++ b/common/artifact-manager/src/main/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgTypeStoreFactory.java
@@ -35,7 +35,6 @@
import static com.vmware.pscoe.iac.artifact.model.vrang.VraNgPackageContent.ContentType.DEPLOYMENT_LIMIT_POLICY;
import static com.vmware.pscoe.iac.artifact.model.vrang.VraNgPackageContent.ContentType.LEASE_POLICY;
import static com.vmware.pscoe.iac.artifact.model.vrang.VraNgPackageContent.ContentType.PROPERTY_GROUP;
-import static com.vmware.pscoe.iac.artifact.model.vrang.VraNgPackageContent.ContentType.REGION_MAPPING;
import static com.vmware.pscoe.iac.artifact.model.vrang.VraNgPackageContent.ContentType.RESOURCE_ACTION;
import static com.vmware.pscoe.iac.artifact.model.vrang.VraNgPackageContent.ContentType.RESOURCE_QUOTA_POLICY;
import static com.vmware.pscoe.iac.artifact.model.vrang.VraNgPackageContent.ContentType.SUBSCRIPTION;
@@ -56,7 +55,6 @@ public class VraNgTypeStoreFactory {
RESOURCE_ACTION,
BLUEPRINT,
SUBSCRIPTION,
- REGION_MAPPING,
CATALOG_ENTITLEMENT,
CATALOG_ITEM,
CONTENT_SHARING_POLICY,
@@ -87,7 +85,6 @@ public static VraNgPackageContent.ContentType[] getImportOrder() {
RESOURCE_ACTION,
BLUEPRINT,
SUBSCRIPTION,
- REGION_MAPPING,
CATALOG_ENTITLEMENT,
CATALOG_ITEM,
CONTENT_SHARING_POLICY,
@@ -123,7 +120,6 @@ public static VraNgPackageContent.ContentType[] getExportOrder() {
CATALOG_ITEM,
CONTENT_SOURCE,
SUBSCRIPTION,
- REGION_MAPPING,
// Must be deleted before the following
BLUEPRINT,
@@ -236,8 +232,6 @@ private static AbstractVraNgStore selectStore(
return new VraNgBlueprintStore();
case SUBSCRIPTION:
return new VraNgSubscriptionStore();
- case REGION_MAPPING:
- return new VraNgRegionalContentStore();
case CATALOG_ENTITLEMENT:
return new VraNgEntitlementStore();
case CUSTOM_RESOURCE:
diff --git a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/FlavorMappingMockBuilder.java b/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/FlavorMappingMockBuilder.java
deleted file mode 100644
index 8a4d86465..000000000
--- a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/FlavorMappingMockBuilder.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.helpers.stubs;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgFlavorMapping;
-
-import org.apache.commons.io.IOUtils;
-
-public class FlavorMappingMockBuilder {
- private JsonElement mockData;
- private String name = "mockedFlavorMappingName";
-
- public FlavorMappingMockBuilder() throws IOException {
- ClassLoader cl = getClass().getClassLoader();
- try {
- String read = IOUtils.toString( cl.getResourceAsStream("test/fixtures/flavorMapping.json"), StandardCharsets.UTF_8 );
- this.mockData = JsonParser.parseString(read);
- }
- catch (IOException ex) {
- throw ex;
- }
- }
-
- public FlavorMappingMockBuilder setName(String name) {
- this.name = name;
- return this;
- }
-
- public FlavorMappingMockBuilder setPropertyInRawData(String key, String value) {
- JsonObject customResource = this.mockData.getAsJsonObject();
- if(customResource.has(key)) {
- customResource.remove(key);
- customResource.addProperty(key, value);
- }
- this.mockData = customResource.getAsJsonObject();
- return this;
- }
-
- public VraNgFlavorMapping build() {
- return new VraNgFlavorMapping(this.name, this.mockData.toString());
- }
-
-}
diff --git a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/ImageMappingMockBuilder.java b/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/ImageMappingMockBuilder.java
deleted file mode 100644
index 9ab8219e0..000000000
--- a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/ImageMappingMockBuilder.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.helpers.stubs;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgImageMapping;
-
-import org.apache.commons.io.IOUtils;
-
-public class ImageMappingMockBuilder {
- private JsonElement mockData;
- private String name = "mockedImageMappingName";
-
- public ImageMappingMockBuilder() throws IOException {
- ClassLoader cl = getClass().getClassLoader();
- try {
- String read = IOUtils.toString( cl.getResourceAsStream("test/fixtures/imageMapping.json"), StandardCharsets.UTF_8 );;
- this.mockData = JsonParser.parseString(read);
- }
- catch (IOException ex) {
- throw ex;
- }
- }
-
- public ImageMappingMockBuilder setName(String name) {
- this.name = name;
- return this;
- }
-
- public ImageMappingMockBuilder setPropertyInRawData(String key, String value) {
- JsonObject customResource = this.mockData.getAsJsonObject();
- if(customResource.has(key)) {
- customResource.remove(key);
- customResource.addProperty(key, value);
- }
- this.mockData = customResource.getAsJsonObject();
- return this;
- }
-
- public VraNgImageMapping build() {
- return new VraNgImageMapping(this.name, this.mockData.toString());
- }
-
-}
diff --git a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/RegionMappingMockBuilder.java b/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/RegionMappingMockBuilder.java
deleted file mode 100644
index 6be626e22..000000000
--- a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/RegionMappingMockBuilder.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.helpers.stubs;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgRegionMapping;
-import com.vmware.pscoe.iac.artifact.model.vrang.objectmapping.VraNgCloudAccountTag;
-
-
-public class RegionMappingMockBuilder {
- private String exportTag;
- private List importTags;
-
- public RegionMappingMockBuilder() {
- this.exportTag = "";
- this.importTags = new ArrayList();
- }
-
- public RegionMappingMockBuilder setExportTag(String exportTag){
- this.exportTag = exportTag;
- return this;
- }
-
- public RegionMappingMockBuilder setImportTags(List importTags){
- this.importTags = importTags;
- return this;
- }
-
- public VraNgRegionMapping build() {
- VraNgCloudAccountTag tags;
- if(this.exportTag == null && this.importTags.isEmpty() ){
- tags = new VraNgCloudAccountTag();
- } else {
- tags = new VraNgCloudAccountTag(this.exportTag, this.importTags);
- }
-
- return new VraNgRegionMapping(tags);
- }
-}
diff --git a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/StorageProfileMockBuilder.java b/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/StorageProfileMockBuilder.java
deleted file mode 100644
index 30393eab5..000000000
--- a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/stubs/StorageProfileMockBuilder.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.helpers.stubs;
-
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgStorageProfile;
-
-import org.apache.commons.io.IOUtils;
-
-public class StorageProfileMockBuilder {
- private JsonElement mockData;
- private String name = "mockedStorageProfileMName";
-
- public StorageProfileMockBuilder() throws IOException {
- ClassLoader cl = getClass().getClassLoader();
- try {
- String read = IOUtils.toString(cl.getResourceAsStream("test/fixtures/storageProfile.json"),
- StandardCharsets.UTF_8);
- this.mockData = JsonParser.parseString(read);
- } catch (IOException ex) {
- throw ex;
- }
- }
-
- public StorageProfileMockBuilder setName(String name) {
- this.name = name;
- return this;
- }
-
- public StorageProfileMockBuilder setPropertyInRawData(String key, String value) {
- JsonObject customResource = this.mockData.getAsJsonObject();
- if (customResource.has(key)) {
- customResource.remove(key);
- customResource.addProperty(key, value);
- }
- this.mockData = customResource.getAsJsonObject();
- return this;
- }
-
- public VraNgStorageProfile build() {
- return new VraNgStorageProfile(this.name, this.mockData.toString());
- }
-
-}
diff --git a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/vrang/RestClientVraNgPrimitiveTestDouble.java b/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/vrang/RestClientVraNgPrimitiveTestDouble.java
index 47853fa24..b68334c8c 100644
--- a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/vrang/RestClientVraNgPrimitiveTestDouble.java
+++ b/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/helpers/vrang/RestClientVraNgPrimitiveTestDouble.java
@@ -14,7 +14,6 @@
*/
package com.vmware.pscoe.iac.artifact.helpers.vrang;
-import com.google.gson.JsonObject;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNgPrimitive;
import com.vmware.pscoe.iac.artifact.configuration.ConfigurationVraNg;
@@ -31,10 +30,7 @@
import com.vmware.pscoe.iac.artifact.model.Version;
import com.vmware.pscoe.iac.artifact.model.abx.AbxAction;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgContentSharingPolicy;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgFlavorMapping;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgImageMapping;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgProject;
-import com.vmware.pscoe.iac.artifact.model.vrang.VraNgStorageProfile;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgCatalogItem;
import com.vmware.pscoe.iac.artifact.model.vrang.VraNgCloudAccount;
@@ -89,27 +85,6 @@ public String getVersion() {
return "";
}
- /**
- * jsonObjectValid.
- *
- * @param ob JsonObject
- * @return isValid boolean
- */
- @Override
- public boolean jsonObjectValid(final JsonObject ob) {
- return super.jsonObjectValid(ob);
- }
-
- /**
- * getAllImageMappingsByRegionPrimitive.
- *
- * @return imageMappingsByRegionPrimitive Map>
- */
- @Override
- public Map> getAllImageMappingsByRegionPrimitive() {
- return super.getAllImageMappingsByRegionPrimitive();
- }
-
/**
* getURIBuilder.
*
@@ -131,37 +106,6 @@ public URI getURI(final URIBuilder builder) {
return super.getURI(builder);
}
- /**
- * getAllFlavorProfilesByRegionPrimitive.
- *
- * @return flavorProfilesByRegionPrimitive Map>
- */
- @Override
- public Map> getAllFlavorProfilesByRegionPrimitive() {
- return super.getAllFlavorProfilesByRegionPrimitive();
- }
-
- /**
- * getAllStorageProfilesByRegionPrimitive.
- *
- * @return storageProfilesByRegionPrimitive Map>
- */
- @Override
- public Map> getAllStorageProfilesByRegionPrimitive() {
- return super.getAllStorageProfilesByRegionPrimitive();
- }
-
- /**
- * getAllImageProfilesByRegionPrimitive.
- *
- * @return imageProfilesByRegionPrimitive Map>
- */
- @Override
- public Map> getAllImageProfilesByRegionPrimitive() {
- return super.getAllImageProfilesByRegionPrimitive();
- }
-
/**
* createAbxActionMap.
*
@@ -173,15 +117,6 @@ public Map createAbxActionMap(final AbxAction action) throws IOE
return super.createAbxActionMap(action);
}
- /**
- * getAllFlavorMappingsByRegionPrimitive.
- *
- * @return mappingsByRegionPrimitive Map>
- */
- public Map> getAllFlavorMappingsByRegionPrimitive() {
- return super.getAllFlavorMappingsByRegionPrimitive();
- }
-
/**
* getContentSharingPolicyPrimitive.
*
diff --git a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/rest/vrang/RestClientVraNgPrimitiveTest.java b/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/rest/vrang/RestClientVraNgPrimitiveTest.java
index af4ba32c7..d6c59b754 100644
--- a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/rest/vrang/RestClientVraNgPrimitiveTest.java
+++ b/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/rest/vrang/RestClientVraNgPrimitiveTest.java
@@ -395,88 +395,6 @@ void testImportCustomFormPrimitiveAlwaysCustomFormFormatNotNull() {
});
}
- @Test
- void testJSONObjectEmptyShouldBeTrue() throws NullPointerException {
- JsonObject ob = new JsonObject();
- ob.add("mapping", new JsonObject());
- ob.add("_links", new JsonObject());
- boolean jsonEmpty = this.restClient.jsonObjectValid(ob);
-
- Assertions.assertTrue(jsonEmpty);
- }
-
- @Test
- void testJSONObjectEmptyShouldNotBeTrue() throws NullPointerException {
- JsonObject ob = new JsonObject();
- JsonObject song = new JsonObject();
- song.add("temp", new JsonObject());
- ob.add("mapping", song);
- ob.add("_links", song);
- boolean jsonEmpty = this.restClient.jsonObjectValid(ob);
-
- Assertions.assertFalse(jsonEmpty);
- }
-
- @Test
- void testGetAllImageMappingsByRegionPrimitiveShouldBeEmpty() {
- URI uri = restClient.getURI(restClient.getURIBuilder().setPath("/iaas/api/images"));
- when(this.restTemplate.exchange(uri, HttpMethod.GET, RestClientVraNgPrimitiveTestDouble.getDefaultHttpEntity(),
- String.class))
- .thenReturn(new ResponseEntity<>("{\"content\":[{\"mapping\":{},\"_links\":{}}]}", HttpStatus.OK));
-
- Assertions.assertDoesNotThrow(() -> {
- this.restClient.getAllImageMappingsByRegionPrimitive();
- });
- }
-
- @Test
- void testGetAllFlavorProfilesByRegionPrimitiveShouldBeEmpty() {
- URI uri = restClient.getURI(restClient.getURIBuilder().setPath("/iaas/api/flavor-profiles"));
- when(this.restTemplate.exchange(uri, HttpMethod.GET, RestClientVraNgPrimitiveTestDouble.getDefaultHttpEntity(),
- String.class))
- .thenReturn(new ResponseEntity<>("{\"content\":[{\"mapping\":{},\"_links\":{}}]}", HttpStatus.OK));
-
- Assertions.assertDoesNotThrow(() -> {
- this.restClient.getAllFlavorProfilesByRegionPrimitive();
- });
- }
-
- @Test
- void testGetAllStorageProfilesByRegionPrimitiveShouldBeEmpty() {
- URI uri = restClient.getURI(restClient.getURIBuilder().setPath("/iaas/api/storage-profiles"));
- when(this.restTemplate.exchange(uri, HttpMethod.GET, RestClientVraNgPrimitiveTestDouble.getDefaultHttpEntity(),
- String.class))
- .thenReturn(new ResponseEntity<>("{\"content\":[{\"mapping\":{},\"_links\":{}}]}", HttpStatus.OK));
-
- Assertions.assertDoesNotThrow(() -> {
- this.restClient.getAllStorageProfilesByRegionPrimitive();
- });
- }
-
- @Test
- void testGetAllImageProfilesByRegionPrimitiveShouldBeEmpty() {
- URI uri = restClient.getURI(restClient.getURIBuilder().setPath("/iaas/api/image-profiles"));
- when(this.restTemplate.exchange(uri, HttpMethod.GET, RestClientVraNgPrimitiveTestDouble.getDefaultHttpEntity(),
- String.class))
- .thenReturn(new ResponseEntity<>("{\"content\":[{\"mapping\":{},\"_links\":{}}]}", HttpStatus.OK));
-
- Assertions.assertDoesNotThrow(() -> {
- this.restClient.getAllImageProfilesByRegionPrimitive();
- });
- }
-
- @Test
- void testGetAllFlavorMappingsByRegionPrimitiveShouldBeEmpty() {
- URI uri = restClient.getURI(restClient.getURIBuilder().setPath("/iaas/api/flavors"));
- when(this.restTemplate.exchange(uri, HttpMethod.GET, RestClientVraNgPrimitiveTestDouble.getDefaultHttpEntity(),
- String.class))
- .thenReturn(new ResponseEntity<>("{\"content\":[{\"mapping\":{},\"_links\":{}}]}", HttpStatus.OK));
-
- Assertions.assertDoesNotThrow(() -> {
- this.restClient.getAllFlavorMappingsByRegionPrimitive();
- });
- }
-
@Test
void testCreatePropertyGroupPrimitive() throws IOException {
PropertyGroupMockBuilder propertyGroupBuilder = new PropertyGroupMockBuilder();
diff --git a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgFlavorMappingStoreTest.java b/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgFlavorMappingStoreTest.java
deleted file mode 100644
index 9fd85dfe8..000000000
--- a/common/artifact-manager/src/test/java/com/vmware/pscoe/iac/artifact/store/vrang/VraNgFlavorMappingStoreTest.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * #%L
- * artifact-manager
- * %%
- * Copyright (C) 2023 VMware
- * %%
- * Build Tools for VMware Aria
- * Copyright 2023 VMware, Inc.
- *
- * This product is licensed to you under the BSD-2 license (the "License"). You may not use this product except in compliance with the BSD-2 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.
- * #L%
- */
-package com.vmware.pscoe.iac.artifact.store.vrang;
-
-import com.vmware.pscoe.iac.artifact.configuration.ConfigurationVraNg;
-import com.vmware.pscoe.iac.artifact.helpers.AssertionsHelper;
-import com.vmware.pscoe.iac.artifact.helpers.FsMocks;
-import com.vmware.pscoe.iac.artifact.helpers.stubs.CloudAccountMockBuilder;
-import com.vmware.pscoe.iac.artifact.helpers.stubs.FlavorMappingMockBuilder;
-import com.vmware.pscoe.iac.artifact.model.Package;
-import com.vmware.pscoe.iac.artifact.model.PackageFactory;
-import com.vmware.pscoe.iac.artifact.model.PackageType;
-import com.vmware.pscoe.iac.artifact.model.vrang.*;
-import com.vmware.pscoe.iac.artifact.rest.RestClient;
-import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
-
-import org.junit.Rule;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.rules.TemporaryFolder;
-import org.mockito.Mockito;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.*;
-
-public class VraNgFlavorMappingStoreTest {
- @Rule
- public TemporaryFolder tempFolder = new TemporaryFolder();
-
- protected VraNgFlavorMappingStore store;
- protected RestClientVraNg restClient;
- protected Package pkg;
- protected ConfigurationVraNg config;
- protected VraNgPackageDescriptor vraNgPackageDescriptor;
- protected FsMocks fsMocks;
-
- @BeforeEach
- void init() {
- try {
- tempFolder.create();
- }
- catch ( IOException e ) {
- throw new RuntimeException( "Could not create a temp folder" );
- }
-
- fsMocks = new FsMocks( tempFolder.getRoot() );
- store = new VraNgFlavorMappingStore();
- restClient = Mockito.mock( RestClientVraNg.class );
- pkg = PackageFactory.getInstance( PackageType.VRANG, tempFolder.getRoot() );
- vraNgPackageDescriptor = Mockito.mock( VraNgPackageDescriptor.class );
-
- store.init( restClient, pkg, vraNgPackageDescriptor );
- System.out.println( "==========================================================" );
- System.out.println( "START" );
- System.out.println( "==========================================================" );
- }
-
- @AfterEach
- void tearDown() {
- tempFolder.delete();
-
- System.out.println( "==========================================================" );
- System.out.println( "END" );
- System.out.println( "==========================================================" );
- }
-
- @Test
- void testExportContentWithNoFlavorMapping(){
- //GIVEN
- CloudAccountMockBuilder builder = new CloudAccountMockBuilder();
- List cloudAccounts = new ArrayList();
- cloudAccounts.add( builder.build() );
-
- when( vraNgPackageDescriptor.getFlavorMapping() ).thenReturn(new ArrayList());
-
- //TEST
- store.exportContent( cloudAccounts ) ;
-
- //VERIFY
- verify( restClient, never() ).getAllFlavorMappingsByRegion();
- assertEquals( 0, tempFolder.getRoot().listFiles().length );
- }
-
- @Test
- void testExportContentWithAllFlavorMapping() throws IOException{
- //GIVEN
- CloudAccountMockBuilder accountBuilder = new CloudAccountMockBuilder();
- List cloudAccounts = new ArrayList();
- List regionIds = new ArrayList();
- regionIds.add("mockedRegionId1");
-
- VraNgCloudAccount cloudAccount = accountBuilder.setName("mockedAccountName").setRegionIds(regionIds).build();
- cloudAccounts.add(cloudAccount);
-
- FlavorMappingMockBuilder mappingBuilder = new FlavorMappingMockBuilder();
- mappingBuilder.setName("smallMock");
-
- Map> mockedFlavorsByRegion = new HashMap>();
- List flavorMappings = new ArrayList();
- flavorMappings.add( mappingBuilder.build() );
- mockedFlavorsByRegion.put("mockedRegionId1", flavorMappings);
-
- when( vraNgPackageDescriptor.getFlavorMapping() ).thenReturn(null);
- when( restClient.getAllFlavorMappingsByRegion() ).thenReturn(mockedFlavorsByRegion);
-
- //TEST
- store.exportContent(cloudAccounts);
-
- String[] expectedFlavorMappingFolder = { "mockedAccountName~mockedRegionId1" };
- String[] expectedFlavorMappingFiles = { "smallMock.json" };
-
- // VERIFY
- verify( restClient, times( 1 ) ).getAllFlavorMappingsByRegion();
- // generated folder regions/{cloudaccountname~regionId}/flavor-mapping/{flavormapping name}.json
- File regionsFolder = new File (tempFolder.getRoot().getPath() + "/regions");
- AssertionsHelper.assertFolderContainsFiles( regionsFolder, expectedFlavorMappingFolder );
-
- File flavorMappingFolder = new File(regionsFolder.getPath() + "/mockedAccountName~mockedRegionId1/flavor-mappings" );
- AssertionsHelper.assertFolderContainsFiles( flavorMappingFolder, expectedFlavorMappingFiles );
- }
-
- @Test
- void testExportContentWithSpecificFlavorMapping() throws IOException{
- //GIVEN
- List flavorMappingNames = new ArrayList<>();
- flavorMappingNames.add("smallMock");
-
- CloudAccountMockBuilder accountBuilder = new CloudAccountMockBuilder();
- List cloudAccounts = new ArrayList();
- List regionIds = new ArrayList();
- regionIds.add("mockedRegionId1");
- VraNgCloudAccount cloudAccount = accountBuilder.setName("mockedAccountName").setRegionIds(regionIds).build();
- cloudAccounts.add(cloudAccount);
-
- FlavorMappingMockBuilder mappingSmallBuilder = new FlavorMappingMockBuilder();
- mappingSmallBuilder.setName("smallMock");
-
- FlavorMappingMockBuilder mappingMediumBuilder = new FlavorMappingMockBuilder();
- mappingMediumBuilder.setName("mediumMock");
-
- Map> mockedFlavorsByRegion = new HashMap>();
- List flavorMappings = new ArrayList();
- flavorMappings.add(mappingSmallBuilder.build());
- flavorMappings.add(mappingMediumBuilder.build());
-
- mockedFlavorsByRegion.put("mockedRegionId1", flavorMappings);
-
- when( vraNgPackageDescriptor.getFlavorMapping() ).thenReturn( flavorMappingNames );
- when( restClient.getAllFlavorMappingsByRegion() ).thenReturn( mockedFlavorsByRegion );
-
- //TEST
- store.exportContent(cloudAccounts);
-
-
- String[] expectedFlavorMappingFolder = { "mockedAccountName~mockedRegionId1" };
- String[] expectedFlavorMappingFiles = { "smallMock.json" };
-
- // VERIFY
- verify( restClient, times( 1 ) ).getAllFlavorMappingsByRegion();
- // generated folder regions/{cloudaccountname~regionId}/flavor-mapping/{flavormapping name}.json
- File regionsFolder = new File (tempFolder.getRoot().getPath() + "/regions");
- AssertionsHelper.assertFolderContainsFiles( regionsFolder, expectedFlavorMappingFolder );
-
- File flavorMappingFolder = new File(regionsFolder.getPath() + "/mockedAccountName~mockedRegionId1/flavor-mappings" );
- AssertionsHelper.assertFolderContainsFiles( flavorMappingFolder, expectedFlavorMappingFiles );
- }
-
- @Test
- void testExportContentWithSpecificFlavorMappingFromSpecificCloudAccount() throws IOException{
- //GIVEN
- List flavorMappingNames = new ArrayList<>();
- flavorMappingNames.add("smallMock");
-
- CloudAccountMockBuilder accountBuilder1 = new CloudAccountMockBuilder();
- List regionIds1 = new ArrayList();
- regionIds1.add("mockedRegionId1");
- VraNgCloudAccount cloudAccount1 = accountBuilder1.setName("mockedAccountName").setRegionIds(regionIds1).build();
-
- CloudAccountMockBuilder accountBuilder2 = new CloudAccountMockBuilder();
- List regionIds2 = new ArrayList();
- regionIds2.add("mockedRegionId2");
- VraNgCloudAccount cloudAccount2 = accountBuilder2.setName("mockedAccountName").setRegionIds(regionIds2).build();
-
- List cloudAccounts = new ArrayList();
- cloudAccounts.add(cloudAccount1);
- cloudAccounts.add(cloudAccount2);
-
- FlavorMappingMockBuilder mappingSmallBuilder = new FlavorMappingMockBuilder();
- mappingSmallBuilder.setName("smallMock");
-
- FlavorMappingMockBuilder mappingMediumBuilder = new FlavorMappingMockBuilder();
- mappingMediumBuilder.setName("mediumMock");
-
- Map> mockedFlavorsByRegion = new HashMap>();
- List