diff --git a/api-lib-core/src/main/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandService.java b/api-lib-core/src/main/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandService.java index 37eed86704a675810bc035248ce4d6db12b6f529..30e31710620fb14d09c6802bc83386220fdf3876 100644 --- a/api-lib-core/src/main/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandService.java +++ b/api-lib-core/src/main/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandService.java @@ -1,5 +1,6 @@ package de.ozgcloud.apilib.common.command.grpc; +import de.itvsh.kop.common.errorhandling.TechnicalException; import de.itvsh.ozg.pluto.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub; import de.itvsh.ozg.pluto.grpc.command.GrpcGetCommandRequest; import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextAttachingInterceptor; @@ -7,6 +8,7 @@ import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextProvider; import de.ozgcloud.apilib.common.command.OzgCloudCommand; import de.ozgcloud.apilib.common.command.OzgCloudCommandId; import de.ozgcloud.apilib.common.command.OzgCloudCommandService; +import de.ozgcloud.apilib.common.command.OzgCloudCommandStatus; import lombok.RequiredArgsConstructor; import net.devh.boot.grpc.client.inject.GrpcClient; @@ -48,6 +50,9 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService { } } } + if (command.getStatus() == OzgCloudCommandStatus.ERROR) { + throw new TechnicalException("Command (id=%s) failed: %s".formatted(command.getId(), command.getErrorMessage())); + } return command; } diff --git a/api-lib-core/src/test/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandServiceTest.java b/api-lib-core/src/test/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandServiceTest.java index 5b8713e61258819b251af5f3851e61b304a13107..5ca125ef30c8f2c944c54c4f45374c337b050d24 100644 --- a/api-lib-core/src/test/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandServiceTest.java +++ b/api-lib-core/src/test/java/de/ozgcloud/apilib/common/command/grpc/GrpcOzgCloudCommandServiceTest.java @@ -4,12 +4,14 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.Mockito; +import de.itvsh.kop.common.errorhandling.TechnicalException; import de.itvsh.ozg.pluto.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub; import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextProvider; import de.ozgcloud.apilib.common.command.OzgCloudCommand; @@ -55,6 +57,23 @@ class GrpcOzgCloudCommandServiceTest { verify(service).waitUntilDone(created); } + @Test + void shouldTerminateByTimeout() { + var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.PENDING).build(); + doReturn(command).when(service).reloadCommand(any()); + + service.waitUntilDone(command); + + Mockito.verify(service, Mockito.times(2)).reloadCommand(command.getId()); + } + + @Test + void shouldThrowException() { + var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.ERROR).build(); + + Assertions.assertThrows(TechnicalException.class, () -> service.waitUntilDone(command)); + } + @Nested class Create { @@ -100,14 +119,4 @@ class GrpcOzgCloudCommandServiceTest { } } - @Test - void shouldTerminateByTimeout() { - var command = OzgCloudCommandTestFactory.createBuilder().status(OzgCloudCommandStatus.PENDING).build(); - doReturn(command).when(service).reloadCommand(any()); - - service.waitUntilDone(command); - - Mockito.verify(service, Mockito.times(2)).reloadCommand(command.getId()); - } - -} +} \ No newline at end of file