Search in sources :

Example 1 with UrlQueryStringBuilder

use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.

the class CoreAnalyticsLinkManager method sendLink.

private CompletableFuture<Void> sendLink(HttpMethod method, Map<String, String> link, CoreCommonOptions options, String tracingId) {
    // ensure mutability, and don't modify caller's map
    link = new HashMap<>(link);
    CoreHttpPath path = getLinkPathAndAdjustMap(link);
    UrlQueryStringBuilder form = newForm();
    link.forEach(form::set);
    return httpClient.newRequest(method, path, options).trace(tracingId).form(form).exec(core).exceptionally(t -> {
        throw translateCompilationFailureToInvalidArgument(t);
    }).thenApply(result -> null);
}
Also used : Builder.newForm(com.couchbase.client.core.endpoint.http.CoreHttpRequest.Builder.newForm) AnalyticsErrorContext(com.couchbase.client.core.error.context.AnalyticsErrorContext) HttpMethod(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpMethod) UrlQueryStringBuilder(com.couchbase.client.core.util.UrlQueryStringBuilder) CoreHttpClient(com.couchbase.client.core.endpoint.http.CoreHttpClient) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) RequestTarget(com.couchbase.client.core.msg.RequestTarget) CompilationFailureException(com.couchbase.client.core.error.CompilationFailureException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) InvalidArgumentException(com.couchbase.client.core.error.InvalidArgumentException) CoreHttpPath(com.couchbase.client.core.endpoint.http.CoreHttpPath) CoreCommonOptions(com.couchbase.client.core.endpoint.http.CoreCommonOptions) CbCollections.mapOf(com.couchbase.client.core.util.CbCollections.mapOf) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) CoreHttpResponse(com.couchbase.client.core.endpoint.http.CoreHttpResponse) Map(java.util.Map) CoreHttpPath.path(com.couchbase.client.core.endpoint.http.CoreHttpPath.path) Builder.newQueryString(com.couchbase.client.core.endpoint.http.CoreHttpRequest.Builder.newQueryString) Objects.requireNonNull(java.util.Objects.requireNonNull) Stability(com.couchbase.client.core.annotation.Stability) CbThrowables(com.couchbase.client.core.util.CbThrowables) Core(com.couchbase.client.core.Core) CoreHttpPath(com.couchbase.client.core.endpoint.http.CoreHttpPath) UrlQueryStringBuilder(com.couchbase.client.core.util.UrlQueryStringBuilder)

Example 2 with UrlQueryStringBuilder

use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.

the class CoreBucketManager method convertSettingsToParams.

private UrlQueryStringBuilder convertSettingsToParams(Map<String, String> settings, boolean update) {
    Map<String, String> params = new HashMap<>(settings);
    // The following values must not be changed on update
    if (update) {
        params.remove("name");
        params.remove("bucketType");
        params.remove("conflictResolutionType");
        params.remove("replicaIndex");
        params.remove("storageBackend");
    }
    UrlQueryStringBuilder form = UrlQueryStringBuilder.createForUrlSafeNames();
    params.forEach(form::set);
    return form;
}
Also used : HashMap(java.util.HashMap) UrlQueryStringBuilder(com.couchbase.client.core.util.UrlQueryStringBuilder)

Example 3 with UrlQueryStringBuilder

use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.

the class AsyncUserManager method upsertUser.

public CompletableFuture<Void> upsertUser(User user, UpsertUserOptions options) {
    String username = user.username();
    UrlQueryStringBuilder params = newForm().add("name", user.displayName()).add("roles", user.roles().stream().map(Role::format).collect(Collectors.joining(",")));
    // Versions >= 6.5 treat the absent parameter just like an empty list.
    if (!user.groups().isEmpty()) {
        params.add("groups", String.join(",", user.groups()));
    }
    // Password is required when creating user, but optional when updating existing user.
    user.password().ifPresent(pwd -> params.add("password", pwd));
    return httpClient.put(pathForUser(AuthDomain.LOCAL, username), options.build()).trace(TracingIdentifiers.SPAN_REQUEST_MU_UPSERT_USER).form(params).exec(core).thenApply(response -> null);
}
Also used : UrlQueryStringBuilder(com.couchbase.client.core.util.UrlQueryStringBuilder)

Example 4 with UrlQueryStringBuilder

use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.

the class RateLimitingIntegrationTest method createLimitedScope.

static void createLimitedScope(String name, String bucket, ScopeRateLimits limits) throws Exception {
    Map<String, Object> jsonLimits = new HashMap<>();
    if (limits.kv != null) {
        jsonLimits.put("kv", mapOf("data_size", limits.kv.dataSize));
    }
    if (limits.fts != null) {
        jsonLimits.put("fts", mapOf("num_fts_indexes", limits.fts.numFtsIndexes));
    }
    if (limits.index != null) {
        jsonLimits.put("index", mapOf("num_indexes", limits.index.numIndexes));
    }
    if (limits.clusterManager != null) {
        jsonLimits.put("clusterManager", mapOf("num_collections", limits.clusterManager.numCollections));
    }
    UrlQueryStringBuilder formParams = UrlQueryStringBuilder.create();
    formParams.add("name", name);
    if (!jsonLimits.isEmpty()) {
        formParams.add("limits", Mapper.encodeAsString(jsonLimits));
    }
    CoreHttpClient client = adminCluster.core().httpClient(RequestTarget.manager());
    CoreHttpResponse result = client.post(path("/pools/default/buckets/" + bucket + "/scopes"), CoreCommonOptions.DEFAULT).form(formParams).exec(adminCluster.core()).get();
    assertEquals(ResponseStatus.SUCCESS, result.status());
}
Also used : HashMap(java.util.HashMap) CoreHttpClient(com.couchbase.client.core.endpoint.http.CoreHttpClient) JsonObject(com.couchbase.client.java.json.JsonObject) UrlQueryStringBuilder(com.couchbase.client.core.util.UrlQueryStringBuilder) CoreHttpResponse(com.couchbase.client.core.endpoint.http.CoreHttpResponse)

