use of org.bson.BasicBSONObject in project jackrabbit-oak by apache.
the class ReplicaSetInfo method updateRevisions.
private void updateRevisions(Iterable<BasicBSONObject> members) {
Set<String> secondaries = new HashSet<String>();
boolean unknownState = false;
String primary = null;
for (BasicBSONObject member : members) {
MemberState state;
try {
state = MemberState.valueOf(member.getString("stateStr"));
} catch (IllegalArgumentException e) {
state = MemberState.UNKNOWN;
}
String name = member.getString("name");
if (hiddenMembers.contains(name)) {
continue;
}
switch(state) {
case PRIMARY:
primary = name;
continue;
case SECONDARY:
secondaries.add(name);
break;
case ARBITER:
continue;
default:
LOG.debug("Invalid state {} for instance {}", state, name);
unknownState = true;
break;
}
}
Set<String> hostsToCheck = new HashSet<String>();
if (secondaries.isEmpty()) {
LOG.debug("No secondaries found: {}", members);
unknownState = true;
} else {
hostsToCheck.addAll(secondaries);
}
if (primary == null) {
LOG.debug("No primary found: {}", members);
unknownState = true;
} else {
hostsToCheck.add(primary);
}
Map<String, Timestamped<RevisionVector>> vectors = null;
if (!unknownState) {
vectors = getRootRevisions(hostsToCheck);
if (vectors.containsValue(null)) {
unknownState = true;
}
}
if (unknownState) {
rootRevisions = null;
secondariesSafeTimestamp = 0;
} else {
Timestamped<RevisionVector> primaryRevision = vectors.get(primary);
Iterable<Timestamped<RevisionVector>> secondaryRevisions = filterKeys(vectors, in(secondaries)).values();
rootRevisions = pmin(transform(secondaryRevisions, Timestamped.<RevisionVector>getExtractFunction()));
if (rootRevisions == null || primaryRevision == null || isEmpty(secondaryRevisions)) {
secondariesSafeTimestamp = 0;
} else {
secondariesSafeTimestamp = getSecondariesSafeTimestamp(primaryRevision, secondaryRevisions);
}
}
LOG.debug("Minimum root revisions: {}. Current lag: {}", rootRevisions, getLag());
nodeCollections.retain(hostsToCheck);
}
use of org.bson.BasicBSONObject in project jackrabbit-oak by apache.
the class ReplicaSetInfo method getHiddenMembers.
List<String> getHiddenMembers() {
BasicDBObject result;
try {
result = getReplicaConfig();
} catch (MongoException e) {
LOG.error("Can't get replica configuration", e);
return null;
}
@SuppressWarnings("unchecked") Iterable<BasicBSONObject> members = (Iterable<BasicBSONObject>) result.get("members");
if (members == null) {
members = Collections.emptyList();
}
List<String> hiddenMembers = new ArrayList<String>();
for (BasicBSONObject member : members) {
if (member.getBoolean("hidden")) {
hiddenMembers.add(member.getString("host"));
}
}
return hiddenMembers;
}
use of org.bson.BasicBSONObject in project v7files by thiloplanz.
the class BucketsServletTest method testFormPostGET.
public void testFormPostGET() throws IOException, SAXException {
BasicBSONObject bucket = prepareBucket("1", "FormPost", null, null);
MongoContentStorage storage = new MongoContentStorage(getMongo().getDB("test"));
ContentSHA sha = storage.storeContent(new ByteArrayInputStream("test".getBytes()));
ServletUnitClient sc = sr.newClient();
{
WebRequest request = new GetMethodWebRequest("http://test/myServlet/1");
request.setParameter("sha", sha.getDigest());
try {
sc.getResponse(request);
fail("bucket not found => 404");
} catch (HttpNotFoundException e) {
assertEquals(String.format("Bucket '1' does not have a file matching digest '%s'", sha.getDigest()), e.getResponseMessage());
}
}
bucket.append("FormPost", new BasicBSONObject("data", new BasicBSONObject("files", new BasicBSONObject("file", new BasicBSONObject("filename", "a.txt").append("sha", sha.getSHA())))));
{
WebRequest request = new GetMethodWebRequest("http://test/myServlet/1");
request.setParameter("sha", sha.getDigest());
WebResponse response = sc.getResponse(request);
assertEquals("test", response.getText());
assertEquals(sha.getDigest(), response.getHeaderField("ETag"));
assertEquals(4, response.getContentLength());
assertEquals("attachment; filename=\"a.txt\"", response.getHeaderField("Content-Disposition"));
}
{
WebRequest request = new GetMethodWebRequest("http://test/myServlet/1");
request.setParameter("sha", sha.getDigest());
request.setParameter("filename", "x.txt");
WebResponse response = sc.getResponse(request);
assertEquals("test", response.getText());
assertEquals(sha.getDigest(), response.getHeaderField("ETag"));
assertEquals(4, response.getContentLength());
assertEquals("attachment; filename=\"x.txt\"", response.getHeaderField("Content-Disposition"));
}
{
WebRequest request = new GetMethodWebRequest("http://test/myServlet/1");
request.setParameter("sha", sha.getDigest());
request.setHeaderField("If-None-Match", sha.getDigest());
WebResponse response = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getResponseCode());
}
}
use of org.bson.BasicBSONObject in project v7files by thiloplanz.
the class MiltonServletTest method testCOPYFile.
public void testCOPYFile() throws IOException, SAXException {
ServletUnitClient sc = sr.newClient();
sc.setAuthentication("V7Files", "admin", "admin");
prepareMockData("test.v7files.files", new BasicBSONObject("_id", new ObjectId()).append("filename", "a.txt").append("parent", "webdav").append("in", "abcd".getBytes()));
{
WebRequest request = new CopyWebRequest("http://test/myServlet/a.txt", "/myServlet/b.txt");
WebResponse resp = sc.getResponse(request);
assertEquals(HttpServletResponse.SC_CREATED, resp.getResponseCode());
}
assertGET(sc, "http://test/myServlet/a.txt", "abcd");
assertGET(sc, "http://test/myServlet/b.txt", "abcd");
}
use of org.bson.BasicBSONObject in project v7files by thiloplanz.
the class MongoContentStorageTest method testFindByPrefix.
public void testFindByPrefix() throws IOException {
byte[] data = "abcdefghijklmnopqrstuvwxyz".getBytes();
byte[] sha = DigestUtils.sha(data);
prepareMockData("test.v7files.content", new BasicBSONObject("_id", sha).append("in", data));
Mongo mongo = getMongo();
MongoContentStorage storage = new MongoContentStorage(mongo.getDB("test"));
assertEquals(new String(data), IOUtils.toString(storage.findContentByPrefix(sha).getInputStream()));
assertEquals(new String(data), IOUtils.toString(storage.findContentByPrefix(ArrayUtils.subarray(sha, 0, 5)).getInputStream()));
assertNull(storage.findContentByPrefix(new byte[] { 0, 0, 0, 0 }));
mongo.close();
}
Aggregations