Skip to content

Commit

Permalink
Adding Basic Mongo Storage Components
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Wiens committed May 20, 2024
1 parent b7fc64d commit e8f1589
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package us.dot.its.jpo.ode.api.services;

public class MongoStorageService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package us.dot.its.jpo.ode.api.tasks;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;
import org.bson.Document;

@Component
public class MongoStorageTask {


@Autowired
private MongoTemplate mongoTemplate;



public void updateMongoIndex(String collectionName){

}


@Bean
public void testMongoIndexUpdate(){
Set<String> collectionNames = mongoTemplate.getCollectionNames();

long totalDocumentSize = 0;

for(String collectionName: collectionNames){
Document collStatsCommand = new Document("collStats", collectionName);

Document result = mongoTemplate.executeCommand(collStatsCommand);

Document blockStore = getDocumentKey(getDocumentKey(result, "wiredTiger"), "block-manager");
Long freeStorage = null;
Long allocatedStorage = null;


// Try Catch to Handle Datasets where data size varies widely
try{
freeStorage = blockStore.getLong("file bytes available for reuse");
}catch(java.lang.ClassCastException e){
freeStorage = blockStore.getInteger("file bytes available for reuse").longValue();
}

try{
allocatedStorage = blockStore.getLong("file size in bytes");
}catch(java.lang.ClassCastException e){
allocatedStorage = blockStore.getInteger("file size in bytes").longValue();
}

if(freeStorage != null && allocatedStorage != null){
Long trueSize = allocatedStorage - freeStorage;
totalDocumentSize += trueSize;
}






break;
}

}

public Document getDocumentKey(Document doc, String key){
if(doc != null){
Object obj = doc.get(key);
if(obj != null){
return (Document)obj;
}
}
return null;
}
}

0 comments on commit e8f1589

Please sign in to comment.