Search in sources :

Example 1 with MarkLogicException

use of org.talend.components.marklogic.exceptions.MarkLogicException in project components by Talend.

the class MarkLogicConnection method connect.

/**
 * Creates new {@link DatabaseClient} connection or gets referenced one from container.
 *
 * @param container
 * @return connection to MarkLogic database.
 * @throws IOException thrown if referenced connection is not connected.
 */
public DatabaseClient connect(RuntimeContainer container) {
    MarkLogicConnectionProperties properties = getMarkLogicConnectionProperties();
    if (properties.getReferencedComponentId() != null && container != null) {
        DatabaseClient client = (DatabaseClient) container.getComponentData(properties.getReferencedComponentId(), CONNECTION);
        if (client != null) {
            return client;
        }
        throw new MarkLogicException(new MarkLogicErrorCode(MESSAGES.getMessage("error.invalid.referenceConnection", properties.getReferencedComponentId())));
    }
    SecurityContext context = "BASIC".equals(properties.authentication.getValue()) ? new DatabaseClientFactory.BasicAuthContext(properties.username.getValue(), properties.password.getValue()) : new DatabaseClientFactory.DigestAuthContext(properties.username.getValue(), properties.password.getValue());
    DatabaseClient client = DatabaseClientFactory.newClient(properties.host.getValue(), properties.port.getValue(), properties.database.getValue(), context);
    testConnection(client);
    LOGGER.info("Connected to MarkLogic server");
    if (container != null) {
        container.setComponentData(container.getCurrentComponentId(), CONNECTION, client);
        LOGGER.info("Connection stored in container");
    }
    return client;
}
Also used : MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) DatabaseClient(com.marklogic.client.DatabaseClient) DatabaseClientFactory(com.marklogic.client.DatabaseClientFactory) MarkLogicConnectionProperties(org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties) MarkLogicErrorCode(org.talend.components.marklogic.exceptions.MarkLogicErrorCode) SecurityContext(com.marklogic.client.DatabaseClientFactory.SecurityContext)

Example 2 with MarkLogicException

use of org.talend.components.marklogic.exceptions.MarkLogicException in project components by Talend.

the class MarkLogicExternalBulkLoadRunner method runBulkLoading.

@Override
protected void runBulkLoading(String... parameters) {
    String mlcpCommand = parameters[0];
    LOGGER.debug(MESSAGES.getMessage("messages.debug.command", mlcpCommand));
    LOGGER.info(MESSAGES.getMessage("messages.info.startBulkLoad"));
    try {
        Process mlcpProcess = CommandExecutor.executeCommand(mlcpCommand);
        try (InputStream normalInput = mlcpProcess.getInputStream();
            InputStream errorInput = mlcpProcess.getErrorStream()) {
            Thread normalInputReadProcess = getInputReadProcess(normalInput, System.out);
            normalInputReadProcess.start();
            Thread errorInputReadProcess = getInputReadProcess(errorInput, System.err);
            errorInputReadProcess.start();
            mlcpProcess.waitFor();
            normalInputReadProcess.interrupt();
            errorInputReadProcess.interrupt();
            LOGGER.info(MESSAGES.getMessage("messages.info.finishBulkLoad"));
        }
    } catch (Exception e) {
        LOGGER.error(MESSAGES.getMessage("messages.error.exception", e.getMessage()));
        throw new MarkLogicException(new MarkLogicErrorCode(e.getMessage()), e);
    }
}
Also used : MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) InputStream(java.io.InputStream) MarkLogicErrorCode(org.talend.components.marklogic.exceptions.MarkLogicErrorCode) MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) IOException(java.io.IOException)

Example 3 with MarkLogicException

use of org.talend.components.marklogic.exceptions.MarkLogicException in project components by Talend.

the class MarkLogicInternalBulkLoadRunner method runBulkLoading.

@Override
protected void runBulkLoading(String... parameters) {
    LOGGER.debug(MESSAGES.getMessage("messages.debug.command", parameters));
    LOGGER.info(MESSAGES.getMessage("messages.info.startBulkLoad"));
    try {
        ContentPump.runCommand(parameters);
    } catch (IOException e) {
        String errorMessage = MESSAGES.getMessage("messages.error.exception");
        LOGGER.error(errorMessage, e.getMessage());
        throw new MarkLogicException(new MarkLogicErrorCode(errorMessage), e);
    }
}
Also used : MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) MarkLogicErrorCode(org.talend.components.marklogic.exceptions.MarkLogicErrorCode) IOException(java.io.IOException)

Example 4 with MarkLogicException

use of org.talend.components.marklogic.exceptions.MarkLogicException in project components by Talend.

the class MarkLogicDataSource method validate.

@Override
public ValidationResult validate(RuntimeContainer container) {
    ValidationResult validationResult;
    try {
        connect(container);
        validationResult = ValidationResult.OK;
    } catch (MarkLogicException me) {
        validationResult = new ValidationResult(me);
    }
    return validationResult;
}
Also used : MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) ValidationResult(org.talend.daikon.properties.ValidationResult)

Example 5 with MarkLogicException

use of org.talend.components.marklogic.exceptions.MarkLogicException in project components by Talend.

the class MarkLogicSourceOrSink method checkDocContentTypeSupported.

protected void checkDocContentTypeSupported(SchemaProperties outputSchema) {
    boolean isDocContentFieldPresent = outputSchema.schema.getValue().getFields().size() >= 2;
    if (isDocContentFieldPresent) {
        Schema.Field docContentField = outputSchema.schema.getValue().getFields().get(1);
        boolean isAvroStringOrBytes = ((docContentField.schema().getType().equals(Schema.Type.STRING) || docContentField.schema().getType().equals(Schema.Type.BYTES)) && docContentField.schema().getProp(SchemaConstants.JAVA_CLASS_FLAG) == null);
        boolean isTalendTypeSupported = false;
        String talendType = docContentField.getProp("di.column.talendType");
        if (talendType != null) {
            isTalendTypeSupported = (talendType.equals("id_Object") || talendType.equals("id_String") || talendType.equals("id_Document") || talendType.equals("id_byte[]"));
        }
        if (!(isAvroStringOrBytes || isTalendTypeSupported)) {
            throw new MarkLogicException(new MarkLogicErrorCode("Wrong docContent type"));
        }
    } else if (outputSchema.schema.getValue().getFields().size() != 1) {
        // it is ok to have only docId field
        throw new MarkLogicException(new MarkLogicErrorCode("No docContent field in the schema"));
    }
}
Also used : MarkLogicException(org.talend.components.marklogic.exceptions.MarkLogicException) Schema(org.apache.avro.Schema) MarkLogicErrorCode(org.talend.components.marklogic.exceptions.MarkLogicErrorCode)

Aggregations

MarkLogicException (org.talend.components.marklogic.exceptions.MarkLogicException)8 MarkLogicErrorCode (org.talend.components.marklogic.exceptions.MarkLogicErrorCode)7 IOException (java.io.IOException)3 Schema (org.apache.avro.Schema)2 GenericData (org.apache.avro.generic.GenericData)2 DatabaseClient (com.marklogic.client.DatabaseClient)1 DatabaseClientFactory (com.marklogic.client.DatabaseClientFactory)1 SecurityContext (com.marklogic.client.DatabaseClientFactory.SecurityContext)1 StringHandle (com.marklogic.client.io.StringHandle)1 MatchDocumentSummary (com.marklogic.client.query.MatchDocumentSummary)1 InputStream (java.io.InputStream)1 NoSuchElementException (java.util.NoSuchElementException)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 MarkLogicConnectionProperties (org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1