Package com.mongodb

Examples of com.mongodb.CommandResult


        return getMemberNameByState(mongo, "secondary");
    }

    @SuppressWarnings({ "unchecked" })
    protected String getMemberNameByState(Mongo mongo, String stateStrToMatch) {
        CommandResult replicaSetStatus = runReplicaSetStatusCommand(mongo);

        for (final BasicDBObject member : (List<BasicDBObject>) replicaSetStatus
                .get("members")) {
            String hostnameAndPort = member.getString("name");
            if (!hostnameAndPort.contains(":"))
                hostnameAndPort = hostnameAndPort + ":27017";
View Full Code Here


    @SuppressWarnings("unchecked")
    protected int getReplicaSetSize(Mongo mongo) {
        int size = 0;

        CommandResult replicaSetStatus = runReplicaSetStatusCommand(mongo);

        for (final BasicDBObject member : (List<BasicDBObject>) replicaSetStatus
                .get("members")) {

            final String stateStr = member.getString("stateStr");

            if (stateStr.equals("PRIMARY") || stateStr.equals("SECONDARY"))
View Full Code Here

        return size;
    }

    protected CommandResult runReplicaSetStatusCommand(final Mongo pMongo) {
        // Check to see if this is a replica set... if not, get out of here.
        final CommandResult result = pMongo.getDB("admin").command(
                new BasicDBObject("replSetGetStatus", 1));

        final String errorMsg = result.getErrorMessage();

        if (errorMsg != null && errorMsg.indexOf("--replSet") != -1) {
            System.err
                    .println("---- SecondaryReadTest: This is not a replica set - not testing secondary reads");
            return null;
View Full Code Here

        lockDoc.put(LockDef.LOCK_ATTEMPT_COUNT.field, 0);
        lockDoc.put(LockDef.INACTIVE_LOCK_TIMEOUT.field, pLockOptions.getInactiveLockTimeout());

        // Insert, if successful then get out of here.
        final WriteResult result = getDbCollection(pMongo, pSvcOptions).insert(lockDoc, WriteConcern.NORMAL);
        final CommandResult cmdResult = result.getLastError(WriteConcern.NORMAL);

        if (!cmdResult.ok() || cmdResult.getException() != null || cmdResult.getErrorMessage() != null) return null;

        if (pSvcOptions.getEnableHistory())
        { LockHistoryDao.insert( pMongo, pLockName, pSvcOptions, pLockOptions, serverTime, LockState.LOCKED, lockId, false); }

        return lockId;
View Full Code Here

    } catch (UnknownHostException e) {
      throw new IllegalStateException( " Unable to connect to MongoDB at '" + uri + "'", e);
    }
        DB db = mongo.getDB(uri.getDatabase());
        DBCollection coll = db.getCollection(uri.getCollection());
        final CommandResult stats = coll.getStats();
       
        final boolean isSharded = stats.getBoolean( "sharded", false );
        log.info("Collection Sharded? " + isSharded);
       
        final DBObject splitKey = getInputSplitKey(splitKeyPattern);
        final String ns = coll.getFullName();
        final DBObject q = getDBObject(inputQuery);
        log.info( "Calculating unsharded input splits on namespace '" + ns
            + "' with Split Key '" + splitKey.toString()
            + "' and a split size of '" + splitSize + "'mb per" );
       
        /*
         * examples:
         * { splitVector : "blog.post" , keyPattern:{x:1} , min:{x:10} , max:{x:20}, maxChunkSize:200 }
         * maxChunkSize unit in MBs
         * May optionally specify 'maxSplitPoints' and 'maxChunkObjects' to avoid traversing the whole chunk
         *
         * { splitVector : "blog.post" , keyPattern:{x:1} , min:{x:10} , max:{x:20}, force: true }
         * 'force' will produce one split point even if data is small; defaults to false
         * NOTE: This command may take a while to run
         */
        final DBObject cmd = BasicDBObjectBuilder.start("splitVector", ns).
            add( "keyPattern", splitKey ).
            add( "force", false ).
            add( "maxChunkSize", splitSize ).get();

        log.trace( "Issuing Command: " + cmd );
        CommandResult data = coll.getDB().command(cmd);

        if (data.containsField("$err")){
          throw new IllegalArgumentException("Error calculating splits: " + data);
        }else if ((Double) data.get("ok") != 1.0){
          throw new IllegalArgumentException("Unable to calculate input splits: " + ((String) data.get( "errmsg" )));
        }
        BasicDBList splitData = (BasicDBList)data.get("splitKeys");
        if (splitData.size() <= 1) {
          // no splits really. Just do the whole thing data is likely small
            splits.add(createParamSplit(this.param, q, null, null));
        }else {
            log.info( "Calculated " + splitData.size() + " splits." );
View Full Code Here

    protected static boolean isReplicaSet(Mongo mongo) {
        return runIsMaster(mongo).get("setName") != null;
    }

    protected static boolean isSharded(Mongo mongo) {
        CommandResult isMasterResult = runIsMaster(mongo);
        Object msg = isMasterResult.get("msg");
        return msg != null && msg.equals("isdbgrid");
    }
View Full Code Here

    }


    @SuppressWarnings({"unchecked"})
    protected String getMemberNameByState(Mongo mongo, String stateStrToMatch) {
        CommandResult replicaSetStatus = runReplicaSetStatusCommand(mongo);

        for (final BasicDBObject member : (List<BasicDBObject>) replicaSetStatus.get("members")) {
            String hostnameAndPort = member.getString("name");
            if (!hostnameAndPort.contains(":"))
                hostnameAndPort = hostnameAndPort + ":27017";

            final String stateStr = member.getString("stateStr");
View Full Code Here

    @SuppressWarnings("unchecked")
    protected int getReplicaSetSize(Mongo mongo) {
        int size = 0;

        CommandResult replicaSetStatus = runReplicaSetStatusCommand(mongo);

        for (final BasicDBObject member : (List<BasicDBObject>) replicaSetStatus.get("members")) {

            final String stateStr = member.getString("stateStr");

            if (stateStr.equals("PRIMARY") || stateStr.equals("SECONDARY"))
                size++;
View Full Code Here

    }

   
    protected static CommandResult runReplicaSetStatusCommand(final Mongo pMongo) {
        // Check to see if this is a replica set... if not, get out of here.
        final CommandResult result = pMongo.getDB("admin").command(new BasicDBObject("replSetGetStatus", 1));

        final String errorMsg = result.getErrorMessage();

        if (errorMsg != null && errorMsg.indexOf("--replSet") != -1) {
            System.err.println("---- SecondaryReadTest: This is not a replica set - not testing secondary reads");
            return null;
        }
View Full Code Here

  private static BuildInfo initBuildInfo(Mongo mongo) {
    DB db = mongo.getDB("admin");
    if (db == null) {
      return null;
    }
    CommandResult cr = db.command("buildInfo");
    String version = (String)cr.get("version");
    if (version == null) {
      return null;
    }
    String[] vss = version.split("\\.");
    if (vss.length <= 2) {
      return null;
    }
    Integer maxBsonObjectSize = (Integer)cr.get("maxBsonObjectSize");
    if (maxBsonObjectSize == null) {
      maxBsonObjectSize = Integer.valueOf(0);
    }
    try {
      return new BuildInfo(Integer.parseInt(vss[0]), Integer.parseInt(vss[1]),
View Full Code Here

TOP

Related Classes of com.mongodb.CommandResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.