public void defineIndexRules()

in src/main/java/org/apache/skywalking/banyandb/v1/client/BanyanDBClient.java [533:568]


    public void defineIndexRules(Stream stream, List<IndexRule> indexRules) throws BanyanDBException {
        Preconditions.checkArgument(stream != null, "stream cannot be null");

        IndexRuleMetadataRegistry irRegistry = new IndexRuleMetadataRegistry(checkNotNull(this.channel));
        for (final IndexRule ir : indexRules) {
            try {
                irRegistry.create(ir);
            } catch (BanyanDBException ex) {
                if (ex.getStatus().equals(Status.Code.ALREADY_EXISTS)) {
                    continue;
                }
                throw ex;
            }
        }
        if (indexRules.isEmpty()) {
            return;
        }

        List<String> indexRuleNames = indexRules.stream()
                                                .map(indexRule -> indexRule.getMetadata().getName())
                                                .collect(Collectors.toList());

        IndexRuleBinding binding = IndexRuleBinding.newBuilder()
                                                   .setMetadata(Metadata.newBuilder()
                                                                        .setGroup(
                                                                            stream.getMetadata().getGroup())
                                                                        .setName(
                                                                            stream.getMetadata().getName()))
                                                   .setSubject(Subject.newBuilder()
                                                                      .setName(stream.getMetadata()
                                                                                     .getName())
                                                                      .setCatalog(
                                                                          BanyandbCommon.Catalog.CATALOG_STREAM))
                                                   .addAllRules(indexRuleNames).build();
        this.define(binding);
    }