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