Search in sources :

Example 1 with CIEvent

use of com.hp.octane.integrations.dto.events.CIEvent in project octane-gitlab-service by MicroFocus.

the class EventListener method getCIEvents.

private List<CIEvent> getCIEvents(JSONObject event) {
    List<CIEvent> events = new ArrayList<>();
    CIEventType eventType = getEventType(event);
    Integer buildCiId = getEventTargetObjectId(event);
    Object duration = getDuration(event);
    Long startTime = getStartTime(event, duration);
    SCMData scmData = null;
    boolean isScmNull = true;
    if (isPipelineEvent(event)) {
        if (eventType == CIEventType.STARTED) {
            scmData = getScmData(event);
            isScmNull = scmData == null;
        } else {
            String GITLAB_BLANK_SHA = "0000000000000000000000000000000000000000";
            isScmNull = event.getJSONObject("object_attributes").getString("before_sha").equals(GITLAB_BLANK_SHA);
        }
    }
    events.add(dtoFactory.newDTO(CIEvent.class).setProjectDisplayName(getCiDisplayName(event)).setEventType(eventType).setBuildCiId(buildCiId.toString()).setNumber(buildCiId.toString()).setProject(getCiFullName(event)).setResult(eventType == CIEventType.STARTED || eventType == CIEventType.DELETED ? null : convertCiBuildResult(getStatus(event))).setStartTime(startTime).setEstimatedDuration(null).setDuration(calculateDuration(eventType, duration)).setScmData(null).setCauses(getCauses(event, isScmNull)).setPhaseType(isPipelineEvent(event) ? PhaseType.POST : PhaseType.INTERNAL));
    if (scmData != null) {
        events.add(dtoFactory.newDTO(CIEvent.class).setProjectDisplayName(getCiDisplayName(event)).setEventType(CIEventType.SCM).setBuildCiId(buildCiId.toString()).setNumber(null).setProject(getCiFullName(event)).setResult(null).setStartTime(null).setEstimatedDuration(null).setDuration(null).setScmData(scmData).setCauses(getCauses(event, false)).setPhaseType(null));
    }
    return events;
}
Also used : SCMData(com.hp.octane.integrations.dto.scm.SCMData) CIEvent(com.hp.octane.integrations.dto.events.CIEvent) CIEventType(com.hp.octane.integrations.dto.events.CIEventType) JSONObject(org.json.JSONObject)

Example 2 with CIEvent

use of com.hp.octane.integrations.dto.events.CIEvent in project octane-ci-java-sdk by MicroFocus.

the class OctaneSDKBasicFunctionalityTest method simulateEventsCycleAllClients.

private void simulateEventsCycleAllClients() {
    OctaneSDK.getClients().forEach(octaneClient -> {
        try {
            CIEvent event = dtoFactory.newDTO(CIEvent.class).setEventType(CIEventType.STARTED).setProject("job-a").setBuildCiId("1").setCauses(Collections.singletonList(dtoFactory.newDTO(CIEventCause.class).setType(CIEventCauseType.USER))).setStartTime(System.currentTimeMillis());
            octaneClient.getEventsService().publishEvent(event);
            event = dtoFactory.newDTO(CIEvent.class).setEventType(CIEventType.SCM).setProject("job-a").setCauses(Collections.singletonList(dtoFactory.newDTO(CIEventCause.class).setType(CIEventCauseType.USER))).setBuildCiId("1").setScmData(dtoFactory.newDTO(SCMData.class).setRepository(dtoFactory.newDTO(SCMRepository.class).setType(SCMType.GIT).setUrl("http://github.org").setBranch("master")).setBuiltRevId(UUID.randomUUID().toString()));
            octaneClient.getEventsService().publishEvent(event);
            event = dtoFactory.newDTO(CIEvent.class).setEventType(CIEventType.FINISHED).setCauses(Collections.singletonList(dtoFactory.newDTO(CIEventCause.class).setType(CIEventCauseType.USER))).setProject("job-a").setBuildCiId("1").setDuration(3000L);
            octaneClient.getEventsService().publishEvent(event);
        } catch (Exception e) {
            logger.error("failed to dispatch events to " + octaneClient, e);
        }
    });
}
Also used : CIEvent(com.hp.octane.integrations.dto.events.CIEvent) CIEventCause(com.hp.octane.integrations.dto.causes.CIEventCause) SCMRepository(com.hp.octane.integrations.dto.scm.SCMRepository) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with CIEvent

