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

Apply auto code formating rules only on changed files, add transform as 1st user #48347

Closed
wants to merge 3 commits into from
Closed
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
32 changes: 32 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
}
String elasticLicenseUrl = "https://raw.githubusercontent.com/elastic/elasticsearch/${licenseCommit}/licenses/ELASTIC-LICENSE.txt"

// Get list of all changed files by project
List<String> getChangedFilesByProject(Project project) {
ByteArrayOutputStream systemOutStream = new ByteArrayOutputStream()

String ghprbTargetBranch = System.getenv("ghprbTargetBranch")
String targetBranch = ghprbTargetBranch ? "origin/${ghprbTargetBranch}" : "master"
String projectDir = project.getRootDir().toPath().relativize(project.getProjectDir().toPath())
String command = "git diff --relative=" + projectDir + " --name-only --diff-filter=ACMRT " + targetBranch

command.execute().waitForProcessOutput(systemOutStream, System.err)
List<String> changedFiles = systemOutStream.toString().trim().split('\n')
systemOutStream.close()
List<String> changedJavaFiles = new ArrayList<>()
for (f in changedFiles) {
if (f.endsWith(".java")) {
changedJavaFiles.add(f)
}
}
return changedJavaFiles
}

subprojects {
// Default to the apache license
project.ext.licenseName = 'The Apache Software License, Version 2.0'
Expand Down Expand Up @@ -107,13 +128,24 @@ subprojects {
// switched to an exclude list, and eventualy removed completely.
def projectPathsToFormat = [
// ':build-tools'
':x-pack:plugin:transform'
]

if (projectPathsToFormat.contains(project.path)) {
project.apply plugin: "com.diffplug.gradle.spotless"

List<String> changedFiles = getChangedFilesByProject(project)

println "[" + project.path + "] Check formating of: " + changedFiles
if (changedFiles.isEmpty()) {
return
}

spotless {
java {
target project.fileTree('.') {
includes = changedFiles
}

removeUnusedImports()
eclipse().configFile rootProject.file('.eclipseformat.xml')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,36 +132,44 @@ public Transform(Settings settings) {
this.enabled = XPackSettings.TRANSFORM_ENABLED.get(settings);
}

protected XPackLicenseState getLicenseState() { return XPackPlugin.getSharedLicenseState(); }
protected XPackLicenseState getLicenseState() {
return XPackPlugin.getSharedLicenseState();
}

@Override
public List<RestHandler> getRestHandlers(final Settings settings, final RestController restController,
final ClusterSettings clusterSettings, final IndexScopedSettings indexScopedSettings, final SettingsFilter settingsFilter,
final IndexNameExpressionResolver indexNameExpressionResolver, final Supplier<DiscoveryNodes> nodesInCluster) {
public List<RestHandler> getRestHandlers(
final Settings settings,
final RestController restController,
final ClusterSettings clusterSettings,
final IndexScopedSettings indexScopedSettings,
final SettingsFilter settingsFilter,
final IndexNameExpressionResolver indexNameExpressionResolver,
final Supplier<DiscoveryNodes> nodesInCluster
) {

if (!enabled) {
return emptyList();
}

return Arrays.asList(
new RestPutTransformAction(restController),
new RestStartTransformAction(restController),
new RestStopTransformAction(restController),
new RestDeleteTransformAction(restController),
new RestGetTransformAction(restController),
new RestGetTransformStatsAction(restController),
new RestPreviewTransformAction(restController),
new RestUpdateTransformAction(restController),
new RestPutTransformAction(restController),
new RestStartTransformAction(restController),
new RestStopTransformAction(restController),
new RestDeleteTransformAction(restController),
new RestGetTransformAction(restController),
new RestGetTransformStatsAction(restController),
new RestPreviewTransformAction(restController),
new RestUpdateTransformAction(restController),

// deprecated endpoints, to be removed for 8.0.0
new RestPutTransformActionDeprecated(restController),
new RestStartTransformActionDeprecated(restController),
new RestStopTransformActionDeprecated(restController),
new RestDeleteTransformActionDeprecated(restController),
new RestGetTransformActionDeprecated(restController),
new RestGetTransformStatsActionDeprecated(restController),
new RestPreviewTransformActionDeprecated(restController),
new RestUpdateTransformActionDeprecated(restController)
// deprecated endpoints, to be removed for 8.0.0
new RestPutTransformActionDeprecated(restController),
new RestStartTransformActionDeprecated(restController),
new RestStopTransformActionDeprecated(restController),
new RestDeleteTransformActionDeprecated(restController),
new RestGetTransformActionDeprecated(restController),
new RestGetTransformStatsActionDeprecated(restController),
new RestPreviewTransformActionDeprecated(restController),
new RestUpdateTransformActionDeprecated(restController)
);
}

Expand All @@ -174,27 +182,28 @@ public List<RestHandler> getRestHandlers(final Settings settings, final RestCont
}

return Arrays.asList(
new ActionHandler<>(PutTransformAction.INSTANCE, TransportPutTransformAction.class),
new ActionHandler<>(StartTransformAction.INSTANCE, TransportStartTransformAction.class),
new ActionHandler<>(StopTransformAction.INSTANCE, TransportStopTransformAction.class),
new ActionHandler<>(DeleteTransformAction.INSTANCE, TransportDeleteTransformAction.class),
new ActionHandler<>(GetTransformAction.INSTANCE, TransportGetTransformAction.class),
new ActionHandler<>(GetTransformStatsAction.INSTANCE, TransportGetTransformStatsAction.class),
new ActionHandler<>(PreviewTransformAction.INSTANCE, TransportPreviewTransformAction.class),
new ActionHandler<>(UpdateTransformAction.INSTANCE, TransportUpdateTransformAction.class),
new ActionHandler<>(PutTransformAction.INSTANCE, TransportPutTransformAction.class),
new ActionHandler<>(StartTransformAction.INSTANCE, TransportStartTransformAction.class),
new ActionHandler<>(StopTransformAction.INSTANCE, TransportStopTransformAction.class),
new ActionHandler<>(DeleteTransformAction.INSTANCE, TransportDeleteTransformAction.class),
new ActionHandler<>(GetTransformAction.INSTANCE, TransportGetTransformAction.class),
new ActionHandler<>(GetTransformStatsAction.INSTANCE, TransportGetTransformStatsAction.class),
new ActionHandler<>(PreviewTransformAction.INSTANCE, TransportPreviewTransformAction.class),
new ActionHandler<>(UpdateTransformAction.INSTANCE, TransportUpdateTransformAction.class),

// deprecated actions, to be removed for 8.0.0
new ActionHandler<>(PutTransformActionDeprecated.INSTANCE, TransportPutTransformActionDeprecated.class),
new ActionHandler<>(StartTransformActionDeprecated.INSTANCE, TransportStartTransformActionDeprecated.class),
new ActionHandler<>(StopTransformActionDeprecated.INSTANCE, TransportStopTransformActionDeprecated.class),
new ActionHandler<>(DeleteTransformActionDeprecated.INSTANCE, TransportDeleteTransformActionDeprecated.class),
new ActionHandler<>(GetTransformActionDeprecated.INSTANCE, TransportGetTransformActionDeprecated.class),
new ActionHandler<>(GetTransformStatsActionDeprecated.INSTANCE, TransportGetTransformStatsActionDeprecated.class),
new ActionHandler<>(PreviewTransformActionDeprecated.INSTANCE, TransportPreviewTransformActionDeprecated.class),
new ActionHandler<>(UpdateTransformActionDeprecated.INSTANCE, TransportUpdateTransformActionDeprecated.class),
// deprecated actions, to be removed for 8.0.0
new ActionHandler<>(PutTransformActionDeprecated.INSTANCE, TransportPutTransformActionDeprecated.class),
new ActionHandler<>(StartTransformActionDeprecated.INSTANCE, TransportStartTransformActionDeprecated.class),
new ActionHandler<>(StopTransformActionDeprecated.INSTANCE, TransportStopTransformActionDeprecated.class),
new ActionHandler<>(DeleteTransformActionDeprecated.INSTANCE, TransportDeleteTransformActionDeprecated.class),
new ActionHandler<>(GetTransformActionDeprecated.INSTANCE, TransportGetTransformActionDeprecated.class),
new ActionHandler<>(GetTransformStatsActionDeprecated.INSTANCE, TransportGetTransformStatsActionDeprecated.class),
new ActionHandler<>(PreviewTransformActionDeprecated.INSTANCE, TransportPreviewTransformActionDeprecated.class),
new ActionHandler<>(UpdateTransformActionDeprecated.INSTANCE, TransportUpdateTransformActionDeprecated.class),

usageAction,
infoAction);
usageAction,
infoAction
);
}

@Override
Expand All @@ -203,35 +212,58 @@ public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
return emptyList();
}

FixedExecutorBuilder indexing = new FixedExecutorBuilder(settings, TASK_THREAD_POOL_NAME, 4, 4,
"transform.task_thread_pool");
FixedExecutorBuilder indexing = new FixedExecutorBuilder(
settings,
TASK_THREAD_POOL_NAME,
4,
4,
"transform.task_thread_pool"
);

return Collections.singletonList(indexing);
}

@Override
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
ResourceWatcherService resourceWatcherService, ScriptService scriptService, NamedXContentRegistry xContentRegistry,
Environment environment, NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {
public Collection<Object> createComponents(
Client client,
ClusterService clusterService,
ThreadPool threadPool,
ResourceWatcherService resourceWatcherService,
ScriptService scriptService,
NamedXContentRegistry xContentRegistry,
Environment environment,
NodeEnvironment nodeEnvironment,
NamedWriteableRegistry namedWriteableRegistry
) {
if (enabled == false) {
return emptyList();
}
transformAuditor.set(new TransformAuditor(client, clusterService.getNodeName()));
transformConfigManager.set(new TransformConfigManager(client, xContentRegistry));
transformCheckpointService.set(new TransformCheckpointService(client,
transformConfigManager.get(),
transformAuditor.get()));
transformCheckpointService.set(
new TransformCheckpointService(
client,
transformConfigManager.get(),
transformAuditor.get()
)
);

return Arrays.asList(transformConfigManager.get(), transformAuditor.get(), transformCheckpointService.get(),
new TransformClusterStateListener(clusterService, client));
return Arrays.asList(
transformConfigManager.get(),
transformAuditor.get(),
transformCheckpointService.get(),
new TransformClusterStateListener(clusterService, client)
);
}

@Override
public UnaryOperator<Map<String, IndexTemplateMetaData>> getIndexTemplateMetaDataUpgrader() {
return templates -> {
try {
templates.put(TransformInternalIndexConstants.LATEST_INDEX_VERSIONED_NAME,
TransformInternalIndex.getIndexTemplateMetaData());
templates.put(
TransformInternalIndexConstants.LATEST_INDEX_VERSIONED_NAME,
TransformInternalIndex.getIndexTemplateMetaData()
);
} catch (IOException e) {
logger.error("Error creating data frame index template", e);
}
Expand All @@ -245,8 +277,12 @@ public UnaryOperator<Map<String, IndexTemplateMetaData>> getIndexTemplateMetaDat
}

@Override
public List<PersistentTasksExecutor<?>> getPersistentTasksExecutor(ClusterService clusterService, ThreadPool threadPool,
Client client, SettingsModule settingsModule) {
public List<PersistentTasksExecutor<?>> getPersistentTasksExecutor(
ClusterService clusterService,
ThreadPool threadPool,
Client client,
SettingsModule settingsModule
) {
if (enabled == false) {
return emptyList();
}
Expand All @@ -260,14 +296,17 @@ public List<PersistentTasksExecutor<?>> getPersistentTasksExecutor(ClusterServic
assert transformCheckpointService.get() != null;

return Collections.singletonList(
new TransformPersistentTasksExecutor(client,
new TransformPersistentTasksExecutor(
client,
transformConfigManager.get(),
transformCheckpointService.get(),
schedulerEngine.get(),
transformAuditor.get(),
threadPool,
clusterService,
settingsModule.getSettings()));
settingsModule.getSettings()
)
);
}

@Override
Expand Down