gpt4 book ai didi

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

转载 作者:知者 更新时间:2024-03-15 20:00:40 27 4
gpt4 key购买 nike

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

ZkPath介绍

[英]Set of paths which are used by fon.
[中]fon使用的路径集。

代码示例

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

/**
 * Returns the path of the profile.
 * @param version
 * @param id
 * @return
 */
public static String getProfilePath(String version, String id) {
  if (ENSEMBLE_PROFILE_PATTERN.matcher(id).matches()) {
    return ZkPath.CONFIG_ENSEMBLE_PROFILE.getPath(id);
  } else return ZkPath.CONFIG_VERSIONS_PROFILE.getPath(version, id);
}

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

@Override
  public String getValue(String key) {
    if (key.startsWith("zk:")) {
      try {
        return new String(ZkPath.loadURL(curator, key), "UTF-8");
      } catch (Exception e) {
        //ignore and just return null.
      }
    }
    return null;
  }
});

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

curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
exists = exists(curator, ZkPath.CONTAINER.getPath(name)) != null;
if (!exists || force) {
  ZkPath.createContainerPaths(curator, containerName, version, profile);

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

/**
   * Returns the path of the profile.
   * @param version
   * @param id
   * @return
   */
  public static String getPath(String version, String id) {
    if (ENSEMBLE_PROFILE_PATTERN.matcher(id).matches()) {
      return ZkPath.CONFIG_ENSEMBLE_PROFILE.getPath(id);
    } else return ZkPath.CONFIG_VERSIONS_PROFILE.getPath(version, id);
  }
}

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

@Override
  public String getValue(String key) {
    if (key.startsWith("zk:")) {
      try {
        return new String(ZkPath.loadURL(curator, key), "UTF-8");
      } catch (Exception e) {
        //ignore and just return null.
      }
    }
    return null;
  }
});

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

/**
 * Returns the path of the profile.
 * @param version
 * @param id
 * @return
 */
public static String getProfilePath(String version, String id) {
  if (ENSEMBLE_PROFILE_PATTERN.matcher(id).matches()) {
    return ZkPath.CONFIG_ENSEMBLE_PROFILE.getPath(id);
  } else return ZkPath.CONFIG_VERSIONS_PROFILE.getPath(version, id);
}

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

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: jboss-fuse/fabric8

/**
   * Returns the path of the profile.
   * @param version
   * @param id
   * @return
   */
  public static String getPath(String version, String id) {
    if (ENSEMBLE_PROFILE_PATTERN.matcher(id).matches()) {
      return ZkPath.CONFIG_ENSEMBLE_PROFILE.getPath(id);
    } else return ZkPath.CONFIG_VERSIONS_PROFILE.getPath(version, id);
  }
}

代码示例来源: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-core-agent-jclouds

/**
 * Clears {@link Cache} and Zookeeper from all {@link Credentials}.
 */
public synchronized Set<String> keySet() {
  Set<String> keys = new HashSet<String>();
    try {
      keys = new HashSet<String>(getChildren(curator, ZkPath.CLOUD_NODE.getPath()));
    } catch (Exception e) {
      LOGGER.warn("Failed to read from zookeeper jclouds credentials store.", e);
      keys = cache.asMap().keySet();
    }
  return keys;
}

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

@Override
  public InputStream getInputStream() throws IOException {
    assertValid();
    try {
      return new ByteArrayInputStream(ZkPath.loadURL(curator.get(), url.toString()));
    } catch (Exception e) {
      LOGGER.error("Error opening zookeeper url", e);
      throw (IOException) new IOException("Error opening zookeeper url").initCause(e);
    }
  }
}

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

@Override
  public Credentials setValue(Credentials credentials) {
    try {
      setData(curator, ZkPath.CLOUD_NODE_IDENTITY.getPath(normalizeKey(key)), credentials.identity);
      setData(curator, ZkPath.CLOUD_NODE_CREDENTIAL.getPath(normalizeKey(key)), credentials.credential);
    } catch (Exception e) {
      LOGGER.warn("Failed to store jclouds credentials to zookeeper.", e);
    }
    return credentials;
  }
}

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

@Override
  public InputStream getInputStream() throws IOException {
    assertValid();
    try {
      return new ByteArrayInputStream(ZkPath.loadURL(curator.get(), url.toString()));
    } catch (Exception e) {
      LOGGER.error("Error opening zookeeper url", e);
      throw (IOException) new IOException("Error opening zookeeper url").initCause(e);
    }
  }
}

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

