gpt4 book ai didi

io.fabric8.zookeeper.utils.ZooKeeperUtils类的使用及代码示例

转载 作者:知者 更新时间:2024-03-16 12:38:40 26 4
gpt4 key购买 nike

本文整理了Java中io.fabric8.zookeeper.utils.ZooKeeperUtils类的一些代码示例,展示了ZooKeeperUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperUtils类的具体详情如下:
包路径:io.fabric8.zookeeper.utils.ZooKeeperUtils
类名称:ZooKeeperUtils

ZooKeeperUtils介绍

暂无

代码示例

代码示例来源:origin: io.fabric8/fabric-zookeeper

public static String getSubstitutedPath(final CuratorFramework curator, String path) throws Exception {
  String normalized = path != null && path.contains("#") ? path.substring(0, path.lastIndexOf('#')) : path;
  if (normalized != null && exists(curator, normalized) != null) {
    byte[] data = ZkPath.loadURL(curator, path);
    if (data != null && data.length > 0) {
      String str = new String(ZkPath.loadURL(curator, path), "UTF-8");
      return getSubstitutedData(curator, str);
    }
  }
  return null;
}

代码示例来源:origin: io.fabric8/fabric-zookeeper

public static Properties getContainerTokens(CuratorFramework curator) throws Exception {
  Properties props = new Properties();
  if (exists(curator, CONTAINERS_NODE) != null) {
    for (String key : getChildren(curator, CONTAINERS_NODE)) {
      props.setProperty("container#" + key, getStringData(curator, CONTAINERS_NODE + "/" + key));
    }
  }
  return props;
}

代码示例来源:origin: io.fabric8/fabric-zookeeper

public static void copy(CuratorFramework curator, String from, String to) throws Exception {
  for (String child : curator.getChildren().forPath(from)) {
    String fromChild = from + "/" + child;
    String toChild = to + "/" + child;
    if (curator.checkExists().forPath(toChild) == null) {
      byte[] data = curator.getData().forPath(fromChild);
      setData(curator, toChild, data);
      copy(curator, fromChild, toChild);
    }
  }
}

代码示例来源:origin: io.fabric8/fabric-zookeeper

public void deleteData(String path) throws Exception {
    if (ZooKeeperUtils.exists(curator, path) != null) {
      LOG.info("unregistered web app at " + path);
      ZooKeeperUtils.deleteSafe(curator, path);
    }
    cache.remove(path);
  }
}

代码示例来源:origin: jboss-fuse/fabric8

protected void removeZkPath(String path) throws Exception {
  CuratorFramework curator = this.curator.get();
  if (curator != null && ZooKeeperUtils.exists(curator, path) != null) {
    LOGGER.info("Unregister API at " + path);
    ZooKeeperUtils.deleteSafe(curator, path);
  }
  registeredZkPaths.remove(path);
}

代码示例来源:origin: io.fabric8/fabric-zookeeper

public static void deleteSafe(CuratorFramework curator, String path) throws Exception {
  if (curator.checkExists().forPath(path) != null) {
    for (String child : curator.getChildren().forPath(path)) {
      deleteSafe(curator, path + "/" + child);
    }
    try {
      curator.delete().forPath(path);
    } catch (KeeperException.NotEmptyException ex) {
      deleteSafe(curator, path);
    }
  }
}

代码示例来源:origin: io.fabric8/fabric-zookeeper

