List of usage examples for java.util Spliterators spliteratorUnknownSize
public static Spliterator.OfDouble spliteratorUnknownSize(PrimitiveIterator.OfDouble iterator, int characteristics)
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraAssignmentsRepository.java
Stream<ExperimentUserByUserIdContextAppNameExperimentId> getUserIndexStream(String userId, String appName, String context) {// ww w .j a v a 2 s . c o m Stream<ExperimentUserByUserIdContextAppNameExperimentId> resultStream = Stream.empty(); try { final Result<ExperimentUserByUserIdContextAppNameExperimentId> result = experimentUserIndexAccessor .selectBy(userId, appName, context); resultStream = StreamSupport .stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not retrieve assignments for " + "experimentID = \"" + appName + "\" userID = \"" + userId + "\" and context " + context, e); } return resultStream; }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java
@Override public ExperimentPageList getExperimentPages(Experiment.ID experimentID) { ExperimentPageList experimentPageList = new ExperimentPageList(); try {//from ww w . j a v a 2s. c o m Result<PageExperimentByAppNamePage> result = experimentPageAccessor.selectBy(experimentID.getRawID()); Stream<PageExperimentByAppNamePage> resultList = StreamSupport .stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); List<ExperimentPage> experimentPages = resultList .map(t -> ExperimentPage.withAttributes(Page.Name.valueOf(t.getPage()), t.isAssign()).build()) .collect(Collectors.toList()); experimentPageList.setPages(experimentPages); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not retrieve the pages for experiment: \"" + experimentID + "\"", e); } return experimentPageList; }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java
@Override public List<PageExperiment> getExperiments(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try {/*from w w w . ja v a 2 s. c o m*/ Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor .selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport .stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException( new StringBuilder("Could not retrieve the experiments for applicationName:\"") .append(applicationName).append("\", page:\"").append(pageName).append("\"").toString(), e); } //TODO: make the experiment label part of the pageExperimentIndex to save a query per page return resultList.map(t -> { Optional<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experiment = Optional .ofNullable(experimentAccessor.selectBy(t.getExperimentId()).one()); PageExperiment.Builder builder = new PageExperiment.Builder(Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign()); if (experiment.isPresent()) { builder.setLabel(Experiment.Label.valueOf(experiment.get().getLabel())); } return builder.build(); }).filter(t -> t.getLabel() != null).collect(Collectors.toList()); }
From source file:io.syndesis.dao.DeploymentDescriptorTest.java
private static void assertActionProperties(final String connectorId, final JsonNode action, final String actionName, final JsonNode catalogedJsonSchema) { final JsonNode actionDefinition = action.get("definition"); final JsonNode propertiesFromCatalog = catalogedJsonSchema.get("properties"); // make sure that all action properties are as defined in // the connector StreamSupport.stream(actionDefinition.get("propertyDefinitionSteps").spliterator(), true) .flatMap(step -> StreamSupport.stream(Spliterators .spliteratorUnknownSize(step.get("properties").fields(), Spliterator.CONCURRENT), true)) .forEach(property -> {//w ww . ja v a 2s .c o m final String propertyName = property.getKey(); final JsonNode propertyDefinition = property.getValue(); final JsonNode catalogedPropertyDefinition = propertiesFromCatalog.get(propertyName); assertThat(catalogedPropertyDefinition).as( "Definition of `%s` connector's action `%s` defines a property `%s` that is not defined in the Camel connector", connectorId, actionName, propertyName).isNotNull(); assertThat(propertyDefinition.get("componentProperty")) .as("`componentProperty` field is missing for connector's %s %s action property %s", connectorId, actionName, propertyName) .isNotNull(); assertThat(propertyDefinition.get("componentProperty").asBoolean()).as( "Definition of `%s` connector's action `%s` property `%s` should be marked as `componentProperty`", connectorId, actionName, propertyName).isFalse(); // remove Syndesis specifics final ObjectNode propertyDefinitionForComparisson = propertyNodeForComparisson( propertyDefinition); // remove properties that we would like to customize removeCustomizedProperties(propertyDefinitionForComparisson, catalogedPropertyDefinition); assertThat(propertyDefinitionForComparisson).as( "Definition of `%s` connector's action's `%s` property `%s` differs from the one in Camel connector", connectorId, actionName, propertyName).isEqualTo(catalogedPropertyDefinition); }); }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java
@Override public List<PageExperiment> getExperimentsWithoutLabels(Application.Name applicationName, Page.Name pageName) { Stream<PageExperimentByAppNamePage> resultList = Stream.empty(); try {// www .j av a 2 s.com Result<PageExperimentByAppNamePage> result = pageExperimentIndexAccessor .selectBy(applicationName.toString(), pageName.toString()); resultList = StreamSupport .stream(Spliterators.spliteratorUnknownSize(result.iterator(), Spliterator.ORDERED), false); } catch (ReadTimeoutException | UnavailableException | NoHostAvailableException e) { throw new RepositoryException("Could not retrieve the experiments for applicationName:\"" + applicationName + "\", page:\"" + pageName, e); } return resultList.map(t -> { PageExperiment.Builder builder = new PageExperiment.Builder(Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign()); return builder.build(); }).collect(Collectors.toList()); }
From source file:com.ikanow.aleph2.analytics.services.BatchEnrichmentContext.java
/** Utility to mutate objects * @param original_json// w w w. j a v a 2s.c o m * @param mutations * @return */ protected static JsonNode handleMutations(JsonNode original_json, Optional<ObjectNode> mutations) { return mutations.map(o -> StreamSupport.<Map.Entry<String, JsonNode>>stream( Spliterators.spliteratorUnknownSize(o.fields(), Spliterator.ORDERED), false).reduce(original_json, (acc, kv) -> ((ObjectNode) acc).set(kv.getKey(), kv.getValue()), (val1, val2) -> val2)) .orElse(original_json); }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraPagesRepository.java
@Override public Map<Pair<Application.Name, Page.Name>, List<PageExperiment>> getExperimentsWithoutLabels( Collection<Pair<Application.Name, Page.Name>> appAndPagePairs) { logger.debug("getExperimentsWithoutLabels {}", appAndPagePairs); Map<Pair<Application.Name, Page.Name>, List<PageExperiment>> resultMap = new HashMap<>(); try {//from ww w. j a v a2s.com Map<Pair<Application.Name, Page.Name>, ListenableFuture<Result<PageExperimentByAppNamePage>>> expFutureMap = new HashMap<>(); appAndPagePairs.forEach(pair -> { expFutureMap.put(pair, pageExperimentIndexAccessor.asyncSelectBy(pair.getLeft().toString(), pair.getRight().toString())); }); for (Pair<Application.Name, Page.Name> pair : expFutureMap.keySet()) { ListenableFuture<Result<PageExperimentByAppNamePage>> expFuture = expFutureMap.get(pair); Stream<PageExperimentByAppNamePage> resultList = StreamSupport.stream( Spliterators.spliteratorUnknownSize( UninterruptibleUtil.getUninterruptibly(expFuture).iterator(), Spliterator.ORDERED), false); List<PageExperiment> pageExperimentsList = resultList.map(t -> { PageExperiment.Builder builder = new PageExperiment.Builder( Experiment.ID.valueOf(t.getExperimentId()), null, t.isAssign()); return builder.build(); }).collect(Collectors.toList()); resultMap.put(pair, pageExperimentsList); } } catch (Exception e) { logger.error("getExperimentsWithoutLabels for {} failed", appAndPagePairs, e); throw new RepositoryException("Could not getExperimentsWithoutLabels", e); } logger.debug("Returning PageExperimentList map {}", resultMap); return resultMap; }
From source file:com.ikanow.aleph2.harvest.logstash.utils.LogstashUtils.java
/** * Reads the given output file and outputs it to the logger with the spec'd log level. * @param logger/*w w w.j ava 2 s. c o m*/ * @param level * @param output_file * @throws IOException */ public static void sendOutputToLogger(final IBucketLogger logger, final Level level, final File output_file, final Optional<Long> max_lines) throws IOException { // _logger.error("Reading output file: " + output_file + " to send to logger at level: " + level); Files.lines(output_file.toPath()).limit(max_lines.orElse(10000L)).forEach(line -> { try { //convert line to valid json, then parse json, build BMB object from it final String fixed_line = line.replaceAll(logstash_colon_search, logstash_colon_replace) .replaceAll(logstash_arrow_search, logstash_arrow_replace) .replaceAll(logstash_newline_search, logstash_newline_replace); final String plugin_fixed = fixPlugin(fixed_line); final ObjectNode line_object = (ObjectNode) _mapper.readTree(plugin_fixed); //move specific fields we want into BMB final Date date = parseLogstashDate(line_object.remove("timestamp").asText()); final Level logstash_level = Level.valueOf(line_object.remove("level").asText()); final String message = line_object.remove("message").asText(); //move everything else into details map logger.inefficientLog(logstash_level, new BasicMessageBean(date, true, LogstashHarvestService.class.getSimpleName(), "test_output", null, message, StreamSupport .stream(Spliterators.spliteratorUnknownSize(line_object.fields(), Spliterator.ORDERED), true) .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().asText())))); } catch (Exception ex) { //fallback on conversion failure logger.inefficientLog(level, ErrorUtils .buildSuccessMessage(LogstashHarvestService.class.getSimpleName(), "test_output", line)); } }); //TODO should we delete log file after we've read it? }
From source file:com.ikanow.aleph2.search_service.elasticsearch.utils.ElasticsearchIndexUtils.java
/** Recursive function that will return all fields in an insert (eg "geoip", "geoip.location") * @param index//from w ww . j a va 2 s. co m * @return */ protected static Stream<String> getAllFixedFields_internal(final JsonNode index) { return Optional.ofNullable(index.get("properties")).filter(p -> !p.isNull()).map(p -> { if (!p.isObject()) throw new RuntimeException("properties must be object"); return p; }).map(p -> { return StreamSupport.stream(Spliterators.spliteratorUnknownSize(p.fields(), Spliterator.ORDERED), false) .map(kv -> { return kv; }).<String>flatMap(kv -> { final Stream<String> parent_element = Stream.of(kv.getKey()); return Stream.concat(parent_element, getAllFixedFields_internal(kv.getValue()).map(s -> kv.getKey() + "." + s)); }); }).orElse(Stream.<String>empty()); }
From source file:com.ikanow.aleph2.analytics.storm.services.StreamingEnrichmentContextService.java
@Override public Validation<BasicMessageBean, JsonNode> emitImmutableObject(final long id, final JsonNode original_json, final Optional<ObjectNode> mutations, final Optional<AnnotationBean> annotations, final Optional<JsonNode> grouping_fields) { if (annotations.isPresent()) { throw new RuntimeException(ErrorUtils.NOT_YET_IMPLEMENTED); }//from w w w. j a va 2s.com if (grouping_fields.isPresent()) { throw new RuntimeException(ErrorUtils.NOT_YET_IMPLEMENTED); } final JsonNode to_emit = mutations.map(o -> StreamSupport.<Map.Entry<String, JsonNode>>stream( Spliterators.spliteratorUnknownSize(o.fields(), Spliterator.ORDERED), false).reduce(original_json, (acc, kv) -> ((ObjectNode) acc).set(kv.getKey(), kv.getValue()), (val1, val2) -> val2)) .orElse(original_json); emitMutableObject(0L, (ObjectNode) to_emit, annotations, Optional.empty()); return Validation.success(to_emit); }