Skip to content

Commit

Permalink
EVDOC01-155: Correccions de codi i logs (#32)
Browse files Browse the repository at this point in the history
Correcció d'aturada inesperada del job
  • Loading branch information
mollerentornos authored Sep 19, 2024
1 parent 835abbd commit d708d56
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,4 @@ error.channel_number_more_than_30=You cannot add another channel because the tea
error.general_failure=General failure
error.channel_number_limit_reached=Channel limitation has been reached
error.user_synchronization=The following users could not be found in Microsoft:


error.users_not_found=No users were found for this group, or Microsoft has not refreshed the data yet. Rerunning synchronization may resolve this issue.
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,4 @@ error.channel_number_more_than_30=No pots afegir altre canal perqu\u00E8 el equi
error.general_failure=Error general
error.user_synchronization=No s\u2019han pogut trobar els seg\u00FCents usuaris a Microsoft:
error.channel_number_limit_reached=S\u2019ha aplegat al l\u00EDmit de canals
error.users_not_found=No s\u2019han trobat usuaris per a aquest grup o Microsoft no ha actualitzat les dades encara. Si torna a executar la sincronitzaci\u00F3, \u00E9s possible que es resolgui el problema.
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,4 @@ error.channel_number_more_than_30=No puedes agregar otro canal porque el equipo
error.general_failure=Error general
error.channel_number_limit_reached=L\u00EDmite de grupos alcanzado
error.user_synchronization=No se han podido encontrar los siguientes usuarios en Microsoft:
error.users_not_found=No se han encontrado usuarios para este grupo o Microsoft a\u00fan no ha actualizado los datos. Si vuelve a ejecutar la sincronizaci\u00F3n, es posible que se resuelva el problema.
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,4 @@ error.channel_number_more_than_30=Ezin duzu beste kanalik gehitu gailuak dagoene
error.general_failure=General failure
error.channel_number_limit_reached=Channel limitation has been reached
error.user_synchronization=The following users could not be found in Microsoft:
error.users_not_found=No users were found for this group, or Microsoft has not refreshed the data yet. Rerunning synchronization may resolve this issue.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</ul>
</ul>
</div>
<p th:if="${errorMembers == null || row.teamId == null || errorMembers[row.teamId] == null}">No users found for this group.</p>
<p th:if="${errorMembers == null || row.teamId == null || errorMembers[row.teamId] == null}" th:text="#{error.users_not_found}"></p>
</div>
</div>
<div style="color: orange;" th:case="${T(org.sakaiproject.microsoft.api.data.SynchronizationStatus).KO}" th:text="#{status.KO}" />
Expand Down Expand Up @@ -138,7 +138,7 @@
</ul>
</ul>
</div>
<p th:if="${errorGroupMembers[grouprow.groupId] == null}">No users found for this group.</p>
<p th:if="${errorGroupMembers[grouprow.groupId] == null}" th:text="#{error.users_not_found}"></p>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ public boolean addOwnerToChannel(String userId, String teamId, String channelId)
public SynchronizationStatus addUsersToChannel(SiteSynchronization ss, GroupSynchronization gs, List<MicrosoftUser> members, SynchronizationStatus status, LinkedList<String> roles) throws MicrosoftCredentialsException {
String teamId = ss.getTeamId();
String channelId = gs.getChannelId();
boolean res = false;
boolean generalError = false;

ConversationMemberCollectionRequest postMembers = graphClient.teams(teamId).channels(channelId).members()
.buildRequest();
Expand All @@ -1780,12 +1780,12 @@ public SynchronizationStatus addUsersToChannel(SiteSynchronization ss, GroupSync
for (int i = 0; i <= MAX_REQUESTS; i++) {
List<MicrosoftUser> pendingMembers = members.subList(i * MAX_PER_REQUEST, Math.min(MAX_PER_REQUEST * (i +1 ), members.size()));
List<MicrosoftUser> successMembers = new LinkedList<>();

generalError = false;
int retryCount = 0;
while (!pendingMembers.isEmpty() && retryCount < MAX_RETRY) {
BatchRequestContent batchRequestContent = new BatchRequestContent();

members.forEach(member -> {
pendingMembers.forEach(member -> {
ConversationMember memberToAdd = new ConversationMember();

memberToAdd.oDataType = "#microsoft.graph.aadUserConversationMember";
Expand All @@ -1794,18 +1794,28 @@ public SynchronizationStatus addUsersToChannel(SiteSynchronization ss, GroupSync

batchRequestContent.addBatchRequestStep(postMembers, HttpMethod.POST, memberToAdd);
});
BatchResponseContent responseContent;

BatchResponseContent responseContent = getGraphClient().batch().buildRequest().post(batchRequestContent);

HashMap<String, ?> membersResponse = parseBatchResponse(responseContent, members);

successMembers.addAll((List<MicrosoftUser>) membersResponse.get("success"));
pendingMembers = (List<MicrosoftUser>) membersResponse.get("failed");
List<Map<String, ?>> errors = (List<Map<String, ?>>) membersResponse.get("errors");
handleMicrosoftExceptions(errors);
retryCount++;
try {
responseContent = getGraphClient().batch().buildRequest().post(batchRequestContent);
HashMap<String, ?> membersResponse = parseBatchResponse(responseContent, pendingMembers);

successMembers.addAll((List<MicrosoftUser>) membersResponse.get("success"));
pendingMembers = (List<MicrosoftUser>) membersResponse.get("failed");
List<Map<String, ?>> errors = (List<Map<String, ?>>) membersResponse.get("errors");
handleMicrosoftExceptions(errors);
} catch (GraphServiceException e) {
log.debug("Microsoft General error adding members ", e);
generalError = true;
break;
} finally {
retryCount++;
}
}

if(generalError)
continue;

for (MicrosoftUser pendingMember : pendingMembers) {
if (status != SynchronizationStatus.ERROR) {
//once ERROR status is set, do not check it again
Expand Down Expand Up @@ -1853,7 +1863,6 @@ public SynchronizationStatus addUsersToChannel(SiteSynchronization ss, GroupSync

private void handleMicrosoftExceptions(List<Map<String,?>> errors) {
if(!errors.isEmpty()) {

if(errors.stream().anyMatch(e -> e.containsValue(429))) {
Map<String, ?> error = errors.stream().filter(e -> e.containsValue(429)).findFirst().get();
microsoftLoggingRepository.save(MicrosoftLog.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,8 @@ public SynchronizationStatus runSiteSynchronization(SiteSynchronization ss) thro
return ret;
}

List<MicrosoftLog> microsoftLogs = new ArrayList<>();
//save log
microsoftLogs.add(MicrosoftLog.builder()
microsoftLoggingRepository.save(MicrosoftLog.builder()
.event(MicrosoftLog.EVENT_SITE_SYNCRHO_START)
.status(MicrosoftLog.Status.OK)
.addData("siteId", ss.getSiteId())
Expand Down Expand Up @@ -766,21 +765,13 @@ public SynchronizationStatus runSiteSynchronization(SiteSynchronization ss) thro
}
}

} else {
microsoftLoggingRepository.save(MicrosoftLog.builder()
.event(MicrosoftLog.EVENT_SITE_SYNCRHO_END)
.status(MicrosoftLog.Status.KO)
.addData("siteId", ss.getSiteId())
.addData("teamId", ss.getTeamId())
.addData("forced", Boolean.toString(ss.isForced()))
.build());
}
ss.setStatus(ret);
ss.setStatusUpdatedAt(ZonedDateTime.now());
saveOrUpdateSiteSynchronization(ss);

//save log
microsoftLogs.add(MicrosoftLog.builder()
microsoftLoggingRepository.save(MicrosoftLog.builder()
.event(MicrosoftLog.EVENT_SITE_SYNCRHO_END)
.status((ret == SynchronizationStatus.OK) ? MicrosoftLog.Status.OK : MicrosoftLog.Status.KO)
.addData("siteId", ss.getSiteId())
Expand All @@ -789,8 +780,6 @@ public SynchronizationStatus runSiteSynchronization(SiteSynchronization ss) thro
.build());

// save logs to db
microsoftLoggingRepository.save(microsoftLogs);

return ret;
}

Expand Down

0 comments on commit d708d56

Please sign in to comment.