public static Object addFile(MongoConnector dbc, String jar) throws FileNotFoundException, URISyntaxException { URL path = ClassLoader.getSystemResource(jar); File f = new File(path.toURI()); return dbc.getPipelineWriter().save(f.getName(), new FileInputStream(f)); } }
@SuppressWarnings("unchecked") private boolean contains(Object object, String needle) { if (object instanceof String) { return ((String) object).contains(needle); } else if (object instanceof List<?>) { for (Object o : (List<?>) object) { if (contains(o, needle)) { return true; } } } else if (object instanceof Map<?, ?>) { for (Map.Entry<Object, Object> o : ((Map<Object, Object>) object) .entrySet()) { if (contains(o.getKey(), needle) || contains(o.getValue(), needle)) { return true; } } } return false; } }
MongoConnector mdc =new MongoConnector(conf.getConfiguration()); mdc.connect(); mdc.getPipelineWriter().save(cmd.getJarFile().getId(), file.getName(), new FileInputStream(f)); MongoConnector mdc =new MongoConnector(conf.getConfiguration()); mdc.connect(); Pipeline pipeline = mdc.getPipelineReader().getPipeline(); for (Stage stage : stages) { if (cmd.getStageNames() != null) { mdc.getPipelineWriter().write(pipeline);
public static void main(String[] args) throws Exception { MongoConnector mdc = new MongoConnector(new TestConfiguration()); mdc.connect(); s.setProperties(map); mdc.getPipelineWriter().write(c);
MongoConnector mdc = new MongoConnector(conf); mdc.connect();
Pipeline pipeline = mdc.getPipelineReader().getPipeline(); mdc.getPipelineWriter().write(pipeline); System.out.println("Removed "+stagesToDelete.size()+" stages from the pipeline"); boolean res = mdc.getPipelineWriter().deleteFile(cmd.getOptionValue("i")); if(res) { System.out.println("Removed library file with id "+cmd.getOptionValue("i"));
public static void main(String[] args) throws IOException, JsonException { MongoClient mongo = new MongoClient(new MongoClientURI(conf.getDatabaseUrl())); DB db = mongo.getDB(conf.getNamespace()); WriteConcern concern = mongo.getWriteConcern(); long documentsToKeep = conf.getOldMaxCount(); int oldDocsMaxSizeMB = conf.getOldMaxSize(); StatusUpdater updater = new StatusUpdater(new MongoConnector(conf)); GridFS documentFs = new GridFS(db); MongoDocumentIO io = new MongoDocumentIO(db, concern, documentsToKeep, oldDocsMaxSizeMB, updater, documentFs); io.prepare(); MongoDocument document = new MongoDocument(args[args.length-1]); io.insert(document); System.out.println("Added document"); }
@Override public void connect() throws IOException { MongoClient mongo; try { mongo = new MongoClient(new MongoClientURI(conf.getDatabaseUrl())); } catch (UnknownHostException e) { logger.error("Failed to establish connection to MongoDB at URL: " + conf.getDatabaseUrl(), e); throw new ConnectionException(e); } catch (MongoException e) { logger.error("A MongoException occurred", e); throw new ConnectionException(e); } connect(mongo, true); }
protected void connect(MongoClient mongo, boolean startStatusUpdater) throws IOException { db = mongo.getDB(conf.getNamespace()); if (requiresAuthentication(mongo)) { if (!mongo.getDB("admin").authenticate(conf.getDatabaseUser(), conf.getDatabasePassword().toCharArray())) {
public static void removeStage(MongoConnector mdc, CommandLine cmd) throws IOException { if(!cmd.hasOption("n")) { System.out.println("No stage name specified\n"); printUsage(cmd); return; } String name = cmd.getOptionValue("n"); Pipeline pipeline = mdc.getPipelineReader().getPipeline(); if(pipeline.getStage(name) == null) { System.out.println("Specified stage '"+name+"' did not exist\n"); return; } boolean found = false; for(StageGroup g : pipeline.getStageGroups()) { if(g.hasStage(name)) { g.removeStage(name); found = true; break; } } if(found) { mdc.getPipelineWriter().write(pipeline); System.out.println("Successfully removed stage '"+name+"'"); } else { System.out.println("Unable to delete '"+name+"'. Stage did not exist."); } }
DatabaseConfiguration.DATABASE_NAMESPACE, coreConfiguration.getNamespace()); DatabaseConnector<MongoType> backing = new MongoConnector(coreConfiguration); try { backing.connect();
s.setMode(Stage.Mode.ACTIVE); Pipeline pipeline = mdc.getPipelineReader() .getPipeline(); StageGroup g = new StageGroup(s.getName()); g.addStage(s); pipeline.addGroup(g); mdc.getPipelineWriter().write(pipeline); System.out.println("Added stage " + name + " to the pipeline.");
public static Object addFile(MongoConnector dbc, String jar, String id) throws FileNotFoundException, URISyntaxException { URL path = ClassLoader.getSystemResource(jar); File f; if (path == null) { f = new File(jar); if (!f.exists()) { System.out.println("Unable to locate file " + jar); return null; } } else { f = new File(path.toURI()); } if (id == null) { return dbc.getPipelineWriter().save(f.getName(), new FileInputStream(f)); } dbc.getPipelineWriter().save(id, f.getName(), new FileInputStream(f)); return id; } }
private boolean contains(Document<?> haystack, String needle) { for (String field : haystack.getContentFields()) { if (field.contains(needle)) { return true; } if (contains(haystack.getContentField(field), needle)) { return true; } } return false; }
@Override public DatabaseDocument<MongoType> convert(Document<?> document) throws ConversionException { try { if (contains(document, "\u0000")) { throw new ConversionException( "A document cannot contain the NUL character. See https://jira.mongodb.org/browse/SERVER-7691"); } return new MongoDocument(document.toJson()); } catch (JsonException e) { throw new ConversionException( "JSON Exception caught while converting", e); } }