Search in sources :

Example 1 with PDSAdapterJobStatusState

use of com.mercedesbenz.sechub.adapter.pds.data.PDSJobStatus.PDSAdapterJobStatusState in project sechub by mercedes-benz.

the class PDSAdapterV1 method waitForJobDone.

private void waitForJobDone(PDSContext context) throws AdapterException {
    PDSAdapterConfig config = context.getConfig();
    PDSAdapterConfigData data = config.getPDSAdapterConfigData();
    UUID secHubJobUUID = data.getSecHubJobUUID();
    UUID pdsJobUUID = context.getPdsJobUUID();
    int count = 0;
    boolean jobEnded = false;
    PDSJobStatus jobstatus = null;
    long started = getCurrentTimeMilliseconds();
    int timeToWaitForNextCheckOperationInMilliseconds = config.getTimeToWaitForNextCheckOperationInMilliseconds();
    LOG.info("Start waiting for PDS-job:{} to be done. Related SecHub-Job is:{} . Will check every {} ms. Adapter will wait maximum {} ms before timeout.", pdsJobUUID, secHubJobUUID, timeToWaitForNextCheckOperationInMilliseconds, config.getTimeOutInMilliseconds());
    while (!jobEnded && isNotTimeout(config, started)) {
        count++;
        LOG.debug("Fetch job status for PDS-job:{}. Elapsed time for {} retries:{} ms", pdsJobUUID, count, calculateElapsedTime(started));
        /* see PDSJobStatusState.java */
        jobstatus = getJobStatus(context);
        PDSAdapterJobStatusState state = jobstatus.state;
        switch(state) {
            case DONE:
                jobEnded = true;
                break;
            case FAILED:
                throw asAdapterException("PDS job execution failed", config);
            case CANCELED:
                throw asAdapterCanceledByUserException(config);
            default:
        }
        if (jobEnded) {
            // break while...
            break;
        }
        assertNotInterrupted();
        try {
            Thread.sleep(timeToWaitForNextCheckOperationInMilliseconds);
        } catch (InterruptedException e) {
            throw new AdapterException(getAdapterLogId(null), "Execution thread was interrupted");
        }
    }
    if (!jobEnded) {
        long elapsedTimeInMilliseconds = calculateElapsedTime(started);
        throw new IllegalStateException("Even after " + count + " retries, every waiting " + timeToWaitForNextCheckOperationInMilliseconds + " ms, no job report state acceppted as END was found.!\nElapsed time were" + elapsedTimeInMilliseconds + " ms.\nLAST fetched jobstatus for " + secHubJobUUID + ", PDS job uuid: " + pdsJobUUID + " was:\n" + jobstatus);
    }
}
Also used : PDSJobStatus(com.mercedesbenz.sechub.adapter.pds.data.PDSJobStatus) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) UUID(java.util.UUID) PDSAdapterJobStatusState(com.mercedesbenz.sechub.adapter.pds.data.PDSJobStatus.PDSAdapterJobStatusState)

Aggregations

AdapterException (com.mercedesbenz.sechub.adapter.AdapterException)1 PDSJobStatus (com.mercedesbenz.sechub.adapter.pds.data.PDSJobStatus)1 PDSAdapterJobStatusState (com.mercedesbenz.sechub.adapter.pds.data.PDSJobStatus.PDSAdapterJobStatusState)1 UUID (java.util.UUID)1