Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grad release 1.19.0 #526

Merged
merged 6 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/build.from.developer.branch.deploy.to.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ env:
MAX_MEM: "1500Mi"
MIN_REPLICAS: "3"
MAX_REPLICAS: "7"
SOAM_KC_REALM_ID: "master"

on:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
Expand Down Expand Up @@ -145,6 +146,16 @@ jobs:
${{ env.BUSINESS_NAMESPACE }} \
${{ secrets.SPLUNK_TOKEN }} \
${{ vars.APP_LOG_LEVEL }}

# UPDATE KC Client
curl -s https://raw.githubusercontent.com/bcgov/${{ env.REPO_NAME }}/${{ env.BRANCH }}/tools/config/update-kc-client.sh \
| bash /dev/stdin \
dev \
${{ env.COMMON_NAMESPACE }} \
${{ env.SOAM_KC_REALM_ID }} \
${{ secrets.CLIENT_ID }} \
${{ env.BRANCH }} \
${{ env.REPO_NAME }}

# Start rollout (if necessary) and follow it
oc rollout latest dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/build.from.main.branch.deploy.to.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ env:
MAX_MEM: "1500Mi"
MIN_REPLICAS: "3"
MAX_REPLICAS: "7"
SOAM_KC_REALM_ID: "master"

on:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
Expand Down Expand Up @@ -127,6 +128,16 @@ jobs:
${{ env.BUSINESS_NAMESPACE }} \
${{ secrets.SPLUNK_TOKEN }} \
${{ vars.APP_LOG_LEVEL }}

# UPDATE KC Client
curl -s https://raw.githubusercontent.com/bcgov/${{ env.REPO_NAME }}/${{ env.BRANCH }}/tools/config/update-kc-client.sh \
| bash /dev/stdin \
dev \
${{ env.COMMON_NAMESPACE }} \
${{ env.SOAM_KC_REALM_ID }} \
${{ secrets.CLIENT_ID }} \
${{ env.BRANCH }} \
${{ env.REPO_NAME }}

# Start rollout (if necessary) and follow it
oc rollout latest dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/build.from.release.branch.deploy.to.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ env:
MAX_MEM: "1500Mi"
MIN_REPLICAS: "3"
MAX_REPLICAS: "7"
SOAM_KC_REALM_ID: "master"

on:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
Expand Down Expand Up @@ -134,6 +135,16 @@ jobs:
${{ env.BUSINESS_NAMESPACE }} \
${{ secrets.SPLUNK_TOKEN }} \
${{ vars.APP_LOG_LEVEL }}

# UPDATE KC Client
curl -s https://raw.githubusercontent.com/bcgov/${{ env.REPO_NAME }}/${{ env.BRANCH }}/tools/config/update-kc-client.sh \
| bash /dev/stdin \
dev \
${{ env.COMMON_NAMESPACE }} \
${{ env.SOAM_KC_REALM_ID }} \
${{ secrets.CLIENT_ID }} \
${{ env.BRANCH }} \
${{ env.REPO_NAME }}

# Start rollout (if necessary) and follow it
oc rollout latest dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/deploy_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ env:
MAX_MEM: "1500Mi"
MIN_REPLICAS: "3"
MAX_REPLICAS: "7"
SOAM_KC_REALM_ID: "master"

on:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
Expand Down Expand Up @@ -83,6 +84,16 @@ jobs:
${{ secrets.SPLUNK_TOKEN }} \
${{ vars.APP_LOG_LEVEL }}

# UPDATE KC Client
curl -s https://raw.githubusercontent.com/bcgov/${{ env.REPO_NAME }}/${{ env.BRANCH }}/tools/config/update-kc-client.sh \
| bash /dev/stdin \
dev \
${{ env.COMMON_NAMESPACE }} \
${{ env.SOAM_KC_REALM_ID }} \
${{ secrets.CLIENT_ID }} \
${{ env.BRANCH }} \
${{ env.REPO_NAME }}

