Search in sources :

Example 6 with BadRequestException

use of com.azure.cosmos.implementation.BadRequestException in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosTransferProcessStore method update.

@Override
public void update(TransferProcess process) {
    var document = new TransferProcessDocument(process, partitionKey);
    try {
        leaseContext.acquireLease(process.getId());
        failsafeExecutor.run(() -> cosmosDbApi.saveItem(document));
        leaseContext.breakLease(process.getId());
    } catch (BadRequestException ex) {
        throw new EdcException(ex);
    }
}
Also used : TransferProcessDocument(org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument) BadRequestException(com.azure.cosmos.implementation.BadRequestException) EdcException(org.eclipse.dataspaceconnector.spi.EdcException)

Example 7 with BadRequestException

use of com.azure.cosmos.implementation.BadRequestException in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosContractNegotiationStore method save.

@Override
public void save(ContractNegotiation negotiation) {
    try {
        leaseContext.acquireLease(negotiation.getId());
        with(retryPolicy).run(() -> cosmosDbApi.saveItem(new ContractNegotiationDocument(negotiation, partitionKey)));
        leaseContext.breakLease(negotiation.getId());
    } catch (BadRequestException ex) {
        throw new EdcException(ex);
    }
}
Also used : ContractNegotiationDocument(org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument) BadRequestException(com.azure.cosmos.implementation.BadRequestException) EdcException(org.eclipse.dataspaceconnector.spi.EdcException)

Example 8 with BadRequestException

use of com.azure.cosmos.implementation.BadRequestException in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosContractNegotiationStore method delete.

@Override
public void delete(String negotiationId) {
    try {
        leaseContext.acquireLease(negotiationId);
        with(retryPolicy).run(() -> cosmosDbApi.deleteItem(negotiationId));
        leaseContext.breakLease(negotiationId);
    } catch (BadRequestException ex) {
        throw new EdcException(ex);
    }
}
Also used : BadRequestException(com.azure.cosmos.implementation.BadRequestException) EdcException(org.eclipse.dataspaceconnector.spi.EdcException)

Example 9 with BadRequestException

use of com.azure.cosmos.implementation.BadRequestException in project kafka-connect-cosmosdb by microsoft.

the class CosmosDBSinkTaskTest method testPutPlainTextString.

@Test
public void testPutPlainTextString() {
    Schema stringSchema = new ConnectSchema(Schema.Type.STRING);
    SinkRecord record = new SinkRecord(topicName, 1, stringSchema, "nokey", stringSchema, "foo", 0L);
    assertNotNull(record.value());
    // Make mock connector to serialize a non-JSON payload
    when(mockContainer.upsertItem(any())).then((invocation) -> {
        Object item = invocation.getArgument(0);
        // Will throw exception:
        try {
            JsonNode jsonNode = new ObjectMapper().readTree(item.toString());
            assertNotNull(jsonNode);
            return null;
        } catch (JsonParseException jpe) {
            throw new BadRequestException("Unable to serialize JSON request", jpe);
        }
    });
    try {
        testTask.put(Arrays.asList(record));
        fail("Expected ConnectException on bad message");
    } catch (ConnectException ce) {
    } catch (Throwable t) {
        fail("Expected ConnectException, but got: " + t.getClass().getName());
    }
    verify(mockContainer, times(1)).upsertItem("foo");
}
Also used : Schema(org.apache.kafka.connect.data.Schema) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) BadRequestException(com.azure.cosmos.implementation.BadRequestException) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) JsonNode(com.fasterxml.jackson.databind.JsonNode) SinkRecord(org.apache.kafka.connect.sink.SinkRecord) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConnectException(org.apache.kafka.connect.errors.ConnectException) Test(org.junit.Test)

Example 10 with BadRequestException

use of com.azure.cosmos.implementation.BadRequestException in project kafka-connect-cosmosdb by microsoft.

the class CosmosDBSinkTaskTestNotFails method testPutMapThatFailsDoesNotStopTaskWithdlq.

@Test
public void testPutMapThatFailsDoesNotStopTaskWithdlq() throws JsonProcessingException, IllegalAccessException {
    FieldUtils.writeField(testTask, "context", mockContext, true);
    Schema stringSchema = new ConnectSchema(Schema.Type.STRING);
    Schema mapSchema = new ConnectSchema(Schema.Type.MAP);
    when(mockContainer.upsertItem(any())).thenThrow(new BadRequestException("Something"));
    SinkRecord record = new SinkRecord(topicName, 1, stringSchema, "nokey", mapSchema, "{", 0L);
    testTask.put(List.of(record));
    verify(mockContext.errantRecordReporter(), times(1)).report(any(), any());
}
Also used : Schema(org.apache.kafka.connect.data.Schema) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) BadRequestException(com.azure.cosmos.implementation.BadRequestException) ConnectSchema(org.apache.kafka.connect.data.ConnectSchema) SinkRecord(org.apache.kafka.connect.sink.SinkRecord) Test(org.junit.Test)

Aggregations

BadRequestException (com.azure.cosmos.implementation.BadRequestException)10 Test (org.junit.jupiter.api.Test)4 ConnectSchema (org.apache.kafka.connect.data.ConnectSchema)3 Schema (org.apache.kafka.connect.data.Schema)3 SinkRecord (org.apache.kafka.connect.sink.SinkRecord)3 EdcException (org.eclipse.dataspaceconnector.spi.EdcException)3 Test (org.junit.Test)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ConnectException (org.apache.kafka.connect.errors.ConnectException)1 ContractNegotiationDocument (org.eclipse.dataspaceconnector.contract.negotiation.store.model.ContractNegotiationDocument)1 TransferProcessDocument (org.eclipse.dataspaceconnector.transfer.store.cosmos.model.TransferProcessDocument)1