protected <RemoteInterfaceType, RemoteCallResponseType> MasterResponse<RemoteCallResponseType> requestOnMaster(
            Function<RemoteInterfaceType, Call<RemoteCallResponseType>> remoteInterfaceFunction,
            Function<String, Optional<RemoteInterfaceType>> remoteInterfaceProvider
    ) throws IOException {
        final Node masterNode = nodeService.allActive().values().stream()
                .filter(Node::isMaster)
                .findFirst()
                .orElseThrow(() -> new IllegalStateException("No active master node found"));

        final RemoteInterfaceType remoteInterfaceType = remoteInterfaceProvider.apply(masterNode.getNodeId())
                .orElseThrow(() -> new IllegalStateException("Master node " + masterNode.getNodeId() + " not found"));

        final Call<RemoteCallResponseType> call = remoteInterfaceFunction.apply(remoteInterfaceType);
        final Response<RemoteCallResponseType> response = call.execute();

        final byte[] errorBody = response.errorBody() == null ? null : response.errorBody().bytes();

        return MasterResponse.create(response.isSuccessful(), response.code(), response.body(), errorBody);
    }
protected < RemoteInterfaceType , RemoteCallResponseType > MasterResponse < RemoteCallResponseType > requestOnMaster ( Function < RemoteInterfaceType , Call < RemoteCallResponseType > > remoteInterfaceFunction , Function < String , Optional < RemoteInterfaceType > > remoteInterfaceProvider ) throws IOException { final Node masterNode = nodeService . allActive ( ) . values ( ) . stream ( ) . filter ( Node :: isMaster ) . findFirst ( ) . orElseThrow ( ( ) -> new IllegalStateException ( "No active master node found" ) ) ; final RemoteInterfaceType remoteInterfaceType = remoteInterfaceProvider . apply ( masterNode . getNodeId ( ) ) . orElseThrow ( ( ) -> new IllegalStateException ( "Master node " + masterNode . getNodeId ( ) + " not found" ) ) ; final Call < RemoteCallResponseType > call = remoteInterfaceFunction . apply ( remoteInterfaceType ) ; final Response < RemoteCallResponseType > response = call . execute ( ) ; final byte [ ] errorBody = response . errorBody ( ) == null ? null : response . errorBody ( ) . bytes ( ) ; return MasterResponse . create ( response . isSuccessful ( ) , response . code ( ) , response . body ( ) , errorBody ) ; }
Execute the given remote interface function on the master node.
<p>
This is used to forward an API request to the master node. It is useful in situations where an API call can
only be executed on the master node.
<p>
The returned {@link MasterResponse} object is constructed from the remote response's status code and body.