Search in sources :

Example 1 with MCRJob

use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.

the class MCRPackerManagerTest method testPackerConfigurationStart.

@Test
public void testPackerConfigurationStart() throws Exception {
    MCRConfiguration mcrConfiguration = MCRConfiguration.instance();
    String testPackerPrefix = MCRPacker.PACKER_CONFIGURATION_PREFIX + TEST_PACKER_ID + ".";
    Map<String, String> parameterMap = new Hashtable<>();
    // add packer parameter
    parameterMap.put("packer", TEST_PACKER_ID);
    // add test parameter
    parameterMap.put(MCRPackerMock.TEST_PARAMETER_KEY, MCRPackerMock.TEST_VALUE);
    MCRJob packerJob = MCRPackerManager.startPacking(parameterMap);
    Assert.assertNotNull("The Packer job is not present!", packerJob);
    endTransaction();
    Thread.sleep(1000);
    startNewTransaction();
    int waitTime = 10;
    while (waitTime > 0 && !mcrConfiguration.getBoolean(MCRPackerMock.FINISHED_PROPERTY, false) && !mcrConfiguration.getBoolean(MCRPackerMock.SETUP_CHECKED_PROPERTY, false)) {
        Thread.sleep(1000);
        waitTime -= 1;
    }
    Assert.assertTrue("PackerJob did not finish in time!", waitTime > 0);
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) Hashtable(java.util.Hashtable) MCRJob(org.mycore.services.queuedjob.MCRJob) Test(org.junit.Test)

Example 2 with MCRJob

use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.

the class MCRPIJobRegistrationService method addDeleteJob.

/**
 * @see #addRegisterJob(Map)
 */
protected void addDeleteJob(Map<String, String> contextParameters) {
    MCRJob job = createJob(contextParameters, PiJobAction.DELETE);
    REGISTER_JOB_QUEUE.offer(job);
}
Also used : MCRJob(org.mycore.services.queuedjob.MCRJob)

Example 3 with MCRJob

use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.

the class MCRPackerManager method startPacking.

/**
 * Creates and starts a new PackagingJob.
 * <p>The rights you need to start a Packer depends on the implementation!</p>
 * @param jobParameters the parameters which will be passed to the job. (Should include a packer)
 * @return the created MCRJob
 * @throws MCRUsageException if invalid parameters are passed to the packer
 * @throws MCRAccessException if the current user doesn't have the rights to use the packer(on a specific  object).
 */
public static MCRJob startPacking(Map<String, String> jobParameters) throws MCRUsageException, MCRAccessException {
    String packer = jobParameters.get("packer");
    if (packer == null) {
        LOGGER.error("No Packer parameter found!");
        return null;
    }
    checkPacker(packer, jobParameters);
    MCRJob mcrJob = new MCRJob(MCRPackerJobAction.class);
    mcrJob.setParameters(jobParameters);
    if (!PACKER_JOB_QUEUE.offer(mcrJob)) {
        throw new MCRException("Could not add Job to Queue!");
    }
    return mcrJob;
}
Also used : MCRException(org.mycore.common.MCRException) MCRJob(org.mycore.services.queuedjob.MCRJob)

Example 4 with MCRJob

use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.

the class MCRPackerServlet method doGetPost.

@Override
protected void doGetPost(MCRServletJob job) throws IOException {
    String packer = job.getRequest().getParameter("packer");
    if (packer == null || packer.isEmpty()) {
        try {
            job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "No or invalid 'packer' parameter!");
        } catch (IOException e) {
            LOGGER.error("Error while sending request error to client!", e);
            return;
        }
    }
    Map<String, String> jobParameters = resolveJobParameters(job);
    try {
        MCRJob mcrJob = MCRPackerManager.startPacking(jobParameters);
        if (mcrJob == null) {
            job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "No packer parameter!");
        }
    } catch (MCRAccessException e) {
        job.getResponse().sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getMessage());
    } catch (MCRUsageException e) {
        job.getResponse().sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid Parameters: " + e.getMessage());
    }
    if (jobParameters.containsKey("redirect")) {
        String redirect = jobParameters.get("redirect");
        job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(redirect));
    }
}
Also used : MCRUsageException(org.mycore.common.MCRUsageException) MCRAccessException(org.mycore.access.MCRAccessException) MCRJob(org.mycore.services.queuedjob.MCRJob) IOException(java.io.IOException)

Example 5 with MCRJob

use of org.mycore.services.queuedjob.MCRJob in project mycore by MyCoRe-Org.

the class MCRPIJobRegistrationService method addRegisterJob.

/**
 * Adds a register job which will be called in the persistent {@link MCRJob} environment in a extra thread.
 * @param contextParameters pass parameters which are needed to register the PI. The parameter action and
 *                          registrationServiceID will be added, because they are necessary to reassign the job to
 *                          the right {@link MCRPIJobRegistrationService} and method.
 */
protected void addRegisterJob(Map<String, String> contextParameters) {
    MCRJob job = createJob(contextParameters, PiJobAction.REGISTER);
    REGISTER_JOB_QUEUE.offer(job);
}
Also used : MCRJob(org.mycore.services.queuedjob.MCRJob)

Aggregations

MCRJob (org.mycore.services.queuedjob.MCRJob)7 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Test (org.junit.Test)1 MCRAccessException (org.mycore.access.MCRAccessException)1 MCRException (org.mycore.common.MCRException)1 MCRUsageException (org.mycore.common.MCRUsageException)1 MCRConfiguration (org.mycore.common.config.MCRConfiguration)1