void procesBuffer() { try { StringBuilder bulkRequest = new StringBuilder(); for (Document document : buffer) { Map<String, Object> jsonDocument = mapToJson(document); if (jsonDocument.isEmpty()) { continue; } String id; if (Strings.isStringEmpty(idField)) { id = UUID.randomUUID().toString(); } else { id = document.getFieldValue(idField); } String index = ElasticHelper.getIndexFromUrl(location); String type = ElasticHelper.getTypeFromUrl(location); String bulkMethod = createBulkMethod("index", index, type, id); String json = gson.toJson(jsonDocument); bulkRequest.append(bulkMethod).append(" \n"); bulkRequest.append(json).append(" \n"); } String bulkUrl = ElasticHelper.getBulkUrl(location); HTTPHelper.post(bulkUrl, bulkRequest.toString()); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
protected String getConfigurationURL(boolean external) throws FileNotFoundException { String confURL = external ? externalConfigurationURL: internalConfigurationURL; if (Strings.isStringEmpty(confURL)) { throw new FileNotFoundException("No configuration URL"); } return confURL; }
protected String getExportURL(boolean external) throws FileNotFoundException { String confURL = external ? externalExportsURL: internalExportsURL; if (Strings.isStringEmpty(confURL)) { throw new FileNotFoundException("No configuration URL"); } return confURL; }
private void validateClusters(final ConfigProblemSetBuilder problems, final DCOSAccount account) { final NodeIterator children = account.getParent().getChildren(); Node n = children.getNext(); Set<String> definedClusters = new HashSet<>(); while (n != null) { if (n instanceof DCOSCluster) { definedClusters.add(((DCOSCluster) n).getName()); } n = children.getNext(); } final Set<String> accountClusters = account.getClusters().stream().map(c -> c.getName()) .collect(Collectors.toSet()); accountClusters.removeAll(definedClusters); accountClusters.forEach(c -> problems.addProblem(ERROR, "Cluster \"" + c.toString() + "\" not defined for provider") .setRemediation("Add cluster to the provider or remove from the account") .setOptions(Lists.newArrayList(definedClusters))); Set<List<String>> credentials = new HashSet<>(); account.getClusters().forEach(c -> { final List<String> key = Lists.newArrayList(c.getName(), c.getUid()); if (credentials.contains(key)) { problems.addProblem(ERROR, "Account contains duplicate credentials for cluster \"" + c.getName() + "\" and user id \"" + c.getUid() + "\".").setRemediation("Remove the duplicate credentials"); } else { credentials.add(key); } // TODO(willgorman) once we have the clouddriver-dcos module pulled in we can just validate whether or not // we can connect without a password if (Strings.isStringEmpty(c.getPassword()) && Strings.isStringEmpty(c.getServiceKeyFile())) { problems.addProblem(WARNING, "Account has no password or service key. Unless the cluster has security disabled this may be an error") .setRemediation("Add a password or service key."); } if (!Strings.isStringEmpty(c.getPassword()) && !Strings.isStringEmpty(c.getServiceKeyFile())) { problems.addProblem(ERROR, "Account has both a password and service key") .setRemediation("Remove either the password or service key."); } if (!Strings.isStringEmpty(c.getServiceKeyFile())) { String resolvedServiceKey = ValidatingFileReader.contents(problems, c.getServiceKeyFile()); if (Strings.isStringEmpty(resolvedServiceKey)) { problems.addProblem(ERROR, "The supplied service key file does not exist or is empty.") .setRemediation("Supply a valid service key file."); } } }); }
public boolean isConfigured() { return !Strings.isStringEmpty(namespace) && !Strings.isStringEmpty(connectionString); }
/** * Does a bonded registry retriever have a configuration? * @param external flag to indicate that it is the external entries to fetch * @return true if there is a URL to the configurations defined */ public boolean hasConfigurations(boolean external) { return !Strings.isStringEmpty( external ? externalConfigurationURL : internalConfigurationURL); }