content: /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.flink.streaming.connectors.redis.common.config.handler;
  
  import static org.apache.flink.streaming.connectors.redis.descriptor.RedisValidator.REDIS_MASTER_NAME;
  import static org.apache.flink.streaming.connectors.redis.descriptor.RedisValidator.REDIS_MODE;
  import static org.apache.flink.streaming.connectors.redis.descriptor.RedisValidator.REDIS_SENTINEL;
  import static org.apache.flink.streaming.connectors.redis.descriptor.RedisValidator.SENTINELS_INFO;
  import static org.apache.flink.streaming.connectors.redis.descriptor.RedisValidator.SENTINELS_PASSWORD;
  
  import java.util.Arrays;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Map;
  import java.util.Objects;
  import java.util.Set;
  import org.apache.flink.streaming.connectors.redis.common.config.FlinkJedisConfigBase;
  import org.apache.flink.streaming.connectors.redis.common.config.FlinkJedisSentinelConfig;
  import org.apache.flink.streaming.connectors.redis.common.hanlder.FlinkJedisConfigHandler;
  
  public class FlinkJedisSentinelConfigHandler implements FlinkJedisConfigHandler {
  
      @Override
      public FlinkJedisConfigBase createFlinkJedisConfig(Map<String, String> properties) {
          String masterName = properties.computeIfAbsent(REDIS_MASTER_NAME, null);
          String sentinelsInfo = properties.computeIfAbsent(SENTINELS_INFO, null);
          Objects.requireNonNull(masterName, "master should not be null in sentinel mode");
          Objects.requireNonNull(sentinelsInfo, "sentinels should not be null in sentinel mode");
          Set<String> sentinels = new HashSet<>(Arrays.asList(sentinelsInfo.split(",")));
          String sentinelsPassword = properties.computeIfAbsent(SENTINELS_PASSWORD, null);
          if (sentinelsPassword != null && sentinelsPassword.trim().isEmpty()) {
              sentinelsPassword = null;
          }
          FlinkJedisSentinelConfig flinkJedisSentinelConfig = new FlinkJedisSentinelConfig.Builder()
                  .setMasterName(masterName).setSentinels(sentinels).setPassword(sentinelsPassword)
                  .build();
          return flinkJedisSentinelConfig;
      }
  
      @Override
      public Map<String, String> requiredContext() {
          Map<String, String> require = new HashMap<>();
          require.put(REDIS_MODE, REDIS_SENTINEL);
          return require;
      }
  
      public FlinkJedisSentinelConfigHandler() {
  
      }
  }
  