use of io.cdap.cdap.common.ConflictException in project cdap by caskdata.
the class TestFrameworkTestRun method testConcurrentRuns.
@Test
public void testConcurrentRuns() throws Exception {
ApplicationManager appManager = deployApplication(ConcurrentRunTestApp.class);
WorkerManager workerManager = appManager.getWorkerManager(ConcurrentRunTestApp.TestWorker.class.getSimpleName());
workerManager.start();
// Start another time should fail as worker doesn't support concurrent run.
workerManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS);
try {
workerManager.start();
Assert.fail("Expected failure to start worker");
} catch (Exception e) {
Assert.assertTrue(Throwables.getRootCause(e) instanceof ConflictException);
}
workerManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS);
workerManager.stop();
// Start the workflow
File tmpDir = TEMP_FOLDER.newFolder();
File actionFile = new File(tmpDir, "action.file");
Map<String, String> args = Collections.singletonMap("action.file", actionFile.getAbsolutePath());
WorkflowManager workflowManager = appManager.getWorkflowManager(ConcurrentRunTestApp.TestWorkflow.class.getSimpleName());
// Starts two runs, both should succeed
workflowManager.start(args);
workflowManager.start(args);
// Should get two active runs
workflowManager.waitForRuns(ProgramRunStatus.RUNNING, 2, 10L, TimeUnit.SECONDS);
// Touch the file to complete the workflow runs
Files.touch(actionFile);
workflowManager.waitForRuns(ProgramRunStatus.COMPLETED, 2, 10L, TimeUnit.SECONDS);
}
use of io.cdap.cdap.common.ConflictException in project cdap by cdapio.
the class TestFrameworkTestRun method testConcurrentRuns.
@Test
public void testConcurrentRuns() throws Exception {
ApplicationManager appManager = deployApplication(ConcurrentRunTestApp.class);
WorkerManager workerManager = appManager.getWorkerManager(ConcurrentRunTestApp.TestWorker.class.getSimpleName());
workerManager.start();
// Start another time should fail as worker doesn't support concurrent run.
workerManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS);
try {
workerManager.start();
Assert.fail("Expected failure to start worker");
} catch (Exception e) {
Assert.assertTrue(Throwables.getRootCause(e) instanceof ConflictException);
}
workerManager.waitForRun(ProgramRunStatus.RUNNING, 10, TimeUnit.SECONDS);
workerManager.stop();
// Start the workflow
File tmpDir = TEMP_FOLDER.newFolder();
File actionFile = new File(tmpDir, "action.file");
Map<String, String> args = Collections.singletonMap("action.file", actionFile.getAbsolutePath());
WorkflowManager workflowManager = appManager.getWorkflowManager(ConcurrentRunTestApp.TestWorkflow.class.getSimpleName());
// Starts two runs, both should succeed
workflowManager.start(args);
workflowManager.start(args);
// Should get two active runs
workflowManager.waitForRuns(ProgramRunStatus.RUNNING, 2, 10L, TimeUnit.SECONDS);
// Touch the file to complete the workflow runs
Files.touch(actionFile);
workflowManager.waitForRuns(ProgramRunStatus.COMPLETED, 2, 10L, TimeUnit.SECONDS);
}
use of io.cdap.cdap.common.ConflictException in project cdap by cdapio.
the class MetadataSubscriberService method processMessages.
@Override
protected void processMessages(StructuredTableContext structuredTableContext, Iterator<ImmutablePair<String, MetadataMessage>> messages) throws IOException, ConflictException {
Map<MetadataMessage.Type, MetadataMessageProcessor> processors = new HashMap<>();
// Loop over all fetched messages and process them with corresponding MetadataMessageProcessor
while (messages.hasNext()) {
ImmutablePair<String, MetadataMessage> next = messages.next();
String messageId = next.getFirst();
MetadataMessage message = next.getSecond();
MetadataMessageProcessor processor = processors.computeIfAbsent(message.getType(), type -> {
switch(type) {
case LINEAGE:
return new DataAccessLineageProcessor();
case FIELD_LINEAGE:
return new FieldLineageProcessor();
case USAGE:
return new UsageProcessor();
case WORKFLOW_TOKEN:
case WORKFLOW_STATE:
return new WorkflowProcessor();
case METADATA_OPERATION:
return new MetadataOperationProcessor(cConf);
case PROFILE_ASSIGNMENT:
case PROFILE_UNASSIGNMENT:
case ENTITY_CREATION:
case ENTITY_DELETION:
return new ProfileMetadataMessageProcessor(metadataStorage, structuredTableContext, metricsCollectionService);
default:
return null;
}
});
// noinspection ConstantConditions
if (processor == null) {
LOG.warn("Unsupported metadata message type {}. Message ignored.", message.getType());
continue;
}
try {
processor.processMessage(message, structuredTableContext);
conflictCount = 0;
} catch (ConflictException e) {
if (messageId.equals(conflictMessageId)) {
conflictCount++;
if (conflictCount >= maxRetriesOnConflict) {
LOG.warn("Skipping metadata message {} after processing it has caused {} consecutive conflicts: {}", message, conflictCount, e.getMessage());
continue;
}
} else {
conflictMessageId = messageId;
conflictCount = 1;
}
throw e;
}
}
}
use of io.cdap.cdap.common.ConflictException in project cdap by cdapio.
the class CoreSchedulerService method updateSchedule.
@Override
public void updateSchedule(ProgramSchedule schedule) throws NotFoundException, BadRequestException, ProfileConflictException {
checkStarted();
ProgramScheduleStatus previousStatus = getScheduleStatus(schedule.getScheduleId());
deleteSchedule(schedule.getScheduleId());
try {
addSchedule(schedule);
} catch (AlreadyExistsException e) {
// Should never reach here because we just deleted it
throw new IllegalStateException("Schedule '" + schedule.getScheduleId() + "' already exists despite just being deleted.");
}
// if the schedule was previously enabled, it should still/again enabled be after the update
if (ProgramScheduleStatus.SCHEDULED == previousStatus) {
try {
enableSchedule(schedule.getScheduleId());
} catch (ConflictException e) {
// Should never reach here because we just added this
throw new IllegalStateException("Schedule '" + schedule.getScheduleId() + "' already enabled despite just being added.");
}
}
}
use of io.cdap.cdap.common.ConflictException in project cdap by cdapio.
the class DatasetAdminOpHTTPHandler method update.
@POST
@Path("/data/datasets/{name}/admin/update")
public void update(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String name) throws Exception {
propagateUserId(request);
InternalDatasetUpdateParams params = GSON.fromJson(request.content().toString(StandardCharsets.UTF_8), InternalDatasetUpdateParams.class);
Preconditions.checkArgument(params.getProperties() != null, "Missing required 'instanceProps' parameter.");
Preconditions.checkArgument(params.getTypeMeta() != null, "Missing required 'typeMeta' parameter.");
Preconditions.checkArgument(params.getExistingSpec() != null, "Missing required 'existingSpec' parameter.");
DatasetProperties props = params.getProperties();
DatasetSpecification existing = params.getExistingSpec();
DatasetTypeMeta typeMeta = params.getTypeMeta();
try {
DatasetId instanceId = new DatasetId(namespaceId, name);
DatasetCreationResponse response = datasetAdminService.createOrUpdate(instanceId, typeMeta, props, existing);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(response));
} catch (IncompatibleUpdateException e) {
throw new ConflictException(e.getMessage());
}
}
Aggregations