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