Search in sources :

Example 1 with ProcessManagerException

use of org.jboss.pnc.spi.exception.ProcessManagerException in project pnc by project-ncl.

the class RestConnector method startProcess.

public Long startProcess(String processId, Object requestObject, String correlationKey, String accessToken) throws ProcessManagerException {
    HttpPost request = endpointUrl.startProcessInstance(currentDeploymentId, processId, correlationKey);
    log.debug("Starting new process using http endpoint: {}", request.getURI());
    Map<String, Object> processParameters = new HashMap<>();
    processParameters.put("auth", Collections.singletonMap("token", accessToken));
    processParameters.put("mdc", new MDCParameters());
    processParameters.put("task", requestObject);
    Map<String, Map<String, Object>> body = Collections.singletonMap("initData", processParameters);
    HttpEntity requestEntity;
    try {
        requestEntity = new StringEntity(JsonOutputConverterMapper.apply(body));
    } catch (UnsupportedEncodingException e) {
        throw new ProcessManagerException("Cannot prepare BPM REST call.", e);
    }
    request.setEntity(requestEntity);
    configureRequest(accessToken, request);
    try (CloseableHttpResponse response = httpClient.execute(request)) {
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode == 201) {
            Long processInstanceId = JsonOutputConverterMapper.readValue(response.getEntity().getContent(), Long.class);
            log.info("Started new process instance with id: {}", processInstanceId);
            return processInstanceId;
        } else {
            throw new ProcessManagerException("Cannot start new process instance, response status: " + statusCode);
        }
    } catch (IOException e) {
        throw new ProcessManagerException("Cannot start new process instance.", e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MDCParameters(org.jboss.pnc.bpm.model.MDCParameters) IOException(java.io.IOException) StringEntity(org.apache.http.entity.StringEntity) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ProcessManagerException

use of org.jboss.pnc.spi.exception.ProcessManagerException in project pnc by project-ncl.

the class ProductMilestoneReleaseManager method triggerRHPAMRelease.

/**
 * Trigger the release using the new RHPAM server
 *
 * @param milestone milestone to be released
 * @param accessToken access token to use to submit request
 * @param milestoneReleaseId the milestone id
 */
private ProductMilestoneRelease triggerRHPAMRelease(ProductMilestone milestone, String accessToken, Long milestoneReleaseId) {
    ProductMilestoneRelease release = new ProductMilestoneRelease();
    release.setId(milestoneReleaseId);
    release.setStartingDate(new Date());
    release.setMilestone(milestone);
    try (RestConnector restConnector = new RestConnector(bpmConfig)) {
        MilestoneReleaseTask releaseTask = new MilestoneReleaseTask(milestone, accessToken);
        releaseTask.setTaskId(bpmManager.getNextTaskId());
        releaseTask.setGlobalConfig(globalConfig);
        releaseTask.setJsonEncodedProcessParameters(false);
        restConnector.startProcess(bpmConfig.getBpmNewReleaseProcessId(), releaseTask.getExtendedProcessParameters(), Numbers.decimalToBase32(milestoneReleaseId), accessToken);
        return release;
    } catch (CoreException | ProcessManagerException e) {
        log.error("Error trying to start brew push task for milestone: {}", milestone.getId(), e);
        userLog.error("Release process creation failed.", e);
        release.setStatus(MilestoneCloseStatus.SYSTEM_ERROR);
        release.setEndDate(new Date());
        return release;
    }
}
Also used : RestConnector(org.jboss.pnc.bpm.RestConnector) CoreException(org.jboss.pnc.spi.exception.CoreException) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) MilestoneReleaseTask(org.jboss.pnc.bpm.task.MilestoneReleaseTask) ProductMilestoneRelease(org.jboss.pnc.model.ProductMilestoneRelease) Date(java.util.Date)

Example 3 with ProcessManagerException

use of org.jboss.pnc.spi.exception.ProcessManagerException in project pnc by project-ncl.

the class ProductMilestoneReleaseManager method storeBuildRecordPush.

private void storeBuildRecordPush(BuildImportResultRest buildRest, ProductMilestoneRelease productMilestoneRelease) {
    Base32LongID recordId = BuildMapper.idMapper.toEntity(buildRest.getBuildRecordId());
    BuildRecord record = buildRecordRepository.queryById(recordId);
    if (record == null) {
        log.error("No record found for record id: {}, skipped saving info: {}", recordId, buildRest);
        return;
    }
    BuildPushStatus status;
    try {
        status = convertStatus(buildRest.getStatus());
    } catch (ProcessManagerException e) {
        log.error("Cannot convert status.", e);
        throw new RuntimeException("Cannot convert status.", e);
    }
    BuildRecordPushResult buildRecordPush = BuildRecordPushResult.newBuilder().id(Sequence.nextId()).buildRecord(record).status(status).brewBuildId(buildRest.getBrewBuildId()).brewBuildUrl(buildRest.getBrewBuildUrl()).tagPrefix(// TODO tag!
    "").productMilestoneRelease(productMilestoneRelease).build();
    buildRecordPushResultRepository.save(buildRecordPush);
}
Also used : Base32LongID(org.jboss.pnc.model.Base32LongID) BuildPushStatus(org.jboss.pnc.enums.BuildPushStatus) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) BuildRecordPushResult(org.jboss.pnc.model.BuildRecordPushResult) BuildRecord(org.jboss.pnc.model.BuildRecord)