private void releaseLock(Lease lease) {
  try {
    if (interProcessLock != null) {
      interProcessLock.returnLease(lease);
    }
  } catch (Exception e) {
    LOGGER.debug("Couldn't realease lock for " + ZkPath.PORTS_LOCK.getPath(), e);
  }
}

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

@Override
  public String resolve(FabricService fabricService, Map<String, Map<String, String>> configs, String pid, String key, String value) {
    try {
      return new String(ZkPath.loadURL(fabricService.adapt(CuratorFramework.class), value), "UTF-8");
    } catch (KeeperException.NoNodeException e) {
      LOGGER.warn("Could not load property value: {}. Ignoring.", value, e);
      return "";
    } catch (Exception e) {
      throw FabricException.launderThrowable(e);
    }
  }
}

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

/**
 * Checks if the container should react to a change in the specified path.
 */
private boolean shouldRunCallbacks(PathChildrenCacheEvent.Type type, String path) {
  if (path == null) {
    return false;
  }
  String runtimeIdentity = runtimeProperties.get().getRuntimeIdentity();
  String currentVersion = getContainerVersion(runtimeIdentity);
  return (path.startsWith(ZkPath.CONTAINERS.getPath()) && type.equals(PathChildrenCacheEvent.Type.CHILD_UPDATED)) ||
          path.equals(ZkPath.CONFIG_ENSEMBLES.getPath()) ||
          path.equals(ZkPath.CONFIG_ENSEMBLE_URL.getPath()) ||
          path.equals(ZkPath.CONFIG_ENSEMBLE_PASSWORD.getPath()) ||
          path.equals(ZkPath.CONFIG_CONTAINER.getPath(runtimeIdentity)) ||
          (currentVersion != null && path.equals(ZkPath.CONFIG_VERSIONS_CONTAINER.getPath(currentVersion, runtimeIdentity)));
}

代码示例来源: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: io.fabric8/fabric-core-agent-jclouds

/**
 * Puts {@link Credentials} both in {@link Cache} and the Zookeeper.
 */
public synchronized Credentials put(String s, Credentials credentials) {
  cache.put(s, credentials);
  try {
    setData(curator, ZkPath.CLOUD_NODE_IDENTITY.getPath(normalizeKey(s)), credentials.identity);
    setData(curator, ZkPath.CLOUD_NODE_CREDENTIAL.getPath(normalizeKey(s)), credentials.credential);
  } catch (Exception e) {
    LOGGER.warn("Failed to store jclouds credentials to zookeeper.", e);
  }
  return credentials;
}

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

/**
 * Checks if {@link Cache} container the key and if not it checks the Zookeeper (if connected).
 */
public synchronized boolean containsKey(Object o) {
  boolean result  = cache.asMap().containsKey(o);
  //If not found in the cache check the zookeeper if available.
  if (!result) {
    try {
      result = (exists(curator, ZkPath.CLOUD_NODE.getPath(normalizeKey(o))) != null);
    } catch (Exception ex) {
      //noop
    }
  }
  return result;
}

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

public static void createContainerPaths(CuratorFramework curator, String container, String version, String profiles) throws Exception {
    boolean versionProvided = version != null;

    String v = version;
    //Try to find the version to use
    if (v == null && exists(curator, CONFIG_CONTAINER.getPath(container)) != null) {
      //Try to acquire the version from the registry path /fabric/configs/containers/{container}
      v = getStringData(curator, CONFIG_CONTAINER.getPath(container));
    }  else if (exists(curator, CONFIG_DEFAULT_VERSION.getPath()) != null) {
      //If version is still null, try the default version.
      v = getStringData(curator, CONFIG_DEFAULT_VERSION.getPath());
    } else {
      //Else assume version 1.0.
      v = ZkDefs.DEFAULT_VERSION;
    }

    //Set the version
    if (exists(curator, ZkPath.CONFIG_CONTAINER.getPath(container)) == null || versionProvided) {
      setData(curator, ZkPath.CONFIG_CONTAINER.getPath(container), v);
    }

    //Set the profiles
    if (profiles != null && !profiles.isEmpty() && exists(curator, ZkPath.CONFIG_VERSIONS_CONTAINER.getPath(v, container)) == null) {
      setData(curator, ZkPath.CONFIG_VERSIONS_CONTAINER.getPath(v, container), profiles);
    }
  }
}

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