Skip to content

Commit

Permalink
Changed indexed scripts to be stored in the cluster state instead of …
Browse files Browse the repository at this point in the history
…the `.scripts` index.

Also added max script size soft limit for stored scripts.

Closes #16651
  • Loading branch information
martijnvg committed Apr 22, 2016
1 parent ae61fc4 commit c5ad2e2
Show file tree
Hide file tree
Showing 137 changed files with 2,389 additions and 2,772 deletions.
18 changes: 9 additions & 9 deletions core/src/main/java/org/elasticsearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@
import org.elasticsearch.action.get.TransportShardMultiGetAction;
import org.elasticsearch.action.index.IndexAction;
import org.elasticsearch.action.index.TransportIndexAction;
import org.elasticsearch.action.indexedscripts.delete.DeleteIndexedScriptAction;
import org.elasticsearch.action.indexedscripts.delete.TransportDeleteIndexedScriptAction;
import org.elasticsearch.action.indexedscripts.get.GetIndexedScriptAction;
import org.elasticsearch.action.indexedscripts.get.TransportGetIndexedScriptAction;
import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptAction;
import org.elasticsearch.action.indexedscripts.put.TransportPutIndexedScriptAction;
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptAction;
import org.elasticsearch.action.admin.cluster.storedscripts.TransportDeleteStoredScriptAction;
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptAction;
import org.elasticsearch.action.admin.cluster.storedscripts.TransportGetStoredScriptAction;
import org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptAction;
import org.elasticsearch.action.admin.cluster.storedscripts.TransportPutStoredScriptAction;
import org.elasticsearch.action.ingest.IngestActionFilter;
import org.elasticsearch.action.ingest.IngestProxyActionFilter;
import org.elasticsearch.action.ingest.DeletePipelineAction;
Expand Down Expand Up @@ -340,9 +340,9 @@ protected void configure() {
registerAction(RenderSearchTemplateAction.INSTANCE, TransportRenderSearchTemplateAction.class);

//Indexed scripts
registerAction(PutIndexedScriptAction.INSTANCE, TransportPutIndexedScriptAction.class);
registerAction(GetIndexedScriptAction.INSTANCE, TransportGetIndexedScriptAction.class);
registerAction(DeleteIndexedScriptAction.INSTANCE, TransportDeleteIndexedScriptAction.class);
registerAction(PutStoredScriptAction.INSTANCE, TransportPutStoredScriptAction.class);
registerAction(GetStoredScriptAction.INSTANCE, TransportGetStoredScriptAction.class);
registerAction(DeleteStoredScriptAction.INSTANCE, TransportDeleteStoredScriptAction.class);

registerAction(FieldStatsAction.INSTANCE, TransportFieldStatsTransportAction.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,30 @@
* under the License.
*/

package org.elasticsearch.action.indexedscripts.delete;
package org.elasticsearch.action.admin.cluster.storedscripts;

import org.elasticsearch.action.Action;
import org.elasticsearch.client.ElasticsearchClient;

/**
*/
public class DeleteIndexedScriptAction extends Action<DeleteIndexedScriptRequest, DeleteIndexedScriptResponse, DeleteIndexedScriptRequestBuilder> {
public class DeleteStoredScriptAction extends Action<DeleteStoredScriptRequest, DeleteStoredScriptResponse,
DeleteStoredScriptRequestBuilder> {

public static final DeleteIndexedScriptAction INSTANCE = new DeleteIndexedScriptAction();
public static final String NAME = "indices:data/write/script/delete";
public static final DeleteStoredScriptAction INSTANCE = new DeleteStoredScriptAction();
public static final String NAME = "cluster:admin/script/delete";

private DeleteIndexedScriptAction() {
private DeleteStoredScriptAction() {
super(NAME);
}

@Override
public DeleteIndexedScriptResponse newResponse() {
return new DeleteIndexedScriptResponse();
public DeleteStoredScriptResponse newResponse() {
return new DeleteStoredScriptResponse();
}

@Override
public DeleteIndexedScriptRequestBuilder newRequestBuilder(ElasticsearchClient client) {
return new DeleteIndexedScriptRequestBuilder(client, this);
public DeleteStoredScriptRequestBuilder newRequestBuilder(ElasticsearchClient client) {
return new DeleteStoredScriptRequestBuilder(client, this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.admin.cluster.storedscripts;

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

import static org.elasticsearch.action.ValidateActions.addValidationError;

public class DeleteStoredScriptRequest extends AcknowledgedRequest<DeleteStoredScriptRequest> {

private String id;
private String scriptLang;

DeleteStoredScriptRequest() {
}

public DeleteStoredScriptRequest(String scriptLang, String id) {
this.scriptLang = scriptLang;
this.id = id;
}

@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (id == null) {
validationException = addValidationError("id is missing", validationException);
} else if (id.contains("#")) {
validationException = addValidationError("id can't contain: '#'", validationException);
}
if (scriptLang == null) {
validationException = addValidationError("lang is missing", validationException);
} else if (scriptLang.contains("#")) {
validationException = addValidationError("lang can't contain: '#'", validationException);
}
return validationException;
}

public String scriptLang() {
return scriptLang;
}

public DeleteStoredScriptRequest scriptLang(String type) {
this.scriptLang = type;
return this;
}

public String id() {
return id;
}

public DeleteStoredScriptRequest id(String id) {
this.id = id;
return this;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
scriptLang = in.readString();
id = in.readString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(scriptLang);
out.writeString(id);
}

@Override
public String toString() {
return "delete script {[" + scriptLang + "][" + id + "]}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.admin.cluster.storedscripts;

import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;

public class DeleteStoredScriptRequestBuilder extends AcknowledgedRequestBuilder<DeleteStoredScriptRequest,
DeleteStoredScriptResponse, DeleteStoredScriptRequestBuilder> {

public DeleteStoredScriptRequestBuilder(ElasticsearchClient client, DeleteStoredScriptAction action) {
super(client, action, new DeleteStoredScriptRequest());
}

public DeleteStoredScriptRequestBuilder setScriptLang(String scriptLang) {
request.scriptLang(scriptLang);
return this;
}

public DeleteStoredScriptRequestBuilder setId(String id) {
request.id(id);
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.admin.cluster.storedscripts;

import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

public class DeleteStoredScriptResponse extends AcknowledgedResponse {

DeleteStoredScriptResponse() {
}

public DeleteStoredScriptResponse(boolean acknowledged) {
super(acknowledged);
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
readAcknowledged(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
writeAcknowledged(out);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,31 @@
* under the License.
*/

package org.elasticsearch.action.indexedscripts.get;
package org.elasticsearch.action.admin.cluster.storedscripts;

import org.elasticsearch.action.Action;
import org.elasticsearch.client.ElasticsearchClient;

/**
*/
public class GetIndexedScriptAction extends Action<GetIndexedScriptRequest, GetIndexedScriptResponse, GetIndexedScriptRequestBuilder> {
public class GetStoredScriptAction extends Action<GetStoredScriptRequest, GetStoredScriptResponse,
GetStoredScriptRequestBuilder> {

public static final GetIndexedScriptAction INSTANCE = new GetIndexedScriptAction();
public static final String NAME = "indices:data/read/script/get";
public static final GetStoredScriptAction INSTANCE = new GetStoredScriptAction();
public static final String NAME = "cluster:admin/script/get";

private GetIndexedScriptAction() {
private GetStoredScriptAction() {
super(NAME);
}

@Override
public GetIndexedScriptResponse newResponse() {
return new GetIndexedScriptResponse();
public GetStoredScriptResponse newResponse() {
return new GetStoredScriptResponse();
}

@Override
public GetIndexedScriptRequestBuilder newRequestBuilder(ElasticsearchClient client) {
return new GetIndexedScriptRequestBuilder(client, this);
public GetStoredScriptRequestBuilder newRequestBuilder(ElasticsearchClient client) {
return new GetStoredScriptRequestBuilder(client, this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.action.admin.cluster.storedscripts;

import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

import java.io.IOException;

public class GetStoredScriptRequest extends MasterNodeReadRequest<GetStoredScriptRequest> {

protected String id;
protected String lang;

GetStoredScriptRequest() {
}

public GetStoredScriptRequest(String lang, String id) {
this.lang = lang;
this.id = id;
}

@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (lang == null) {
validationException = ValidateActions.addValidationError("lang is missing", validationException);
}
if (id == null) {
validationException = ValidateActions.addValidationError("id is missing", validationException);
}
return validationException;
}

public GetStoredScriptRequest lang(@Nullable String type) {
this.lang = type;
return this;
}

public GetStoredScriptRequest id(String id) {
this.id = id;
return this;
}


public String lang() {
return lang;
}

public String id() {
return id;
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
lang = in.readString();
id = in.readString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(lang);
out.writeString(id);
}

@Override
public String toString() {
return "get script [" + lang + "][" + id + "]";
}
}
Loading

0 comments on commit c5ad2e2

Please sign in to comment.