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;
}
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);
}
}
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);
}
}
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;
}
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"));
}
}
Aggregations