diff --git a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/Automaton.java b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/Automaton.java index da9ced92..6ccf31a2 100644 --- a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/Automaton.java +++ b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/Automaton.java @@ -172,7 +172,7 @@ public void deployCustomWorkload(LiveSystemIdValue liveSystemId, String commitId, InstantiationConfiguration config) throws ComponentInstantiationException, InstantiatorException { - if (isBlank(liveSystemId.resourceGroupId())) { + if (liveSystemId.resourceGroupId() == null) { throw new ComponentInstantiationException("Resource group ID cannot be blank."); } @@ -250,7 +250,7 @@ public void deployCustomWorkload(LiveSystemIdValue liveSystemId, public void deployCustomWorkload(LiveSystemIdValue liveSystemId, String customWorkloadComponentId) throws ComponentInstantiationException, InstantiatorException { - if (isBlank(liveSystemId.resourceGroupId())) { + if (liveSystemId.resourceGroupId() == null) { throw new ComponentInstantiationException("Resource group ID cannot be blank."); } diff --git a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/blueprint/FractalIdValue.java b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/blueprint/FractalIdValue.java index a75772d3..88a72489 100644 --- a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/blueprint/FractalIdValue.java +++ b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/blueprint/FractalIdValue.java @@ -1,8 +1,12 @@ package com.yanchware.fractal.sdk.domain.blueprint; -public record FractalIdValue(String resourceGroupId, String name, String version) { +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import org.jetbrains.annotations.NotNull; + +public record FractalIdValue(ResourceGroupId resourceGroupId, String name, String version) { + @NotNull @Override public String toString(){ - return String.format("%s/%s:%s", resourceGroupId, name, version); + return String.format("%s/%s:%s", resourceGroupId.toString(), name, version); } } diff --git a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/blueprint/service/commands/UpdateBlueprintCommandRequest.java b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/blueprint/service/commands/UpdateBlueprintCommandRequest.java index 5d847aa9..14522121 100644 --- a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/blueprint/service/commands/UpdateBlueprintCommandRequest.java +++ b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/blueprint/service/commands/UpdateBlueprintCommandRequest.java @@ -18,11 +18,11 @@ public class UpdateBlueprintCommandRequest { Collection components; public static UpdateBlueprintCommandRequest fromCreateCommand(CreateBlueprintCommandRequest command, FractalIdValue fractalId) { - String[] splitId = fractalId.toString().split("/|\\:"); + String[] splitId = fractalId.toString().split("[/:]"); return UpdateBlueprintCommandRequest.builder() - .resourceGroupId(splitId[0]) - .fractalName(splitId[1]) - .fractalVersion(splitId[2]) + .resourceGroupId(String.format("%s/%s/%s", splitId[0], splitId[1], splitId[2])) + .fractalName(splitId[3]) + .fractalVersion(splitId[4]) .description(command.description()) .isPrivate(command.isPrivate()) .components(command.components()) diff --git a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAggregate.java b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAggregate.java index b2ef8e8b..9e954c9e 100644 --- a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAggregate.java +++ b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAggregate.java @@ -148,7 +148,7 @@ public Collection validate() { errors.add(NAME_IS_NULL); } - if (isBlank(id.resourceGroupId())) { + if (id.resourceGroupId() == null) { errors.add(RESOURCE_GROUP_ID_IS_NULL); } diff --git a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemIdValue.java b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemIdValue.java index 6d9b0097..8dc41f3b 100644 --- a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemIdValue.java +++ b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemIdValue.java @@ -1,10 +1,14 @@ package com.yanchware.fractal.sdk.domain.livesystem; -public record LiveSystemIdValue(String resourceGroupId, String name) { +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import org.jetbrains.annotations.NotNull; +public record LiveSystemIdValue(ResourceGroupId resourceGroupId, String name) { + + @NotNull @Override public String toString(){ - return String.format("%s/%s", resourceGroupId, name); + return String.format("%s/%s", resourceGroupId.toString(), name); } } diff --git a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/service/LiveSystemService.java b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/service/LiveSystemService.java index c31c649f..c251caa2 100644 --- a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/service/LiveSystemService.java +++ b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/livesystem/service/LiveSystemService.java @@ -407,7 +407,7 @@ private LiveSystemComponentMutationDto getComponentMutationStatus( private URI getInstantiateComponentUri(LiveSystemIdValue liveSystemId, String componentId) { return URI.create(String.format( "%s/%s/%s/component/%s/instantiate", - getLiveSystemUri(), liveSystemId.resourceGroupId(), liveSystemId.name(), componentId)); + getLiveSystemUri(), liveSystemId.resourceGroupId().toString(), liveSystemId.name(), componentId)); } private URI getComponentStateUri(String liveSystemId, String componentId, String mutationId) { diff --git a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/values/ResourceGroupId.java b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/values/ResourceGroupId.java index 2e0e0ae3..039dbb07 100644 --- a/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/values/ResourceGroupId.java +++ b/fractal.sdk/src/main/java/com/yanchware/fractal/sdk/domain/values/ResourceGroupId.java @@ -32,14 +32,13 @@ public boolean equals(Object o) { if (o == this){ return true; } - if (!(o instanceof ResourceGroupId)) { + if (!(o instanceof ResourceGroupId(ResourceGroupType groupType, UUID id, String name))) { return false; } - ResourceGroupId other = (ResourceGroupId)o; - return this.resourceGroupType.getValue().equals(other.resourceGroupType.getValue()) - && this.ownerId.toString().equals(other.ownerId.toString()) - && this.shortName.equals(other.shortName); + return this.resourceGroupType.getValue().equals(groupType.getValue()) + && this.ownerId.toString().equals(id.toString()) + && this.shortName.equals(name); } @Override diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/aggregates/LiveSystemTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/aggregates/LiveSystemTest.java index 7e8427b6..a200a653 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/aggregates/LiveSystemTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/aggregates/LiveSystemTest.java @@ -5,12 +5,15 @@ import com.yanchware.fractal.sdk.domain.livesystem.LiveSystemIdValue; import com.yanchware.fractal.sdk.domain.livesystem.LiveSystemsFactory; import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.ProviderType; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import io.github.resilience4j.retry.RetryRegistry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.net.http.HttpClient; +import java.util.UUID; import static com.yanchware.fractal.sdk.utils.TestUtils.getDefaultAks; import static org.assertj.core.api.Assertions.assertThat; @@ -18,16 +21,17 @@ public class LiveSystemTest { + private static ResourceGroupId validResourceGroupId = new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"); LiveSystemsFactory factory; @BeforeEach public void setup() { factory = new LiveSystemsFactory( - HttpClient.newBuilder().build(), - new LocalSdkConfiguration(""), - RetryRegistry.ofDefaults()); + HttpClient.newBuilder().build(), + new LocalSdkConfiguration(""), + RetryRegistry.ofDefaults()); } - + @Test public void multipleValidationErrors_when_liveSystemHasNoFields() { assertThatThrownBy(() -> factory.builder().build()).isInstanceOf(IllegalArgumentException.class).hasMessageContainingAll("Id has not been defined"); @@ -40,17 +44,17 @@ public void multipleValidationErrors_when_liveSystemHasNullId() { @Test public void multipleValidationErrors_when_liveSystemHasNullName() { - assertThatThrownBy(() -> factory.builder().withId(new LiveSystemIdValue("xxx", null)).build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Name has not been defined"); + assertThatThrownBy(() -> factory.builder().withId(new LiveSystemIdValue(validResourceGroupId, null)).build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Name has not been defined"); } @Test public void multipleValidationErrors_when_liveSystemHasEmptyId() { - assertThatThrownBy(() -> factory.builder().withId(new LiveSystemIdValue("xxx", "")).build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Name has not been defined"); + assertThatThrownBy(() -> factory.builder().withId(new LiveSystemIdValue(validResourceGroupId, "")).build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Name has not been defined"); } @Test public void multipleValidationErrors_when_liveSystemHasBlankId() { - assertThatThrownBy(() -> factory.builder().withId(new LiveSystemIdValue("xxx", " ")).build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Name has not been defined"); + assertThatThrownBy(() -> factory.builder().withId(new LiveSystemIdValue(validResourceGroupId, " ")).build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Name has not been defined"); } @Test @@ -58,23 +62,13 @@ public void multipleValidationErrors_when_liveSystemHasNullResourceGroupId() { assertThatThrownBy(() -> factory.builder().withId(new LiveSystemIdValue(null, "xxx")).build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("ResourceGroupId has not been defined and it is required"); } - @Test - public void multipleValidationErrors_when_liveSystemHasEmptyResourceGroupId() { - assertThatThrownBy(() -> factory.builder().withId(new LiveSystemIdValue("", "xxx")).build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("ResourceGroupId has not been defined and it is required"); - } - - @Test - public void multipleValidationErrors_when_liveSystemHasBlankResourceGroupId() { - assertThatThrownBy(() -> factory.builder().withId(new LiveSystemIdValue(" ", "xxx")).build()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("ResourceGroupId has not been defined and it is required"); - } - @Test public void multipleValidationErrors_when_liveSystemHasNoComponents() { assertThatThrownBy(() -> factory.builder() - .withId(new LiveSystemIdValue("res/group", "ls")) - .withStandardProvider(ProviderType.AWS) - .build().instantiate()).isInstanceOf(InstantiatorException.class) - .hasMessageContaining("Components list is null or empty and at least one component is required"); + .withId(new LiveSystemIdValue(validResourceGroupId, "ls")) + .withStandardProvider(ProviderType.AWS) + .build().instantiate()).isInstanceOf(InstantiatorException.class) + .hasMessageContaining("Components list is null or empty and at least one component is required"); } @Test @@ -84,11 +78,11 @@ public void noValidationErrors_when_liveSystemWithValidFields() { private LiveSystemAggregate generateBuilder() { return factory.builder() - .withId(new LiveSystemIdValue("res/group", "ls")) - .withStandardProvider(ProviderType.AZURE) - .withComponent( - getDefaultAks() - .build()) - .build(); + .withId(new LiveSystemIdValue(validResourceGroupId, "ls")) + .withStandardProvider(ProviderType.AZURE) + .withComponent( + getDefaultAks() + .build()) + .build(); } } \ No newline at end of file diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/blueprint/service/BlueprintServiceTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/blueprint/service/BlueprintServiceTest.java index 79caef4e..771d8033 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/blueprint/service/BlueprintServiceTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/blueprint/service/BlueprintServiceTest.java @@ -6,6 +6,8 @@ import com.yanchware.fractal.sdk.domain.blueprint.service.commands.CreateBlueprintCommandRequest; import com.yanchware.fractal.sdk.domain.blueprint.service.dtos.BlueprintComponentDto; import com.yanchware.fractal.sdk.domain.exceptions.InstantiatorException; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import com.yanchware.fractal.sdk.utils.StringHandler; import io.github.resilience4j.retry.RetryRegistry; @@ -13,6 +15,7 @@ import java.net.http.HttpClient; import java.util.List; +import java.util.UUID; import static com.github.tomakehurst.wiremock.client.WireMock.*; import static java.util.Collections.emptyMap; @@ -35,9 +38,11 @@ public void urlPathMatching_when_postRequestToBlueprint(WireMockRuntimeInfo wmRu assertThat(inputStream).isNotNull(); + var resourceGroupId = new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"); var postRequestToBlueprintBody = StringHandler.getStringFromInputStream(inputStream); + var url = String.format("/blueprints/%s/fr/fr", resourceGroupId); - stubFor(post(urlPathMatching("/blueprints/resource-group/fr/fr")) + stubFor(post(urlPathMatching(url)) .withRequestBody(equalToJson(postRequestToBlueprintBody)) .willReturn(aResponse() .withStatus(202) @@ -45,9 +50,9 @@ public void urlPathMatching_when_postRequestToBlueprint(WireMockRuntimeInfo wmRu blueprintService.create( buildBlueprintRequest(), - new FractalIdValue("resource-group", "fr", "fr")); + new FractalIdValue(resourceGroupId, "fr", "fr")); - verify(postRequestedFor(urlPathEqualTo("/blueprints/resource-group/fr/fr"))); + verify(postRequestedFor(urlPathEqualTo(url))); } private CreateBlueprintCommandRequest buildBlueprintRequest() { diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAggregateTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAggregateTest.java index 21177fb4..63df8dd5 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAggregateTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAggregateTest.java @@ -10,6 +10,8 @@ import com.yanchware.fractal.sdk.domain.livesystem.paas.providers.azure.cosmos.AzureCosmosGremlinDatabase; import com.yanchware.fractal.sdk.domain.livesystem.paas.providers.azure.cosmos.AzureCosmosGremlinDbms; import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.ProviderType; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import io.github.resilience4j.retry.RetryRegistry; import org.junit.jupiter.api.BeforeEach; @@ -35,7 +37,7 @@ void setUp(WireMockRuntimeInfo wmRuntimeInfo) { var sdkConfiguration = new LocalSdkConfiguration(wmRuntimeInfo.getHttpBaseUrl()); liveSystemAggregate = new LiveSystemsFactory(httpClient, sdkConfiguration, RetryRegistry.ofDefaults()) .builder() - .withId(new LiveSystemIdValue(UUID.randomUUID().toString(), UUID.randomUUID().toString())) + .withId(new LiveSystemIdValue(new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"), UUID.randomUUID().toString())) .withStandardProvider(ProviderType.AZURE) .withEnvironmentId(new EnvironmentIdValue( EnvironmentType.PERSONAL, diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAksComponentDtoTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAksComponentDtoTest.java index 1b35851a..e2fc7539 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAksComponentDtoTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemAksComponentDtoTest.java @@ -5,6 +5,8 @@ import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.LiveSystemKubernetesComponentDtoTest; import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.ProviderType; import com.yanchware.fractal.sdk.domain.values.ComponentType; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import com.yanchware.fractal.sdk.utils.TestUtils; import io.github.resilience4j.retry.RetryRegistry; @@ -13,6 +15,7 @@ import java.net.http.HttpClient; import java.util.Map; +import java.util.UUID; import static com.yanchware.fractal.sdk.utils.TestUtils.assertGenericComponent; import static org.assertj.core.api.Assertions.assertThat; @@ -27,7 +30,7 @@ public void liveSystemComponentDto_matches_liveSystemComponents_withCorrectTypeF RetryRegistry.ofDefaults()); var aks = TestUtils.getAksExample(); var liveSystem = factory.builder() - .withId(new LiveSystemIdValue("test", "test")) + .withId(new LiveSystemIdValue(new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"), "test")) .withStandardProvider(ProviderType.AZURE) .withComponent(aks) .build(); diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemEksComponentDtoTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemEksComponentDtoTest.java index eb158da1..ab20cb54 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemEksComponentDtoTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemEksComponentDtoTest.java @@ -5,6 +5,8 @@ import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.LiveSystemKubernetesComponentDtoTest; import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.ProviderType; import com.yanchware.fractal.sdk.domain.values.ComponentType; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import com.yanchware.fractal.sdk.utils.TestUtils; import io.github.resilience4j.retry.RetryRegistry; @@ -13,6 +15,7 @@ import java.net.http.HttpClient; import java.util.List; import java.util.Map; +import java.util.UUID; import static com.yanchware.fractal.sdk.utils.TestUtils.assertGenericComponent; import static org.assertj.core.api.Assertions.assertThat; @@ -27,7 +30,7 @@ public void liveSystemComponentDto_matches_liveSystemComponents_withCorrectTypeF var eks = TestUtils.getEksExample(); var postgres = TestUtils.getGcpPostgresExample(); var liveSystem = factory.builder() - .withId(new LiveSystemIdValue("test", "test")) + .withId(new LiveSystemIdValue(new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"), "test")) .withStandardProvider(ProviderType.AWS) .withComponents(List.of(eks, postgres)) .build(); diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemGkeComponentDtoTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemGkeComponentDtoTest.java index 64933108..719059ca 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemGkeComponentDtoTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemGkeComponentDtoTest.java @@ -5,6 +5,8 @@ import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.LiveSystemKubernetesComponentDtoTest; import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.ProviderType; import com.yanchware.fractal.sdk.domain.values.ComponentType; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import com.yanchware.fractal.sdk.utils.TestUtils; import io.github.resilience4j.retry.RetryRegistry; @@ -13,6 +15,7 @@ import java.net.http.HttpClient; import java.util.List; import java.util.Map; +import java.util.UUID; import static com.yanchware.fractal.sdk.utils.TestUtils.assertGenericComponent; import static org.assertj.core.api.Assertions.assertThat; @@ -27,7 +30,7 @@ public void liveSystemComponentDto_matches_liveSystemComponents_withCorrectTypeF var gke = TestUtils.getGkeExample(); var postgres = TestUtils.getGcpPostgresExample(); var liveSystem = factory.builder() - .withId(new LiveSystemIdValue("test", "test")) + .withId(new LiveSystemIdValue(new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"), "test")) .withStandardProvider(ProviderType.GCP) .withComponents(List.of(gke, postgres)) .build(); diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemHetznerComponentDtoTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemHetznerKubernetesDtoTest.java similarity index 87% rename from fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemHetznerComponentDtoTest.java rename to fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemHetznerKubernetesDtoTest.java index c19ed6e8..1fc2596d 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemHetznerComponentDtoTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemHetznerKubernetesDtoTest.java @@ -5,6 +5,8 @@ import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.LiveSystemKubernetesComponentDtoTest; import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.ProviderType; import com.yanchware.fractal.sdk.domain.values.ComponentType; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import com.yanchware.fractal.sdk.utils.TestUtils; import io.github.resilience4j.retry.RetryRegistry; @@ -13,11 +15,12 @@ import java.net.http.HttpClient; import java.util.List; import java.util.Map; +import java.util.UUID; import static com.yanchware.fractal.sdk.utils.TestUtils.assertGenericComponent; import static org.assertj.core.api.Assertions.assertThat; -class LiveSystemHetznerComponentDtoTest extends LiveSystemKubernetesComponentDtoTest { +class LiveSystemHetznerKubernetesDtoTest extends LiveSystemKubernetesComponentDtoTest { @Test public void liveSystemComponentDto_matches_liveSystemComponents_withCorrectTypeForLiveSystem_forHetznerKubernetes() { var factory = new LiveSystemsFactory( @@ -27,7 +30,7 @@ public void liveSystemComponentDto_matches_liveSystemComponents_withCorrectTypeF var hetznerKubernetes = TestUtils.getHetznerKubernetesExample(); var postgres = TestUtils.getGcpPostgresExample(); var liveSystem = factory.builder() - .withId(new LiveSystemIdValue("test", "test")) + .withId(new LiveSystemIdValue(new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"), "test")) .withStandardProvider(ProviderType.HETZNER) .withComponents(List.of(hetznerKubernetes, postgres)) .build(); diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemOkeComponentDtoTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemOkeComponentDtoTest.java index 51aceea6..e7472d6d 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemOkeComponentDtoTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemOkeComponentDtoTest.java @@ -5,6 +5,8 @@ import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.LiveSystemKubernetesComponentDtoTest; import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.ProviderType; import com.yanchware.fractal.sdk.domain.values.ComponentType; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import com.yanchware.fractal.sdk.utils.TestUtils; import io.github.resilience4j.retry.RetryRegistry; @@ -13,6 +15,7 @@ import java.net.http.HttpClient; import java.util.List; import java.util.Map; +import java.util.UUID; import static com.yanchware.fractal.sdk.utils.TestUtils.assertGenericComponent; import static org.assertj.core.api.Assertions.assertThat; @@ -27,7 +30,7 @@ public void liveSystemComponentDto_matches_liveSystemComponents_withCorrectTypeF var oke = TestUtils.getOkeExample(); var postgres = TestUtils.getGcpPostgresExample(); var liveSystem = factory.builder() - .withId(new LiveSystemIdValue("test", "test")) + .withId(new LiveSystemIdValue(new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"), "test")) .withStandardProvider(ProviderType.OCI) .withComponents(List.of(oke, postgres)) .build(); diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemPostgresComponentDtoTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemPostgresComponentDtoTest.java index e6f3972f..d07a3559 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemPostgresComponentDtoTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemPostgresComponentDtoTest.java @@ -5,6 +5,8 @@ import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.LiveSystemComponentDto; import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.ProviderType; import com.yanchware.fractal.sdk.domain.values.ComponentType; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import com.yanchware.fractal.sdk.utils.TestUtils; import io.github.resilience4j.retry.RetryRegistry; @@ -12,6 +14,7 @@ import java.net.http.HttpClient; import java.util.Map; +import java.util.UUID; import static com.yanchware.fractal.sdk.utils.TestUtils.assertGenericComponent; import static org.assertj.core.api.Assertions.assertThat; @@ -26,7 +29,7 @@ public void liveSystemComponentDto_matches_liveSystemComponents_withCorrectTypeF RetryRegistry.ofDefaults()); var postgres = TestUtils.getAzurePostgresExample(); var liveSystem = factory.builder() - .withId(new LiveSystemIdValue("test", "test")) + .withId(new LiveSystemIdValue(new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"), "test")) .withStandardProvider(ProviderType.AZURE) .withComponent(postgres) .build(); diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemServiceTest.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemServiceTest.java index 80a25d2e..c314afaf 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemServiceTest.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/domain/livesystem/LiveSystemServiceTest.java @@ -15,6 +15,7 @@ import com.yanchware.fractal.sdk.domain.livesystem.service.LiveSystemService; import com.yanchware.fractal.sdk.domain.livesystem.service.dtos.ProviderType; import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import com.yanchware.fractal.sdk.utils.LocalSdkConfiguration; import com.yanchware.fractal.sdk.utils.StringHandler; import io.github.resilience4j.retry.RetryRegistry; @@ -33,12 +34,14 @@ public class LiveSystemServiceTest { @Test public void urlPathMatching_when_postRequestToLiveSystem(WireMockRuntimeInfo wmRuntimeInfo) throws InstantiatorException { - HttpClient httpClient = HttpClient.newBuilder() + var httpClient = HttpClient.newBuilder() .version(HttpClient.Version.HTTP_2) .build(); - SdkConfiguration sdkConfiguration = new LocalSdkConfiguration(wmRuntimeInfo.getHttpBaseUrl()); + var sdkConfiguration = new LocalSdkConfiguration(wmRuntimeInfo.getHttpBaseUrl()); var liveSystemsFactory = new LiveSystemsFactory(httpClient, sdkConfiguration, RetryRegistry.ofDefaults()); var liveSystemsService = new LiveSystemService(httpClient, sdkConfiguration, RetryRegistry.ofDefaults()); + var ownerId = UUID.fromString("b2bd7eab-ee3d-4603-86ac-3112ff6b2175"); + var resourceGroupId = new ResourceGroupId(ResourceGroupType.PERSONAL, ownerId, "rg"); var inputStream = getClass().getClassLoader() .getResourceAsStream("test-resources/postRequestToLiveSystemBody.json"); @@ -50,14 +53,14 @@ public void urlPathMatching_when_postRequestToLiveSystem(WireMockRuntimeInfo wmR var managementEnvironment = ManagementEnvironment.builder() .withId(new EnvironmentIdValue( EnvironmentType.PERSONAL, - UUID.fromString("b2bd7eab-ee3d-4603-86ac-3112ff6b2175"), + ownerId, "5d5bc38d-1d23-4d10-8")) .withResourceGroup(ResourceGroupId.fromString("Personal/b2bd7eab-ee3d-4603-86ac-3112ff6b2175/rg")) .build(); var liveSystem = liveSystemsFactory.builder() - .withId(new LiveSystemIdValue("resourceGroupId", "livesystem-name")) - .withFractalId(new FractalIdValue("resourceGroupId", "fractalName", "fractalVersion" )) + .withId(new LiveSystemIdValue(resourceGroupId, "livesystem-name")) + .withFractalId(new FractalIdValue(resourceGroupId, "fractalName", "fractalVersion" )) .withDescription("prod") .withEnvironmentId(managementEnvironment.getId()) .withStandardProvider(ProviderType.AZURE) @@ -99,18 +102,19 @@ public void urlPathMatching_when_getRequestToLiveSystemMutation(WireMockRuntimeI .build(); SdkConfiguration sdkConfiguration = new LocalSdkConfiguration(wmRuntimeInfo.getHttpBaseUrl()); var liveSystemService = new LiveSystemService(httpClient, sdkConfiguration, RetryRegistry.ofDefaults()); - - stubFor(get(urlPathMatching("/livesystems/resourceGroupId/livesystem-name/mutations/mutation-id")) + var resourceGroupId = new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"); + var url = String.format("/livesystems/%s/livesystem-name/mutations/mutation-id", resourceGroupId); + stubFor(get(urlPathMatching(url)) .willReturn(aResponse() .withStatus(200) .withBody("{\"liveSystemId\":\"fancy-group/CompanyCloud\",\"id\":\"a09f1ca7-5ee8-4d53-a187-644146d19479\",\"status\":\"Completed\",\"created\":\"2023-04-13T23:24:29.503384+00:00\",\"lastUpdated\":\"2023-04-13T23:24:29.503384+00:00\",\"componentsReadyIds\":[\"company-cloud\",\"relational-dbms-platform\"],\"componentsCompletedIds\":[],\"componentsFailedIds\":[],\"componentsById\":{\"company-cloud\":{\"status\":\"Instantiating\",\"outputFields\":{\"cluster\":{\"abc\":123}},\"lastUpdated\":\"2023-04-13T23:24:30.948156+00:00\",\"lastOperationRetried\":0,\"provider\":\"Azure\",\"lastOperationStatusMessage\":\"\",\"displayName\":\"AKS instantiation\",\"description\":\"Cloud AKS cluster\",\"type\":\"NetworkAndCompute.PaaS.ContainerPlatform\",\"id\":\"company-cloud\",\"version\":\"1.0\",\"parameters\":{\"region\":\"westeurope\",\"network\":\"network-host\",\"nodePools\":[{\"name\":\"linuxdynamic\",\"osType\":\"LINUX\",\"maxSurge\":1,\"diskSizeGb\":128,\"machineType\":\"STANDARD_B4MS\",\"maxNodeCount\":9,\"minNodeCount\":1,\"agentPoolMode\":\"SYSTEM\",\"maxPodsPerNode\":30,\"initialNodeCount\":1},{\"name\":\"windyn\",\"osType\":\"WINDOWS\",\"maxSurge\":1,\"diskSizeGb\":128,\"machineType\":\"STANDARD_B4MS\",\"maxNodeCount\":9,\"minNodeCount\":1,\"agentPoolMode\":\"USER\",\"maxPodsPerNode\":30,\"initialNodeCount\":1}],\"podsRange\":\"tier-1-pods\",\"subNetwork\":\"compute-tier-1\",\"serviceRange\":\"tier-1-services\"},\"dependencies\":[],\"links\":[]},\"company-controller\":{\"status\":\"Instantiating\",\"outputFields\":{},\"lastUpdated\":\"2023-04-13T23:24:30.948169+00:00\",\"lastOperationRetried\":0,\"provider\":\"Azure\",\"lastOperationStatusMessage\":\"\",\"displayName\":\"Company controller\",\"description\":\"Company controller\",\"type\":\"CustomWorkloads.Caas.K8sWorkload\",\"id\":\"company-controller\",\"version\":\"1.0\",\"parameters\":{\"roles\":[],\"repoId\":\"Company.Cloud/Company.Cloud.Controller\",\"namespace\":\"company-cloud\",\"sshRepositoryURI\":\"git@ssh.dev.azure.com:v3/CompanyCloud/Company.Cloud/Company.Cloud.Controller\",\"containerPlatform\":\"company-cloud\",\"privateSSHKeySecretId\":\"fractalDeployerSshKey\",\"privateSSHKeyPassphraseSecretId\":\"fractalDeployerSshKeyPassphrase\"},\"dependencies\":[\"company-cloud\"],\"links\":[]},\"relational-dbms-platform\":{\"status\":\"Instantiating\",\"outputFields\":{},\"lastUpdated\":\"2023-04-13T23:24:30.948178+00:00\",\"lastOperationRetried\":0,\"provider\":\"Azure\",\"lastOperationStatusMessage\":\"\",\"displayName\":\"Relational DBMS Platform\",\"description\":\"Platform providing RDBMS as a service\",\"type\":\"DataStorage.PaaS.PostgreSQL\",\"id\":\"relational-dbms-platform\",\"version\":\"1.0\",\"parameters\":{\"tier\":\"GP_Gen5_4\",\"region\":\"westeurope\",\"version\":\"11\",\"storageAutoResize\":true},\"dependencies\":[],\"links\":[]}},\"componentsBlocked\":{\"company-cloud\":[\"company-controller\"]}}") .withHeader("Content-Type", "application/json"))); liveSystemService.checkLiveSystemMutationStatus( - new LiveSystemIdValue("resourceGroupId", "livesystem-name"), + new LiveSystemIdValue(resourceGroupId, "livesystem-name"), "mutation-id"); - verify(getRequestedFor(urlPathEqualTo("/livesystems/resourceGroupId/livesystem-name/mutations/mutation-id"))); + verify(getRequestedFor(urlPathEqualTo(url))); } @Test @@ -122,8 +126,9 @@ public void testRetrieveLiveSystem_Success(WireMockRuntimeInfo wmRuntimeInfo) th SdkConfiguration sdkConfiguration = new LocalSdkConfiguration(wmRuntimeInfo.getHttpBaseUrl()); var liveSystemService = new LiveSystemService(httpClient, sdkConfiguration, RetryRegistry.ofDefaults()); + var resourceGroupId = new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"); - LiveSystemIdValue liveSystemId = new LiveSystemIdValue("company", "Development"); + LiveSystemIdValue liveSystemId = new LiveSystemIdValue(resourceGroupId, "Development"); var inputStream = getClass().getClassLoader() .getResourceAsStream("test-resources/getRequestToLiveSystemResponse.json"); @@ -132,7 +137,7 @@ public void testRetrieveLiveSystem_Success(WireMockRuntimeInfo wmRuntimeInfo) th var liveSystemResponse= StringHandler.getStringFromInputStream(inputStream); - stubFor(get(urlPathMatching("/livesystems/company/Development")) + stubFor(get(urlPathMatching(String.format("/livesystems/%s/Development", resourceGroupId))) .willReturn(aResponse() .withStatus(200) .withBody(liveSystemResponse) diff --git a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/utils/TestUtils.java b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/utils/TestUtils.java index 9dcbc284..8b95a335 100644 --- a/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/utils/TestUtils.java +++ b/fractal.sdk/src/test/java/com/yanchware/fractal/sdk/utils/TestUtils.java @@ -38,6 +38,7 @@ import com.yanchware.fractal.sdk.domain.services.contracts.ComponentDto; import com.yanchware.fractal.sdk.domain.values.ComponentId; import com.yanchware.fractal.sdk.domain.values.ResourceGroupId; +import com.yanchware.fractal.sdk.domain.values.ResourceGroupType; import io.github.resilience4j.retry.RetryRegistry; import lombok.extern.slf4j.Slf4j; import org.assertj.core.api.SoftAssertions; @@ -411,13 +412,14 @@ public static Environment getEnvExample() { } public static LiveSystemAggregate getLiveSystemExample() { + var resourceGroupId = new ResourceGroupId(ResourceGroupType.PERSONAL, UUID.randomUUID(), "rg"); var liveSystemsFactory = new LiveSystemsFactory( HttpClient.newBuilder().build(), new LocalSdkConfiguration(""), RetryRegistry.ofDefaults()); return liveSystemsFactory.builder() - .withId(new LiveSystemIdValue("test-resource-group", "business-platform-test")) - .withFractalId(new FractalIdValue("test-resource-group", "business-platform-test", "v1.0")) + .withId(new LiveSystemIdValue(resourceGroupId, "business-platform-test")) + .withFractalId(new FractalIdValue(resourceGroupId, "business-platform-test", "v1.0")) .withDescription("Business platform") .withStandardProvider(ProviderType.AZURE) .withComponent(getAksExample()) diff --git a/fractal.sdk/src/test/resources/test-resources/postRequestToLiveSystemBody.json b/fractal.sdk/src/test/resources/test-resources/postRequestToLiveSystemBody.json index 28341e99..07c3f7d3 100644 --- a/fractal.sdk/src/test/resources/test-resources/postRequestToLiveSystemBody.json +++ b/fractal.sdk/src/test/resources/test-resources/postRequestToLiveSystemBody.json @@ -1,6 +1,6 @@ { - "liveSystemId": "resourceGroupId/livesystem-name", - "fractalId": "resourceGroupId/fractalName:fractalVersion", + "liveSystemId": "Personal/b2bd7eab-ee3d-4603-86ac-3112ff6b2175/rg/livesystem-name", + "fractalId": "Personal/b2bd7eab-ee3d-4603-86ac-3112ff6b2175/rg/fractalName:fractalVersion", "description": "prod", "blueprintMap": { "graph-db-1": {