List of usage examples for java.util Optional isPresent
public boolean isPresent()
From source file:org.apache.ambari.view.web.service.PackageScannerServiceImpl.java
private void updateScanningStatus(String repoName, RegistryScanStatus status) { Optional<Registry> registryOptional = registryRepository.findByName(repoName); if (!registryOptional.isPresent()) { log.error("Cannot find registry name '{}', unable to mark it as {}", repoName, status); return;/* ww w .ja v a 2 s. c o m*/ } Registry registry = registryOptional.get(); registry.setScanStatus(status); registryRepository.save(registry); }
From source file:com.netflix.genie.core.jobs.workflow.impl.ClusterTask.java
/** * {@inheritDoc}//from w ww . jav a 2s .co m */ @Override public void executeTask(@NotNull final Map<String, Object> context) throws GenieException, IOException { final long start = System.nanoTime(); try { final JobExecutionEnvironment jobExecEnv = (JobExecutionEnvironment) context .get(JobConstants.JOB_EXECUTION_ENV_KEY); final String jobWorkingDirectory = jobExecEnv.getJobWorkingDir().getCanonicalPath(); final String genieDir = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + JobConstants.GENIE_PATH_VAR; final Writer writer = (Writer) context.get(JobConstants.WRITER_KEY); log.info("Starting Cluster Task for job {}", jobExecEnv.getJobRequest().getId()); final String clusterId = jobExecEnv.getCluster().getId() .orElseThrow(() -> new GeniePreconditionException("No cluster id found")); // Create the directory for this application under applications in the cwd createEntityInstanceDirectory(genieDir, clusterId, AdminResources.CLUSTER); // Create the config directory for this id createEntityInstanceConfigDirectory(genieDir, clusterId, AdminResources.CLUSTER); // Get the set up file for cluster and add it to source in launcher script final Optional<String> setupFile = jobExecEnv.getCluster().getSetupFile(); if (setupFile.isPresent()) { final String clusterSetupFile = setupFile.get(); if (StringUtils.isNotBlank(clusterSetupFile)) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, clusterId, clusterSetupFile, FileType.SETUP, AdminResources.CLUSTER); fts.getFile(clusterSetupFile, localPath); super.generateSetupFileSourceSnippet(clusterId, "Cluster:", localPath, writer, jobWorkingDirectory); } } // Iterate over and get all configuration files for (final String configFile : jobExecEnv.getCluster().getConfigs()) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, clusterId, configFile, FileType.CONFIG, AdminResources.CLUSTER); fts.getFile(configFile, localPath); } log.info("Finished Cluster Task for job {}", jobExecEnv.getJobRequest().getId()); } finally { final long finish = System.nanoTime(); this.timer.record(finish - start, TimeUnit.NANOSECONDS); } }
From source file:gndata.lib.srv.LocalFileTest.java
@Test public void testGetParent() throws Exception { Optional<LocalFile> currParent = localFile.getParent(); assertThat(currParent.isPresent()); assertThat(currParent.get().hasPath(testFileFolder)); }
From source file:org.apache.ambari.view.web.service.PackageScannerServiceImpl.java
@Override @Transactional//from ww w. j ava 2 s . c o m public void updateApplications(List<Application> applications, String repo) { Optional<Registry> registryOptional = registryRepository.findByName(repo); if (!registryOptional.isPresent()) { log.error("Cannot find registry name '{}', unable to update applications ", repo); return; } Registry registry = registryOptional.get(); registry.setLastScannedAt(new Date()); registry.setScanStatus(RegistryScanStatus.RUNNING); registryRepository.save(registry); applications.forEach(app -> this.updateApplication(app, registry)); }
From source file:io.mapzone.controller.vm.http.AuthTokenValidator.java
/** * /*from w ww. j ava 2 s .com*/ * * @param token * @param pid * @return * @throws HttpProvisionRuntimeException If project does not exists. */ protected Boolean isValidToken(String token, ProjectInstanceIdentifier pid) { CacheKey key = new CacheKey(token, pid); return validTokens.get(key, _key -> { Project project = uow.get().findProject(pid.organization(), pid.project()) .orElseThrow(() -> new HttpProvisionRuntimeException(404, "No such project: " + pid)); Optional<AuthToken> projectToken = project.serviceAuthToken(); return projectToken.isPresent() ? projectToken.get().isValid(token) : false; }); }
From source file:io.gravitee.gateway.env.GatewayConfigurationTest.java
@Test public void shouldReturnEmptyTenant2() { System.setProperty(GatewayConfiguration.MULTI_TENANT_SYSTEM_PROPERTY, ""); gatewayConfiguration.afterPropertiesSet(); Optional<String> tenant = gatewayConfiguration.tenant(); Assert.assertFalse(tenant.isPresent()); }
From source file:io.apiman.cli.PluginTest.java
/** * @return the plugin expected to have been added * @throws java.io.IOException//from w ww . ja v a 2 s .co m */ @NotNull private Plugin getPlugin() throws java.io.IOException { // fetch all plugins final Response response = given().log().all() .header(AuthUtil.HEADER_AUTHORIZATION, AuthUtil.BASIC_AUTH_VALUE).when().get("/plugins") .thenReturn(); assertEquals(HttpURLConnection.HTTP_OK, response.statusCode()); @SuppressWarnings("unchecked") final List<Plugin> plugins = MappingUtil.JSON_MAPPER.readValue(response.body().asByteArray(), new TypeReference<List<Plugin>>() { }); assertNotNull(plugins); assertTrue("At least one plugin should be installed", plugins.size() > 0); // find the expected plugin final Optional<Plugin> addedPlugin = plugins.stream().filter(this::isArtifactMatch).findAny(); assertTrue(addedPlugin.isPresent()); return addedPlugin.get(); }
From source file:com.netflix.genie.core.jobs.workflow.impl.CommandTask.java
/** * {@inheritDoc}/* ww w.jav a 2s. c om*/ */ @Override public void executeTask(@NotNull final Map<String, Object> context) throws GenieException, IOException { final long start = System.nanoTime(); try { final JobExecutionEnvironment jobExecEnv = (JobExecutionEnvironment) context .get(JobConstants.JOB_EXECUTION_ENV_KEY); final String jobWorkingDirectory = jobExecEnv.getJobWorkingDir().getCanonicalPath(); final String genieDir = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + JobConstants.GENIE_PATH_VAR; final Writer writer = (Writer) context.get(JobConstants.WRITER_KEY); log.info("Starting Command Task for job {}", jobExecEnv.getJobRequest().getId()); final String commandId = jobExecEnv.getCommand().getId() .orElseThrow(() -> new GeniePreconditionException("No command id found")); // Create the directory for this command under command dir in the cwd createEntityInstanceDirectory(genieDir, commandId, AdminResources.COMMAND); // Create the config directory for this id createEntityInstanceConfigDirectory(genieDir, commandId, AdminResources.COMMAND); // Get the setup file if specified and add it as source command in launcher script final Optional<String> setupFile = jobExecEnv.getCommand().getSetupFile(); if (setupFile.isPresent()) { final String commandSetupFile = setupFile.get(); if (StringUtils.isNotBlank(commandSetupFile)) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, commandId, commandSetupFile, FileType.SETUP, AdminResources.COMMAND); fts.getFile(commandSetupFile, localPath); super.generateSetupFileSourceSnippet(commandId, "Command:", localPath, writer, jobWorkingDirectory); } } // Iterate over and get all configuration files for (final String configFile : jobExecEnv.getCommand().getConfigs()) { final String localPath = super.buildLocalFilePath(jobWorkingDirectory, commandId, configFile, FileType.CONFIG, AdminResources.COMMAND); fts.getFile(configFile, localPath); } log.info("Finished Command Task for job {}", jobExecEnv.getJobRequest().getId()); } finally { final long finish = System.nanoTime(); this.timer.record(finish - start, TimeUnit.NANOSECONDS); } }
From source file:spring.travel.site.services.news.NewsServiceTest.java
@Test public void shouldReturnNoneIfNewsDigesterBarfsReadingTheNews() throws Exception { stubGet("/news", ""); HandOff<Optional<List<NewsItem>>> handOff = new HandOff<>(); newsService.news().whenComplete((items, t) -> handOff.put(items)); Optional<List<NewsItem>> newsItems = handOff.get(2); assertThat(newsItems.isPresent(), is(false)); }
From source file:com.arpnetworking.configuration.jackson.JsonNodeMergingSource.java
private JsonNodeMergingSource(final Builder builder) { Optional<JsonNode> mergedNode = Optional.empty(); for (final JsonNodeSource source : builder._sources) { final Optional<JsonNode> sourceNode = source.getValue(); if (sourceNode.isPresent()) { if (mergedNode.isPresent()) { mergedNode = Optional.of(merge(mergedNode.get(), sourceNode.get())); } else { mergedNode = Optional.of(sourceNode.get().deepCopy()); }//w ww . j a v a2 s. co m } } _mergedNode = mergedNode; }