Example 5 with UrlQueryStringBuilder

use of com.couchbase.client.core.util.UrlQueryStringBuilder in project couchbase-jvm-clients by couchbase.

the class RateLimitingIntegrationTest method createRateLimitedUser.

/**
 * Creates a user which is rate limited to perform the tests.
 */
static void createRateLimitedUser(String username, Limits limits) throws Exception {
    Map<String, Object> jsonLimits = new HashMap<>();
    if (limits.keyValueLimits != null) {
        KeyValueLimits kv = limits.keyValueLimits;
        jsonLimits.put("kv", CbCollections.mapOf("num_connections", kv.numConnections, "num_ops_per_min", kv.numOpsPerMin, "ingress_mib_per_min", kv.ingressMibPerMin, "egress_mib_per_min", kv.egressMibPerMin));
    }
    if (limits.queryLimits != null) {
        QueryLimits query = limits.queryLimits;
        jsonLimits.put("query", mapOf("num_queries_per_min", query.numQueriesPerMin, "num_concurrent_requests", query.numConcurrentRequests, "ingress_mib_per_min", query.ingressMibPerMin, "egress_mib_per_min", query.egressMibPerMin));
    }
    if (limits.searchLimits != null) {
        SearchLimits fts = limits.searchLimits;
        jsonLimits.put("fts", mapOf("num_queries_per_min", fts.numQueriesPerMin, "num_concurrent_requests", fts.numConcurrentRequests, "ingress_mib_per_min", fts.ingressMibPerMin, "egress_mib_per_min", fts.egressMibPerMin));
    }
    if (limits.clusterManagerLimits != null) {
        ClusterManagerLimits cm = limits.clusterManagerLimits;
        jsonLimits.put("clusterManager", mapOf("num_concurrent_requests", cm.numConcurrentRequests, "ingress_mib_per_min", cm.ingressMibPerMin, "egress_mib_per_min", cm.egressMibPerMin));
    }
    UrlQueryStringBuilder formParams = UrlQueryStringBuilder.create();
    formParams.add("password", RL_PASSWORD);
    formParams.add("roles", "admin");
    if (!jsonLimits.isEmpty()) {
        formParams.add("limits", Mapper.encodeAsString(jsonLimits));
    }
    CoreHttpClient client = adminCluster.core().httpClient(RequestTarget.manager());
    CoreHttpResponse result = client.put(path("/settings/rbac/users/local/" + username), CoreCommonOptions.DEFAULT).form(formParams).exec(adminCluster.core()).get();
    assertEquals(ResponseStatus.SUCCESS, result.status());
}
Also used : HashMap(java.util.HashMap) CoreHttpClient(com.couchbase.client.core.endpoint.http.CoreHttpClient) JsonObject(com.couchbase.client.java.json.JsonObject) UrlQueryStringBuilder(com.couchbase.client.core.util.UrlQueryStringBuilder) CoreHttpResponse(com.couchbase.client.core.endpoint.http.CoreHttpResponse)

Aggregations

UrlQueryStringBuilder (com.couchbase.client.core.util.UrlQueryStringBuilder)6 CoreHttpResponse (com.couchbase.client.core.endpoint.http.CoreHttpResponse)4 HashMap (java.util.HashMap)4 CoreHttpClient (com.couchbase.client.core.endpoint.http.CoreHttpClient)3 CoreHttpPath (com.couchbase.client.core.endpoint.http.CoreHttpPath)2 JsonObject (com.couchbase.client.java.json.JsonObject)2 Core (com.couchbase.client.core.Core)1 Stability (com.couchbase.client.core.annotation.Stability)1 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)1 HttpMethod (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpMethod)1 CoreCommonOptions (com.couchbase.client.core.endpoint.http.CoreCommonOptions)1 CoreHttpPath.path (com.couchbase.client.core.endpoint.http.CoreHttpPath.path)1 Builder.newForm (com.couchbase.client.core.endpoint.http.CoreHttpRequest.Builder.newForm)1 Builder.newQueryString (com.couchbase.client.core.endpoint.http.CoreHttpRequest.Builder.newQueryString)1 CompilationFailureException (com.couchbase.client.core.error.CompilationFailureException)1 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)1 InvalidArgumentException (com.couchbase.client.core.error.InvalidArgumentException)1 AnalyticsErrorContext (com.couchbase.client.core.error.context.AnalyticsErrorContext)1 RequestTarget (com.couchbase.client.core.msg.RequestTarget)1 CbCollections.mapOf (com.couchbase.client.core.util.CbCollections.mapOf)1