Search in sources :

Example 6 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class CleanNopolCollection method main.

public static void main(String[] args) {
    Map<Integer, Set<String>> presentInDb = new HashMap<>();
    String dbCollectionUrl = args[0];
    String dbName = args[1];
    String collectionName = args[2];
    MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Block<Document> block = new Block<Document>() {

        @Override
        public void apply(Document document) {
            int buildId = document.getInteger("buildId");
            String location = document.getString("testClassLocation");
            ObjectId id = document.getObjectId("_id");
            if (presentInDb.containsKey(buildId)) {
                Set<String> localSet = presentInDb.get(buildId);
                if (localSet.contains(location)) {
                    collection.deleteOne(eq("_id", id));
                    counterDeleted++;
                    return;
                } else {
                    localSet.add(location);
                }
            } else {
                Set<String> localSet = new HashSet<>();
                localSet.add(location);
                presentInDb.put(buildId, localSet);
            }
            counterKept++;
        }
    };
    collection.find().forEach(block);
    System.out.println(counterDeleted + " entries deleted and " + counterKept + " kept.");
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ObjectId(org.bson.types.ObjectId) Document(org.bson.Document) MongoCollection(com.mongodb.client.MongoCollection) Block(com.mongodb.Block) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDatabase(com.mongodb.client.MongoDatabase) HashSet(java.util.HashSet)

Example 7 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class RemoveDuplicatedBuildsId method main.

public static void main(String[] args) {
    Set<Integer> buildIds = new HashSet<>();
    String dbCollectionUrl = args[0];
    String dbName = args[1];
    String collectionName = args[2];
    MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Block<Document> block = new Block<Document>() {

        @Override
        public void apply(Document document) {
            int buildId = document.getInteger("buildId");
            ObjectId id = document.getObjectId("_id");
            if (buildIds.contains(buildId)) {
                collection.deleteOne(eq("_id", id));
                counterDeleted++;
                return;
            } else {
                buildIds.add(buildId);
                counterKept++;
            }
        }
    };
    collection.find().sort(orderBy(descending("buildReproductionDate"))).forEach(block);
    System.out.println(counterDeleted + " entries deleted and " + counterKept + " kept.");
}
Also used : MongoCollection(com.mongodb.client.MongoCollection) ObjectId(org.bson.types.ObjectId) Block(com.mongodb.Block) Document(org.bson.Document) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) HashSet(java.util.HashSet) MongoDatabase(com.mongodb.client.MongoDatabase)

Example 8 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class InspectorTimeSerializer method main.

public static void main(String[] args) throws IOException, GeneralSecurityException {
    GoogleSpreadSheetFactory.initWithFileSecret("client_secret.json");
    GoogleSpreadSheetFactory.setSpreadsheetId(args[1]);
    Sheets sheets = GoogleSpreadSheetFactory.getSheets();
    List<List<Object>> results = sheets.spreadsheets().values().get(GoogleSpreadSheetFactory.getSpreadsheetID(), "Duration Data!A:P").execute().getValues();
    MongoConnection mongoConnection = new MongoConnection(args[0], "repairnator");
    if (!mongoConnection.isConnected()) {
        throw new RuntimeException("Error when connection to mongodb");
    }
    MongoDBSerializerEngine serializerEngine = new MongoDBSerializerEngine(mongoConnection);
    List<SerializedData> data = new ArrayList<>();
    for (int i = 1; i < results.size(); i++) {
        List<Object> value = results.get(i);
        JsonObject result = new JsonObject();
        result.addProperty("buildId", Utils.getValue(value, 0));
        result.addProperty("repositoryName", Utils.getValue(value, 1));
        result.addProperty("buildReproductionDate", Utils.getValue(value, 2));
        result.addProperty("hostname", Utils.getValue(value, 3));
        result.addProperty("totalDuration", Utils.getValue(value, 4));
        result.addProperty("clonage", Utils.getValue(value, 5));
        result.addProperty("checkoutBuild", Utils.getValue(value, 6));
        result.addProperty("build", Utils.getValue(value, 7));
        result.addProperty("test", Utils.getValue(value, 8));
        result.addProperty("gatherTestInfo", Utils.getValue(value, 9));
        result.addProperty("squashRepository", Utils.getValue(value, 10));
        result.addProperty("push", Utils.getValue(value, 11));
        result.addProperty("computeClasspath", Utils.getValue(value, 12));
        result.addProperty("computeSourceDir", Utils.getValue(value, 13));
        result.addProperty("repair", Utils.getValue(value, 14));
        result.addProperty("runId", Utils.getValue(value, 15));
        data.add(new SerializedData(Collections.EMPTY_LIST, result));
    }
    serializerEngine.serialize(data, SerializerType.TIMES);
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) Sheets(com.google.api.services.sheets.v4.Sheets)

