mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 18:35:25 +00:00
WatchSourceBuilder to extend ToXContentToBytes
Original commit: elastic/x-pack-elasticsearch@b97ad8f92c
This commit is contained in:
parent
c23de42f29
commit
0b93bc98bf
@ -5,18 +5,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.watcher.client;
|
package org.elasticsearch.xpack.watcher.client;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.action.support.ToXContentToBytes;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
|
||||||
import org.elasticsearch.xpack.watcher.actions.Action;
|
import org.elasticsearch.xpack.watcher.actions.Action;
|
||||||
import org.elasticsearch.xpack.watcher.actions.throttler.Throttler;
|
import org.elasticsearch.xpack.watcher.actions.throttler.Throttler;
|
||||||
import org.elasticsearch.xpack.watcher.condition.Condition;
|
|
||||||
import org.elasticsearch.xpack.watcher.condition.AlwaysCondition;
|
import org.elasticsearch.xpack.watcher.condition.AlwaysCondition;
|
||||||
|
import org.elasticsearch.xpack.watcher.condition.Condition;
|
||||||
import org.elasticsearch.xpack.watcher.input.Input;
|
import org.elasticsearch.xpack.watcher.input.Input;
|
||||||
import org.elasticsearch.xpack.watcher.input.none.NoneInput;
|
import org.elasticsearch.xpack.watcher.input.none.NoneInput;
|
||||||
import org.elasticsearch.xpack.watcher.support.Exceptions;
|
import org.elasticsearch.xpack.watcher.support.Exceptions;
|
||||||
@ -31,7 +28,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
|
|
||||||
public class WatchSourceBuilder implements ToXContent {
|
public class WatchSourceBuilder extends ToXContentToBytes implements ToXContent {
|
||||||
|
|
||||||
private Trigger trigger;
|
private Trigger trigger;
|
||||||
private Input input = NoneInput.INSTANCE;
|
private Input input = NoneInput.INSTANCE;
|
||||||
@ -165,17 +162,6 @@ public class WatchSourceBuilder implements ToXContent {
|
|||||||
return builder.endObject();
|
return builder.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BytesReference buildAsBytes(XContentType contentType) {
|
|
||||||
try {
|
|
||||||
XContentBuilder builder = XContentFactory.contentBuilder(contentType);
|
|
||||||
toXContent(builder, ToXContent.EMPTY_PARAMS);
|
|
||||||
return builder.bytes();
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
// todo think of a better std exception for this
|
|
||||||
throw new ElasticsearchException("failed to render watch source as bytes", ioe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class TransformedAction implements ToXContent {
|
static class TransformedAction implements ToXContent {
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package org.elasticsearch.xpack.watcher.transport.action.put;
|
package org.elasticsearch.xpack.watcher.transport.action.put;
|
||||||
|
|
||||||
|
|
||||||
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||||
import org.elasticsearch.xpack.watcher.condition.AlwaysCondition;
|
import org.elasticsearch.xpack.watcher.condition.AlwaysCondition;
|
||||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||||
@ -45,15 +46,12 @@ public class PutWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||||||
|
|
||||||
public void testPutNoTrigger() throws Exception {
|
public void testPutNoTrigger() throws Exception {
|
||||||
ensureWatcherStarted();
|
ensureWatcherStarted();
|
||||||
try {
|
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
|
||||||
watcherClient().preparePutWatch("_name").setSource(watchBuilder()
|
() -> watcherClient().preparePutWatch("_name").setSource(watchBuilder()
|
||||||
.input(simpleInput())
|
.input(simpleInput())
|
||||||
.condition(AlwaysCondition.INSTANCE)
|
.condition(AlwaysCondition.INSTANCE)
|
||||||
.addAction("_action1", loggingAction("{{ctx.watch_id}}")))
|
.addAction("_action1", loggingAction("{{ctx.watch_id}}")))
|
||||||
.get();
|
.get());
|
||||||
fail("Expected IllegalStateException");
|
assertEquals("Failed to build ToXContent", exception.getMessage());
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
assertThat(e.getMessage(), is("failed to build watch source. no trigger defined"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user