Search in sources :

Example 1 with MidpointConfiguration

use of com.evolveum.midpoint.common.configuration.api.MidpointConfiguration in project midpoint by Evolveum.

the class PageAccounts method createWriter.

private Writer createWriter(String fileName) throws IOException {
    //todo improve!!!!!!!
    MidpointConfiguration config = getMidpointConfiguration();
    File exportFolder = new File(config.getMidpointHome() + "/export/");
    File file = new File(exportFolder, fileName);
    try {
        if (!exportFolder.exists() || !exportFolder.isDirectory()) {
            exportFolder.mkdir();
        }
        file.createNewFile();
    } catch (Exception ex) {
        error(getString("PageAccounts.exportFileDoesntExist", file.getAbsolutePath()));
        throw ex;
    }
    return new OutputStreamWriter(new FileOutputStream(file), "utf-8");
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) AjaxDownloadBehaviorFromFile(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile) File(org.apache.wicket.util.file.File) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 2 with MidpointConfiguration

use of com.evolveum.midpoint.common.configuration.api.MidpointConfiguration in project midpoint by Evolveum.

the class PageAccounts method clearExportPerformed.

private void clearExportPerformed(AjaxRequestTarget target) {
    try {
        MidpointConfiguration config = getMidpointConfiguration();
        File exportFolder = new File(config.getMidpointHome() + "/export");
        java.io.File[] files = exportFolder.listFiles();
        if (files == null) {
            return;
        }
        for (java.io.File file : files) {
            file.delete();
        }
    } catch (Exception ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete export files", ex);
        error("Couldn't delete export files, reason: " + ex.getMessage());
    }
    filesModel.reset();
    success(getString("PageAccounts.message.success.clearExport"));
    target.add(getFeedbackPanel(), get(createComponentPath(ID_FORM_ACCOUNT, ID_FILES_CONTAINER)));
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) AjaxDownloadBehaviorFromFile(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile) File(org.apache.wicket.util.file.File) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 3 with MidpointConfiguration

use of com.evolveum.midpoint.common.configuration.api.MidpointConfiguration in project midpoint by Evolveum.

the class Initializer method init.

public void init(OperationResult result) throws TaskManagerInitializationException {
    MidpointConfiguration midpointConfiguration = taskManager.getMidpointConfiguration();
    LOGGER.info("Task Manager initialization.");
    // get the configuration (general section + JDBC section as well)
    TaskManagerConfiguration configuration = taskManager.getConfiguration();
    configuration.checkAllowedKeys(midpointConfiguration);
    configuration.setBasicInformation(midpointConfiguration);
    configuration.validateBasicInformation();
    LOGGER.info("Task Manager: Quartz Job Store: " + (configuration.isJdbcJobStore() ? "JDBC" : "in-memory") + ", " + (configuration.isClustered() ? "" : "NOT ") + "clustered. Threads: " + configuration.getThreads());
    if (configuration.isJdbcJobStore()) {
        // quartz properties related to database connection will be taken from SQL repository
        String defaultJdbcUrlPrefix = null;
        SqlRepositoryConfiguration sqlConfig = null;
        try {
            SqlRepositoryFactory sqlRepositoryFactory = (SqlRepositoryFactory) taskManager.getBeanFactory().getBean("sqlRepositoryFactory");
            sqlConfig = sqlRepositoryFactory.getSqlConfiguration();
            if (sqlConfig.isEmbedded()) {
                defaultJdbcUrlPrefix = sqlRepositoryFactory.prepareJdbcUrlPrefix(sqlConfig);
            }
        } catch (NoSuchBeanDefinitionException e) {
            LOGGER.info("SqlRepositoryFactory is not available, JDBC Job Store configuration will be taken from taskManager section only.");
            LOGGER.trace("Reason is", e);
        } catch (RepositoryServiceFactoryException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Cannot determine default JDBC URL for embedded database", e);
        }
        configuration.setJdbcJobStoreInformation(midpointConfiguration, sqlConfig, defaultJdbcUrlPrefix);
        configuration.validateJdbcJobStoreInformation();
    }
    // register node
    // may throw initialization exception
    taskManager.getClusterManager().createNodeObject(result);
    if (!taskManager.getConfiguration().isTestMode()) {
        // in test mode do not start cluster manager thread nor verify cluster config
        // does not throw exceptions, sets the ERROR state if necessary, however
        taskManager.getClusterManager().checkClusterConfiguration(result);
    }
    NoOpTaskHandler.instantiateAndRegister(taskManager);
    WaitForSubtasksByPollingTaskHandler.instantiateAndRegister(taskManager);
    WaitForTasksTaskHandler.instantiateAndRegister(taskManager);
    // unfortunately, there seems to be no clean way of letting jobs know the taskManager
    JobExecutor.setTaskManagerQuartzImpl(taskManager);
    // the same here
    JobStarter.setTaskManagerQuartzImpl(taskManager);
    taskManager.getExecutionManager().initializeLocalScheduler();
    if (taskManager.getLocalNodeErrorStatus() != NodeErrorStatusType.OK) {
        taskManager.getExecutionManager().shutdownLocalSchedulerChecked();
    }
    // populate the scheduler with jobs (if RAM-based), or synchronize with midPoint repo
    if (taskManager.getExecutionManager().synchronizeJobStores(result) == false) {
        if (!configuration.isJdbcJobStore()) {
            LOGGER.error("Some or all tasks could not be imported from midPoint repository to Quartz job store. They will therefore not be executed.");
        } else {
            LOGGER.warn("Some or all tasks could not be synchronized between midPoint repository and Quartz job store. They may not function correctly.");
        }
    }
    LOGGER.trace("Quartz scheduler initialized (not yet started, however)");
    LOGGER.info("Task Manager initialized");
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) SqlRepositoryFactory(com.evolveum.midpoint.repo.sql.SqlRepositoryFactory) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) RepositoryServiceFactoryException(com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration)

