Alternate to "tctl admin cluster add-search-attributes" to add new search attributes

  1. Replacing .usePlaintext() with `.useTransportSecurity(); fixed the connectivity issues.
  2. Post that I got "UNIMPLEMENTED" exception. Solved this by setting the package to temporal.server.api.adminservice.v1 in proto file.

Here’s the final proto and java code.

Proto

syntax = "proto3";
package temporal.server.api.adminservice.v1;

enum IndexedValueType {
    INDEXED_VALUE_TYPE_UNSPECIFIED = 0;
    INDEXED_VALUE_TYPE_TEXT = 1;
    INDEXED_VALUE_TYPE_KEYWORD = 2;
    INDEXED_VALUE_TYPE_INT = 3;
    INDEXED_VALUE_TYPE_DOUBLE = 4;
    INDEXED_VALUE_TYPE_BOOL = 5;
    INDEXED_VALUE_TYPE_DATETIME = 6;
}

message AddSearchAttributesRequest {
    map<string, IndexedValueType> search_attributes = 1;
    string index_name = 2;
    bool skip_schema_update = 3;
}

message AddSearchAttributesResponse {
}

service AdminService {
    rpc AddSearchAttributes (AddSearchAttributesRequest) returns (AddSearchAttributesResponse);
}

Java

package temporal.server.api.adminservice.v1;

import io.grpc.ManagedChannel;
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;

public class Service {
    public static void main(String[] args) {
        Service service = new Service();
        String serverUrl = "serverUrl";
        String key = "search_attr_key";
        Temporaladmin.IndexedValueType type = Temporaladmin.IndexedValueType.INDEXED_VALUE_TYPE_TEXT;
        service.addSearchAttr(key, type, serverUrl);
    }

    private void addSearchAttr(String key, Temporaladmin.IndexedValueType type, String serverUrl) {

        ManagedChannel channel = getChannel(serverUrl);

        AdminServiceGrpc.AdminServiceBlockingStub adminServiceBlockingStub = AdminServiceGrpc.newBlockingStub(channel);

        adminServiceBlockingStub.addSearchAttributes(
                Temporaladmin.AddSearchAttributesRequest
                        .newBuilder()
                        .putSearchAttributes(key, type)
                        .build()
        );

    }

    public ManagedChannel getChannel(String serverUrl) {
        NettyChannelBuilder builder =
                NettyChannelBuilder.forTarget(serverUrl)
                        .defaultLoadBalancingPolicy("round_robin")
                        .maxInboundMessageSize(25_000_000)
                        .useTransportSecurity();
        return builder.build();
    }
}
1 Like