Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand Down Expand Up @@ -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.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class UpdateBlueprintCommandRequest {
Collection<BlueprintComponentDto> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public Collection<String> validate() {
errors.add(NAME_IS_NULL);
}

if (isBlank(id.resourceGroupId())) {
if (id.resourceGroupId() == null) {
errors.add(RESOURCE_GROUP_ID_IS_NULL);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,33 @@
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;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

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");
Expand All @@ -40,41 +44,31 @@ 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
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
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
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;
import org.junit.jupiter.api.Test;

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;
Expand All @@ -35,19 +38,21 @@ 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)
.withHeader("Content-Type", "application/json")));

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -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();
Expand Down
Loading
Loading