Example 9 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class LauncherUtils method initMongoDBSerializerEngine.

public static SerializerEngine initMongoDBSerializerEngine(Logger logger) {
    RepairnatorConfig config = RepairnatorConfig.getInstance();
    if (config.getMongodbHost() != null) {
        logger.info("Initialize mongoDB serializer engine.");
        MongoConnection mongoConnection = new MongoConnection(config.getMongodbHost(), config.getMongodbName());
        if (mongoConnection.isConnected()) {
            return new MongoDBSerializerEngine(mongoConnection);
        } else {
            logger.error("Error while connecting to mongoDB.");
        }
    } else {
        logger.info("MongoDB won't be used for serialization.");
    }
    return null;
}
Also used : RepairnatorConfig(fr.inria.spirals.repairnator.config.RepairnatorConfig) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine)

Example 10 with MongoConnection

use of fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection in project repairnator by Spirals-Team.

the class NopolSerializer method main.

public static void main(String[] args) throws IOException, GeneralSecurityException {
    GoogleSpreadSheetFactory.initWithFileSecret("client_secret.json");
    GoogleSpreadSheetFactory.setSpreadsheetId(args[1]);
    Sheets sheets = GoogleSpreadSheetFactory.getSheets();
    List<List<Object>> results = sheets.spreadsheets().values().get(GoogleSpreadSheetFactory.getSpreadsheetID(), "Nopol Stats!A:T").execute().getValues();
    MongoConnection mongoConnection = new MongoConnection(args[0], "repairnator");
    if (!mongoConnection.isConnected()) {
        throw new RuntimeException("Error when connection to mongodb");
    }
    MongoDBSerializerEngine serializerEngine = new MongoDBSerializerEngine(mongoConnection);
    List<SerializedData> data = new ArrayList<>();
    for (int i = 1; i < results.size(); i++) {
        List<Object> value = results.get(i);
        JsonObject result = new JsonObject();
        result.addProperty("buildId", Utils.getValue(value, 3));
        result.addProperty("repositoryName", Utils.getValue(value, 4));
        result.addProperty("hostname", Utils.getValue(value, 0));
        result.addProperty("nopolDateEnd", Utils.getValue(value, 1));
        result.addProperty("nopolDayEnd", Utils.getValue(value, 2));
        result.addProperty("testClassLocation", Utils.getValue(value, 5));
        result.addProperty("failures", Utils.getValue(value, 6));
        result.addProperty("allocatedTime", Utils.getValue(value, 7));
        result.addProperty("passingTime", Utils.getValue(value, 8));
        result.addProperty("status", Utils.getValue(value, 9));
        result.addProperty("exceptionDetail", Utils.getValue(value, 10));
        result.addProperty("patchNumber", Utils.getValue(value, 11));
        result.addProperty("patchType", Utils.getValue(value, 12));
        result.addProperty("patch", Utils.getValue(value, 13));
        result.addProperty("patchLocation", Utils.getValue(value, 14));
        result.addProperty("nopolContext", Utils.getValue(value, 15));
        result.addProperty("nbAngelicValues", Utils.getValue(value, 16));
        result.addProperty("nbStatements", Utils.getValue(value, 17));
        result.addProperty("ignoreStatus", Utils.getValue(value, 18));
        result.addProperty("runId", Utils.getValue(value, 19));
        data.add(new SerializedData(Collections.EMPTY_LIST, result));
    }
    serializerEngine.serialize(data, SerializerType.NOPOL);
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) SerializedData(fr.inria.spirals.repairnator.serializer.engines.SerializedData) MongoDBSerializerEngine(fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine) ArrayList(java.util.ArrayList) List(java.util.List) JsonObject(com.google.gson.JsonObject) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) Sheets(com.google.api.services.sheets.v4.Sheets)

Aggregations

MongoConnection (fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection)14 ArrayList (java.util.ArrayList)10 List (java.util.List)8 MongoDatabase (com.mongodb.client.MongoDatabase)7 MongoDBSerializerEngine (fr.inria.spirals.repairnator.serializer.engines.json.MongoDBSerializerEngine)7 Sheets (com.google.api.services.sheets.v4.Sheets)6 JsonObject (com.google.gson.JsonObject)6 MongoCollection (com.mongodb.client.MongoCollection)6 SerializedData (fr.inria.spirals.repairnator.serializer.engines.SerializedData)6 Block (com.mongodb.Block)5 Document (org.bson.Document)5 File (java.io.File)4 Calendar (java.util.Calendar)4 HashMap (java.util.HashMap)4 Build (fr.inria.spirals.jtravis.entities.Build)3 HashSet (java.util.HashSet)3 ObjectId (org.bson.types.ObjectId)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 UpdateOptions (com.mongodb.client.model.UpdateOptions)1