Example 4 with ProcessManagerException

use of org.jboss.pnc.spi.exception.ProcessManagerException in project pnc by project-ncl.

the class BpmMock method startTask.

@Override
public boolean startTask(BpmTask task) throws CoreException {
    Connector connector = Mockito.mock(Connector.class);
    try {
        Mockito.when(connector.startProcess(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1L);
    } catch (ProcessManagerException e) {
        log.error("Cannot mock start process.", e);
    }
    task.setConnector(connector);
    boolean started = super.startTask(task);
    onTaskStarted.ifPresent(supplier -> supplier.accept(task));
    return started;
}
Also used : Connector(org.jboss.pnc.bpm.Connector) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException)

Example 5 with ProcessManagerException

use of org.jboss.pnc.spi.exception.ProcessManagerException in project pnc by project-ncl.

the class DeliverableAnalyzerManagerImpl method startAnalysis.

private void startAnalysis(String milestoneId, List<String> sourcesLink, Base32LongID operationId) {
    Request callback = operationsManager.getOperationCallback(operationId);
    String id = operationId.getId();
    try (RestConnector restConnector = new RestConnector(bpmConfig)) {
        AnalyzeDeliverablesBpmRequest bpmRequest = new AnalyzeDeliverablesBpmRequest(id, milestoneId, sourcesLink);
        AnalyzeDeliverablesTask analyzeTask = new AnalyzeDeliverablesTask(bpmRequest, callback);
        restConnector.startProcess(bpmConfig.getAnalyzeDeliverablesBpmProcessId(), analyzeTask, id, userService.currentUserToken());
        DeliverableAnalysisStatusChangedEvent analysisStatusChanged = DefaultDeliverableAnalysisStatusChangedEvent.started(id, milestoneId, sourcesLink);
        analysisStatusChangedEventNotifier.fire(analysisStatusChanged);
    } catch (ProcessManagerException e) {
        log.error("Error trying to start analysis of deliverables task for milestone: {}", milestoneId, e);
        throw new RuntimeException(e);
    }
}
Also used : RestConnector(org.jboss.pnc.bpm.RestConnector) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) AnalyzeDeliverablesTask(org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest) Request(org.jboss.pnc.api.dto.Request) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest)

Aggregations

ProcessManagerException (org.jboss.pnc.spi.exception.ProcessManagerException)6 RestConnector (org.jboss.pnc.bpm.RestConnector)3 Map (java.util.Map)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Pattern (java.util.regex.Pattern)1 PermitAll (javax.annotation.security.PermitAll)1 Stateless (javax.ejb.Stateless)1 Inject (javax.inject.Inject)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1