use of com.hp.octane.integrations.dto.events.CIEvent in project octane-ci-java-sdk by MicroFocus.

the class EventsServiceImpl method getEventsChunk.

private List<CIEvent> getEventsChunk() {
    int maxInBulk = ConfigurationParameterFactory.isSendEventsInBulk(configurer.octaneConfiguration) ? EVENTS_CHUNK_SIZE : 1;
    List<CIEvent> eventsChunk = new ArrayList<>(events.subList(0, Math.min(events.size(), maxInBulk)));
    // - if in iteration we encounter multibranch child start event - no other event is allowed to be after it and will be pushed in next bulk
    if (eventsChunk.size() > 1) {
        for (int i = 0; i < eventsChunk.size(); i++) {
            CIEvent ciEvent = eventsChunk.get(i);
            if (CIEventType.STARTED.equals(ciEvent.getEventType()) && MultiBranchType.MULTI_BRANCH_CHILD.equals(ciEvent.getMultiBranchType()) && i + 1 < eventsChunk.size()) {
                eventsChunk = new ArrayList<>(eventsChunk.subList(0, i + 1));
                break;
            }
        }
    }
    return eventsChunk;
}
Also used : CIEvent(com.hp.octane.integrations.dto.events.CIEvent)

Example 4 with CIEvent

use of com.hp.octane.integrations.dto.events.CIEvent in project octane-ci-java-sdk by MicroFocus.

the class EventsServiceImpl method worker.

// infallible everlasting worker function
private void worker() {
    while (!eventsPushExecutor.isShutdown()) {
        if (!workerPreflight.preflight()) {
            continue;
        }
        // build events list to be sent
        List<CIEvent> eventsChunk = null;
        CIEventsList eventsSnapshot;
        try {
            eventsChunk = getEventsChunk();
            CIServerInfo serverInfo = configurer.pluginServices.getServerInfo();
            serverInfo.setInstanceId(configurer.octaneConfiguration.getInstanceId());
            eventsSnapshot = dtoFactory.newDTO(CIEventsList.class).setServer(serverInfo).setEvents(eventsChunk);
        } catch (Throwable t) {
            logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to serialize chunk of " + (eventsChunk != null ? eventsChunk.size() : "[NULL]") + " events, dropping them off (if any) and continue");
            removeEvents(eventsChunk);
            continue;
        }
        // send the data to Octane
        try {
            String correlationId = CIPluginSDKUtils.getNextCorrelationId();
            logEventsToBeSent(eventsSnapshot, correlationId);
            sendEventsData(eventsSnapshot, correlationId);
            removeEvents(eventsChunk);
            if (events.size() > 0) {
                logger.info(configurer.octaneConfiguration.getLocationForLog() + "left to send " + events.size() + " events");
            }
        } catch (RequestTimeoutException rte) {
            requestTimeoutCount++;
            lastRequestTimeoutTime = System.currentTimeMillis();
            logger.info(configurer.octaneConfiguration.getLocationForLog() + rte.getMessage());
            CIPluginSDKUtils.doWait(TEMPORARY_FAILURE_PAUSE);
        } catch (TemporaryException tqie) {
            logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to send events with temporary error, breathing " + TEMPORARY_FAILURE_PAUSE + "ms and continue", tqie);
            CIPluginSDKUtils.doWait(TEMPORARY_FAILURE_PAUSE);
        } catch (PermanentException pqie) {
            logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to send events with permanent error, dropping this chunk and continue", pqie);
            removeEvents(eventsChunk);
        } catch (Throwable t) {
            logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to send events with unexpected error, dropping this chunk and continue", t);
            removeEvents(eventsChunk);
        }
    }
}
Also used : RequestTimeoutException(com.hp.octane.integrations.exceptions.RequestTimeoutException) TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) CIEvent(com.hp.octane.integrations.dto.events.CIEvent) CIEventsList(com.hp.octane.integrations.dto.events.CIEventsList) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) CIServerInfo(com.hp.octane.integrations.dto.general.CIServerInfo)

