diff --git a/.github/workflows/check-license-header.yml b/.github/workflows/check-license-header.yml index 5f9742646d..f7df8b49a1 100644 --- a/.github/workflows/check-license-header.yml +++ b/.github/workflows/check-license-header.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v2 - - name: Set up JDK 17 + - uses: actions/checkout@v4 + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' # don't use setup-java cache - hash file pattern has issues - name: Cache local Maven repository diff --git a/.github/workflows/helm-tests.yaml b/.github/workflows/helm-tests.yaml index c6c0004c15..e86836543f 100644 --- a/.github/workflows/helm-tests.yaml +++ b/.github/workflows/helm-tests.yaml @@ -20,7 +20,7 @@ jobs: steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Helm uses: azure/setup-helm@v1 @@ -56,4 +56,4 @@ jobs: run: | yq e 'select(.kind == "ConfigMap" and .metadata.name == "thirdeye-worker")' rendered.yaml > worker-configmap.yaml yq e '.data."server.yaml"' worker-configmap.yaml > worker-config.yaml - yq e '.' worker-config.yaml \ No newline at end of file + yq e '.' worker-config.yaml diff --git a/.github/workflows/publish-backend.yaml b/.github/workflows/publish-backend.yaml index f923a15ac9..03bcd60ff4 100644 --- a/.github/workflows/publish-backend.yaml +++ b/.github/workflows/publish-backend.yaml @@ -17,10 +17,10 @@ jobs: steps: - name: Pull repository uses: actions/checkout@v4 - - name: Install JDK 17 + - name: Install JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Cache - restore local Maven repository id: cache-restore diff --git a/.github/workflows/publish-frontend.yaml b/.github/workflows/publish-frontend.yaml index 676b70d223..279c64c1ec 100644 --- a/.github/workflows/publish-frontend.yaml +++ b/.github/workflows/publish-frontend.yaml @@ -29,10 +29,10 @@ jobs: cache: "npm" cache-dependency-path: './thirdeye-ui/package-lock.json' # java is required to get the backend project version with maven - - name: Install JDK 17 + - name: Install JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Generate frontend distribution id: generate-frontend-dist diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index eee9bee17e..f08caae6a2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -66,10 +66,10 @@ jobs: steps: - name: Pull repository uses: actions/checkout@v4 - - name: Install JDK 17 + - name: Install JDK 21 uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: Set git ci user info run: | diff --git a/.github/workflows/run-backend-tests.yml b/.github/workflows/run-backend-tests.yml index beaae70108..d5f1047dac 100644 --- a/.github/workflows/run-backend-tests.yml +++ b/.github/workflows/run-backend-tests.yml @@ -22,11 +22,11 @@ jobs: timeout-minutes: 20 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install java and setup artifactory uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' server-id: startree-releases server-username: ARTIFACTORY_USERNAME_REF diff --git a/Dockerfile b/Dockerfile index 654894aab0..c0759be893 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ # the License. # -FROM eclipse-temurin:17-jdk-alpine as builder +FROM eclipse-temurin:21-jdk-alpine AS builder # build jcmd tools to make them available at runtime RUN ${JAVA_HOME}/bin/jlink --module-path jmods --add-modules jdk.jcmd --output /jcmd WORKDIR /build @@ -21,7 +21,7 @@ COPY ./ ./ # if the disitrbution is provided, do nothing - else build it RUN if [[ ! -d thirdeye-distribution/target/thirdeye-distribution-*-dist/thirdeye-distribution-* ]]; then ./mvnw package -U -DskipTests; fi -FROM eclipse-temurin:17-jre-alpine +FROM eclipse-temurin:21-jre-alpine RUN addgroup -g 1000 thirdeye && \ adduser -u 1000 thirdeye -G thirdeye -D diff --git a/README.md b/README.md index 3e60ef31d7..9b9644ef11 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ For a complete description of ThirdEye's features, see [**ThirdEye documentation ### Requirements - tested on Linux and Mac OS -- Java 17 +- Java 21 - MySQL 8.0 - the UI requires internal npm packages. Make sure you can access them. See [thirdeye-ui prerequisites](./thirdeye-ui/README.md#configure-node-package-manager-npm-for-use-with-artifactory) diff --git a/pom.xml b/pom.xml index d1a395c1e4..1b90863065 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ - 17 + 21 UTF-8 @@ -232,7 +232,7 @@ org.apache.maven.plugins maven-dependency-plugin - 3.3.0 + 3.8.1 resolve diff --git a/thirdeye-benchmarks/pom.xml b/thirdeye-benchmarks/pom.xml index c45ee608ea..8987040b60 100644 --- a/thirdeye-benchmarks/pom.xml +++ b/thirdeye-benchmarks/pom.xml @@ -27,7 +27,7 @@ UTF-8 1.37 - 17 + 21 benchmarks diff --git a/thirdeye-core/src/main/java/ai/startree/thirdeye/datasource/query/QueryProjection.java b/thirdeye-core/src/main/java/ai/startree/thirdeye/datasource/query/QueryProjection.java index 76146e3198..e142e48107 100644 --- a/thirdeye-core/src/main/java/ai/startree/thirdeye/datasource/query/QueryProjection.java +++ b/thirdeye-core/src/main/java/ai/startree/thirdeye/datasource/query/QueryProjection.java @@ -114,7 +114,7 @@ private SqlNode toSqlNode(final Config sqlParserConfig) { SqlParserPos.ZERO, quantifier != null ? symbolLiteralOf(quantifier) : null)); } else if (operands.size() == 1 && quantifier == null) { - return applySpecialOperators(operandNodes(sqlParserConfig).get(0)); + return applySpecialOperators(operandNodes(sqlParserConfig).getFirst()); } else { throw new UnsupportedOperationException(String.format( "Unsupported combination for QueryProjection: %s", diff --git a/thirdeye-core/src/main/java/ai/startree/thirdeye/detectionpipeline/sql/filter/FilterEngine.java b/thirdeye-core/src/main/java/ai/startree/thirdeye/detectionpipeline/sql/filter/FilterEngine.java index 9a97679dff..95d128711c 100644 --- a/thirdeye-core/src/main/java/ai/startree/thirdeye/detectionpipeline/sql/filter/FilterEngine.java +++ b/thirdeye-core/src/main/java/ai/startree/thirdeye/detectionpipeline/sql/filter/FilterEngine.java @@ -105,7 +105,7 @@ private SqlNode injectPredicates(final SqlCall call) { } else if (call.getClass() == SqlOrderBy.class) { final SqlOrderBy orderByNode = (SqlOrderBy) call; // element of index 0 is the select node - selectNode = (SqlSelect) orderByNode.getOperandList().get(0); + selectNode = (SqlSelect) orderByNode.getOperandList().getFirst(); } else if (call.getClass() == SqlWith.class) { final SqlWith withNode = (SqlWith) call; // element of index 1 is the select node - in simple with + select queries diff --git a/thirdeye-core/src/main/java/ai/startree/thirdeye/util/CalciteUtils.java b/thirdeye-core/src/main/java/ai/startree/thirdeye/util/CalciteUtils.java index e7ef4c1113..8643051716 100644 --- a/thirdeye-core/src/main/java/ai/startree/thirdeye/util/CalciteUtils.java +++ b/thirdeye-core/src/main/java/ai/startree/thirdeye/util/CalciteUtils.java @@ -235,9 +235,9 @@ public static SqlNode combinePredicates(final List predicates) { if (predicates.isEmpty()) { return null; } else if (predicates.size() == 1) { - return predicates.get(0); + return predicates.getFirst(); } - return addPredicates(predicates.get(0), predicates.subList(1, predicates.size())); + return addPredicates(predicates.getFirst(), predicates.subList(1, predicates.size())); } /** diff --git a/thirdeye-detectionpipeline/src/test/java/ai/startree/thirdeye/detectionpipeline/operator/PostProcessorOperatorTest.java b/thirdeye-detectionpipeline/src/test/java/ai/startree/thirdeye/detectionpipeline/operator/PostProcessorOperatorTest.java index a7f94f25fa..82a7266228 100644 --- a/thirdeye-detectionpipeline/src/test/java/ai/startree/thirdeye/detectionpipeline/operator/PostProcessorOperatorTest.java +++ b/thirdeye-detectionpipeline/src/test/java/ai/startree/thirdeye/detectionpipeline/operator/PostProcessorOperatorTest.java @@ -154,7 +154,7 @@ public void testPostProcessorOperatorWithCombinerResult() throws Exception { private void assertLabelsAreCorrect(final OperatorResult r) { for (final AnomalyDTO anomaly : r.getAnomalies()) { assertThat(anomaly.getAnomalyLabels().size()).isEqualTo(1); - final AnomalyLabelDTO label = anomaly.getAnomalyLabels().get(0); + final AnomalyLabelDTO label = anomaly.getAnomalyLabels().getFirst(); assertThat(label.getName()).isEqualTo(TEST_POST_PROCESSOR_LABEL_NAME); assertThat(label.getSourceNodeName()).isEqualTo(NODE_BEAN_NAME); assertThat(label.getSourcePostProcessor()).isEqualTo(TEST_POST_PROCESSOR_NAME); diff --git a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/AnomalyPaginationTest.java b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/AnomalyPaginationTest.java index 4378c8b1cc..bb17b50122 100644 --- a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/AnomalyPaginationTest.java +++ b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/AnomalyPaginationTest.java @@ -83,7 +83,7 @@ public void beforeClass() throws Exception { .setLastTimestamp(new Date()) .setTemplate(new AlertTemplateApi().setNodes(List.of(new PlanNodeApi())))))) .readEntity(new GenericType>() {}) - .get(0) + .getFirst() .getId(); final List anomalies = new ArrayList<>(); @@ -144,7 +144,7 @@ public void testNegativeLimitValue() { final StatusListApi results = response.readEntity(ERROR_LIST_TYPE); assertThat(response.getStatus()).isEqualTo(400); assertThat(results.getList()).isNotEmpty(); - assertThat(results.getList().get(0).getCode()).isEqualTo(ERR_NEGATIVE_LIMIT_VALUE); + assertThat(results.getList().getFirst().getCode()).isEqualTo(ERR_NEGATIVE_LIMIT_VALUE); } @Test @@ -153,7 +153,7 @@ public void testNegativeOffsetValue() { final StatusListApi results = response.readEntity(ERROR_LIST_TYPE); assertThat(response.getStatus()).isEqualTo(400); assertThat(results.getList()).isNotEmpty(); - assertThat(results.getList().get(0).getCode()).isEqualTo(ERR_NEGATIVE_OFFSET_VALUE); + assertThat(results.getList().getFirst().getCode()).isEqualTo(ERR_NEGATIVE_OFFSET_VALUE); } @Test @@ -162,7 +162,7 @@ public void testOffsetWithoutLimit() { final StatusListApi results = response.readEntity(ERROR_LIST_TYPE); assertThat(response.getStatus()).isEqualTo(400); assertThat(results.getList()).isNotEmpty(); - assertThat(results.getList().get(0).getCode()).isEqualTo(ERR_OFFSET_WITHOUT_LIMIT); + assertThat(results.getList().getFirst().getCode()).isEqualTo(ERR_OFFSET_WITHOUT_LIMIT); } @Test diff --git a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/AnomalyResolutionTest.java b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/AnomalyResolutionTest.java index 0cb56ca561..4d99fed585 100644 --- a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/AnomalyResolutionTest.java +++ b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/AnomalyResolutionTest.java @@ -137,7 +137,7 @@ public void setUpData() { response = client.request("api/data-sources") .post(Entity.json(List.of(pinotDataSourceApi))); assert200(response); - final DataSourceApi dataSourceInResponse = response.readEntity(DATASOURCE_LIST_TYPE).get(0); + final DataSourceApi dataSourceInResponse = response.readEntity(DATASOURCE_LIST_TYPE).getFirst(); pinotDataSourceApi.setId(dataSourceInResponse.getId()); // create dataset @@ -158,7 +158,7 @@ public void testCreateAlertLastTimestamp() { .post(Entity.json(List.of(ALERT_API))); assertThat(createResponse.getStatus()).isEqualTo(200); final List alerts = createResponse.readEntity(ALERT_LIST_TYPE); - alertId = alerts.get(0).getId(); + alertId = alerts.getFirst().getId(); final AlertDTO alert = alertManager.findById(alertId); final AlertTemplateDTO renderedTemplate = alertTemplateRenderer.renderAlert(alert); @@ -182,7 +182,7 @@ public void testCreateSubscriptionGroup() { try (final Response r = client.request("api/subscription-groups") .post(Entity.json(List.of(SUBSCRIPTION_GROUP_API)))) { assertThat(r.getStatus()).isEqualTo(200); - subscriptionGroupId = r.readEntity(SUBSCRIPTION_GROUP_LIST_TYPE).get(0).getId(); + subscriptionGroupId = r.readEntity(SUBSCRIPTION_GROUP_LIST_TYPE).getFirst().getId(); } } @@ -231,7 +231,7 @@ public void testDailyFeb21() throws InterruptedException { final NotificationPayloadApi notificationPayload = nsf.getNotificationPayload(); assertThat(notificationPayload.getAnomalyReports()).hasSize(1); - final AnomalyApi anomalyApi = notificationPayload.getAnomalyReports().get(0).getAnomaly(); + final AnomalyApi anomalyApi = notificationPayload.getAnomalyReports().getFirst().getAnomaly(); assertThat(anomalyApi.getStartTime()).isEqualTo(new Date(epoch("2020-02-17 00:00"))); assertThat(anomalyApi.getEndTime()).isEqualTo(new Date(epoch("2020-02-21 00:00"))); } @@ -296,7 +296,7 @@ public void testDailyMar4() throws InterruptedException { final NotificationPayloadApi notificationPayload = nsf.getNotificationPayload(); assertThat(notificationPayload.getAnomalyReports()).hasSize(1); - final AnomalyApi anomalyApi = notificationPayload.getAnomalyReports().get(0).getAnomaly(); + final AnomalyApi anomalyApi = notificationPayload.getAnomalyReports().getFirst().getAnomaly(); assertThat(anomalyApi.getStartTime()).isEqualTo(new Date(epoch("2020-03-02 00:00"))); assertThat(anomalyApi.getEndTime()).isEqualTo(new Date(epoch("2020-03-03 00:00"))); } diff --git a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/HappyPathTest.java b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/HappyPathTest.java index 191fff5c79..0a4d04544e 100644 --- a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/HappyPathTest.java +++ b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/HappyPathTest.java @@ -170,7 +170,7 @@ public void testCreatePinotDataSource() { final Response response = request("api/data-sources").post(Entity.json(List.of( pinotDataSourceApi))); assert200(response); - final DataSourceApi dataSourceInResponse = response.readEntity(DATASOURCE_LIST_TYPE).get(0); + final DataSourceApi dataSourceInResponse = response.readEntity(DATASOURCE_LIST_TYPE).getFirst(); pinotDataSourceApi.setId(dataSourceInResponse.getId()); } @@ -268,7 +268,7 @@ public void testCreateAlert() { assert200(response); final List alerts = response.readEntity(ALERT_LIST_TYPE); - alertId = alerts.get(0).getId(); + alertId = alerts.getFirst().getId(); UPDATE_ALERT_API.setId(alertId); } @@ -370,8 +370,8 @@ public void testUpdateAlert() throws InterruptedException { final Response response = request("api/alerts").put(Entity.json(List.of(UPDATE_ALERT_API))); assert200(response); final List alerts = response.readEntity(ALERT_LIST_TYPE); - assertThat(alerts.get(0).getId()).isEqualTo(alertId); - alertLastUpdateTime = alerts.get(0).getUpdated().getTime(); + assertThat(alerts.getFirst().getId()).isEqualTo(alertId); + alertLastUpdateTime = alerts.getFirst().getUpdated().getTime(); } @Test(dependsOnMethods = "testUpdateAlert", timeOut = 50000L) @@ -748,7 +748,7 @@ private long mustCreateAlert(final AlertApi alertApi) { final var response = request("api/alerts") .post(Entity.json(List.of(alertApi))); assertThat(response.getStatus()).isEqualTo(200); - final var gotApi = response.readEntity(new GenericType>() {}).get(0); + final var gotApi = response.readEntity(new GenericType>() {}).getFirst(); assertThat(gotApi).isNotNull(); assertThat(gotApi.getId()).isNotNull(); return gotApi.getId(); @@ -758,7 +758,7 @@ private long mustCreateInvestigation(final RcaInvestigationApi investigationApi) final var response = request("api/rca/investigations") .post(Entity.json(List.of(investigationApi))); assertThat(response.getStatus()).isEqualTo(200); - final var gotApi = response.readEntity(new GenericType>() {}).get(0); + final var gotApi = response.readEntity(new GenericType>() {}).getFirst(); assertThat(gotApi).isNotNull(); assertThat(gotApi.getId()).isNotNull(); return gotApi.getId(); diff --git a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/SchedulingTest.java b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/SchedulingTest.java index 4dbab5228d..06adbf217a 100644 --- a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/SchedulingTest.java +++ b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/SchedulingTest.java @@ -112,7 +112,7 @@ public void setUpData() { response = client.request("api/data-sources") .post(Entity.json(List.of(pinotDataSourceApi))); assert200(response); - final DataSourceApi dataSourceInResponse = response.readEntity(DATASOURCE_LIST_TYPE).get(0); + final DataSourceApi dataSourceInResponse = response.readEntity(DATASOURCE_LIST_TYPE).getFirst(); pinotDataSourceApi.setId(dataSourceInResponse.getId()); // create dataset @@ -133,7 +133,7 @@ public void testCreateAlertLastTimestamp() { .post(Entity.json(List.of(ALERT_API))); assertThat(createResponse.getStatus()).isEqualTo(200); final List alerts = createResponse.readEntity(ALERT_LIST_TYPE); - alertId = alerts.get(0).getId(); + alertId = alerts.getFirst().getId(); // time advancing should not impact lastTimestamp CLOCK.tick(5); diff --git a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/auth/AuthIntegrationTest.java b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/auth/AuthIntegrationTest.java index cb45783ef8..4d69cc6bc2 100644 --- a/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/auth/AuthIntegrationTest.java +++ b/thirdeye-integration-tests/src/test/java/ai/startree/thirdeye/auth/AuthIntegrationTest.java @@ -105,7 +105,7 @@ private void oauthSetup() throws Exception { .issuer(ISSUER) .expirationTime(new Date(System.currentTimeMillis() + 36000000)) .build(); - oAuthToken = String.format("Bearer %s", getToken(jwks.getKeys().get(0), claimsSet)); + oAuthToken = String.format("Bearer %s", getToken(jwks.getKeys().getFirst(), claimsSet)); dir = new File(DIR); dir.mkdir(); diff --git a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/bao/MetricConfigManagerImpl.java b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/bao/MetricConfigManagerImpl.java index 9a9051ba02..c0f73a0121 100644 --- a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/bao/MetricConfigManagerImpl.java +++ b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/bao/MetricConfigManagerImpl.java @@ -43,7 +43,7 @@ public MetricConfigDTO findBy(final String metricName, .stream().filter(d -> Objects.equals(d.namespace(), namespace)).toList(); if (CollectionUtils.isNotEmpty(list)) { // TODO CYRIL behavior is different in AbstractManager#findUniqueByNameAndNamespace --> clarify - return list.get(0); + return list.getFirst(); } return null; } diff --git a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/bao/TaskManagerImpl.java b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/bao/TaskManagerImpl.java index 8cc8fb8e31..0e1bf2acb2 100644 --- a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/bao/TaskManagerImpl.java +++ b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/bao/TaskManagerImpl.java @@ -135,7 +135,7 @@ AND ref_id not in (select ref_id from task_entity where status = 'RUNNING') if (dtos.isEmpty()) { return null; } - return dtos.get(0); + return dtos.getFirst(); } /** diff --git a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/core/EnumerationItemMaintainer.java b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/core/EnumerationItemMaintainer.java index 32098f9056..e76cc48ab8 100644 --- a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/core/EnumerationItemMaintainer.java +++ b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/core/EnumerationItemMaintainer.java @@ -156,7 +156,7 @@ private EnumerationItemDTO findExistingOrCreate(final EnumerationItemDTO source, return source; } else if (matching.size() == 1) { // already exists - return matching.get(0); + return matching.getFirst(); } else { final List ids = matching.stream() .map(EnumerationItemDTO::getId) @@ -166,7 +166,7 @@ private EnumerationItemDTO findExistingOrCreate(final EnumerationItemDTO source, ids); // returning the first item of the list // fixme cyril kept the existing behavior but we should throw an error - the system is in an inconsistent state - return matching.get(0); + return matching.getFirst(); } } diff --git a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/dao/GenericPojoDao.java b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/dao/GenericPojoDao.java index cfa33a5704..96b7e60154 100644 --- a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/dao/GenericPojoDao.java +++ b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/dao/GenericPojoDao.java @@ -265,7 +265,7 @@ public AbstractDTO getRaw(final Long id) { if (genericJsonEntity != null) { return toDto(genericJsonEntity, SubEntities.BEAN_TYPE_MAP.asMultimap().inverse().get( - SubEntityType.valueOf(genericJsonEntity.getType())).asList().get(0)); + SubEntityType.valueOf(genericJsonEntity.getType())).asList().getFirst()); } } catch (final JsonProcessingException | SQLException e) { LOG.error(e.getMessage(), e); diff --git a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/mapper/DtoIndexMapper.java b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/mapper/DtoIndexMapper.java index fff1f1779e..8bf9f496ad 100644 --- a/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/mapper/DtoIndexMapper.java +++ b/thirdeye-persistence/src/main/java/ai/startree/thirdeye/datalayer/mapper/DtoIndexMapper.java @@ -54,19 +54,16 @@ public static AbstractIndexEntity toAbstractIndexEntity( private static AbstractIndexEntity buildAbstractIndexEntity(final E pojo, final Class indexClass) throws InstantiationException, IllegalAccessException { - if (pojo instanceof AnomalyDTO) { - return IndexMapper.INSTANCE.toIndexEntity((AnomalyDTO) pojo); - } else if (pojo instanceof EnumerationItemDTO) { - return IndexMapper.INSTANCE.toIndexEntity((EnumerationItemDTO) pojo); - } else if (pojo instanceof RcaInvestigationDTO) { - return IndexMapper.INSTANCE.toIndexEntity((RcaInvestigationDTO) pojo); - } - - return buildWithLegacyModelMapper(pojo, indexClass); + return switch (pojo) { + case AnomalyDTO obj -> IndexMapper.INSTANCE.toIndexEntity(obj); + case EnumerationItemDTO obj -> IndexMapper.INSTANCE.toIndexEntity(obj); + case RcaInvestigationDTO obj -> IndexMapper.INSTANCE.toIndexEntity(obj); + case null, default -> buildWithLegacyModelMapper(pojo, indexClass); + }; } /** - * TODO spyne remove modelmapper code and dependencies + * TODO cyril remove modelmapper code and dependencies */ private static AbstractIndexEntity buildWithLegacyModelMapper( final E pojo, diff --git a/thirdeye-plugins/thirdeye-bootstrap-open-core/src/main/java/ai/startree/thirdeye/plugins/bootstrap/opencore/CommonProperties.java b/thirdeye-plugins/thirdeye-bootstrap-open-core/src/main/java/ai/startree/thirdeye/plugins/bootstrap/opencore/CommonProperties.java index c1193968ec..44192654b4 100644 --- a/thirdeye-plugins/thirdeye-bootstrap-open-core/src/main/java/ai/startree/thirdeye/plugins/bootstrap/opencore/CommonProperties.java +++ b/thirdeye-plugins/thirdeye-bootstrap-open-core/src/main/java/ai/startree/thirdeye/plugins/bootstrap/opencore/CommonProperties.java @@ -38,7 +38,7 @@ private Map nameToProperty() { final TemplatePropertyMetadata[] commonProperties = readJsonObjectsFromResourcesFolder( COMMON_PROPERTIES_PATH, this.getClass(), - TemplatePropertyMetadata[].class).get(0); + TemplatePropertyMetadata[].class).getFirst(); NAME_TO_PROPERTY = Arrays.stream(commonProperties) .collect(Collectors.toMap(TemplatePropertyMetadata::getName, e -> e)); } diff --git a/thirdeye-plugins/thirdeye-pinot/src/main/java/ai/startree/thirdeye/plugins/datasource/pinot/PinotSqlExpressionBuilder.java b/thirdeye-plugins/thirdeye-pinot/src/main/java/ai/startree/thirdeye/plugins/datasource/pinot/PinotSqlExpressionBuilder.java index 9b0c4bd095..92f5bb617e 100644 --- a/thirdeye-plugins/thirdeye-pinot/src/main/java/ai/startree/thirdeye/plugins/datasource/pinot/PinotSqlExpressionBuilder.java +++ b/thirdeye-plugins/thirdeye-pinot/src/main/java/ai/startree/thirdeye/plugins/datasource/pinot/PinotSqlExpressionBuilder.java @@ -176,7 +176,7 @@ public String getCustomDialectSql(final MetricAggFunction metricAggFunction, checkArgument(operands.size() == 1, "Incorrect number of operands for percentile sql generation. Expected: 1. Got: %s", operands.size()); - return PERCENTILE_TDIGEST_PREFIX + "(" + operands.get(0) + "," + percentile + ")"; + return PERCENTILE_TDIGEST_PREFIX + "(" + operands.getFirst() + "," + percentile + ")"; default: throw new UnsupportedOperationException(); } diff --git a/thirdeye-plugins/thirdeye-postprocessors/src/main/java/ai/startree/thirdeye/plugins/postprocessor/AnomalyMergerPostProcessor.java b/thirdeye-plugins/thirdeye-postprocessors/src/main/java/ai/startree/thirdeye/plugins/postprocessor/AnomalyMergerPostProcessor.java index cff14a39c6..e622e6a113 100644 --- a/thirdeye-plugins/thirdeye-postprocessors/src/main/java/ai/startree/thirdeye/plugins/postprocessor/AnomalyMergerPostProcessor.java +++ b/thirdeye-plugins/thirdeye-postprocessors/src/main/java/ai/startree/thirdeye/plugins/postprocessor/AnomalyMergerPostProcessor.java @@ -428,9 +428,8 @@ private Set vanishedAnomalies(final List operatorAnomali .filter(a -> !hasOutdatedLabel(a)) .sorted(COMPARATOR) .toList(); - final AnomalyDTO firstChildren = sortedNotOutdatedChildren.get(0); - final AnomalyDTO lastChildren = sortedNotOutdatedChildren.get( - sortedNotOutdatedChildren.size() - 1); + final AnomalyDTO firstChildren = sortedNotOutdatedChildren.getFirst(); + final AnomalyDTO lastChildren = sortedNotOutdatedChildren.getLast(); existingAnomaly.setStartTime(firstChildren.getStartTime()); updateAnomalyWithNewValues(existingAnomaly, firstChildren); final List> notOutdatedLabels = sortedNotOutdatedChildren.stream() diff --git a/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/ColdStartPostProcessorTest.java b/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/ColdStartPostProcessorTest.java index 54cf2cfa06..37ccfe0be8 100644 --- a/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/ColdStartPostProcessorTest.java +++ b/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/ColdStartPostProcessorTest.java @@ -111,10 +111,10 @@ public void testPostProcess28DaysColdStart() throws Exception { assertThat(resultMap).hasSize(2); final List res1Anomalies = resultMap.get(RES_1_KEY).getAnomalies(); assertThat(res1Anomalies).hasSize(2); - final AnomalyDTO firstAnomaly = res1Anomalies.get(0); + final AnomalyDTO firstAnomaly = res1Anomalies.getFirst(); // first anomaly is in cold start zone assertThat(firstAnomaly.getAnomalyLabels()).hasSize(1); - final AnomalyLabelDTO label = firstAnomaly.getAnomalyLabels().get(0); + final AnomalyLabelDTO label = firstAnomaly.getAnomalyLabels().getFirst(); assertThat(label.getName()).isEqualTo(labelName(Period.days(28))); assertThat(label.isIgnore()).isTrue(); // second anomaly is out of cold start zone @@ -123,10 +123,10 @@ public void testPostProcess28DaysColdStart() throws Exception { final List res2Anomalies = resultMap.get(RES_2_KEY).getAnomalies(); assertThat(res2Anomalies).hasSize(1); - final AnomalyDTO res2SingleAnomaly = res2Anomalies.get(0); + final AnomalyDTO res2SingleAnomaly = res2Anomalies.getFirst(); // first anomaly is in cold start zone assertThat(res2SingleAnomaly.getAnomalyLabels()).hasSize(1); - final AnomalyLabelDTO res2Label = res2SingleAnomaly.getAnomalyLabels().get(0); + final AnomalyLabelDTO res2Label = res2SingleAnomaly.getAnomalyLabels().getFirst(); assertThat(res2Label.getName()).isEqualTo(labelName(Period.days(28))); assertThat(res2Label.isIgnore()).isTrue(); } @@ -143,8 +143,8 @@ public void testPostProcess28DaysColdStartIgnoreFalse() throws Exception { postProcessor.postProcess(UTC_DETECTION_INTERVAL, resultMap); final List res1Anomalies = resultMap.get(RES_1_KEY).getAnomalies(); - final AnomalyDTO firstAnomaly = res1Anomalies.get(0); - final AnomalyLabelDTO label = firstAnomaly.getAnomalyLabels().get(0); + final AnomalyDTO firstAnomaly = res1Anomalies.getFirst(); + final AnomalyLabelDTO label = firstAnomaly.getAnomalyLabels().getFirst(); assertThat(label.isIgnore()).isFalse(); } @@ -167,7 +167,7 @@ public void testPostProcess28DaysColdStartAnomaliesWithExistingLabels() throws E postProcessor.postProcess(UTC_DETECTION_INTERVAL, resultMap); final List res1Anomalies = resultMap.get(RES_1_KEY).getAnomalies(); - final AnomalyDTO firstAnomaly = res1Anomalies.get(0); + final AnomalyDTO firstAnomaly = res1Anomalies.getFirst(); final List labels = firstAnomaly.getAnomalyLabels(); assertThat(labels).hasSize(2); final AnomalyLabelDTO label1 = labels.get(0); diff --git a/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/EventPostProcessorTest.java b/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/EventPostProcessorTest.java index 4cde966d0e..828f61399c 100644 --- a/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/EventPostProcessorTest.java +++ b/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/EventPostProcessorTest.java @@ -183,7 +183,7 @@ public void testPostProcessWithEvent(final long eventStart, final long eventEnd, final List labels = res1Anomalies.get(i).getAnomalyLabels(); if (expectedIsLabeled) { assertThat(labels).hasSize(1); - final AnomalyLabelDTO label = labels.get(0); + final AnomalyLabelDTO label = labels.getFirst(); assertThat(label.isIgnore()).isEqualTo(isIgnore); assertThat(label.getName()).isEqualTo("Anomaly happens during " + eventName + " event"); } else { diff --git a/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/ThresholdPostProcessorTest.java b/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/ThresholdPostProcessorTest.java index 7b13d5d046..bb6a235e31 100644 --- a/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/ThresholdPostProcessorTest.java +++ b/thirdeye-plugins/thirdeye-postprocessors/src/test/java/ai/startree/thirdeye/plugins/postprocessor/ThresholdPostProcessorTest.java @@ -121,7 +121,7 @@ public void testPostProcessWithDefaultInput(final boolean ignoreMode, final doub if (isLabeled) { final List anomalyLabels = anomaly.getAnomalyLabels(); assertThat(anomalyLabels).hasSize(1); - final AnomalyLabelDTO label = anomalyLabels.get(0); + final AnomalyLabelDTO label = anomalyLabels.getFirst(); assertThat(label.isIgnore()).isEqualTo(ignoreMode); assertThat(label.getName()).isEqualTo(labelName(min, max, metric1)); } else { @@ -211,7 +211,7 @@ public void testPostProcessWithCustomInput(final @Nullable String timestampColum if (isLabeled) { final List anomalyLabels = anomaly.getAnomalyLabels(); assertThat(anomalyLabels).hasSize(1); - final AnomalyLabelDTO label = anomalyLabels.get(0); + final AnomalyLabelDTO label = anomalyLabels.getFirst(); assertThat(label.isIgnore()).isEqualTo(true); assertThat(label.getName()).isEqualTo(labelName(min, max, metric1)); } else { diff --git a/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/DetectionCronScheduler.java b/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/DetectionCronScheduler.java index 03001e7731..ebef78de99 100644 --- a/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/DetectionCronScheduler.java +++ b/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/DetectionCronScheduler.java @@ -191,7 +191,7 @@ public String getJobKey(final Long id, final TaskType taskType) { @SuppressWarnings("unchecked") private boolean isJobUpdated(final AlertDTO config, final JobKey key) throws SchedulerException { final List triggers = (List) scheduler.getTriggersOfJob(key); - final CronTrigger cronTrigger = (CronTrigger) triggers.get(0); + final CronTrigger cronTrigger = (CronTrigger) triggers.getFirst(); final String cronInSchedule = cronTrigger.getCronExpression(); if (!config.getCron().equals(cronInSchedule)) { diff --git a/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/SubscriptionCronScheduler.java b/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/SubscriptionCronScheduler.java index 9a319538e5..1d80ac0205 100644 --- a/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/SubscriptionCronScheduler.java +++ b/thirdeye-scheduler/src/main/java/ai/startree/thirdeye/scheduler/SubscriptionCronScheduler.java @@ -195,7 +195,7 @@ private void updateJobIfNecessary(final JobKey jobKey, final String cron) throws SchedulerException { final List triggers = scheduler.getTriggersOfJob(jobKey); if (!triggers.isEmpty()) { - final CronTrigger cronTrigger = (CronTrigger) triggers.get(0); + final CronTrigger cronTrigger = (CronTrigger) triggers.getFirst(); final String currentCron = cronTrigger.getCronExpression(); if (!currentCron.equals(cron)) { stopJob(jobKey); diff --git a/thirdeye-server/src/main/java/ai/startree/thirdeye/service/CrudService.java b/thirdeye-server/src/main/java/ai/startree/thirdeye/service/CrudService.java index 153d009ae4..ee071939b0 100644 --- a/thirdeye-server/src/main/java/ai/startree/thirdeye/service/CrudService.java +++ b/thirdeye-server/src/main/java/ai/startree/thirdeye/service/CrudService.java @@ -112,7 +112,7 @@ public List createMultiple(final ThirdEyePrincipal principal, .map(this::toApi) .collect(Collectors.toList()); if (!result.isEmpty()) { - authorizationManager.invalidateCache(result.get(0).namespace(), result.get(0).getClass()); + authorizationManager.invalidateCache(result.getFirst().namespace(), result.getFirst().getClass()); } return result; } @@ -127,7 +127,7 @@ public List editMultiple(final ThirdEyeServerPrincipal principal, .map(this::toApi) .collect(Collectors.toList()); if (!result.isEmpty()) { - authorizationManager.invalidateCache(result.get(0).namespace(), result.get(0).getClass()); + authorizationManager.invalidateCache(result.getFirst().namespace(), result.getFirst().getClass()); } return result; } @@ -218,7 +218,7 @@ public void deleteAll(final ThirdEyeServerPrincipal principal) { LOG.warn("Deleted id: {} by principal: {}", dto.getId(), principal.getName()); } if (!entities.isEmpty()) { - authorizationManager.invalidateCache(namespace, entities.get(0).getClass()); + authorizationManager.invalidateCache(namespace, entities.getFirst().getClass()); } } diff --git a/thirdeye-server/src/main/java/ai/startree/thirdeye/service/EventService.java b/thirdeye-server/src/main/java/ai/startree/thirdeye/service/EventService.java index 99bcbf0cc8..0c13fd6cda 100644 --- a/thirdeye-server/src/main/java/ai/startree/thirdeye/service/EventService.java +++ b/thirdeye-server/src/main/java/ai/startree/thirdeye/service/EventService.java @@ -91,6 +91,6 @@ public EventApi createFromAnomaly(final ThirdEyePrincipal principal, long anomal LOG.error("Failed to create event from an anomaly. List of created entities is not of size 1. Returned list: {}", created); throw new RuntimeException("Failed to create event from anomaly. Number of anomalies created: " + created.size()); } - return created.get(0); + return created.getFirst(); } } diff --git a/thirdeye-server/src/test/java/ai/startree/thirdeye/alert/EvaluationContextProcessorTest.java b/thirdeye-server/src/test/java/ai/startree/thirdeye/alert/EvaluationContextProcessorTest.java index f548455963..09658ea6cf 100644 --- a/thirdeye-server/src/test/java/ai/startree/thirdeye/alert/EvaluationContextProcessorTest.java +++ b/thirdeye-server/src/test/java/ai/startree/thirdeye/alert/EvaluationContextProcessorTest.java @@ -62,6 +62,6 @@ public void testInjectFilters() { assertThat(res.getPredicates()).isNotNull(); assertThat(res.getPredicates().size()).isEqualTo(1); - assertThat(res.getPredicates().get(0)).isEqualTo(new Predicate("browser", OPER.EQ, "chrome")); + assertThat(res.getPredicates().getFirst()).isEqualTo(new Predicate("browser", OPER.EQ, "chrome")); } } diff --git a/thirdeye-server/src/test/java/ai/startree/thirdeye/resources/CrudResourceTest.java b/thirdeye-server/src/test/java/ai/startree/thirdeye/resources/CrudResourceTest.java index e0d364c96c..f683bc0a46 100644 --- a/thirdeye-server/src/test/java/ai/startree/thirdeye/resources/CrudResourceTest.java +++ b/thirdeye-server/src/test/java/ai/startree/thirdeye/resources/CrudResourceTest.java @@ -71,7 +71,7 @@ public void createUserInfoTest() { new ThirdEyeAuthorizerProvider.AlwaysAllowAuthorizer(Map.of())); final List emails = List.of("tester1@testing.com", "tester2@testing.com"); - final ThirdEyeServerPrincipal owner = getPrincipal(emails.get(0)); + final ThirdEyeServerPrincipal owner = getPrincipal(emails.getFirst()); final DummyApi api = new DummyApi().setData("testData"); final Timestamp before = new Timestamp(1671476530000L); @@ -80,9 +80,9 @@ public void createUserInfoTest() { assertThat(response).isNotNull(); assertThat(response.isEmpty()).isFalse(); - final DummyApi responseApi = response.get(0); - assertThat(responseApi.getCreatedBy()).isEqualTo(emails.get(0)); - assertThat(responseApi.getUpdatedBy()).isEqualTo(emails.get(0)); + final DummyApi responseApi = response.getFirst(); + assertThat(responseApi.getCreatedBy()).isEqualTo(emails.getFirst()); + assertThat(responseApi.getUpdatedBy()).isEqualTo(emails.getFirst()); assertThat(responseApi.getCreateTime().after(before)).isTrue(); assertThat(responseApi.getCreateTime()).isEqualTo(responseApi.getUpdateTime()); } @@ -119,7 +119,7 @@ public void updateUserInfoTest() { assertThat(response).isNotNull(); assertThat(response.isEmpty()).isFalse(); - final DummyApi responseApi = response.get(0); + final DummyApi responseApi = response.getFirst(); assertThat(responseApi.getData()).isEqualTo("updateTestData"); assertThat(responseApi.getCreatedBy()).isEqualTo(owner.getName()); assertThat(responseApi.getUpdatedBy()).isEqualTo(updater.getName()); @@ -166,7 +166,7 @@ public void testGetAll_withPartialAccess() { final List entities = ((Stream) resp.getEntity()).collect( Collectors.toList()); assertThat(1).isEqualTo(entities.size()); - assertThat(2L).isEqualTo(entities.get(0).getId()); + assertThat(2L).isEqualTo(entities.getFirst().getId()); } } diff --git a/thirdeye-server/src/test/java/ai/startree/thirdeye/resources/DataSourceResourceTest.java b/thirdeye-server/src/test/java/ai/startree/thirdeye/resources/DataSourceResourceTest.java index e560405ca8..fde0c2809f 100644 --- a/thirdeye-server/src/test/java/ai/startree/thirdeye/resources/DataSourceResourceTest.java +++ b/thirdeye-server/src/test/java/ai/startree/thirdeye/resources/DataSourceResourceTest.java @@ -105,7 +105,7 @@ public void testValidateFailure() { assertThat(entity.getList()).isNotNull(); assertThat(entity.getList().isEmpty()).isFalse(); - final StatusApi statusApi = entity.getList().get(0); + final StatusApi statusApi = entity.getList().getFirst(); assertThat(statusApi.getCode()).isEqualTo(ThirdEyeStatus.ERR_DATASOURCE_VALIDATION_FAILED); } diff --git a/thirdeye-spi/pom.xml b/thirdeye-spi/pom.xml index 963aaa2f60..ed623a92a1 100644 --- a/thirdeye-spi/pom.xml +++ b/thirdeye-spi/pom.xml @@ -27,6 +27,7 @@ thirdeye-spi http://maven.apache.org +