try {
  curator = createCuratorFramework(connectionUrl, options);
  curator.start();
  curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    ZooKeeperUtils.setData(curator, ZkPath.CONFIG_DEFAULT_VERSION.getPath(), versionId);
    ZooKeeperUtils.setData(curator, ZkPath.CONFIG_ENSEMBLE_URL.getPath(), "${zk:" + name + "/ip}:" + zooKeeperServerConnectionPort);
    ZooKeeperUtils.setData(curator, ZkPath.CONFIG_ENSEMBLE_PASSWORD.getPath(), PasswordEncoder.encode(options.getZookeeperPassword()));
    profileRegistry.createProfile(serverProfileBuilder.getProfile());
    ZooKeeperUtils.setData(curator, ZkPath.CONFIG_ENSEMBLES.getPath(), "0000");
    ZooKeeperUtils.setData(curator, ZkPath.CONFIG_ENSEMBLE.getPath("0000"), name);
  ZooKeeperUtils.createDefault(curator, ZkPath.CONFIG_CONTAINER.getPath(name), versionId);
  ZooKeeperUtils.createDefault(curator, ZkPath.CONFIG_VERSIONS_CONTAINER.getPath(versionId, name), profilesBuilder.toString());
  ZooKeeperUtils.createDefault(curator, "/fabric/authentication/encryption.enabled", Boolean.valueOf(encryption != null).toString());
  ZooKeeperUtils.createDefault(curator, "/fabric/authentication/domain", "karaf");
  ZooKeeperUtils.createDefault(curator, ZkPath.AUTHENTICATION_CRYPT_ALGORITHM.getPath(), "PBEWithMD5AndDES");
  ZooKeeperUtils.createDefault(curator, ZkPath.AUTHENTICATION_CRYPT_PASSWORD.getPath(), PasswordEncoder.encode(options.getZookeeperPassword()));
  curator.close();

代码示例来源:origin: io.fabric8.runtime/fabric-runtime-container-wildfly-registration

private void checkAlive() throws Exception {
  RuntimeProperties sysprops = runtimeProperties.get();
  String runtimeIdentity = sysprops.getRuntimeIdentity();
  String nodeAlive = CONTAINER_ALIVE.getPath(runtimeIdentity);
  Stat stat = ZooKeeperUtils.exists(curator.get(), nodeAlive);
  if (stat != null) {
    if (stat.getEphemeralOwner() != curator.get().getZookeeperClient().getZooKeeper().getSessionId()) {
      ZooKeeperUtils.delete(curator.get(), nodeAlive);
      ZooKeeperUtils.create(curator.get(), nodeAlive, CreateMode.EPHEMERAL);
    }
  } else {
    ZooKeeperUtils.create(curator.get(), nodeAlive, CreateMode.EPHEMERAL);
  }
}

代码示例来源:origin: io.fabric8/fabric-zookeeper

public static void add(CuratorFramework curator, String path, String value) throws Exception {
  if (curator.checkExists().forPath(path) == null) {
    curator.setData().forPath(path, value != null ? value.getBytes(UTF_8) : null);
  } else {
    String data = getStringData(curator, path);
    if (data == null) {
      data = "";
    }
    if (data.length() > 0) {
      data += " ";
    }
    data += value;
    curator.setData().forPath(path, data.getBytes(UTF_8));
  }
}

代码示例来源:origin: jboss-fuse/fabric8

protected String getFirstService(String containerPath) throws Exception {
  CuratorFramework curatorFramework = curator.get();
  if (curatorFramework != null) {
    byte[] data = curatorFramework.getData().forPath(containerPath);
    if (data != null && data.length > 0) {
      String text = new String(data).trim();
      if (!text.isEmpty()) {
        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> map = mapper.readValue(data, HashMap.class);
        Object serviceValue = map.get("services");
        if (serviceValue instanceof List) {
          List services = (List) serviceValue;
          if (!services.isEmpty()) {
            List<String> serviceTexts = new ArrayList<String>();
            for (Object service : services) {
              String serviceText = getSubstitutedData(curatorFramework, service.toString());
              if (io.fabric8.common.util.Strings.isNotBlank(serviceText)) {
                return serviceText;
              }
            }
          }
        }
      }
    }
  }
  return null;
}

代码示例来源:origin: jboss-fuse/fabric8

private String getWebUrl(String containerPath) throws Exception {
  if (curator.get().checkExists().forPath(containerPath) != null) {
    byte[] bytes = ZkPath.loadURL(curator.get(), containerPath);
    String text = new String(bytes);
    // NOTE this is a bit naughty, we should probably be doing
    // Jackson parsing here; but we only need 1 String and
    // this avoids the jackson runtime dependency - its just a bit brittle
    // only finding http endpoints and all
    String prefix = "\"services\":[\"";
    int idx = text.indexOf(prefix);
    String answer = text;
    if (idx > 0) {
      int startIndex = idx + prefix.length();
      int endIdx = text.indexOf("\"]", startIndex);
      if (endIdx > 0) {
        answer = text.substring(startIndex, endIdx);
        if (answer.length() > 0) {
          // lets expand any variables
          answer = ZooKeeperUtils.getSubstitutedData(curator.get(), answer);
          return answer;
        }
      }
    }
  }
  return null;
}

代码示例来源:origin: jboss-fuse/fabric8

private void registerDomains() throws Exception {
  String runtimeIdentity = runtimeProperties.get().getRuntimeIdentity();
  String domainsNode = CONTAINER_DOMAINS.getPath(runtimeIdentity);
  try {
    Stat stat = exists(curator.get(), domainsNode);
    if (stat != null) {
      try {
        deleteSafe(curator.get(), domainsNode);
      } catch (IllegalStateException e) {
        handleException(e);
      }
    }
    synchronized (this) {
      domains.addAll(Arrays.asList(mbeanServer.get().getDomains()));
      for (String domain : domains) {
        try {
          setData(curator.get(), CONTAINER_DOMAIN.getPath(runtimeIdentity, domain), "", CreateMode.EPHEMERAL);
        } catch (IllegalStateException e) {
          handleException(e);
        }
      }
    }
  } catch (IllegalStateException e){
    handleException(e);
  }
}

代码示例来源:origin: jboss-fuse/fabric8

private void zkCleanUp(Group<GitNode> group) {
  try {
    RuntimeProperties sysprops = runtimeProperties.get();
    String runtimeIdentity = sysprops.getRuntimeIdentity();
    curator.get().newNamespaceAwareEnsurePath(ZkPath.GIT.getPath()).ensure(curator.get().getZookeeperClient());
    List<String> allChildren = ZooKeeperUtils.getAllChildren(curator.get(), ZkPath.GIT.getPath());
    for (String path : allChildren) {
      String stringData = ZooKeeperUtils.getStringData(curator.get(), path);
      if (stringData.contains("\"container\":\"" + runtimeIdentity + "\"")) {
        LOGGER.info("Found older ZK \"/fabric/registry/clusters/git\" entry for node " + runtimeIdentity);
        ZooKeeperUtils.delete(curator.get(), path);
        LOGGER.info("Older ZK \"/fabric/registry/clusters/git\" entry for node " + runtimeIdentity + " has been removed");
      }
    }
  } catch (KeeperException.NoNodeException ignored) {
  } catch (Exception e) {
    handleException( e);
  }
}

代码示例来源:origin: jboss-fuse/fabric8

@Override
public String getDefaultJvmOptions() {
  assertValid();
  try {
    CuratorFramework curatorFramework = curator.get();
    if (curatorFramework.getZookeeperClient().isConnected() && exists(curatorFramework, JVM_OPTIONS_PATH) != null) {
      return getStringData(configCache, JVM_OPTIONS_PATH);
    } else {
      return "";
    }
  } catch (Exception e) {
    throw FabricException.launderThrowable(e);
  }
}

代码示例来源:origin: jboss-fuse/fabric8

if (curator.get().getZookeeperClient().isConnected()) {
  Version defaultVersion = getDefaultVersion();
  if (defaultVersion != null) {
      Map<String, String> zookeeperConfig = profile.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID);
      if (zookeeperConfig != null) {
        zooKeeperUrl = getSubstitutedData(curator.get(), zookeeperConfig.get(name));
  Configuration config = configAdmin.get().getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
  zooKeeperUrl = (String) config.getProperties().get(name);
} catch (Exception e) {

代码示例来源:origin: jboss-fuse/fabric8

@Override
public void setDefaultVersion(String versionId) {
  assertValid();
  try {
    setData(curator.get(), ZkPath.CONFIG_DEFAULT_VERSION.getPath(), versionId);
  } catch (Exception e) {
    throw FabricException.launderThrowable(e);
  }
}

代码示例来源:origin: io.fabric8/fabric-git-server

private void updateMasterUrl(Group<GitNode> group) {
  try {
    if (group.isMaster()) {
      LOGGER.debug("Git repo is the master");
      if (!isMaster.getAndSet(true)) {
        registerServlet(dataPath, realm, role);
      }
    } else {
      LOGGER.debug("Git repo is not the master");
      if (isMaster.getAndSet(false)) {
        unregisterServlet();
      }
    }
    GitNode state = createState();
    group.update(state);
    String url = state.getUrl();
    gitRemoteUrl.set(ZooKeeperUtils.getSubstitutedData(curator.get(), url));
  } catch (Exception e) {
    // Ignore
  }
}

代码示例来源:origin: io.fabric8/fabric-core-agent-jclouds

@Override
protected Object doExecute() throws Exception {
  boolean connected = getCurator().getZookeeperClient().isConnected();
  Container current = null;
  if (connected) {
    deleteSafe(getCurator(), ZkPath.CLOUD_SERVICE.getPath(name));
    current = fabricService.getCurrentContainer();
  }
  //Remove compute configurations for the service.
  Configuration[] computeConfigs = findConfigurationByFactoryPid("org.jclouds.compute");
  if (computeConfigs != null) {
    for (Configuration configuration : computeConfigs) {
      Dictionary props = configuration.getProperties();
      if (props != null) {
        String contextName = (String) props.get(Constants.NAME);
        if (name.equals(contextName)) {
          configuration.delete();
        }
      }
    }
  }
  return null;
}

代码示例来源:origin: jboss-fuse/fabric8

private String getContainerResolutionPolicy(CuratorFramework zooKeeper, String container) throws Exception {
  String policy = null;
  List<String> validResolverList = Arrays.asList(ZkDefs.VALID_RESOLVERS);
  if (exists(zooKeeper, ZkPath.CONTAINER_RESOLVER.getPath(container)) != null) {
    policy = getStringData(zooKeeper, ZkPath.CONTAINER_RESOLVER.getPath(container));
  } else if (bootstrapConfiguration.get().getLocalResolver() != null && validResolverList.contains(bootstrapConfiguration.get().getLocalResolver())) {
    policy = bootstrapConfiguration.get().getLocalResolver();
  }
  return policy;
}

代码示例来源:origin: jboss-fuse/fabric8

createDefault(curator.get(), containerPortsPath, portAsString);
createDefault(curator.get(), ipPortsPath, portAsString);
setData(curator.get(), containerPortsPath, portAsString);
String existingPorts = getStringData(curator.get(), ipPortsPath);
if (!existingPorts.contains(portAsString)) {
  setData(curator.get(), ipPortsPath, existingPorts + " " + portAsString);
  createDefault(curator.get(), reservedPortsPath, portAsString);
  String reservedPortsPerContainer = getStringData(curator.get(), reservedPortsPath);
  if (!reservedPortsPerContainer.contains(portAsString)) {
    setData(curator.get(), reservedPortsPath, reservedPortsPerContainer + " " + portAsString);

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com