class GrapesServer extends Service<GrapesServerConfig> {

	@Override
	public void run(final GrapesServerConfig config, final Environment env) throws DBException, UnknownHostException {
        PromoConfigValidator v = new PromoConfigValidator();
        v.testValidity(config.getPromoValidationCfg());
        PromoConfigPrinter.display(config.getPromoValidationCfg(),
                str -> {
                    if (LOG.isInfoEnabled()) {
                        LOG.info(str);
                    }
                });

        // init the repoHandler
        final RepositoryHandler repoHandler = getRepositoryHandler(config);
        
        Messages.init(config.getMsgBundle());
        env.scanPackagesForResourcesAndProviders(CsvReportWriter.class);

        // Add credential management
        final GrapesAuthenticator grapesAuthenticator = new GrapesAuthenticator(repoHandler);
        final BasicAuthProvider authProvider = new BasicAuthProvider<>(grapesAuthenticator, "Grapes Authenticator Provider");
        env.addProvider(authProvider);
        
        
        // Tasks
        env.addTask(new AddUserTask(repoHandler));
        env.addTask(new AddRoleTask(repoHandler));
        env.addTask(new RemoveRoleTask(repoHandler));
        env.addTask(new MaintenanceModeTask(config));
        env.addTask(new KillTask());
        env.addTask(new MigrationTask(config.getDataBaseConfig()));
        env.addTask(new RefreshCommercialDeliveriesTask(repoHandler));
        env.addTask(new SendEmailTestTask(config.getGrapesEmailConfig()));
        env.addTask(new ShowValidationsTask());
        env.addTask(new ChangeValidationsTask());

        
        // Health checks
        env.addHealthCheck(new DataBaseCheck(config.getDataBaseConfig()));
        env.addHealthCheck(new DataModelVersionCheck(config.getDataBaseConfig()));

        // Resources
        env.addResource(new OrganizationResource(repoHandler, config));
        env.addResource(new ProductResource(repoHandler, config));
        env.addResource(new ModuleResource(repoHandler, config));
        env.addResource(new ArtifactResource(repoHandler, config));
        env.addResource(new LicenseResource(repoHandler, config));
        env.addResource(new Sequoia(repoHandler, config));
        env.addResource(new WebAppResource(repoHandler, config));
        env.addResource(new RootResource(repoHandler, config));
        env.addResource(new ReportResource(repoHandler, config));
        env.addResource(new SearchResource(repoHandler, config));
        env.addResource(new WebSearchResource(repoHandler, config));
	}

	protected  GrapesServer();

}