use of com.aliyun.dysmsapi20170525.Client in project stream-services by Backbase.
the class DbsWebClientConfiguration method dbsWebClient.
/**
* Default Reactive Web Client to be used when interacting with DBS Services. Requires OAuth2 client credentials set
* in application.yml
*
* @param objectMapper The Jackson Object mapper to register serialization and deserialization json
* content.
* @param reactiveOAuth2AuthorizedClientManager Client Manager managing OAuth2 tokens
* @param builder THe Web Client Builder which is already preconfigured using MicroMeter
* instrumentation.
* @return Preconfigured Web Client
*/
@Bean
public WebClient dbsWebClient(ObjectMapper objectMapper, ReactiveOAuth2AuthorizedClientManager reactiveOAuth2AuthorizedClientManager, WebClient.Builder builder, DbsWebClientConfigurationProperties dbsWebClientConfigurationProperties) {
ServerOAuth2AuthorizedClientExchangeFilterFunction oauth2ClientFilter = new ServerOAuth2AuthorizedClientExchangeFilterFunction(reactiveOAuth2AuthorizedClientManager);
oauth2ClientFilter.setDefaultClientRegistrationId(dbsWebClientConfigurationProperties.getDefaultClientRegistrationId());
builder.defaultHeader("Content-Type", MediaType.APPLICATION_JSON.toString()).defaultHeader("Accept", MediaType.APPLICATION_JSON.toString()).filter((clientRequest, exchangeFunction) -> {
final ClientRequest newRequest = Optional.ofNullable(dbsWebClientConfigurationProperties.getAdditionalHeaders()).map(additionalHeaders -> {
log.debug("Adding additional headers: {} from configuration Request: {}", additionalHeaders, clientRequest.url());
return ClientRequest.from(clientRequest).headers(httpHeaders -> httpHeaders.addAll(additionalHeaders)).build();
}).orElse(clientRequest);
return Mono.subscriberContext().flatMap(context -> {
Optional<MultiValueMap<String, String>> forwardHeaders = context.<MultiValueMap<String, String>>getOrEmpty(CONTEXT_KEY_FORWARDED_HEADERS);
log.debug("context contains headers? " + forwardHeaders.isPresent());
log.debug("forward headers:" + forwardHeaders.map(MultiValueMap::toString).orElse("null"));
ClientRequest contextRequest = context.<MultiValueMap<String, String>>getOrEmpty("headers").map(headers -> {
log.debug("Adding additional headers: {} from Reactive subscriber context to Request: {}", headers, clientRequest.url());
return ClientRequest.from(newRequest).headers(httpHeaders -> httpHeaders.addAll(headers)).build();
}).orElse(newRequest);
return exchangeFunction.exchange(contextRequest);
});
}).filter(new CsrfClientExchangeFilterFunction()).filter(oauth2ClientFilter);
if (log.isDebugEnabled()) {
HttpClient httpClient = HttpClient.create().wiretap("reactor.netty.http.client.HttpClient", LogLevel.DEBUG, AdvancedByteBufFormat.TEXTUAL);
builder.clientConnector(new ReactorClientHttpConnector(httpClient));
}
// ensure correct exchange strategy is installed
ExchangeStrategies strategies = ExchangeStrategies.builder().codecs(clientDefaultCodecsConfigurer -> {
Jackson2JsonEncoder encoder = new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON);
Jackson2JsonDecoder decoder = new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON);
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder(encoder);
clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder(decoder);
}).build();
builder.exchangeStrategies(strategies);
return builder.build();
}
use of com.aliyun.dysmsapi20170525.Client in project submarine by apache.
the class ModelManager method transferDescription.
private void transferDescription(ServeSpec spec) {
Client s3Client = new Client();
String modelUniquePath = String.format("%s-%d-%s", spec.getModelName(), spec.getModelVersion(), spec.getModelId());
String res = new String(s3Client.downloadArtifact(String.format("registry/%s/%s/%d/description.json", modelUniquePath, spec.getModelName(), spec.getModelVersion())));
JSONObject description = new JSONObject(res);
TritonModelConfig.ModelConfig.Builder modelConfig = TritonModelConfig.ModelConfig.newBuilder();
modelConfig.setPlatform("pytorch_libtorch");
JSONArray inputs = (JSONArray) description.get("input");
for (int idx = 0; idx < inputs.length(); idx++) {
JSONArray dims = (JSONArray) ((JSONObject) inputs.get(idx)).get("dims");
TritonModelConfig.ModelInput.Builder modelInput = TritonModelConfig.ModelInput.newBuilder();
modelInput.setName("INPUT__" + idx);
modelInput.setDataType(TritonModelConfig.DataType.valueOf("TYPE_FP32"));
dims.forEach(dim -> modelInput.addDims((Integer) dim));
modelConfig.addInput(modelInput);
}
JSONArray outputs = (JSONArray) description.get("output");
for (int idx = 0; idx < outputs.length(); idx++) {
JSONArray dims = (JSONArray) ((JSONObject) outputs.get(idx)).get("dims");
TritonModelConfig.ModelOutput.Builder modelOutput = TritonModelConfig.ModelOutput.newBuilder();
modelOutput.setName("OUTPUT__" + idx);
modelOutput.setDataType(TritonModelConfig.DataType.valueOf("TYPE_FP32"));
dims.forEach(dim -> modelOutput.addDims((Integer) dim));
modelConfig.addOutput(modelOutput);
}
s3Client.logArtifact(String.format("registry/%s/%s/config.pbtxt", modelUniquePath, spec.getModelName()), modelConfig.toString().getBytes());
}
Aggregations