Example 4 with MidpointConfiguration

use of com.evolveum.midpoint.common.configuration.api.MidpointConfiguration in project midpoint by Evolveum.

the class TaskManagerConfiguration method setJdbcJobStoreInformation.

void setJdbcJobStoreInformation(MidpointConfiguration masterConfig, SqlRepositoryConfiguration sqlConfig, String defaultJdbcUrlPrefix) {
    Configuration c = masterConfig.getConfiguration(TASK_MANAGER_CONFIG_SECTION);
    jdbcDriver = c.getString(JDBC_DRIVER_CONFIG_ENTRY, sqlConfig != null ? sqlConfig.getDriverClassName() : null);
    String explicitJdbcUrl = c.getString(JDBC_URL_CONFIG_ENTRY, null);
    if (explicitJdbcUrl == null) {
        if (sqlConfig.isEmbedded()) {
            jdbcUrl = defaultJdbcUrlPrefix + "-quartz;MVCC=TRUE;DB_CLOSE_ON_EXIT=FALSE";
        } else {
            jdbcUrl = sqlConfig.getJdbcUrl();
        }
    } else {
        jdbcUrl = explicitJdbcUrl;
    }
    dataSource = c.getString(DATA_SOURCE_CONFIG_ENTRY, null);
    if (dataSource == null && explicitJdbcUrl == null && sqlConfig != null) {
        // we want to use quartz-specific JDBC if there is one (i.e. we do not want to inherit data source from repo in such a case)
        dataSource = sqlConfig.getDataSource();
    }
    if (dataSource != null) {
        LOGGER.info("Quartz database is at {} (a data source)", dataSource);
    } else {
        LOGGER.info("Quartz database is at {} (a JDBC URL)", jdbcUrl);
    }
    jdbcUser = c.getString(JDBC_USER_CONFIG_ENTRY, sqlConfig != null ? sqlConfig.getJdbcUsername() : null);
    jdbcPassword = c.getString(JDBC_PASSWORD_CONFIG_ENTRY, sqlConfig != null ? sqlConfig.getJdbcPassword() : null);
    hibernateDialect = sqlConfig != null ? sqlConfig.getHibernateDialect() : "";
    String defaultSqlSchemaFile = schemas.get(hibernateDialect);
    String defaultDriverDelegate = delegates.get(hibernateDialect);
    sqlSchemaFile = c.getString(SQL_SCHEMA_FILE_CONFIG_ENTRY, defaultSqlSchemaFile);
    jdbcDriverDelegateClass = c.getString(JDBC_DRIVER_DELEGATE_CLASS_CONFIG_ENTRY, defaultDriverDelegate);
    createQuartzTables = c.getBoolean(CREATE_QUARTZ_TABLES_CONFIG_ENTRY, CREATE_QUARTZ_TABLES_DEFAULT);
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) Configuration(org.apache.commons.configuration.Configuration) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration)

Example 5 with MidpointConfiguration

use of com.evolveum.midpoint.common.configuration.api.MidpointConfiguration in project midpoint by Evolveum.

the class TaskManagerConfiguration method setBasicInformation.

