Search in sources :

Example 16 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class TaskResultCreatorTest method testThatEmptyTaskResultIsUsedWhenResultIsNotInDatabase.

@Test
public void testThatEmptyTaskResultIsUsedWhenResultIsNotInDatabase() throws UnknownTaskException {
    TaskResultCreator taskResultCreator = spy(TaskResultCreator.class);
    TaskResultImpl mockedTaskResultImpl = mock(TaskResultImpl.class);
    doReturn(mockedTaskResultImpl).when(taskResultCreator).getEmptyTaskResult(any(InternalTask.class), any(Throwable.class), any(TaskLogs.class));
    Map<TaskId, TaskResult> loadTaskResultsValue = new HashMap<>();
    loadTaskResultsValue.put(this.createTaskID(), mockedTaskResultImpl);
    SchedulerDBManager mockedschedulerDbManager = mock(SchedulerDBManager.class);
    when(mockedschedulerDbManager.loadTasksResults(any(JobId.class), any(List.class))).thenThrow(DatabaseManagerException.class);
    taskResultCreator.getTaskResult(mockedschedulerDbManager, this.getMockedInternalJob(this.getMockedJobDescriptorWithPausedTask()), this.getMockedInternalTask());
    verify(mockedTaskResultImpl).setPropagatedVariables(any(Map.class));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) HashMap(java.util.HashMap) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) TaskLogs(org.ow2.proactive.scheduler.common.task.TaskLogs) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 17 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class SchedulingService method addThirdPartyCredentials.

/**
 * Create a new Credential object containing users' 3rd Party Credentials.
 *
 * @param creds credentials for specific user
 * @return in case of success new object containing the 3rd party credentials used to create bindings
 * at clean script
 */
Credentials addThirdPartyCredentials(Credentials creds) throws KeyException, IllegalAccessException {
    // retrieve scheduler key pair
    String privateKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PRIVKEY_PATH.getValueAsString());
    String publicKeyPath = PASchedulerProperties.getAbsolutePath(PASchedulerProperties.SCHEDULER_AUTH_PUBKEY_PATH.getValueAsString());
    // get keys from task
    PrivateKey privateKey = Credentials.getPrivateKey(privateKeyPath);
    PublicKey publicKey = Credentials.getPublicKey(publicKeyPath);
    // retrieve the current creData from task
    CredData credData = creds.decrypt(privateKey);
    // retrive database to get third party credentials from
    SchedulerDBManager dbManager = getInfrastructure().getDBManager();
    if (dbManager != null) {
        Map<String, HybridEncryptedData> thirdPartyCredentials = dbManager.thirdPartyCredentialsMap(credData.getLogin());
        if (thirdPartyCredentials == null) {
            logger.error("Failed to retrieve Third Party Credentials!");
            throw new KeyException("Failed to retrieve thirdPartyCredentials!");
        } else {
            // cycle third party credentials, add one-by-one to the decrypter
            for (Map.Entry<String, HybridEncryptedData> thirdPartyCredential : thirdPartyCredentials.entrySet()) {
                String decryptedValue = HybridEncryptionUtil.decryptString(thirdPartyCredential.getValue(), privateKey);
                credData.addThirdPartyCredential(thirdPartyCredential.getKey(), decryptedValue);
            }
        }
    }
    return Credentials.createCredentials(credData, publicKey);
}
Also used : PrivateKey(java.security.PrivateKey) HybridEncryptedData(org.ow2.proactive.authentication.crypto.HybridEncryptionUtil.HybridEncryptedData) PublicKey(java.security.PublicKey) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) CredData(org.ow2.proactive.authentication.crypto.CredData) Map(java.util.Map) KeyException(java.security.KeyException)

Example 18 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class TaskResultCreator method extractTaskResultsAndMergeIntoMap.

private Map<String, byte[]> extractTaskResultsAndMergeIntoMap(SchedulerDBManager dbManager, EligibleTaskDescriptor eligibleTaskDescriptor, InternalJob job) {
    Map<String, byte[]> mergedVariables = new HashMap<>();
    int numberOfParentTasks = eligibleTaskDescriptor.getParents().size();
    List<TaskId> parentIds = new ArrayList<>(numberOfParentTasks);
    for (int i = 0; i < numberOfParentTasks; i++) {
        parentIds.add(eligibleTaskDescriptor.getParents().get(i).getTaskId());
    }
    // Batch fetching of parent tasks results
    Map<TaskId, TaskResult> taskResults = new HashMap<>();
    for (List<TaskId> parentsSubList : ListUtils.partition(new ArrayList<>(parentIds), PASchedulerProperties.SCHEDULER_DB_FETCH_TASK_RESULTS_BATCH_SIZE.getValueAsInt())) {
        taskResults.putAll(dbManager.loadTasksResults(job.getId(), parentsSubList));
    }
    for (TaskResult taskResult : taskResults.values()) {
        if (taskResult.getPropagatedVariables() != null) {
            mergedVariables.putAll(taskResult.getPropagatedVariables());
        }
    }
    return mergedVariables;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult)

Example 19 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class SchedulerDbManagerRecoveryTest method createDatabase.

private SchedulerDBManager createDatabase(boolean wipeOnStartup) throws URISyntaxException {
    String configureFilename = "hibernate-update.cfg.xml";
    if (wipeOnStartup) {
        configureFilename = "hibernate.cfg.xml";
    }
    Configuration config = new Configuration().configure(new File(this.getClass().getResource("/functionaltests/config/" + configureFilename).toURI()));
    String jdbcUrl = "jdbc:hsqldb:file:" + dbFolder.getRoot().getAbsolutePath() + ";create=true;hsqldb.tx=mvcc;hsqldb.write_delay=false";
    config.setProperty("hibernate.connection.url", jdbcUrl);
    return new SchedulerDBManager(config, wipeOnStartup);
}
Also used : Configuration(org.hibernate.cfg.Configuration) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) File(java.io.File)

Example 20 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class SchedulingServiceTest10 method init.

@Before
public void init() throws Exception {
    // default test infrastructure executes all requests in the same thread, for this test real thread pool is needed
    SchedulerDBManager dbManager = SchedulerDBManager.createInMemorySchedulerDBManager();
    MockSchedulingInfrastructure infrastructure = new MockSchedulingInfrastructure(dbManager, Executors.newFixedThreadPool(1));
    MockSchedulingListener listener = new MockSchedulingListener();
    service = new SchedulingService(infrastructure, listener, null, DefaultPolicy.class.getName(), Mockito.mock(SchedulingMethod.class));
}
Also used : SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) SchedulingService(org.ow2.proactive.scheduler.core.SchedulingService) Before(org.junit.Before)

Aggregations

SchedulerDBManager (org.ow2.proactive.scheduler.core.db.SchedulerDBManager)18 Test (org.junit.Test)14 HashMap (java.util.HashMap)9 JobId (org.ow2.proactive.scheduler.common.job.JobId)9 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)9 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)8 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)8 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)8 List (java.util.List)7 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)3 ProActiveTest (org.ow2.tests.ProActiveTest)3 File (java.io.File)2 Map (java.util.Map)2 Configuration (org.hibernate.cfg.Configuration)2 Before (org.junit.Before)2 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)2 JobDescriptorImpl (org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl)2 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)2 ImmutableList (com.google.common.collect.ImmutableList)1 KeyException (java.security.KeyException)1