Skip to content
Snippets Groups Projects
Commit d3d1f69a authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4390 add interceptor to stubs

parent dfd6bae9
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,8 @@ package de.ozgcloud.apilib.common.command.grpc; ...@@ -2,6 +2,8 @@ package de.ozgcloud.apilib.common.command.grpc;
import de.itvsh.ozg.pluto.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub; import de.itvsh.ozg.pluto.grpc.command.CommandServiceGrpc.CommandServiceBlockingStub;
import de.itvsh.ozg.pluto.grpc.command.GrpcGetCommandRequest; import de.itvsh.ozg.pluto.grpc.command.GrpcGetCommandRequest;
import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextAttachingInterceptor;
import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextProvider;
import de.ozgcloud.apilib.common.command.OzgCloudCommand; import de.ozgcloud.apilib.common.command.OzgCloudCommand;
import de.ozgcloud.apilib.common.command.OzgCloudCommandId; import de.ozgcloud.apilib.common.command.OzgCloudCommandId;
import de.ozgcloud.apilib.common.command.OzgCloudCommandService; import de.ozgcloud.apilib.common.command.OzgCloudCommandService;
...@@ -18,13 +20,15 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService { ...@@ -18,13 +20,15 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService {
private final CommandMapper mapper; private final CommandMapper mapper;
private final OzgCloudCallContextProvider contextProvider;
@Override @Override
public OzgCloudCommand createAndWaitUntilDone(OzgCloudCommand commandToCreate) { public OzgCloudCommand createAndWaitUntilDone(OzgCloudCommand commandToCreate) {
return waitUntilDone(create(commandToCreate)); return waitUntilDone(create(commandToCreate));
} }
OzgCloudCommand create(OzgCloudCommand commandToCreate) { OzgCloudCommand create(OzgCloudCommand commandToCreate) {
var created = commandServiceStub.createCommand(mapper.buildCreateCommandRequest(commandToCreate)); var created = getCommandServiceStub().createCommand(mapper.buildCreateCommandRequest(commandToCreate));
return mapper.fromGrpc(created.getCommand()); return mapper.fromGrpc(created.getCommand());
} }
...@@ -46,6 +50,10 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService { ...@@ -46,6 +50,10 @@ public class GrpcOzgCloudCommandService implements OzgCloudCommandService {
private OzgCloudCommand reloadCommand(OzgCloudCommandId commandId) { private OzgCloudCommand reloadCommand(OzgCloudCommandId commandId) {
GrpcGetCommandRequest request = GrpcGetCommandRequest.newBuilder().setId(commandId.toString()).build(); GrpcGetCommandRequest request = GrpcGetCommandRequest.newBuilder().setId(commandId.toString()).build();
return mapper.fromGrpc(commandServiceStub.getCommand(request)); return mapper.fromGrpc(getCommandServiceStub().getCommand(request));
}
CommandServiceBlockingStub getCommandServiceStub() {
return commandServiceStub.withInterceptors(new OzgCloudCallContextAttachingInterceptor(contextProvider));
} }
} }
...@@ -18,6 +18,8 @@ import de.itvsh.ozg.pluto.grpc.binaryFile.GrpcBinaryFilesRequest; ...@@ -18,6 +18,8 @@ import de.itvsh.ozg.pluto.grpc.binaryFile.GrpcBinaryFilesRequest;
import de.itvsh.ozg.pluto.grpc.binaryFile.GrpcFindFilesResponse; import de.itvsh.ozg.pluto.grpc.binaryFile.GrpcFindFilesResponse;
import de.itvsh.ozg.pluto.grpc.binaryFile.GrpcGetBinaryFileDataRequest; import de.itvsh.ozg.pluto.grpc.binaryFile.GrpcGetBinaryFileDataRequest;
import de.itvsh.ozg.pluto.grpc.file.GrpcOzgFile; import de.itvsh.ozg.pluto.grpc.file.GrpcOzgFile;
import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextAttachingInterceptor;
import de.ozgcloud.apilib.common.callcontext.OzgCloudCallContextProvider;
import de.ozgcloud.apilib.common.errorhandling.NotFoundException; import de.ozgcloud.apilib.common.errorhandling.NotFoundException;
import de.ozgcloud.apilib.file.OzgCloudFile; import de.ozgcloud.apilib.file.OzgCloudFile;
import de.ozgcloud.apilib.file.OzgCloudFileId; import de.ozgcloud.apilib.file.OzgCloudFileId;
...@@ -37,13 +39,15 @@ public class GrpcOzgCloudFileService implements OzgCloudFileService { ...@@ -37,13 +39,15 @@ public class GrpcOzgCloudFileService implements OzgCloudFileService {
@GrpcClient("file-manager") @GrpcClient("file-manager")
private final BinaryFileServiceStub asyncServiceStub; private final BinaryFileServiceStub asyncServiceStub;
private final OzgCloudCallContextProvider contextProvider;
private final OzgCloudFileMapper mapper; private final OzgCloudFileMapper mapper;
static final int CHUNK_SIZE = 255 * 1024; static final int CHUNK_SIZE = 255 * 1024;
@Override @Override
public OzgCloudFile getFile(OzgCloudFileId id) { public OzgCloudFile getFile(OzgCloudFileId id) {
var response = blockingStub.findBinaryFilesMetaData(buildFindFileRequest(id)); var response = getBlockingStub().findBinaryFilesMetaData(buildFindFileRequest(id));
return mapper.fromGrpc(getSingleResponse(response, id)); return mapper.fromGrpc(getSingleResponse(response, id));
} }
...@@ -71,7 +75,7 @@ public class GrpcOzgCloudFileService implements OzgCloudFileService { ...@@ -71,7 +75,7 @@ public class GrpcOzgCloudFileService implements OzgCloudFileService {
var streamFuture = new CompletableFuture<Boolean>(); var streamFuture = new CompletableFuture<Boolean>();
var responseObserver = new OzgCloudFileDownloadStreamObserver(streamFuture, streamToWriteData); var responseObserver = new OzgCloudFileDownloadStreamObserver(streamFuture, streamToWriteData);
asyncServiceStub.getBinaryFileContent(buildGrpcGetBinaryFileDataRequest(fileId), responseObserver); getAsyncServiceStub().getBinaryFileContent(buildGrpcGetBinaryFileDataRequest(fileId), responseObserver);
waitUntilFutureToComplete(streamFuture); waitUntilFutureToComplete(streamFuture);
} }
...@@ -90,4 +94,12 @@ public class GrpcOzgCloudFileService implements OzgCloudFileService { ...@@ -90,4 +94,12 @@ public class GrpcOzgCloudFileService implements OzgCloudFileService {
throw new TechnicalException(e.getMessage(), e); throw new TechnicalException(e.getMessage(), e);
} }
} }
BinaryFileServiceBlockingStub getBlockingStub() {
return blockingStub.withInterceptors(new OzgCloudCallContextAttachingInterceptor(contextProvider));
}
BinaryFileServiceStub getAsyncServiceStub() {
return asyncServiceStub.withInterceptors(new OzgCloudCallContextAttachingInterceptor(contextProvider));
}
} }
...@@ -54,6 +54,7 @@ class GrpcOzgCloudCommandServiceTest { ...@@ -54,6 +54,7 @@ class GrpcOzgCloudCommandServiceTest {
@BeforeEach @BeforeEach
void init() { void init() {
when(serviceStub.withInterceptors(any())).thenReturn(serviceStub);
when(serviceStub.createCommand(any())).thenReturn(GrpcCommandResponseTestFactory.create()); when(serviceStub.createCommand(any())).thenReturn(GrpcCommandResponseTestFactory.create());
} }
......
...@@ -34,6 +34,7 @@ class GrpcOzgCloudFileServiceTest { ...@@ -34,6 +34,7 @@ class GrpcOzgCloudFileServiceTest {
class CallGetFile { class CallGetFile {
@BeforeEach @BeforeEach
void init() { void init() {
when(blockingStub.withInterceptors(any())).thenReturn(blockingStub);
when(blockingStub.findBinaryFilesMetaData(any())).thenReturn(GrpcFindFilesResponse.newBuilder().addFile(GrpcOzgFileTestFactory.create()).build()); when(blockingStub.findBinaryFilesMetaData(any())).thenReturn(GrpcFindFilesResponse.newBuilder().addFile(GrpcOzgFileTestFactory.create()).build());
} }
......
...@@ -104,8 +104,8 @@ public class OzgCloudClientAutoConfiguration { ...@@ -104,8 +104,8 @@ public class OzgCloudClientAutoConfiguration {
@Bean @Bean
@ConditionalOnProperty("ozgcloud.command-manager.address") @ConditionalOnProperty("ozgcloud.command-manager.address")
OzgCloudCommandService grpcCommandService(@GrpcClient("command-manager") CommandServiceBlockingStub commandServiceStub, OzgCloudCommandService grpcCommandService(@GrpcClient("command-manager") CommandServiceBlockingStub commandServiceStub,
CommandMapper commandMapper) { CommandMapper commandMapper, OzgCloudCallContextProvider contextProvider) {
return new GrpcOzgCloudCommandService(commandServiceStub, commandMapper); return new GrpcOzgCloudCommandService(commandServiceStub, commandMapper, contextProvider);
} }
@Bean @Bean
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment