Skip to content

Commit

Permalink
Project wide code reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tgianos committed Feb 15, 2021
1 parent 6c294c9 commit 85c5d55
Show file tree
Hide file tree
Showing 53 changed files with 262 additions and 264 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ class ExecCommand implements AgentCommand {
private final KillService killService;
private final ThreadFactory threadFactory;
private final ShutdownProperties shutdownProperties;

private boolean isRunning;
private final ReentrantLock isRunningLock = new ReentrantLock();
private final Condition isRunningCondition = this.isRunningLock.newCondition();
private boolean isRunning;

ExecCommand(
final ExecCommandArguments execCommandArguments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Set<File> downloadJobResources(
* Creates the executable script that executes setup and runs the job (a.k.a. run file).
*
* @param jobSpecification the job specification
* @param jobDirectory the job directory
* @param jobDirectory the job directory
* @return the generated executable script file
* @throws SetUpJobException if the file cannot be created
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ private static class JobScriptComposer {
JobScriptComposer(
final JobSpecification jobSpecification,
final File jobDirectory
) {
) {

this.jobId = jobSpecification.getJob().getId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public abstract class ExecutionStage {
* @param state the state machine state associated with this stage
*/
protected ExecutionStage(
final States state
final States state
) {
this.state = state;
}
Expand All @@ -57,15 +57,15 @@ protected FatalJobExecutionException createFatalException(final String message,

protected FatalJobExecutionException createFatalException(final Throwable cause) {
return this.createFatalException(
"Fatal error in state " + this.getState().name() + ": " + cause.getMessage(),
cause
"Fatal error in state " + this.getState().name() + ": " + cause.getMessage(),
cause
);
}

protected RetryableJobExecutionException createRetryableException(final Throwable cause) {
throw new RetryableJobExecutionException(
"Retryable error in state " + this.getState().name() + ": " + cause.getMessage(),
cause
"Retryable error in state " + this.getState().name() + ": " + cause.getMessage(),
cause
);
}

Expand All @@ -80,6 +80,6 @@ protected RetryableJobExecutionException createRetryableException(final Throwabl
* job id that was already in use)
*/
protected abstract void attemptStageAction(
ExecutionContext executionContext
ExecutionContext executionContext
) throws RetryableJobExecutionException, FatalJobExecutionException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ public void run() {
this.listener.stateMachineStopped();
}

@Override
public void kill(final KillService.KillSource killSource) {
log.info("Shutting down job execution (kill event source: {}", killSource);
if (killSource == KillService.KillSource.REMOTE_STATUS_MONITOR) {
this.executionContext.setSkipFinalStatusUpdate(true);
}
this.executionContext.setJobKilled(true);
this.jobProcessManager.kill(killSource);
}

private void executeStageAction(final States state, final ExecutionStage executionStage) {

// Reset retries backoff
Expand Down Expand Up @@ -188,16 +198,6 @@ private void executeStageAction(final States state, final ExecutionStage executi
}
}

@Override
public void kill(final KillService.KillSource killSource) {
log.info("Shutting down job execution (kill event source: {}", killSource);
if (killSource == KillService.KillSource.REMOTE_STATUS_MONITOR) {
this.executionContext.setSkipFinalStatusUpdate(true);
}
this.executionContext.setJobKilled(true);
this.jobProcessManager.kill(killSource);
}

private static final class CompositeListener implements JobExecutionListener {
private final Collection<JobExecutionListener> listeners;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ResolveJobSpecCommandSpec extends Specification {
def "Write spec to file"() {
setup:
String specId = "12345"
File outputFile = this.temporaryFolder.resolve( "spec.json").toFile()
File outputFile = this.temporaryFolder.resolve("spec.json").toFile()

when:
ExitCode exitCode = command.run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.netflix.genie.agent.execution.exceptions

import com.netflix.genie.proto.ChangeJobArchiveStatusRequest

import spock.lang.Specification
import spock.lang.Unroll

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ class GRpcAgentFileStreamServiceImplSpec extends Specification {
.setDeprecatedStartOffset(0)
.setDeprecatedEndOffset(20)
.setStartOffset(0)
.setEndOffset(20) .build()
.setEndOffset(20).build()
)
.build()
)
Expand Down Expand Up @@ -460,7 +460,7 @@ class GRpcAgentFileStreamServiceImplSpec extends Specification {
Random rnd = new Random()
int fileSize = 0
File largeFile = Files.createFile(temporaryFolder.resolve("large-file.txt")).toFile()
while(fileSize <= fileStreamServiceProperties.getDataChunkMaxSize().toBytes() * 2) {
while (fileSize <= fileStreamServiceProperties.getDataChunkMaxSize().toBytes() * 2) {
byte[] buf = new byte[512]
rnd.nextBytes(buf)
largeFile.append(buf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class GRpcAgentJobKillServiceImplSpec extends Specification {
task.run()

then:
0 * server.registerForKillNotification(_ , _)
0 * server.registerForKillNotification(_, _)

when:
observer.onNext(JobKillRegistrationResponse.newInstance())
Expand All @@ -143,7 +143,6 @@ class GRpcAgentJobKillServiceImplSpec extends Specification {
}



def "Error"() {
Runnable task
ExponentialBackOffTrigger trigger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@
*/
package com.netflix.genie.agent.execution.statemachine.stages

import com.netflix.genie.agent.cli.ArgumentDelegates
import com.netflix.genie.agent.cli.JobRequestConverter
import com.netflix.genie.agent.execution.CleanupStrategy

import com.netflix.genie.agent.execution.exceptions.ConfigureException
import com.netflix.genie.agent.execution.services.AgentJobService
import com.netflix.genie.agent.execution.statemachine.ExecutionContext
import com.netflix.genie.agent.execution.statemachine.ExecutionStage
import com.netflix.genie.agent.execution.statemachine.FatalJobExecutionException
import com.netflix.genie.agent.execution.statemachine.RetryableJobExecutionException
import com.netflix.genie.agent.properties.AgentProperties
import com.netflix.genie.common.external.dtos.v4.AgentClientMetadata
import com.netflix.genie.common.external.dtos.v4.AgentJobRequest
import spock.lang.Specification

import java.time.Duration
Expand Down Expand Up @@ -80,7 +76,7 @@ class ConfigureAgentStageSpec extends Specification {
1 * executionContext.getAgentProperties() >> agentProperties
1 * agentJobService.configure(agentClientMetadata) >> [
'genie.agent.runtime.heart-beat-service.interval': '10s',
'foo.bar': 'blah',
'foo.bar' : 'blah',
]

expect:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class PathUtilsSpec extends Specification {
PathUtils.jobEntitySetupFilePath(entityDirectoryPath).toString() == expectedPath

where:
entityDirectoryPath | expectedPath
jobDirectory.toPath() | jobDirectoryStr + "/genie_setup.sh"
entityDirectoryPath | expectedPath
jobDirectory.toPath() | jobDirectoryStr + "/genie_setup.sh"
PathUtils.jobApplicationDirectoryPath(jobDirectory, "my-app") | jobDirectoryStr + "/genie/applications/my-app/genie_setup.sh"
PathUtils.jobClusterDirectoryPath(jobDirectory, "my-cluster") | jobDirectoryStr + "/genie/cluster/my-cluster/genie_setup.sh"
PathUtils.jobCommandDirectoryPath(jobDirectory, "my-command") | jobDirectoryStr + "/genie/command/my-command/genie_setup.sh"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public interface ClusterService {
* @param tagList The list of tags.
* @param minUpdateTime Minimum Time after which cluster was updated.
* @param maxUpdateTime Maximum Time before which cluster was updated.
* @param size The maximum number of results in the page
* @param sort The sort order
* @param page The page index
* @param size The maximum number of results in the page
* @param sort The sort order
* @param page The page index
* @return A callable object.
*/
@GET(CLUSTER_URL_SUFFIX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class Builder extends CommonRequestImpl.Builder<AgentJobRequest.Builder> {
/**
* Constructor with required parameters.
*
* @param metadata All user supplied metadata
* @param criteria All user supplied execution criteria
* @param requestedAgentConfig The requested configuration of the Genie agent
* @param metadata All user supplied metadata
* @param criteria All user supplied execution criteria
* @param requestedAgentConfig The requested configuration of the Genie agent
*/
@JsonCreator
public Builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public class JobRequest extends CommonRequestImpl implements AgentJobRequest, Ap
/**
* Constructor.
*
* @param requestedId The requested id of the job if one was provided by the user
* @param resources The execution resources (if any) provided by the user
* @param commandArgs Any command args provided by the user
* @param metadata Any metadata related to the job provided by the user
* @param criteria The criteria used by the server to determine execution resources
* (cluster, command, etc)
* @param requestedJobEnvironment The optional job environment request parameters
* @param requestedAgentConfig The optional configuration options for the Genie Agent
* @param requestedId The requested id of the job if one was provided by the user
* @param resources The execution resources (if any) provided by the user
* @param commandArgs Any command args provided by the user
* @param metadata Any metadata related to the job provided by the user
* @param criteria The criteria used by the server to determine execution resources
* (cluster, command, etc)
* @param requestedJobEnvironment The optional job environment request parameters
* @param requestedAgentConfig The optional configuration options for the Genie Agent
*/
public JobRequest(
@Nullable final String requestedId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.netflix.genie.common.external.dtos.v4
import com.google.common.collect.Maps
import com.netflix.genie.test.suppliers.RandomSuppliers
import spock.lang.Specification

/**
* Specifications for the {@link JobRequestMetadata} class.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,39 @@ public S3ProtocolResolver(
this.s3TaskExecutor = s3TaskExecutor;
}

/**
* TODO: It would be nice to use Spring's HttpRange for this parsing, but this module does not
* currently depend on spring-web. And this class cannot be moved to genie-web since it is used by
* {@link S3ProtocolResolver} which is shared with the genie-agent module.
*/
static Pair<Integer, Integer> parseRangeHeader(@Nullable final String rangeHeader) {
if (StringUtils.isBlank(rangeHeader)) {
return NULL_RANGE;
}

final Matcher matcher = RANGE_HEADER_PATTERN.matcher(rangeHeader);

if (!matcher.matches()) {
return NULL_RANGE;
}

final String rangeStartString = matcher.group(1);
final String rangeEndString = matcher.group(2);

Integer rangeStart = null;
Integer rangeEnd = null;

if (!StringUtils.isBlank(rangeStartString)) {
rangeStart = Integer.parseInt(rangeStartString);
}

if (!StringUtils.isBlank(rangeEndString)) {
rangeEnd = Integer.parseInt(rangeEndString);
}

return ImmutablePair.of(rangeStart, rangeEnd);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -128,37 +161,4 @@ public Resource resolve(final String location, final ResourceLoader resourceLoad
return null;
}
}

/**
* TODO: It would be nice to use Spring's HttpRange for this parsing, but this module does not
* currently depend on spring-web. And this class cannot be moved to genie-web since it is used by
* {@link S3ProtocolResolver} which is shared with the genie-agent module.
*/
static Pair<Integer, Integer> parseRangeHeader(@Nullable final String rangeHeader) {
if (StringUtils.isBlank(rangeHeader)) {
return NULL_RANGE;
}

final Matcher matcher = RANGE_HEADER_PATTERN.matcher(rangeHeader);

if (!matcher.matches()) {
return NULL_RANGE;
}

final String rangeStartString = matcher.group(1);
final String rangeEndString = matcher.group(2);

Integer rangeStart = null;
Integer rangeEnd = null;

if (!StringUtils.isBlank(rangeStartString)) {
rangeStart = Integer.parseInt(rangeStartString);
}

if (!StringUtils.isBlank(rangeEndString)) {
rangeEnd = Integer.parseInt(rangeEndString);
}

return ImmutablePair.of(rangeStart, rangeEnd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class SimpleStorageRangeResource extends SimpleStorageResource {
final Pair<Integer, Integer> range
) throws IOException {
super(client, bucket, key, s3TaskExecutor, versionId);
this.client = AmazonS3ProxyFactory.createProxy(client);
this.client = AmazonS3ProxyFactory.createProxy(client);
this.bucket = bucket;
this.key = key;
this.versionId = versionId;
Expand All @@ -83,15 +83,6 @@ public final class SimpleStorageRangeResource extends SimpleStorageResource {
}
}


@Override
public boolean exists() {
if (this.contentLength == -1) {
return false;
}
return super.exists();
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -149,6 +140,14 @@ public InputStream getInputStream() throws IOException {
return new SkipInputStream(skipBytes, inputStream);
}

@Override
public boolean exists() {
if (this.contentLength == -1) {
return false;
}
return super.exists();
}

/**
* An input stream that skips some amount of bytes because they are ignored by the web tier when sending back
* the response content.
Expand All @@ -162,12 +161,6 @@ private static class SkipInputStream extends InputStream {
this.skipBytesLeft = bytesToSkip;
}

@Override
public void close() throws IOException {
super.close();
this.objectRangeInputStream.close();
}

@Override
public int read() throws IOException {
// Overriding other read(...) methods and hoping nobody is using this one directly.
Expand Down Expand Up @@ -204,6 +197,12 @@ public long skip(final long n) throws IOException {

return skipped;
}

@Override
public void close() throws IOException {
super.close();
this.objectRangeInputStream.close();
}
}

private static class EmptyInputStream extends InputStream {
Expand Down
Loading

0 comments on commit 85c5d55

Please sign in to comment.