void setBasicInformation(MidpointConfiguration masterConfig) throws TaskManagerConfigurationException {
    Configuration c = masterConfig.getConfiguration(TASK_MANAGER_CONFIG_SECTION);
    stopOnInitializationFailure = c.getBoolean(STOP_ON_INITIALIZATION_FAILURE_CONFIG_ENTRY, STOP_ON_INITIALIZATION_FAILURE_DEFAULT);
    threads = c.getInt(THREADS_CONFIG_ENTRY, THREADS_DEFAULT);
    clustered = c.getBoolean(CLUSTERED_CONFIG_ENTRY, CLUSTERED_DEFAULT);
    jdbcJobStore = c.getBoolean(JDBC_JOB_STORE_CONFIG_ENTRY, clustered);
    nodeId = System.getProperty(MIDPOINT_NODE_ID_PROPERTY);
    if (StringUtils.isEmpty(nodeId) && !clustered) {
        nodeId = NODE_ID_DEFAULT;
    }
    jmxHostName = System.getProperty(MIDPOINT_JMX_HOST_NAME_PROPERTY);
    String portString = System.getProperty(JMX_PORT_PROPERTY);
    if (StringUtils.isEmpty(portString)) {
        jmxPort = JMX_PORT_DEFAULT;
    } else {
        try {
            jmxPort = Integer.parseInt(portString);
        } catch (NumberFormatException nfe) {
            throw new TaskManagerConfigurationException("Cannot get JMX management port - invalid integer value of " + portString, nfe);
        }
    }
    jmxConnectTimeout = c.getInt(JMX_CONNECT_TIMEOUT_CONFIG_ENTRY, JMX_CONNECT_TIMEOUT_DEFAULT);
    if (c.containsKey(TEST_MODE_CONFIG_ENTRY)) {
        midPointTestMode = c.getBoolean(TEST_MODE_CONFIG_ENTRY);
        LOGGER.trace(TEST_MODE_CONFIG_ENTRY + " present, its value = " + midPointTestMode);
    } else {
        LOGGER.trace(TEST_MODE_CONFIG_ENTRY + " NOT present");
        Properties sp = System.getProperties();
        if (sp.containsKey(SUREFIRE_PRESENCE_PROPERTY)) {
            LOGGER.info("Determined to run in a test environment, setting midPointTestMode to 'true'.");
            midPointTestMode = true;
        } else {
            midPointTestMode = false;
        }
    }
    LOGGER.trace("midPointTestMode = " + midPointTestMode);
    String useTI = c.getString(USE_THREAD_INTERRUPT_CONFIG_ENTRY, USE_THREAD_INTERRUPT_DEFAULT);
    try {
        useThreadInterrupt = UseThreadInterrupt.fromValue(useTI);
    } catch (IllegalArgumentException e) {
        throw new TaskManagerConfigurationException("Illegal value for " + USE_THREAD_INTERRUPT_CONFIG_ENTRY + ": " + useTI, e);
    }
    quartzNodeRegistrationCycleTime = c.getInt(QUARTZ_NODE_REGISTRATION_INTERVAL_CONFIG_ENTRY, QUARTZ_NODE_REGISTRATION_CYCLE_TIME_DEFAULT);
    nodeRegistrationCycleTime = c.getInt(NODE_REGISTRATION_INTERVAL_CONFIG_ENTRY, NODE_REGISTRATION_CYCLE_TIME_DEFAULT);
    nodeTimeout = c.getInt(NODE_TIMEOUT_CONFIG_ENTRY, NODE_TIMEOUT_DEFAULT);
    jmxUsername = c.getString(JMX_USERNAME_CONFIG_ENTRY, JMX_USERNAME_DEFAULT);
    jmxPassword = c.getString(JMX_PASSWORD_CONFIG_ENTRY, JMX_PASSWORD_DEFAULT);
    waitingTasksCheckInterval = c.getInt(WAITING_TASKS_CHECK_INTERVAL_CONFIG_ENTRY, WAITING_TASKS_CHECK_INTERVAL_DEFAULT);
    stalledTasksCheckInterval = c.getInt(STALLED_TASKS_CHECK_INTERVAL_CONFIG_ENTRY, STALLED_TASKS_CHECK_INTERVAL_DEFAULT);
    stalledTasksThreshold = c.getInt(STALLED_TASKS_THRESHOLD_CONFIG_ENTRY, STALLED_TASKS_THRESHOLD_DEFAULT);
    stalledTasksRepeatedNotificationInterval = c.getInt(STALLED_TASKS_REPEATED_NOTIFICATION_INTERVAL_CONFIG_ENTRY, STALLED_TASKS_REPEATED_NOTIFICATION_INTERVAL_DEFAULT);
    runNowKeepsOriginalSchedule = c.getBoolean(RUN_NOW_KEEPS_ORIGINAL_SCHEDULE_CONFIG_ENTRY, RUN_NOW_KEEPS_ORIGINAL_SCHEDULE_DEFAULT);
    schedulerInitiallyStopped = c.getBoolean(SCHEDULER_INITIALLY_STOPPED_CONFIG_ENTRY, false);
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) Configuration(org.apache.commons.configuration.Configuration) SqlRepositoryConfiguration(com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration) TaskManagerConfigurationException(com.evolveum.midpoint.task.api.TaskManagerConfigurationException) Properties(java.util.Properties)

Aggregations

MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)8 SqlRepositoryConfiguration (com.evolveum.midpoint.repo.sql.SqlRepositoryConfiguration)4 AjaxDownloadBehaviorFromFile (com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile)4 File (org.apache.wicket.util.file.File)4 CommonException (com.evolveum.midpoint.util.exception.CommonException)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 IOException (java.io.IOException)3 Configuration (org.apache.commons.configuration.Configuration)3 RestartResponseException (org.apache.wicket.RestartResponseException)3 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 RepositoryServiceFactoryException (com.evolveum.midpoint.repo.api.RepositoryServiceFactoryException)1 SqlRepositoryFactory (com.evolveum.midpoint.repo.sql.SqlRepositoryFactory)1 TaskManagerConfigurationException (com.evolveum.midpoint.task.api.TaskManagerConfigurationException)1 PageDashboard (com.evolveum.midpoint.web.page.admin.home.PageDashboard)1 FileOutputStream (java.io.FileOutputStream)1 FilenameFilter (java.io.FilenameFilter)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1