use of com.mongodb.CommandResult in project graylog2-server by Graylog2.
the class MongoProbe method createBuildInfo.
private static BuildInfo createBuildInfo(DB adminDb) {
final BuildInfo buildInfo;
final CommandResult buildInfoResult = adminDb.command("buildInfo");
if (buildInfoResult.ok()) {
buildInfo = BuildInfo.create(buildInfoResult.getString("version"), buildInfoResult.getString("gitVersion"), buildInfoResult.getString("sysInfo"), buildInfoResult.getString("loaderFlags"), buildInfoResult.getString("compilerFlags"), buildInfoResult.getString("allocator"), (List<Integer>) buildInfoResult.get("versionArray"), buildInfoResult.getString("javascriptEngine"), buildInfoResult.getInt("bits"), buildInfoResult.getBoolean("debug"), buildInfoResult.getLong("maxBsonObjectSize"));
} else {
LOG.debug("Couldn't retrieve MongoDB buildInfo: {}", buildInfoResult.getErrorMessage());
buildInfo = null;
}
return buildInfo;
}
use of com.mongodb.CommandResult in project incubator-skywalking by apache.
the class MongoDBCollectionMethodInterceptor method afterMethod.
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
AbstractSpan activeSpan = ContextManager.activeSpan();
CommandResult cresult = null;
if (ret instanceof WriteResult) {
WriteResult wresult = (WriteResult) ret;
cresult = wresult.getCachedLastError();
} else if (ret instanceof AggregationOutput) {
AggregationOutput aresult = (AggregationOutput) ret;
cresult = aresult.getCommandResult();
}
if (null != cresult && !cresult.ok()) {
activeSpan.log(cresult.getException());
}
ContextManager.stopSpan();
return ret;
}
use of com.mongodb.CommandResult in project embedmongo-maven-plugin by joelittlejohn.
the class MongoScriptsMojo method executeStart.
@Override
public void executeStart() throws MojoExecutionException, MojoFailureException {
DB db = connectToMongoAndGetDatabase();
if (scriptsDirectory.isDirectory()) {
Scanner scanner = null;
StringBuilder instructions = new StringBuilder();
File[] files = scriptsDirectory.listFiles();
if (files == null) {
getLog().info("Can't read scripts directory: " + scriptsDirectory.getAbsolutePath());
} else {
getLog().info("Folder " + scriptsDirectory.getAbsolutePath() + " contains " + files.length + " file(s):");
for (File file : files) {
if (file.isFile()) {
try {
if (scriptCharsetEncoding == null) {
scanner = new Scanner(file);
} else {
// no need to check encoding, the constructor throws
// an IllegalArgumentException if the charset cannot be determined
// from the provided value.
scanner = new Scanner(file, scriptCharsetEncoding);
}
while (scanner.hasNextLine()) {
instructions.append(scanner.nextLine()).append("\n");
}
} catch (FileNotFoundException e) {
throw new MojoExecutionException("Unable to find file with name '" + file.getName() + "'", e);
} catch (IllegalArgumentException e) {
throw new MojoExecutionException("Unable to determine charset encoding for provided charset '" + scriptCharsetEncoding + "'", e);
} finally {
if (scanner != null) {
scanner.close();
}
}
CommandResult result;
try {
result = db.doEval("(function() {" + instructions.toString() + "})();", new Object[0]);
} catch (MongoException e) {
throw new MojoExecutionException("Unable to execute file with name '" + file.getName() + "'", e);
}
if (!result.ok()) {
getLog().error("- file " + file.getName() + " parsed with error: " + result.getErrorMessage());
throw new MojoExecutionException("Error while executing instructions from file '" + file.getName() + "': " + result.getErrorMessage(), result.getException());
}
getLog().info("- file " + file.getName() + " parsed successfully");
}
}
}
getLog().info("Data initialized with success");
}
}
use of com.mongodb.CommandResult in project embedmongo-maven-plugin by joelittlejohn.
the class MongoScriptsMojoTest method should_fail_to_execute_instruction_with_error.
@Test
public void should_fail_to_execute_instruction_with_error() throws IOException, MojoFailureException, MojoExecutionException {
DB database = mock(DB.class);
initFolderWithError();
CommandResult result = new EmbedMongoDB("myDB").notOkErrorResult("Error while executing instructions from file '" + rootFolderWithError.listFiles()[0].getName());
given(database.doEval(anyString(), Matchers.<Object>anyVararg())).willReturn(result);
thrown.expect(MojoExecutionException.class);
thrown.expectMessage("Error while executing instructions from file '" + rootFolderWithError.listFiles()[0].getName());
new MongoScriptsMojoForTest(rootFolderWithError, PORT, "myDB", database, null).execute();
}
use of com.mongodb.CommandResult in project symmetric-ds by JumpMind.
the class MongoDatabaseWriter method sql.
@Override
protected boolean sql(CsvData data) {
statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS);
try {
DB db = clientManager.getDB(objectMapper.mapToDatabase(this.targetTable));
String command = data.getParsedData(CsvData.ROW_DATA)[0];
log.info("About to run command: {}", command);
CommandResult results = db.command(command);
log.info("The results of the command were: {}", results);
} finally {
statistics.get(batch).stopTimer(DataWriterStatisticConstants.DATABASEMILLIS);
}
return true;
}
Aggregations