# Start rollout (if necessary) and follow it
oc rollout latest dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
|| true && echo "Rollout in progress"
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ env:
MAX_MEM: "1500Mi"
MIN_REPLICAS: "3"
MAX_REPLICAS: "7"
SOAM_KC_REALM_ID: "master"

on:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
Expand Down Expand Up @@ -83,6 +84,16 @@ jobs:
${{ secrets.SPLUNK_TOKEN }} \
${{ vars.APP_LOG_LEVEL }}

# UPDATE KC Client
curl -s https://raw.githubusercontent.com/bcgov/${{ env.REPO_NAME }}/${{ env.BRANCH }}/tools/config/update-kc-client.sh \
| bash /dev/stdin \
dev \
${{ env.COMMON_NAMESPACE }} \
${{ env.SOAM_KC_REALM_ID }} \
${{ secrets.CLIENT_ID }} \
${{ env.BRANCH }} \
${{ env.REPO_NAME }}

# Start rollout (if necessary) and follow it
oc rollout latest dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
|| true && echo "Rollout in progress"
Expand Down
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-graduation-api</artifactId>
<version>1.8.55</version>
<version>1.8.56</version>
<name>educ-grad-graduation-api</name>
<description>Ministry of Education GRAD GRADUATION API</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager;
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
import org.springframework.security.oauth2.client.web.reactive.function.client.ServletOAuth2AuthorizedClientExchangeFilterFunction;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -18,20 +25,48 @@
@Profile("!test")
public class RestWebClient {

@Autowired
EducGraduationApiConstants constants;

@Autowired
LogHelper logHelper;

private final HttpClient httpClient;
@Autowired
public RestWebClient(EducGraduationApiConstants constants, LogHelper logHelper) {
this.constants = constants;
this.logHelper = logHelper;
}

public RestWebClient() {
this.httpClient = HttpClient.create().compress(true)
.resolver(spec -> spec.queryTimeout(Duration.ofMillis(200)).trace("DNS", LogLevel.TRACE));
this.httpClient.warmup().block();
@Bean("graduationClient")
public WebClient getGraduationClientWebClient(OAuth2AuthorizedClientManager authorizedClientManager) {
ServletOAuth2AuthorizedClientExchangeFilterFunction filter = new ServletOAuth2AuthorizedClientExchangeFilterFunction(authorizedClientManager);
filter.setDefaultClientRegistrationId("graduationclient");
return WebClient.builder()
.exchangeStrategies(ExchangeStrategies
.builder()
.codecs(codecs -> codecs
.defaultCodecs()
.maxInMemorySize(50 * 1024 * 1024))
.build())
.apply(filter.oauth2Configuration())
.filter(this.log())
.build();
}
@Bean
public OAuth2AuthorizedClientManager authorizedClientManager(
ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientRepository authorizedClientRepository) {
OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder()
.clientCredentials()
.build();
DefaultOAuth2AuthorizedClientManager authorizedClientManager = new DefaultOAuth2AuthorizedClientManager(
clientRegistrationRepository, authorizedClientRepository);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
return authorizedClientManager;
}

/**
* Old web client. You can use a @Qualifier('default') to summon it.
* @return
*/
@Bean
public WebClient webClient() {
return WebClient.builder().exchangeStrategies(ExchangeStrategies.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ public void restoreStudentGradStatus(String studentID, String accessToken,boolea

public List<GraduationStudentRecord> getStudentListByMinCode(String schoolOfRecord, String accessToken) {
List<Map> response = this.restService.get(String.format(educGraduationApiConstants.getGradStudentListSchoolReport(),schoolOfRecord),
List.class,
accessToken);
List.class);
return jsonTransformer.convertValue(response, new TypeReference<>(){});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,8 @@ public byte[] getSchoolReports(List<String> uniqueSchoolList, String type, Strin

public Integer createAndStoreSchoolReports(List<String> uniqueSchoolList, String type, String accessToken) {
int numberOfReports = 0;
Pair<String, Long> res = Pair.of(accessToken, System.currentTimeMillis());
ExceptionMessage exception = new ExceptionMessage();
int i = 0;
for (String usl : uniqueSchoolList) {
if (i == 0) {
res = getAccessToken(accessToken);
} else {
res = checkAndGetAccessToken(res);
}
accessToken = res.getLeft();

try {
List<GraduationStudentRecord> stdList = gradStatusService.getStudentListByMinCode(usl, accessToken);
if(logger.isDebugEnabled()) {
Expand All @@ -281,8 +272,6 @@ public Integer createAndStoreSchoolReports(List<String> uniqueSchoolList, String
List<Student> gradRegStudents = processStudentList(filterStudentList(stdList, GRADREG), type);
logger.debug("*** Process processGradRegReport {} for {} students", schoolObj.getMincode(), gradRegStudents.size());
numberOfReports = processGradRegReport(schoolObj, gradRegStudents, usl, accessToken, numberOfReports);
res = checkAndGetAccessToken(res);
accessToken = res.getLeft();
List<Student> nonGradRegStudents = processStudentList(filterStudentList(stdList, NONGRADREG), type);
logger.debug("*** Process processNonGradRegReport {} for {} students", schoolObj.getMincode(), nonGradRegStudents.size());
numberOfReports = processNonGradRegReport(schoolObj, nonGradRegStudents, usl, accessToken, numberOfReports);
Expand All @@ -292,7 +281,6 @@ public Integer createAndStoreSchoolReports(List<String> uniqueSchoolList, String
} catch (Exception e) {
logger.error("Failed to generate {} report for mincode: {} due to: {}", type, usl, e.getLocalizedMessage());
}
i++;
}
return numberOfReports;
}
Expand Down Expand Up @@ -423,8 +411,7 @@ private byte[] getSchoolReportGradRegReport(ReportData data, String mincode, Str

return this.restService.post(educGraduationApiConstants.getSchoolGraduation(),
reportParams,
byte[].class,
accessToken);
byte[].class);

}

Expand All @@ -437,16 +424,15 @@ private byte[] createAndSaveSchoolReportGradRegReport(ReportData data, String mi

SchoolReports requestObj = getSchoolReports(mincode, encodedPdf, GRADREG);

updateSchoolReport(accessToken, requestObj);
updateSchoolReport(requestObj);

return bytesSAR;
}

private void updateSchoolReport(String accessToken, SchoolReports requestObj) {
private void updateSchoolReport(SchoolReports requestObj) {
this.restService.post(educGraduationApiConstants.getUpdateSchoolReport(),
requestObj,
SchoolReports.class,
accessToken);
SchoolReports.class);
}

private String getEncodedPdfFromBytes(byte[] bytesSAR) {
Expand Down Expand Up @@ -474,7 +460,7 @@ private void createAndSaveSchoolReportNonGradRegReport(ReportData data, String m
byte[] bytesSAR = getSchoolReportNonGradRegReport(data, mincode, accessToken);
String encodedPdf = getEncodedPdfFromBytes(bytesSAR);
SchoolReports requestObj = getSchoolReports(mincode, encodedPdf, NONGRADREG);
updateSchoolReport(accessToken, requestObj);
updateSchoolReport(requestObj);
}

private byte[] getSchoolReportStudentNonGradPrjReport(ReportData data, String mincode, String accessToken) {
Expand All @@ -489,8 +475,7 @@ private byte[] getSchoolReportStudentNonGradPrjReport(ReportData data, String mi

return this.restService.post(educGraduationApiConstants.getStudentNonGradProjected(),
reportParams,
byte[].class,
accessToken);
byte[].class);
}

@Generated
Expand All @@ -514,7 +499,7 @@ private void createAndSaveSchoolReportStudentNonGradPrjReport(ReportData data, S
byte[] bytesSAR = getSchoolReportStudentNonGradPrjReport(data, mincode, accessToken);
String encodedPdf = getEncodedPdfFromBytes(bytesSAR);
SchoolReports requestObj = getSchoolReports(mincode, encodedPdf, NONGRADPRJ);
updateSchoolReport(accessToken, requestObj);
updateSchoolReport(requestObj);
}

/**
Expand Down
Loading
Loading