List of usage examples for java.util Set stream
default Stream<E> stream()
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v2.KubernetesV2Service.java
default List<ConfigSource> stageConfig(AccountDeploymentDetails<KubernetesAccount> details, GenerateService.ResolvedConfiguration resolvedConfiguration) { Map<String, Profile> profiles = resolvedConfiguration.getProfilesForService(getService().getType()); String stagingPath = getSpinnakerStagingPath(details.getDeploymentName()); SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings(); Map<String, Set<Profile>> profilesByDirectory = new HashMap<>(); List<String> requiredFiles = new ArrayList<>(); List<ConfigSource> configSources = new ArrayList<>(); String secretNamePrefix = getServiceName() + "-files"; String namespace = getNamespace(resolvedConfiguration.getServiceSettings(getService())); KubernetesAccount account = details.getAccount(); for (SidecarService sidecarService : getSidecars(runtimeSettings)) { for (Profile profile : sidecarService.getSidecarProfiles(resolvedConfiguration, getService())) { if (profile == null) { throw new HalException(Problem.Severity.FATAL, "Service " + sidecarService.getService().getCanonicalName() + " is required but was not supplied for deployment."); }/*from w ww .j a va2 s .co m*/ profiles.put(profile.getName(), profile); requiredFiles.addAll(profile.getRequiredFiles()); } } for (Entry<String, Profile> entry : profiles.entrySet()) { Profile profile = entry.getValue(); String outputFile = profile.getOutputFile(); String mountPoint = Paths.get(outputFile).getParent().toString(); Set<Profile> profilesInDirectory = profilesByDirectory.getOrDefault(mountPoint, new HashSet<>()); profilesInDirectory.add(profile); requiredFiles.addAll(profile.getRequiredFiles()); profilesByDirectory.put(mountPoint, profilesInDirectory); } for (Entry<String, Set<Profile>> entry : profilesByDirectory.entrySet()) { Set<Profile> profilesInDirectory = entry.getValue(); String mountPath = entry.getKey(); List<SecretMountPair> files = profilesInDirectory.stream().map(p -> { File input = new File(p.getStagedFile(stagingPath)); File output = new File(p.getOutputFile()); return new SecretMountPair(input, output); }).collect(Collectors.toList()); Map<String, String> env = profilesInDirectory.stream().map(Profile::getEnv).map(Map::entrySet) .flatMap(Collection::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue)); String name = KubernetesV2Utils.createSecret(account, namespace, getService().getCanonicalName(), secretNamePrefix, files); configSources.add(new ConfigSource().setId(name).setMountPath(mountPath).setEnv(env)); } if (!requiredFiles.isEmpty()) { List<SecretMountPair> files = requiredFiles.stream().map(File::new).map(SecretMountPair::new) .collect(Collectors.toList()); String name = KubernetesV2Utils.createSecret(account, namespace, getService().getCanonicalName(), secretNamePrefix, files); configSources.add(new ConfigSource().setId(name).setMountPath(files.get(0).getContents().getParent())); } return configSources; }
From source file:io.swagger.jaxrs.SynapseReader.java
private void prepareOperation(Operation operation, ApiOperation apiOperation, Map<String, String> regexMap, Set<Scheme> globalSchemes) { operation.getParameters().stream().filter((param) -> (regexMap.get(param.getName()) != null)) .forEach((param) -> {//from w w w . j av a 2 s. c om String pattern = regexMap.get(param.getName()); param.setPattern(pattern); }); if (apiOperation != null) { parseSchemes(apiOperation.protocols()).stream().forEach((scheme) -> { operation.scheme(scheme); }); } if (operation.getSchemes() == null || operation.getSchemes().isEmpty()) { globalSchemes.stream().forEach((scheme) -> { operation.scheme(scheme); }); } }
From source file:com.ggvaidya.scinames.summary.NameStabilityView.java
private Set<Name> getBinomialNamesIntersection(Project p, Dataset ds1, Dataset ds2) { Set<Name> recog1 = p.getRecognizedNames(ds1).stream().flatMap(n -> n.asBinomial()) .collect(Collectors.toSet()); Set<Name> recog2 = p.getRecognizedNames(ds2).stream().flatMap(n -> n.asBinomial()) .collect(Collectors.toSet()); return recog1.stream().filter(n -> recog2.contains(n)).collect(Collectors.toSet()); }
From source file:com.netflix.genie.web.services.impl.JobSpecificationServiceImpl.java
private Cluster selectCluster(final String id, final JobRequest jobRequest, final Set<Cluster> clusters) throws GenieException { final long start = System.nanoTime(); final Set<Tag> timerTags = Sets.newHashSet(); final Set<Tag> counterTags = Sets.newHashSet(); try {/* w w w . ja v a2 s .c o m*/ final Cluster cluster; if (clusters.isEmpty()) { this.noClusterFoundCounter.increment(); throw new GeniePreconditionException( "No cluster/command combination found for the given criteria. Unable to continue"); } else if (clusters.size() == 1) { cluster = clusters.stream().findFirst() .orElseThrow(() -> new GenieServerException("Couldn't get cluster when size was one")); } else { cluster = this.selectClusterWithLoadBalancer(counterTags, clusters, id, jobRequest); } log.info("Selected cluster {} for job {}", cluster.getId(), id); MetricsUtils.addSuccessTags(timerTags); return cluster; } catch (final Throwable t) { MetricsUtils.addFailureTagsWithException(timerTags, t); throw t; } finally { this.registry.timer(SELECT_CLUSTER_TIMER_NAME, timerTags).record(System.nanoTime() - start, TimeUnit.NANOSECONDS); } }
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void addDeviceToUser_addAfterDelete_deviceIdReused() { LocalDateTime startTime = TimeUtil.utcNow(); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; richard.addDevice(//from w w w . j a v a 2 s . c o m createDevice(1, deviceName2, operatingSystem2, SOME_APP_VERSION, SUPPORTED_APP_VERSION_CODE)); assertThat(richard.getDevices().size(), equalTo(1)); String deviceName3 = "Third"; OperatingSystem operatingSystem3 = OperatingSystem.IOS; UserDeviceDto deviceDto3 = new UserDeviceDto(deviceName3, operatingSystem3, SOME_APP_VERSION, SUPPORTED_APP_VERSION_CODE); service.addDeviceToUser(richard, deviceDto3); Set<UserDevice> devices = richard.getDevices(); assertThat(devices.size(), equalTo(2)); Optional<UserDevice> device2Optional = devices.stream().filter(d -> d.getName().equals(deviceName2)) .findAny(); assertThat(device2Optional.isPresent(), equalTo(true)); UserDevice device2 = device2Optional.get(); assertDevice(device2, startTime, deviceName2, operatingSystem2, 1); Optional<UserDevice> device3Optional = devices.stream().filter(d -> d.getName().equals(deviceName3)) .findAny(); assertThat(device3Optional.isPresent(), equalTo(true)); UserDevice device3 = device3Optional.get(); assertDevice(device3, startTime, deviceName3, operatingSystem3, 0); }
From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java
@Test public void addDeviceToUser_addSecondDevice_userHasTwoDevices() { String deviceName1 = "First"; OperatingSystem operatingSystem1 = OperatingSystem.ANDROID; LocalDateTime startTime = TimeUtil.utcNow(); richard.addDevice(//from ww w.j av a2 s. c o m createDevice(0, deviceName1, operatingSystem1, SOME_APP_VERSION, SUPPORTED_APP_VERSION_CODE)); String deviceName2 = "Second"; OperatingSystem operatingSystem2 = OperatingSystem.IOS; UserDeviceDto deviceDto2 = new UserDeviceDto(deviceName2, operatingSystem2, SOME_APP_VERSION, SUPPORTED_APP_VERSION_CODE); service.addDeviceToUser(richard, deviceDto2); verify(userDeviceRepository, times(2)).save(any(UserDevice.class)); assertThat(deviceAnonymizedRepository.count(), equalTo(2L)); Set<UserDevice> devices = richard.getDevices(); assertThat(devices.size(), equalTo(2)); Optional<UserDevice> device1Optional = devices.stream().filter(d -> d.getName().equals(deviceName1)) .findAny(); assertThat(device1Optional.isPresent(), equalTo(true)); UserDevice device1 = device1Optional.get(); assertDevice(device1, startTime, deviceName1, operatingSystem1, 0); Optional<UserDevice> device2Optional = devices.stream().filter(d -> d.getName().equals(deviceName2)) .findAny(); assertThat(device2Optional.isPresent(), equalTo(true)); UserDevice device2 = device2Optional.get(); assertDevice(device2, startTime, deviceName2, operatingSystem2, 1); assertVpnAccountCreated(device2); }
From source file:com.thinkbiganalytics.nifi.feedmgr.TemplateCreationHelper.java
/** * Instantiates the specified template in the specified process group. * * <p>Controller services that are created under the specified process group will be moved to the root process group. This side-effect may be removed in the future.</p> * * @param processGroupId the process group id * @param templateId the template id * @return the instantiated flow//from ww w . jav a 2 s . c o m * @throws NifiComponentNotFoundException if the process group or template does not exist */ @Nonnull public TemplateInstance instantiateFlowFromTemplate(@Nonnull final String processGroupId, @Nonnull final String templateId) throws NifiComponentNotFoundException { // Instantiate template final NiFiRestClient nifiClient = restClient.getNiFiRestClient(); final FlowSnippetDTO templateFlow = nifiClient.processGroups().instantiateTemplate(processGroupId, templateId); TemplateInstance instance = new TemplateInstance(templateFlow); // Move controller services to root process group (NiFi >= v1.0) final Set<ControllerServiceDTO> groupControllerServices = nifiClient.processGroups() .getControllerServices(processGroupId); final Map<String, String> idMap = new HashMap<>(groupControllerServices.size()); groupControllerServices.stream() .filter(controllerService -> controllerService.getParentGroupId().equals(processGroupId)) .forEach(groupControllerService -> { // Delete scoped service final String oldId = groupControllerService.getId(); nifiClient.controllerServices().delete(groupControllerService.getId()); // Create root service final ControllerServiceDTO rootControllerService = new ControllerServiceDTO(); rootControllerService.setComments(groupControllerService.getComments()); rootControllerService.setName(groupControllerService.getName()); rootControllerService.setType(groupControllerService.getType()); ControllerServiceDTO newRootService = nifiClient.processGroups().createControllerService("root", rootControllerService); final String rootId = newRootService.getId(); // Map old ID to new ID idMap.put(oldId, rootId); instance.movedScopedControllerService(groupControllerService, newRootService); }); // Set properties on root controller services groupControllerServices.stream() .filter(controllerService -> controllerService.getParentGroupId().equals(processGroupId)) .forEach(groupControllerService -> { final Map<String, String> properties = groupControllerService.getProperties(); groupControllerService.getDescriptors().values().stream().filter( descriptor -> StringUtils.isNotBlank(descriptor.getIdentifiesControllerService())) .forEach(descriptor -> { final String name = descriptor.getName(); final String oldId = properties.get(name); properties.put(name, idMap.get(oldId)); }); final ControllerServiceDTO rootControllerService = new ControllerServiceDTO(); rootControllerService.setId(idMap.get(groupControllerService.getId())); rootControllerService.setProperties(properties); nifiClient.controllerServices().update(rootControllerService); }); // Return flow return instance; }
From source file:blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.java
public void removeConnection(World world, Connection con, Vec3d vecStart, Vec3d vecEnd) { if (con == null || world == null) return;// w ww .j a v a 2 s .co m int dim = world.provider.getDimension(); resetCachedIndirectConnections(world, con.start); Map<BlockPos, Set<Connection>> connsInDim = getMultimap(world.provider.getDimension()); Set<Connection> reverseConns = connsInDim.get(con.end); Set<Connection> forwardConns = connsInDim.get(con.start); Optional<Connection> back = reverseConns.stream().filter(con::hasSameConnectors).findAny(); reverseConns.removeIf(con::hasSameConnectors); forwardConns.removeIf(con::hasSameConnectors); Map<BlockPos, BlockWireInfo> mapForDim = blockWireMap.lookup(world.provider.getDimension()); BiConsumer<BlockPos, Map<BlockPos, BlockWireInfo>> handle = (p, map) -> { if (mapForDim != null) { BlockWireInfo info = map.get(p); if (info != null) { for (int i = 0; i < 2; i++) { Set<Triple<Connection, Vec3d, Vec3d>> s = i == 0 ? info.in : info.near; s.removeIf((t) -> t.getLeft().hasSameConnectors(con)); if (s.isEmpty()) map.remove(p); } if (info.near.isEmpty() && info.in.isEmpty()) map.remove(p); } } }; raytraceAlongCatenaryRelative(con, (p) -> { handle.accept(p.getLeft(), mapForDim); return false; }, (p) -> handle.accept(p.getLeft(), mapForDim), vecStart, vecEnd); IImmersiveConnectable iic = toIIC(con.end, world); if (iic != null) { iic.removeCable(con); back.ifPresent(iic::removeCable); } iic = toIIC(con.start, world); if (iic != null) { iic.removeCable(con); back.ifPresent(iic::removeCable); } if (world.isBlockLoaded(con.start)) world.addBlockEvent(con.start, world.getBlockState(con.start).getBlock(), -1, 0); if (world.isBlockLoaded(con.end)) world.addBlockEvent(con.end, world.getBlockState(con.end).getBlock(), -1, 0); IESaveData.setDirty(dim); }
From source file:nu.yona.server.analysis.service.ActivityService.java
private List<DayActivity> findAllActivitiesForUserInInterval(UUID userAnonymizedId, Set<GoalDto> relevantGoals, Interval interval) {//from www . j a v a 2s .c om if (relevantGoals.isEmpty()) { // SQL in-query fails when the list is empty, so don't go to the // repository with an empty list return Collections.emptyList(); } return dayActivityRepository.findAll(userAnonymizedId, relevantGoals.stream().map(GoalDto::getGoalId).collect(Collectors.toSet()), interval.startDate, interval.endDate); }
From source file:com.netflix.genie.web.services.loadbalancers.script.ScriptLoadBalancer.java
/** * {@inheritDoc}/* w w w .j av a 2 s . co m*/ */ @Override public Cluster selectCluster(@Nonnull @NonNull @NotEmpty final Set<Cluster> clusters, @Nonnull @NonNull final JobRequest jobRequest) throws GenieException { final long selectStart = System.nanoTime(); log.debug("Called"); final Set<Tag> tags = Sets.newHashSet(); try { if (this.isConfigured.get() && this.script.get() != null) { log.debug("Evaluating script for job {}", jobRequest.getId().orElse("without id")); final Bindings bindings = new SimpleBindings(); // TODO: For now for backwards compatibility with balancer scripts continue writing Clusters out in // V3 format. Change to V4 once stabalize a bit more bindings.put(CLUSTERS_BINDING, this.mapper.writeValueAsString( clusters.stream().map(DtoConverters::toV3Cluster).collect(Collectors.toSet()))); bindings.put(JOB_REQUEST_BINDING, this.mapper.writeValueAsString(jobRequest)); // Run as callable and timeout after the configured timeout length final String clusterId = this.asyncTaskExecutor .submit(() -> (String) this.script.get().eval(bindings)) .get(this.timeoutLength.get(), TimeUnit.MILLISECONDS); // Find the cluster if not null if (clusterId != null) { for (final Cluster cluster : clusters) { if (clusterId.equals(cluster.getId())) { tags.add(Tag.of(MetricsConstants.TagKeys.STATUS, STATUS_TAG_FOUND)); return cluster; } } } log.warn("Script returned a cluster not in the input list: {}", clusterId); } else { log.debug("Script returned null"); tags.add(Tag.of(MetricsConstants.TagKeys.STATUS, STATUS_TAG_NOT_CONFIGURED)); return null; } tags.add(Tag.of(MetricsConstants.TagKeys.STATUS, STATUS_TAG_NOT_FOUND)); // Defer to any subsequent load balancer in the chain return null; } catch (final Exception e) { tags.add(Tag.of(MetricsConstants.TagKeys.STATUS, STATUS_TAG_FAILED)); tags.add(Tag.of(MetricsConstants.TagKeys.EXCEPTION_CLASS, e.getClass().getCanonicalName())); log.error("Unable to execute script due to {}", e.getMessage(), e); return null; } finally { this.registry.timer(SELECT_TIMER_NAME, tags).record(System.nanoTime() - selectStart, TimeUnit.NANOSECONDS); } }