Search in sources :

Example 11 with ConflictException

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);
}
Also used : WorkerManager(io.cdap.cdap.test.WorkerManager) ApplicationManager(io.cdap.cdap.test.ApplicationManager) ConflictException(io.cdap.cdap.common.ConflictException) WorkflowManager(io.cdap.cdap.test.WorkflowManager) File(java.io.File) IOException(java.io.IOException) ConflictException(io.cdap.cdap.common.ConflictException) Test(org.junit.Test)

Example 12 with ConflictException

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);
}
Also used : WorkerManager(io.cdap.cdap.test.WorkerManager) ApplicationManager(io.cdap.cdap.test.ApplicationManager) ConflictException(io.cdap.cdap.common.ConflictException) WorkflowManager(io.cdap.cdap.test.WorkflowManager) File(java.io.File) IOException(java.io.IOException) ConflictException(io.cdap.cdap.common.ConflictException) Test(org.junit.Test)

Example 13 with ConflictException

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;
        }
    }
}
Also used : HashMap(java.util.HashMap) ConflictException(io.cdap.cdap.common.ConflictException) ProfileMetadataMessageProcessor(io.cdap.cdap.metadata.profile.ProfileMetadataMessageProcessor) EntityType(io.cdap.cdap.proto.element.EntityType) MetadataMessage(io.cdap.cdap.data2.metadata.writer.MetadataMessage) ProfileMetadataMessageProcessor(io.cdap.cdap.metadata.profile.ProfileMetadataMessageProcessor)

Example 14 with ConflictException

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.");
        }
    }
}
Also used : ProgramScheduleStatus(io.cdap.cdap.internal.app.runtime.schedule.ProgramScheduleStatus) AlreadyExistsException(io.cdap.cdap.common.AlreadyExistsException) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) ConflictException(io.cdap.cdap.common.ConflictException)

Example 15 with ConflictException

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());
    }
}
Also used : ConflictException(io.cdap.cdap.common.ConflictException) DatasetProperties(io.cdap.cdap.api.dataset.DatasetProperties) DatasetSpecification(io.cdap.cdap.api.dataset.DatasetSpecification) DatasetTypeMeta(io.cdap.cdap.proto.DatasetTypeMeta) DatasetId(io.cdap.cdap.proto.id.DatasetId) IncompatibleUpdateException(io.cdap.cdap.api.dataset.IncompatibleUpdateException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

ConflictException (io.cdap.cdap.common.ConflictException)36 NotFoundException (io.cdap.cdap.common.NotFoundException)14 IOException (java.io.IOException)10 POST (javax.ws.rs.POST)10 Path (javax.ws.rs.Path)10 BadRequestException (io.cdap.cdap.common.BadRequestException)8 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)8 ProgramId (io.cdap.cdap.proto.id.ProgramId)8 UnauthorizedException (io.cdap.cdap.security.spi.authorization.UnauthorizedException)8 JsonSyntaxException (com.google.gson.JsonSyntaxException)6 DatasetManagementException (io.cdap.cdap.api.dataset.DatasetManagementException)6 AccessException (io.cdap.cdap.api.security.AccessException)6 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)6 ArtifactAlreadyExistsException (io.cdap.cdap.common.ArtifactAlreadyExistsException)6 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)6 File (java.io.File)6 InvalidArtifactException (io.cdap.cdap.common.InvalidArtifactException)5 NotImplementedException (io.cdap.cdap.common.NotImplementedException)5 ServiceException (io.cdap.cdap.common.ServiceException)5 WriteConflictException (io.cdap.cdap.internal.app.runtime.artifact.WriteConflictException)5