Skip to content

Commit

Permalink
Upgrade dependency version, apply spotless formatter, checkstyle and …
Browse files Browse the repository at this point in the history
…enable jacoco test coverage. (opensearch-project#39)

* Upgrade opensearch from beta1 to rc1
* Add code formatter, checkstyle and spotless to ml plugin.
* Apply spotless formatter to source code, and enable jacoco test coverage
verification

Signed-off-by: Alex <[email protected]>

Co-authored-by: Alex <[email protected]>
  • Loading branch information
2 people authored and jackiehanyang committed Nov 16, 2021
1 parent 851d49e commit 6f8e46c
Show file tree
Hide file tree
Showing 45 changed files with 902 additions and 567 deletions.
362 changes: 362 additions & 0 deletions .eclipseformat.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/CI-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
with:
repository: 'opensearch-project/OpenSearch'
path: OpenSearch
ref: 1.0.0-beta1
ref: '1.x'

- name: Build OpenSearch
working-directory: ./OpenSearch
run: ./gradlew publishToMavenLocal -Dbuild.version_qualifier=beta1 -Dbuild.snapshot=false
run: ./gradlew publishToMavenLocal -Dbuild.version_qualifier=rc1 -Dbuild.snapshot=false

- name: Build with Gradle
run: ./gradlew build
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
ext {
ext {
opensearch_group = "org.opensearch"
opensearch_version = "1.0.0-beta1"
opensearch_version = "1.0.0-rc1"
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
#
#

opensearch_version=1.0.0-beta1
opensearch_version=1.0.0-rc1
opensearchBaseVersion=1.0.0
40 changes: 36 additions & 4 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ plugins {
id 'nebula.ospackage'
id "io.freefair.lombok"
id 'jacoco'
id "com.diffplug.gradle.spotless" version "3.26.1"
id 'checkstyle'
}
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.testclusters'
Expand All @@ -40,6 +42,7 @@ dependencies {
compile("com.fasterxml.jackson.core:jackson-databind:${versions.jackson}")
compile group: 'com.google.guava', name: 'guava', version:'29.0-jre'

checkstyle "com.puppycrawl.tools:checkstyle:${project.checkstyle.toolVersion}"
}

test {
Expand Down Expand Up @@ -94,18 +97,34 @@ jacocoTestReport {
dependsOn test
}

List<String> jacocoExclusions = [
// TODO: add more unit test to meet the minimal test coverage.
'org.opensearch.ml.action.*',
'org.opensearch.ml.constant.CommonValue',
'org.opensearch.ml.indices.MLInputDatasetHandler',
'org.opensearch.ml.plugin.*',
'org.opensearch.ml.task.MLTaskRunner',
]

jacocoTestCoverageVerification {
violationRules {
rule {
limit {
counter = 'LINE'
minimum = 0.7
}
element = 'CLASS'
excludes = jacocoExclusions
limit {
counter = 'BRANCH'
minimum = 0.8
}
}
rule {
element = 'CLASS'
excludes = jacocoExclusions
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.7
}
}
}
dependsOn jacocoTestReport
}
Expand All @@ -115,4 +134,17 @@ configurations.all {
resolutionStrategy.force 'junit:junit:4.12'
resolutionStrategy.force 'org.apache.commons:commons-lang3:3.10'
resolutionStrategy.force 'commons-logging:commons-logging:1.2'
}

spotless {
java {
removeUnusedImports()
importOrder 'java', 'javax', 'org', 'com'

eclipse().configFile rootProject.file('.eclipseformat.xml')
}
}

checkstyle {
toolVersion = '8.29'
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

package org.opensearch.ml.action.prediction;

import org.opensearch.ml.common.transport.prediction.MLPredictionTaskResponse;
import org.opensearch.action.ActionType;
import org.opensearch.ml.common.transport.prediction.MLPredictionTaskResponse;

public class MLPredictionTaskExecutionAction extends ActionType<MLPredictionTaskResponse> {
public static MLPredictionTaskExecutionAction INSTANCE = new MLPredictionTaskExecutionAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

package org.opensearch.ml.action.prediction;

import org.opensearch.ml.task.MLTaskRunner;
import org.opensearch.ml.common.transport.prediction.MLPredictionTaskRequest;
import org.opensearch.ml.common.transport.prediction.MLPredictionTaskResponse;
import org.opensearch.action.ActionListener;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.HandledTransportAction;
import org.opensearch.common.inject.Inject;
import org.opensearch.ml.common.transport.prediction.MLPredictionTaskRequest;
import org.opensearch.ml.common.transport.prediction.MLPredictionTaskResponse;
import org.opensearch.ml.task.MLTaskRunner;
import org.opensearch.tasks.Task;
import org.opensearch.transport.TransportService;

Expand All @@ -28,9 +28,9 @@ public class MLPredictionTaskExecutionTransportAction extends HandledTransportAc

@Inject
public MLPredictionTaskExecutionTransportAction(
ActionFilters actionFilters,
TransportService transportService,
MLTaskRunner mlTaskRunner
ActionFilters actionFilters,
TransportService transportService,
MLTaskRunner mlTaskRunner
) {
super(MLPredictionTaskExecutionAction.NAME, transportService, actionFilters, MLPredictionTaskRequest::new);
this.mlTaskRunner = mlTaskRunner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.AccessLevel;
import lombok.experimental.FieldDefaults;
import lombok.extern.log4j.Log4j2;

import org.opensearch.action.ActionListener;
import org.opensearch.action.ActionRequest;
import org.opensearch.action.support.ActionFilters;
Expand All @@ -41,8 +42,7 @@ public TransportPredictionTaskAction(TransportService transportService, ActionFi
}

@Override
protected void doExecute(Task task, ActionRequest request,
ActionListener<MLPredictionTaskResponse> listener) {
protected void doExecute(Task task, ActionRequest request, ActionListener<MLPredictionTaskResponse> listener) {
MLPredictionTaskRequest mlPredictionTaskRequest = MLPredictionTaskRequest.fromActionRequest(request);
mlTaskRunner.runPrediction(mlPredictionTaskRequest, transportService, listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
*
*/


package org.opensearch.ml.action.stats;

import java.io.IOException;

import lombok.Getter;

import org.opensearch.action.support.nodes.BaseNodeRequest;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;

import java.io.IOException;

public class MLStatsNodeRequest extends BaseNodeRequest {
@Getter
private MLStatsNodesRequest mlStatsNodesRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
*
*/


package org.opensearch.ml.action.stats;

import java.io.IOException;
import java.util.Map;

import lombok.Getter;

import org.opensearch.action.support.nodes.BaseNodeResponse;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.ToXContentFragment;
import org.opensearch.common.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Map;

public class MLStatsNodeResponse extends BaseNodeResponse implements ToXContentFragment {
@Getter
private Map<String, Object> statsMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
*
*/


package org.opensearch.ml.action.stats;

import org.opensearch.ml.constant.CommonValue;
import org.opensearch.action.ActionType;
import org.opensearch.ml.constant.CommonValue;

public class MLStatsNodesAction extends ActionType<MLStatsNodesResponse> {
// Internal Action which is not used for public facing RestAPIs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
*
*/


package org.opensearch.ml.action.stats;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

import lombok.Getter;

import org.opensearch.action.support.nodes.BaseNodesRequest;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class MLStatsNodesRequest extends BaseNodesRequest<MLStatsNodesRequest> {
/**
* Key indicating all stats should be retrieved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
*
*/


package org.opensearch.ml.action.stats;

import java.io.IOException;
import java.util.List;

import org.opensearch.action.FailedNodeException;
import org.opensearch.action.support.nodes.BaseNodesResponse;
import org.opensearch.cluster.ClusterName;
Expand All @@ -22,9 +24,6 @@
import org.opensearch.common.xcontent.ToXContentObject;
import org.opensearch.common.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.List;

public class MLStatsNodesResponse extends BaseNodesResponse<MLStatsNodeResponse> implements ToXContentObject {
private static final String NODES_KEY = "nodes";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@
*
*/


package org.opensearch.ml.action.stats;

import org.opensearch.ml.stats.InternalStatNames;
import org.opensearch.ml.stats.MLStats;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.opensearch.action.FailedNodeException;
import org.opensearch.action.support.ActionFilters;
import org.opensearch.action.support.nodes.TransportNodesAction;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.inject.Inject;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.ml.stats.InternalStatNames;
import org.opensearch.ml.stats.MLStats;
import org.opensearch.monitor.jvm.JvmService;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.TransportService;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MLStatsNodesTransportAction extends
TransportNodesAction<MLStatsNodesRequest, MLStatsNodesResponse, MLStatsNodeRequest, MLStatsNodeResponse> {
TransportNodesAction<MLStatsNodesRequest, MLStatsNodesResponse, MLStatsNodeRequest, MLStatsNodeResponse> {
private MLStats mlStats;
private final JvmService jvmService;

Expand All @@ -48,33 +47,33 @@ public class MLStatsNodesTransportAction extends
*/
@Inject
public MLStatsNodesTransportAction(
ThreadPool threadPool,
ClusterService clusterService,
TransportService transportService,
ActionFilters actionFilters,
MLStats mlStats,
JvmService jvmService
ThreadPool threadPool,
ClusterService clusterService,
TransportService transportService,
ActionFilters actionFilters,
MLStats mlStats,
JvmService jvmService
) {
super(
MLStatsNodesAction.NAME,
threadPool,
clusterService,
transportService,
actionFilters,
MLStatsNodesRequest::new,
MLStatsNodeRequest::new,
ThreadPool.Names.MANAGEMENT,
MLStatsNodeResponse.class
MLStatsNodesAction.NAME,
threadPool,
clusterService,
transportService,
actionFilters,
MLStatsNodesRequest::new,
MLStatsNodeRequest::new,
ThreadPool.Names.MANAGEMENT,
MLStatsNodeResponse.class
);
this.mlStats = mlStats;
this.jvmService = jvmService;
}

@Override
protected MLStatsNodesResponse newResponse(
MLStatsNodesRequest request,
List<MLStatsNodeResponse> responses,
List<FailedNodeException> failures
MLStatsNodesRequest request,
List<MLStatsNodeResponse> responses,
List<FailedNodeException> failures
) {
return new MLStatsNodesResponse(clusterService.getClusterName(), responses, failures);
}
Expand Down Expand Up @@ -112,4 +111,3 @@ private MLStatsNodeResponse createMLStatsNodeResponse(MLStatsNodesRequest mlStat
return new MLStatsNodeResponse(clusterService.localNode(), statValues);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

package org.opensearch.ml.action.training;

import org.opensearch.ml.common.transport.training.MLTrainingTaskResponse;
import org.opensearch.action.ActionType;
import org.opensearch.ml.common.transport.training.MLTrainingTaskResponse;

public class MLTrainingTaskExecutionAction extends ActionType<MLTrainingTaskResponse> {

Expand Down
Loading

0 comments on commit 6f8e46c

Please sign in to comment.