Search in sources :

Example 11 with MongoConnection

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

the class InspectorSerializer 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(), "All data!A:L").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("status", Utils.getValue(value, 2));
        result.addProperty("prNumber", Utils.getValue(value, 3));
        result.addProperty("buildFinishedDate", Utils.getValue(value, 4));
        result.addProperty("buildFinishedDay", Utils.getValue(value, 5));
        result.addProperty("realStatus", Utils.getValue(value, 6));
        result.addProperty("hostname", Utils.getValue(value, 7));
        result.addProperty("buildReproductionDate", Utils.getValue(value, 8));
        result.addProperty("travisURL", Utils.getValue(value, 9));
        result.addProperty("typeOfFailures", Utils.getValue(value, 10));
        result.addProperty("runId", Utils.getValue(value, 11));
        data.add(new SerializedData(Collections.EMPTY_LIST, result));
    }
    serializerEngine.serialize(data, SerializerType.INSPECTOR);
}
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 12 with MongoConnection

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

the class InspectorSerializer4Bears 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(), "All data!A:Q").execute().getValues();
    MongoConnection mongoConnection = new MongoConnection(args[0], "bears");
    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("previousBuildId", Utils.getValue(value, 1));
        result.addProperty("scannedBuildStatus", Utils.getValue(value, 2));
        result.addProperty("status", Utils.getValue(value, 3));
        result.addProperty("realStatus", Utils.getValue(value, 4));
        result.addProperty("checkoutType", Utils.getValue(value, 5));
        result.addProperty("typeOfFailures", Utils.getValue(value, 6));
        result.addProperty("repositoryName", Utils.getValue(value, 7));
        result.addProperty("prNumber", Utils.getValue(value, 8));
        result.addProperty("buildFinishedDate", Utils.getValue(value, 9));
        result.addProperty("buildFinishedDay", Utils.getValue(value, 10));
        result.addProperty("hostname", Utils.getValue(value, 11));
        result.addProperty("buildReproductionDate", Utils.getValue(value, 12));
        result.addProperty("buildTravisUrl", Utils.getValue(value, 13));
        result.addProperty("previousBuildTravisUrl", Utils.getValue(value, 14));
        result.addProperty("committerEmail", Utils.getValue(value, 15));
        result.addProperty("runId", Utils.getValue(value, 16));
        data.add(new SerializedData(Collections.EMPTY_LIST, result));
    }
    serializerEngine.serialize(data, SerializerType.INSPECTOR4BEARS);
}
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 13 with MongoConnection

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

the class CleanProjectList method main.

public static void main(String[] args) throws IOException {
    String projectPath = args[0];
    String dbUrl = args[1];
    String dbName = args[2];
    String collectionName = args[3];
    String destList = args[4];
    List<String> allProjects = Files.readAllLines(new File(projectPath).toPath());
    MongoConnection mongoConnection = new MongoConnection(dbUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    List<String> selectedProjects = new ArrayList<>();
    for (String project : allProjects) {
        Repository repo = RepositoryHelper.getRepositoryFromSlug(project);
        if (repo != null) {
            Build b = repo.getLastBuild(false);
            if (b != null) {
                if (b.getBuildTool() == BuildTool.MAVEN) {
                    long results = collection.count(and(eq("repositoryName", project), ne("typeOfFailures", null)));
                    if (results > 0) {
                        selectedProjects.add(project);
                    }
                }
            }
        }
    }
    File outputFile = new File(destList);
    BufferedWriter buffer = new BufferedWriter(new FileWriter(outputFile));
    buffer.write(StringUtils.join(selectedProjects, "\n"));
    buffer.close();
    System.out.println("Read projects: " + allProjects.size() + " | Selected projects : " + selectedProjects.size());
    System.out.println(StringUtils.join(selectedProjects, "\n"));
}
Also used : MongoCollection(com.mongodb.client.MongoCollection) Repository(fr.inria.spirals.jtravis.entities.Repository) Build(fr.inria.spirals.jtravis.entities.Build) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) File(java.io.File) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDatabase(com.mongodb.client.MongoDatabase) BufferedWriter(java.io.BufferedWriter)

Example 14 with MongoConnection

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

the class ComputeTestFailingStats method main.

public static void main(String[] args) throws IOException {
    if (args.length < 4) {
        System.err.println("Usage: java ComputeTestFailingStats <url of mongodb with auth> <db name> <collection name> <path of the file to write>");
        System.exit(-1);
    }
    Map<String, Integer> occurencesByFailure = new HashMap<>();
    String dbCollectionUrl = args[0];
    String dbName = args[1];
    String collectionName = args[2];
    String pathOutput = args[3];
    File outputFile = new File(pathOutput);
    MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection<Document> collection = database.getCollection(collectionName);
    Calendar limitDateFebruary2017 = Calendar.getInstance();
    Calendar limitDateJanuary2018 = Calendar.getInstance();
    limitDateFebruary2017.set(2017, Calendar.FEBRUARY, 1);
    limitDateJanuary2018.set(2018, Calendar.JANUARY, 1);
    Block<Document> block = new Block<Document>() {

        @Override
        public void apply(Document document) {
            totalFailingBuild++;
            String typeOfFailures = document.getString("typeOfFailures");
            for (String failure : typeOfFailures.split(",")) {
                if (failure.endsWith(":")) {
                    failure = failure.substring(0, failure.length() - 1);
                }
                if (failure.equals("skip") || failure.equals("skipped")) {
                    continue;
                }
                if (!occurencesByFailure.containsKey(failure)) {
                    occurencesByFailure.put(failure, 0);
                }
                int nbOcc = occurencesByFailure.get(failure);
                nbOcc++;
                occurencesByFailure.put(failure, nbOcc);
                totalNumberOfFailures++;
            }
        }
    };
    collection.find(and(lt("buildFinishedDate", limitDateJanuary2018.getTime()), gt("buildFinishedDate", limitDateFebruary2017.getTime()), in("status", "PATCHED", "test errors", "test failure"))).forEach(block);
    BufferedWriter buffer = new BufferedWriter(new FileWriter(outputFile));
    buffer.write("failure\tNb Occurences\n");
    buffer.flush();
    for (Map.Entry<String, Integer> entry : occurencesByFailure.entrySet().stream().sorted(Map.Entry.comparingByValue(Collections.reverseOrder())).collect(Collectors.toList())) {
        buffer.write(entry.getKey() + "\t" + entry.getValue() + "\n");
        buffer.flush();
    }
    buffer.close();
    System.out.println("Output written to " + pathOutput + " - " + totalFailingBuild + " failing build detected and " + totalNumberOfFailures + " failures counted.");
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) FileWriter(java.io.FileWriter) Document(org.bson.Document) BufferedWriter(java.io.BufferedWriter) Block(com.mongodb.Block) File(java.io.File) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) HashMap(java.util.HashMap) Map(java.util.Map) MongoDatabase(com.mongodb.client.MongoDatabase)

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