Example 5 with CIEvent

use of com.hp.octane.integrations.dto.events.CIEvent in project octane-ci-java-sdk by MicroFocus.

the class EventsServiceImpl method logEventsToBeSent.

private void logEventsToBeSent(CIEventsList eventsList, String correlationId) {
    try {
        List<String> eventsStringified = new LinkedList<>();
        for (CIEvent event : eventsList.getEvents()) {
            String str = event.getProject() + ":" + event.getBuildCiId() + ":" + event.getEventType();
            if (CIEventType.FINISHED.equals(event.getEventType()) && event.getTestResultExpected() != null && event.getTestResultExpected() == true) {
                str += "(tests=true)";
            }
            eventsStringified.add(str);
        }
        logger.info(configurer.octaneConfiguration.getLocationForLog() + "sending [" + String.join(", ", eventsStringified) + "] event/s. Correlation ID - " + correlationId);
        if (ConfigurationParameterFactory.isLogEvents(configurer.octaneConfiguration)) {
            for (CIEvent event : eventsList.getEvents()) {
                String str = String.format("%s%s:%s:%s %s", configurer.octaneConfiguration.getLocationForLog(), event.getProject(), event.getBuildCiId(), event.getEventType(), dtoFactory.dtoToJson(event));
                logger.info(eventsMarker, str);
            }
        }
    } catch (Exception e) {
        logger.error(configurer.octaneConfiguration.getLocationForLog() + "failed to log events to be sent", e);
    }
}
Also used : CIEvent(com.hp.octane.integrations.dto.events.CIEvent) RequestTimeoutException(com.hp.octane.integrations.exceptions.RequestTimeoutException) InterruptedIOException(java.io.InterruptedIOException) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) IOException(java.io.IOException)

Aggregations

CIEvent (com.hp.octane.integrations.dto.events.CIEvent)7 IOException (java.io.IOException)4 PermanentException (com.hp.octane.integrations.exceptions.PermanentException)3 TemporaryException (com.hp.octane.integrations.exceptions.TemporaryException)3 CIEventType (com.hp.octane.integrations.dto.events.CIEventType)2 RequestTimeoutException (com.hp.octane.integrations.exceptions.RequestTimeoutException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CIEventCause (com.hp.octane.integrations.dto.causes.CIEventCause)1 CIEventsList (com.hp.octane.integrations.dto.events.CIEventsList)1 CIServerInfo (com.hp.octane.integrations.dto.general.CIServerInfo)1 CIParameter (com.hp.octane.integrations.dto.parameters.CIParameter)1 SCMData (com.hp.octane.integrations.dto.scm.SCMData)1 SCMRepository (com.hp.octane.integrations.dto.scm.SCMRepository)1 ParsedPath (com.microfocus.octane.gitlab.helpers.ParsedPath)1 GherkinTestResultsProvider (com.microfocus.octane.gitlab.testresults.GherkinTestResultsProvider)1 JunitTestResultsProvider (com.microfocus.octane.gitlab.testresults.JunitTestResultsProvider)1 InterruptedIOException (java.io.InterruptedIOException)1 MalformedURLException (java.net.MalformedURLException)1 ExecutionException (java.util.concurrent.ExecutionException)1 GitLabApiException (org.gitlab4j.api.GitLabApiException)1