Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 6, 2025. It is now read-only.
/GafferPublic archive

Gh-2478: JobTracker tracks all operations, not just jobs#3347

Merged
wb36499 merged 7 commits intodevelopfromgh-2478-remove-job-tracker-from-execute
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
job tracker fixes
  • Loading branch information
@cn337131
cn337131 committedJan 6, 2025
commit779e53f65dea28b54957fe53c4b44e9c659b3c70
12 changes: 2 additions & 10 deletionscore/store/src/main/java/uk/gov/gchq/gaffer/store/Store.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 Crown Copyright
* Copyright 2016-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand DownExpand Up@@ -386,15 +386,7 @@ public <O> O execute(final Output<O> operation, final Context context) throws Op
}

protected <O> O execute(final OperationChain<O> operation, final Context context) throws OperationException {
try {
addOrUpdateJobDetail(operation, context, null, JobStatus.RUNNING);
final O result = (O) handleOperation(operation, context);
addOrUpdateJobDetail(operation, context, null, JobStatus.FINISHED);
return result;
} catch (final Throwable t) {
addOrUpdateJobDetail(operation, context, t.getMessage(), JobStatus.FAILED);
throw t;
}
return (O) handleOperation(operation, context);
}

/**
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 Crown Copyright
* Copyright 2016-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand DownExpand Up@@ -274,7 +274,7 @@ public void shouldExecuteOperationWhenJobTrackerCacheIsBroken(@Mock final StoreP
store.initialise("graphId", createSchemaMock(), storeProperties);

// When
store.execute(addElements, context);
store.executeJob(addElements, context);

// Then
verify(addElementsHandler).doOperation(addElements, context, store);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 Crown Copyright
* Copyright 2020-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All@@ -17,7 +17,6 @@
package uk.gov.gchq.gaffer.rest.service.v2;

import uk.gov.gchq.gaffer.commonutil.CloseableUtil;
import uk.gov.gchq.gaffer.commonutil.pair.Pair;
import uk.gov.gchq.gaffer.core.exception.GafferRuntimeException;
import uk.gov.gchq.gaffer.core.exception.Status;
import uk.gov.gchq.gaffer.graph.GraphRequest;
Expand DownExpand Up@@ -97,7 +96,7 @@ protected void postOperationHook(final OperationChain<?> opChain, final Context
}

@SuppressWarnings({"ThrowFromFinallyBlock", "PMD.UseTryWithResources"})
protected <O>Pair<O, String> _execute(final Operation operation, final Context context) {
protected <O>O _execute(final Operation operation, final Context context) {

OperationChain<O> opChain = (OperationChain<O>) OperationChain.wrap(operation);

Expand All@@ -119,7 +118,7 @@ protected <O> Pair<O, String> _execute(final Operation operation, final Context
}
}

returnnew Pair<>(result.getResult(), result.getContext().getJobId());
return result.getResult();
}

protected Operation generateExampleJson(final Class<? extends Operation> opClass) throws IllegalAccessException, InstantiationException {
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 Crown Copyright
* Copyright 2016-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand DownExpand Up@@ -42,8 +42,6 @@
import static uk.gov.gchq.gaffer.rest.ServiceConstants.GAFFER_MEDIA_TYPE_HEADER;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.GAFFER_MEDIA_TYPE_HEADER_DESCRIPTION;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.INTERNAL_SERVER_ERROR;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.JOB_ID_HEADER;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.JOB_ID_HEADER_DESCRIPTION;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.OK;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.OPERATION_NOT_FOUND;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.OPERATION_NOT_IMPLEMENTED;
Expand DownExpand Up@@ -91,7 +89,6 @@ public interface IOperationServiceV2 {
produces = (APPLICATION_JSON + "," + TEXT_PLAIN),
response = Object.class,
responseHeaders = {
@ResponseHeader(name = JOB_ID_HEADER, description = JOB_ID_HEADER_DESCRIPTION),
@ResponseHeader(name = GAFFER_MEDIA_TYPE_HEADER, description = GAFFER_MEDIA_TYPE_HEADER_DESCRIPTION)
})
@ApiResponses(value = {@ApiResponse(code = 200, message = OK, response = Object.class),
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Crown Copyright
* Copyright 2017-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All@@ -24,7 +24,6 @@

import uk.gov.gchq.gaffer.commonutil.CloseableUtil;
import uk.gov.gchq.gaffer.commonutil.exception.UnauthorisedException;
import uk.gov.gchq.gaffer.commonutil.pair.Pair;
import uk.gov.gchq.gaffer.core.exception.Error;
import uk.gov.gchq.gaffer.core.exception.Status;
import uk.gov.gchq.gaffer.operation.Operation;
Expand All@@ -45,7 +44,6 @@
import static uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser.createDefaultMapper;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.GAFFER_MEDIA_TYPE;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.GAFFER_MEDIA_TYPE_HEADER;
import static uk.gov.gchq.gaffer.rest.ServiceConstants.JOB_ID_HEADER;

/**
* An implementation of {@link IOperationServiceV2}. By default it will use a singleton
Expand DownExpand Up@@ -85,10 +83,9 @@ public Response getOperationDetails() {

@Override
public Response execute(final Operation operation) {
finalPair<Object, String> resultAndJobId = _execute(operation, userFactory.createContext());
return Response.ok(resultAndJobId.getFirst())
final Object result = _execute(operation, userFactory.createContext());
return Response.ok(result)
.header(GAFFER_MEDIA_TYPE_HEADER, GAFFER_MEDIA_TYPE)
.header(JOB_ID_HEADER, resultAndJobId.getSecond())
.build();
}

Expand All@@ -109,7 +106,7 @@ public Response executeChunkedChain(final OperationChain opChain) {
// create thread to write chunks to the chunked output object
Thread thread = new Thread(() -> {
try {
final Object result = _execute(opChain, context).getFirst();
final Object result = _execute(opChain, context);
chunkResult(result, output);
} catch (final Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 Crown Copyright
* Copyright 2019-2025 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand DownExpand Up@@ -35,14 +35,12 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

publicclass JobServiceV2IT extends AbstractRestApiV2IT {
class JobServiceV2IT extends AbstractRestApiV2IT {

@Test
publicvoid shouldCorrectlyDoAndThenCancelScheduledJob() throws IOException, InterruptedException {
void shouldCorrectlyDoAndThenCancelScheduledJob() throws IOException, InterruptedException {
// When
final Repeat repeat = new Repeat(1, 2, TimeUnit.SECONDS);
Job job = new Job(repeat, new OperationChain.Builder().first(new GetAllElements()).build());
Expand All@@ -52,7 +50,7 @@ public void shouldCorrectlyDoAndThenCancelScheduledJob() throws IOException, Int
});

// Then
assertEquals(201,jobSchedulingResponse.getStatus());
assertThat(jobSchedulingResponse.getStatus()).isEqualTo(201);
String parentJobId = jobSchedulingDetail.getJobId();

// Wait for first scheduled to run
Expand All@@ -65,10 +63,10 @@ public void shouldCorrectlyDoAndThenCancelScheduledJob() throws IOException, Int

for (JobDetail jobDetail : jobDetails) {
if (null != jobDetail.getParentJobId() && jobDetail.getParentJobId().equals(parentJobId)) {
assertEquals(JobStatus.FINISHED,jobDetail.getStatus());
assertThat(jobDetail.getStatus()).isEqualTo(JobStatus.FINISHED);
}
if (jobDetail.getJobId().equals(parentJobId)) {
assertEquals(JobStatus.SCHEDULED_PARENT,jobDetail.getStatus());
assertThat(jobDetail.getStatus()).isEqualTo(JobStatus.SCHEDULED_PARENT);
}
}

Expand All@@ -81,13 +79,13 @@ public void shouldCorrectlyDoAndThenCancelScheduledJob() throws IOException, Int

for (JobDetail jobDetail : jobDetailsAfterCancelled) {
if (parentJobId.equals(jobDetail.getJobId())) {
assertEquals(JobStatus.CANCELLED,jobDetail.getStatus());
assertThat(jobDetail.getStatus()).isEqualTo(JobStatus.CANCELLED);
}
}
}

@Test
publicvoid shouldNotKeepScheduledJobsRunningAfterRestartWhenUsingInMemoryCache() throws IOException {
void shouldNotKeepScheduledJobsRunningAfterRestartWhenUsingInMemoryCache() throws IOException {
// Given - schedule Job
final Repeat repeat = new Repeat(1, 2, TimeUnit.SECONDS);
Job job = new Job(repeat, new OperationChain.Builder().first(new GetAllElements()).build());
Expand All@@ -104,8 +102,8 @@ public void shouldNotKeepScheduledJobsRunningAfterRestartWhenUsingInMemoryCache(
});

// then - assert parent is of Scheduled parent
assertEquals(JobStatus.SCHEDULED_PARENT,
allJobDetails.stream().filter(jobDetail -> jobDetail.getJobId().equals(parentJobId)).findFirst().get().getStatus());
JobStatus jobStatus = allJobDetails.stream().filter(jobDetail -> jobDetail.getJobId().equals(parentJobId)).findFirst().get().getStatus();
assertThat(jobStatus).isEqualTo(JobStatus.SCHEDULED_PARENT);

// Restart server to check Job still scheduled
client.stopServer();
Expand All@@ -119,15 +117,15 @@ public void shouldNotKeepScheduledJobsRunningAfterRestartWhenUsingInMemoryCache(
});

// Then - assert parent job id is not present
assertTrue(allJobDetails2.stream().noneMatch(jobDetail -> jobDetail.getJobId().equals(parentJobId)));
assertThat(allJobDetails2.stream().noneMatch(jobDetail -> jobDetail.getJobId().equals(parentJobId))).isTrue();
}

@Test
publicvoidshouldReturnJobIdHeader() throws IOException {
voidshouldNotReturnJobIdHeader() throws IOException {
// When
final Response response = client.executeOperation(new GetAllElements());

// Then
assertNotNull(response.getHeaderString(ServiceConstants.JOB_ID_HEADER));
assertThat(response.getHeaders().toString()).doesNotContain(ServiceConstants.JOB_ID_HEADER);
}
}
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp