List of usage examples for org.apache.commons.lang3 StringUtils SPACE
String SPACE
To view the source code for org.apache.commons.lang3 StringUtils SPACE.
Click Source Link
From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.sign_browser.search.SignSearchActivity.java
private void setupSupportActionBar() { final ActionBar supportActionBar = getSupportActionBar(); Validate.notNull(supportActionBar, "SupportActionBar is null. Should have been set in onCreate()."); supportActionBar//from ww w. j a va 2s . c o m .setTitle(getResources().getString(R.string.search_results) + StringUtils.SPACE + this.query); supportActionBar.setDisplayHomeAsUpEnabled(true); }
From source file:com.netflix.genie.common.dto.JobTest.java
/** * Test to make sure can build a valid Job with optional parameters. *///from w ww.j a va 2 s. com @Test @SuppressWarnings("deprecation") public void canBuildJobWithOptionalsDeprecated() { final Job.Builder builder = new Job.Builder(NAME, USER, VERSION); builder.withCommandArgs(StringUtils.join(COMMAND_ARGS, StringUtils.SPACE)); final String archiveLocation = UUID.randomUUID().toString(); builder.withArchiveLocation(archiveLocation); final String clusterName = UUID.randomUUID().toString(); builder.withClusterName(clusterName); final String commandName = UUID.randomUUID().toString(); builder.withCommandName(commandName); final Instant finished = Instant.now(); builder.withFinished(finished); final Instant started = Instant.now(); builder.withStarted(started); builder.withStatus(JobStatus.SUCCEEDED); final String statusMsg = UUID.randomUUID().toString(); builder.withStatusMsg(statusMsg); final Instant created = Instant.now(); builder.withCreated(created); final String description = UUID.randomUUID().toString(); builder.withDescription(description); final String id = UUID.randomUUID().toString(); builder.withId(id); final Set<String> tags = Sets.newHashSet(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()); builder.withTags(tags); final Instant updated = Instant.now(); builder.withUpdated(updated); final String grouping = UUID.randomUUID().toString(); builder.withGrouping(grouping); final String groupingInstance = UUID.randomUUID().toString(); builder.withGroupingInstance(groupingInstance); final Job job = builder.build(); Assert.assertThat(job.getName(), Matchers.is(NAME)); Assert.assertThat(job.getUser(), Matchers.is(USER)); Assert.assertThat(job.getVersion(), Matchers.is(VERSION)); Assert.assertThat(job.getCommandArgs().orElseThrow(IllegalArgumentException::new), Matchers.is(StringUtils.join(COMMAND_ARGS, StringUtils.SPACE))); Assert.assertThat(job.getArchiveLocation().orElseThrow(IllegalArgumentException::new), Matchers.is(archiveLocation)); Assert.assertThat(job.getClusterName().orElseThrow(IllegalArgumentException::new), Matchers.is(clusterName)); Assert.assertThat(job.getCommandName().orElseThrow(IllegalArgumentException::new), Matchers.is(commandName)); Assert.assertThat(job.getFinished().orElseThrow(IllegalArgumentException::new), Matchers.is(finished)); Assert.assertThat(job.getStarted().orElseThrow(IllegalArgumentException::new), Matchers.is(started)); Assert.assertThat(job.getStatus(), Matchers.is(JobStatus.SUCCEEDED)); Assert.assertThat(job.getStatusMsg().orElseThrow(IllegalArgumentException::new), Matchers.is(statusMsg)); Assert.assertThat(job.getCreated().orElseThrow(IllegalArgumentException::new), Matchers.is(created)); Assert.assertThat(job.getDescription().orElseThrow(IllegalArgumentException::new), Matchers.is(description)); Assert.assertThat(job.getId().orElseThrow(IllegalArgumentException::new), Matchers.is(id)); Assert.assertThat(job.getTags(), Matchers.is(tags)); Assert.assertThat(job.getUpdated().orElseThrow(IllegalArgumentException::new), Matchers.is(updated)); Assert.assertThat(job.getRuntime(), Matchers.is(Duration.ofMillis(finished.toEpochMilli() - started.toEpochMilli()))); Assert.assertThat(job.getGrouping().orElseThrow(IllegalArgumentException::new), Matchers.is(grouping)); Assert.assertThat(job.getGroupingInstance().orElseThrow(IllegalArgumentException::new), Matchers.is(groupingInstance)); }
From source file:com.netflix.genie.web.jobs.workflow.impl.JobTask.java
/** * {@inheritDoc}//from ww w .ja v a 2 s .c om */ @Override public void executeTask(@NotNull final Map<String, Object> context) throws GenieException, IOException { final long start = System.nanoTime(); final Set<Tag> tags = Sets.newHashSet(); try { final JobExecutionEnvironment jobExecEnv = (JobExecutionEnvironment) context .get(JobConstants.JOB_EXECUTION_ENV_KEY); final String jobWorkingDirectory = jobExecEnv.getJobWorkingDir().getCanonicalPath(); final Writer writer = (Writer) context.get(JobConstants.WRITER_KEY); final String jobId = jobExecEnv.getJobRequest().getId() .orElseThrow(() -> new GeniePreconditionException("No job id found. Unable to continue")); log.info("Starting Job Task for job {}", jobId); final Optional<String> setupFile = jobExecEnv.getJobRequest().getSetupFile(); if (setupFile.isPresent()) { final String jobSetupFile = setupFile.get(); if (StringUtils.isNotBlank(jobSetupFile)) { final String localPath = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + jobSetupFile .substring(jobSetupFile.lastIndexOf(JobConstants.FILE_PATH_DELIMITER) + 1); fts.getFile(jobSetupFile, localPath); writer.write("# Sourcing setup file specified in job request" + System.lineSeparator()); writer.write( JobConstants.SOURCE + localPath.replace(jobWorkingDirectory, "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}") + System.lineSeparator()); // Append new line writer.write(System.lineSeparator()); } } // Iterate over and get all configs and dependencies final Collection<String> configsAndDependencies = Sets.newHashSet(); configsAndDependencies.addAll(jobExecEnv.getJobRequest().getDependencies()); configsAndDependencies.addAll(jobExecEnv.getJobRequest().getConfigs()); for (final String dependentFile : configsAndDependencies) { if (StringUtils.isNotBlank(dependentFile)) { final String localPath = jobWorkingDirectory + JobConstants.FILE_PATH_DELIMITER + dependentFile .substring(dependentFile.lastIndexOf(JobConstants.FILE_PATH_DELIMITER) + 1); fts.getFile(dependentFile, localPath); } } // Copy down the attachments if any to the current working directory this.attachmentService.copy(jobId, jobExecEnv.getJobWorkingDir()); // Delete the files from the attachment service to save space on disk this.attachmentService.delete(jobId); // Print out the current Envrionment to a env file before running the command. writer.write("# Dump the environment to a env.log file" + System.lineSeparator()); writer.write("env | sort > " + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}" + JobConstants.GENIE_ENV_PATH + System.lineSeparator()); // Append new line writer.write(System.lineSeparator()); writer.write("# Kick off the command in background mode and wait for it using its pid" + System.lineSeparator()); writer.write(StringUtils.join(jobExecEnv.getCommand().getExecutable(), StringUtils.SPACE) + JobConstants.WHITE_SPACE + jobExecEnv.getJobRequest().getCommandArgs().orElse(EMPTY_STRING) + JobConstants.STDOUT_REDIRECT + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}/" + JobConstants.STDOUT_LOG_FILE_NAME + JobConstants.STDERR_REDIRECT + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}/" + JobConstants.STDERR_LOG_FILE_NAME + " &" + System.lineSeparator()); // Save PID of children process, used in trap handlers to kill and verify termination writer.write(JobConstants.EXPORT + JobConstants.CHILDREN_PID_ENV_VAR + "=$!" + System.lineSeparator()); // Wait for the above process started in background mode. Wait lets us get interrupted by kill signals. writer.write("wait ${" + JobConstants.CHILDREN_PID_ENV_VAR + "}" + System.lineSeparator()); // Append new line writer.write(System.lineSeparator()); // capture exit code and write to temporary genie.done writer.write("# Write the return code from the command in the done file." + System.lineSeparator()); writer.write(JobConstants.GENIE_DONE_FILE_CONTENT_PREFIX + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}" + "/" + JobConstants.GENIE_TEMPORARY_DONE_FILE_NAME + System.lineSeparator()); // atomically swap temporary and actual genie.done file if one doesn't exist writer.write( "# Swapping done file, unless one exist created by trap handler." + System.lineSeparator()); writer.write("mv -n " + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}" + "/" + JobConstants.GENIE_TEMPORARY_DONE_FILE_NAME + " " + "${" + JobConstants.GENIE_JOB_DIR_ENV_VAR + "}" + "/" + JobConstants.GENIE_DONE_FILE_NAME + System.lineSeparator()); // Print the timestamp once its done running. writer.write("echo End: `date '+%Y-%m-%d %H:%M:%S'`\n"); log.info("Finished Job Task for job {}", jobId); MetricsUtils.addSuccessTags(tags); } catch (final Throwable t) { MetricsUtils.addFailureTagsWithException(tags, t); throw t; } finally { this.getRegistry().timer(JOB_TASK_TIMER_NAME, tags).record(System.nanoTime() - start, TimeUnit.NANOSECONDS); } }
From source file:cop.raml.utils.Utils.java
public static String offs(String str, int offs, boolean strict) { if (StringUtils.isBlank(str) || offs < 0) return str; String tmp = StringUtils.repeat(StringUtils.SPACE, offs); String[] lines = Arrays.stream(splitLine(str)).map(line -> tmp + (strict ? line : line.trim())) .map(line -> StringUtils.isBlank(line) ? StringUtils.EMPTY : line).toArray(String[]::new); return String.join("\n", lines); }
From source file:com.netflix.genie.common.dto.JobRequestTest.java
/** * Test to make sure can build a valid JobRequest with optional parameters. *//*from ww w.ja v a 2 s. c o m*/ @Test @SuppressWarnings("deprecation") public void canBuildJobRequestWithOptionalsDeprecated() { final JobRequest.Builder builder = new JobRequest.Builder(NAME, USER, VERSION, CLUSTER_CRITERIAS, COMMAND_CRITERIA); builder.withCommandArgs(StringUtils.join(COMMAND_ARGS, StringUtils.SPACE)); final int cpu = 5; builder.withCpu(cpu); final boolean disableLogArchival = true; builder.withDisableLogArchival(disableLogArchival); final String email = UUID.randomUUID().toString() + "@netflix.com"; builder.withEmail(email); final Set<String> configs = Sets.newHashSet(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()); builder.withConfigs(configs); final Set<String> dependencies = Sets.newHashSet(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()); builder.withDependencies(dependencies); final String group = UUID.randomUUID().toString(); builder.withGroup(group); final int memory = 2048; builder.withMemory(memory); final String setupFile = UUID.randomUUID().toString(); builder.withSetupFile(setupFile); final Instant created = Instant.now(); builder.withCreated(created); final String description = UUID.randomUUID().toString(); builder.withDescription(description); final String id = UUID.randomUUID().toString(); builder.withId(id); final Set<String> tags = Sets.newHashSet(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()); builder.withTags(tags); final Instant updated = Instant.now(); builder.withUpdated(updated); final List<String> applications = Lists.newArrayList(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()); builder.withApplications(applications); final int timeout = 8970243; builder.withTimeout(timeout); final String grouping = UUID.randomUUID().toString(); builder.withGrouping(grouping); final String groupingInstance = UUID.randomUUID().toString(); builder.withGroupingInstance(groupingInstance); final JobRequest request = builder.build(); Assert.assertThat(request.getName(), Matchers.is(NAME)); Assert.assertThat(request.getUser(), Matchers.is(USER)); Assert.assertThat(request.getVersion(), Matchers.is(VERSION)); Assert.assertThat(request.getCommandArgs().orElseThrow(IllegalArgumentException::new), Matchers.is(StringUtils.join(COMMAND_ARGS, StringUtils.SPACE))); Assert.assertThat(request.getClusterCriterias(), Matchers.is(CLUSTER_CRITERIAS)); Assert.assertThat(request.getCommandCriteria(), Matchers.is(COMMAND_CRITERIA)); Assert.assertThat(request.getCpu().orElseThrow(IllegalArgumentException::new), Matchers.is(cpu)); Assert.assertThat(request.isDisableLogArchival(), Matchers.is(disableLogArchival)); Assert.assertThat(request.getEmail().orElseThrow(IllegalArgumentException::new), Matchers.is(email)); Assert.assertThat(request.getConfigs(), Matchers.is(configs)); Assert.assertThat(request.getDependencies(), Matchers.is(dependencies)); Assert.assertThat(request.getGroup().orElseThrow(IllegalArgumentException::new), Matchers.is(group)); Assert.assertThat(request.getMemory().orElseThrow(IllegalArgumentException::new), Matchers.is(memory)); Assert.assertThat(request.getSetupFile().orElseThrow(IllegalArgumentException::new), Matchers.is(setupFile)); Assert.assertThat(request.getCreated().orElseThrow(IllegalArgumentException::new), Matchers.is(created)); Assert.assertThat(request.getDescription().orElseThrow(IllegalArgumentException::new), Matchers.is(description)); Assert.assertThat(request.getId().orElseThrow(IllegalArgumentException::new), Matchers.is(id)); Assert.assertThat(request.getTags(), Matchers.is(tags)); Assert.assertThat(request.getUpdated().orElseThrow(IllegalArgumentException::new), Matchers.is(updated)); Assert.assertThat(request.getApplications(), Matchers.is(applications)); Assert.assertThat(request.getTimeout().orElseThrow(IllegalArgumentException::new), Matchers.is(timeout)); Assert.assertThat(request.getGrouping().orElseThrow(IllegalArgumentException::new), Matchers.is(grouping)); Assert.assertThat(request.getGroupingInstance().orElseThrow(IllegalArgumentException::new), Matchers.is(groupingInstance)); }
From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.activities.MainActivity.java
@Override public void onSignBrowserSignSelected(Sign sign) { Log.d(TAG, "onSignBrowserSignSelected: " + sign.getName() + StringUtils.SPACE + hashCode()); showSignVideo(sign); }
From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.activities.MainActivity.java
@Override public void toggleLearningMode(LearningMode learningMode) { Log.d(TAG, "toggleLearningMode() learningMode: " + learningMode + StringUtils.SPACE + hashCode()); showSignTrainer(learningMode);/* www .j a va2s. c o m*/ }
From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.activities.MainActivity.java
private void setFragment(Fragment fragment, String actionBarTitle) { Log.d(TAG, "setFragment: " + actionBarTitle + StringUtils.SPACE + hashCode()); final FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.content_frame, fragment, actionBarTitle); transaction.addToBackStack(actionBarTitle); transaction.commit();/*from w w w. java 2s . c om*/ }
From source file:com.netflix.genie.web.services.impl.JobCoordinatorServiceImpl.java
/** * {@inheritDoc}/*from www . ja v a2 s . c o m*/ */ @Override public String coordinateJob( @Valid @NotNull(message = "No job request provided. Unable to execute.") final JobRequest jobRequest, @Valid @NotNull(message = "No job metadata provided. Unable to execute.") final JobMetadata jobMetadata) throws GenieException { final long coordinationStart = System.nanoTime(); final Set<Tag> tags = Sets.newHashSet(); final String jobId = jobRequest.getId() .orElseThrow(() -> new GenieServerException("Id of the jobRequest cannot be null")); JobStatus jobStatus = JobStatus.FAILED; try { log.info("Called to schedule job launch for job {}", jobId); // create the job object in the database with status INIT final Job.Builder jobBuilder = new Job.Builder(jobRequest.getName(), jobRequest.getUser(), jobRequest.getVersion()).withId(jobId).withTags(jobRequest.getTags()).withStatus(JobStatus.INIT) .withStatusMsg("Job Accepted and in initialization phase."); jobRequest.getCommandArgs().ifPresent(commandArgs -> jobBuilder.withCommandArgs( Lists.newArrayList(StringUtils.splitByWholeSeparator(commandArgs, StringUtils.SPACE)))); jobRequest.getDescription().ifPresent(jobBuilder::withDescription); if (!jobRequest.isDisableLogArchival()) { jobBuilder.withArchiveLocation(this.jobsProperties.getLocations().getArchives() + JobConstants.FILE_PATH_DELIMITER + jobId + ".tar.gz"); } final JobExecution jobExecution = new JobExecution.Builder(this.hostname).withId(jobId).build(); // Log all the job initial job information this.jobPersistenceService.createJob(jobRequest, jobMetadata, jobBuilder.build(), jobExecution); this.jobStateService.init(jobId); log.info("Finding possible clusters and commands for job {}", jobRequest.getId().orElse(NO_ID_FOUND)); final JobSpecification jobSpecification; try { jobSpecification = this.specificationService.resolveJobSpecification(jobId, DtoConverters.toV4JobRequest(jobRequest)); } catch (final RuntimeException re) { //TODO: Here for now as we figure out what to do with exceptions for JobSpecificationServiceImpl throw new GeniePreconditionException(re.getMessage(), re); } final Cluster cluster = this.clusterPersistenceService .getCluster(jobSpecification.getCluster().getId()); final Command command = this.commandPersistenceService .getCommand(jobSpecification.getCommand().getId()); // Now that we have command how much memory should the job use? final int memory = jobRequest.getMemory() .orElse(command.getMemory().orElse(this.jobsProperties.getMemory().getDefaultJobMemory())); final ImmutableList.Builder<Application> applicationsBuilder = ImmutableList.builder(); for (final JobSpecification.ExecutionResource applicationResource : jobSpecification .getApplications()) { applicationsBuilder .add(this.applicationPersistenceService.getApplication(applicationResource.getId())); } final ImmutableList<Application> applications = applicationsBuilder.build(); // Save all the runtime information this.setRuntimeEnvironment(jobId, cluster, command, applications, memory); final int maxJobMemory = this.jobsProperties.getMemory().getMaxJobMemory(); if (memory > maxJobMemory) { jobStatus = JobStatus.INVALID; throw new GeniePreconditionException("Requested " + memory + " MB to run job which is more than the " + maxJobMemory + " MB allowed"); } log.info("Checking if can run job {} from user {}", jobRequest.getId(), jobRequest.getUser()); final JobsUsersActiveLimitProperties activeLimit = this.jobsProperties.getUsers().getActiveLimit(); if (activeLimit.isEnabled()) { final long activeJobsLimit = activeLimit.getCount(); final long activeJobsCount = this.jobSearchService.getActiveJobCountForUser(jobRequest.getUser()); if (activeJobsCount >= activeJobsLimit) { throw GenieUserLimitExceededException.createForActiveJobsLimit(jobRequest.getUser(), activeJobsCount, activeJobsLimit); } } synchronized (this) { log.info("Checking if can run job {} on this node", jobRequest.getId()); final int maxSystemMemory = this.jobsProperties.getMemory().getMaxSystemMemory(); final int usedMemory = this.jobStateService.getUsedMemory(); if (usedMemory + memory <= maxSystemMemory) { log.info("Job {} can run on this node as only {}/{} MB are used and requested {} MB", jobId, usedMemory, maxSystemMemory, memory); // Tell the system a new job has been scheduled so any actions can be taken log.info("Publishing job scheduled event for job {}", jobId); this.jobStateService.schedule(jobId, jobRequest, cluster, command, applications, memory); MetricsUtils.addSuccessTags(tags); return jobId; } else { throw new GenieServerUnavailableException("Job " + jobId + " can't run on this node " + usedMemory + "/" + maxSystemMemory + " MB are used and requested " + memory + " MB"); } } } catch (final GenieConflictException e) { MetricsUtils.addFailureTagsWithException(tags, e); // Job has not been initiated so we don't have to call JobStateService.done() throw e; } catch (final GenieException e) { MetricsUtils.addFailureTagsWithException(tags, e); // // Need to check if the job exists in the JobStateService // because this error can happen before the job is initiated. // if (this.jobStateService.jobExists(jobId)) { this.jobStateService.done(jobId); this.jobPersistenceService.updateJobStatus(jobId, jobStatus, e.getMessage()); } throw e; } catch (final Exception e) { MetricsUtils.addFailureTagsWithException(tags, e); // // Need to check if the job exists in the JobStateService // because this error can happen before the job is initiated. // if (this.jobStateService.jobExists(jobId)) { this.jobStateService.done(jobId); this.jobPersistenceService.updateJobStatus(jobId, jobStatus, e.getMessage()); } throw new GenieServerException("Failed to coordinate job launch", e); } catch (final Throwable t) { MetricsUtils.addFailureTagsWithException(tags, t); throw t; } finally { this.registry.timer(OVERALL_COORDINATION_TIMER_NAME, tags).record(System.nanoTime() - coordinationStart, TimeUnit.NANOSECONDS); } }
From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.activities.MainActivity.java
private void setActionBarTitle(String actionBarTitle) { Log.d(TAG, "setActionBarTitle: " + actionBarTitle + StringUtils.SPACE + hashCode()); Validate.notNull(getSupportActionBar(), "SupportActionBar is null. Should be set in onCreate() method."); this.actionBarTitle = actionBarTitle; getSupportActionBar().setTitle(this.actionBarTitle); }