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);
}
}
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);
}
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();
}
Aggregations