Search in sources :

Example 1 with ConsistencyChecker

use of org.eclipse.winery.repository.backend.consistencycheck.ConsistencyChecker in project winery by eclipse.

the class WineryCli method doConsistencyCheck.

private static void doConsistencyCheck(CommandLine line, IRepository repository) {
    EnumSet<ConsistencyCheckerVerbosity> verbosity;
    if (line.hasOption("v")) {
        verbosity = EnumSet.of(ConsistencyCheckerVerbosity.OUTPUT_NUMBER_OF_TOSCA_COMPONENTS, ConsistencyCheckerVerbosity.OUTPUT_CURRENT_TOSCA_COMPONENT_ID, ConsistencyCheckerVerbosity.OUTPUT_ERRORS);
    } else {
        verbosity = EnumSet.of(ConsistencyCheckerVerbosity.OUTPUT_NUMBER_OF_TOSCA_COMPONENTS);
    }
    boolean serviceTemplatesOnly = line.hasOption("so");
    boolean checkDocumentation = line.hasOption("cd");
    ConsistencyCheckerConfiguration configuration = new ConsistencyCheckerConfiguration(serviceTemplatesOnly, checkDocumentation, verbosity, repository);
    final ConsistencyChecker consistencyChecker = new ConsistencyChecker(configuration);
    int numberOfDefinitionsToCheck = consistencyChecker.numberOfDefinitionsToCheck();
    ProgressBar progressBar = new ProgressBar("Check", numberOfDefinitionsToCheck, ProgressBarStyle.ASCII);
    consistencyChecker.setConsistencyCheckerProgressListener(new ConsistencyCheckerProgressListener() {

        @Override
        public void updateProgress(float progress) {
            progressBar.stepTo((long) (progress * numberOfDefinitionsToCheck));
        }

        @Override
        public void updateProgress(float progress, String checkingDefinition) {
            progressBar.setExtraMessage("Now checking " + checkingDefinition);
            progressBar.stepTo((long) (progress * numberOfDefinitionsToCheck));
        }
    });
    progressBar.start();
    consistencyChecker.checkCorruption();
    progressBar.stop();
    ConsistencyErrorCollector errors = consistencyChecker.getErrorCollector();
    System.out.println();
    if (errors.getErrorList().isEmpty()) {
        System.out.println("No errors exist.");
    } else {
        System.out.println("Errors found in the repository:");
        System.out.println();
        for (Map.Entry<QName, ElementErrorList> qName : errors.getErrorList().entrySet()) {
            System.out.println(qName.getKey());
            ElementErrorList elementErrorList = qName.getValue();
            if (!elementErrorList.getErrors().isEmpty()) {
                System.out.println("\tErrors:");
                for (String error : elementErrorList.getErrors()) {
                    System.out.println("\t\t" + error);
                }
            }
            if (!elementErrorList.getWarnings().isEmpty()) {
                System.out.println("\n\tWarnings:");
                for (String error : elementErrorList.getWarnings()) {
                    System.out.println("\t\t" + error);
                }
            }
            System.out.println();
        }
        System.exit(1);
    }
}
Also used : ConsistencyCheckerProgressListener(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerProgressListener) QName(javax.xml.namespace.QName) ElementErrorList(org.eclipse.winery.repository.backend.consistencycheck.ElementErrorList) ConsistencyErrorCollector(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyErrorCollector) ConsistencyCheckerConfiguration(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerConfiguration) ConsistencyChecker(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyChecker) ConsistencyCheckerVerbosity(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerVerbosity) ProgressBar(me.tongfei.progressbar.ProgressBar) Map(java.util.Map)

Example 2 with ConsistencyChecker

use of org.eclipse.winery.repository.backend.consistencycheck.ConsistencyChecker in project winery by eclipse.

the class ConsistencyCheckWebSocket method onMessage.

@Override
@OnMessage
public void onMessage(String message, Session session) throws IOException {
    ConsistencyCheckerConfiguration config = JacksonProvider.mapper.readValue(message, ConsistencyCheckerConfiguration.class);
    logger.info("Start checking using config: {}", message);
    long startTime = System.currentTimeMillis();
    final ConsistencyChecker consistencyChecker = new ConsistencyChecker(config, this);
    consistencyChecker.checkCorruption();
    ConsistencyErrorCollector errorList = consistencyChecker.getErrorCollector();
    long duration = (System.currentTimeMillis() - startTime) / 1000;
    logger.info("Finished checking repository consistency! Duration: {}min, {}s", (int) duration / 60, duration % 60);
    // Transform object to JSON and send it.
    this.session.getBasicRemote().sendText(JacksonProvider.mapper.writeValueAsString(errorList));
    // Close the connection after the check has passed.
    onClose(session);
}
Also used : ConsistencyCheckerConfiguration(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerConfiguration) ConsistencyChecker(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyChecker) ConsistencyErrorCollector(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyErrorCollector) OnMessage(javax.websocket.OnMessage)

Example 3 with ConsistencyChecker

use of org.eclipse.winery.repository.backend.consistencycheck.ConsistencyChecker in project winery by eclipse.

the class AdminTopResource method checkConsistency.

@GET
@Path("consistencycheck")
@Produces(MediaType.APPLICATION_JSON)
public ConsistencyErrorCollector checkConsistency(@QueryParam("serviceTemplatesOnly") boolean serviceTemplatesOnly, @QueryParam("checkDocumentation") boolean checkDocumentation) {
    IRepository repo = RepositoryFactory.getRepository();
    EnumSet<ConsistencyCheckerVerbosity> verbosity = EnumSet.of(ConsistencyCheckerVerbosity.NONE);
    ConsistencyCheckerConfiguration config = new ConsistencyCheckerConfiguration(serviceTemplatesOnly, checkDocumentation, verbosity, repo);
    final ConsistencyChecker consistencyChecker = new ConsistencyChecker(config);
    consistencyChecker.checkCorruption();
    return consistencyChecker.getErrorCollector();
}
Also used : ConsistencyCheckerConfiguration(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerConfiguration) ConsistencyChecker(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyChecker) ConsistencyCheckerVerbosity(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerVerbosity) IRepository(org.eclipse.winery.repository.backend.IRepository) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

ConsistencyChecker (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyChecker)3 ConsistencyCheckerConfiguration (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerConfiguration)3 ConsistencyCheckerVerbosity (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerVerbosity)2 ConsistencyErrorCollector (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyErrorCollector)2 Map (java.util.Map)1 OnMessage (javax.websocket.OnMessage)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 QName (javax.xml.namespace.QName)1 ProgressBar (me.tongfei.progressbar.ProgressBar)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1 ConsistencyCheckerProgressListener (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerProgressListener)1 ElementErrorList (org.eclipse.winery.repository.backend.consistencycheck.ElementErrorList)1