/** * Issues an "Info" request to all nodes in the cluster. * @param client * @param infoString * @return */ public static String[] infoAll(AerospikeClient client, String infoString) { String[] messages = new String[client.getNodes().length]; int index = 0; for (Node node : client.getNodes()){ messages[index] = Info.request(node, infoString); } return messages; } /**
@Override public long count(Class<?> type, String setName) { Assert.notNull(type, "Type for count must not be null!"); Node[] nodes = client.getNodes(); int replicationCount = 2; int nodeCount = nodes.length; int n_objects = 0; for (Node node : nodes) { String infoString = Info.request(node, "sets/" + this.namespace + "/" + setName); String n_objectsString = infoString.substring( infoString.indexOf("=") + 1, infoString.indexOf(":")); n_objects = Integer.parseInt(n_objectsString); } return (nodeCount > 1) ? n_objects / replicationCount : n_objects; }
public static Version getServerVersion(AerospikeClient client, InfoPolicy policy) { Node node = client.getNodes()[0]; String response = Info.request(policy, node, "build"); return new Version(response); }
public static Version getServerVersion(AerospikeClient client, InfoPolicy policy) { Node node = client.getNodes()[0]; String response = Info.request(policy, node, "build"); return new Version(response); }
Node node = client.getNodes()[0]; String featuresFilter = "features"; String namespaceFilter = "namespace/" + namespace;
/** * refreshes the cached Namespace information */ public synchronized void refreshNamespaces() { /* * cache namespaces */ if (this.namespaceCache == null) { this.namespaceCache = new TreeMap<String, Namespace>(); Node[] nodes = client.getNodes(); for (Node node : nodes) { try { String namespaceString = Info.request(getInfoPolicy(), node, "namespaces"); if (!namespaceString.isEmpty()) { String[] namespaceList = namespaceString.split(";"); for (String namespace : namespaceList) { Namespace ns = this.namespaceCache.get(namespace); if (ns == null) { ns = new Namespace(namespace); this.namespaceCache.put(namespace, ns); } refreshNamespaceData(node, ns); } } } catch (AerospikeException e) { log.error("Error geting Namespaces ", e); } } } }
@Override public boolean indexExists(String indexName) { //TODO: should be moved to aerospike-client try { Node[] nodes = client.getNodes(); if (nodes.length == 0) { throw new AerospikeException.InvalidNode(); } Node node = nodes[0]; String response = Info.request(node, "sindex/" + namespace + '/' + indexName); return !response.startsWith("FAIL:201"); } catch (AerospikeException e) { DataAccessException translatedException = exceptionTranslator.translateExceptionIfPossible(e); throw translatedException == null ? e : translatedException; } }
/** * Retrieves and sets the server specific parameters * Validates the existence of user provided namespace and validates for single binned * namespaces * * @param client aerospike client used to connect with the server */ public void setServerSpecificParameters(AerospikeClient client) { String namespaceTokens = null; for (Node node : client.getNodes()) { String namespaceFilter = "namespace/" + aerospikeMapping.getNamespace(); namespaceTokens = Info.request(null, node, namespaceFilter); if (namespaceTokens != null) { isSingleBinEnabled = parseBoolean(namespaceTokens, "single-bin"); break; } } if (namespaceTokens == null) { LOG.error("Failed to get namespace info from Aerospike"); throw new RuntimeException("Failed to get namespace info from Aerospike"); } }
/** * Retrieves and sets the server specific parameters * Validates the existence of user provided namespace and validates for single binned * namespaces * * @param client aerospike client used to connect with the server */ public void setServerSpecificParameters(AerospikeClient client) { String namespaceTokens = null; for (Node node : client.getNodes()) { String namespaceFilter = "namespace/" + aerospikeMapping.getNamespace(); namespaceTokens = Info.request(null, node, namespaceFilter); if (namespaceTokens != null) { isSingleBinEnabled = parseBoolean(namespaceTokens, "single-bin"); break; } } if (namespaceTokens == null) { LOG.error("Failed to get namespace info from Aerospike"); throw new RuntimeException("Failed to get namespace info from Aerospike"); } }
/** * Query server configuration, cluster status and namespace configuration. */ @Override public void runExample(AerospikeClient client, Parameters params) throws Exception { Node node = client.getNodes()[0]; GetServerConfig(node, params); console.write(""); GetNamespaceConfig(node, params); }
/** * refreshes the Index cache from the Cluster */ public synchronized void refreshIndexes() { /* * cache index by Bin name */ if (this.indexCache == null) this.indexCache = new TreeMap<String, Index>(); Node[] nodes = client.getNodes(); for (Node node : nodes) { if (node.isActive()) { try { String indexString = Info.request(getInfoPolicy(), node, "sindex"); if (!indexString.isEmpty()) { String[] indexList = indexString.split(";"); for (String oneIndexString : indexList) { Index index = new Index(oneIndexString); this.indexCache.put(index.toKeyString(), index); } } break; } catch (AerospikeException e) { log.error("Error geting Index informaton", e); } } } }
/** * refreshes the Module cache from the cluster. The Module cache contains a list of register UDF modules. */ public synchronized void refreshModules() { if (this.moduleCache == null) this.moduleCache = new TreeMap<String, Module>(); boolean loadedModules = false; Node[] nodes = client.getNodes(); for (Node node : nodes) { try { String packagesString = Info.request(infoPolicy, node, "udf-list"); if (!packagesString.isEmpty()) { String[] packagesList = packagesString.split(";"); for (String pkgString : packagesList) { Module module = new Module(pkgString); String udfString = Info.request(infoPolicy, node, "udf-get:filename=" + module.getName()); module.setDetailInfo(udfString);//gen=qgmyp0d8hQNvJdnR42X3BXgUGPE=;type=LUA;recordContent=bG9jYWwgZnVuY3Rpb24gcHV0QmluKHIsbmFtZSx2YWx1ZSkKICAgIGlmIG5vdCBhZXJvc3Bpa2U6ZXhpc3RzKHIpIHRoZW4gYWVyb3NwaWtlOmNyZWF0ZShyKSBlbmQKICAgIHJbbmFtZV0gPSB2YWx1ZQogICAgYWVyb3NwaWtlOnVwZGF0ZShyKQplbmQKCi0tIFNldCBhIHBhcnRpY3VsYXIgYmluCmZ1bmN0aW9uIHdyaXRlQmluKHIsbmFtZSx2YWx1ZSkKICAgIHB1dEJpbihyLG5hbWUsdmFsdWUpCmVuZAoKLS0gR2V0IGEgcGFydGljdWxhciBiaW4KZnVuY3Rpb24gcmVhZEJpbihyLG5hbWUpCiAgICByZXR1cm4gcltuYW1lXQplbmQKCi0tIFJldHVybiBnZW5lcmF0aW9uIGNvdW50IG9mIHJlY29yZApmdW5jdGlvbiBnZXRHZW5lcmF0aW9uKHIpCiAgICByZXR1cm4gcmVjb3JkLmdlbihyKQplbmQKCi0tIFVwZGF0ZSByZWNvcmQgb25seSBpZiBnZW4gaGFzbid0IGNoYW5nZWQKZnVuY3Rpb24gd3JpdGVJZkdlbmVyYXRpb25Ob3RDaGFuZ2VkKHIsbmFtZSx2YWx1ZSxnZW4pCiAgICBpZiByZWNvcmQuZ2VuKHIpID09IGdlbiB0aGVuCiAgICAgICAgcltuYW1lXSA9IHZhbHVlCiAgICAgICAgYWVyb3NwaWtlOnVwZGF0ZShyKQogICAgZW5kCmVuZAoKLS0gU2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iAgICBlbmQKCiAgICBpZiAodiAlIDUgPT0gMCkgdGhlbgogICAgICAgIHJbbmFtZTJdID0gbmlsCiAgICAgICAgYWVyb3NwaWtlOnVwZGF0ZShyKQogICAgICAgIHJldHVybgogICAgZW5kCgogICAgaWYgKHYgJSAyID09IDApIHRoZW4KICAgICAgICByW25hbWUxXSA9IHYgKyBhZGRWYWx1ZQogICAgICAgIGFlcm9zcGlrZTp1cGRhdGUocikKICAgIGVuZAplbmQKCi0tIFNldCBleHBpcmF0aW9uIG9mIHJlY29yZAotLSBmdW5jdGlvbiBleHBpcmUocix0dGwpCi0tICAgIGlmIHJlY29yZC50dGwocikgPT0gZ2VuIHRoZW4KLS0gICAgICAgIHJbbmFtZV0gPSB2YWx1ZQotLSAgICAgICAgYWVyb3NwaWtlOnVwZGF0ZShyKQotLSAgICBlbmQKLS0gZW5kCg==; this.moduleCache.put(module.getName(), module); } } loadedModules = true; break; } catch (AerospikeException e) { } } if (!loadedModules) { throw new ClusterRefreshError("Cannot find UDF modules"); } }